HaikuDepot: CharacterStyle: Added convenience methods

This commit is contained in:
Stephan Aßmus
2013-09-05 13:21:32 +02:00
parent 15990b01a2
commit d922357fa1
4 changed files with 57 additions and 4 deletions
@@ -73,6 +73,15 @@ CharacterStyle::Font() const
} }
bool
CharacterStyle::SetFontSize(float size)
{
BFont font(Font());
font.SetSize(size);
return SetFont(font);
}
bool bool
CharacterStyle::SetAscent(float ascent) CharacterStyle::SetAscent(float ascent)
{ {
@@ -149,6 +158,13 @@ CharacterStyle::GlyphSpacing() const
} }
bool
CharacterStyle::SetForegroundColor(uint8 r, uint8 g, uint8 b, uint8 a)
{
return SetForegroundColor((rgb_color){ r, g, b, a });
}
bool bool
CharacterStyle::SetForegroundColor(rgb_color color) CharacterStyle::SetForegroundColor(rgb_color color)
{ {
@@ -168,6 +184,13 @@ CharacterStyle::ForegroundColor() const
} }
bool
CharacterStyle::SetBackgroundColor(uint8 r, uint8 g, uint8 b, uint8 a)
{
return SetBackgroundColor((rgb_color){ r, g, b, a });
}
bool bool
CharacterStyle::SetBackgroundColor(rgb_color color) CharacterStyle::SetBackgroundColor(rgb_color color)
{ {
@@ -20,6 +20,8 @@ public:
bool SetFont(const BFont& font); bool SetFont(const BFont& font);
const BFont& Font() const; const BFont& Font() const;
bool SetFontSize(float size);
bool SetAscent(float ascent); bool SetAscent(float ascent);
float Ascent() const; float Ascent() const;
@@ -32,9 +34,15 @@ public:
bool SetGlyphSpacing(float spacing); bool SetGlyphSpacing(float spacing);
float GlyphSpacing() const; float GlyphSpacing() const;
bool SetForegroundColor(
uint8 r, uint8 g, uint8 b,
uint8 a = 255);
bool SetForegroundColor(rgb_color color); bool SetForegroundColor(rgb_color color);
rgb_color ForegroundColor() const; rgb_color ForegroundColor() const;
bool SetBackgroundColor(
uint8 r, uint8 g, uint8 b,
uint8 a = 255);
bool SetBackgroundColor(rgb_color color); bool SetBackgroundColor(rgb_color color);
rgb_color BackgroundColor() const; rgb_color BackgroundColor() const;
@@ -110,6 +110,18 @@ CharacterStyleData::SetAscent(float ascent)
} }
float
CharacterStyleData::Ascent() const
{
if (fAscent >= 0.0f)
return fAscent;
font_height fontHeight;
fFont.GetHeight(&fontHeight);
return fontHeight.ascent;
}
CharacterStyleDataRef CharacterStyleDataRef
CharacterStyleData::SetDescent(float descent) CharacterStyleData::SetDescent(float descent)
{ {
@@ -125,6 +137,18 @@ CharacterStyleData::SetDescent(float descent)
} }
float
CharacterStyleData::Descent() const
{
if (fDescent >= 0.0f)
return fDescent;
font_height fontHeight;
fFont.GetHeight(&fontHeight);
return fontHeight.descent;
}
CharacterStyleDataRef CharacterStyleDataRef
CharacterStyleData::SetWidth(float width) CharacterStyleData::SetWidth(float width)
{ {
@@ -46,12 +46,10 @@ public:
{ return fFont; } { return fFont; }
CharacterStyleDataRef SetAscent(float ascent); CharacterStyleDataRef SetAscent(float ascent);
inline float Ascent() const float Ascent() const;
{ return fAscent; }
CharacterStyleDataRef SetDescent(float descent); CharacterStyleDataRef SetDescent(float descent);
inline float Descent() const float Descent() const;
{ return fDescent; }
CharacterStyleDataRef SetWidth(float width); CharacterStyleDataRef SetWidth(float width);
inline float Width() const inline float Width() const