font.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package theme
  2. import (
  3. "image/color"
  4. "fyne.io/fyne/v2"
  5. )
  6. // DefaultEmojiFont returns the font resource for the built-in emoji font.
  7. // This may return nil if the application was packaged without an emoji font.
  8. //
  9. // Since: 2.4
  10. func DefaultEmojiFont() fyne.Resource {
  11. return emoji
  12. }
  13. // DefaultTextBoldFont returns the font resource for the built-in bold font style.
  14. func DefaultTextBoldFont() fyne.Resource {
  15. return bold
  16. }
  17. // DefaultTextBoldItalicFont returns the font resource for the built-in bold and italic font style.
  18. func DefaultTextBoldItalicFont() fyne.Resource {
  19. return bolditalic
  20. }
  21. // DefaultTextFont returns the font resource for the built-in regular font style.
  22. func DefaultTextFont() fyne.Resource {
  23. return regular
  24. }
  25. // DefaultTextItalicFont returns the font resource for the built-in italic font style.
  26. func DefaultTextItalicFont() fyne.Resource {
  27. return italic
  28. }
  29. // DefaultTextMonospaceFont returns the font resource for the built-in monospace font face.
  30. func DefaultTextMonospaceFont() fyne.Resource {
  31. return monospace
  32. }
  33. // DefaultSymbolFont returns the font resource for the built-in symbol font.
  34. //
  35. // Since: 2.2
  36. func DefaultSymbolFont() fyne.Resource {
  37. return symbol
  38. }
  39. // TextBoldFont returns the font resource for the bold font style.
  40. func TextBoldFont() fyne.Resource {
  41. return safeFontLookup(fyne.TextStyle{Bold: true})
  42. }
  43. // TextBoldItalicFont returns the font resource for the bold and italic font style.
  44. func TextBoldItalicFont() fyne.Resource {
  45. return safeFontLookup(fyne.TextStyle{Bold: true, Italic: true})
  46. }
  47. // TextColor returns the theme's standard text color - this is actually the foreground color since 1.4.
  48. //
  49. // Deprecated: Use theme.ForegroundColor() colour instead.
  50. func TextColor() color.Color {
  51. return safeColorLookup(ColorNameForeground, currentVariant())
  52. }
  53. // TextFont returns the font resource for the regular font style.
  54. func TextFont() fyne.Resource {
  55. return safeFontLookup(fyne.TextStyle{})
  56. }
  57. // TextItalicFont returns the font resource for the italic font style.
  58. func TextItalicFont() fyne.Resource {
  59. return safeFontLookup(fyne.TextStyle{Italic: true})
  60. }
  61. // TextMonospaceFont returns the font resource for the monospace font face.
  62. func TextMonospaceFont() fyne.Resource {
  63. return safeFontLookup(fyne.TextStyle{Monospace: true})
  64. }
  65. // SymbolFont returns the font resource for the symbol font style.
  66. //
  67. // Since: 2.4
  68. func SymbolFont() fyne.Resource {
  69. return safeFontLookup(fyne.TextStyle{Symbol: true})
  70. }
  71. func safeFontLookup(s fyne.TextStyle) fyne.Resource {
  72. font := current().Font(s)
  73. if font != nil {
  74. return font
  75. }
  76. fyne.LogError("Loaded theme returned nil font", nil)
  77. if s.Monospace {
  78. return DefaultTextMonospaceFont()
  79. }
  80. if s.Bold {
  81. if s.Italic {
  82. return DefaultTextBoldItalicFont()
  83. }
  84. return DefaultTextBoldFont()
  85. }
  86. if s.Italic {
  87. return DefaultTextItalicFont()
  88. }
  89. if s.Symbol {
  90. return DefaultSymbolFont()
  91. }
  92. return DefaultTextFont()
  93. }