]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/Style.cxx
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, false);
22 Style::Style(const Style
&source
) {
23 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
25 false, false, false, false, caseMixed
, true, true, false);
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
;
37 hotspot
= source
.hotspot
;
41 if (aliasOfDefaultFont
)
45 aliasOfDefaultFont
= false;
48 Style
&Style::operator=(const Style
&source
) {
51 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
52 0, 0, SC_CHARSET_DEFAULT
,
53 false, false, false, false, caseMixed
, true, true, false);
54 fore
.desired
= source
.fore
.desired
;
55 back
.desired
= source
.back
.desired
;
56 characterSet
= source
.characterSet
;
58 italic
= source
.italic
;
60 eolFilled
= source
.eolFilled
;
61 underline
= source
.underline
;
62 caseForce
= source
.caseForce
;
63 visible
= source
.visible
;
64 changeable
= source
.changeable
;
68 void Style::Clear(ColourDesired fore_
, ColourDesired back_
, int size_
,
69 const char *fontName_
, int characterSet_
,
70 bool bold_
, bool italic_
, bool eolFilled_
,
71 bool underline_
, ecaseForced caseForce_
,
72 bool visible_
, bool changeable_
, bool hotspot_
) {
75 characterSet
= characterSet_
;
80 eolFilled
= eolFilled_
;
81 underline
= underline_
;
82 caseForce
= caseForce_
;
84 changeable
= changeable_
;
86 if (aliasOfDefaultFont
)
90 aliasOfDefaultFont
= false;
93 void Style::ClearTo(const Style
&source
) {
110 bool Style::EquivalentFontTo(const Style
*other
) const {
111 if (bold
!= other
->bold
||
112 italic
!= other
->italic
||
113 size
!= other
->size
||
114 characterSet
!= other
->characterSet
)
116 if (fontName
== other
->fontName
)
120 if (!other
->fontName
)
122 return strcmp(fontName
, other
->fontName
) == 0;
125 void Style::Realise(Surface
&surface
, int zoomLevel
, Style
*defaultStyle
, bool extraFontFlag
) {
126 sizeZoomed
= size
+ zoomLevel
;
127 if (sizeZoomed
<= 2) // Hangs if sizeZoomed <= 1
130 if (aliasOfDefaultFont
)
134 int deviceHeight
= surface
.DeviceHeightFont(sizeZoomed
);
135 aliasOfDefaultFont
= defaultStyle
&&
136 (EquivalentFontTo(defaultStyle
) || !fontName
);
137 if (aliasOfDefaultFont
) {
138 font
.SetID(defaultStyle
->font
.GetID());
139 } else if (fontName
) {
140 font
.Create(fontName
, characterSet
, deviceHeight
, bold
, italic
, extraFontFlag
);
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
, ' ');