1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:27:35 +00:00

LibPDF: Fix glyph sizing bug that caused incorrect spacing

When loading OpenType fonts, either as a replacement for the standard
14 fonts or an embedded one, we previously passed the font size as the
_point_ size to the loader class. The difference is quite subtle, being
that Gfx::ScaledFont uses the optional dpi parameter to convert the
input from inches to pixels.

This meant that our glyphs were exactly 1.333% too large, causing them
to overlap in places.
This commit is contained in:
Julian Offenhäuser 2023-02-09 14:16:22 +01:00 committed by Andreas Kling
parent 152a8c5c43
commit 4f4bd3793f
2 changed files with 12 additions and 11 deletions

View file

@ -33,10 +33,11 @@ static bool is_standard_latin_font(DeprecatedFlyString const& font)
PDFErrorOr<void> PDFFont::CommonData::load_from_dict(Document* document, NonnullRefPtr<DictObject> dict, float font_size)
{
base_font_name = TRY(dict->get_name(document, CommonNames::BaseFont))->name();
if ((is_standard_font = is_standard_latin_font(base_font_name))) {
auto replacement = replacement_for_standard_latin_font(base_font_name.to_lowercase());
font = Gfx::FontDatabase::the().get(replacement.get<0>(), replacement.get<1>(), font_size);
auto base_font = TRY(dict->get_name(document, CommonNames::BaseFont))->name();
if ((is_standard_font = is_standard_latin_font(base_font))) {
auto replacement = replacement_for_standard_latin_font(base_font);
float point_size = (font_size * POINTS_PER_INCH) / DEFAULT_DPI;
font = Gfx::FontDatabase::the().get(replacement.get<0>(), replacement.get<1>(), point_size);
VERIFY(font);
}