]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/Style.cxx
7aa44c0eb991a5a7e55c53ff59453e0881f3adbf
[wxWidgets.git] / contrib / src / stc / scintilla / src / Style.cxx
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.
5
6 #include <string.h>
7
8 #include "Platform.h"
9
10 #include "Scintilla.h"
11 #include "Style.h"
12
13 Style::Style() {
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);
18 }
19
20 Style::Style(const Style &source) {
21 Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
22 0, 0, 0,
23 false, false, false, false);
24 fore.desired = source.fore.desired;
25 back.desired = source.back.desired;
26 characterSet = source.characterSet;
27 bold = source.bold;
28 italic = source.italic;
29 size = source.size;
30 eolFilled = source.eolFilled;
31 underline = source.underline;
32 }
33
34 Style::~Style() {
35 if (aliasOfDefaultFont)
36 font.SetID(0);
37 else
38 font.Release();
39 aliasOfDefaultFont = false;
40 }
41
42 Style &Style::operator=(const Style &source) {
43 if (this == &source)
44 return *this;
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;
51 bold = source.bold;
52 italic = source.italic;
53 size = source.size;
54 eolFilled = source.eolFilled;
55 underline = source.underline;
56 return *this;
57 }
58
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_) {
62 fore.desired = fore_;
63 back.desired = back_;
64 characterSet = characterSet_;
65 bold = bold_;
66 italic = italic_;
67 size = size_;
68 fontName = fontName_;
69 eolFilled = eolFilled_;
70 underline = underline_;
71 if (aliasOfDefaultFont)
72 font.SetID(0);
73 else
74 font.Release();
75 aliasOfDefaultFont = false;
76 }
77
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)
83 return false;
84 if (fontName == other->fontName)
85 return true;
86 if (!fontName)
87 return false;
88 if (!other->fontName)
89 return false;
90 return strcmp(fontName, other->fontName) == 0;
91 }
92
93 void Style::Realise(Surface &surface, int zoomLevel, Style *defaultStyle) {
94 int sizeZoomed = size + zoomLevel;
95 if (sizeZoomed <= 2) // Hangs if sizeZoomed <= 1
96 sizeZoomed = 2;
97
98 if (aliasOfDefaultFont)
99 font.SetID(0);
100 else
101 font.Release();
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);
109 } else {
110 font.SetID(0);
111 }
112
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, ' ');
122 }