mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:07:36 +00:00
LibPDF: Fix text positioning with operator TJ
As per spec, the positioning (or kerning) parameter of this operator should translate the text matrix before the next showing of text. Previously, this calculation was slightly wrong and also only applied after the text was already shown.
This commit is contained in:
parent
563d91b6c4
commit
97ed4106e5
2 changed files with 6 additions and 5 deletions
|
@ -453,8 +453,10 @@ RENDERER_HANDLER(text_show_string_array)
|
||||||
} else if (element.has<float>()) {
|
} else if (element.has<float>()) {
|
||||||
next_shift = element.get<float>();
|
next_shift = element.get<float>();
|
||||||
} else {
|
} else {
|
||||||
|
auto shift = next_shift / 1000.0f;
|
||||||
|
m_text_matrix.translate(-shift * text_state().font_size * text_state().horizontal_scaling, 0.0f);
|
||||||
auto str = element.get<NonnullRefPtr<Object>>()->cast<StringObject>()->string();
|
auto str = element.get<NonnullRefPtr<Object>>()->cast<StringObject>()->string();
|
||||||
show_text(str, next_shift);
|
show_text(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,7 +639,7 @@ PDFErrorOr<void> Renderer::set_graphics_state_from_dict(NonnullRefPtr<DictObject
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::show_text(String const& string, float shift)
|
void Renderer::show_text(String const& string)
|
||||||
{
|
{
|
||||||
auto& text_rendering_matrix = calculate_text_rendering_matrix();
|
auto& text_rendering_matrix = calculate_text_rendering_matrix();
|
||||||
|
|
||||||
|
@ -660,7 +662,7 @@ void Renderer::show_text(String const& string, float shift)
|
||||||
m_painter.draw_glyph(glyph_position.to_type<int>(), code_point, *font, state().paint_color);
|
m_painter.draw_glyph(glyph_position.to_type<int>(), code_point, *font, state().paint_color);
|
||||||
|
|
||||||
auto glyph_width = char_width * font_size;
|
auto glyph_width = char_width * font_size;
|
||||||
auto tx = (glyph_width - shift / 1000.0f);
|
auto tx = glyph_width;
|
||||||
tx += text_state().character_spacing;
|
tx += text_state().character_spacing;
|
||||||
|
|
||||||
if (code_point == ' ')
|
if (code_point == ' ')
|
||||||
|
|
|
@ -98,8 +98,7 @@ private:
|
||||||
PDFErrorOr<void> handle_text_next_line_show_string_set_spacing(Vector<Value> const& args);
|
PDFErrorOr<void> handle_text_next_line_show_string_set_spacing(Vector<Value> const& args);
|
||||||
|
|
||||||
PDFErrorOr<void> set_graphics_state_from_dict(NonnullRefPtr<DictObject>);
|
PDFErrorOr<void> set_graphics_state_from_dict(NonnullRefPtr<DictObject>);
|
||||||
// shift is the manual advance given in the TJ operator array
|
void show_text(String const&);
|
||||||
void show_text(String const&, float shift = 0.0f);
|
|
||||||
PDFErrorOr<NonnullRefPtr<ColorSpace>> get_color_space(Value const&);
|
PDFErrorOr<NonnullRefPtr<ColorSpace>> get_color_space(Value const&);
|
||||||
|
|
||||||
ALWAYS_INLINE GraphicsState const& state() const { return m_graphics_state_stack.last(); }
|
ALWAYS_INLINE GraphicsState const& state() const { return m_graphics_state_stack.last(); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue