Skip to content

Sample application that uses different fonts in Fyne

License

Notifications You must be signed in to change notification settings

ghp268/fyne-font-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fyne-font-example

Fyne で日本語フォントを利用するサンプルアプリケーションです。

Sample application that uses different fonts in Fyne.

これは Fyne v2.x についての説明です. Fyne v1.x 以前のバージョンについて知りたい場合は v1 以下を参照してください.

This is a description for Fyne v2.x. If you want to know for Fyne v1.x or earlier, please refer to the v1 directory.

Prefer to work with the GUI? Try the fyne-theme-generator!

Summary

0. fyne コマンドをインストール / Install fyne command

$ go get fyne.io/fyne/v2/cmd/fyne

$ fyne
Usage: fyne [command] [parameters], where command is one of:
...

1. フォントファイルを用意して fyne bundle コマンドを実行 / Prepare the font file and execute fyne bundle command

$ fyne bundle mplus-1c-regular.ttf > bundle.go

$ head -n 9 bundle.go
// auto-generated

package main

import "fyne.io/fyne/v2"

var resourceMplus1cRegularTtf = &fyne.StaticResource{
	StaticName: "mplus-1c-regular.ttf",
	StaticContent: []byte{

See ./v2/bundle.go.

Warning: the file size is very large

2. カスタムテーマを作成しフォントリソースを読み込む / Create the custom theme and load font resources

type myTheme struct{}

func (*myTheme) Font(s fyne.TextStyle) fyne.Resource {
	if s.Monospace {
		return theme.DefaultTheme().Font(s)
	}
	if s.Bold {
		if s.Italic {
			return theme.DefaultTheme().Font(s)
		}
		return resourceMplus1cBoldTtf
	}
	if s.Italic {
		return theme.DefaultTheme().Font(s)
	}
	return resourceMplus1cRegularTtf
}
...

See ./v2/theme.go.

3. カスタムテーマを読み込む / Load the custom theme

...
	a := app.New()
	a.Settings().SetTheme(&myTheme{})
...

See ./v2/main.go.

もう少し詳しく

bundle.gofyne command を利用して生成しています.

$ fyne bundle mplus-1c-regular.ttf > bundle.go
$ fyne bundle -append mplus-1c-bold.ttf >> bundle.go

詳細については以下の記事に記載しています.

公式のチュートリアルにもリソースのバンドルについて追記されました.

A little more details

bundle.go is generated using fyne command.

$ fyne bundle mplus-1c-regular.ttf > bundle.go
$ fyne bundle -append mplus-1c-bold.ttf >> bundle.go

See the Blog below for more information. (Japanese)

An official tutorial has also been added on resource bundling.


M+ FONTS is included and used as a sample font file.

http://mplus-fonts.osdn.jp/

About

Sample application that uses different fonts in Fyne

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%