{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleInstances #-}
module Graphics.PDF.Resources(
PDFResource(..)
, addResource
, emptyRsrc
, StrokeAlpha(..)
, FillAlpha(..)
, PdfResourceObject(..)
, resourceToDict
, emptyResource
, PDFColoredPattern
, PDFUncoloredPattern
, AnyPdfPattern
, PDFColorSpace(..)
) where
import Graphics.PDF.LowLevel.Types
import qualified Data.Map.Strict as M
newtype StrokeAlpha = StrokeAlpha Double deriving(StrokeAlpha -> StrokeAlpha -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StrokeAlpha -> StrokeAlpha -> Bool
$c/= :: StrokeAlpha -> StrokeAlpha -> Bool
== :: StrokeAlpha -> StrokeAlpha -> Bool
$c== :: StrokeAlpha -> StrokeAlpha -> Bool
Eq,Eq StrokeAlpha
StrokeAlpha -> StrokeAlpha -> Bool
StrokeAlpha -> StrokeAlpha -> Ordering
StrokeAlpha -> StrokeAlpha -> StrokeAlpha
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: StrokeAlpha -> StrokeAlpha -> StrokeAlpha
$cmin :: StrokeAlpha -> StrokeAlpha -> StrokeAlpha
max :: StrokeAlpha -> StrokeAlpha -> StrokeAlpha
$cmax :: StrokeAlpha -> StrokeAlpha -> StrokeAlpha
>= :: StrokeAlpha -> StrokeAlpha -> Bool
$c>= :: StrokeAlpha -> StrokeAlpha -> Bool
> :: StrokeAlpha -> StrokeAlpha -> Bool
$c> :: StrokeAlpha -> StrokeAlpha -> Bool
<= :: StrokeAlpha -> StrokeAlpha -> Bool
$c<= :: StrokeAlpha -> StrokeAlpha -> Bool
< :: StrokeAlpha -> StrokeAlpha -> Bool
$c< :: StrokeAlpha -> StrokeAlpha -> Bool
compare :: StrokeAlpha -> StrokeAlpha -> Ordering
$ccompare :: StrokeAlpha -> StrokeAlpha -> Ordering
Ord)
instance PdfResourceObject StrokeAlpha where
toRsrc :: StrokeAlpha -> AnyPdfObject
toRsrc (StrokeAlpha Double
a) = forall a. (PdfObject a, PdfLengthInfo a) => a -> AnyPdfObject
AnyPdfObject forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map PDFName AnyPdfObject -> PDFDictionary
PDFDictionary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall a b. (a -> b) -> a -> b
$ [(String -> PDFName
PDFName String
"CA",forall a. (PdfObject a, PdfLengthInfo a) => a -> AnyPdfObject
AnyPdfObject Double
a)]
newtype FillAlpha = FillAlpha Double deriving(FillAlpha -> FillAlpha -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FillAlpha -> FillAlpha -> Bool
$c/= :: FillAlpha -> FillAlpha -> Bool
== :: FillAlpha -> FillAlpha -> Bool
$c== :: FillAlpha -> FillAlpha -> Bool
Eq,Eq FillAlpha
FillAlpha -> FillAlpha -> Bool
FillAlpha -> FillAlpha -> Ordering
FillAlpha -> FillAlpha -> FillAlpha
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FillAlpha -> FillAlpha -> FillAlpha
$cmin :: FillAlpha -> FillAlpha -> FillAlpha
max :: FillAlpha -> FillAlpha -> FillAlpha
$cmax :: FillAlpha -> FillAlpha -> FillAlpha
>= :: FillAlpha -> FillAlpha -> Bool
$c>= :: FillAlpha -> FillAlpha -> Bool
> :: FillAlpha -> FillAlpha -> Bool
$c> :: FillAlpha -> FillAlpha -> Bool
<= :: FillAlpha -> FillAlpha -> Bool
$c<= :: FillAlpha -> FillAlpha -> Bool
< :: FillAlpha -> FillAlpha -> Bool
$c< :: FillAlpha -> FillAlpha -> Bool
compare :: FillAlpha -> FillAlpha -> Ordering
$ccompare :: FillAlpha -> FillAlpha -> Ordering
Ord)
instance PdfResourceObject FillAlpha where
toRsrc :: FillAlpha -> AnyPdfObject
toRsrc (FillAlpha Double
a) = forall a. (PdfObject a, PdfLengthInfo a) => a -> AnyPdfObject
AnyPdfObject forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map PDFName AnyPdfObject -> PDFDictionary
PDFDictionary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall a b. (a -> b) -> a -> b
$ [(String -> PDFName
PDFName String
"ca",forall a. (PdfObject a, PdfLengthInfo a) => a -> AnyPdfObject
AnyPdfObject Double
a)]
class PdfResourceObject a where
toRsrc :: a -> AnyPdfObject
data PDFResource = PDFResource {
PDFResource -> PDFArray
procSet :: !PDFArray
, PDFResource -> Map PDFName PDFDictionary
resources :: M.Map PDFName PDFDictionary
}
emptyRsrc :: PDFResource
emptyRsrc :: PDFResource
emptyRsrc = PDFArray -> Map PDFName PDFDictionary -> PDFResource
PDFResource [] (forall k a. Map k a
M.empty)
getResources :: M.Map PDFName PDFDictionary -> [(PDFName,AnyPdfObject)]
getResources :: Map PDFName PDFDictionary -> [(PDFName, AnyPdfObject)]
getResources = forall k a. Map k a -> [(k, a)]
M.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b k. (a -> b) -> Map k a -> Map k b
M.map forall a. (PdfObject a, PdfLengthInfo a) => a -> AnyPdfObject
AnyPdfObject
instance PdfObject PDFResource where
toPDF :: PDFResource -> Builder
toPDF PDFResource
r = forall a. PdfObject a => a -> Builder
toPDF forall b c a. (b -> c) -> (a -> b) -> a -> c
. PDFResource -> PDFDictionary
resourceToDict forall a b. (a -> b) -> a -> b
$ PDFResource
r
instance PdfLengthInfo PDFResource where
addResource :: PDFName
-> PDFName
-> AnyPdfObject
-> PDFResource
-> PDFResource
addResource :: PDFName -> PDFName -> AnyPdfObject -> PDFResource -> PDFResource
addResource PDFName
dict PDFName
name AnyPdfObject
newValue PDFResource
r = let addValue :: Maybe PDFDictionary -> Maybe PDFDictionary
addValue (Just (PDFDictionary Map PDFName AnyPdfObject
a)) = forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map PDFName AnyPdfObject -> PDFDictionary
PDFDictionary forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert PDFName
name AnyPdfObject
newValue Map PDFName AnyPdfObject
a
addValue (Maybe PDFDictionary
Nothing) = forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map PDFName AnyPdfObject -> PDFDictionary
PDFDictionary forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert PDFName
name AnyPdfObject
newValue forall k a. Map k a
M.empty
in
PDFResource
r {resources :: Map PDFName PDFDictionary
resources = forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
M.alter Maybe PDFDictionary -> Maybe PDFDictionary
addValue PDFName
dict (PDFResource -> Map PDFName PDFDictionary
resources PDFResource
r)}
resourceToDict :: PDFResource -> PDFDictionary
resourceToDict :: PDFResource -> PDFDictionary
resourceToDict PDFResource
r = Map PDFName AnyPdfObject -> PDFDictionary
PDFDictionary forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall a b. (a -> b) -> a -> b
$
Map PDFName PDFDictionary -> [(PDFName, AnyPdfObject)]
getResources (PDFResource -> Map PDFName PDFDictionary
resources PDFResource
r)
emptyResource :: PDFResource -> Bool
emptyResource :: PDFResource -> Bool
emptyResource (PDFResource PDFArray
a Map PDFName PDFDictionary
b) = forall (t :: * -> *) a. Foldable t => t a -> Bool
null PDFArray
a Bool -> Bool -> Bool
&& forall k a. Map k a -> Bool
M.null Map PDFName PDFDictionary
b
data PDFUncoloredPattern
data PDFColoredPattern
data AnyPdfPattern
data PDFColorSpace = PatternRGB deriving(PDFColorSpace -> PDFColorSpace -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PDFColorSpace -> PDFColorSpace -> Bool
$c/= :: PDFColorSpace -> PDFColorSpace -> Bool
== :: PDFColorSpace -> PDFColorSpace -> Bool
$c== :: PDFColorSpace -> PDFColorSpace -> Bool
Eq,Eq PDFColorSpace
PDFColorSpace -> PDFColorSpace -> Bool
PDFColorSpace -> PDFColorSpace -> Ordering
PDFColorSpace -> PDFColorSpace -> PDFColorSpace
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: PDFColorSpace -> PDFColorSpace -> PDFColorSpace
$cmin :: PDFColorSpace -> PDFColorSpace -> PDFColorSpace
max :: PDFColorSpace -> PDFColorSpace -> PDFColorSpace
$cmax :: PDFColorSpace -> PDFColorSpace -> PDFColorSpace
>= :: PDFColorSpace -> PDFColorSpace -> Bool
$c>= :: PDFColorSpace -> PDFColorSpace -> Bool
> :: PDFColorSpace -> PDFColorSpace -> Bool
$c> :: PDFColorSpace -> PDFColorSpace -> Bool
<= :: PDFColorSpace -> PDFColorSpace -> Bool
$c<= :: PDFColorSpace -> PDFColorSpace -> Bool
< :: PDFColorSpace -> PDFColorSpace -> Bool
$c< :: PDFColorSpace -> PDFColorSpace -> Bool
compare :: PDFColorSpace -> PDFColorSpace -> Ordering
$ccompare :: PDFColorSpace -> PDFColorSpace -> Ordering
Ord)
instance PdfResourceObject PDFColorSpace where
toRsrc :: PDFColorSpace -> AnyPdfObject
toRsrc PDFColorSpace
PatternRGB = forall a. (PdfObject a, PdfLengthInfo a) => a -> AnyPdfObject
AnyPdfObject forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a. (PdfObject a, PdfLengthInfo a) => a -> AnyPdfObject
AnyPdfObject forall a b. (a -> b) -> a -> b
$ [String -> PDFName
PDFName String
"Pattern",String -> PDFName
PDFName String
"DeviceRGB"]
instance PdfObject PDFColoredPattern where
toPDF :: PDFColoredPattern -> Builder
toPDF PDFColoredPattern
_ = forall s. Monoid s => s
noPdfObject
instance PdfLengthInfo PDFColoredPattern where
instance PdfResourceObject (PDFReference PDFColoredPattern) where
toRsrc :: PDFReference PDFColoredPattern -> AnyPdfObject
toRsrc = forall a. (PdfObject a, PdfLengthInfo a) => a -> AnyPdfObject
AnyPdfObject
instance PdfObject PDFUncoloredPattern where
toPDF :: PDFUncoloredPattern -> Builder
toPDF PDFUncoloredPattern
_ = forall s. Monoid s => s
noPdfObject
instance PdfLengthInfo PDFUncoloredPattern where
instance PdfResourceObject (PDFReference PDFUncoloredPattern) where
toRsrc :: PDFReference PDFUncoloredPattern -> AnyPdfObject
toRsrc = forall a. (PdfObject a, PdfLengthInfo a) => a -> AnyPdfObject
AnyPdfObject
instance PdfObject AnyPdfPattern where
toPDF :: AnyPdfPattern -> Builder
toPDF AnyPdfPattern
_ = forall s. Monoid s => s
noPdfObject
instance PdfLengthInfo AnyPdfPattern where
instance PdfResourceObject (PDFReference AnyPdfPattern) where
toRsrc :: PDFReference AnyPdfPattern -> AnyPdfObject
toRsrc = forall a. (PdfObject a, PdfLengthInfo a) => a -> AnyPdfObject
AnyPdfObject