]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/Style.cxx
7aa44c0eb991a5a7e55c53ff59453e0881f3adbf
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);
20 Style::Style(const Style
&source
) {
21 Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
23 false, false, false, false);
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
;
35 if (aliasOfDefaultFont
)
39 aliasOfDefaultFont
= false;
42 Style
&Style::operator=(const Style
&source
) {
45 Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
46 0, 0, SC_CHARSET_DEFAULT
,
47 false, false, false, false);
48 fore
.desired
= source
.fore
.desired
;
49 back
.desired
= source
.back
.desired
;
50 characterSet
= source
.characterSet
;
52 italic
= source
.italic
;
54 eolFilled
= source
.eolFilled
;
55 underline
= source
.underline
;
59 void Style::Clear(Colour fore_
, Colour back_
, int size_
,
60 const char *fontName_
, int characterSet_
,
61 bool bold_
, bool italic_
, bool eolFilled_
, bool underline_
) {
64 characterSet
= characterSet_
;
69 eolFilled
= eolFilled_
;
70 underline
= underline_
;
71 if (aliasOfDefaultFont
)
75 aliasOfDefaultFont
= false;
78 bool Style::EquivalentFontTo(const Style
*other
) const {
79 if (bold
!= other
->bold
||
80 italic
!= other
->italic
||
81 size
!= other
->size
||
82 characterSet
!= other
->characterSet
)
84 if (fontName
== other
->fontName
)
90 return strcmp(fontName
, other
->fontName
) == 0;
93 void Style::Realise(Surface
&surface
, int zoomLevel
, Style
*defaultStyle
) {
94 int sizeZoomed
= size
+ zoomLevel
;
95 if (sizeZoomed
<= 2) // Hangs if sizeZoomed <= 1
98 if (aliasOfDefaultFont
)
102 int deviceHeight
= surface
.DeviceHeightFont(sizeZoomed
);
103 aliasOfDefaultFont
= defaultStyle
&&
104 (EquivalentFontTo(defaultStyle
) || !fontName
);
105 if (aliasOfDefaultFont
) {
106 font
.SetID(defaultStyle
->font
.GetID());
107 } else if (fontName
) {
108 font
.Create(fontName
, characterSet
, deviceHeight
, bold
, italic
);
113 ascent
= surface
.Ascent(font
);
114 descent
= surface
.Descent(font
);
115 // Probably more typographically correct to include leading
116 // but that means more complex drawing as leading must be erased
117 //lineHeight = surface.ExternalLeading() + surface.Height();
118 externalLeading
= surface
.ExternalLeading(font
);
119 lineHeight
= surface
.Height(font
);
120 aveCharWidth
= surface
.AverageCharWidth(font
);
121 spaceWidth
= surface
.WidthChar(font
, ' ');