pdf-toolbox-document 0.0.2.0 → 0.0.3.0
raw patch · 2 files changed
+76/−6 lines, 2 filesdep ~basedep ~pdf-toolbox-content
Dependency ranges changed: base, pdf-toolbox-content
Files
lib/Pdf/Toolbox/Document/FontDict.hs view
@@ -11,8 +11,10 @@ ) where +import Data.Word import Data.Monoid import Data.Functor+import Data.ByteString (ByteString) import Control.Monad import qualified System.IO.Streams as Streams @@ -49,6 +51,23 @@ subtype <- fontDictSubtype fd case subtype of FontType0 -> FontInfoComposite <$> loadFontInfoComposite fontDict+ FontType3 -> do+ fi <- loadFontInfoSimple fontDict+ Array arr <- lookupDict "FontMatrix" fontDict >>= deref >>= fromObject+ fontMatrix <-+ case arr of+ [a, b, c, d, e, f] -> do+ a' <- fromObject a >>= realValue+ b' <- fromObject b >>= realValue+ c' <- fromObject c >>= realValue+ d' <- fromObject d >>= realValue+ e' <- fromObject e >>= realValue+ f' <- fromObject f >>= realValue+ return $ Transform a' b' c' d' e' f'+ _ -> left $ UnexpectedError "FontMatrix: wrong number of elements"+ return $ FontInfoSimple fi {+ fiSimpleFontMatrix = fontMatrix+ } _ -> FontInfoSimple <$> loadFontInfoSimple fontDict loadFontInfoComposite :: (MonadPdf m, MonadIO m) => Dict -> PdfE m FIComposite@@ -78,8 +97,36 @@ toUnicode <- loadUnicodeCMap fontDict encoding <- case lookupDict' "Encoding" fontDict of- Just (OName "WinAnsiEncoding") -> return $ Just SimpleFontEncodingWinAnsi- Just (OName "MacRomanEncoding") -> return $ Just SimpleFontEncodingMacRoman+ Just (OName "WinAnsiEncoding") -> return $ Just SimpleFontEncoding {+ simpleFontBaseEncoding = FontBaseEncodingWinAnsi,+ simpleFontDifferences = []+ }+ Just (OName "MacRomanEncoding") -> return $ Just SimpleFontEncoding {+ simpleFontBaseEncoding = FontBaseEncodingMacRoman,+ simpleFontDifferences = []+ }+ Just o -> do+ encDict <- deref o >>= fromObject+ case lookupDict' "BaseEncoding" encDict of+ Just (OName "WinAnsiEncoding") -> do+ diffs <- loadEncodingDifferences encDict+ return $ Just SimpleFontEncoding {+ simpleFontBaseEncoding = FontBaseEncodingWinAnsi,+ simpleFontDifferences = diffs+ }+ Just (OName "MacRomanEncoding") -> do+ diffs <- loadEncodingDifferences encDict+ return $ Just SimpleFontEncoding {+ simpleFontBaseEncoding = FontBaseEncodingMacRoman,+ simpleFontDifferences = diffs+ }+ Nothing -> do+ diffs <- loadEncodingDifferences encDict+ return $ Just SimpleFontEncoding {+ simpleFontBaseEncoding = FontBaseEncodingWinAnsi, -- XXX: should be StandardEncoding?+ simpleFontDifferences = diffs+ }+ _ -> return Nothing _ -> return Nothing widths <- case lookupDict' "Widths" fontDict of@@ -93,8 +140,31 @@ return $ FISimple { fiSimpleUnicodeCMap = toUnicode, fiSimpleEncoding = encoding,- fiSimpleWidths = widths+ fiSimpleWidths = widths,+ fiSimpleFontMatrix = scale 0.001 0.001 }++loadEncodingDifferences :: MonadPdf m => Dict -> PdfE m [(Word8, ByteString)]+loadEncodingDifferences dict = do+ case lookupDict' "Differences" dict of+ Nothing -> return []+ Just o -> do+ Array arr <- deref o >>= fromObject+ case arr of+ [] -> return []+ (ONumber n : rest) -> do+ n' <- fromIntegral <$> intValue n+ go [] n' rest+ _ -> left $ UnexpectedError "Differences array: the first object should be a number"+ where+ go res _ [] = return res+ go res n (o:rest) =+ case o of+ (ONumber n') -> do+ n'' <- fromIntegral <$> intValue n'+ go res n'' rest+ (OName (Name bs)) -> go (((n, bs)) : res) (n + 1) rest+ _ -> left $ UnexpectedError $ "Differences array: unexpected object: " ++ show o loadUnicodeCMap :: (MonadPdf m, MonadIO m) => Dict -> PdfE m (Maybe UnicodeCMap) loadUnicodeCMap fontDict =
pdf-toolbox-document.cabal view
@@ -1,5 +1,5 @@ name: pdf-toolbox-document-version: 0.0.2.0+version: 0.0.3.0 synopsis: A collection of tools for processing PDF files. license: BSD3 license-file: LICENSE@@ -34,7 +34,7 @@ Pdf.Toolbox.Document.Encryption Pdf.Toolbox.Document.Internal.Types Pdf.Toolbox.Document.Internal.Util- build-depends: base ==4.6.*,+ build-depends: base >= 4.6 && < 4.8, transformers, containers, text,@@ -43,4 +43,4 @@ cipher-rc4, cryptohash, pdf-toolbox-core ==0.0.2.*,- pdf-toolbox-content ==0.0.2.*+ pdf-toolbox-content ==0.0.3.*