1 // Scintilla source code edit control
2 /** @file Style.cxx
3 ** Defines the font and colour style for a class of text.
4 **/
5 // Copyright 1998-2001 by Neil Hodgson <[email protected]>
6 // The License.txt file describes the conditions under which this software may be distributed.
7
8 #include <stdexcept>
9 #include <string_view>
10 #include <vector>
11 #include <memory>
12
13 #include "Platform.h"
14
15 #include "Scintilla.h"
16 #include "Style.h"
17
18 using namespace Scintilla;
19
FontAlias()20 FontAlias::FontAlias() noexcept {
21 }
22
FontAlias(const FontAlias & other)23 FontAlias::FontAlias(const FontAlias &other) noexcept : Font() {
24 SetID(other.fid);
25 }
26
FontAlias(FontAlias && other)27 FontAlias::FontAlias(FontAlias &&other) noexcept : Font() {
28 SetID(other.fid);
29 other.ClearFont();
30 }
31
~FontAlias()32 FontAlias::~FontAlias() {
33 SetID(FontID{});
34 // ~Font will not release the actual font resource since it is now 0
35 }
36
MakeAlias(const Font & fontOrigin)37 void FontAlias::MakeAlias(const Font &fontOrigin) noexcept {
38 SetID(fontOrigin.GetID());
39 }
40
ClearFont()41 void FontAlias::ClearFont() noexcept {
42 SetID(FontID{});
43 }
44
operator ==(const FontSpecification & other) const45 bool FontSpecification::operator==(const FontSpecification &other) const noexcept {
46 return fontName == other.fontName &&
47 weight == other.weight &&
48 italic == other.italic &&
49 size == other.size &&
50 characterSet == other.characterSet &&
51 extraFontFlag == other.extraFontFlag;
52 }
53
operator <(const FontSpecification & other) const54 bool FontSpecification::operator<(const FontSpecification &other) const noexcept {
55 if (fontName != other.fontName)
56 return fontName < other.fontName;
57 if (weight != other.weight)
58 return weight < other.weight;
59 if (italic != other.italic)
60 return italic == false;
61 if (size != other.size)
62 return size < other.size;
63 if (characterSet != other.characterSet)
64 return characterSet < other.characterSet;
65 if (extraFontFlag != other.extraFontFlag)
66 return extraFontFlag < other.extraFontFlag;
67 return false;
68 }
69
FontMeasurements()70 FontMeasurements::FontMeasurements() noexcept {
71 ClearMeasurements();
72 }
73
ClearMeasurements()74 void FontMeasurements::ClearMeasurements() noexcept {
75 ascent = 1;
76 descent = 1;
77 capitalHeight = 1;
78 aveCharWidth = 1;
79 spaceWidth = 1;
80 sizeZoomed = 2;
81 }
82
Style()83 Style::Style() : FontSpecification() {
84 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
85 Platform::DefaultFontSize() * SC_FONT_SIZE_MULTIPLIER, nullptr, SC_CHARSET_DEFAULT,
86 SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false);
87 }
88
Style(const Style & source)89 Style::Style(const Style &source) noexcept : FontSpecification(), FontMeasurements() {
90 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
91 0, nullptr, 0,
92 SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false);
93 fore = source.fore;
94 back = source.back;
95 characterSet = source.characterSet;
96 weight = source.weight;
97 italic = source.italic;
98 size = source.size;
99 fontName = source.fontName;
100 eolFilled = source.eolFilled;
101 underline = source.underline;
102 caseForce = source.caseForce;
103 visible = source.visible;
104 changeable = source.changeable;
105 hotspot = source.hotspot;
106 }
107
~Style()108 Style::~Style() {
109 }
110
operator =(const Style & source)111 Style &Style::operator=(const Style &source) noexcept {
112 if (this == &source)
113 return * this;
114 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
115 0, nullptr, SC_CHARSET_DEFAULT,
116 SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false);
117 fore = source.fore;
118 back = source.back;
119 characterSet = source.characterSet;
120 weight = source.weight;
121 italic = source.italic;
122 size = source.size;
123 fontName = source.fontName;
124 eolFilled = source.eolFilled;
125 underline = source.underline;
126 caseForce = source.caseForce;
127 visible = source.visible;
128 changeable = source.changeable;
129 return *this;
130 }
131
Clear(ColourDesired fore_,ColourDesired back_,int size_,const char * fontName_,int characterSet_,int weight_,bool italic_,bool eolFilled_,bool underline_,ecaseForced caseForce_,bool visible_,bool changeable_,bool hotspot_)132 void Style::Clear(ColourDesired fore_, ColourDesired back_, int size_,
133 const char *fontName_, int characterSet_,
134 int weight_, bool italic_, bool eolFilled_,
135 bool underline_, ecaseForced caseForce_,
136 bool visible_, bool changeable_, bool hotspot_) noexcept {
137 fore = fore_;
138 back = back_;
139 characterSet = characterSet_;
140 weight = weight_;
141 italic = italic_;
142 size = size_;
143 fontName = fontName_;
144 eolFilled = eolFilled_;
145 underline = underline_;
146 caseForce = caseForce_;
147 visible = visible_;
148 changeable = changeable_;
149 hotspot = hotspot_;
150 font.ClearFont();
151 FontMeasurements::ClearMeasurements();
152 }
153
ClearTo(const Style & source)154 void Style::ClearTo(const Style &source) noexcept {
155 Clear(
156 source.fore,
157 source.back,
158 source.size,
159 source.fontName,
160 source.characterSet,
161 source.weight,
162 source.italic,
163 source.eolFilled,
164 source.underline,
165 source.caseForce,
166 source.visible,
167 source.changeable,
168 source.hotspot);
169 }
170
Copy(const Font & font_,const FontMeasurements & fm_)171 void Style::Copy(const Font &font_, const FontMeasurements &fm_) noexcept {
172 font.MakeAlias(font_);
173 (FontMeasurements &)(*this) = fm_;
174 }
175