1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:57:44 +00:00

LibPDF: Handle the TJ graphical operator

This commit is contained in:
Matthew Olsson 2021-05-27 14:53:10 -07:00 committed by Ali Mohammad Pur
parent 47531619e3
commit c142dadbe8
2 changed files with 22 additions and 4 deletions

View file

@ -385,7 +385,25 @@ RENDERER_HANDLER(text_next_line_show_string)
}
RENDERER_TODO(text_next_line_show_string_set_spacing);
RENDERER_TODO(text_show_string_array);
RENDERER_HANDLER(text_show_string_array)
{
auto elements = m_document->resolve_to<ArrayObject>(args[0])->elements();
float next_shift = 0.0f;
for (auto& element : elements) {
if (element.is_number()) {
next_shift = element.to_float();
} else {
VERIFY(element.is_object());
auto obj = element.as_object();
VERIFY(obj->is_string());
auto str = object_cast<StringObject>(obj)->string();
show_text(str, next_shift);
}
}
}
RENDERER_TODO(type3_font_set_glyph_width);
RENDERER_TODO(type3_font_set_glyph_width_and_bbox);
@ -504,7 +522,7 @@ void Renderer::set_graphics_state_from_dict(NonnullRefPtr<DictObject> dict)
handle_set_flatness_tolerance({ dict->get_value(CommonNames::FL) });
}
void Renderer::show_text(const String& string, int shift)
void Renderer::show_text(const String& string, float shift)
{
auto utf = Utf8View(string);
auto& font = text_state().font;
@ -522,7 +540,7 @@ void Renderer::show_text(const String& string, int shift)
m_painter.draw_glyph(text_position.to_type<int>(), code_point, *text_state().font, state().paint_color);
auto glyph_width = static_cast<float>(font->glyph_width(code_point));
auto tx = (glyph_width - static_cast<float>(shift) / 1000.0f);
auto tx = (glyph_width - shift / 1000.0f);
tx += text_state().character_spacing;
if (code_point == ' ')