pdf-toolbox-core 0.1.1 → 0.1.2
raw patch · 8 files changed
+57/−25 lines, 8 filesdep ~bytestringPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: bytestring
API changes (from Hackage documentation)
+ Pdf.Core.Parsers.Util: skipSpace :: Parser ()
+ Pdf.Core.Types: rectangleToArray :: Rectangle Double -> Array
Files
- changelog.md +4/−1
- lib/Pdf/Core/Parsers/Object.hs +11/−11
- lib/Pdf/Core/Parsers/Util.hs +13/−2
- lib/Pdf/Core/Parsers/XRef.hs +6/−6
- lib/Pdf/Core/Types.hs +7/−1
- lib/Pdf/Core/XRef.hs +4/−1
- pdf-toolbox-core.cabal +3/−3
- test/Test/Parsers/Object.hs +9/−0
changelog.md view
@@ -1,4 +1,7 @@-unreleased+0.1.2++* support ghc from 8.6 to 9.6 and drop older versions+* handle comments inside objects 0.1.1
lib/Pdf/Core/Parsers/Object.hs view
@@ -44,13 +44,13 @@ parseDict = do void $ P.string "<<" dict <- many parseKey- P.skipSpace+ skipSpace void $ P.string ">>" return $ HashMap.fromList dict parseKey :: Parser (Name, Object) parseKey = do- P.skipSpace+ skipSpace key <- parseName val <- parseObject return (key, val)@@ -60,7 +60,7 @@ parseArray = do void $ P.char '[' array <- many parseObject- P.skipSpace+ skipSpace void $ P.char ']' return $ Vector.fromList array @@ -143,9 +143,9 @@ parseRef :: Parser Ref parseRef = do obj <- P.decimal- P.skipSpace+ skipSpace gen <- P.decimal- P.skipSpace+ skipSpace void $ P.char 'R' return $ R obj gen @@ -181,7 +181,7 @@ -- Done "1234\nendstream" Dict [(Name "Key",ONumber (NumInt 123))] parseTillStreamData :: Parser () parseTillStreamData = do- P.skipSpace+ skipSpace void $ P.string "stream" endOfLine @@ -192,7 +192,7 @@ -- Right (OName (Name "Name")) parseObject :: Parser Object parseObject = do- P.skipSpace+ skipSpace P.choice [ const Null <$> P.string "null", Name <$> parseName,@@ -212,13 +212,13 @@ -- Right (Ref 1 2,ONumber (NumInt 12)) parseIndirectObject :: Parser (Ref, Object) parseIndirectObject = do- P.skipSpace+ skipSpace index <- P.decimal :: Parser Int- P.skipSpace+ skipSpace gen <- P.decimal :: Parser Int- P.skipSpace+ skipSpace void $ P.string "obj"- P.skipSpace+ skipSpace obj <- parseObject let ref = R index gen case obj of
lib/Pdf/Core/Parsers/Util.hs view
@@ -2,8 +2,8 @@ -- | Utils module Pdf.Core.Parsers.Util-(- endOfLine+( endOfLine+, skipSpace ) where @@ -21,3 +21,14 @@ P.endOfLine, -- it already handles both the \n and \n\r P.char '\r' >>= const (return ()) ]++skipSpace :: Parser ()+skipSpace = do+ P.skipSpace+ _ <- many (skipComment *> P.skipSpace)+ return ()++skipComment :: Parser ()+skipComment = do+ _ <- P.char '%'+ P.skipWhile (`notElem` "\r\n")
lib/Pdf/Core/Parsers/XRef.hs view
@@ -37,7 +37,7 @@ startXRef = do res <- many $ do _ <- P.manyTill P.anyChar $ P.string "startxref"- P.skipSpace+ skipSpace offset <- P.decimal P.skipSpace _ <- P.string "%%EOF"@@ -66,7 +66,7 @@ parseSubsectionHeader :: Parser (Int, Int) parseSubsectionHeader = do start <- P.decimal- P.skipSpace+ skipSpace count <- P.decimal endOfLine return (start, count)@@ -76,19 +76,19 @@ -- Input position should point to the \"trailer\" keyword parseTrailerAfterTable :: Parser Dict parseTrailerAfterTable = do- P.skipSpace+ skipSpace _ <- P.string "trailer" endOfLine- P.skipSpace+ skipSpace parseDict -- | Parse XRef table entry. Returns offset, generation and whether the object is free. parseTableEntry :: Parser (Int64, Int, Bool) parseTableEntry = do offset <- P.decimal- P.skipSpace+ skipSpace generation <- P.decimal- P.skipSpace+ skipSpace c <- P.anyChar case c of 'n' -> return (offset, generation, False)
lib/Pdf/Core/Types.hs view
@@ -4,10 +4,12 @@ module Pdf.Core.Types ( Rectangle(..),- rectangleFromArray+ rectangleFromArray,+ rectangleToArray ) where +import qualified Data.Scientific as Scientific import Pdf.Core import Pdf.Core.Util import Pdf.Core.Object.Util@@ -26,3 +28,7 @@ case res of [a, b, c, d] -> return $ Rectangle a b c d _ -> Left ("rectangleFromArray: " ++ show arr)++rectangleToArray :: Rectangle Double -> Array+rectangleToArray (Rectangle a b c d) =+ Vector.fromList . map (Number . Scientific.fromFloatDigits) $ [a, b, c, d]
lib/Pdf/Core/XRef.hs view
@@ -228,7 +228,7 @@ case values of Nothing -> return Nothing Just vs -> do- let [v1, v2, v3] = map conv $ collect [] width vs :: [Int64]+ let vs' = map conv $ collect [] width vs :: [Int64] where conv l = conv' (length l - 1) 0 l conv' _ res [] = res@@ -237,6 +237,9 @@ collect res [] [] = reverse res collect res (x:xs) ys = collect (take x ys : res) xs (drop x ys) collect _ _ _ = error "readStreamEntry: collect: impossible"+ (v1, v2, v3) <- case vs' of+ [a, b, c] -> return (a, b, c)+ _ -> throwIO $ Corrupted "lookupStreamEntry" ["expected 3 values"] case v1 of 0 -> return $ Just $ EntryFree (fromIntegral v2) (fromIntegral v3)
pdf-toolbox-core.cabal view
@@ -1,5 +1,5 @@ name: pdf-toolbox-core-version: 0.1.1+version: 0.1.2 synopsis: A collection of tools for processing PDF files. license: BSD3 license-file: LICENSE@@ -60,8 +60,8 @@ Pdf.Core.Util Pdf.Core.Writer other-modules: Prelude- build-depends: base >= 4.5 && < 5,- bytestring >= 0.10.4 && < 0.12,+ build-depends: base >= 4.9 && < 5,+ bytestring >= 0.10.4 && < 0.13, base16-bytestring >= 1, io-streams, attoparsec >= 0.12,
test/Test/Parsers/Object.hs view
@@ -94,6 +94,15 @@ it "should parse a dictionary" $ do parseOnly parseDict "<</hello true>>" `shouldBe` Right (HashMap.fromList [("hello", Bool True)])+ it "should allow comments inside" $ do+ parseOnly parseDict "<</hello%I'm a comment\ntrue>>"+ `shouldBe` Right (HashMap.fromList [("hello", Bool True)])+ parseOnly parseDict "<</hello%I'm a comment\n%another\ntrue>>"+ `shouldBe` Right (HashMap.fromList [("hello", Bool True)])+ parseOnly parseDict "<</hello%I'm a comment\n\rtrue>>"+ `shouldBe` Right (HashMap.fromList [("hello", Bool True)])+ parseOnly parseDict "<</hello %I'm a comment\n true>>"+ `shouldBe` Right (HashMap.fromList [("hello", Bool True)]) parseRefSpec :: Spec parseRefSpec = describe "parseRef" $ do