Twinside / Rasterific

A drawing engine in Haskell
BSD 3-Clause "New" or "Revised" License
140 stars 11 forks source link

Radial Gradients radius #12

Closed jeffreyrosenbluth closed 10 years ago

jeffreyrosenbluth commented 10 years ago

We are adding gradients to diagrams and in order to do it properly in the Rasterific backend we need to be able to specify the radius as a proportion between 0 and 1. See for example the SVG definition:

http://www.w3.org/TR/SVG11/pservers.html#RadialGradients

here is an example of SVG code: http://www.w3schools.com/svg/svg_grad_radial.asp

<svg height="150" width="500">
  <defs>
    <radialGradient id="grad1" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
      <stop offset="0%" style="stop-color:rgb(255,255,255);
      stop-opacity:0" />
      <stop offset="100%" style="stop-color:rgb(0,0,255);stop-opacity:1" />
    </radialGradient>
  </defs>
  <ellipse cx="200" cy="70" rx="85" ry="55" fill="url(#grad1)" />
</svg>

that produces an elliptical gradient.

Twinside commented 10 years ago

The gradient calculation in SVG rely on object bounding boxes, as I don't have any support for bounding boxes, I can't do it quickly.

The main pain point is precise bounding box of cubic & quadratic bezier curve, otherwise it is trivial.

jeffreyrosenbluth commented 10 years ago

It turns out that I was wrong and that I don't think I need % radii. What I need are gradient transforms like Cairo and SVG have. How hard would this be to implement?

Twinside commented 10 years ago

The transformTexture function should fit the bill.

Twinside commented 10 years ago

That being said, I may implement bounding in the future, if I want to make rasterific-svg more or less standard compliant.

jeffreyrosenbluth commented 10 years ago

cool, somehow I missed this :)

On Fri, Apr 18, 2014 at 4:09 AM, Vincent notifications@github.com wrote:

The transformTexturehttp://hackage.haskell.org/package/Rasterific-0.2/docs/Graphics-Rasterific-Texture.html#v:transformTexturefunction should fit the bill.

— Reply to this email directly or view it on GitHubhttps://github.com/Twinside/Rasterific/issues/12#issuecomment-40794109 .