]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/Style.cxx
0a52ed41a3209184ca8a517c66ad99bbe1c89851
[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, true);
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, true);
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 visible = source.visible;
33 }
34
35 Style::~Style() {
36 if (aliasOfDefaultFont)
37 font.SetID(0);
38 else
39 font.Release();
40 aliasOfDefaultFont = false;
41 }
42
43 Style &Style::operator=(const Style &source) {
44 if (this == &source)
45 return *this;
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;
52 bold = source.bold;
53 italic = source.italic;
54 size = source.size;
55 eolFilled = source.eolFilled;
56 underline = source.underline;
57 visible = source.visible;
58 return *this;
59 }
60
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_) {
64 fore.desired = fore_;
65 back.desired = back_;
66 characterSet = characterSet_;
67 bold = bold_;
68 italic = italic_;
69 size = size_;
70 fontName = fontName_;
71 eolFilled = eolFilled_;
72 underline = underline_;
73 visible = visible_;
74 if (aliasOfDefaultFont)
75 font.SetID(0);
76 else
77 font.Release();
78 aliasOfDefaultFont = false;
79 }
80
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)
86 return false;
87 if (fontName == other->fontName)
88 return true;
89 if (!fontName)
90 return false;
91 if (!other->fontName)
92 return false;
93 return strcmp(fontName, other->fontName) == 0;
94 }
95
96 void Style::Realise(Surface &surface, int zoomLevel, Style *defaultStyle) {
97 int sizeZoomed = size + zoomLevel;
98 if (sizeZoomed <= 2) // Hangs if sizeZoomed <= 1
99 sizeZoomed = 2;
100
101 if (aliasOfDefaultFont)
102 font.SetID(0);
103 else
104 font.Release();
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);
112 } else {
113 font.SetID(0);
114 }
115
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, ' ');
125 }