[librsvg: 1/5] (#727) Implement paint-order for text




commit bcec7f29cf0cc831199fd2249747b8d7ff6df058
Author: Madds H <madds hollandart io>
Date:   Thu Jul 1 18:11:32 2021 -0500

    (#727) Implement paint-order for text
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/560>

 src/drawing_ctx.rs | 77 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 48 insertions(+), 29 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index 9e7fa2f6..69a20924 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -1350,6 +1350,8 @@ impl DrawingCtx {
     ) -> Result<BoundingBox, RenderingError> {
         let transform = self.get_transform();
 
+        let paint_order = values.paint_order();
+
         let gravity = span.layout.context().unwrap().gravity();
 
         let bbox = compute_text_box(&span.layout, span.x, span.y, transform, gravity);
@@ -1378,38 +1380,55 @@ impl DrawingCtx {
                 return Ok(self.empty_bbox());
             }
 
-            // Fill
-
             if span.is_visible {
-                let fill_paint = span.fill_paint.to_user_space(&bbox, &view_params, values);
-
-                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);
-                        };
-                    })?;
-            }
-
-            // Stroke
-
-            let stroke_paint = span.stroke_paint.to_user_space(&bbox, &view_params, values);
-
-            let had_paint_server = self.set_paint_source(&stroke_paint, acquired_nodes)?;
+                for &target in &paint_order.targets {
+                    match target {
+                        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 fill_paint =
+                                span.fill_paint.to_user_space(&bbox, &view_params, values);
+
+                            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);
+                                    };
+                                },
+                            )?;
+                        }
 
-            if had_paint_server {
-                pangocairo::functions::update_layout(&self.cr, &span.layout);
-                pangocairo::functions::layout_path(&self.cr, &span.layout);
+                        PaintTarget::Stroke => {
+                            //path_helper.set()?;
+                            //dc.stroke(&cr, an, &stroke_paint)?;
+                            let stroke_paint =
+                                span.stroke_paint.to_user_space(&bbox, &view_params, values);
+                            let had_paint_server =
+                                self.set_paint_source(&stroke_paint, acquired_nodes)?;
+                            if had_paint_server {
+                                pangocairo::functions::update_layout(&self.cr, &span.layout);
+                                pangocairo::functions::layout_path(&self.cr, &span.layout);
+
+                                let (x0, y0, x1, y1) = self.cr.stroke_extents()?;
+                                let r = Rect::new(x0, y0, x1, y1);
+                                let ib = BoundingBox::new()
+                                    .with_transform(transform)
+                                    .with_ink_rect(r);
+                                bbox.insert(&ib);
+                                self.cr.stroke()?;
+                            }
+                        }
 
-                let (x0, y0, x1, y1) = self.cr.stroke_extents()?;
-                let r = Rect::new(x0, y0, x1, y1);
-                let ib = BoundingBox::new()
-                    .with_transform(transform)
-                    .with_ink_rect(r);
-                bbox.insert(&ib);
-                if span.is_visible {
-                    self.cr.stroke()?;
+                        PaintTarget::Markers => {}
+                    }
                 }
             }
 


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