]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/Style.cxx
48302332164e6b46cdbae3b243ee916299149e55
[wxWidgets.git] / 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 "Style.h"
11
12 Style::Style() {
13 aliasOfDefaultFont = true;
14 Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
15 Platform::DefaultFontSize(), 0,
16 false, false, false);
17 }
18
19 Style::~Style() {
20 if (aliasOfDefaultFont)
21 font.SetID(0);
22 else
23 font.Release();
24 aliasOfDefaultFont = false;
25 }
26
27 Style &Style::operator=(const Style &source) {
28 if (this == &source)
29 return *this;
30 Clear(Colour(0,0,0), Colour(0xff,0xff,0xff),
31 0, 0,
32 false, false, false);
33 fore.desired = source.fore.desired;
34 back.desired = source.back.desired;
35 bold = source.bold;
36 italic = source.italic;
37 size = source.size;
38 eolFilled = source.eolFilled;
39 return *this;
40 }
41
42 void Style::Clear(Colour fore_, Colour back_, int size_, const char *fontName_,
43 bool bold_, bool italic_, bool eolFilled_) {
44 fore.desired = fore_;
45 back.desired = back_;
46 bold = bold_;
47 italic = italic_;
48 size = size_;
49 fontName = fontName_;
50 eolFilled = eolFilled_;
51 if (aliasOfDefaultFont)
52 font.SetID(0);
53 else
54 font.Release();
55 aliasOfDefaultFont = false;
56 }
57
58 bool Style::EquivalentFontTo(const Style *other) const {
59 if (bold != other->bold ||
60 italic != other->italic ||
61 size != other->size)
62 return false;
63 if (fontName == other->fontName)
64 return true;
65 if (!fontName)
66 return false;
67 if (!other->fontName)
68 return false;
69 return strcmp(fontName, other->fontName) == 0;
70 }
71
72 void Style::Realise(Surface &surface, int zoomLevel, Style *defaultStyle) {
73 int sizeZoomed = size + zoomLevel;
74 if (sizeZoomed <= 2) // Hangs if sizeZoomed <= 1
75 sizeZoomed = 2;
76
77 if (aliasOfDefaultFont)
78 font.SetID(0);
79 else
80 font.Release();
81 int deviceHeight = (sizeZoomed * surface.LogPixelsY()) / 72;
82 aliasOfDefaultFont = defaultStyle &&
83 (EquivalentFontTo(defaultStyle) || !fontName);
84 if (aliasOfDefaultFont) {
85 font.SetID(defaultStyle->font.GetID());
86 } else if (fontName) {
87 font.Create(fontName, deviceHeight, bold, italic);
88 } else {
89 font.SetID(0);
90 }
91
92 ascent = surface.Ascent(font);
93 descent = surface.Descent(font);
94 // Probably more typographically correct to include leading
95 // but that means more complex drawing as leading must be erased
96 //lineHeight = surface.ExternalLeading() + surface.Height();
97 externalLeading = surface.ExternalLeading(font);
98 lineHeight = surface.Height(font);
99 aveCharWidth = surface.AverageCharWidth(font);
100 spaceWidth = surface.WidthChar(font, ' ');
101 }