35#include <wx/hashmap.h>
40#include <wx/settings.h>
44#include "FontAttribs.h"
46#include <unordered_map>
49static constexpr uint32_t MAKE_RGB(uint32_t r, uint32_t g, uint32_t b)
50{
return (0xFF & r) | ((0xFF & g) << 8) | ((0xFF & b) << 16); }
80 Style &Read(wxConfigBase *config,
const wxString &where);
82 void Write(wxConfigBase *config,
const wxString &where)
const;
87 static Style FromStockFont(wxStockGDI::Item font);
89 constexpr static wxFontFamily Default_Family{wxFONTFAMILY_DEFAULT};
90 constexpr static wxFontEncoding Default_Encoding{wxFONTENCODING_DEFAULT};
91 constexpr static wxFontWeight Default_Weight{wxFONTWEIGHT_NORMAL};
92 constexpr static wxFontStyle Default_FontStyle{wxFONTSTYLE_NORMAL};
93 constexpr static bool Default_Underlined{
false};
94 constexpr static bool Default_Strikethrough{
false};
95 constexpr static AFontSize Default_FontSize{10.0f};
96 constexpr static uint32_t Default_ColorRGB{MAKE_RGB(0, 0, 0)};
97 static const wxColor &Default_Color();
99 wxFontFamily GetFamily()
const;
100 wxFontEncoding GetEncoding()
const;
101 wxFontWeight GetWeight()
const;
102 bool IsBold()
const {
return GetWeight() == wxFONTWEIGHT_BOLD; }
103 bool IsLight()
const {
return GetWeight() == wxFONTWEIGHT_LIGHT; }
104 wxFontStyle GetFontStyle()
const;
105 bool IsItalic()
const {
return GetFontStyle() == wxFONTSTYLE_ITALIC; }
106 bool IsSlant()
const {
return GetFontStyle() == wxFONTSTYLE_SLANT; }
107 bool IsUnderlined()
const;
108 bool IsStrikethrough()
const;
109 const wxString &GetFontName()
const;
111 uint32_t GetRGBColor()
const;
112 wxColor GetColor()
const {
return wxColor(GetRGBColor()); }
114 using did_change = bool;
115 did_change SetFamily(wxFontFamily family);
116 did_change SetEncoding(wxFontEncoding encoding);
117 did_change SetWeight(wxFontWeight weight);
118 did_change SetBold(
bool bold =
true);
119 did_change SetLight(
bool light =
true);
120 did_change SetFontStyle(wxFontStyle style);
121 did_change SetItalic(
bool italic =
true);
122 did_change SetSlant(
bool slant =
true);
123 did_change SetUnderlined(
bool underlined =
true);
124 did_change SetStrikethrough(
bool strikethrough =
true);
125 did_change SetFontName(wxString fontName);
126 did_change SetFontSize(
AFontSize fontSize);
127 did_change SetRGBColor(uint32_t rgb);
128 did_change SetColor(
const wxColor &color);
129 did_change SetColor(wxSystemColour sysColour);
131 Style& Family(wxFontFamily family) {
return SetFamily(family), *
this; }
132 Style& Encoding(wxFontEncoding encoding) {
return SetEncoding(encoding), *
this; }
133 Style& Weight(wxFontWeight weight) {
return SetWeight(weight), *
this; }
134 Style& FontStyle(wxFontStyle style) {
return SetFontStyle(style), *
this; }
135 Style& Bold(
bool bold =
true) {
return SetBold(bold), *
this; }
136 Style& Light(
bool light =
true) {
return SetLight(light), *
this; }
137 Style& Italic(
bool italic =
true) {
return SetItalic(italic), *
this; }
138 Style& Slant(
bool slant =
true) {
return SetSlant(slant), *
this; }
139 Style& Underlined(
bool underlined =
true) {
return SetUnderlined(underlined), *
this; }
140 Style& Strikethrough(
bool strikethrough =
true) {
return SetStrikethrough(strikethrough), *
this; }
141 Style& FontSize(
float size) {
return SetFontSize(
AFontSize(size)), *
this; }
142 Style& FontSize(
AFontSize fontSize) {
return SetFontSize(fontSize), *
this; }
143 Style& RGBColor(uint32_t rgb) {
return SetRGBColor(rgb), *
this; }
144 Style& Color(
const wxColor &color) {
return SetColor(color), *
this; }
145 Style& Color(uint8_t r, uint8_t g, uint8_t b) {
return SetColor({r, g, b}), *
this; }
146 Style& Color(wxSystemColour sysColour) {
return SetColor(sysColour), *
this; }
147 Style& ChangeLightness(
int alpha) {
return SetColor(GetColor().ChangeLightness(alpha)), *
this; }
149 bool CantChangeFontName()
const {
return m.cantChangeFontName;}
150 bool CantChangeFontVariant()
const {
return m.cantChangeFontVariant;}
151 void CantChangeFontName(
bool changeForbidden) {m.cantChangeFontName = changeForbidden;}
152 void CantChangeFontVariant(
bool changeForbidden) {m.cantChangeFontVariant = changeForbidden;}
153 wxFontInfo GetAsFontInfo()
const;
156 bool IsFontOk()
const;
158 const wxFont &GetFont(
AFontSize fontSize)
const;
161 return GetFont(GetFontSize());
165 did_change SetFromFont(
const wxFont&);
167 did_change SetFontFrom(
const Style&);
169 did_change SetFontFaceFrom(
const Style&);
171 did_change SetFontFaceAndSizeFrom(
const Style&);
173 static AFontSize GetFontSize(
const wxFont &);
175 static void SetFontSize(wxFont &,
AFontSize fontSize);
180 m.fontCache->ClearCache();
182 std::shared_ptr<FontVariantCache> GetFontCache()
const {
return m.fontCache;}
184 using FontVariantCachesMap =
185 std::unordered_map<wxString, std::shared_ptr<FontVariantCache>, wxStringHash>;
188 static wxString m_emptyString;
190 static FontVariantCachesMap m_fontCaches;
201 mutable std::shared_ptr<FontVariantCache> fontCache;
203 uint32_t rgbColor = Default_ColorRGB;
212 bool strikethrough : 1;
213 bool cantChangeFontName : 1;
214 bool cantChangeFontVariant : 1;
216 Data() : underlined(false), strikethrough(false), cantChangeFontName(false),
217 cantChangeFontVariant(false) {}
247 TS_SPECIAL_CONSTANT ,
265 TS_DOCUMENT_BACKGROUND,
267 TS_ACTIVE_CELL_BRACKET,
Small compatibility shims for older toolchains and older wxWidgets.
#define wxWARN_UNUSED
Marks a class whose unused instances are a bug.
Definition: Compat.h:116
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:382
TextStyle
All text styles known to wxMaxima.
Definition: TextStyle.h:230
@ TS_INVALID
If a text style cannot be determined this value is used.
Definition: TextStyle.h:274
@ NUMBEROFSTYLES
This is not a style, but its value tells us how many styles are defined.
Definition: TextStyle.h:273
@ TS_LINK
Links in text cells (GH #2396)
Definition: TextStyle.h:272
@ TS_DIFF_CHANGED
Background of text the diff viewer's counterpart cell lacks.
Definition: TextStyle.h:271
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:99
Text Style Definition.
Definition: TextStyle.h:67
void ClearCache() const
Empties the font variant cache.
Definition: TextStyle.h:177
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:160