ttf_font: add sanity check for invalid scale value

The check prevents the Ttf_font from violating the bounding box in the
presence of very small scale values. This can happen during the startup
of Sculpt. Before the framebuffer driver is up, Sculpt bases its dynamic
font-size setting on a screen resolution of 1x1.

Issue #3812
This commit is contained in:
Norman Feske 2020-08-20 13:55:05 +02:00
parent e8e14ad1bf
commit 658091bfad
2 changed files with 12 additions and 0 deletions

View File

@ -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;

View File

@ -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;
{