-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
dynamic_font.go
95 lines (77 loc) · 2.38 KB
/
dynamic_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
// Copyright (c) 2021-2024 by Richard A. Wilkes. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.
package unison
import (
"github.com/richardwilkes/unison/internal/skia"
)
var _ Font = &DynamicFont{}
// DynamicFont holds a Font that can be dynamically adjusted.
type DynamicFont struct {
Resolver func() FontDescriptor
font Font
desc FontDescriptor
}
func (f *DynamicFont) resolvedFont() Font {
if desc := f.Resolver(); desc != f.desc {
f.desc = desc
f.font = desc.Font()
}
return f.font
}
// Face implements Font.
func (f *DynamicFont) Face() *FontFace {
return f.resolvedFont().Face()
}
// Size implements Font.
func (f *DynamicFont) Size() float32 {
return f.resolvedFont().Size()
}
// Metrics implements Font.
func (f *DynamicFont) Metrics() FontMetrics {
return f.resolvedFont().Metrics()
}
// Baseline implements Font.
func (f *DynamicFont) Baseline() float32 {
return f.resolvedFont().Baseline()
}
// LineHeight implements Font.
func (f *DynamicFont) LineHeight() float32 {
return f.resolvedFont().LineHeight()
}
// RuneToGlyph implements Font.
func (f *DynamicFont) RuneToGlyph(r rune) uint16 {
return f.resolvedFont().RuneToGlyph(r)
}
// RunesToGlyphs implements Font.
func (f *DynamicFont) RunesToGlyphs(r []rune) []uint16 {
return f.resolvedFont().RunesToGlyphs(r)
}
// GlyphWidth implements Font.
func (f *DynamicFont) GlyphWidth(glyph uint16) float32 {
return f.resolvedFont().GlyphWidth(glyph)
}
// GlyphWidths implements Font.
func (f *DynamicFont) GlyphWidths(glyphs []uint16) []float32 {
return f.resolvedFont().GlyphWidths(glyphs)
}
// SimpleWidth implements Font.
func (f *DynamicFont) SimpleWidth(str string) float32 {
return f.resolvedFont().SimpleWidth(str)
}
// Descriptor implements Font.
func (f *DynamicFont) Descriptor() FontDescriptor {
return f.resolvedFont().Descriptor()
}
// TextBlobPosH implements Font.
func (f *DynamicFont) TextBlobPosH(glyphs []uint16, positions []float32, y float32) *TextBlob {
return f.resolvedFont().TextBlobPosH(glyphs, positions, y)
}
func (f *DynamicFont) skiaFont() skia.Font {
return f.resolvedFont().skiaFont()
}