36 lines
1.4 KiB
Haskell
36 lines
1.4 KiB
Haskell
{-# LANGUAGE NamedFieldPuns #-}
|
|
module Main where
|
|
|
|
import Control.Monad.Reader
|
|
import qualified Data.ByteString as BS
|
|
import qualified Data.ByteString.Char8 as C8
|
|
import qualified Data.Map as Map
|
|
import PDF.Object (Name(..), StringObject(..), array)
|
|
import PDF.CMap (CMappers, CRange(..), cMap, emptyCMap)
|
|
import PDF.Parser (evalParser)
|
|
import PDF.Text
|
|
|
|
test :: CMappers -> ParserWithFont a -> BS.ByteString -> Either String a
|
|
test fonts parser =
|
|
evalParser (runReaderT parser fonts) emptyCMap
|
|
|
|
main :: IO ()
|
|
main = do
|
|
input <- BS.readFile "20.stream"
|
|
--input <- BS.readFile "array.bin"
|
|
--let input = C8.pack "\f\xb5\0I"
|
|
Right font <- cMap <$> BS.readFile "6300.stream"
|
|
--mapM_ (\(size, m) -> putStrLn ("taille " ++ show size) >> mapM_ showCRange m) $ Map.toList font
|
|
--case pageContents (Map.singleton (Name "R9") font) input of
|
|
--case test (Map.singleton (Name "R9") font) array input of
|
|
--case test (Map.singleton (Name "R9") font) (a textOperator) input of
|
|
case test (Map.singleton (Name "R9") font) page input of
|
|
Left e -> putStrLn e
|
|
Right l -> putStrLn . show $ l
|
|
where
|
|
showMapping = mapM_ (\(k, v) -> putStr (show k) >> putStr " -> " >> C8.putStrLn v) . Map.toList
|
|
showCRange :: CRange -> IO ()
|
|
showCRange (CRange {fromSequence, toSequence, mapping}) = do
|
|
putStrLn $ "from " ++ C8.unpack fromSequence ++ " to " ++ C8.unpack toSequence
|
|
showMapping mapping
|