module Ipe.IpeRender where
import qualified System.Process.Typed as Process
ipeRenderWith :: Options
-> FileType
-> FilePath
-> FilePath
-> IO ()
ipeRenderWith :: Options -> FileType -> FilePath -> FilePath -> IO ()
ipeRenderWith Options
options FileType
fType FilePath
inFp FilePath
outFp =
ProcessConfig () () () -> (Process () () () -> IO ()) -> IO ()
forall (m :: * -> *) stdin stdout stderr a.
MonadUnliftIO m =>
ProcessConfig stdin stdout stderr
-> (Process stdin stdout stderr -> m a) -> m a
Process.withProcessWait ProcessConfig () () ()
processCfg ((Process () () () -> IO ()) -> IO ())
-> (Process () () () -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Process () () ()
_iperenderProc -> () -> IO ()
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
where
processCfg :: ProcessConfig () () ()
processCfg = FilePath -> [FilePath] -> ProcessConfig () () ()
Process.proc FilePath
"iperender" [FilePath]
args
args :: [FilePath]
args = [ FilePath
"-" FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> FileType -> FilePath
forall a. Show a => a -> FilePath
show FileType
fType
, FilePath
"-page", Int -> FilePath
forall a. Show a => a -> FilePath
show (Options -> Int
pageNumber Options
options)
, FilePath
"-view", Int -> FilePath
forall a. Show a => a -> FilePath
show (Options -> Int
viewNumber Options
options)
, FilePath
"-resolution", Int -> FilePath
forall a. Show a => a -> FilePath
show (Options -> Int
resolution Options
options)
] [FilePath] -> [FilePath] -> [FilePath]
forall a. Semigroup a => a -> a -> a
<>
[ FilePath
"-transparent" | Background
TransparentBackground Background -> Background -> Bool
forall a. Eq a => a -> a -> Bool
== Options -> Background
transparent Options
options ] [FilePath] -> [FilePath] -> [FilePath]
forall a. Semigroup a => a -> a -> a
<>
[ FilePath
"-nocrop" | Crop
NoCrop Crop -> Crop -> Bool
forall a. Eq a => a -> a -> Bool
== Options -> Crop
crop Options
options ] [FilePath] -> [FilePath] -> [FilePath]
forall a. Semigroup a => a -> a -> a
<>
[ FilePath
inFp
, FilePath
outFp
]
ipeRender :: FileType -> FilePath -> FilePath -> IO ()
ipeRender :: FileType -> FilePath -> FilePath -> IO ()
ipeRender = Options -> FileType -> FilePath -> FilePath -> IO ()
ipeRenderWith Options
defaultOptions
data FileType = PNG | EPS | PDF | SVG
deriving (FileType -> FileType -> Bool
(FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool) -> Eq FileType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FileType -> FileType -> Bool
$c/= :: FileType -> FileType -> Bool
== :: FileType -> FileType -> Bool
$c== :: FileType -> FileType -> Bool
Eq,Eq FileType
Eq FileType
-> (FileType -> FileType -> Ordering)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> FileType)
-> (FileType -> FileType -> FileType)
-> Ord FileType
FileType -> FileType -> Bool
FileType -> FileType -> Ordering
FileType -> FileType -> FileType
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 :: FileType -> FileType -> FileType
$cmin :: FileType -> FileType -> FileType
max :: FileType -> FileType -> FileType
$cmax :: FileType -> FileType -> FileType
>= :: FileType -> FileType -> Bool
$c>= :: FileType -> FileType -> Bool
> :: FileType -> FileType -> Bool
$c> :: FileType -> FileType -> Bool
<= :: FileType -> FileType -> Bool
$c<= :: FileType -> FileType -> Bool
< :: FileType -> FileType -> Bool
$c< :: FileType -> FileType -> Bool
compare :: FileType -> FileType -> Ordering
$ccompare :: FileType -> FileType -> Ordering
$cp1Ord :: Eq FileType
Ord,Int -> FileType
FileType -> Int
FileType -> [FileType]
FileType -> FileType
FileType -> FileType -> [FileType]
FileType -> FileType -> FileType -> [FileType]
(FileType -> FileType)
-> (FileType -> FileType)
-> (Int -> FileType)
-> (FileType -> Int)
-> (FileType -> [FileType])
-> (FileType -> FileType -> [FileType])
-> (FileType -> FileType -> [FileType])
-> (FileType -> FileType -> FileType -> [FileType])
-> Enum FileType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: FileType -> FileType -> FileType -> [FileType]
$cenumFromThenTo :: FileType -> FileType -> FileType -> [FileType]
enumFromTo :: FileType -> FileType -> [FileType]
$cenumFromTo :: FileType -> FileType -> [FileType]
enumFromThen :: FileType -> FileType -> [FileType]
$cenumFromThen :: FileType -> FileType -> [FileType]
enumFrom :: FileType -> [FileType]
$cenumFrom :: FileType -> [FileType]
fromEnum :: FileType -> Int
$cfromEnum :: FileType -> Int
toEnum :: Int -> FileType
$ctoEnum :: Int -> FileType
pred :: FileType -> FileType
$cpred :: FileType -> FileType
succ :: FileType -> FileType
$csucc :: FileType -> FileType
Enum)
instance Show FileType where
show :: FileType -> FilePath
show = \case
FileType
PNG -> FilePath
"png"
FileType
EPS -> FilePath
"eps"
FileType
PDF -> FilePath
"pdf"
FileType
SVG -> FilePath
"svg"
data Options = Options { Options -> Int
pageNumber :: Int
, Options -> Int
viewNumber :: Int
, Options -> Int
resolution :: Int
, Options -> Background
transparent :: Background
, Options -> Crop
crop :: Crop
} deriving (Int -> Options -> FilePath -> FilePath
[Options] -> FilePath -> FilePath
Options -> FilePath
(Int -> Options -> FilePath -> FilePath)
-> (Options -> FilePath)
-> ([Options] -> FilePath -> FilePath)
-> Show Options
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
showList :: [Options] -> FilePath -> FilePath
$cshowList :: [Options] -> FilePath -> FilePath
show :: Options -> FilePath
$cshow :: Options -> FilePath
showsPrec :: Int -> Options -> FilePath -> FilePath
$cshowsPrec :: Int -> Options -> FilePath -> FilePath
Show,Options -> Options -> Bool
(Options -> Options -> Bool)
-> (Options -> Options -> Bool) -> Eq Options
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Options -> Options -> Bool
$c/= :: Options -> Options -> Bool
== :: Options -> Options -> Bool
$c== :: Options -> Options -> Bool
Eq,Eq Options
Eq Options
-> (Options -> Options -> Ordering)
-> (Options -> Options -> Bool)
-> (Options -> Options -> Bool)
-> (Options -> Options -> Bool)
-> (Options -> Options -> Bool)
-> (Options -> Options -> Options)
-> (Options -> Options -> Options)
-> Ord Options
Options -> Options -> Bool
Options -> Options -> Ordering
Options -> Options -> Options
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 :: Options -> Options -> Options
$cmin :: Options -> Options -> Options
max :: Options -> Options -> Options
$cmax :: Options -> Options -> Options
>= :: Options -> Options -> Bool
$c>= :: Options -> Options -> Bool
> :: Options -> Options -> Bool
$c> :: Options -> Options -> Bool
<= :: Options -> Options -> Bool
$c<= :: Options -> Options -> Bool
< :: Options -> Options -> Bool
$c< :: Options -> Options -> Bool
compare :: Options -> Options -> Ordering
$ccompare :: Options -> Options -> Ordering
$cp1Ord :: Eq Options
Ord)
defaultOptions :: Options
defaultOptions :: Options
defaultOptions = Int -> Int -> Int -> Background -> Crop -> Options
Options Int
1 Int
1 Int
72 Background
TransparentBackground Crop
Crop
data Background = OpaqueBackground | TransparentBackground
deriving (Int -> Background -> FilePath -> FilePath
[Background] -> FilePath -> FilePath
Background -> FilePath
(Int -> Background -> FilePath -> FilePath)
-> (Background -> FilePath)
-> ([Background] -> FilePath -> FilePath)
-> Show Background
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
showList :: [Background] -> FilePath -> FilePath
$cshowList :: [Background] -> FilePath -> FilePath
show :: Background -> FilePath
$cshow :: Background -> FilePath
showsPrec :: Int -> Background -> FilePath -> FilePath
$cshowsPrec :: Int -> Background -> FilePath -> FilePath
Show,ReadPrec [Background]
ReadPrec Background
Int -> ReadS Background
ReadS [Background]
(Int -> ReadS Background)
-> ReadS [Background]
-> ReadPrec Background
-> ReadPrec [Background]
-> Read Background
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Background]
$creadListPrec :: ReadPrec [Background]
readPrec :: ReadPrec Background
$creadPrec :: ReadPrec Background
readList :: ReadS [Background]
$creadList :: ReadS [Background]
readsPrec :: Int -> ReadS Background
$creadsPrec :: Int -> ReadS Background
Read,Background -> Background -> Bool
(Background -> Background -> Bool)
-> (Background -> Background -> Bool) -> Eq Background
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Background -> Background -> Bool
$c/= :: Background -> Background -> Bool
== :: Background -> Background -> Bool
$c== :: Background -> Background -> Bool
Eq,Eq Background
Eq Background
-> (Background -> Background -> Ordering)
-> (Background -> Background -> Bool)
-> (Background -> Background -> Bool)
-> (Background -> Background -> Bool)
-> (Background -> Background -> Bool)
-> (Background -> Background -> Background)
-> (Background -> Background -> Background)
-> Ord Background
Background -> Background -> Bool
Background -> Background -> Ordering
Background -> Background -> Background
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 :: Background -> Background -> Background
$cmin :: Background -> Background -> Background
max :: Background -> Background -> Background
$cmax :: Background -> Background -> Background
>= :: Background -> Background -> Bool
$c>= :: Background -> Background -> Bool
> :: Background -> Background -> Bool
$c> :: Background -> Background -> Bool
<= :: Background -> Background -> Bool
$c<= :: Background -> Background -> Bool
< :: Background -> Background -> Bool
$c< :: Background -> Background -> Bool
compare :: Background -> Background -> Ordering
$ccompare :: Background -> Background -> Ordering
$cp1Ord :: Eq Background
Ord,Int -> Background
Background -> Int
Background -> [Background]
Background -> Background
Background -> Background -> [Background]
Background -> Background -> Background -> [Background]
(Background -> Background)
-> (Background -> Background)
-> (Int -> Background)
-> (Background -> Int)
-> (Background -> [Background])
-> (Background -> Background -> [Background])
-> (Background -> Background -> [Background])
-> (Background -> Background -> Background -> [Background])
-> Enum Background
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Background -> Background -> Background -> [Background]
$cenumFromThenTo :: Background -> Background -> Background -> [Background]
enumFromTo :: Background -> Background -> [Background]
$cenumFromTo :: Background -> Background -> [Background]
enumFromThen :: Background -> Background -> [Background]
$cenumFromThen :: Background -> Background -> [Background]
enumFrom :: Background -> [Background]
$cenumFrom :: Background -> [Background]
fromEnum :: Background -> Int
$cfromEnum :: Background -> Int
toEnum :: Int -> Background
$ctoEnum :: Int -> Background
pred :: Background -> Background
$cpred :: Background -> Background
succ :: Background -> Background
$csucc :: Background -> Background
Enum)
data Crop = NoCrop | Crop
deriving (Int -> Crop -> FilePath -> FilePath
[Crop] -> FilePath -> FilePath
Crop -> FilePath
(Int -> Crop -> FilePath -> FilePath)
-> (Crop -> FilePath)
-> ([Crop] -> FilePath -> FilePath)
-> Show Crop
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
showList :: [Crop] -> FilePath -> FilePath
$cshowList :: [Crop] -> FilePath -> FilePath
show :: Crop -> FilePath
$cshow :: Crop -> FilePath
showsPrec :: Int -> Crop -> FilePath -> FilePath
$cshowsPrec :: Int -> Crop -> FilePath -> FilePath
Show,ReadPrec [Crop]
ReadPrec Crop
Int -> ReadS Crop
ReadS [Crop]
(Int -> ReadS Crop)
-> ReadS [Crop] -> ReadPrec Crop -> ReadPrec [Crop] -> Read Crop
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Crop]
$creadListPrec :: ReadPrec [Crop]
readPrec :: ReadPrec Crop
$creadPrec :: ReadPrec Crop
readList :: ReadS [Crop]
$creadList :: ReadS [Crop]
readsPrec :: Int -> ReadS Crop
$creadsPrec :: Int -> ReadS Crop
Read,Crop -> Crop -> Bool
(Crop -> Crop -> Bool) -> (Crop -> Crop -> Bool) -> Eq Crop
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Crop -> Crop -> Bool
$c/= :: Crop -> Crop -> Bool
== :: Crop -> Crop -> Bool
$c== :: Crop -> Crop -> Bool
Eq,Eq Crop
Eq Crop
-> (Crop -> Crop -> Ordering)
-> (Crop -> Crop -> Bool)
-> (Crop -> Crop -> Bool)
-> (Crop -> Crop -> Bool)
-> (Crop -> Crop -> Bool)
-> (Crop -> Crop -> Crop)
-> (Crop -> Crop -> Crop)
-> Ord Crop
Crop -> Crop -> Bool
Crop -> Crop -> Ordering
Crop -> Crop -> Crop
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 :: Crop -> Crop -> Crop
$cmin :: Crop -> Crop -> Crop
max :: Crop -> Crop -> Crop
$cmax :: Crop -> Crop -> Crop
>= :: Crop -> Crop -> Bool
$c>= :: Crop -> Crop -> Bool
> :: Crop -> Crop -> Bool
$c> :: Crop -> Crop -> Bool
<= :: Crop -> Crop -> Bool
$c<= :: Crop -> Crop -> Bool
< :: Crop -> Crop -> Bool
$c< :: Crop -> Crop -> Bool
compare :: Crop -> Crop -> Ordering
$ccompare :: Crop -> Crop -> Ordering
$cp1Ord :: Eq Crop
Ord,Int -> Crop
Crop -> Int
Crop -> [Crop]
Crop -> Crop
Crop -> Crop -> [Crop]
Crop -> Crop -> Crop -> [Crop]
(Crop -> Crop)
-> (Crop -> Crop)
-> (Int -> Crop)
-> (Crop -> Int)
-> (Crop -> [Crop])
-> (Crop -> Crop -> [Crop])
-> (Crop -> Crop -> [Crop])
-> (Crop -> Crop -> Crop -> [Crop])
-> Enum Crop
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Crop -> Crop -> Crop -> [Crop]
$cenumFromThenTo :: Crop -> Crop -> Crop -> [Crop]
enumFromTo :: Crop -> Crop -> [Crop]
$cenumFromTo :: Crop -> Crop -> [Crop]
enumFromThen :: Crop -> Crop -> [Crop]
$cenumFromThen :: Crop -> Crop -> [Crop]
enumFrom :: Crop -> [Crop]
$cenumFrom :: Crop -> [Crop]
fromEnum :: Crop -> Int
$cfromEnum :: Crop -> Int
toEnum :: Int -> Crop
$ctoEnum :: Int -> Crop
pred :: Crop -> Crop
$cpred :: Crop -> Crop
succ :: Crop -> Crop
$csucc :: Crop -> Crop
Enum)