1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:47:34 +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

@ -11,6 +11,7 @@
#include <LibPDF/Fonts/SimpleFont.h>
#include <LibPDF/Fonts/TrueTypeFont.h>
#include <LibPDF/Fonts/Type1Font.h>
#include <LibPDF/Renderer.h>
namespace PDF {
@ -45,8 +46,17 @@ PDFErrorOr<void> SimpleFont::initialize(Document* document, NonnullRefPtr<DictOb
return {};
}
PDFErrorOr<Gfx::FloatPoint> SimpleFont::draw_string(Gfx::Painter& painter, Gfx::FloatPoint glyph_position, DeprecatedString const& string, Color const& paint_color, float font_size, float character_spacing, float word_spacing, float horizontal_scaling)
PDFErrorOr<Gfx::FloatPoint> SimpleFont::draw_string(Gfx::Painter& painter, Gfx::FloatPoint glyph_position, DeprecatedString const& string, Renderer const& renderer)
{
Color const& paint_color = renderer.state().paint_color;
auto const& text_rendering_matrix = renderer.calculate_text_rendering_matrix();
auto font_size = text_rendering_matrix.x_scale() * renderer.text_state().font_size;
auto character_spacing = text_rendering_matrix.x_scale() * renderer.text_state().character_spacing;
auto word_spacing = text_rendering_matrix.x_scale() * renderer.text_state().word_spacing;
auto horizontal_scaling = renderer.text_state().horizontal_scaling;
for (auto char_code : string.bytes()) {
// Use the width specified in the font's dictionary if available,
// and use the default width for the given font otherwise.