*** empty log message ***
[anjuta-git-plugin.git] / scintilla / Style.cxx
blobf01aee0826c820e8b9db9d069379abfe8507a4f1
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 Style::Style() {
16 aliasOfDefaultFont = true;
17 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
18 Platform::DefaultFontSize(), 0, SC_CHARSET_DEFAULT,
19 false, false, false, false, caseMixed, true, true, false);
22 Style::Style(const Style &source) {
23 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
24 0, 0, 0,
25 false, false, false, false, caseMixed, true, true, false);
26 fore.desired = source.fore.desired;
27 back.desired = source.back.desired;
28 characterSet = source.characterSet;
29 bold = source.bold;
30 italic = source.italic;
31 size = source.size;
32 eolFilled = source.eolFilled;
33 underline = source.underline;
34 caseForce = source.caseForce;
35 visible = source.visible;
36 changeable = source.changeable;
37 hotspot = source.hotspot;
40 Style::~Style() {
41 if (aliasOfDefaultFont)
42 font.SetID(0);
43 else
44 font.Release();
45 aliasOfDefaultFont = false;
48 Style &Style::operator=(const Style &source) {
49 if (this == &source)
50 return * this;
51 Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
52 0, 0, SC_CHARSET_DEFAULT,
53 false, false, false, false, caseMixed, true, true, false);
54 fore.desired = source.fore.desired;
55 back.desired = source.back.desired;
56 characterSet = source.characterSet;
57 bold = source.bold;
58 italic = source.italic;
59 size = source.size;
60 eolFilled = source.eolFilled;
61 underline = source.underline;
62 caseForce = source.caseForce;
63 visible = source.visible;
64 changeable = source.changeable;
65 return *this;
68 void Style::Clear(ColourDesired fore_, ColourDesired back_, int size_,
69 const char *fontName_, int characterSet_,
70 bool bold_, bool italic_, bool eolFilled_,
71 bool underline_, ecaseForced caseForce_,
72 bool visible_, bool changeable_, bool hotspot_) {
73 fore.desired = fore_;
74 back.desired = back_;
75 characterSet = characterSet_;
76 bold = bold_;
77 italic = italic_;
78 size = size_;
79 fontName = fontName_;
80 eolFilled = eolFilled_;
81 underline = underline_;
82 caseForce = caseForce_;
83 visible = visible_;
84 changeable = changeable_;
85 hotspot = hotspot_;
86 if (aliasOfDefaultFont)
87 font.SetID(0);
88 else
89 font.Release();
90 aliasOfDefaultFont = false;
93 void Style::ClearTo(const Style &source) {
94 Clear(
95 source.fore.desired,
96 source.back.desired,
97 source.size,
98 source.fontName,
99 source.characterSet,
100 source.bold,
101 source.italic,
102 source.eolFilled,
103 source.underline,
104 source.caseForce,
105 source.visible,
106 source.changeable,
107 source.hotspot);
110 bool Style::EquivalentFontTo(const Style *other) const {
111 if (bold != other->bold ||
112 italic != other->italic ||
113 size != other->size ||
114 characterSet != other->characterSet)
115 return false;
116 if (fontName == other->fontName)
117 return true;
118 if (!fontName)
119 return false;
120 if (!other->fontName)
121 return false;
122 return strcmp(fontName, other->fontName) == 0;
125 void Style::Realise(Surface &surface, int zoomLevel, Style *defaultStyle, bool extraFontFlag) {
126 sizeZoomed = size + zoomLevel;
127 if (sizeZoomed <= 2) // Hangs if sizeZoomed <= 1
128 sizeZoomed = 2;
130 if (aliasOfDefaultFont)
131 font.SetID(0);
132 else
133 font.Release();
134 int deviceHeight = surface.DeviceHeightFont(sizeZoomed);
135 aliasOfDefaultFont = defaultStyle &&
136 (EquivalentFontTo(defaultStyle) || !fontName);
137 if (aliasOfDefaultFont) {
138 font.SetID(defaultStyle->font.GetID());
139 } else if (fontName) {
140 font.Create(fontName, characterSet, deviceHeight, bold, italic, extraFontFlag);
141 } else {
142 font.SetID(0);
145 ascent = surface.Ascent(font);
146 descent = surface.Descent(font);
147 // Probably more typographically correct to include leading
148 // but that means more complex drawing as leading must be erased
149 //lineHeight = surface.ExternalLeading() + surface.Height();
150 externalLeading = surface.ExternalLeading(font);
151 lineHeight = surface.Height(font);
152 aveCharWidth = surface.AverageCharWidth(font);
153 spaceWidth = surface.WidthChar(font, ' ');