Don't trust serializer, they have nothing todo with a reasonable binary encoding
This commit is contained in:
parent
e7484ef536
commit
c349d9b4c2
3 changed files with 20 additions and 11 deletions
|
@ -30,8 +30,8 @@ library
|
||||||
, base >=4.9 && <4.13
|
, base >=4.9 && <4.13
|
||||||
, bytestring
|
, bytestring
|
||||||
, containers
|
, containers
|
||||||
, data-serializer
|
|
||||||
, mtl
|
, mtl
|
||||||
|
, utf8-string
|
||||||
hs-source-dirs: src
|
hs-source-dirs: src
|
||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
|
@ -34,8 +34,8 @@ module PDF.Object (
|
||||||
|
|
||||||
import Control.Applicative ((<|>), many)
|
import Control.Applicative ((<|>), many)
|
||||||
import Data.Attoparsec.ByteString.Char8 (choice, count, option, sepBy)
|
import Data.Attoparsec.ByteString.Char8 (choice, count, option, sepBy)
|
||||||
import Data.ByteString (ByteString)
|
import Data.ByteString.Char8 (ByteString)
|
||||||
import qualified Data.ByteString as BS (
|
import qualified Data.ByteString.Char8 as BS (
|
||||||
concat, cons, pack, singleton, unpack
|
concat, cons, pack, singleton, unpack
|
||||||
)
|
)
|
||||||
import Data.Map (Map, (!), mapWithKey)
|
import Data.Map (Map, (!), mapWithKey)
|
||||||
|
|
|
@ -15,6 +15,7 @@ import Control.Monad.State (put)
|
||||||
import Data.Attoparsec.ByteString.Char8 (choice, count, parseOnly, sepBy)
|
import Data.Attoparsec.ByteString.Char8 (choice, count, parseOnly, sepBy)
|
||||||
import qualified Data.Attoparsec.ByteString.Char8 as Atto (Parser)
|
import qualified Data.Attoparsec.ByteString.Char8 as Atto (Parser)
|
||||||
import Data.ByteString.Char8 (ByteString, pack)
|
import Data.ByteString.Char8 (ByteString, pack)
|
||||||
|
import qualified Data.ByteString.UTF8 as UTF8 (toString)
|
||||||
import Data.Map (Map, (!))
|
import Data.Map (Map, (!))
|
||||||
import qualified Data.Map as Map (empty, fromList)
|
import qualified Data.Map as Map (empty, fromList)
|
||||||
import PDF.Object (
|
import PDF.Object (
|
||||||
|
@ -55,20 +56,28 @@ cMapChar = do
|
||||||
<$> (stringObject <* blank) <*> (stringObject <* blank) <* EOL.parser
|
<$> (stringObject <* blank) <*> (stringObject <* blank) <* EOL.parser
|
||||||
|
|
||||||
mapFromTo (Hexadecimal from) (Hexadecimal to) (StringObject (Hexadecimal dstFrom)) =
|
mapFromTo (Hexadecimal from) (Hexadecimal to) (StringObject (Hexadecimal dstFrom)) =
|
||||||
undefined
|
let dstFrom
|
||||||
mapFromTo (Hexadecimal from) (Hexadecimal to) (Array dstPoints) = undefined
|
mapFromTo (Hexadecimal from) (Hexadecimal to) (Array dstPoints) = undefined
|
||||||
mapFromTo _ _ _ = Map.empty
|
mapFromTo _ _ _ = fail "invalid range mapping found"
|
||||||
|
|
||||||
pairMapping :: StringObject -> StringObject -> (Int, ByteString)
|
pairMapping :: StringObject -> StringObject -> (Int, ByteString)
|
||||||
pairMapping (Hexadecimal from) (Hexadecimal to) =
|
pairMapping (Hexadecimal from) (Hexadecimal to) =
|
||||||
(read $ "0x" ++ from,
|
(hexString from, toByteString to)
|
||||||
|
pairMapping = fail "invalid pair mapping found"
|
||||||
|
|
||||||
fromBytes :: String -> ByteString
|
hexString :: Num a => String -> a
|
||||||
fromBytes s
|
hexString s = read $ "0x" ++ s
|
||||||
|
|
||||||
|
toByteString :: String -> [Word8]
|
||||||
|
toByteString = pack . toBaseWord8 [] . hexString
|
||||||
where
|
where
|
||||||
toBaseWord8 n
|
toBaseWord8 digits n
|
||||||
| n < 0xff = [
|
| n < 0xff = (fromIntegral n):digits
|
||||||
to
|
| otherwise =
|
||||||
|
let newDigits = (fromIntegral (n `mod` 0xff)):digits in
|
||||||
|
case n `div` 0xff of
|
||||||
|
0 -> newDigits
|
||||||
|
k -> toBaseWord8 newDigits k
|
||||||
|
|
||||||
data StateOperator =
|
data StateOperator =
|
||||||
Cm | W | J | J_ | M | D | Ri | I | Gs -- general graphic state
|
Cm | W | J | J_ | M | D | Ri | I | Gs -- general graphic state
|
||||||
|
|
Loading…
Reference in a new issue