diff --git a/repos/gems/include/gems/vfs_font.h b/repos/gems/include/gems/vfs_font.h index 52be3c4e65..8a8067530c 100644 --- a/repos/gems/include/gems/vfs_font.h +++ b/repos/gems/include/gems/vfs_font.h @@ -60,11 +60,22 @@ class Genode::Vfs_font : public Text_painter::Font Glyph_header() { } - Glyph glyph() const { return Glyph { .width = _width, - .height = _height, - .vpos = _vpos, - .advance = _advance(), - .values = _values }; } + Advance_info advance_info() const + { + return { .width = _width, .advance = _advance() }; + } + + void with_glyph(Text_painter::Area const bb, auto const &fn) const + { + /* consider glyph bounds exceeding the font's bounding box */ + uint8_t const clipped_h = uint8_t(_width ? (bb.count() / _width) : 0u); + + fn(Glyph { .width = _width, + .height = min(_height, clipped_h), + .vpos = _vpos, + .advance = _advance(), + .values = _values }); + } } __attribute__((packed)); @@ -149,7 +160,8 @@ class Genode::Vfs_font : public Text_painter::Font { _glyphs_file.read(_file_pos(c), _buffer); - fn.apply(_buffer.header.glyph()); + _buffer.header.with_glyph(_bounding_box, [&] (Glyph const &glyph) { + fn.apply(glyph); }); } Advance_info advance_info(Codepoint c) const override @@ -158,9 +170,7 @@ class Genode::Vfs_font : public Text_painter::Font _glyphs_file.read(_file_pos(c), header_buffer); - Glyph const glyph = _buffer.header.glyph(); - - return Advance_info { .width = glyph.width, .advance = glyph.advance }; + return _buffer.header.advance_info(); } unsigned baseline() const override { return _baseline; }