LibPDF: Apply all offsets of TJ operator

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.
This commit is contained in:
Nico Weber 2023-11-13 18:39:10 -05:00 committed by Andreas Kling
parent 4f51ff456e
commit 9b022239c3
Notes: sideshowbarker 2024-07-16 23:03:06 +09:00

View File

@ -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>();
} else if (element.has<float>()) {
next_shift = element.get<float>();
} else {
auto shift = next_shift / 1000.0f;
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>()) {
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));
}