Custom fonts hindi , urdu, persian, arabic – Fyne Golang tutorial

Custom fonts hindi , urdu, persian, arabic – Fyne Golang tutorial

Do you want to use custom fonts in fyne & Golang. Here is the working fyne custom font example.

First step enviroment variable

    os.Setenv(“FYNE_FONT”, “urdu.ttf”) // enviroment variable
Here you need to mention key & value.
  • Key is “FYNE_FONT”
  • value is font name with .ttf extenson. For Example myfontname.ttf
import “os” package. No need to download. It is already installed by default.
Now you can use widget.NewLabel or canvas.NewText to display text in fyne GUI
<div>package main</div>
<div>import (</div>
<div>    "image/color"</div>
<div>    "os"</div>
<div>    ""</div>
<div>    ""</div>
<div>func main() {</div>
<div>    // enviroment variable</div>
<div>    os.Setenv("FYNE_FONT", "urdu.ttf")</div>
<div>    // lets use urdu font</div>
<div>    // urdu result is not acceptable</div>
<div>    // next font</div>
<div>    // some fonts are not working in fyne</div>
<div>    // creating app</div>
<div>    a := app.New()</div>
<div>    // new window</div>
<div>    w := a.NewWindow("Custom font hindi &amp; URDU")</div>
<div>    //label to show hindi text</div>
<div>    label1 := canvas.NewText("کیا حال ہے؟", color.Black)</div>
<div>    //label1 := canvas.NewText("किया हाल है ?", color.Black)</div>
<div>    //it means "How are you ?"</div>
<div>    // Urdu and arabic are broken</div>
<div>    // set content</div>
<div>    w.SetContent(label1)</div>
<div>    //show and run</div>
<div>    w.ShowAndRun()</div>
Tony BB

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: