Gradient #37

Merged
merged 11 commits into from Apr 23, 2014

Projects

None yet

3 participants

@jeffreyrosenbluth
Member

This pull request accompanies #41 in -svg and #136 in -lib
*** Please do not merge yet ***

SVG and Cairo have built in support for different types of radial gradients.
SVG allows the specification of a focal point in addition to a center and radius from which the gradient eminates.
Cairo allows the specification of a torus on which the gradient lives.

The easiest way to understand the difference is to look at: http://www.w3.org/TR/SVG/pservers.html#RadialGradients

and

cairo_pattern_create_radial () in: http://cairographics.org/manual/cairo-cairo-pattern-t.html

@fryguybob
Member

Perhaps we could have gradients at the -lib level express the intersection of these forms and each backend could expose attributes with additional parameters that they can support?

@jeffreyrosenbluth
Member

@fryguybob - Yes, I think that probably makes the most sense.

Perhaps for 1.0 we will just expose the intersection?

Now that I think about it - SVG has more options for linear gradients, that is a spread method parameter.

Let's give it a bit more thought.

@byorgey byorgey and 1 other commented on an outdated diff Nov 16, 2013
src/Diagrams/Backend/Cairo/Internal.hs
@@ -371,9 +408,9 @@ instance Renderable Text Cairo where
ff <- fromMaybe "" <$> getStyleAttrib getFont
fs <- fromMaybe C.FontSlantNormal <$> getStyleAttrib (fromFontSlant . getFontSlant)
fw <- fromMaybe C.FontWeightNormal <$> getStyleAttrib (fromFontWeight . getFontWeight)
- f <- getStyleAttrib (toAlphaColour . getFillColor)
+ f <- getStyleAttrib getFillTexture--getStyleAttrib (toAlphaColour . getFillColor)
@byorgey
byorgey Nov 16, 2013 Member

Comment should be removed.

@jeffreyrosenbluth
Member

Lost the default line color - not sure why get

@jeffreyrosenbluth
Member

This code renders differently than in svg and i presume incorrectly:

{-# LANGUAGE NoMonomorphismRestriction #-}

module Main where

import           Diagrams.Prelude
import           Diagrams.Backend.Cairo.CmdLine

radial = mkRadialGradient (mkStops [(red,0,1), (gray,1,1)])  ((-0.25) ^& 0) 0.1 (0 ^& 0) 0.35 GradPad

example = square 1 # fillTexture radial

main = defaultMain $ example # centerXY # pad 1.1
@jeffreyrosenbluth
Member

Radial gradients still have same bug as pre units

{-# LANGUAGE NoMonomorphismRestriction #-}

module Main where

import           Diagrams.Prelude
import           Diagrams.Backend.Cairo.CmdLine

radial = mkRadialGradient (mkStops [(red,0,1), (gray,1,1)])  ((-0.25) ^& 0) 0.1 (0 ^& 0) 0.35 GradPad

example = square 1 # fillTexture radial -- # rotateBy(1/16)
main = defaultMain $ example
@jeffreyrosenbluth
Member

Handle gradient spread methods. Cairo also can handle a spread method of type ExtendNone
but neither SVG or Rasterific do and I don't see a use case, but it would be easy enough to
include if someone wants it.

It's possible that the bug mentioned in the previous commit is a cairo bug.

see: http://hackage.haskell.org/package/cairo-0.12.5.3/docs/Graphics-Rendering-Cairo.html#t:Extend

@jeffreyrosenbluth
Member

Fixed bug not but

@byorgey byorgey commented on an outdated diff Apr 19, 2014
src/Diagrams/Backend/Cairo/Internal.hs
+ (x1, y1) = unp2 (g^.lGradEnd)
+setTexture (Just (RG g)) = liftC $
+ C.withRadialPattern x0 y0 r0 x1 y1 r1 $ \pat -> do
+ mapM_ (addStop pat) (g^.rGradStops)
+ C.patternSetMatrix pat m
+ C.patternSetExtend pat (cairoSpreadMethod (g^.rGradSpreadMethod))
+ C.setSource pat
+ where
+ m = CM.Matrix a1 a2 b1 b2 c1 c2
+ (a1, a2, b1, b2, c1, c2) = getMatrix (inv (g^.rGradTrans))
+ (r0, r1) = ((g^.rGradRadius0), (g^.rGradRadius1))
+ (x0', y0') = unp2 (g^.rGradCenter0)
+ (x1', y1') = unp2 (g^.rGradCenter1)
+ (x0, y0, x1, y1) = (x0' * (r1-r0) / r1, y0' * (r1-r0) / r1, x1' ,y1')
+
+getMatrix :: Transformation R2 -> (Double, Double, Double, Double, Double, Double)
@byorgey
byorgey Apr 19, 2014 Member

We should use matrixRep from -core instead of reimplementing this here.

@byorgey
byorgey Apr 19, 2014 Member

In fact, I just noticed that we should do the same in -svg.

@byorgey byorgey merged commit 7209558 into master Apr 23, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
@byorgey byorgey deleted the gradient branch Apr 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment