Commit | Line | Data |
---|---|---|
9ce192d4 | 1 | // Scintilla source code edit control |
65ec6247 RD |
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> | |
9ce192d4 RD |
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 | ||
f6bcfd97 | 12 | #include "Scintilla.h" |
9ce192d4 RD |
13 | #include "Style.h" |
14 | ||
7e0c58e9 RD |
15 | #ifdef SCI_NAMESPACE |
16 | using namespace Scintilla; | |
17 | #endif | |
18 | ||
1dcf666d RD |
19 | FontAlias::FontAlias() { |
20 | } | |
21 | ||
22 | FontAlias::~FontAlias() { | |
23 | SetID(0); | |
24 | // ~Font will not release the actual font resource sine it is now 0 | |
25 | } | |
26 | ||
27 | void FontAlias::MakeAlias(Font &fontOrigin) { | |
28 | SetID(fontOrigin.GetID()); | |
29 | } | |
30 | ||
31 | void FontAlias::ClearFont() { | |
32 | SetID(0); | |
33 | } | |
34 | ||
35 | 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 | ||
43 | FontMeasurements::FontMeasurements() { | |
44 | Clear(); | |
45 | } | |
46 | ||
47 | void FontMeasurements::Clear() { | |
48 | ascent = 1; | |
49 | descent = 1; | |
50 | aveCharWidth = 1; | |
51 | spaceWidth = 1; | |
52 | sizeZoomed = 2; | |
53 | } | |
54 | ||
55 | Style::Style() : FontSpecification() { | |
1a2fb4cd | 56 | Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), |
1dcf666d RD |
57 | Platform::DefaultFontSize() * SC_FONT_SIZE_MULTIPLIER, 0, SC_CHARSET_DEFAULT, |
58 | SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false); | |
f6bcfd97 | 59 | } |
65ec6247 | 60 | |
1dcf666d | 61 | Style::Style(const Style &source) : FontSpecification(), FontMeasurements() { |
1a2fb4cd | 62 | Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), |
65ec6247 | 63 | 0, 0, 0, |
1dcf666d RD |
64 | SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false); |
65 | fore = source.fore; | |
66 | back = source.back; | |
f6bcfd97 | 67 | characterSet = source.characterSet; |
1dcf666d | 68 | weight = source.weight; |
f6bcfd97 BP |
69 | italic = source.italic; |
70 | size = source.size; | |
71 | eolFilled = source.eolFilled; | |
72 | underline = source.underline; | |
65ec6247 RD |
73 | caseForce = source.caseForce; |
74 | visible = source.visible; | |
1a2fb4cd | 75 | changeable = source.changeable; |
9e730a78 | 76 | hotspot = source.hotspot; |
9ce192d4 | 77 | } |
88b780d9 | 78 | |
9ce192d4 | 79 | Style::~Style() { |
9ce192d4 RD |
80 | } |
81 | ||
82 | Style &Style::operator=(const Style &source) { | |
83 | if (this == &source) | |
65ec6247 | 84 | return * this; |
1a2fb4cd | 85 | Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), |
65ec6247 | 86 | 0, 0, SC_CHARSET_DEFAULT, |
1dcf666d RD |
87 | SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false); |
88 | fore = source.fore; | |
89 | back = source.back; | |
f6bcfd97 | 90 | characterSet = source.characterSet; |
1dcf666d | 91 | weight = source.weight; |
9ce192d4 RD |
92 | italic = source.italic; |
93 | size = source.size; | |
9ce192d4 | 94 | eolFilled = source.eolFilled; |
f6bcfd97 | 95 | underline = source.underline; |
65ec6247 RD |
96 | caseForce = source.caseForce; |
97 | visible = source.visible; | |
1a2fb4cd | 98 | changeable = source.changeable; |
9ce192d4 RD |
99 | return *this; |
100 | } | |
101 | ||
1a2fb4cd | 102 | void Style::Clear(ColourDesired fore_, ColourDesired back_, int size_, |
1dcf666d RD |
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_; | |
f6bcfd97 | 109 | characterSet = characterSet_; |
1dcf666d | 110 | weight = weight_; |
9ce192d4 RD |
111 | italic = italic_; |
112 | size = size_; | |
f6bcfd97 | 113 | fontName = fontName_; |
9ce192d4 | 114 | eolFilled = eolFilled_; |
f6bcfd97 | 115 | underline = underline_; |
65ec6247 RD |
116 | caseForce = caseForce_; |
117 | visible = visible_; | |
1a2fb4cd | 118 | changeable = changeable_; |
9e730a78 | 119 | hotspot = hotspot_; |
1dcf666d RD |
120 | font.ClearFont(); |
121 | FontMeasurements::Clear(); | |
9ce192d4 RD |
122 | } |
123 | ||
65ec6247 RD |
124 | void Style::ClearTo(const Style &source) { |
125 | Clear( | |
1dcf666d RD |
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); | |
f6bcfd97 BP |
139 | } |
140 | ||
1dcf666d RD |
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_; | |
9ce192d4 | 147 | } |