Skip to content

Commit

Permalink
LibPDF: Apply all offsets of TJ operator
Browse files Browse the repository at this point in the history
TJ acts on a list of either strings or numbers.
The strings are drawn, and the numbers are treated as offsets.

Previously, we'd only apply the last-seen number as offset when
we saw a string. That had the effect of us ignoring all but the
last number in front of a string, and ignoring numbers at the
end of the list.

Now, we apply all numbers as offsets.
Our rendering of Tests/LibPDF/text.pdf now matches other PDF viewers.
  • Loading branch information
nico committed Nov 13, 2023
1 parent 02458cc commit e1d62b2
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Userland/Libraries/LibPDF/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,15 @@ RENDERER_HANDLER(text_next_line_show_string_set_spacing)
RENDERER_HANDLER(text_show_string_array)
{
auto elements = MUST(m_document->resolve_to<ArrayObject>(args[0]))->elements();
float next_shift = 0.0f;

for (auto& element : elements) {
if (element.has<int>()) {
next_shift = element.get<int>();
float shift = (float)element.get<int>() / 1000.0f;
m_text_matrix.translate(-shift * text_state().font_size * text_state().horizontal_scaling, 0.0f);
} else if (element.has<float>()) {
next_shift = element.get<float>();
} else {
auto shift = next_shift / 1000.0f;
float shift = element.get<float>() / 1000.0f;
m_text_matrix.translate(-shift * text_state().font_size * text_state().horizontal_scaling, 0.0f);
} else {
auto str = element.get<NonnullRefPtr<Object>>()->cast<StringObject>()->string();
TRY(show_text(str));
}
Expand Down

0 comments on commit e1d62b2

Please sign in to comment.