-
Notifications
You must be signed in to change notification settings - Fork 8
/
font.go
101 lines (82 loc) · 2.31 KB
/
font.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2018 Hajime Hoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package bitmapfont offers a font.Face value of some bitmap fonts.
//
// - [Baekmuk Gulim](https://kldp.net/baekmuk/) (Baekmuk License)
// - [misc-fixed](https://www.cl.cam.ac.uk/~mgk25/ucs-fonts.html) (Public Domain)
// - [M+ Bitmap Font](https://mplus-fonts.osdn.jp/mplus-bitmap-fonts/) (M+ Bitmap Fonts License)
// - Arabic glyphs by [@MansourSorosoro](https://twitter.com/MansourSorosoro) (Eternal Dream Arabization) (OFL-1.1)
package bitmapfont
import (
"compress/gzip"
"embed"
"io/ioutil"
"golang.org/x/image/font"
"golang.org/x/image/math/fixed"
"github.com/hajimehoshi/bitmapfont/v3/internal/bitmap"
)
//go:embed data/*.bin
var data embed.FS
func init() {
const (
imageWidth = 12 * 256
imageHeight = 16 * 256
dotX = 0
dotY = 12
)
f, err := data.Open("data/face.bin")
if err != nil {
panic(err)
}
defer f.Close()
s, err := gzip.NewReader(f)
if err != nil {
panic(err)
}
defer s.Close()
bits, err := ioutil.ReadAll(s)
if err != nil {
panic(err)
}
Face = bitmap.NewFace(bitmap.NewBinaryImage(bits, imageWidth, imageHeight), fixed.I(dotX), fixed.I(dotY), false)
}
func init() {
const (
imageWidth = 12 * 256
imageHeight = 16 * 256
dotX = 0
dotY = 12
)
f, err := data.Open("data/faceea.bin")
if err != nil {
panic(err)
}
defer f.Close()
s, err := gzip.NewReader(f)
if err != nil {
panic(err)
}
defer s.Close()
bits, err := ioutil.ReadAll(s)
if err != nil {
panic(err)
}
FaceEA = bitmap.NewFace(bitmap.NewBinaryImage(bits, imageWidth, imageHeight), fixed.I(dotX), fixed.I(dotY), true)
}
var (
// Face is a font.Face of the bitmap font (12px regular).
Face font.Face
// FaceEA is a font.Face of the bitmap font (12px regular, prefer East Asian wide characters).
FaceEA font.Face
)