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

LibPDF: Pass Renderer to PDFFont::draw_string()

It's a bit unfortunate that fonts need to know about the renderer,
but type 3 fonts contain PDF drawing operators, so it's necessary.

On the bright side, it makes it possible to pass fewer parameters
around and compute things locally as needed.

(As we implement more fonts, we'll probably want to create some
functions to do these computations in a central place, eventually.)

No behavior change.
This commit is contained in:
Nico Weber 2023-11-14 10:11:39 -05:00 committed by Sam Atkins
parent e0c0864ddf
commit bcc6439b5f
7 changed files with 32 additions and 21 deletions

View file

@ -802,12 +802,10 @@ PDFErrorOr<void> Renderer::show_text(DeprecatedString const& string)
if (!text_state().font)
return Error::rendering_unsupported_error("Can't draw text because an invalid font was in use");
auto& text_rendering_matrix = calculate_text_rendering_matrix();
auto font_size = text_rendering_matrix.x_scale() * text_state().font_size;
auto const& text_rendering_matrix = calculate_text_rendering_matrix();
auto start_position = text_rendering_matrix.map(Gfx::FloatPoint { 0.0f, 0.0f });
auto end_position = TRY(text_state().font->draw_string(m_painter, start_position, string, state().paint_color, font_size, text_state().character_spacing * text_rendering_matrix.x_scale(), text_state().word_spacing * text_rendering_matrix.x_scale(), text_state().horizontal_scaling));
auto end_position = TRY(text_state().font->draw_string(m_painter, start_position, string, *this));
// Update text matrix
auto delta_x = end_position.x() - start_position.x();
@ -983,7 +981,7 @@ PDFErrorOr<NonnullRefPtr<ColorSpace>> Renderer::get_color_space_from_document(No
return ColorSpace::create(m_document, color_space_object);
}
Gfx::AffineTransform const& Renderer::calculate_text_rendering_matrix()
Gfx::AffineTransform const& Renderer::calculate_text_rendering_matrix() const
{
if (m_text_rendering_matrix_is_dirty) {
m_text_rendering_matrix = Gfx::AffineTransform(