Don't trust serializer, they have nothing todo with a reasonable binary encoding

This commit is contained in:
Tissevert 2019-09-25 23:46:24 +02:00
parent e7484ef536
commit c349d9b4c2
3 changed files with 20 additions and 11 deletions

View File

@ -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

View File

@ -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)

View File

@ -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