33 #include <wx/colour.h>
34 #include <wx/config.h>
36 #include <wx/settings.h>
39 #include "FontAttribs.h"
64 explicit AFontName(
const wxString &fontName) : m_fontName(Intern(fontName)) {}
66 operator const wxString &()
const {
return GetAsString(); }
67 bool operator==(
const AFontName &o)
const {
return m_fontName == o.m_fontName; }
68 bool operator<(
const AFontName &o)
const {
return m_fontName < o.m_fontName; }
69 bool empty()
const {
return !m_fontName || m_fontName->empty(); }
72 m_fontName = o.m_fontName;
77 m_fontName = Intern(str);
80 const wxString& GetAsString()
const {
return m_fontName ? *m_fontName : *GetInternedEmpty(); }
84 static AFontName Linux_Libertine_O() {
static auto n = AFN(wxT(
"Linux Libertine O"));
return n; }
85 static AFontName Linux_Libertine_G() {
static auto n = AFN(wxT(
"Linux Libertine G"));
return n; }
86 static AFontName Linux_Libertine() {
static auto n = AFN(wxT(
"Linux Libertine"));
return n; }
87 static AFontName Times_New_Roman() {
static auto n = AFN(wxT(
"Times New Roman"));
return n; }
88 static AFontName Monaco() {
static auto n = AFN(wxT(
"Monaco"));
return n; }
89 static AFontName Arial() {
static auto n = AFN(wxT(
"Arial"));
return n; }
90 static AFontName Symbol() {
static auto n = AFN(wxT(
"Symbol"));
return n; }
91 static AFontName CMEX10() {
static auto n = AFN(wxT(
"jsMath-cmex10"));
return n; }
92 static AFontName CMSY10() {
static auto n = AFN(wxT(
"jsMath-cmsy10"));
return n; }
93 static AFontName CMR10() {
static auto n = AFN(wxT(
"jsMath-cmr10"));
return n; }
94 static AFontName CMMI10() {
static auto n = AFN(wxT(
"jsMath-cmmi10"));
return n; }
95 static AFontName CMTI10() {
static auto n = AFN(wxT(
"jsMath-cmti10"));
return n; }
100 const wxString *m_fontName = {};
102 static const wxString *Intern(
const wxString &str);
103 static const wxString *GetInternedEmpty();
111 return hash<const void*>()(name.m_fontName);
117 static constexpr uint32_t MAKE_RGB(uint32_t r, uint32_t g, uint32_t b)
118 {
return (0xFF & r) | ((0xFF & g) << 8) | ((0xFF & b) << 16); }
138 bool operator==(
const Style &o)
const =
delete;
144 Style &
Read(wxConfigBase *config,
const wxString &where);
146 void Write(wxConfigBase *config,
const wxString &where)
const;
153 constexpr
static wxFontFamily Default_Family{wxFONTFAMILY_DEFAULT};
154 constexpr
static wxFontEncoding Default_Encoding{wxFONTENCODING_DEFAULT};
155 constexpr
static wxFontWeight Default_Weight{wxFONTWEIGHT_NORMAL};
156 constexpr
static wxFontStyle Default_FontStyle{wxFONTSTYLE_NORMAL};
157 constexpr
static bool Default_Underlined{
false};
158 constexpr
static bool Default_Strikethrough{
false};
159 constexpr
static AFontSize Default_FontSize{10.0f};
160 constexpr
static uint32_t Default_ColorRGB{MAKE_RGB(0, 0, 0)};
162 static const wxColor &Default_Color();
164 wxFontFamily GetFamily()
const;
165 wxFontEncoding GetEncoding()
const;
166 wxFontWeight GetWeight()
const;
167 bool IsBold()
const {
return GetWeight() == wxFONTWEIGHT_BOLD; }
168 bool IsLight()
const {
return GetWeight() == wxFONTWEIGHT_LIGHT; }
169 wxFontStyle GetFontStyle()
const;
170 bool IsItalic()
const {
return GetFontStyle() == wxFONTSTYLE_ITALIC; }
171 bool IsSlant()
const {
return GetFontStyle() == wxFONTSTYLE_SLANT; }
172 bool IsUnderlined()
const;
173 bool IsStrikethrough()
const;
175 const wxString &GetNameStr()
const;
177 uint32_t GetRGBColor()
const;
178 wxColor GetColor()
const {
return wxColor(GetRGBColor()); }
180 using did_change = bool;
181 did_change SetFamily(wxFontFamily family);
182 did_change SetEncoding(wxFontEncoding encoding);
183 did_change SetWeight(wxFontWeight weight);
184 did_change SetBold(
bool bold =
true);
185 did_change SetLight(
bool light =
true);
186 did_change SetFontStyle(wxFontStyle style);
187 did_change SetItalic(
bool italic =
true);
188 did_change SetSlant(
bool slant =
true);
189 did_change SetUnderlined(
bool underlined =
true);
190 did_change SetStrikethrough(
bool strikethrough =
true);
191 did_change SetFontName(
AFontName fontName);
192 did_change SetFontSize(
AFontSize fontSize);
193 did_change SetRGBColor(uint32_t rgb);
194 did_change SetColor(
const wxColor &color);
195 did_change SetColor(wxSystemColour sysColour);
200 Style& Family(wxFontFamily family) {
return SetFamily(family), *
this; }
201 Style& Encoding(wxFontEncoding encoding) {
return SetEncoding(encoding), *
this; }
202 Style& Weight(wxFontWeight weight) {
return SetWeight(weight), *
this; }
203 Style& FontStyle(wxFontStyle style) {
return SetFontStyle(style), *
this; }
204 Style& Bold(
bool bold =
true) {
return SetBold(bold), *
this; }
205 Style& Light(
bool light =
true) {
return SetLight(light), *
this; }
206 Style& Italic(
bool italic =
true) {
return SetItalic(italic), *
this; }
207 Style& Slant(
bool slant =
true) {
return SetSlant(slant), *
this; }
208 Style& Underlined(
bool underlined =
true) {
return SetUnderlined(underlined), *
this; }
209 Style& Strikethrough(
bool strikethrough =
true) {
return SetStrikethrough(strikethrough), *
this; }
210 Style& FontName(
class AFontName fontName) {
return SetFontName(fontName), *
this; }
211 Style& FontSize(
float size) {
return SetFontSize(
AFontSize(size)), *
this; }
212 Style& FontSize(
AFontSize fontSize) {
return SetFontSize(fontSize), *
this; }
213 Style& RGBColor(uint32_t rgb) {
return SetRGBColor(rgb), *
this; }
214 Style& Color(
const wxColor &color) {
return SetColor(color), *
this; }
215 Style& Color(uint8_t r, uint8_t g, uint8_t b) {
return SetColor({r, g, b}), *
this; }
216 Style& Color(wxSystemColour sysColour) {
return SetColor(sysColour), *
this; }
217 Style& ChangeLightness(
int alpha) {
return SetColor(GetColor().ChangeLightness(alpha)), *
this; }
219 wxFontInfo GetAsFontInfo()
const;
221 bool IsFontLessThan(
const Style &o)
const {
return GetFontHash() < o.GetFontHash(); }
222 bool IsFontEqualTo(
const Style &)
const;
223 bool IsStyleEqualTo(
const Style &o)
const;
225 bool IsFontOk()
const;
226 bool HasFontCached()
const {
return m.fontHash && m.font; }
227 const wxFont& GetFont()
const {
return HasFontCached() ? *m.font : LookupFont(); }
238 constexpr
static bool IsFractionalFontSizeSupported() {
return wxCHECK_VERSION(3,1,2); }
240 static void SetFontSize(wxFont &,
AFontSize fontSize);
242 wxString GetDump()
const;
247 Style &FromFontNoCache(
const wxFont &);
248 void SetFromFontNoCache(
const wxFont &);
254 mutable const wxFont *font =
nullptr;
255 mutable size_t fontHash = 0;
257 uint32_t rgbColor = Default_ColorRGB;
266 bool strikethrough : 1;
269 Data() : underlined(
false), strikethrough(
false), isNotOK(
false) {}
270 static constexpr
enum class NotOK_t {} NotOK = {};
272 Data(NotOK_t) : underlined(
false), strikethrough(
false), isNotOK(
true) {}
274 static_assert(
sizeof(Data) <= 40,
275 "Style::Data is misaligned and grew too big.");
277 size_t GetFontHash()
const;
279 const wxFont& LookupFont()
const;
281 Style(Data::NotOK_t) : m(Data::NotOK) {}
287 size_t operator()(
const Style &style)
const {
return style.GetFontHash(); }
293 bool operator()(
const Style &l,
const Style &r)
const {
return l.IsFontLessThan(r); }
299 bool operator()(
const Style &l,
const Style &r)
const {
return l.IsFontEqualTo(r); }
313 TS_SPECIAL_CONSTANT = 4,
314 TS_GREEK_CONSTANT = 5,
328 TS_SUBSUBSECTION = 19,
332 TS_TEXT_BACKGROUND = 23,
333 TS_DOCUMENT_BACKGROUND = 24,
334 TS_CELL_BRACKET = 25,
335 TS_ACTIVE_CELL_BRACKET = 26,
338 TS_EQUALSSELECTION = 29,
340 TS_CODE_VARIABLE = 31,
341 TS_CODE_FUNCTION = 32,
342 TS_CODE_COMMENT = 33,
345 TS_CODE_OPERATOR = 36,
347 TS_CODE_ENDOFLINE = 38,
352 #endif // TEXTSTYLE_H