Skip to content

Commit

Permalink
update for R2 generalization in -lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Yorgey committed Mar 27, 2013
1 parent e382d4b commit e1d4076
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
17 changes: 9 additions & 8 deletions src/Diagrams/Backend/Cairo.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE TypeFamilies, CPP #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeFamilies #-}

-----------------------------------------------------------------------------
-- |
Expand Down Expand Up @@ -37,7 +38,7 @@
--
-- > data family Options Cairo R2 = CairoOptions
-- > { cairoFileName :: String -- ^ The name of the file you want generated
-- > , cairoSizeSpec :: SizeSpec2D -- ^ The requested size of the output
-- > , cairoSizeSpec :: SizeSpec2D Double -- ^ The requested size of the output
-- > , cairoOutputType :: OutputType -- ^ the output format and associated options
-- > , cairoBypassAdjust :: Bool -- ^ Should the 'adjustDia' step be bypassed during rendering?
-- > }
Expand Down Expand Up @@ -94,10 +95,10 @@ module Diagrams.Backend.Cairo
, Cairo(..)
) where

import System.FilePath (takeExtension)
import System.FilePath (takeExtension)

import Diagrams.Backend.Cairo.Internal
import Diagrams.Prelude
import Diagrams.Backend.Cairo.Internal
import Diagrams.Prelude

-- $CairoOptions
--
Expand All @@ -107,7 +108,7 @@ import Diagrams.Prelude
--
-- > data family Options Cairo R2 = CairoOptions
-- > { cairoFileName :: String -- ^ The name of the file you want generated
-- > , cairoSizeSpec :: SizeSpec2D -- ^ The requested size of the output
-- > , cairoSizeSpec :: SizeSpec2D Double -- ^ The requested size of the output
-- > , cairoOutputType :: OutputType -- ^ the output format and associated options
-- > }
--
Expand All @@ -128,7 +129,7 @@ import Diagrams.Prelude
-- This function is provided as a convenience; if you need more
-- flexibility than it provides, you can call 'renderDia' directly,
-- as described above.
renderCairo :: FilePath -> SizeSpec2D -> Diagram Cairo R2 -> IO ()
renderCairo :: FilePath -> SizeSpec2D Double -> Diagram Cairo R2 -> IO ()
renderCairo outFile sizeSpec d
= fst (renderDia Cairo (CairoOptions outFile sizeSpec outTy False) d)
where
Expand All @@ -138,4 +139,4 @@ renderCairo outFile sizeSpec d
".ps" -> PS
".pdf" -> PDF
".svg" -> SVG
_ -> PNG
_ -> PNG
10 changes: 5 additions & 5 deletions src/Diagrams/Backend/Cairo/Internal.hs
Expand Up @@ -111,9 +111,9 @@ instance Backend Cairo R2 where
type Result Cairo R2 = (IO (), C.Render ())
data Options Cairo R2 = CairoOptions
{ cairoFileName :: String -- ^ The name of the file you want generated
, cairoSizeSpec :: SizeSpec2D -- ^ The requested size of the output
, cairoSizeSpec :: SizeSpec2D Double -- ^ The requested size of the output
, cairoOutputType :: OutputType -- ^ the output format and associated options
, cairoBypassAdjust :: Bool -- ^ Should the 'adjustDia' step be bypassed during rendering?
, cairoBypassAdjust :: Bool -- ^ Should the 'adjustDia' step be bypassed during rendering?
}
deriving Show

Expand Down Expand Up @@ -228,7 +228,7 @@ setSource c s = C.setSourceRGBA r g b a'

-- | Multiply the current transformation matrix by the given 2D
-- transformation.
cairoTransf :: T2 -> C.Render ()
cairoTransf :: T2D -> C.Render ()
cairoTransf t = C.transform m
where m = CM.Matrix a1 a2 b1 b2 c1 c2
(unr2 -> (a1,a2)) = apply t unitX
Expand Down Expand Up @@ -276,7 +276,7 @@ instance Renderable (Path R2) Cairo where


-- Can only do PNG files at the moment...
instance Renderable Image Cairo where
instance Renderable (Image Double) Cairo where
render _ (Image file sz tr) = C . lift $ do
if ".png" `isSuffixOf` file
then do
Expand All @@ -303,7 +303,7 @@ instance Renderable Image Cairo where
]

-- see http://www.cairographics.org/tutorial/#L1understandingtext
instance Renderable Text Cairo where
instance Renderable (Text Double) Cairo where
render _ (Text tr al str) = C $ do
lift $ do
C.save
Expand Down

0 comments on commit e1d4076

Please sign in to comment.