repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / haikudepot / textview / CharacterStyleData.cpp
blob5f9ce2cae27223e0fa5139fdb1dba5bbd21dd113
1 /*
2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
6 #include "CharacterStyleData.h"
8 #include <new>
11 CharacterStyleData::CharacterStyleData()
13 fFont(),
15 fAscent(-1.0f),
16 fDescent(-1.0f),
17 fWidth(-1.0f),
19 fGlyphSpacing(0.0f),
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)
39 fFont(other.fFont),
41 fAscent(other.fAscent),
42 fDescent(other.fDescent),
43 fWidth(other.fWidth),
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)
63 bool
64 CharacterStyleData::operator==(const CharacterStyleData& other) const
66 if (this == &other)
67 return true;
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;
91 bool
92 CharacterStyleData::operator!=(const CharacterStyleData& other) const
94 return !(*this == other);
98 CharacterStyleDataRef
99 CharacterStyleData::SetFont(const BFont& font)
101 if (fFont == font)
102 return CharacterStyleDataRef(this);
104 CharacterStyleData* ret = new(std::nothrow) CharacterStyleData(*this);
105 if (ret == NULL)
106 return CharacterStyleDataRef(this);
108 ret->fFont = font;
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);
120 if (ret == NULL)
121 return CharacterStyleDataRef(this);
123 ret->fAscent = ascent;
124 return CharacterStyleDataRef(ret, true);
128 float
129 CharacterStyleData::Ascent() const
131 if (fAscent >= 0.0f)
132 return fAscent;
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);
147 if (ret == NULL)
148 return CharacterStyleDataRef(this);
150 ret->fDescent = descent;
151 return CharacterStyleDataRef(ret, true);
155 float
156 CharacterStyleData::Descent() const
158 if (fDescent >= 0.0f)
159 return fDescent;
161 font_height fontHeight;
162 fFont.GetHeight(&fontHeight);
163 return fontHeight.descent;
167 CharacterStyleDataRef
168 CharacterStyleData::SetWidth(float width)
170 if (fWidth == width)
171 return CharacterStyleDataRef(this);
173 CharacterStyleData* ret = new(std::nothrow) CharacterStyleData(*this);
174 if (ret == NULL)
175 return CharacterStyleDataRef(this);
177 ret->fWidth = width;
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);
189 if (ret == NULL)
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);
204 if (ret == NULL)
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);
219 if (ret == NULL)
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);
235 if (ret == NULL)
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);
250 if (ret == NULL)
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);
266 if (ret == NULL)
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);
281 if (ret == NULL)
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);
297 if (ret == NULL)
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);
312 if (ret == NULL)
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);
328 if (ret == NULL)
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);
343 if (ret == NULL)
344 return CharacterStyleDataRef(this);
346 ret->fUnderlineStyle = underline;
347 return CharacterStyleDataRef(ret, true);
351 // #pragma mark - private
354 CharacterStyleData&
355 CharacterStyleData::operator=(const CharacterStyleData& other)
357 return *this;