diff --git a/repos/gems/include/gems/cached_font.h b/repos/gems/include/gems/cached_font.h index 9bfb150862..ebd6b2a3d5 100644 --- a/repos/gems/include/gems/cached_font.h +++ b/repos/gems/include/gems/cached_font.h @@ -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(); } }; diff --git a/repos/gems/include/gems/ttf_font.h b/repos/gems/include/gems/ttf_font.h index f628d1f9b5..e9d97ca18e 100644 --- a/repos/gems/include/gems/ttf_font.h +++ b/repos/gems/include/gems/ttf_font.h @@ -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; } }; diff --git a/repos/gems/include/gems/vfs_font.h b/repos/gems/include/gems/vfs_font.h index 0747262e5b..b0512fea6c 100644 --- a/repos/gems/include/gems/vfs_font.h +++ b/repos/gems/include/gems/vfs_font.h @@ -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; } }; diff --git a/repos/gems/src/lib/ttf_font/ttf_font.cc b/repos/gems/src/lib/ttf_font/ttf_font.cc index c0c3623e79..453ee7c2a5 100644 --- a/repos/gems/src/lib/ttf_font/ttf_font.cc +++ b/repos/gems/src/lib/ttf_font/ttf_font.cc @@ -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)) { } diff --git a/repos/gems/src/lib/vfs/ttf/vfs.cc b/repos/gems/src/lib/vfs/ttf/vfs.cc index 9e1be225ce..435ba83c0a 100644 --- a/repos/gems/src/lib/vfs/ttf/vfs.cc +++ b/repos/gems/src/lib/vfs/ttf/vfs.cc @@ -94,12 +94,14 @@ struct Vfs_ttf::Local_factory : File_system_factory Glyphs_file_system _glyphs_fs { _font->cached_font }; Readonly_value_file_system _baseline_fs { "baseline", 0 }; + Readonly_value_file_system _height_fs { "height", 0 }; Readonly_value_file_system _max_width_fs { "max_width", 0 }; Readonly_value_file_system _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::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"); }); }); diff --git a/repos/os/include/nitpicker_gfx/text_painter.h b/repos/os/include/nitpicker_gfx/text_painter.h index eba14d7edb..80841b4794 100644 --- a/repos/os/include/nitpicker_gfx/text_painter.h +++ b/repos/os/include/nitpicker_gfx/text_painter.h @@ -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 */ diff --git a/repos/os/include/nitpicker_gfx/tff_font.h b/repos/os/include/nitpicker_gfx/tff_font.h index 22e3965254..3de0bccdbf 100644 --- a/repos/os/include/nitpicker_gfx/tff_font.h +++ b/repos/os/include/nitpicker_gfx/tff_font.h @@ -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; } };