]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/Style.cxx
4314dec0acff0d569dcc694b50d35a655383c4b1
[wxWidgets.git] / src / stc / scintilla / src / Style.cxx
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
19 Style::Style() {
20 aliasOfDefaultFont = true;
21 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
22 Platform::DefaultFontSize(), 0, SC_CHARSET_DEFAULT,
23 false, false, false, false, caseMixed, true, true, false);
24 }
25
26 Style::Style(const Style &source) {
27 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
28 0, 0, 0,
29 false, false, false, false, caseMixed, true, true, false);
30 fore.desired = source.fore.desired;
31 back.desired = source.back.desired;
32 characterSet = source.characterSet;
33 bold = source.bold;
34 italic = source.italic;
35 size = source.size;
36 eolFilled = source.eolFilled;
37 underline = source.underline;
38 caseForce = source.caseForce;
39 visible = source.visible;
40 changeable = source.changeable;
41 hotspot = source.hotspot;
42 }
43
44 Style::~Style() {
45 if (aliasOfDefaultFont)
46 font.SetID(0);
47 else
48 font.Release();
49 aliasOfDefaultFont = false;
50 }
51
52 Style &Style::operator=(const Style &source) {
53 if (this == &source)
54 return * this;
55 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
56 0, 0, SC_CHARSET_DEFAULT,
57 false, false, false, false, caseMixed, true, true, false);
58 fore.desired = source.fore.desired;
59 back.desired = source.back.desired;
60 characterSet = source.characterSet;
61 bold = source.bold;
62 italic = source.italic;
63 size = source.size;
64 eolFilled = source.eolFilled;
65 underline = source.underline;
66 caseForce = source.caseForce;
67 visible = source.visible;
68 changeable = source.changeable;
69 return *this;
70 }
71
72 void Style::Clear(ColourDesired fore_, ColourDesired back_, int size_,
73 const char *fontName_, int characterSet_,
74 bool bold_, bool italic_, bool eolFilled_,
75 bool underline_, ecaseForced caseForce_,
76 bool visible_, bool changeable_, bool hotspot_) {
77 fore.desired = fore_;
78 back.desired = back_;
79 characterSet = characterSet_;
80 bold = bold_;
81 italic = italic_;
82 size = size_;
83 fontName = fontName_;
84 eolFilled = eolFilled_;
85 underline = underline_;
86 caseForce = caseForce_;
87 visible = visible_;
88 changeable = changeable_;
89 hotspot = hotspot_;
90 if (aliasOfDefaultFont)
91 font.SetID(0);
92 else
93 font.Release();
94 aliasOfDefaultFont = false;
95 }
96
97 void Style::ClearTo(const Style &source) {
98 Clear(
99 source.fore.desired,
100 source.back.desired,
101 source.size,
102 source.fontName,
103 source.characterSet,
104 source.bold,
105 source.italic,
106 source.eolFilled,
107 source.underline,
108 source.caseForce,
109 source.visible,
110 source.changeable,
111 source.hotspot);
112 }
113
114 bool Style::EquivalentFontTo(const Style *other) const {
115 if (bold != other->bold ||
116 italic != other->italic ||
117 size != other->size ||
118 characterSet != other->characterSet)
119 return false;
120 if (fontName == other->fontName)
121 return true;
122 if (!fontName)
123 return false;
124 if (!other->fontName)
125 return false;
126 return strcmp(fontName, other->fontName) == 0;
127 }
128
129 void Style::Realise(Surface &surface, int zoomLevel, Style *defaultStyle, int extraFontFlag) {
130 sizeZoomed = size + zoomLevel;
131 if (sizeZoomed <= 2) // Hangs if sizeZoomed <= 1
132 sizeZoomed = 2;
133
134 if (aliasOfDefaultFont)
135 font.SetID(0);
136 else
137 font.Release();
138 int deviceHeight = surface.DeviceHeightFont(sizeZoomed);
139 aliasOfDefaultFont = defaultStyle &&
140 (EquivalentFontTo(defaultStyle) || !fontName);
141 if (aliasOfDefaultFont) {
142 font.SetID(defaultStyle->font.GetID());
143 } else if (fontName) {
144 font.Create(fontName, characterSet, deviceHeight, bold, italic, extraFontFlag);
145 } else {
146 font.SetID(0);
147 }
148
149 ascent = surface.Ascent(font);
150 descent = surface.Descent(font);
151 // Probably more typographically correct to include leading
152 // but that means more complex drawing as leading must be erased
153 //lineHeight = surface.ExternalLeading() + surface.Height();
154 externalLeading = surface.ExternalLeading(font);
155 lineHeight = surface.Height(font);
156 aveCharWidth = surface.AverageCharWidth(font);
157 spaceWidth = surface.WidthChar(font, ' ');
158 }