2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
6 #include "CharacterStyleData.h"
11 CharacterStyleData::CharacterStyleData()
21 fWhichFgColor(B_PANEL_TEXT_COLOR
),
22 fWhichBgColor(B_PANEL_BACKGROUND_COLOR
),
23 fWhichStrikeOutColor(fWhichFgColor
),
24 fWhichUnderlineColor(fWhichFgColor
),
26 fFgColor(ui_color(fWhichFgColor
)),
27 fBgColor(ui_color(fWhichBgColor
)),
28 fStrikeOutColor(fFgColor
),
29 fUnderlineColor(fFgColor
),
31 fStrikeOutStyle(STRIKE_OUT_NONE
),
32 fUnderlineStyle(UNDERLINE_NONE
)
37 CharacterStyleData::CharacterStyleData(const CharacterStyleData
& other
)
41 fAscent(other
.fAscent
),
42 fDescent(other
.fDescent
),
45 fGlyphSpacing(other
.fGlyphSpacing
),
47 fWhichFgColor(other
.fWhichFgColor
),
48 fWhichBgColor(other
.fWhichBgColor
),
49 fWhichStrikeOutColor(other
.fWhichStrikeOutColor
),
50 fWhichUnderlineColor(other
.fWhichUnderlineColor
),
52 fFgColor(other
.fFgColor
),
53 fBgColor(other
.fBgColor
),
54 fStrikeOutColor(other
.fStrikeOutColor
),
55 fUnderlineColor(other
.fUnderlineColor
),
57 fStrikeOutStyle(other
.fStrikeOutStyle
),
58 fUnderlineStyle(other
.fUnderlineStyle
)
64 CharacterStyleData::operator==(const CharacterStyleData
& other
) const
69 return fFont
== other
.fFont
70 && fAscent
== other
.fAscent
71 && fDescent
== other
.fDescent
72 && fWidth
== other
.fWidth
74 && fGlyphSpacing
== other
.fGlyphSpacing
76 && fWhichFgColor
== other
.fWhichFgColor
77 && fWhichBgColor
== other
.fWhichBgColor
78 && fWhichStrikeOutColor
== other
.fWhichStrikeOutColor
79 && fWhichUnderlineColor
== other
.fWhichUnderlineColor
81 && fFgColor
== other
.fFgColor
82 && fBgColor
== other
.fBgColor
83 && fStrikeOutColor
== other
.fStrikeOutColor
84 && fUnderlineColor
== other
.fUnderlineColor
86 && fStrikeOutStyle
== other
.fStrikeOutStyle
87 && fUnderlineStyle
== other
.fUnderlineStyle
;
92 CharacterStyleData::operator!=(const CharacterStyleData
& other
) const
94 return !(*this == other
);
99 CharacterStyleData::SetFont(const BFont
& font
)
102 return CharacterStyleDataRef(this);
104 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
106 return CharacterStyleDataRef(this);
109 return CharacterStyleDataRef(ret
, true);
113 CharacterStyleDataRef
114 CharacterStyleData::SetAscent(float ascent
)
116 if (fAscent
== ascent
)
117 return CharacterStyleDataRef(this);
119 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
121 return CharacterStyleDataRef(this);
123 ret
->fAscent
= ascent
;
124 return CharacterStyleDataRef(ret
, true);
129 CharacterStyleData::Ascent() const
134 font_height fontHeight
;
135 fFont
.GetHeight(&fontHeight
);
136 return fontHeight
.ascent
;
140 CharacterStyleDataRef
141 CharacterStyleData::SetDescent(float descent
)
143 if (fDescent
== descent
)
144 return CharacterStyleDataRef(this);
146 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
148 return CharacterStyleDataRef(this);
150 ret
->fDescent
= descent
;
151 return CharacterStyleDataRef(ret
, true);
156 CharacterStyleData::Descent() const
158 if (fDescent
>= 0.0f
)
161 font_height fontHeight
;
162 fFont
.GetHeight(&fontHeight
);
163 return fontHeight
.descent
;
167 CharacterStyleDataRef
168 CharacterStyleData::SetWidth(float width
)
171 return CharacterStyleDataRef(this);
173 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
175 return CharacterStyleDataRef(this);
178 return CharacterStyleDataRef(ret
, true);
182 CharacterStyleDataRef
183 CharacterStyleData::SetGlyphSpacing(float glyphSpacing
)
185 if (fGlyphSpacing
== glyphSpacing
)
186 return CharacterStyleDataRef(this);
188 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
190 return CharacterStyleDataRef(this);
192 ret
->fGlyphSpacing
= glyphSpacing
;
193 return CharacterStyleDataRef(ret
, true);
197 CharacterStyleDataRef
198 CharacterStyleData::SetForegroundColor(color_which which
)
200 if (fWhichFgColor
== which
)
201 return CharacterStyleDataRef(this);
203 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
205 return CharacterStyleDataRef(this);
207 ret
->fWhichFgColor
= which
;
208 return CharacterStyleDataRef(ret
, true);
212 CharacterStyleDataRef
213 CharacterStyleData::SetForegroundColor(rgb_color color
)
215 if (fFgColor
== color
)
216 return CharacterStyleDataRef(this);
218 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
220 return CharacterStyleDataRef(this);
222 ret
->fFgColor
= color
;
223 ret
->fWhichFgColor
= B_NO_COLOR
;
224 return CharacterStyleDataRef(ret
, true);
228 CharacterStyleDataRef
229 CharacterStyleData::SetBackgroundColor(color_which which
)
231 if (fWhichBgColor
== which
)
232 return CharacterStyleDataRef(this);
234 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
236 return CharacterStyleDataRef(this);
238 ret
->fWhichBgColor
= which
;
239 return CharacterStyleDataRef(ret
, true);
243 CharacterStyleDataRef
244 CharacterStyleData::SetBackgroundColor(rgb_color color
)
246 if (fBgColor
== color
)
247 return CharacterStyleDataRef(this);
249 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
251 return CharacterStyleDataRef(this);
253 ret
->fBgColor
= color
;
254 ret
->fWhichBgColor
= B_NO_COLOR
;
255 return CharacterStyleDataRef(ret
, true);
259 CharacterStyleDataRef
260 CharacterStyleData::SetStrikeOutColor(color_which which
)
262 if (fWhichStrikeOutColor
== which
)
263 return CharacterStyleDataRef(this);
265 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
267 return CharacterStyleDataRef(this);
269 ret
->fWhichStrikeOutColor
= which
;
270 return CharacterStyleDataRef(ret
, true);
274 CharacterStyleDataRef
275 CharacterStyleData::SetStrikeOutColor(rgb_color color
)
277 if (fStrikeOutColor
== color
)
278 return CharacterStyleDataRef(this);
280 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
282 return CharacterStyleDataRef(this);
284 ret
->fStrikeOutColor
= color
;
285 ret
->fWhichStrikeOutColor
= B_NO_COLOR
;
286 return CharacterStyleDataRef(ret
, true);
290 CharacterStyleDataRef
291 CharacterStyleData::SetUnderlineColor(color_which which
)
293 if (fWhichUnderlineColor
== which
)
294 return CharacterStyleDataRef(this);
296 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
298 return CharacterStyleDataRef(this);
300 ret
->fWhichUnderlineColor
= which
;
301 return CharacterStyleDataRef(ret
, true);
305 CharacterStyleDataRef
306 CharacterStyleData::SetUnderlineColor(rgb_color color
)
308 if (fUnderlineColor
== color
)
309 return CharacterStyleDataRef(this);
311 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
313 return CharacterStyleDataRef(this);
315 ret
->fUnderlineColor
= color
;
316 ret
->fWhichUnderlineColor
= B_NO_COLOR
;
317 return CharacterStyleDataRef(ret
, true);
321 CharacterStyleDataRef
322 CharacterStyleData::SetStrikeOut(uint8 strikeOut
)
324 if (fStrikeOutStyle
== strikeOut
)
325 return CharacterStyleDataRef(this);
327 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
329 return CharacterStyleDataRef(this);
331 ret
->fStrikeOutStyle
= strikeOut
;
332 return CharacterStyleDataRef(ret
, true);
336 CharacterStyleDataRef
337 CharacterStyleData::SetUnderline(uint8 underline
)
339 if (fUnderlineStyle
== underline
)
340 return CharacterStyleDataRef(this);
342 CharacterStyleData
* ret
= new(std::nothrow
) CharacterStyleData(*this);
344 return CharacterStyleDataRef(this);
346 ret
->fUnderlineStyle
= underline
;
347 return CharacterStyleDataRef(ret
, true);
351 // #pragma mark - private
355 CharacterStyleData::operator=(const CharacterStyleData
& other
)