35#include <wx/hashmap.h>
40#include <wx/settings.h>
43#include "FontAttribs.h"
45#include <unordered_map>
48static constexpr uint32_t MAKE_RGB(uint32_t r, uint32_t g, uint32_t b)
49{
return (0xFF & r) | ((0xFF & g) << 8) | ((0xFF & b) << 16); }
78 Style &
Read(wxConfigBase *config,
const wxString &where);
80 void Write(wxConfigBase *config,
const wxString &where)
const;
87 constexpr static wxFontFamily Default_Family{wxFONTFAMILY_DEFAULT};
88 constexpr static wxFontEncoding Default_Encoding{wxFONTENCODING_DEFAULT};
89 constexpr static wxFontWeight Default_Weight{wxFONTWEIGHT_NORMAL};
90 constexpr static wxFontStyle Default_FontStyle{wxFONTSTYLE_NORMAL};
91 constexpr static bool Default_Underlined{
false};
92 constexpr static bool Default_Strikethrough{
false};
93 constexpr static AFontSize Default_FontSize{10.0f};
94 constexpr static uint32_t Default_ColorRGB{MAKE_RGB(0, 0, 0)};
95 static const wxColor &Default_Color();
97 wxFontFamily GetFamily()
const;
98 wxFontEncoding GetEncoding()
const;
99 wxFontWeight GetWeight()
const;
100 bool IsBold()
const {
return GetWeight() == wxFONTWEIGHT_BOLD; }
101 bool IsLight()
const {
return GetWeight() == wxFONTWEIGHT_LIGHT; }
102 wxFontStyle GetFontStyle()
const;
103 bool IsItalic()
const {
return GetFontStyle() == wxFONTSTYLE_ITALIC; }
104 bool IsSlant()
const {
return GetFontStyle() == wxFONTSTYLE_SLANT; }
105 bool IsUnderlined()
const;
106 bool IsStrikethrough()
const;
107 const wxString &GetFontName()
const;
109 uint32_t GetRGBColor()
const;
110 wxColor GetColor()
const {
return wxColor(GetRGBColor()); }
112 using did_change = bool;
113 did_change SetFamily(wxFontFamily family);
114 did_change SetEncoding(wxFontEncoding encoding);
115 did_change SetWeight(wxFontWeight weight);
116 did_change SetBold(
bool bold =
true);
117 did_change SetLight(
bool light =
true);
118 did_change SetFontStyle(wxFontStyle style);
119 did_change SetItalic(
bool italic =
true);
120 did_change SetSlant(
bool slant =
true);
121 did_change SetUnderlined(
bool underlined =
true);
122 did_change SetStrikethrough(
bool strikethrough =
true);
123 did_change SetFontName(wxString fontName);
124 did_change SetFontSize(
AFontSize fontSize);
125 did_change SetRGBColor(uint32_t rgb);
126 did_change SetColor(
const wxColor &color);
127 did_change SetColor(wxSystemColour sysColour);
129 Style& Family(wxFontFamily family) {
return SetFamily(family), *
this; }
130 Style& Encoding(wxFontEncoding encoding) {
return SetEncoding(encoding), *
this; }
131 Style& Weight(wxFontWeight weight) {
return SetWeight(weight), *
this; }
132 Style& FontStyle(wxFontStyle style) {
return SetFontStyle(style), *
this; }
133 Style& Bold(
bool bold =
true) {
return SetBold(bold), *
this; }
134 Style& Light(
bool light =
true) {
return SetLight(light), *
this; }
135 Style& Italic(
bool italic =
true) {
return SetItalic(italic), *
this; }
136 Style& Slant(
bool slant =
true) {
return SetSlant(slant), *
this; }
137 Style& Underlined(
bool underlined =
true) {
return SetUnderlined(underlined), *
this; }
138 Style& Strikethrough(
bool strikethrough =
true) {
return SetStrikethrough(strikethrough), *
this; }
139 Style& FontSize(
float size) {
return SetFontSize(
AFontSize(size)), *
this; }
140 Style& FontSize(
AFontSize fontSize) {
return SetFontSize(fontSize), *
this; }
141 Style& RGBColor(uint32_t rgb) {
return SetRGBColor(rgb), *
this; }
142 Style& Color(
const wxColor &color) {
return SetColor(color), *
this; }
143 Style& Color(uint8_t r, uint8_t g, uint8_t b) {
return SetColor({r, g, b}), *
this; }
144 Style& Color(wxSystemColour sysColour) {
return SetColor(sysColour), *
this; }
145 Style& ChangeLightness(
int alpha) {
return SetColor(GetColor().ChangeLightness(alpha)), *
this; }
147 bool CantChangeFontName()
const {
return m.cantChangeFontName;}
148 bool CantChangeFontVariant()
const {
return m.cantChangeFontVariant;}
149 void CantChangeFontName(
bool changeForbidden) {m.cantChangeFontName = changeForbidden;}
150 void CantChangeFontVariant(
bool changeForbidden) {m.cantChangeFontVariant = changeForbidden;}
151 wxFontInfo GetAsFontInfo()
const;
154 bool IsFontOk()
const;
172 return wxCHECK_VERSION(3, 1, 2); }
176 static void SetFontSize(wxFont &,
AFontSize fontSize);
181 m.fontCache->ClearCache();
183 std::shared_ptr<FontVariantCache> GetFontCache()
const {
return m.fontCache;}
185 typedef std::unordered_map <wxString, std::shared_ptr<FontVariantCache>,
186 wxStringHash> FontVariantCachesMap;
189 static wxString m_emptyString;
191 static FontVariantCachesMap m_fontCaches;
202 mutable std::shared_ptr<FontVariantCache> fontCache;
204 uint32_t rgbColor = Default_ColorRGB;
213 bool strikethrough : 1;
214 bool cantChangeFontName : 1;
215 bool cantChangeFontVariant : 1;
217 Data() : underlined(false), strikethrough(false), cantChangeFontName(false),
218 cantChangeFontVariant(false) {}
248 TS_SPECIAL_CONSTANT ,
266 TS_DOCUMENT_BACKGROUND,
268 TS_ACTIVE_CELL_BRACKET,
This file implements the wxFont cache system.
std::ostream & operator<<(std::ostream &out, const TextStyle textstyle)
Allow Standard c++ streams to print out our enum values as text.
Definition: TextStyle.cpp:383
TextStyle
All text styles known to wxMaxima.
Definition: TextStyle.h:231
@ TS_INVALID
If a text style cannot be determined this value is used.
Definition: TextStyle.h:273
@ NUMBEROFSTYLES
This is not a style, but its value tells us how many styles are defined.
Definition: TextStyle.h:272
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:98
Text Style Definition.
Definition: TextStyle.h:63
static Style FromStockFont(wxStockGDI::Item font)
Gets a style that represents a stock font. The font is pre-cached.
Definition: TextStyle.cpp:354
void Write(wxConfigBase *config, const wxString &where) const
Write this style to a config source.
Definition: TextStyle.cpp:337
did_change SetFontFaceAndSizeFrom(const Style &)
Sets font-face and size only properties based on another style (not attributes like bold,...
Definition: TextStyle.cpp:223
did_change SetFontFaceFrom(const Style &)
Sets font-face-only properties based on another style.
Definition: TextStyle.cpp:217
void ClearCache() const
Empties the font variant cache.
Definition: TextStyle.h:178
AFontSize GetFontSize() const
The size of this style's font, asserted to be valid.
Definition: TextStyle.cpp:101
did_change SetFontFrom(const Style &)
Sets all font-related properties based on another style, including size, font style and weight.
Definition: TextStyle.cpp:209
did_change SetFromFont(const wxFont &)
Sets all font-related properties based on another font.
Definition: TextStyle.cpp:229
bool operator==(const Style &o) const
Compares.
static constexpr bool IsFractionalFontSizeSupported()
Old wxWidgets versions only support integers as font sizes.
Definition: TextStyle.h:171
static const Style & FromFont(const wxFont &font)
Gets a style that represents a given font. The font gets cached.
const wxFont & GetFont() const
Returns the font associated with this style.
Definition: TextStyle.h:158
Style & Read(wxConfigBase *config, const wxString &where)
Read this style from a config source.
Definition: TextStyle.cpp:300