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 bold == other.bold &&
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 	lineHeight = 2;
49 	ascent = 1;
50 	descent = 1;
51 	externalLeading = 0;
52 	aveCharWidth = 1;
53 	spaceWidth = 1;
54 	sizeZoomed = 2;
55 }
56 
Style()57 Style::Style() : FontSpecification() {
58 	Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
59 	      Platform::DefaultFontSize(), 0, SC_CHARSET_DEFAULT,
60 	      false, false, false, false, caseMixed, true, true, false);
61 }
62 
Style(const Style & source)63 Style::Style(const Style &source) : FontSpecification(), FontMeasurements() {
64 	Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
65 	      0, 0, 0,
66 	      false, false, false, false, caseMixed, true, true, false);
67 	fore.desired = source.fore.desired;
68 	back.desired = source.back.desired;
69 	characterSet = source.characterSet;
70 	bold = source.bold;
71 	italic = source.italic;
72 	size = source.size;
73 	eolFilled = source.eolFilled;
74 	underline = source.underline;
75 	caseForce = source.caseForce;
76 	visible = source.visible;
77 	changeable = source.changeable;
78 	hotspot = source.hotspot;
79 }
80 
~Style()81 Style::~Style() {
82 }
83 
operator =(const Style & source)84 Style &Style::operator=(const Style &source) {
85 	if (this == &source)
86 		return * this;
87 	Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
88 	      0, 0, SC_CHARSET_DEFAULT,
89 	      false, false, false, false, caseMixed, true, true, false);
90 	fore.desired = source.fore.desired;
91 	back.desired = source.back.desired;
92 	characterSet = source.characterSet;
93 	bold = source.bold;
94 	italic = source.italic;
95 	size = source.size;
96 	eolFilled = source.eolFilled;
97 	underline = source.underline;
98 	caseForce = source.caseForce;
99 	visible = source.visible;
100 	changeable = source.changeable;
101 	return *this;
102 }
103 
Clear(ColourDesired fore_,ColourDesired back_,int size_,const char * fontName_,int characterSet_,bool bold_,bool italic_,bool eolFilled_,bool underline_,ecaseForced caseForce_,bool visible_,bool changeable_,bool hotspot_)104 void Style::Clear(ColourDesired fore_, ColourDesired back_, int size_,
105         const char *fontName_, int characterSet_,
106         bool bold_, bool italic_, bool eolFilled_,
107         bool underline_, ecaseForced caseForce_,
108         bool visible_, bool changeable_, bool hotspot_) {
109 	fore.desired = fore_;
110 	back.desired = back_;
111 	characterSet = characterSet_;
112 	bold = bold_;
113 	italic = italic_;
114 	size = size_;
115 	fontName = fontName_;
116 	eolFilled = eolFilled_;
117 	underline = underline_;
118 	caseForce = caseForce_;
119 	visible = visible_;
120 	changeable = changeable_;
121 	hotspot = hotspot_;
122 	font.ClearFont();
123 	FontMeasurements::Clear();
124 }
125 
ClearTo(const Style & source)126 void Style::ClearTo(const Style &source) {
127 	Clear(
128 	    source.fore.desired,
129 	    source.back.desired,
130 	    source.size,
131 	    source.fontName,
132 	    source.characterSet,
133 	    source.bold,
134 	    source.italic,
135 	    source.eolFilled,
136 	    source.underline,
137 	    source.caseForce,
138 	    source.visible,
139 	    source.changeable,
140 	    source.hotspot);
141 }
142 
Copy(Font & font_,const FontMeasurements & fm_)143 void Style::Copy(Font &font_, const FontMeasurements &fm_) {
144 	font.MakeAlias(font_);
145 #if PLAT_WX
146 	font.SetAscent(fm_.ascent);
147 #endif
148 	(FontMeasurements &)(*this) = fm_;
149 }
150