diff --git a/Hufflepdf.cabal b/Hufflepdf.cabal index 5238663..40f2a06 100644 --- a/Hufflepdf.cabal +++ b/Hufflepdf.cabal @@ -30,8 +30,8 @@ library , base >=4.9 && <4.13 , bytestring , containers - , data-serializer , mtl + , utf8-string hs-source-dirs: src ghc-options: -Wall default-language: Haskell2010 diff --git a/src/PDF/Object.hs b/src/PDF/Object.hs index 495f2a3..a2c4b71 100644 --- a/src/PDF/Object.hs +++ b/src/PDF/Object.hs @@ -34,8 +34,8 @@ module PDF.Object ( import Control.Applicative ((<|>), many) import Data.Attoparsec.ByteString.Char8 (choice, count, option, sepBy) -import Data.ByteString (ByteString) -import qualified Data.ByteString as BS ( +import Data.ByteString.Char8 (ByteString) +import qualified Data.ByteString.Char8 as BS ( concat, cons, pack, singleton, unpack ) import Data.Map (Map, (!), mapWithKey) diff --git a/src/PDF/Text.hs b/src/PDF/Text.hs index 35d787f..e7c71a6 100644 --- a/src/PDF/Text.hs +++ b/src/PDF/Text.hs @@ -15,6 +15,7 @@ import Control.Monad.State (put) import Data.Attoparsec.ByteString.Char8 (choice, count, parseOnly, sepBy) import qualified Data.Attoparsec.ByteString.Char8 as Atto (Parser) import Data.ByteString.Char8 (ByteString, pack) +import qualified Data.ByteString.UTF8 as UTF8 (toString) import Data.Map (Map, (!)) import qualified Data.Map as Map (empty, fromList) import PDF.Object ( @@ -55,20 +56,28 @@ cMapChar = do <$> (stringObject <* blank) <*> (stringObject <* blank) <* EOL.parser mapFromTo (Hexadecimal from) (Hexadecimal to) (StringObject (Hexadecimal dstFrom)) = - undefined + let dstFrom mapFromTo (Hexadecimal from) (Hexadecimal to) (Array dstPoints) = undefined -mapFromTo _ _ _ = Map.empty +mapFromTo _ _ _ = fail "invalid range mapping found" pairMapping :: StringObject -> StringObject -> (Int, ByteString) pairMapping (Hexadecimal from) (Hexadecimal to) = - (read $ "0x" ++ from, + (hexString from, toByteString to) +pairMapping = fail "invalid pair mapping found" -fromBytes :: String -> ByteString -fromBytes s +hexString :: Num a => String -> a +hexString s = read $ "0x" ++ s + +toByteString :: String -> [Word8] +toByteString = pack . toBaseWord8 [] . hexString where - toBaseWord8 n - | n < 0xff = [ - to + toBaseWord8 digits n + | n < 0xff = (fromIntegral n):digits + | otherwise = + let newDigits = (fromIntegral (n `mod` 0xff)):digits in + case n `div` 0xff of + 0 -> newDigits + k -> toBaseWord8 newDigits k data StateOperator = Cm | W | J | J_ | M | D | Ri | I | Gs -- general graphic state