mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:57:35 +00:00
LibPDF: Apply text matrix to each glyph's position
We still don't apply it to the glyph itself, so they don't show up scaled or rotated, but they're at the right spot now. One big thing this here hsa going for it is that the final glyph position is now calculated with just `ext_rendering_matrix.map(glyph_position)`. Also, character_spacing and word_spacing are now used unmodified in the SimpleFont::draw_string() loop. This also means we no longer have to undo a scale when updating the position in `Renderer::show_text()`. Most of the rest stays pretty yucky though. The root cause of many problems is that ScaledFont has its rendering sized baked into the object. We want to render fonts at size font_size times scale from text matrix times scale from current transformation matrix (but not size from hotizontal_scaling). So we have to make that the font_size, but then we have to undo that in a bunch of places to get the actualy font size. This will eventually get better when LibPDF moves off ScaledFont.
This commit is contained in:
parent
09a91e54c0
commit
d2f3288666
2 changed files with 16 additions and 11 deletions
|
@ -1011,15 +1011,13 @@ PDFErrorOr<void> Renderer::show_text(ByteString const& string)
|
|||
if (!text_state().font)
|
||||
return Error::rendering_unsupported_error("Can't draw text because an invalid font was in use");
|
||||
|
||||
auto const& text_rendering_matrix = calculate_text_rendering_matrix();
|
||||
|
||||
auto start_position = text_rendering_matrix.map(Gfx::FloatPoint { 0.0f, 0.0f });
|
||||
auto start_position = Gfx::FloatPoint { 0.0f, 0.0f };
|
||||
auto end_position = TRY(text_state().font->draw_string(m_painter, start_position, string, *this));
|
||||
|
||||
// Update text matrix
|
||||
// Update text matrix.
|
||||
auto delta_x = end_position.x() - start_position.x();
|
||||
m_text_rendering_matrix_is_dirty = true;
|
||||
m_text_matrix.translate(delta_x / text_rendering_matrix.x_scale() * text_state().horizontal_scaling, 0.0f);
|
||||
m_text_matrix.translate(delta_x * text_state().horizontal_scaling, 0.0f);
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue