-- GENERATED by C->Haskell Compiler, version 0.13.12 (gtk2hs branch) "Bin IO", 27 May 2012 (Haskell)
-- Edit the ORIGNAL .chs file instead!

{-# LANGUAGE RecordWildCards #-}

{-# LINE 1 "./Graphics/Rendering/Cairo/Types.chs" #-}
{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  Graphics.Rendering.Cairo.Types
-- Copyright   :  (c) Paolo Martini 2005
-- License     :  BSD-style (see cairo/COPYRIGHT)
--
-- Maintainer  :  p.martini@neuralnoise.com
-- Stability   :  experimental
-- Portability :  portable
--
-- Haskell bindings to the cairo types.
-----------------------------------------------------------------------------

-- #hide
module Graphics.Rendering.Cairo.Types (
    PixelData
  , Matrix(Matrix), MatrixPtr
  , Cairo(Cairo), unCairo
  , Surface(Surface), withSurface, mkSurface, manageSurface
  , Pattern(Pattern), unPattern
  , Status(..)
  , Operator(..)
  , Antialias(..)
  , FillRule(..)
  , LineCap(..)
  , LineJoin(..)
  , ScaledFont(..), unScaledFont
  , FontFace(..), unFontFace
  , Glyph, unGlyph
  , TextExtentsPtr
  , TextExtents(..)
  , FontExtentsPtr
  , FontExtents(..)
  , FontSlant(..)
  , FontWeight(..)
  , SubpixelOrder(..)
  , HintStyle(..)
  , HintMetrics(..)
  , FontOptions(..), withFontOptions, mkFontOptions
  , Path(..), unPath
  , RectangleInt(..)
  , RegionOverlap(..)
  , Region(..), withRegion, mkRegion
  , Content(..)
  , Format(..)
  , Extend(..)
  , Filter(..)

  , cIntConv
  , cFloatConv
  , cFromBool
  , cToBool
  , cToEnum
  , cFromEnum
  , peekFloatConv
  , withFloatConv

  ) where

import Graphics.Rendering.Cairo.Matrix
{-# LINE 64 "./Graphics/Rendering/Cairo/Types.chs" #-}

import Foreign hiding (rotate)
import Foreign.C

import Control.Monad (liftM)


{-# LINE 71 "./Graphics/Rendering/Cairo/Types.chs" #-}

type PixelData = Ptr CUChar

-- not visible
newtype Cairo = Cairo (Ptr (Cairo))
{-# LINE 76 "./Graphics/Rendering/Cairo/Types.chs" #-}
unCairo (Cairo x) = x

-- | The medium to draw on.
newtype Surface = Surface (ForeignPtr (Surface))
{-# LINE 80 "./Graphics/Rendering/Cairo/Types.chs" #-}
withSurface (Surface x) = withForeignPtr x

mkSurface :: Ptr Surface -> IO Surface
mkSurface surfacePtr = do
  surfaceForeignPtr <- newForeignPtr_ surfacePtr
  return (Surface surfaceForeignPtr)

manageSurface :: Surface -> IO ()
manageSurface (Surface surfaceForeignPtr) = do
  addForeignPtrFinalizer surfaceDestroy surfaceForeignPtr

foreign import ccall unsafe "&cairo_surface_destroy"
  surfaceDestroy :: FinalizerPtr Surface

-- | Patterns can be simple solid colors, various kinds of gradients or
-- bitmaps. The current pattern for a 'Render' context is used by the 'stroke',
-- 'fill' and paint operations. These operations composite the current pattern
-- with the target surface using the currently selected 'Operator'.
--
newtype Pattern = Pattern (Ptr (Pattern))
{-# LINE 100 "./Graphics/Rendering/Cairo/Types.chs" #-}
unPattern (Pattern x) = x

-- | Cairo status.
--
-- * 'Status' is used to indicate errors that can occur when using
--   Cairo. In some cases it is returned directly by functions. When using
--   'Graphics.Rendering.Cairo.Render', the last error, if any, is stored
--   in the monad and can be retrieved with 'Graphics.Rendering.Cairo.status'.
--
data Status = StatusSuccess
            | StatusNoMemory
            | StatusInvalidRestore
            | StatusInvalidPopGroup
            | StatusNoCurrentPoint
            | StatusInvalidMatrix
            | StatusInvalidStatus
            | StatusNullPointer
            | StatusInvalidString
            | StatusInvalidPathData
            | StatusReadError
            | StatusWriteError
            | StatusSurfaceFinished
            | StatusSurfaceTypeMismatch
            | StatusPatternTypeMismatch
            | StatusInvalidContent
            | StatusInvalidFormat
            | StatusInvalidVisual
            | StatusFileNotFound
            | StatusInvalidDash
            | StatusInvalidDscComment
            | StatusInvalidIndex
            | StatusClipNotRepresentable
            | StatusTempFileError
            | StatusInvalidStride
            | StatusFontTypeMismatch
            | StatusUserFontImmutable
            | StatusUserFontError
            | StatusNegativeCount
            | StatusInvalidClusters
            | StatusInvalidSlant
            | StatusInvalidWeight
            | StatusInvalidSize
            | StatusUserFontNotImplemented
            | StatusDeviceTypeMismatch
            | StatusDeviceError
            | StatusInvalidMeshConstruction
            | StatusDeviceFinished
            | StatusLastStatus
            deriving (Eq,Show)
instance Enum Status where
  fromEnum StatusSuccess = 0
  fromEnum StatusNoMemory = 1
  fromEnum StatusInvalidRestore = 2
  fromEnum StatusInvalidPopGroup = 3
  fromEnum StatusNoCurrentPoint = 4
  fromEnum StatusInvalidMatrix = 5
  fromEnum StatusInvalidStatus = 6
  fromEnum StatusNullPointer = 7
  fromEnum StatusInvalidString = 8
  fromEnum StatusInvalidPathData = 9
  fromEnum StatusReadError = 10
  fromEnum StatusWriteError = 11
  fromEnum StatusSurfaceFinished = 12
  fromEnum StatusSurfaceTypeMismatch = 13
  fromEnum StatusPatternTypeMismatch = 14
  fromEnum StatusInvalidContent = 15
  fromEnum StatusInvalidFormat = 16
  fromEnum StatusInvalidVisual = 17
  fromEnum StatusFileNotFound = 18
  fromEnum StatusInvalidDash = 19
  fromEnum StatusInvalidDscComment = 20
  fromEnum StatusInvalidIndex = 21
  fromEnum StatusClipNotRepresentable = 22
  fromEnum StatusTempFileError = 23
  fromEnum StatusInvalidStride = 24
  fromEnum StatusFontTypeMismatch = 25
  fromEnum StatusUserFontImmutable = 26
  fromEnum StatusUserFontError = 27
  fromEnum StatusNegativeCount = 28
  fromEnum StatusInvalidClusters = 29
  fromEnum StatusInvalidSlant = 30
  fromEnum StatusInvalidWeight = 31
  fromEnum StatusInvalidSize = 32
  fromEnum StatusUserFontNotImplemented = 33
  fromEnum StatusDeviceTypeMismatch = 34
  fromEnum StatusDeviceError = 35
  fromEnum StatusInvalidMeshConstruction = 36
  fromEnum StatusDeviceFinished = 37
  fromEnum StatusLastStatus = 38

  toEnum 0 = StatusSuccess
  toEnum 1 = StatusNoMemory
  toEnum 2 = StatusInvalidRestore
  toEnum 3 = StatusInvalidPopGroup
  toEnum 4 = StatusNoCurrentPoint
  toEnum 5 = StatusInvalidMatrix
  toEnum 6 = StatusInvalidStatus
  toEnum 7 = StatusNullPointer
  toEnum 8 = StatusInvalidString
  toEnum 9 = StatusInvalidPathData
  toEnum 10 = StatusReadError
  toEnum 11 = StatusWriteError
  toEnum 12 = StatusSurfaceFinished
  toEnum 13 = StatusSurfaceTypeMismatch
  toEnum 14 = StatusPatternTypeMismatch
  toEnum 15 = StatusInvalidContent
  toEnum 16 = StatusInvalidFormat
  toEnum 17 = StatusInvalidVisual
  toEnum 18 = StatusFileNotFound
  toEnum 19 = StatusInvalidDash
  toEnum 20 = StatusInvalidDscComment
  toEnum 21 = StatusInvalidIndex
  toEnum 22 = StatusClipNotRepresentable
  toEnum 23 = StatusTempFileError
  toEnum 24 = StatusInvalidStride
  toEnum 25 = StatusFontTypeMismatch
  toEnum 26 = StatusUserFontImmutable
  toEnum 27 = StatusUserFontError
  toEnum 28 = StatusNegativeCount
  toEnum 29 = StatusInvalidClusters
  toEnum 30 = StatusInvalidSlant
  toEnum 31 = StatusInvalidWeight
  toEnum 32 = StatusInvalidSize
  toEnum 33 = StatusUserFontNotImplemented
  toEnum 34 = StatusDeviceTypeMismatch
  toEnum 35 = StatusDeviceError
  toEnum 36 = StatusInvalidMeshConstruction
  toEnum 37 = StatusDeviceFinished
  toEnum 38 = StatusLastStatus
  toEnum unmatched = error ("Status.toEnum: Cannot match " ++ show unmatched)

  succ StatusSuccess = StatusNoMemory
  succ StatusNoMemory = StatusInvalidRestore
  succ StatusInvalidRestore = StatusInvalidPopGroup
  succ StatusInvalidPopGroup = StatusNoCurrentPoint
  succ StatusNoCurrentPoint = StatusInvalidMatrix
  succ StatusInvalidMatrix = StatusInvalidStatus
  succ StatusInvalidStatus = StatusNullPointer
  succ StatusNullPointer = StatusInvalidString
  succ StatusInvalidString = StatusInvalidPathData
  succ StatusInvalidPathData = StatusReadError
  succ StatusReadError = StatusWriteError
  succ StatusWriteError = StatusSurfaceFinished
  succ StatusSurfaceFinished = StatusSurfaceTypeMismatch
  succ StatusSurfaceTypeMismatch = StatusPatternTypeMismatch
  succ StatusPatternTypeMismatch = StatusInvalidContent
  succ StatusInvalidContent = StatusInvalidFormat
  succ StatusInvalidFormat = StatusInvalidVisual
  succ StatusInvalidVisual = StatusFileNotFound
  succ StatusFileNotFound = StatusInvalidDash
  succ StatusInvalidDash = StatusInvalidDscComment
  succ StatusInvalidDscComment = StatusInvalidIndex
  succ StatusInvalidIndex = StatusClipNotRepresentable
  succ StatusClipNotRepresentable = StatusTempFileError
  succ StatusTempFileError = StatusInvalidStride
  succ StatusInvalidStride = StatusFontTypeMismatch
  succ StatusFontTypeMismatch = StatusUserFontImmutable
  succ StatusUserFontImmutable = StatusUserFontError
  succ StatusUserFontError = StatusNegativeCount
  succ StatusNegativeCount = StatusInvalidClusters
  succ StatusInvalidClusters = StatusInvalidSlant
  succ StatusInvalidSlant = StatusInvalidWeight
  succ StatusInvalidWeight = StatusInvalidSize
  succ StatusInvalidSize = StatusUserFontNotImplemented
  succ StatusUserFontNotImplemented = StatusDeviceTypeMismatch
  succ StatusDeviceTypeMismatch = StatusDeviceError
  succ StatusDeviceError = StatusInvalidMeshConstruction
  succ StatusInvalidMeshConstruction = StatusDeviceFinished
  succ StatusDeviceFinished = StatusLastStatus
  succ _ = undefined

  pred StatusNoMemory = StatusSuccess
  pred StatusInvalidRestore = StatusNoMemory
  pred StatusInvalidPopGroup = StatusInvalidRestore
  pred StatusNoCurrentPoint = StatusInvalidPopGroup
  pred StatusInvalidMatrix = StatusNoCurrentPoint
  pred StatusInvalidStatus = StatusInvalidMatrix
  pred StatusNullPointer = StatusInvalidStatus
  pred StatusInvalidString = StatusNullPointer
  pred StatusInvalidPathData = StatusInvalidString
  pred StatusReadError = StatusInvalidPathData
  pred StatusWriteError = StatusReadError
  pred StatusSurfaceFinished = StatusWriteError
  pred StatusSurfaceTypeMismatch = StatusSurfaceFinished
  pred StatusPatternTypeMismatch = StatusSurfaceTypeMismatch
  pred StatusInvalidContent = StatusPatternTypeMismatch
  pred StatusInvalidFormat = StatusInvalidContent
  pred StatusInvalidVisual = StatusInvalidFormat
  pred StatusFileNotFound = StatusInvalidVisual
  pred StatusInvalidDash = StatusFileNotFound
  pred StatusInvalidDscComment = StatusInvalidDash
  pred StatusInvalidIndex = StatusInvalidDscComment
  pred StatusClipNotRepresentable = StatusInvalidIndex
  pred StatusTempFileError = StatusClipNotRepresentable
  pred StatusInvalidStride = StatusTempFileError
  pred StatusFontTypeMismatch = StatusInvalidStride
  pred StatusUserFontImmutable = StatusFontTypeMismatch
  pred StatusUserFontError = StatusUserFontImmutable
  pred StatusNegativeCount = StatusUserFontError
  pred StatusInvalidClusters = StatusNegativeCount
  pred StatusInvalidSlant = StatusInvalidClusters
  pred StatusInvalidWeight = StatusInvalidSlant
  pred StatusInvalidSize = StatusInvalidWeight
  pred StatusUserFontNotImplemented = StatusInvalidSize
  pred StatusDeviceTypeMismatch = StatusUserFontNotImplemented
  pred StatusDeviceError = StatusDeviceTypeMismatch
  pred StatusInvalidMeshConstruction = StatusDeviceError
  pred StatusDeviceFinished = StatusInvalidMeshConstruction
  pred StatusLastStatus = StatusDeviceFinished
  pred _ = undefined

  enumFromTo x y | fromEnum x == fromEnum y = [ y ]
                 | otherwise = x : enumFromTo (succ x) y
  enumFrom x = enumFromTo x StatusLastStatus
  enumFromThen _ _ =     error "Enum Status: enumFromThen not implemented"
  enumFromThenTo _ _ _ =     error "Enum Status: enumFromThenTo not implemented"

{-# LINE 110 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Composition operator for all drawing operations.
--
data Operator = OperatorClear
              | OperatorSource
              | OperatorOver
              | OperatorIn
              | OperatorOut
              | OperatorAtop
              | OperatorDest
              | OperatorDestOver
              | OperatorDestIn
              | OperatorDestOut
              | OperatorDestAtop
              | OperatorXor
              | OperatorAdd
              | OperatorSaturate
              | OperatorMultiply
              | OperatorScreen
              | OperatorOverlay
              | OperatorDarken
              | OperatorLighten
              | OperatorColorDodge
              | OperatorColorBurn
              | OperatorHardLight
              | OperatorSoftLight
              | OperatorDifference
              | OperatorExclusion
              | OperatorHslHue
              | OperatorHslSaturation
              | OperatorHslColor
              | OperatorHslLuminosity
              deriving (Enum,Eq,Show)

{-# LINE 114 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Specifies the type of antialiasing to do when rendering text or shapes
--
-- ['AntialiasDefault']  Use the default antialiasing for the subsystem
-- and target device.
--
-- ['AntialiasNone']  Use a bilevel alpha mask.
--
-- ['AntialiasGray']  Perform single-color antialiasing (using shades of
-- gray for black text on a white background, for example).
--
-- ['AntialiasSubpixel']  Perform antialiasing by taking advantage of
-- the order of subpixel elements on devices such as LCD panels.
--
data Antialias = AntialiasDefault
               | AntialiasNone
               | AntialiasGray
               | AntialiasSubpixel
               | AntialiasFast
               | AntialiasGood
               | AntialiasBest
               deriving (Enum,Eq,Show)

{-# LINE 129 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Specify how paths are filled.
--
-- * For both fill rules, whether or not a point is included in the fill is
--   determined by taking a ray from that point to infinity and looking at
--   intersections with the path. The ray can be in any direction, as long
--   as it doesn't pass through the end point of a segment or have a tricky
--   intersection such as intersecting tangent to the path. (Note that
--   filling is not actually implemented in this way. This is just a
--   description of the rule that is applied.)
--
-- ['FillRuleWinding']  If the path crosses the ray from left-to-right,
--   counts +1. If the path crosses the ray from right to left, counts -1.
--   (Left and right are determined from the perspective of looking along
--   the ray from the starting point.) If the total count is non-zero, the
--   point will be filled.
--
-- ['FillRuleEvenOdd']  Counts the total number of intersections,
--   without regard to the orientation of the contour. If the total number
--   of intersections is odd, the point will be filled.
--
data FillRule = FillRuleWinding
              | FillRuleEvenOdd
              deriving (Enum,Eq,Show)

{-# LINE 151 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Specify line endings.
--
-- ['LineCapButt'] Start(stop) the line exactly at the start(end) point.
--
-- ['LineCapRound'] Use a round ending, the center of the circle is the
--   end point.
--
-- ['LineCapSquare'] Use squared ending, the center of the square is the
--   end point
--
data LineCap = LineCapButt
             | LineCapRound
             | LineCapSquare
             deriving (Enum,Eq,Show)

{-# LINE 163 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Specify how lines join.
--
data LineJoin = LineJoinMiter
              | LineJoinRound
              | LineJoinBevel
              deriving (Enum,Eq,Show)

{-# LINE 167 "./Graphics/Rendering/Cairo/Types.chs" #-}

newtype ScaledFont = ScaledFont (Ptr (ScaledFont))
{-# LINE 169 "./Graphics/Rendering/Cairo/Types.chs" #-}
unScaledFont (ScaledFont x) = x

newtype FontFace = FontFace (Ptr (FontFace))
{-# LINE 172 "./Graphics/Rendering/Cairo/Types.chs" #-}
unFontFace (FontFace x) = x

newtype Glyph = Glyph (Ptr (Glyph))
{-# LINE 175 "./Graphics/Rendering/Cairo/Types.chs" #-}
unGlyph (Glyph x) = x

type TextExtentsPtr = Ptr (TextExtents)
{-# LINE 178 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Specify the extents of a text.
data TextExtents = TextExtents {
    textExtentsXbearing :: Double
  , textExtentsYbearing :: Double
  , textExtentsWidth    :: Double
  , textExtentsHeight   :: Double
  , textExtentsXadvance :: Double
  , textExtentsYadvance :: Double
  }

instance Storable TextExtents where
  sizeOf _ = 48
{-# LINE 191 "./Graphics/Rendering/Cairo/Types.chs" #-}
  alignment _ = alignment (undefined :: CDouble)
  peek p = do
    x_bearing <- (\ptr -> do {peekByteOff ptr 0 ::IO CDouble}) p
    y_bearing <- (\ptr -> do {peekByteOff ptr 8 ::IO CDouble}) p
    width     <- (\ptr -> do {peekByteOff ptr 16 ::IO CDouble})     p
    height    <- (\ptr -> do {peekByteOff ptr 24 ::IO CDouble})    p
    x_advance <- (\ptr -> do {peekByteOff ptr 32 ::IO CDouble}) p
    y_advance <- (\ptr -> do {peekByteOff ptr 40 ::IO CDouble}) p
    return $ TextExtents (cFloatConv x_bearing) (cFloatConv y_bearing)
                         (cFloatConv width)     (cFloatConv height)
                         (cFloatConv x_advance) (cFloatConv y_advance)
  poke p (TextExtents x_bearing y_bearing width height x_advance y_advance) = do
    (\ptr val -> do {pokeByteOff ptr 0 (val::CDouble)}) p (cFloatConv x_bearing)
    (\ptr val -> do {pokeByteOff ptr 8 (val::CDouble)}) p (cFloatConv y_bearing)
    (\ptr val -> do {pokeByteOff ptr 16 (val::CDouble)})     p (cFloatConv width)
    (\ptr val -> do {pokeByteOff ptr 24 (val::CDouble)})    p (cFloatConv height)
    (\ptr val -> do {pokeByteOff ptr 32 (val::CDouble)}) p (cFloatConv x_advance)
    (\ptr val -> do {pokeByteOff ptr 40 (val::CDouble)}) p (cFloatConv y_advance)
    return ()

type FontExtentsPtr = Ptr (FontExtents)
{-# LINE 212 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Result of querying the font extents.
data FontExtents = FontExtents {
    fontExtentsAscent      :: Double
  , fontExtentsDescent     :: Double
  , fontExtentsHeight      :: Double
  , fontExtentsMaxXadvance :: Double
  , fontExtentsMaxYadvance :: Double
  }

instance Storable FontExtents where
  sizeOf _ = 40
{-# LINE 224 "./Graphics/Rendering/Cairo/Types.chs" #-}
  alignment _ = alignment (undefined :: CDouble)
  peek p = do
    ascent        <- (\ptr -> do {peekByteOff ptr 0 ::IO CDouble})        p
    descent       <- (\ptr -> do {peekByteOff ptr 8 ::IO CDouble})       p
    height        <- (\ptr -> do {peekByteOff ptr 16 ::IO CDouble})        p
    max_x_advance <- (\ptr -> do {peekByteOff ptr 24 ::IO CDouble}) p
    max_y_advance <- (\ptr -> do {peekByteOff ptr 32 ::IO CDouble}) p
    return $ FontExtents (cFloatConv ascent) (cFloatConv descent) (cFloatConv height)
                         (cFloatConv max_x_advance) (cFloatConv max_y_advance)
  poke p (FontExtents ascent descent height max_x_advance max_y_advance) = do
    (\ptr val -> do {pokeByteOff ptr 0 (val::CDouble)})        p (cFloatConv ascent)
    (\ptr val -> do {pokeByteOff ptr 8 (val::CDouble)})       p (cFloatConv descent)
    (\ptr val -> do {pokeByteOff ptr 16 (val::CDouble)})        p (cFloatConv height)
    (\ptr val -> do {pokeByteOff ptr 24 (val::CDouble)}) p (cFloatConv max_x_advance)
    (\ptr val -> do {pokeByteOff ptr 32 (val::CDouble)}) p (cFloatConv max_y_advance)
    return ()

-- | Specify font slant.
data FontSlant = FontSlantNormal
               | FontSlantItalic
               | FontSlantOblique
               deriving (Enum,Eq,Show)

{-# LINE 243 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Specify font weight.
data FontWeight = FontWeightNormal
                | FontWeightBold
                deriving (Enum,Eq,Show)

{-# LINE 246 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | The subpixel order specifies the order of color elements within each pixel
-- on the display device when rendering with an antialiasing mode of
-- 'AntialiasSubpixel'.
--
-- ['SubpixelOrderDefault'] Use the default subpixel order for for the
--                          target device
--
-- ['SubpixelOrderRgb']     Subpixel elements are arranged horizontally
--                          with red at the left
--
-- ['SubpixelOrderBgr']     Subpixel elements are arranged horizontally
--                          with blue at the left
--
-- ['SubpixelOrderVrgb']    Subpixel elements are arranged vertically
--                          with red at the top
--
-- ['SubpixelOrderVbgr']    Subpixel elements are arranged vertically
--                          with blue at the top
--
data SubpixelOrder = SubpixelOrderDefault
                   | SubpixelOrderRgb
                   | SubpixelOrderBgr
                   | SubpixelOrderVrgb
                   | SubpixelOrderVbgr
                   deriving (Enum,Eq,Show)

{-# LINE 267 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Specifies the type of hinting to do on font outlines.
--
-- Hinting is the process of fitting outlines to the pixel grid in order to
-- improve the appearance of the result. Since hinting outlines involves
-- distorting them, it also reduces the faithfulness to the original outline
-- shapes. Not all of the outline hinting styles are supported by all font
-- backends.
--
-- ['HintStyleDefault']  Use the default hint style for for font backend and
--                       target device
--
-- ['HintStyleNone']     Do not hint outlines
--
-- ['HintStyleSlight']   Hint outlines slightly to improve contrast while
--                       retaining good fidelity to the original shapes.
--
-- ['HintStyleMedium']   Hint outlines with medium strength giving a compromise
--                       between fidelity to the original shapes and contrast
--
-- ['HintStyleFull']     Hint outlines to maximize contrast
--
data HintStyle = HintStyleDefault
               | HintStyleNone
               | HintStyleSlight
               | HintStyleMedium
               | HintStyleFull
               deriving (Enum)

{-# LINE 290 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Specifies whether to hint font metrics.
--
-- Hinting font metrics means quantizing them so that they are integer values
-- in device space. Doing this improves the consistency of letter and line
-- spacing, however it also means that text will be laid out differently at
-- different zoom factors.
--
-- ['HintMetricsDefault']  Hint metrics in the default manner for the font
--                         backend and target device
--
-- ['HintMetricsOff']      Do not hint font metrics
--
-- ['HintMetricsOn']       Hint font metrics
--
--
data HintMetrics = HintMetricsDefault
                 | HintMetricsOff
                 | HintMetricsOn
                 deriving (Enum,Eq,Show)

{-# LINE 307 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Specifies how to render text.
newtype FontOptions = FontOptions (ForeignPtr (FontOptions))
{-# LINE 310 "./Graphics/Rendering/Cairo/Types.chs" #-}

withFontOptions (FontOptions fptr) = withForeignPtr fptr

mkFontOptions :: Ptr FontOptions -> IO FontOptions
mkFontOptions fontOptionsPtr = do
  fontOptionsForeignPtr <- newForeignPtr fontOptionsDestroy fontOptionsPtr
  return (FontOptions fontOptionsForeignPtr)

foreign import ccall unsafe "&cairo_font_options_destroy"
  fontOptionsDestroy :: FinalizerPtr FontOptions

-- XXX: pathToList :: Path -> [PathData]
--
-- http://cairographics.org/manual/bindings-path.html
--
-- {#enum path_data_type_t as PathDataType {underscoreToCase}#}
--
-- type Point = (Double, Double)
-- data PathData = PathMoveTo Point
--               | PathLineTo Point
--               | PathCurveTo Point Point Point
--               | PathClose

-- | A Cairo path.
--
-- * A path is a sequence of drawing operations that are accumulated until
--   'Graphics.Rendering.Cairo.stroke' is called. Using a path is particularly
--   useful when drawing lines with special join styles and
--   'Graphics.Rendering.Cairo.closePath'.
--
newtype Path = Path (Ptr (Path))
{-# LINE 341 "./Graphics/Rendering/Cairo/Types.chs" #-}
unPath (Path x) = x


type RectangleIntPtr = Ptr (RectangleInt)
{-# LINE 346 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | A data structure for holding a rectangle with integer coordinates.
data RectangleInt = RectangleInt {
    x      :: Int
  , y      :: Int
  , width  :: Int
  , height :: Int
  }

instance Storable RectangleInt where
  sizeOf _ = 16
{-# LINE 357 "./Graphics/Rendering/Cairo/Types.chs" #-}
  alignment _ = alignment (undefined :: CInt)
  peek p = do
    x      <- (\ptr -> do {peekByteOff ptr 0 ::IO CInt})      p
    y      <- (\ptr -> do {peekByteOff ptr 4 ::IO CInt})      p
    width  <- (\ptr -> do {peekByteOff ptr 8 ::IO CInt})  p
    height <- (\ptr -> do {peekByteOff ptr 12 ::IO CInt}) p
    return $ RectangleInt (fromIntegral x) (fromIntegral y) (fromIntegral width) (fromIntegral height)
  poke p (RectangleInt {..}) = do
    (\ptr val -> do {pokeByteOff ptr 0 (val::CInt)})      p (fromIntegral x)
    (\ptr val -> do {pokeByteOff ptr 4 (val::CInt)})      p (fromIntegral y)
    (\ptr val -> do {pokeByteOff ptr 8 (val::CInt)})  p (fromIntegral width)
    (\ptr val -> do {pokeByteOff ptr 12 (val::CInt)}) p (fromIntegral height)
    return ()

-- | Used as the return value for regionContainsRectangle.
data RegionOverlap = RegionOverlapIn
                   | RegionOverlapOut
                   | RegionOverlapPart
                   deriving (Enum,Eq,Show)

{-# LINE 373 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | A Cairo region. Represents a set of integer-aligned rectangles.
--
-- It allows set-theoretical operations like regionUnion and regionIntersect to be performed on them.
newtype Region = Region (ForeignPtr (Region))
{-# LINE 378 "./Graphics/Rendering/Cairo/Types.chs" #-}

withRegion (Region fptr) = withForeignPtr fptr

mkRegion :: Ptr Region -> IO Region
mkRegion regionPtr = do
  regionForeignPtr <- newForeignPtr regionDestroy regionPtr
  return (Region regionForeignPtr)

foreign import ccall unsafe "&cairo_region_destroy"
  regionDestroy :: FinalizerPtr Region


data Content = ContentColor
             | ContentAlpha
             | ContentColorAlpha
             deriving (Eq,Show)
instance Enum Content where
  fromEnum ContentColor = 4096
  fromEnum ContentAlpha = 8192
  fromEnum ContentColorAlpha = 12288

  toEnum 4096 = ContentColor
  toEnum 8192 = ContentAlpha
  toEnum 12288 = ContentColorAlpha
  toEnum unmatched = error ("Content.toEnum: Cannot match " ++ show unmatched)

  succ ContentColor = ContentAlpha
  succ ContentAlpha = ContentColorAlpha
  succ _ = undefined

  pred ContentAlpha = ContentColor
  pred ContentColorAlpha = ContentAlpha
  pred _ = undefined

  enumFromTo x y | fromEnum x == fromEnum y = [ y ]
                 | otherwise = x : enumFromTo (succ x) y
  enumFrom x = enumFromTo x ContentColorAlpha
  enumFromThen _ _ =     error "Enum Content: enumFromThen not implemented"
  enumFromThenTo _ _ _ =     error "Enum Content: enumFromThenTo not implemented"

{-# LINE 392 "./Graphics/Rendering/Cairo/Types.chs" #-}

data Format = FormatARGB32
            | FormatRGB24
            | FormatA8
            | FormatA1
            deriving (Enum,Show,Eq)

-- | FIXME: We should find out about this.
data Extend = ExtendNone
            | ExtendRepeat
            | ExtendReflect
            | ExtendPad
            deriving (Enum,Eq,Show)

{-# LINE 401 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- | Specify how filtering is done.
data Filter = FilterFast
            | FilterGood
            | FilterBest
            | FilterNearest
            | FilterBilinear
            | FilterGaussian
            deriving (Enum,Eq,Show)

{-# LINE 404 "./Graphics/Rendering/Cairo/Types.chs" #-}

-- Marshalling functions

{-# INLINE cIntConv #-}
cIntConv :: (Integral a, Integral b) => a -> b
cIntConv  = fromIntegral

{-# INLINE cFloatConv #-}
cFloatConv :: (RealFloat a, RealFloat b) => a -> b
cFloatConv  = realToFrac

{-# INLINE cFromBool #-}
cFromBool :: Num a => Bool -> a
cFromBool  = fromBool

{-# INLINE cToBool #-}
cToBool :: (Eq a, Num a) => a -> Bool
cToBool  = toBool

{-# INLINE cToEnum #-}
cToEnum :: (Integral i, Enum e) => i -> e
cToEnum  = toEnum . cIntConv

{-# INLINE cFromEnum #-}
cFromEnum :: (Enum e, Integral i) => e -> i
cFromEnum  = cIntConv . fromEnum

{-# INLINE peekFloatConv #-}
peekFloatConv :: (Storable a, RealFloat a, RealFloat b) =>  Ptr a -> IO b
peekFloatConv  = liftM cFloatConv . peek

{-# INLINE withFloatConv #-}
withFloatConv :: (Storable b, RealFloat a, RealFloat b) => a -> (Ptr b -> IO c) -> IO c
withFloatConv  = with . cFloatConv

{-# INLINE withArrayFloatConv #-}
withArrayFloatConv :: (Storable b, RealFloat a, RealFloat b) => [a] -> (Ptr b -> IO b1) -> IO b1
withArrayFloatConv = withArray . map (cFloatConv)