]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/Style.cxx
2ee09f57d27745227b286be46e27675c7dfa81a1
1 // Scintilla source code edit control
3 ** Defines the font and colour style for a class of text.
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.
12 #include "Scintilla.h"
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);
22 Style::Style(const Style
&source
) {
23 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
25 false, false, false, false, caseMixed
, true, true);
26 fore
.desired
= source
.fore
.desired
;
27 back
.desired
= source
.back
.desired
;
28 characterSet
= source
.characterSet
;
30 italic
= source
.italic
;
32 eolFilled
= source
.eolFilled
;
33 underline
= source
.underline
;
34 caseForce
= source
.caseForce
;
35 visible
= source
.visible
;
36 changeable
= source
.changeable
;
40 if (aliasOfDefaultFont
)
44 aliasOfDefaultFont
= false;
47 Style
&Style::operator=(const Style
&source
) {
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
;
57 italic
= source
.italic
;
59 eolFilled
= source
.eolFilled
;
60 underline
= source
.underline
;
61 caseForce
= source
.caseForce
;
62 visible
= source
.visible
;
63 changeable
= source
.changeable
;
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_
) {
74 characterSet
= characterSet_
;
79 eolFilled
= eolFilled_
;
80 underline
= underline_
;
81 caseForce
= caseForce_
;
83 changeable
= changeable_
;
84 if (aliasOfDefaultFont
)
88 aliasOfDefaultFont
= false;
91 void Style::ClearTo(const Style
&source
) {
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
)
113 if (fontName
== other
->fontName
)
117 if (!other
->fontName
)
119 return strcmp(fontName
, other
->fontName
) == 0;
122 void Style::Realise(Surface
&surface
, int zoomLevel
, Style
*defaultStyle
) {
123 sizeZoomed
= size
+ zoomLevel
;
124 if (sizeZoomed
<= 2) // Hangs if sizeZoomed <= 1
127 if (aliasOfDefaultFont
)
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
);
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
, ' ');