HPDF-0.3: Graphics/PDF/Color.hs
-- | Functions used to control the colors in a PDF document
module Graphics.PDF.Color
(-- * Colors
-- ** Data types
Color(..)
-- ** Operators
, strokeColor,fillColor,rgbSpace, setAlpha,resetAlpha
)
where
import Graphics.PDF.LowLevel
import Text.Printf
-- | Color data type
data Color = Rgb Float Float Float -- ^ RGB Color
instance Show Color where
show (Rgb r g b) = "rgb" ++ (show r) ++ (show g) ++ (show b)
-- | Create a new state dictionary for an alpha value
newState :: Float -> PdfObject
newState a = pdfDictionary [("Type",PdfName "ExtGState"),
("CA",PdfFloat a),
("ca",PdfFloat a)
]
-- | Change the stroke color in a PDF document
strokeColor :: Color -> PdfCmd
strokeColor c = case c of
Rgb r g b -> (PdfSC r g b,[])
-- | Change the fill color in a PDF document
fillColor :: Color -> PdfCmd
fillColor c = case c of
Rgb r g b -> (PdfSF r g b,[])
-- | Change the alpha setting for transparency in the document
setAlpha :: Float -> PdfCmd
setAlpha a = (PdfAlpha dictName,[(PdfState,dictName,PdfUnknownPointer dictName),
(PdfAnyObject,dictName,newState a)])
where
dictName = printf "alpha%f" a
-- | Reset alpha value to opaque for stroke and fill colors
resetAlpha :: PdfCmd
resetAlpha = (PdfResetAlpha,[])
-- | Set color space to RGB. Must always be used before starting to use any color.
rgbSpace :: PdfCmd
rgbSpace = (PdfRgbSpace,[])