]>
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, |
1a2fb4cd | 19 | false, false, false, false, caseMixed, true, true); |
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, |
1a2fb4cd | 25 | false, false, false, false, caseMixed, true, true); |
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; |
9ce192d4 | 37 | } |
88b780d9 | 38 | |
9ce192d4 | 39 | Style::~Style() { |
f6bcfd97 BP |
40 | if (aliasOfDefaultFont) |
41 | font.SetID(0); | |
42 | else | |
43 | font.Release(); | |
44 | aliasOfDefaultFont = false; | |
9ce192d4 RD |
45 | } |
46 | ||
47 | Style &Style::operator=(const Style &source) { | |
48 | if (this == &source) | |
65ec6247 | 49 | return * this; |
1a2fb4cd | 50 | Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff), |
65ec6247 | 51 | 0, 0, SC_CHARSET_DEFAULT, |
1a2fb4cd | 52 | false, false, false, false, caseMixed, true, true); |
9ce192d4 RD |
53 | fore.desired = source.fore.desired; |
54 | back.desired = source.back.desired; | |
f6bcfd97 | 55 | characterSet = source.characterSet; |
9ce192d4 RD |
56 | bold = source.bold; |
57 | italic = source.italic; | |
58 | size = source.size; | |
9ce192d4 | 59 | eolFilled = source.eolFilled; |
f6bcfd97 | 60 | underline = source.underline; |
65ec6247 RD |
61 | caseForce = source.caseForce; |
62 | visible = source.visible; | |
1a2fb4cd | 63 | changeable = source.changeable; |
9ce192d4 RD |
64 | return *this; |
65 | } | |
66 | ||
1a2fb4cd | 67 | void Style::Clear(ColourDesired fore_, ColourDesired back_, int size_, |
65ec6247 RD |
68 | const char *fontName_, int characterSet_, |
69 | bool bold_, bool italic_, bool eolFilled_, | |
1a2fb4cd RD |
70 | bool underline_, ecaseForced caseForce_, |
71 | bool visible_, bool changeable_) { | |
9ce192d4 RD |
72 | fore.desired = fore_; |
73 | back.desired = back_; | |
f6bcfd97 | 74 | characterSet = characterSet_; |
9ce192d4 RD |
75 | bold = bold_; |
76 | italic = italic_; | |
77 | size = size_; | |
f6bcfd97 | 78 | fontName = fontName_; |
9ce192d4 | 79 | eolFilled = eolFilled_; |
f6bcfd97 | 80 | underline = underline_; |
65ec6247 RD |
81 | caseForce = caseForce_; |
82 | visible = visible_; | |
1a2fb4cd | 83 | changeable = changeable_; |
f6bcfd97 BP |
84 | if (aliasOfDefaultFont) |
85 | font.SetID(0); | |
65ec6247 | 86 | else |
f6bcfd97 BP |
87 | font.Release(); |
88 | aliasOfDefaultFont = false; | |
9ce192d4 RD |
89 | } |
90 | ||
65ec6247 RD |
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, | |
1a2fb4cd RD |
103 | source.visible, |
104 | source.changeable); | |
65ec6247 RD |
105 | } |
106 | ||
f6bcfd97 BP |
107 | bool Style::EquivalentFontTo(const Style *other) const { |
108 | if (bold != other->bold || | |
65ec6247 RD |
109 | italic != other->italic || |
110 | size != other->size || | |
111 | characterSet != other->characterSet) | |
f6bcfd97 BP |
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) { | |
65ec6247 | 123 | sizeZoomed = size + zoomLevel; |
9ce192d4 RD |
124 | if (sizeZoomed <= 2) // Hangs if sizeZoomed <= 1 |
125 | sizeZoomed = 2; | |
f6bcfd97 BP |
126 | |
127 | if (aliasOfDefaultFont) | |
128 | font.SetID(0); | |
65ec6247 | 129 | else |
f6bcfd97 BP |
130 | font.Release(); |
131 | int deviceHeight = surface.DeviceHeightFont(sizeZoomed); | |
65ec6247 RD |
132 | aliasOfDefaultFont = defaultStyle && |
133 | (EquivalentFontTo(defaultStyle) || !fontName); | |
f6bcfd97 BP |
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 | } | |
9ce192d4 RD |
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 | } |