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