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

LibPDF: Don't accidentally put horizontal_scaling in places

Fonts should have size font_size times total scaling. We tried to
get that by computing text_rendering_matrix.x_scale() * font_size,
but text_rendering_matrix.x_scale() also includes
horizontal_scaling, which shouldn't be part of font size.

Same for character_spacing and word_spacing.

This is all a big mess that's caused by LibPDF using ScaledFont,
which requires scaling to be aprt of the text type. I have an
in-progress local branch that moves LibPDF to directly use VectorFont,
which will hopefully make this (and other things) nicer. But first,
let's get this right, and then make sure we don't regress it when
things change :^)
This commit is contained in:
Nico Weber 2024-01-16 18:10:36 -05:00 committed by Andreas Kling
parent abda5e66f6
commit f54b0e7c22
2 changed files with 8 additions and 7 deletions

View file

@ -487,7 +487,7 @@ RENDERER_HANDLER(text_set_font)
text_state().font_size = args[1].to_float();
auto& text_rendering_matrix = calculate_text_rendering_matrix();
auto font_size = text_rendering_matrix.x_scale() * text_state().font_size;
auto font_size = text_rendering_matrix.x_scale() * text_state().font_size / text_state().horizontal_scaling;
auto resources = extra_resources.value_or(m_page.resources);
auto fonts_dictionary = MUST(resources->get_dict(m_document, CommonNames::Font));
@ -545,7 +545,7 @@ RENDERER_HANDLER(text_set_matrix_and_line_matrix)
// Settings the text/line matrix retroactively affects fonts
if (text_state().font) {
auto new_text_rendering_matrix = calculate_text_rendering_matrix();
text_state().font->set_font_size(text_state().font_size * new_text_rendering_matrix.x_scale());
text_state().font->set_font_size(text_state().font_size * new_text_rendering_matrix.x_scale() / text_state().horizontal_scaling);
}
return {};