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