lántas script stuff

This commit is contained in:
Rhiannon Morris 2021-04-28 12:29:21 +02:00
parent 13836bac8b
commit 292c5d5920
5 changed files with 217 additions and 114 deletions

View file

@ -1,14 +1,21 @@
{-# OPTIONS_GHC -fdefer-typed-holes #-}
import Prelude hiding (Word)
import Prelude hiding (getContents, readFile, writeFile, putStrLn)
import Svg
import qualified Glyphs as G
import Glyphs (doGlyphs, lineHeight')
import Split
import Options.Applicative
import Data.Functor
import Data.Text.IO (readFile, getContents)
import Data.Text.Lazy.IO (writeFile, putStrLn)
data Options =
Opts { width, size, stroke :: {-# UNPACK #-} !Double }
Opts {
width, size, stroke :: {-# UNPACK #-} !Double,
inFile, outFile :: Maybe FilePath,
text :: Maybe Text
}
deriving Show
options :: IO Options
@ -16,18 +23,30 @@ options = execParser desc where
desc = info (opts <**> helper) $
fullDesc <> header "render lántas text as svg"
opts =
Opts <$> dimOpt 'W' "width" Nothing
<*> (dimOpt' 'S' "size" "text size" (Just 10)
<&> (/ G.lineHeight'))
<*> dimOpt' 'K' "stroke" "line thickness" (Just 2)
Opts <$> dimOpt 'W' "width" 1000
<*> (dimOpt' 'S' "size" "text size" 60 <&> (/ lineHeight'))
<*> dimOpt' 'K' "stroke" "line thickness" 2
<*> filePath 'i' "input"
<*> filePath 'o' "output"
<*> text
dimOpt s l d = dimOpt' s l l d
dimOpt' s l n d = option auto $ mconcat $
[short s, long l, help $ n <> " in pixels", metavar "SIZE"] <>
maybe [] (\x -> [value x]) d
dimOpt' s l n d = option auto $ mconcat
[short s, long l, help $ n <> " in pixels", metavar "SIZE", value d]
filePath s n = optional $ option str $ mconcat
[short s, long n, help $ n <> " file", metavar "FILE"]
text = optional $ option str $ mconcat
[short 't', long "text", help $ "use given text instead of a file",
metavar "TEXT"]
main :: IO ()
main = do
Opts {..} <- options
let lántas = _
let res = G.doGlyphs [lántas, lántas] (E {..})
writeFile "/home/niss/e.svg" $ show res
txt <- split <$> if
| Just t <- text -> pure t
| Just "-" <- inFile -> getContents
| Just i <- inFile -> readFile i
| otherwise -> fail "no input given"
let res = prettyText $ doGlyphs txt (E {..})
case outFile of
Just o | o /= "-" -> writeFile o res
_ -> putStrLn res