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