1 /* 2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef CHARACTER_STYLE_DATA_H 6 #define CHARACTER_STYLE_DATA_H 7 8 #include <Font.h> 9 #include <Referenceable.h> 10 11 12 enum { 13 STRIKE_OUT_NONE = 0, 14 STRIKE_OUT_SINGLE = 1, 15 }; 16 17 18 enum { 19 UNDERLINE_NONE = 0, 20 UNDERLINE_SINGLE = 1, 21 UNDERLINE_DOUBLE = 2, 22 UNDERLINE_WIGGLE = 3, 23 UNDERLINE_DOTTED = 4, 24 }; 25 26 27 class CharacterStyleData; 28 typedef BReference<CharacterStyleData> CharacterStyleDataRef; 29 30 31 // You cannot modify a CharacterStyleData object once it has been 32 // created. Instead, the setter methods return a new object that equals 33 // the object on which the method has been called, except for the changed 34 // property. If the property already has the requested value, then a 35 // reference to the same object is returned. 36 class CharacterStyleData : public BReferenceable { 37 public: 38 CharacterStyleData(); 39 CharacterStyleData( 40 const CharacterStyleData& other); 41 42 bool operator==( 43 const CharacterStyleData& other) const; 44 bool operator!=( 45 const CharacterStyleData& other) const; 46 47 CharacterStyleDataRef SetFont(const BFont& font); 48 inline const BFont& Font() const 49 { return fFont; } 50 51 CharacterStyleDataRef SetAscent(float ascent); 52 53 // Returns the ascent of the configured font, unless the ascent 54 // has been overridden by a fixed value with SetAscent(). 55 float Ascent() const; 56 57 CharacterStyleDataRef SetDescent(float descent); 58 59 // Returns the descent of the configured font, unless the descent 60 // has been overridden by a fixed value with SetDescent(). 61 float Descent() const; 62 63 CharacterStyleDataRef SetWidth(float width); 64 inline float Width() const 65 { return fWidth; } 66 67 CharacterStyleDataRef SetGlyphSpacing(float glyphSpacing); 68 inline float GlyphSpacing() const 69 { return fGlyphSpacing; } 70 71 CharacterStyleDataRef SetForegroundColor(rgb_color color); 72 inline rgb_color ForegroundColor() const 73 { return fFgColor; } 74 75 CharacterStyleDataRef SetBackgroundColor(rgb_color color); 76 inline rgb_color BackgroundColor() const 77 { return fBgColor; } 78 79 CharacterStyleDataRef SetStrikeOutColor(rgb_color color); 80 inline rgb_color StrikeOutColor() const 81 { return fStrikeOutColor; } 82 83 CharacterStyleDataRef SetUnderlineColor(rgb_color color); 84 inline rgb_color UnderlineColor() const 85 { return fUnderlineColor; } 86 87 CharacterStyleDataRef SetStrikeOut(uint8 strikeOut); 88 inline uint8 StrikeOut() const 89 { return fStrikeOutStyle; } 90 91 CharacterStyleDataRef SetUnderline(uint8 underline); 92 inline uint8 Underline() const 93 { return fUnderlineStyle; } 94 95 private: 96 CharacterStyleData& operator=(const CharacterStyleData& other); 97 98 private: 99 BFont fFont; 100 101 // The following three values override glyph metrics unless -1 102 // This is useful when you want to have a place-holder character 103 // in the text. You would assign this character a CharacterStyle 104 // which defines ascent, descent and width to fixed values, thereby 105 // controlling the exact dimensions of the character, regardless of 106 // font size. Instead of the character, one could render an icon 107 // that is layouted within the text. 108 float fAscent; 109 float fDescent; 110 float fWidth; 111 112 // Additional spacing to be applied between glyphs. 113 float fGlyphSpacing; 114 115 rgb_color fFgColor; 116 rgb_color fBgColor; 117 118 rgb_color fStrikeOutColor; 119 rgb_color fUnderlineColor; 120 121 uint8 fStrikeOutStyle; 122 uint8 fUnderlineStyle; 123 }; 124 125 126 127 #endif // CHARACTER_STYLE_DATA_H 128