[librsvg: 3/5] draw_text_span: do the transforms the same way for each of the clipping/fill/stroke cases




commit 6637aafb9f537650a94b24c2b742474b700f60a1
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Jul 2 13:26:33 2021 -0500

    draw_text_span: do the transforms the same way for each of the clipping/fill/stroke cases
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/560>

 src/drawing_ctx.rs     | 58 +++++++++++++++++++++++++++++++-------------------
 tests/src/reference.rs |  1 -
 2 files changed, 36 insertions(+), 23 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 69a20924..59f60ddc 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1367,16 +1367,26 @@ impl DrawingCtx {
 
             setup_cr_for_stroke(&self.cr, &span.stroke);
 
-            self.cr.move_to(span.x, span.y);
-
-            let rotation = gravity.to_rotation();
-            if !rotation.approx_eq_cairo(0.0) {
-                self.cr.rotate(-rotation);
-            }
+            let rotation_from_gravity = gravity.to_rotation();
+            let rotation = if !rotation_from_gravity.approx_eq_cairo(0.0) {
+                Some(-rotation_from_gravity)
+            } else {
+                None
+            };
 
             if clipping {
+                self.cr.move_to(span.x, span.y);
+
+                let matrix = self.cr.matrix();
+                if let Some(rot) = rotation {
+                    self.cr.rotate(rot);
+                }
+
                 pangocairo::functions::update_layout(&self.cr, &span.layout);
                 pangocairo::functions::layout_path(&self.cr, &span.layout);
+
+                self.cr.set_matrix(matrix);
+
                 return Ok(self.empty_bbox());
             }
 
@@ -1386,29 +1396,31 @@ impl DrawingCtx {
                         PaintTarget::Fill => {
                             self.cr.move_to(span.x, span.y);
 
-                            let rotation = gravity.to_rotation();
-                            if !rotation.approx_eq_cairo(0.0) {
-                                self.cr.rotate(-rotation);
+                            let matrix = self.cr.matrix();
+                            if let Some(rot) = rotation {
+                                self.cr.rotate(rot);
                             }
+
                             let fill_paint =
                                 span.fill_paint.to_user_space(&bbox, &view_params, values);
+                            let had_paint_server =
+                                self.set_paint_source(&fill_paint, acquired_nodes)?;
+                            if had_paint_server {
+                                pangocairo::functions::update_layout(&self.cr, &span.layout);
+                                pangocairo::functions::show_layout(&self.cr, &span.layout);
+                            }
 
-                            self.set_paint_source(&fill_paint, acquired_nodes).map(
-                                |had_paint_server| {
-                                    if had_paint_server {
-                                        pangocairo::functions::update_layout(
-                                            &self.cr,
-                                            &span.layout,
-                                        );
-                                        pangocairo::functions::show_layout(&self.cr, &span.layout);
-                                    };
-                                },
-                            )?;
+                            self.cr.set_matrix(matrix);
                         }
 
                         PaintTarget::Stroke => {
-                            //path_helper.set()?;
-                            //dc.stroke(&cr, an, &stroke_paint)?;
+                            self.cr.move_to(span.x, span.y);
+
+                            let matrix = self.cr.matrix();
+                            if let Some(rot) = rotation {
+                                self.cr.rotate(rot);
+                            }
+
                             let stroke_paint =
                                 span.stroke_paint.to_user_space(&bbox, &view_params, values);
                             let had_paint_server =
@@ -1425,6 +1437,8 @@ impl DrawingCtx {
                                 bbox.insert(&ib);
                                 self.cr.stroke()?;
                             }
+
+                            self.cr.set_matrix(matrix);
                         }
 
                         PaintTarget::Markers => {}
diff --git a/tests/src/reference.rs b/tests/src/reference.rs
index 177e5692..17e011cc 100644
--- a/tests/src/reference.rs
+++ b/tests/src/reference.rs
@@ -301,7 +301,6 @@ test_compare_render_output!(
                 fill="context-stroke" stroke="context-fill" stroke-width="2"/>
       </marker>
     </svg>"##,
-
     br##"<?xml version="1.0" encoding="UTF-8"?>
     <svg xmlns="http://www.w3.org/2000/svg"; width="400" height="400">
       <path d="M20,20 L200,20 L380,20" stroke="lime" stroke-width="4"/>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]