r5116 | eht16 | 2010-08-05 22:13:47 +0100 (Thu, 05 Aug 2010) | 3 lines
[geany-mirror.git] / scintilla / Style.cxx
blob392fd1c9aab88e7533673e60c2c35bb7d3d1aca7
1 // Scintilla source code edit control
2 /** @file Style.cxx
3 ** Defines the font and colour style for a class of text.
4 **/
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.
8 #include <string.h>
10 #include "Platform.h"
12 #include "Scintilla.h"
13 #include "Style.h"
15 #ifdef SCI_NAMESPACE
16 using namespace Scintilla;
17 #endif
19 Style::Style() {
20 aliasOfDefaultFont = true;
21 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
22 Platform::DefaultFontSize(), 0, SC_CHARSET_DEFAULT,
23 false, false, false, false, caseMixed, true, true, false);
26 Style::Style(const Style &source) {
27 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
28 0, 0, 0,
29 false, false, false, false, caseMixed, true, true, false);
30 fore.desired = source.fore.desired;
31 back.desired = source.back.desired;
32 characterSet = source.characterSet;
33 bold = source.bold;
34 italic = source.italic;
35 size = source.size;
36 eolFilled = source.eolFilled;
37 underline = source.underline;
38 caseForce = source.caseForce;
39 visible = source.visible;
40 changeable = source.changeable;
41 hotspot = source.hotspot;
44 Style::~Style() {
45 if (aliasOfDefaultFont)
46 font.SetID(0);
47 else
48 font.Release();
49 aliasOfDefaultFont = false;
52 Style &Style::operator=(const Style &source) {
53 if (this == &source)
54 return * this;
55 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
56 0, 0, SC_CHARSET_DEFAULT,
57 false, false, false, false, caseMixed, true, true, false);
58 fore.desired = source.fore.desired;
59 back.desired = source.back.desired;
60 characterSet = source.characterSet;
61 bold = source.bold;
62 italic = source.italic;
63 size = source.size;
64 eolFilled = source.eolFilled;
65 underline = source.underline;
66 caseForce = source.caseForce;
67 visible = source.visible;
68 changeable = source.changeable;
69 return *this;
72 void Style::Clear(ColourDesired fore_, ColourDesired back_, int size_,
73 const char *fontName_, int characterSet_,
74 bool bold_, bool italic_, bool eolFilled_,
75 bool underline_, ecaseForced caseForce_,
76 bool visible_, bool changeable_, bool hotspot_) {
77 fore.desired = fore_;
78 back.desired = back_;
79 characterSet = characterSet_;
80 bold = bold_;
81 italic = italic_;
82 size = size_;
83 fontName = fontName_;
84 eolFilled = eolFilled_;
85 underline = underline_;
86 caseForce = caseForce_;
87 visible = visible_;
88 changeable = changeable_;
89 hotspot = hotspot_;
90 if (aliasOfDefaultFont)
91 font.SetID(0);
92 else
93 font.Release();
94 aliasOfDefaultFont = false;
95 sizeZoomed = 2;
96 lineHeight = 2;
97 ascent = 1;
98 descent = 1;
99 externalLeading = 0;
100 aveCharWidth = 1;
101 spaceWidth = 1;
104 void Style::ClearTo(const Style &source) {
105 Clear(
106 source.fore.desired,
107 source.back.desired,
108 source.size,
109 source.fontName,
110 source.characterSet,
111 source.bold,
112 source.italic,
113 source.eolFilled,
114 source.underline,
115 source.caseForce,
116 source.visible,
117 source.changeable,
118 source.hotspot);
121 bool Style::EquivalentFontTo(const Style *other) const {
122 if (bold != other->bold ||
123 italic != other->italic ||
124 size != other->size ||
125 characterSet != other->characterSet)
126 return false;
127 if (fontName == other->fontName)
128 return true;
129 if (!fontName)
130 return false;
131 if (!other->fontName)
132 return false;
133 return strcmp(fontName, other->fontName) == 0;
136 void Style::Realise(Surface &surface, int zoomLevel, Style *defaultStyle, int extraFontFlag) {
137 sizeZoomed = size + zoomLevel;
138 if (sizeZoomed <= 2) // Hangs if sizeZoomed <= 1
139 sizeZoomed = 2;
141 if (aliasOfDefaultFont)
142 font.SetID(0);
143 else
144 font.Release();
145 int deviceHeight = surface.DeviceHeightFont(sizeZoomed);
146 aliasOfDefaultFont = defaultStyle &&
147 (EquivalentFontTo(defaultStyle) || !fontName);
148 if (aliasOfDefaultFont) {
149 font.SetID(defaultStyle->font.GetID());
150 } else if (fontName) {
151 font.Create(fontName, characterSet, deviceHeight, bold, italic, extraFontFlag);
152 } else {
153 font.SetID(0);
156 ascent = surface.Ascent(font);
157 descent = surface.Descent(font);
158 // Probably more typographically correct to include leading
159 // but that means more complex drawing as leading must be erased
160 //lineHeight = surface.ExternalLeading() + surface.Height();
161 externalLeading = surface.ExternalLeading(font);
162 lineHeight = surface.Height(font);
163 aveCharWidth = surface.AverageCharWidth(font);
164 spaceWidth = surface.WidthChar(font, ' ');