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