Skip to content

Commit 4579350

Browse files
X-ylMacDue
authored andcommitted
Reapply "LibPDF: Offset PaintStyle when painting so pattern overlaps..."
This reverts commit 7cb216c.
1 parent ded1a12 commit 4579350

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Userland/Libraries/LibPDF/Renderer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@ PDFErrorOr<void> Renderer::restore_previous_clip_after_graphics_state_restore()
415415
void Renderer::begin_path_paint()
416416
{
417417
m_current_path.transform(state().ctm);
418+
if (state().paint_style.has<NonnullRefPtr<Gfx::PaintStyle>>()) {
419+
VERIFY(!m_original_paint_style);
420+
m_original_paint_style = state().paint_style.get<NonnullRefPtr<Gfx::PaintStyle>>();
421+
auto translation = Gfx::AffineTransform().translate(m_current_path.bounding_box().x(), m_current_path.bounding_box().y());
422+
state().paint_style = { MUST(Gfx::OffsetPaintStyle::create(state().paint_style.get<NonnullRefPtr<Gfx::PaintStyle>>(), translation)) };
423+
}
418424
}
419425

420426
PDFErrorOr<void> Renderer::end_path_paint()
@@ -424,6 +430,11 @@ PDFErrorOr<void> Renderer::end_path_paint()
424430
m_add_path_as_clip = AddPathAsClip::No;
425431
}
426432

433+
if (m_original_paint_style) {
434+
state().paint_style = m_original_paint_style.release_nonnull();
435+
m_original_paint_style = nullptr;
436+
}
437+
427438
// "Once a path has been painted, it is no longer defined; there is then no current path
428439
// until a new one is begun with the m or re operator."
429440
m_current_path.clear();

Userland/Libraries/LibPDF/Renderer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ class Renderer {
293293
// Only used for m_rendering_preferences.show_clipping_paths.
294294
void show_clipping_paths();
295295
Vector<Gfx::Path> m_clip_paths_to_show_for_debugging;
296+
// Used to offset the PaintStyle's origin when rendering a pattern.
297+
RefPtr<Gfx::PaintStyle> m_original_paint_style;
296298
};
297299

298300
}

0 commit comments

Comments
 (0)