We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2479795 commit e7201d6Copy full SHA for e7201d6
.github/workflows/ci.yml
@@ -61,6 +61,13 @@ jobs:
61
find . -name "*.cpp" -type f -delete
62
shell: bash
63
64
+ - name: Install Microsoft core fonts
65
+ if: runner.os == 'Linux'
66
+ run: |
67
+ echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections
68
+ sudo apt-get update -q
69
+ sudo apt-get install -y ttf-mscorefonts-installer
70
+
71
- name: Run examples
72
73
run: go test -v -count=1 ./...
examples/fonts_test.go
@@ -0,0 +1,38 @@
1
+package main
2
3
+import "runtime"
4
5
+// fontPath returns the OS-specific file path for a given font name.
6
+// Supported names: "Impact", "Arial", "Arial Bold".
7
+func fontPath(name string) string {
8
+ switch runtime.GOOS {
9
+ case "windows":
10
+ switch name {
11
+ case "Impact":
12
+ return `C:\Windows\Fonts\impact.ttf`
13
+ case "Arial":
14
+ return `C:\Windows\Fonts\arial.ttf`
15
+ case "Arial Bold":
16
+ return `C:\Windows\Fonts\arialbd.ttf`
17
+ }
18
+ case "darwin":
19
20
21
+ return "/System/Library/Fonts/Supplemental/Impact.ttf"
22
23
+ return "/System/Library/Fonts/Supplemental/Arial.ttf"
24
25
+ return "/System/Library/Fonts/Supplemental/Arial Bold.ttf"
26
27
+ default: // linux, freebsd, etc.
28
29
30
+ return "/usr/share/fonts/truetype/msttcorefonts/Impact.ttf"
31
32
+ return "/usr/share/fonts/truetype/msttcorefonts/Arial.ttf"
33
34
+ return "/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf"
35
36
37
+ return name
38
+}
examples/gradient-text_test.go
@@ -16,7 +16,7 @@ func TestGT(*testing.T) {
// draw text
dc.SetRGB(0, 0, 0)
- if err := dc.LoadFontFace("/System/Library/Fonts/Supplemental/Impact.ttf", 128); err != nil {
+ if err := dc.LoadFontFace(fontPath("Impact"), 128); err != nil {
panic(err)
}
dc.DrawStringAnchored("Gradient Text", W/2, H/2, 0.5, 0.5)
examples/meme_test.go
@@ -11,7 +11,7 @@ func TestMeme(*testing.T) {
dc := gg.NewContext(S, S)
dc.SetRGB(1, 1, 1)
dc.Clear()
- if err := dc.LoadFontFace("/System/Library/Fonts/Supplemental/Impact.ttf", 96); err != nil {
+ if err := dc.LoadFontFace(fontPath("Impact"), 96); err != nil {
examples/quadratic_test.go
@@ -50,7 +50,7 @@ func TestQuadratic(*testing.T) {
50
dc.SetLineWidth(4)
51
dc.Stroke()
52
53
- if err := dc.LoadFontFace("/System/Library/Fonts/Supplemental/Arial.ttf", 200); err != nil {
+ if err := dc.LoadFontFace(fontPath("Arial"), 200); err != nil {
54
55
56
dc.DrawStringAnchored("g", -5, 5, 0.5, 0.5)
examples/scatter_test.go
@@ -55,11 +55,11 @@ func TestScatter(*testing.T) {
dc.Identity()
57
58
- if err := dc.LoadFontFace("/System/Library/Fonts/Supplemental/Arial Bold.ttf", 24); err != nil {
+ if err := dc.LoadFontFace(fontPath("Arial Bold"), 24); err != nil {
59
60
dc.DrawStringAnchored("Chart Title", S/2, P/2, 0.5, 0.5)
- if err := dc.LoadFontFace("/System/Library/Fonts/Supplemental/Arial.ttf", 18); err != nil {
+ if err := dc.LoadFontFace(fontPath("Arial"), 18); err != nil {
dc.DrawStringAnchored("X Axis Title", S/2, S-P/2, 0.5, 0.5)
examples/text_test.go
@@ -13,7 +13,7 @@ func TestText(*testing.T) {
// 字体路径
- if err := dc.LoadFontFace("/System/Library/Fonts/Supplemental/Arial.ttf", 96); err != nil {
+ if err := dc.LoadFontFace(fontPath("Arial"), 96); err != nil {
dc.DrawStringAnchored("Hello, world!", S/2, S/2, 0.5, 0.5)
examples/unicode_test.go
@@ -14,7 +14,7 @@ func TestUnicode(*testing.T) {
- if err := dc.LoadFontFace("/System/Library/Fonts/Supplemental/Impact.ttf", F); err != nil {
+ if err := dc.LoadFontFace(fontPath("Impact"), F); err != nil {
for r := range 256 {
examples/wrap_test.go
@@ -22,7 +22,7 @@ func TestWrap(*testing.T) {
dc.SetLineWidth(3)
- if err := dc.LoadFontFace("/System/Library/Fonts/Supplemental/Arial Bold.ttf", 18); err != nil {
+ if err := dc.LoadFontFace(fontPath("Arial Bold"), 18); err != nil {
dc.DrawStringWrapped("UPPER LEFT", P, P, 0, 0, 0, 1.5, gg.AlignLeft)
@@ -33,7 +33,7 @@ func TestWrap(*testing.T) {
dc.DrawStringWrapped("LOWER MIDDLE", W/2, H-P, 0.5, 1, 0, 1.5, gg.AlignCenter)
dc.DrawStringWrapped("LEFT MIDDLE", P, H/2, 0, 0.5, 0, 1.5, gg.AlignLeft)
dc.DrawStringWrapped("RIGHT MIDDLE", W-P, H/2, 1, 0.5, 0, 1.5, gg.AlignRight)
- if err := dc.LoadFontFace("/System/Library/Fonts/Supplemental/Arial.ttf", 12); err != nil {
+ if err := dc.LoadFontFace(fontPath("Arial"), 12); err != nil {
39
dc.DrawStringWrapped(TEXT, W/2-P, H/2-P, 1, 1, W/3, 1.75, gg.AlignLeft)
0 commit comments