xref: /MusicPlayer2/scintilla/src/Style.cxx (revision 8af74909132ed5e696cb05b6689ae4baf14c1c96)
1*8af74909SZhong Yang // Scintilla source code edit control
2*8af74909SZhong Yang /** @file Style.cxx
3*8af74909SZhong Yang  ** Defines the font and colour style for a class of text.
4*8af74909SZhong Yang  **/
5*8af74909SZhong Yang // Copyright 1998-2001 by Neil Hodgson <[email protected]>
6*8af74909SZhong Yang // The License.txt file describes the conditions under which this software may be distributed.
7*8af74909SZhong Yang 
8*8af74909SZhong Yang #include <stdexcept>
9*8af74909SZhong Yang #include <string_view>
10*8af74909SZhong Yang #include <vector>
11*8af74909SZhong Yang #include <memory>
12*8af74909SZhong Yang 
13*8af74909SZhong Yang #include "Platform.h"
14*8af74909SZhong Yang 
15*8af74909SZhong Yang #include "Scintilla.h"
16*8af74909SZhong Yang #include "Style.h"
17*8af74909SZhong Yang 
18*8af74909SZhong Yang using namespace Scintilla;
19*8af74909SZhong Yang 
FontAlias()20*8af74909SZhong Yang FontAlias::FontAlias() noexcept {
21*8af74909SZhong Yang }
22*8af74909SZhong Yang 
FontAlias(const FontAlias & other)23*8af74909SZhong Yang FontAlias::FontAlias(const FontAlias &other) noexcept : Font() {
24*8af74909SZhong Yang 	SetID(other.fid);
25*8af74909SZhong Yang }
26*8af74909SZhong Yang 
FontAlias(FontAlias && other)27*8af74909SZhong Yang FontAlias::FontAlias(FontAlias &&other) noexcept : Font() {
28*8af74909SZhong Yang 	SetID(other.fid);
29*8af74909SZhong Yang 	other.ClearFont();
30*8af74909SZhong Yang }
31*8af74909SZhong Yang 
~FontAlias()32*8af74909SZhong Yang FontAlias::~FontAlias() {
33*8af74909SZhong Yang 	SetID(FontID{});
34*8af74909SZhong Yang 	// ~Font will not release the actual font resource since it is now 0
35*8af74909SZhong Yang }
36*8af74909SZhong Yang 
MakeAlias(const Font & fontOrigin)37*8af74909SZhong Yang void FontAlias::MakeAlias(const Font &fontOrigin) noexcept {
38*8af74909SZhong Yang 	SetID(fontOrigin.GetID());
39*8af74909SZhong Yang }
40*8af74909SZhong Yang 
ClearFont()41*8af74909SZhong Yang void FontAlias::ClearFont() noexcept {
42*8af74909SZhong Yang 	SetID(FontID{});
43*8af74909SZhong Yang }
44*8af74909SZhong Yang 
operator ==(const FontSpecification & other) const45*8af74909SZhong Yang bool FontSpecification::operator==(const FontSpecification &other) const noexcept {
46*8af74909SZhong Yang 	return fontName == other.fontName &&
47*8af74909SZhong Yang 	       weight == other.weight &&
48*8af74909SZhong Yang 	       italic == other.italic &&
49*8af74909SZhong Yang 	       size == other.size &&
50*8af74909SZhong Yang 	       characterSet == other.characterSet &&
51*8af74909SZhong Yang 	       extraFontFlag == other.extraFontFlag;
52*8af74909SZhong Yang }
53*8af74909SZhong Yang 
operator <(const FontSpecification & other) const54*8af74909SZhong Yang bool FontSpecification::operator<(const FontSpecification &other) const noexcept {
55*8af74909SZhong Yang 	if (fontName != other.fontName)
56*8af74909SZhong Yang 		return fontName < other.fontName;
57*8af74909SZhong Yang 	if (weight != other.weight)
58*8af74909SZhong Yang 		return weight < other.weight;
59*8af74909SZhong Yang 	if (italic != other.italic)
60*8af74909SZhong Yang 		return italic == false;
61*8af74909SZhong Yang 	if (size != other.size)
62*8af74909SZhong Yang 		return size < other.size;
63*8af74909SZhong Yang 	if (characterSet != other.characterSet)
64*8af74909SZhong Yang 		return characterSet < other.characterSet;
65*8af74909SZhong Yang 	if (extraFontFlag != other.extraFontFlag)
66*8af74909SZhong Yang 		return extraFontFlag < other.extraFontFlag;
67*8af74909SZhong Yang 	return false;
68*8af74909SZhong Yang }
69*8af74909SZhong Yang 
FontMeasurements()70*8af74909SZhong Yang FontMeasurements::FontMeasurements() noexcept {
71*8af74909SZhong Yang 	ClearMeasurements();
72*8af74909SZhong Yang }
73*8af74909SZhong Yang 
ClearMeasurements()74*8af74909SZhong Yang void FontMeasurements::ClearMeasurements() noexcept {
75*8af74909SZhong Yang 	ascent = 1;
76*8af74909SZhong Yang 	descent = 1;
77*8af74909SZhong Yang 	capitalHeight = 1;
78*8af74909SZhong Yang 	aveCharWidth = 1;
79*8af74909SZhong Yang 	spaceWidth = 1;
80*8af74909SZhong Yang 	sizeZoomed = 2;
81*8af74909SZhong Yang }
82*8af74909SZhong Yang 
Style()83*8af74909SZhong Yang Style::Style() : FontSpecification() {
84*8af74909SZhong Yang 	Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
85*8af74909SZhong Yang 	      Platform::DefaultFontSize() * SC_FONT_SIZE_MULTIPLIER, nullptr, SC_CHARSET_DEFAULT,
86*8af74909SZhong Yang 	      SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false);
87*8af74909SZhong Yang }
88*8af74909SZhong Yang 
Style(const Style & source)89*8af74909SZhong Yang Style::Style(const Style &source) noexcept : FontSpecification(), FontMeasurements() {
90*8af74909SZhong Yang 	Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
91*8af74909SZhong Yang 	      0, nullptr, 0,
92*8af74909SZhong Yang 	      SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false);
93*8af74909SZhong Yang 	fore = source.fore;
94*8af74909SZhong Yang 	back = source.back;
95*8af74909SZhong Yang 	characterSet = source.characterSet;
96*8af74909SZhong Yang 	weight = source.weight;
97*8af74909SZhong Yang 	italic = source.italic;
98*8af74909SZhong Yang 	size = source.size;
99*8af74909SZhong Yang 	fontName = source.fontName;
100*8af74909SZhong Yang 	eolFilled = source.eolFilled;
101*8af74909SZhong Yang 	underline = source.underline;
102*8af74909SZhong Yang 	caseForce = source.caseForce;
103*8af74909SZhong Yang 	visible = source.visible;
104*8af74909SZhong Yang 	changeable = source.changeable;
105*8af74909SZhong Yang 	hotspot = source.hotspot;
106*8af74909SZhong Yang }
107*8af74909SZhong Yang 
~Style()108*8af74909SZhong Yang Style::~Style() {
109*8af74909SZhong Yang }
110*8af74909SZhong Yang 
operator =(const Style & source)111*8af74909SZhong Yang Style &Style::operator=(const Style &source) noexcept {
112*8af74909SZhong Yang 	if (this == &source)
113*8af74909SZhong Yang 		return * this;
114*8af74909SZhong Yang 	Clear(ColourDesired(0, 0, 0), ColourDesired(0xff, 0xff, 0xff),
115*8af74909SZhong Yang 	      0, nullptr, SC_CHARSET_DEFAULT,
116*8af74909SZhong Yang 	      SC_WEIGHT_NORMAL, false, false, false, caseMixed, true, true, false);
117*8af74909SZhong Yang 	fore = source.fore;
118*8af74909SZhong Yang 	back = source.back;
119*8af74909SZhong Yang 	characterSet = source.characterSet;
120*8af74909SZhong Yang 	weight = source.weight;
121*8af74909SZhong Yang 	italic = source.italic;
122*8af74909SZhong Yang 	size = source.size;
123*8af74909SZhong Yang 	fontName = source.fontName;
124*8af74909SZhong Yang 	eolFilled = source.eolFilled;
125*8af74909SZhong Yang 	underline = source.underline;
126*8af74909SZhong Yang 	caseForce = source.caseForce;
127*8af74909SZhong Yang 	visible = source.visible;
128*8af74909SZhong Yang 	changeable = source.changeable;
129*8af74909SZhong Yang 	return *this;
130*8af74909SZhong Yang }
131*8af74909SZhong Yang 
Clear(ColourDesired fore_,ColourDesired back_,int size_,const char * fontName_,int characterSet_,int weight_,bool italic_,bool eolFilled_,bool underline_,ecaseForced caseForce_,bool visible_,bool changeable_,bool hotspot_)132*8af74909SZhong Yang void Style::Clear(ColourDesired fore_, ColourDesired back_, int size_,
133*8af74909SZhong Yang         const char *fontName_, int characterSet_,
134*8af74909SZhong Yang         int weight_, bool italic_, bool eolFilled_,
135*8af74909SZhong Yang         bool underline_, ecaseForced caseForce_,
136*8af74909SZhong Yang         bool visible_, bool changeable_, bool hotspot_) noexcept {
137*8af74909SZhong Yang 	fore = fore_;
138*8af74909SZhong Yang 	back = back_;
139*8af74909SZhong Yang 	characterSet = characterSet_;
140*8af74909SZhong Yang 	weight = weight_;
141*8af74909SZhong Yang 	italic = italic_;
142*8af74909SZhong Yang 	size = size_;
143*8af74909SZhong Yang 	fontName = fontName_;
144*8af74909SZhong Yang 	eolFilled = eolFilled_;
145*8af74909SZhong Yang 	underline = underline_;
146*8af74909SZhong Yang 	caseForce = caseForce_;
147*8af74909SZhong Yang 	visible = visible_;
148*8af74909SZhong Yang 	changeable = changeable_;
149*8af74909SZhong Yang 	hotspot = hotspot_;
150*8af74909SZhong Yang 	font.ClearFont();
151*8af74909SZhong Yang 	FontMeasurements::ClearMeasurements();
152*8af74909SZhong Yang }
153*8af74909SZhong Yang 
ClearTo(const Style & source)154*8af74909SZhong Yang void Style::ClearTo(const Style &source) noexcept {
155*8af74909SZhong Yang 	Clear(
156*8af74909SZhong Yang 	    source.fore,
157*8af74909SZhong Yang 	    source.back,
158*8af74909SZhong Yang 	    source.size,
159*8af74909SZhong Yang 	    source.fontName,
160*8af74909SZhong Yang 	    source.characterSet,
161*8af74909SZhong Yang 	    source.weight,
162*8af74909SZhong Yang 	    source.italic,
163*8af74909SZhong Yang 	    source.eolFilled,
164*8af74909SZhong Yang 	    source.underline,
165*8af74909SZhong Yang 	    source.caseForce,
166*8af74909SZhong Yang 	    source.visible,
167*8af74909SZhong Yang 	    source.changeable,
168*8af74909SZhong Yang 	    source.hotspot);
169*8af74909SZhong Yang }
170*8af74909SZhong Yang 
Copy(const Font & font_,const FontMeasurements & fm_)171*8af74909SZhong Yang void Style::Copy(const Font &font_, const FontMeasurements &fm_) noexcept {
172*8af74909SZhong Yang 	font.MakeAlias(font_);
173*8af74909SZhong Yang 	(FontMeasurements &)(*this) = fm_;
174*8af74909SZhong Yang }
175