forked from fyne-io/fyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.go
111 lines (93 loc) · 2.87 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
102
103
104
105
106
107
108
109
110
111
package theme
import (
"image/color"
"fyne.io/fyne/v2"
)
// DefaultEmojiFont returns the font resource for the built-in emoji font.
// This may return nil if the application was packaged without an emoji font.
//
// Since: 2.4
func DefaultEmojiFont() fyne.Resource {
return emoji
}
// DefaultTextBoldFont returns the font resource for the built-in bold font style.
func DefaultTextBoldFont() fyne.Resource {
return bold
}
// DefaultTextBoldItalicFont returns the font resource for the built-in bold and italic font style.
func DefaultTextBoldItalicFont() fyne.Resource {
return bolditalic
}
// DefaultTextFont returns the font resource for the built-in regular font style.
func DefaultTextFont() fyne.Resource {
return regular
}
// DefaultTextItalicFont returns the font resource for the built-in italic font style.
func DefaultTextItalicFont() fyne.Resource {
return italic
}
// DefaultTextMonospaceFont returns the font resource for the built-in monospace font face.
func DefaultTextMonospaceFont() fyne.Resource {
return monospace
}
// DefaultSymbolFont returns the font resource for the built-in symbol font.
//
// Since: 2.2
func DefaultSymbolFont() fyne.Resource {
return symbol
}
// TextBoldFont returns the font resource for the bold font style.
func TextBoldFont() fyne.Resource {
return safeFontLookup(fyne.TextStyle{Bold: true})
}
// TextBoldItalicFont returns the font resource for the bold and italic font style.
func TextBoldItalicFont() fyne.Resource {
return safeFontLookup(fyne.TextStyle{Bold: true, Italic: true})
}
// TextColor returns the theme's standard text color - this is actually the foreground color since 1.4.
//
// Deprecated: Use theme.ForegroundColor() colour instead.
func TextColor() color.Color {
return safeColorLookup(ColorNameForeground, currentVariant())
}
// TextFont returns the font resource for the regular font style.
func TextFont() fyne.Resource {
return safeFontLookup(fyne.TextStyle{})
}
// TextItalicFont returns the font resource for the italic font style.
func TextItalicFont() fyne.Resource {
return safeFontLookup(fyne.TextStyle{Italic: true})
}
// TextMonospaceFont returns the font resource for the monospace font face.
func TextMonospaceFont() fyne.Resource {
return safeFontLookup(fyne.TextStyle{Monospace: true})
}
// SymbolFont returns the font resource for the symbol font style.
//
// Since: 2.4
func SymbolFont() fyne.Resource {
return safeFontLookup(fyne.TextStyle{Symbol: true})
}
func safeFontLookup(s fyne.TextStyle) fyne.Resource {
font := current().Font(s)
if font != nil {
return font
}
fyne.LogError("Loaded theme returned nil font", nil)
if s.Monospace {
return DefaultTextMonospaceFont()
}
if s.Bold {
if s.Italic {
return DefaultTextBoldItalicFont()
}
return DefaultTextBoldFont()
}
if s.Italic {
return DefaultTextItalicFont()
}
if s.Symbol {
return DefaultSymbolFont()
}
return DefaultTextFont()
}