LibGfx+LibWeb: Allow inexact size lookups when requesting scaled fonts

For bitmap fonts, we will often not have an exact match for requested
sizes. Return the closest match instead of a nullptr.

LibWeb is currently the only user of this API. If it needs to be
configurable in the future to only allow exact matches, we can add a
parameter or another method at that time.
This commit is contained in:
Timothy Flynn 2024-05-06 13:12:16 -04:00 committed by Alexander Kalenik
commit 464d7d5858
Notes: sideshowbarker 2024-07-16 22:14:49 +09:00
12 changed files with 17 additions and 18 deletions

View file

@ -89,8 +89,8 @@ void CommandList::execute(CommandExecutor& executor)
for (auto const& glyph_or_emoji : command.get<DrawGlyphRun>().glyph_run->glyphs()) {
if (glyph_or_emoji.has<Gfx::DrawGlyph>()) {
auto const& glyph = glyph_or_emoji.get<Gfx::DrawGlyph>();
auto const& font = *glyph.font->with_size(glyph.font->point_size() * static_cast<float>(scale));
unique_glyphs.ensure(&font, [] { return HashTable<u32> {}; }).set(glyph.code_point);
auto font = glyph.font->with_size(glyph.font->point_size() * static_cast<float>(scale));
unique_glyphs.ensure(font, [] { return HashTable<u32> {}; }).set(glyph.code_point);
}
}
}