Skip to content

Commit 8c7fc4f

Browse files
X-ylawesomekling
authored andcommitted
LibPDF: Offset PaintStyle when painting so pattern overlaps properly
1 parent 8ff8791 commit 8c7fc4f

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
@@ -293,6 +293,12 @@ RENDERER_HANDLER(path_append_rect)
293293

294294
void Renderer::begin_path_paint()
295295
{
296+
if (state().paint_style.has<NonnullRefPtr<Gfx::PaintStyle>>()) {
297+
VERIFY(!m_original_paint_style);
298+
m_original_paint_style = state().paint_style.get<NonnullRefPtr<Gfx::PaintStyle>>();
299+
auto translation = Gfx::AffineTransform().translate(m_current_path.bounding_box().x(), m_current_path.bounding_box().y());
300+
state().paint_style = { MUST(Gfx::OffsetPaintStyle::create(state().paint_style.get<NonnullRefPtr<Gfx::PaintStyle>>(), translation)) };
301+
}
296302
auto bounding_box = state().clipping_paths.current.bounding_box();
297303
m_painter.clear_clip_rect();
298304
if (m_rendering_preferences.show_clipping_paths) {
@@ -306,6 +312,11 @@ void Renderer::end_path_paint()
306312
m_current_path.clear();
307313
m_painter.clear_clip_rect();
308314
state().clipping_paths.current = state().clipping_paths.next;
315+
316+
if (m_original_paint_style) {
317+
state().paint_style = m_original_paint_style.release_nonnull();
318+
m_original_paint_style = nullptr;
319+
}
309320
}
310321

311322
RENDERER_HANDLER(path_stroke)

Userland/Libraries/LibPDF/Renderer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class Renderer {
173173
Gfx::AffineTransform mutable m_text_rendering_matrix;
174174

175175
HashMap<FontCacheKey, NonnullRefPtr<PDFFont>> m_font_cache;
176+
// Used to offset the PaintStyle's origin when rendering a pattern.
177+
RefPtr<Gfx::PaintStyle> m_original_paint_style;
176178
};
177179

178180
}

0 commit comments

Comments
 (0)