RazrFalcon / resvg

An SVG rendering library.
Mozilla Public License 2.0
2.61k stars 215 forks source link

context-stroke in marker has no gradient #742

Closed yisibl closed 2 months ago

yisibl commented 2 months ago

Test SVG

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="210mm" height="297mm" viewBox="0 0 210 297" version="1.1" id="svg1"
   xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg">
   <defs id="defs1">
      <marker style="overflow:visible" id="Diamond" refX="0" refY="0" orient="auto" markerWidth="6.36396102"
         markerHeight="6.36396106" viewBox="0 0 6.36396102 6.36396106" preserveAspectRatio="xMidYMid">
         <path transform="scale(0.45)" style="fill:context-stroke;fill-rule:evenodd;stroke:none"
            d="M 0,-7.0710768 -7.0710894,0 0,7.0710589 7.0710462,0 Z" id="path19" />
      </marker>
      <linearGradient id="linearGradient4">
         <stop style="stop-color:#00ff1d;stop-opacity:1;" offset="0" id="stop3" />
         <stop style="stop-color:#3747c8;stop-opacity:1;" offset="1" id="stop4" />
      </linearGradient>
      <linearGradient xlink:href="#linearGradient4" id="linearGradient5" x1="80.862183" y1="88.780045" x2="37.325718"
         y2="89.479042" gradientUnits="userSpaceOnUse" />
      <marker style="overflow:visible" id="Diamond-3" refX="0" refY="0" orient="auto" markerWidth="6.3639612"
         markerHeight="6.3639612" viewBox="0 0 6.363961 6.3639611" preserveAspectRatio="xMidYMid">
         <path transform="scale(0.45)" style="fill:url(#linearGradient6);fill-rule:evenodd;stroke:none"
            d="M 0,-7.0710768 -7.0710894,0 0,7.0710589 7.0710462,0 Z" id="path19-5" />
      </marker>
   </defs>
   <g id="layer1">
      <path
         style="fill:none;stroke:url(#linearGradient5);stroke-width:0.499999;fill-opacity:1;marker-start:url(#Diamond)"
         d="M 58.707988,66.020116 50.400317,106.47886" id="path1" />
   </g>
</svg>

Output

context-stroke

See also: https://gitlab.com/inkscape/inkscape/-/issues/3957

RazrFalcon commented 2 months ago

@LaurenzV

LaurenzV commented 2 months ago

Yes, I'll take a look. It's probably also because of the view box, like for the pattern.

LaurenzV commented 2 months ago

@RazrFalcon Both issues are regressions from the tree viewbox flattening that was implemented recently. 👀 It works fine on previous commits:

test

test

The issue seems to be that the abs_transform of the children doesn't include the viewbox transform that is applied in the beginning.

LaurenzV commented 2 months ago

... but it's my fault after all, I'm not propagating the abs transforms when creating the marker's group:

https://github.com/RazrFalcon/resvg/blob/d5d9ff98bc61ed19296a909d38628a40d18b3574/crates/usvg/src/parser/converter.rs#L819-L824

Will try to fix tomorrow or so.

RazrFalcon commented 2 months ago

Meh... abs_transform again. Will see what I can do to avoid it. But also I though that usvg doesn't rely on abs_transform except in one place during text layouting. I guess I was wrong.

And also, we have to add tests for those cases to make sure we would not break them in the future.

PS: I'm open to any ideas about how to make abs_transform implementation easier. We cannot calculate it on demand, because we would have to have a reference to the parent node somehow. And we can't calculate it after parsing (like bboxes), because it's needed during text layouting.

LaurenzV commented 2 months ago

I have to rely on it unfortunately... But yes, I will add a test case for it.