@@ -86,22 +86,22 @@ struct Rectangle {
8686 }
8787};
8888
89- Rc<Scene::Node> rectToSceneNode (Rectangle<f64 > rect, Opt<Gfx::Fill> fill, Opt<Gfx::Fill> strokeColor, f64 strokeWidth ) {
89+ Rc<Scene::Node> rectToSceneNode (Rectangle<f64 > rect, Opt<Gfx::Fill> fill, Opt<Gfx::Stroke> const & stroke ) {
9090 Gfx::Borders borders;
91- if (strokeColor and strokeWidth > 0 ) {
91+ if (stroke ) {
9292 borders = Gfx::Borders{
9393 Math::Radiif{},
94- Math::Insetsf{strokeWidth },
95- Array<Gfx::Fill, 4 >::fill (*strokeColor ),
94+ Math::Insetsf{stroke-> width },
95+ Array<Gfx::Fill, 4 >::fill (stroke-> fill ),
9696 Array<Gfx::BorderStyle, 4 >::fill (Gfx::BorderStyle::SOLID),
9797 };
9898
9999 // FIXME: needed due to mismatch between SVG's and Scene's box model
100100 // svg's stroke's center is at the shape's edges
101- rect.width += strokeWidth ;
102- rect.height += strokeWidth ;
103- rect.x -= strokeWidth / 2 ;
104- rect.y -= strokeWidth / 2 ;
101+ rect.width += stroke-> width ;
102+ rect.height += stroke-> width ;
103+ rect.x -= stroke-> width / 2 ;
104+ rect.y -= stroke-> width / 2 ;
105105 }
106106
107107 return makeRc<Scene::Box>(
@@ -267,18 +267,33 @@ struct ShapeFrag : Frag {
267267 unreachable ();
268268 }
269269
270+ Opt<Gfx::Stroke> _resolveStroke (SVGProps const & style, Gfx::Color currentColor) const {
271+ Opt<Gfx::Color> color = Vaev::Layout::resolve (style.stroke , currentColor);
272+ if (not color)
273+ return NONE;
274+
275+ if (Math::epsilonEq (style.strokeOpacity , 0 .))
276+ return NONE;
277+
278+ color = color->withOpacity (style.strokeOpacity );
279+
280+ if (strokeWidth == 0_au)
281+ return NONE;
282+
283+ return Gfx::Stroke{*color, static_cast <f64 >(strokeWidth)};
284+ }
285+
270286 Rc<Scene::Node> toSceneNode (Gfx::Color currentColor) const {
271- Opt<Gfx::Color> resolvedFill = Vaev::Layout::resolve (box->style ->svg ->fill , currentColor).map ([&](auto fill) {
272- return fill.withOpacity (box->style ->svg ->fillOpacity );
287+ auto const & style = *box->style ->svg ;
288+
289+ Opt<Gfx::Color> resolvedFill = Vaev::Layout::resolve (style.fill , currentColor).map ([&](auto fill) {
290+ return fill.withOpacity (style.fillOpacity );
273291 });
274- Opt<Gfx::Color> resolvedStrokeColor = Vaev::Layout::resolve (box->style ->svg ->stroke , currentColor);
275- Opt<Gfx::Stroke> resolvedStroke =
276- resolvedStrokeColor
277- ? Opt<Gfx::Stroke>{{*resolvedStrokeColor, (f64 )strokeWidth}}
278- : NONE;
292+
293+ Opt<Gfx::Stroke> resolvedStroke = _resolveStroke (style, currentColor);
279294
280295 if (auto rect = shape.is <Rectangle<Au>>()) {
281- return rectToSceneNode (rect->cast <f64 >(), resolvedFill, resolvedStrokeColor, ( f64 )strokeWidth );
296+ return rectToSceneNode (rect->cast <f64 >(), resolvedFill, resolvedStroke );
282297 } else if (auto circle = shape.is <Circle<Au>>()) {
283298 return circleToSceneNode (circle->cast <f64 >(), resolvedFill, resolvedStroke);
284299 } else if (auto path = shape.is <Rc<Math::Path>>()) {
0 commit comments