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