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

package main
import (
    "image/color"
    "os"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/canvas"
)
func main() {
    // enviroment variable
    os.Setenv("FYNE_FONT", "urdu.ttf")
    // lets use urdu font
    // urdu result is not acceptable
    // next font
    // some fonts are not working in fyne
    // creating app
    a := app.New()
    // new window
    w := a.NewWindow("Custom font hindi & URDU")
    //label to show hindi text
    label1 := canvas.NewText("کیا حال ہے؟", color.Black)
    //label1 := canvas.NewText("किया हाल है ?", color.Black)
    //it means "How are you ?"
    // Urdu and arabic are broken
    // set content
    w.SetContent(label1)
    //show and run
    w.ShowAndRun()
}

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: