Line data Source code
1 : package resources
2 :
3 : import (
4 : "github.com/hajimehoshi/ebiten/v2/text/v2"
5 :
6 : "github.com/kijimaD/ruins/assets"
7 : )
8 :
9 : // Font はロード済みのフォント
10 : type Font struct {
11 : Font text.Face
12 : FaceSource *text.GoTextFaceSource // コピーが禁止されていて参照渡ししかできない
13 : }
14 :
15 : // NewFont はフォントパスからフォントを読み込む
16 : func NewFont(fontPath string) (Font, error) {
17 1 : fontFile, err := assets.FS.Open(fontPath)
18 1 : if err != nil {
19 1 : return Font{}, err
20 1 : }
21 :
22 1 : s, err := text.NewGoTextFaceSource(fontFile)
23 1 : if err != nil {
24 1 : return Font{}, err
25 1 : }
26 :
27 1 : return Font{
28 1 : FaceSource: s,
29 1 : Font: &text.GoTextFace{Source: s, Size: 24},
30 1 : }, nil
31 : }
|