瀏覽代碼

LibPDF: Offset PaintStyle when painting so pattern overlaps properly

Kyle Pereira 1 年之前
父節點
當前提交
8c7fc4fe6c
共有 2 個文件被更改,包括 13 次插入0 次删除
  1. 11 0
      Userland/Libraries/LibPDF/Renderer.cpp
  2. 2 0
      Userland/Libraries/LibPDF/Renderer.h

+ 11 - 0
Userland/Libraries/LibPDF/Renderer.cpp

@@ -293,6 +293,12 @@ RENDERER_HANDLER(path_append_rect)
 
 void Renderer::begin_path_paint()
 {
+    if (state().paint_style.has<NonnullRefPtr<Gfx::PaintStyle>>()) {
+        VERIFY(!m_original_paint_style);
+        m_original_paint_style = state().paint_style.get<NonnullRefPtr<Gfx::PaintStyle>>();
+        auto translation = Gfx::AffineTransform().translate(m_current_path.bounding_box().x(), m_current_path.bounding_box().y());
+        state().paint_style = { MUST(Gfx::OffsetPaintStyle::create(state().paint_style.get<NonnullRefPtr<Gfx::PaintStyle>>(), translation)) };
+    }
     auto bounding_box = state().clipping_paths.current.bounding_box();
     m_painter.clear_clip_rect();
     if (m_rendering_preferences.show_clipping_paths) {
@@ -306,6 +312,11 @@ void Renderer::end_path_paint()
     m_current_path.clear();
     m_painter.clear_clip_rect();
     state().clipping_paths.current = state().clipping_paths.next;
+
+    if (m_original_paint_style) {
+        state().paint_style = m_original_paint_style.release_nonnull();
+        m_original_paint_style = nullptr;
+    }
 }
 
 RENDERER_HANDLER(path_stroke)

+ 2 - 0
Userland/Libraries/LibPDF/Renderer.h

@@ -173,6 +173,8 @@ private:
     Gfx::AffineTransform mutable m_text_rendering_matrix;
 
     HashMap<FontCacheKey, NonnullRefPtr<PDFFont>> m_font_cache;
+    // Used to offset the PaintStyle's origin when rendering a pattern.
+    RefPtr<Gfx::PaintStyle> m_original_paint_style;
 };
 
 }