os: add Text_painter::Font::height method

Issue #2716
This commit is contained in:
Norman Feske 2018-04-17 12:20:59 +02:00
parent e896d13eec
commit 8bcf540915
7 changed files with 21 additions and 3 deletions

View File

@ -263,7 +263,7 @@ class Genode::Cached_font : public Text_painter::Font
}
unsigned baseline() const override { return _font.baseline(); }
unsigned height() const override { return _font.height(); }
Area bounding_box() const override { return _font.bounding_box(); }
};

View File

@ -36,6 +36,7 @@ class Ttf_font : public Text_painter::Font
float const _scale;
unsigned const _baseline;
unsigned const _height;
Area const _bounding_box;
struct Glyph_buffer;
@ -67,7 +68,7 @@ class Ttf_font : public Text_painter::Font
Advance_info advance_info(Codepoint) const override;
unsigned baseline() const override { return _baseline; }
unsigned height() const override { return _height; }
Area bounding_box() const override { return _bounding_box; }
};

View File

@ -77,6 +77,7 @@ class Genode::Vfs_font : public Text_painter::Font
Directory const _font_dir;
unsigned const _baseline;
Area const _bounding_box;
unsigned const _height;
struct Glyph_buffer
{
@ -141,6 +142,7 @@ class Genode::Vfs_font : public Text_painter::Font
_baseline(_value_from_file(_font_dir, "baseline", 0U)),
_bounding_box(_value_from_file(_font_dir, "max_width", 0U),
_value_from_file(_font_dir, "max_height", 0U)),
_height(_value_from_file(_font_dir, "height", 0U)),
_buffer(alloc, _bounding_box),
_glyphs_file(_font_dir, "glyphs")
{ }
@ -162,7 +164,7 @@ class Genode::Vfs_font : public Text_painter::Font
}
unsigned baseline() const override { return _baseline; }
unsigned height() const override { return _height; }
Area bounding_box() const override { return _bounding_box; }
};

View File

@ -247,6 +247,7 @@ Ttf_font::Ttf_font(Allocator &alloc, void const *ttf, float px)
_stbtt_font_info(_create_stbtt_font_info(alloc, ttf)),
_scale(stbtt_ScaleForPixelHeight(&_stbtt_font_info, px)),
_baseline(obtain_baseline(_stbtt_font_info, _scale)),
_height(px + 0.5 /* round to integer */),
_bounding_box(obtain_bounding_box(_stbtt_font_info, _scale)),
_glyph_buffer(*new (alloc) Glyph_buffer(alloc, _bounding_box))
{ }

View File

@ -94,12 +94,14 @@ struct Vfs_ttf::Local_factory : File_system_factory
Glyphs_file_system _glyphs_fs { _font->cached_font };
Readonly_value_file_system<unsigned> _baseline_fs { "baseline", 0 };
Readonly_value_file_system<unsigned> _height_fs { "height", 0 };
Readonly_value_file_system<unsigned> _max_width_fs { "max_width", 0 };
Readonly_value_file_system<unsigned> _max_height_fs { "max_height", 0 };
void _update_attributes()
{
_baseline_fs .value(_font->font.font().baseline());
_height_fs .value(_font->font.font().height());
_max_width_fs .value(_font->font.font().bounding_box().w());
_max_height_fs.value(_font->font.font().bounding_box().h());
}
@ -118,6 +120,7 @@ struct Vfs_ttf::Local_factory : File_system_factory
if (node.has_type(Readonly_value_file_system<unsigned>::type_name()))
return _baseline_fs.matches(node) ? &_baseline_fs
: _height_fs.matches(node) ? &_height_fs
: _max_width_fs.matches(node) ? &_max_width_fs
: _max_height_fs.matches(node) ? &_max_height_fs
: nullptr;
@ -149,6 +152,7 @@ class Vfs_ttf::File_system : private Local_factory,
xml.attribute("name", node.attribute_value("name", Name()));
xml.node("glyphs", [&] () { });
xml.node("readonly_value", [&] () { xml.attribute("name", "baseline"); });
xml.node("readonly_value", [&] () { xml.attribute("name", "height"); });
xml.node("readonly_value", [&] () { xml.attribute("name", "max_width"); });
xml.node("readonly_value", [&] () { xml.attribute("name", "max_height"); });
});

View File

@ -75,6 +75,11 @@ struct Text_painter
*/
virtual unsigned baseline() const = 0;
/**
* Return height of text in pixels when rendered with the font
*/
virtual unsigned height() const = 0;
/**
* Return the bounding box that fits each single glyph of the font
*/

View File

@ -231,6 +231,11 @@ class Tff_font : public Text_painter::Font
return m.vpos + m.height;
}
unsigned height() const override
{
return _bounding_box.h();
}
Area bounding_box() const override { return _bounding_box; }
};