font

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2023 License: MIT Imports: 6 Imported by: 0

README

font

autoload font file for fyne app

zh: 自动加载系统中的字体文件

package main

import (
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/container"
    "fyne.io/fyne/v2/widget"
    _ "github.com/lengzhao/font/autoload"
)

func main() {
    a := app.New()
    w := a.NewWindow("Hello")

    hello := widget.NewLabel("Hello Fyne!你好")
    w.SetContent(container.NewVBox(
        hello,
        widget.NewButton("Hi!", func() {
            hello.SetText("Welcome :)")
        }),
    ))

    w.ShowAndRun()
}

description

FindFontFile: finds font files based on the specified language.

It takes a language code as a parameter and returns a slice of strings representing the file paths of the font files. If no font files are found, an error is returned.

params: language string, e.g. "en", "fr", "de", etc. if language is "", the system language is used.

See https://www.microsoft.com/typography/otspec/languagetags.htm

package main

import (
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/container"
    "fyne.io/fyne/v2/widget"
    "github.com/lengzhao/font"
)

func main() {
    files := font.FindFontFile("ZHS")
    if len(files) > 0 {
        os.Setenv("FYNE_FONT", files[0])
    }

    a := app.New()
    w := a.NewWindow("Hello")

    hello := widget.NewLabel("Hello Fyne!你好")
    w.SetContent(container.NewVBox(
        hello,
        widget.NewButton("Hi!", func() {
            hello.SetText("Welcome :)")
        }),
    ))

    w.ShowAndRun()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindFontFile

func FindFontFile(lg string) []string

FindFontFile finds font files based on the specified language.

It takes a language code as a parameter and returns a slice of strings representing the file paths of the font files. If no font files are found, an error is returned.

params: language string, e.g. "en", "fr", "de", etc.

if language is "", the system language is used.

See https://www.microsoft.com/typography/otspec/languagetags.htm

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL