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