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); }
82 Style &Read(wxConfigBase *config,
const wxString &where);
84 void Write(wxConfigBase *config,
const wxString &where)
const;
89 static Style FromStockFont(wxStockGDI::Item font);
91 constexpr static wxFontFamily Default_Family{wxFONTFAMILY_DEFAULT};
92 constexpr static wxFontEncoding Default_Encoding{wxFONTENCODING_DEFAULT};
93 constexpr static wxFontWeight Default_Weight{wxFONTWEIGHT_NORMAL};
94 constexpr static wxFontStyle Default_FontStyle{wxFONTSTYLE_NORMAL};
95 constexpr static bool Default_Underlined{
false};
96 constexpr static bool Default_Strikethrough{
false};
97 constexpr static AFontSize Default_FontSize{10.0f};
98 constexpr static uint32_t Default_ColorRGB{MAKE_RGB(0, 0, 0)};
99 static const wxColor &Default_Color();
101 wxFontFamily GetFamily()
const;
102 wxFontEncoding GetEncoding()
const;
103 wxFontWeight GetWeight()
const;
104 bool IsBold()
const {
return GetWeight() == wxFONTWEIGHT_BOLD; }
105 bool IsLight()
const {
return GetWeight() == wxFONTWEIGHT_LIGHT; }
106 wxFontStyle GetFontStyle()
const;
107 bool IsItalic()
const {
return GetFontStyle() == wxFONTSTYLE_ITALIC; }
108 bool IsSlant()
const {
return GetFontStyle() == wxFONTSTYLE_SLANT; }
109 bool IsUnderlined()
const;
110 bool IsStrikethrough()
const;
111 const wxString &GetFontName()
const;
113 uint32_t GetRGBColor()
const;
114 wxColor GetColor()
const {
return wxColor(GetRGBColor()); }
116 using did_change = bool;
117 did_change SetFamily(wxFontFamily family);
118 did_change SetEncoding(wxFontEncoding encoding);
119 did_change SetWeight(wxFontWeight weight);
120 did_change SetBold(
bool bold =
true);
121 did_change SetLight(
bool light =
true);
122 did_change SetFontStyle(wxFontStyle style);
123 did_change SetItalic(
bool italic =
true);
124 did_change SetSlant(
bool slant =
true);
125 did_change SetUnderlined(
bool underlined =
true);
126 did_change SetStrikethrough(
bool strikethrough =
true);
127 did_change SetFontName(wxString fontName);
128 did_change SetFontSize(
AFontSize fontSize);
129 did_change SetRGBColor(uint32_t rgb);
130 did_change SetColor(
const wxColor &color);
131 did_change SetColor(wxSystemColour sysColour);
133 Style& Family(wxFontFamily family) {
return SetFamily(family), *
this; }
134 Style& Encoding(wxFontEncoding encoding) {
return SetEncoding(encoding), *
this; }
135 Style& Weight(wxFontWeight weight) {
return SetWeight(weight), *
this; }
136 Style& FontStyle(wxFontStyle style) {
return SetFontStyle(style), *
this; }
137 Style& Bold(
bool bold =
true) {
return SetBold(bold), *
this; }
138 Style& Light(
bool light =
true) {
return SetLight(light), *
this; }
139 Style& Italic(
bool italic =
true) {
return SetItalic(italic), *
this; }
140 Style& Slant(
bool slant =
true) {
return SetSlant(slant), *
this; }
141 Style& Underlined(
bool underlined =
true) {
return SetUnderlined(underlined), *
this; }
142 Style& Strikethrough(
bool strikethrough =
true) {
return SetStrikethrough(strikethrough), *
this; }
143 Style& FontSize(
float size) {
return SetFontSize(
AFontSize(size)), *
this; }
144 Style& FontSize(
AFontSize fontSize) {
return SetFontSize(fontSize), *
this; }
145 Style& RGBColor(uint32_t rgb) {
return SetRGBColor(rgb), *
this; }
146 Style& Color(
const wxColor &color) {
return SetColor(color), *
this; }
147 Style& Color(uint8_t r, uint8_t g, uint8_t b) {
return SetColor({r, g, b}), *
this; }
148 Style& Color(wxSystemColour sysColour) {
return SetColor(sysColour), *
this; }
149 Style& ChangeLightness(
int alpha) {
return SetColor(GetColor().ChangeLightness(alpha)), *
this; }
151 bool CantChangeFontName()
const {
return m.cantChangeFontName;}
152 bool CantChangeFontVariant()
const {
return m.cantChangeFontVariant;}
153 void CantChangeFontName(
bool changeForbidden) {m.cantChangeFontName = changeForbidden;}
154 void CantChangeFontVariant(
bool changeForbidden) {m.cantChangeFontVariant = changeForbidden;}
155 wxFontInfo GetAsFontInfo()
const;
158 bool IsFontOk()
const;
160 const wxFont &GetFont(
AFontSize fontSize)
const;
163 return GetFont(GetFontSize());
167 did_change SetFromFont(
const wxFont&);
169 did_change SetFontFrom(
const Style&);
171 did_change SetFontFaceFrom(
const Style&);
173 did_change SetFontFaceAndSizeFrom(
const Style&);
176 return wxCHECK_VERSION(3, 1, 2); }
178 static AFontSize GetFontSize(
const wxFont &);
180 static void SetFontSize(wxFont &,
AFontSize fontSize);
185 m.fontCache->ClearCache();
187 std::shared_ptr<FontVariantCache> GetFontCache()
const {
return m.fontCache;}
189 typedef std::unordered_map <wxString, std::shared_ptr<FontVariantCache>,
190 wxStringHash> FontVariantCachesMap;
193 static wxString m_emptyString;
195 static FontVariantCachesMap m_fontCaches;
206 mutable std::shared_ptr<FontVariantCache> fontCache;
208 uint32_t rgbColor = Default_ColorRGB;
217 bool strikethrough : 1;
218 bool cantChangeFontName : 1;
219 bool cantChangeFontVariant : 1;
221 Data() : underlined(false), strikethrough(false), cantChangeFontName(false),
222 cantChangeFontVariant(false) {}
252 TS_SPECIAL_CONSTANT ,
270 TS_DOCUMENT_BACKGROUND,
272 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:399
TextStyle
All text styles known to wxMaxima.
Definition: TextStyle.h:235
@ TS_INVALID
If a text style cannot be determined this value is used.
Definition: TextStyle.h:278
@ NUMBEROFSTYLES
This is not a style, but its value tells us how many styles are defined.
Definition: TextStyle.h:277
@ TS_DIFF_CHANGED
Background of text the diff viewer's counterpart cell lacks.
Definition: TextStyle.h:276
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:182
bool operator==(const Style &o) const
Compares.
static constexpr bool IsFractionalFontSizeSupported()
Old wxWidgets versions only support integers as font sizes.
Definition: TextStyle.h:175
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:162