diff options
author | Madds H <madds@hollandart.io> | 2021-06-28 17:47:39 -0500 |
---|---|---|
committer | Marge Bot <marge-bot@gnome.org> | 2021-06-28 23:29:30 +0000 |
commit | bd3493836446df2ff2076665fd229bfc99d658e9 (patch) | |
tree | b7f83a674294d64b589293b01ea557cc93d23ca3 | |
parent | 9c34f72fec3ca4b07ab4214e8262aa5a589fe49b (diff) | |
download | librsvg-bd3493836446df2ff2076665fd229bfc99d658e9.tar.gz |
(#760) Resolve both context_fill and context_stroke
Also implement test for swapped context_fill and stroke
ie fill="context_stroke"
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/558>
-rw-r--r-- | src/drawing_ctx.rs | 2 | ||||
-rw-r--r-- | src/paint_server.rs | 7 | ||||
-rw-r--r-- | src/shapes.rs | 2 | ||||
-rw-r--r-- | src/text.rs | 2 | ||||
-rw-r--r-- | tests/src/reference.rs | 76 |
5 files changed, 63 insertions, 26 deletions
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs index 5ea9e9a9..97c63fc5 100644 --- a/src/drawing_ctx.rs +++ b/src/drawing_ctx.rs @@ -757,6 +757,7 @@ impl DrawingCtx { values.stroke_opacity().0, current_color, None, + None, ) .to_user_space(&bbox, ¶ms, values), ); @@ -770,6 +771,7 @@ impl DrawingCtx { values.fill_opacity().0, current_color, None, + None, ) .to_user_space(&bbox, ¶ms, values), ); diff --git a/src/paint_server.rs b/src/paint_server.rs index 5ead5e6c..70ee8b6f 100644 --- a/src/paint_server.rs +++ b/src/paint_server.rs @@ -124,7 +124,8 @@ impl PaintServer { acquired_nodes: &mut AcquiredNodes<'_>, opacity: UnitInterval, current_color: cssparser::RGBA, - context: Option<PaintSource>, + context_fill: Option<PaintSource>, + context_stroke: Option<PaintSource>, ) -> PaintSource { match self { PaintServer::Iri { @@ -201,7 +202,7 @@ impl PaintServer { } PaintServer::ContextFill => { - if let Some(paint) = context { + if let Some(paint) = context_fill { paint } else { PaintSource::None @@ -209,7 +210,7 @@ impl PaintServer { } PaintServer::ContextStroke => { - if let Some(paint) = context { + if let Some(paint) = context_stroke { paint } else { PaintSource::None diff --git a/src/shapes.rs b/src/shapes.rs index bb6bf302..17cb79df 100644 --- a/src/shapes.rs +++ b/src/shapes.rs @@ -66,6 +66,7 @@ macro_rules! impl_draw { acquired_nodes, values.stroke_opacity().0, values.color().0, + cascaded.context_fill.clone(), cascaded.context_stroke.clone(), ); @@ -74,6 +75,7 @@ macro_rules! impl_draw { values.fill_opacity().0, values.color().0, cascaded.context_fill.clone(), + cascaded.context_stroke.clone(), ); let fill_rule = values.fill_rule(); diff --git a/src/text.rs b/src/text.rs index f243587e..c83991b0 100644 --- a/src/text.rs +++ b/src/text.rs @@ -271,6 +271,7 @@ impl PositionedSpan { self.values.stroke_opacity().0, self.values.color().0, None, + None, ); let fill_paint = self.values.fill().0.resolve( @@ -278,6 +279,7 @@ impl PositionedSpan { self.values.fill_opacity().0, self.values.color().0, None, + None, ); let text_rendering = self.values.text_rendering(); diff --git a/tests/src/reference.rs b/tests/src/reference.rs index c770d9fe..427cce04 100644 --- a/tests/src/reference.rs +++ b/tests/src/reference.rs @@ -265,28 +265,58 @@ test_compare_render_output!( 400, 400, br##"<?xml version="1.0" encoding="UTF-8"?> -<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400"> - <style> - .path1 { - fill: none; - stroke-width: 4px; - marker: url(#marker1); - } - </style> - - <path class="path1" d="M20,20 L200,20 L380,20" stroke="lime"/> - - <marker id="marker1" markerWidth="12" markerHeight="12" refX="6" refY="6" - markerUnits="userSpaceOnUse"> - <circle cx="6" cy="6" r="3" - fill="white" stroke="context-stroke" stroke-width="2"/> - </marker> -</svg>"##, + <svg xmlns="http://www.w3.org/2000/svg" width="400" height="400"> + <style> + .path1 { + fill: none; + stroke-width: 4px; + marker: url(#marker1); + } + + .path2 { + fill: darkblue; + stroke: mediumseagreen; + stroke-width: 4px; + marker: url(#marker2); + } + </style> + + <path class="path1" d="M20,20 L200,20 L380,20" stroke="lime"/> + + <path class="path2" d="M20,40 h360 v320 h-360 v-320 Z"/> + + <marker id="marker1" markerWidth="12" markerHeight="12" refX="6" refY="6" + markerUnits="userSpaceOnUse"> + <circle cx="6" cy="6" r="3" + fill="white" stroke="context-stroke" stroke-width="2"/> + </marker> + + <marker id="marker2" markerWidth="12" markerHeight="12" refX="6" refY="6" + markerUnits="userSpaceOnUse"> + <!-- Note that here the paint is reversed: + fill=context-stroke, + stroke=context-fill + --> + <circle cx="6" cy="6" r="3" + 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"/> - <circle cx="20" cy="20" r="3" stroke-width="2" fill="white" stroke="lime"/> - <circle cx="200" cy="20" r="3" stroke-width="2" fill="white" stroke="lime"/> - <circle cx="380" cy="20" r="3" stroke-width="2" fill="white" stroke="lime"/> -</svg>"##, + <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"/> + <circle cx="20" cy="20" r="3" stroke-width="2" fill="white" stroke="lime"/> + <circle cx="200" cy="20" r="3" stroke-width="2" fill="white" stroke="lime"/> + <circle cx="380" cy="20" r="3" stroke-width="2" fill="white" stroke="lime"/> + + <path class="path2" d="M20,40 h360 v320 h-360 v-320 Z" fill="darkblue" + stroke="mediumseagreen" stroke-width="4"/> + <circle cx="20" cy="40" r="3" fill="mediumseagreen" stroke="darkblue" stroke-width="2"/> + <circle cx="20" cy="40" r="3" fill="mediumseagreen" stroke="darkblue" stroke-width="2"/> + <circle cx="380" cy="40" r="3" fill="mediumseagreen" stroke="darkblue" stroke-width="2"/> + <circle cx="380" cy="360" r="3" fill="mediumseagreen" stroke="darkblue" stroke-width="2"/> + <circle cx="20" cy="360" r="3" fill="mediumseagreen" stroke="darkblue" stroke-width="2"/> + <circle cx="20" cy="40" r="3" fill="mediumseagreen" stroke="darkblue" stroke-width="2"/> + </svg> + "##, ); |