Adapt main for new Hufflepdf using strict ByteStrings + replace buggy lines / unlines by correct implementations

This commit is contained in:
Tissevert 2019-05-23 16:27:29 +02:00
parent 042f3e4fc4
commit bb064eb0c7

View file

@ -2,21 +2,28 @@
module Main where
import Codec.Compression.Zlib (compress, decompress)
import Data.ByteString.Lazy.Char8 (ByteString)
import qualified Data.ByteString.Lazy.Char8 as BS (
length, lines, readFile, unlines, writeFile
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS (
length, readFile
)
import qualified Data.ByteString.Lazy.Char8 as Lazy (
fromStrict, intercalate, pack, split, toStrict, writeFile
)
import qualified Data.Map as Map (insert, lookup)
import PDF (Document(..), parseDocument, render)
import PDF.Object (Content(..), DirectObject(..), Object(..), Name(..), Number(..))
import PDF.TextRendering (TextRendering(..), update)
import Prelude hiding (lines, unlines)
import System.Environment (getArgs)
import System.IO (hPutStrLn, stderr)
revealFlateEncodedText :: ByteString -> ByteString
revealFlateEncodedText = compress . revealText . decompress
revealFlateEncodedText =
Lazy.toStrict . compress . revealText . decompress . Lazy.fromStrict
where
revealText = BS.unlines . fmap fill . BS.lines
lines = Lazy.split '\n'
unlines = Lazy.intercalate $ Lazy.pack "\n"
revealText = unlines . fmap fill . lines
fill = update $ const Fill
revealObject :: Object -> Object
@ -48,4 +55,4 @@ main = do
result <- parseDocument <$> BS.readFile inputPath
case result of
Left parseError -> hPutStrLn stderr $ show parseError
Right doc -> BS.writeFile outputPath . render $ reveal doc
Right doc -> Lazy.writeFile outputPath . render $ reveal doc