diff --git a/repos/gems/include/gems/ttf_font.h b/repos/gems/include/gems/ttf_font.h index e9d97ca18e..f62ba590a9 100644 --- a/repos/gems/include/gems/ttf_font.h +++ b/repos/gems/include/gems/ttf_font.h @@ -34,6 +34,7 @@ class Ttf_font : public Text_painter::Font Stbtt_font_info &_stbtt_font_info; + float const _px; float const _scale; unsigned const _baseline; unsigned const _height; diff --git a/repos/gems/src/lib/ttf_font/ttf_font.cc b/repos/gems/src/lib/ttf_font/ttf_font.cc index 62706a4693..17c7a4918e 100644 --- a/repos/gems/src/lib/ttf_font/ttf_font.cc +++ b/repos/gems/src/lib/ttf_font/ttf_font.cc @@ -250,6 +250,7 @@ Ttf_font::_create_stbtt_font_info(Allocator &alloc, void const *ttf) Ttf_font::Ttf_font(Allocator &alloc, void const *ttf, float px) : _stbtt_font_info(_create_stbtt_font_info(alloc, ttf)), + _px(px), _scale(stbtt_ScaleForPixelHeight(&_stbtt_font_info, px)), _baseline(obtain_baseline(_stbtt_font_info, _scale)), _height(px + 0.5 /* round to integer */), @@ -269,6 +270,16 @@ Ttf_font::~Ttf_font() void Ttf_font::_apply_glyph(Codepoint c, Apply_fn const &fn) const { + if (_px < 1.0) { + Glyph const glyph { .width = 0, + .height = 0, + .vpos = 0, + .advance = 0, + .values = nullptr }; + fn.apply(glyph); + return; + } + /* find vertical subpixel position that yields the sharpest glyph */ float best_shift_y = 0; {