]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/Style.cxx
0a52ed41a3209184ca8a517c66ad99bbe1c89851
1 // Scintilla source code edit control
2 // Style.cxx - defines the font and colour style for a class of text
3 // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
10 #include "Scintilla.h"
14 aliasOfDefaultFont
= true;
15 Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
16 Platform::DefaultFontSize(), 0, SC_CHARSET_DEFAULT
,
17 false, false, false, false, true);
20 Style::Style(const Style
&source
) {
21 Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
23 false, false, false, false, true);
24 fore
.desired
= source
.fore
.desired
;
25 back
.desired
= source
.back
.desired
;
26 characterSet
= source
.characterSet
;
28 italic
= source
.italic
;
30 eolFilled
= source
.eolFilled
;
31 underline
= source
.underline
;
32 visible
= source
.visible
;
36 if (aliasOfDefaultFont
)
40 aliasOfDefaultFont
= false;
43 Style
&Style::operator=(const Style
&source
) {
46 Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
47 0, 0, SC_CHARSET_DEFAULT
,
48 false, false, false, false, true);
49 fore
.desired
= source
.fore
.desired
;
50 back
.desired
= source
.back
.desired
;
51 characterSet
= source
.characterSet
;
53 italic
= source
.italic
;
55 eolFilled
= source
.eolFilled
;
56 underline
= source
.underline
;
57 visible
= source
.visible
;
61 void Style::Clear(Colour fore_
, Colour back_
, int size_
,
62 const char *fontName_
, int characterSet_
,
63 bool bold_
, bool italic_
, bool eolFilled_
, bool underline_
, bool visible_
) {
66 characterSet
= characterSet_
;
71 eolFilled
= eolFilled_
;
72 underline
= underline_
;
74 if (aliasOfDefaultFont
)
78 aliasOfDefaultFont
= false;
81 bool Style::EquivalentFontTo(const Style
*other
) const {
82 if (bold
!= other
->bold
||
83 italic
!= other
->italic
||
84 size
!= other
->size
||
85 characterSet
!= other
->characterSet
)
87 if (fontName
== other
->fontName
)
93 return strcmp(fontName
, other
->fontName
) == 0;
96 void Style::Realise(Surface
&surface
, int zoomLevel
, Style
*defaultStyle
) {
97 int sizeZoomed
= size
+ zoomLevel
;
98 if (sizeZoomed
<= 2) // Hangs if sizeZoomed <= 1
101 if (aliasOfDefaultFont
)
105 int deviceHeight
= surface
.DeviceHeightFont(sizeZoomed
);
106 aliasOfDefaultFont
= defaultStyle
&&
107 (EquivalentFontTo(defaultStyle
) || !fontName
);
108 if (aliasOfDefaultFont
) {
109 font
.SetID(defaultStyle
->font
.GetID());
110 } else if (fontName
) {
111 font
.Create(fontName
, characterSet
, deviceHeight
, bold
, italic
);
116 ascent
= surface
.Ascent(font
);
117 descent
= surface
.Descent(font
);
118 // Probably more typographically correct to include leading
119 // but that means more complex drawing as leading must be erased
120 //lineHeight = surface.ExternalLeading() + surface.Height();
121 externalLeading
= surface
.ExternalLeading(font
);
122 lineHeight
= surface
.Height(font
);
123 aveCharWidth
= surface
.AverageCharWidth(font
);
124 spaceWidth
= surface
.WidthChar(font
, ' ');