{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Diagrams.Backend.Postscript.CmdLine
(
mainWith
, defaultMain
, multiMain
, pagesMain
, animMain
, Postscript
, B
) where
import qualified Data.ByteString.Builder as B
import System.IO (IOMode (..), withFile)
import Diagrams.Backend.CmdLine
import Diagrams.Backend.Postscript
import Diagrams.Prelude hiding (height, interval, option,
output, value, width, (<>))
import Data.List.Split
defaultMain :: QDiagram Postscript V2 Double Any -> IO ()
defaultMain :: QDiagram Postscript V2 Double Any -> IO ()
defaultMain = forall d. (Mainable d, Parseable (MainOpts d)) => d -> IO ()
mainWith
instance Mainable (QDiagram Postscript V2 Double Any) where
type MainOpts (QDiagram Postscript V2 Double Any) = DiagramOpts
mainRender :: MainOpts (QDiagram Postscript V2 Double Any)
-> QDiagram Postscript V2 Double Any -> IO ()
mainRender MainOpts (QDiagram Postscript V2 Double Any)
opts QDiagram Postscript V2 Double Any
d = DiagramOpts -> (Options Postscript V2 Double -> IO ()) -> IO ()
chooseRender MainOpts (QDiagram Postscript V2 Double Any)
opts (QDiagram Postscript V2 Double Any
-> Options Postscript V2 Double -> IO ()
renderDia' QDiagram Postscript V2 Double Any
d)
chooseRender :: DiagramOpts -> (Options Postscript V2 Double -> IO ()) -> IO ()
chooseRender :: DiagramOpts -> (Options Postscript V2 Double -> IO ()) -> IO ()
chooseRender DiagramOpts
opts Options Postscript V2 Double -> IO ()
renderer =
case forall a. Eq a => [a] -> [a] -> [[a]]
splitOn String
"." (DiagramOpts
optsforall s a. s -> Getting a s a -> a
^.Lens' DiagramOpts String
output) of
[String
""] -> String -> IO ()
putStrLn String
"No output file given."
[String]
ps | forall a. [a] -> a
last [String]
ps forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String
"eps"]
Bool -> Bool -> Bool
|| forall a. [a] -> a
last [String]
ps forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String
"ps"] -> do
let outfmt :: OutputFormat
outfmt = OutputFormat
EPS
sizeSpec :: SizeSpec V2 Double
sizeSpec = forall a b. (Integral a, Num b) => a -> b
fromIntegral forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall n. Num n => Maybe n -> Maybe n -> SizeSpec V2 n
mkSizeSpec2D (DiagramOpts
optsforall s a. s -> Getting a s a -> a
^.Lens' DiagramOpts (Maybe Int)
width) (DiagramOpts
optsforall s a. s -> Getting a s a -> a
^.Lens' DiagramOpts (Maybe Int)
height)
Options Postscript V2 Double -> IO ()
renderer (String
-> SizeSpec V2 Double
-> OutputFormat
-> Options Postscript V2 Double
PostscriptOptions (DiagramOpts
optsforall s a. s -> Getting a s a -> a
^.Lens' DiagramOpts String
output) SizeSpec V2 Double
sizeSpec OutputFormat
outfmt)
| Bool
otherwise -> String -> IO ()
putStrLn forall a b. (a -> b) -> a -> b
$ String
"Unknown file type: " forall a. [a] -> [a] -> [a]
++ forall a. [a] -> a
last [String]
ps
renderDias' :: [QDiagram Postscript V2 Double Any] -> Options Postscript V2 Double -> IO ()
renderDias' :: [QDiagram Postscript V2 Double Any]
-> Options Postscript V2 Double -> IO ()
renderDias' [QDiagram Postscript V2 Double Any]
ds Options Postscript V2 Double
o = forall m.
(Semigroup m, Monoid m) =>
Options Postscript V2 Double
-> [QDiagram Postscript V2 Double m] -> IO [()]
renderDias Options Postscript V2 Double
o [QDiagram Postscript V2 Double Any]
ds forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return ()
renderDia' :: QDiagram Postscript V2 Double Any -> Options Postscript V2 Double -> IO ()
renderDia' :: QDiagram Postscript V2 Double Any
-> Options Postscript V2 Double -> IO ()
renderDia' QDiagram Postscript V2 Double Any
d Options Postscript V2 Double
o = do
let b :: Result Postscript V2 Double
b = forall b (v :: * -> *) n m.
(Backend b v n, HasLinearMap v, Metric v, Typeable n,
OrderedField n, Monoid' m) =>
b -> Options b v n -> QDiagram b v n m -> Result b v n
renderDia Postscript
Postscript Options Postscript V2 Double
o QDiagram Postscript V2 Double Any
d
forall r. String -> IOMode -> (Handle -> IO r) -> IO r
withFile (Options Postscript V2 Double
o forall s a. s -> Getting a s a -> a
^. Lens' (Options Postscript V2 Double) String
psfileName) IOMode
WriteMode forall a b. (a -> b) -> a -> b
$ \Handle
h -> Handle -> Builder -> IO ()
B.hPutBuilder Handle
h Result Postscript V2 Double
b
multiMain :: [(String, QDiagram Postscript V2 Double Any)] -> IO ()
multiMain :: [(String, QDiagram Postscript V2 Double Any)] -> IO ()
multiMain = forall d. (Mainable d, Parseable (MainOpts d)) => d -> IO ()
mainWith
instance Mainable [(String,QDiagram Postscript V2 Double Any)] where
type MainOpts [(String,QDiagram Postscript V2 Double Any)] = (DiagramOpts, DiagramMultiOpts)
mainRender :: MainOpts [(String, QDiagram Postscript V2 Double Any)]
-> [(String, QDiagram Postscript V2 Double Any)] -> IO ()
mainRender = forall d.
Mainable d =>
(MainOpts d, DiagramMultiOpts) -> [(String, d)] -> IO ()
defaultMultiMainRender
pagesMain :: [QDiagram Postscript V2 Double Any] -> IO ()
pagesMain :: [QDiagram Postscript V2 Double Any] -> IO ()
pagesMain = forall d. (Mainable d, Parseable (MainOpts d)) => d -> IO ()
mainWith
instance Mainable [QDiagram Postscript V2 Double Any] where
type MainOpts [QDiagram Postscript V2 Double Any] = DiagramOpts
mainRender :: MainOpts [QDiagram Postscript V2 Double Any]
-> [QDiagram Postscript V2 Double Any] -> IO ()
mainRender MainOpts [QDiagram Postscript V2 Double Any]
opts [QDiagram Postscript V2 Double Any]
ds = DiagramOpts -> (Options Postscript V2 Double -> IO ()) -> IO ()
chooseRender MainOpts [QDiagram Postscript V2 Double Any]
opts ([QDiagram Postscript V2 Double Any]
-> Options Postscript V2 Double -> IO ()
renderDias' [QDiagram Postscript V2 Double Any]
ds)
animMain :: Animation Postscript V2 Double -> IO ()
animMain :: Animation Postscript V2 Double -> IO ()
animMain = forall d. (Mainable d, Parseable (MainOpts d)) => d -> IO ()
mainWith
instance Mainable (Animation Postscript V2 Double) where
type MainOpts (Animation Postscript V2 Double) = (DiagramOpts, DiagramAnimOpts)
mainRender :: MainOpts (Animation Postscript V2 Double)
-> Animation Postscript V2 Double -> IO ()
mainRender = forall opts b (v :: * -> *) n.
(opts -> QDiagram b v n Any -> IO ())
-> Lens' opts String
-> (opts, DiagramAnimOpts)
-> Animation b v n
-> IO ()
defaultAnimMainRender forall d. Mainable d => MainOpts d -> d -> IO ()
mainRender Lens' DiagramOpts String
output