mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16: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:
parent
152a8c5c43
commit
4f4bd3793f
2 changed files with 12 additions and 11 deletions
|
@ -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)
|
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();
|
auto base_font = TRY(dict->get_name(document, CommonNames::BaseFont))->name();
|
||||||
if ((is_standard_font = is_standard_latin_font(base_font_name))) {
|
if ((is_standard_font = is_standard_latin_font(base_font))) {
|
||||||
auto replacement = replacement_for_standard_latin_font(base_font_name.to_lowercase());
|
auto replacement = replacement_for_standard_latin_font(base_font);
|
||||||
font = Gfx::FontDatabase::the().get(replacement.get<0>(), replacement.get<1>(), font_size);
|
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);
|
VERIFY(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,13 @@ PDFErrorOr<PDFFont::CommonData> TrueTypeFont::parse_data(Document* document, Non
|
||||||
TRY(data.load_from_dict(document, dict, font_size));
|
TRY(data.load_from_dict(document, dict, font_size));
|
||||||
|
|
||||||
if (!data.is_standard_font) {
|
if (!data.is_standard_font) {
|
||||||
auto descriptor = MUST(dict->get_dict(document, CommonNames::FontDescriptor));
|
auto descriptor = TRY(dict->get_dict(document, CommonNames::FontDescriptor));
|
||||||
if (!descriptor->contains(CommonNames::FontFile2))
|
if (descriptor->contains(CommonNames::FontFile2)) {
|
||||||
return data;
|
auto font_file_stream = TRY(descriptor->get_stream(document, CommonNames::FontFile2));
|
||||||
|
auto ttf_font = TRY(OpenType::Font::try_load_from_externally_owned_memory(font_file_stream->bytes()));
|
||||||
auto font_file_stream = TRY(descriptor->get_stream(document, CommonNames::FontFile2));
|
float point_size = (font_size * POINTS_PER_INCH) / DEFAULT_DPI;
|
||||||
auto ttf_font = TRY(OpenType::Font::try_load_from_externally_owned_memory(font_file_stream->bytes()));
|
data.font = adopt_ref(*new Gfx::ScaledFont(*ttf_font, point_size, point_size));
|
||||||
data.font = adopt_ref(*new Gfx::ScaledFont(*ttf_font, font_size, font_size));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue