mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +00:00
LibPDF: Handle the TJ graphical operator
This commit is contained in:
parent
47531619e3
commit
c142dadbe8
2 changed files with 22 additions and 4 deletions
|
@ -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 == ' ')
|
||||
|
|
|
@ -94,7 +94,7 @@ private:
|
|||
|
||||
void set_graphics_state_from_dict(NonnullRefPtr<DictObject>);
|
||||
// shift is the manual advance given in the TJ command array
|
||||
void show_text(const String&, int shift = 0);
|
||||
void show_text(const String&, float shift = 0.0f);
|
||||
RefPtr<ColorSpace> get_color_space(const Value&);
|
||||
|
||||
ALWAYS_INLINE const GraphicsState& state() const { return m_graphics_state_stack.last(); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue