Main.hs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. {-# LANGUAGE PatternGuards #-}
  2. module Main where
  3. import Control.Monad (forM_)
  4. import qualified Data.ByteString as BS
  5. import Data.Sequence (Seq, ViewL(..))
  6. import qualified Data.Sequence as S
  7. import Graphics.HVIF
  8. main :: IO ()
  9. main = do
  10. contents <- BS.getContents
  11. case decodeFile contents of
  12. Left err -> putStrLn err
  13. Right hvif -> do
  14. putStrLn "<svg width=\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\">"
  15. forM_ (hvifPaths hvif) $ \path -> do
  16. putStr "<path d=\""
  17. drawPoints True 0.0 0.0 (pathPoints path)
  18. putStrLn "stroke=\"black\"/>"
  19. putStrLn "</svg>"
  20. drawPoints :: Bool -> Float -> Float -> Seq Command -> IO ()
  21. drawPoints first lx ly seq
  22. | cmd :< xs <- S.viewl seq = do
  23. let dir = if first then "M" else "L"
  24. case cmd of
  25. CmdLine (Point x y) -> do
  26. putStr $ unwords [dir, show (floor x), show (floor y)]
  27. drawPoints False x y xs
  28. CmdHLine x -> do
  29. putStr $ unwords [dir, show (floor x), show (floor ly)]
  30. drawPoints False x ly xs
  31. CmdVLine y -> do
  32. putStr $ unwords [dir, show (floor lx), show (floor y)]
  33. drawPoints False lx y xs
  34. CmdCurve (Point x y) _ _ -> do
  35. putStr $ unwords [dir, show (floor x), show (floor y)]
  36. drawPoints False x y xs
  37. | otherwise = putStr "Z\" "