From 7cef65d799ae776cfd7cd00e7323c9f44bf7c58d Mon Sep 17 00:00:00 2001 From: Tissevert Date: Wed, 4 Mar 2020 18:14:33 +0100 Subject: [PATCH] =?UTF-8?q?Fixed=20vicious=20bug=20introduced=20by=206096a?= =?UTF-8?q?1a2379b785b95c3431927f7ace5f5815a72=20(since=20follow=20is=20no?= =?UTF-8?q?w=20automatic=20for=20references,=20it's=20not=20called=20expli?= =?UTF-8?q?citely=20but=20should=20in=20case=20of=20'several'=20Content,?= =?UTF-8?q?=20which=20is=20an=20array=20of=20references,=20each=20of=20whi?= =?UTF-8?q?ch=20should=20be=20expended)=20=E2=80=94=20TODO:=20add=20a=20un?= =?UTF-8?q?it=20test=20for=20that?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PDF/Object/Navigation.hs | 10 ++++++---- src/PDF/Pages.hs | 12 ++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/PDF/Object/Navigation.hs b/src/PDF/Object/Navigation.hs index fc8a7d1..e0ba786 100644 --- a/src/PDF/Object/Navigation.hs +++ b/src/PDF/Object/Navigation.hs @@ -12,6 +12,7 @@ module PDF.Object.Navigation ( , (//) , (>./) , (>//) + , castObject , getDictionary , objectById , origin @@ -68,10 +69,11 @@ objectById objectId = do (./) :: PDFContent m => m Object -> Component -> m Object (./) object key = (object >>= getDictionary >>= getField key >>= castObject) - where - castObject (Reference (IndirectObjCoordinates {objectId})) = - objectById objectId - castObject directObject = return $ Direct directObject + +castObject :: PDFContent m => DirectObject -> m Object +castObject (Reference (IndirectObjCoordinates {objectId})) = + objectById objectId +castObject directObject = return $ Direct directObject (//) :: PDFContent m => m Object -> [Component] -> m Object (//) object [] = object diff --git a/src/PDF/Pages.hs b/src/PDF/Pages.hs index c4fd585..0eb8e36 100755 --- a/src/PDF/Pages.hs +++ b/src/PDF/Pages.hs @@ -37,8 +37,8 @@ import PDF.Object ( , Name(..), Object(..) ,) import PDF.Object.Navigation ( - Error(..), PDFContent, StreamContent(..), (//), (>./), (>//), getDictionary, objectById - , origin + Error(..), PDFContent, StreamContent(..), (./), (//), (>./), (>//) + , castObject, getDictionary, objectById, origin ) import PDF.Output (ObjectId(..)) import Prelude hiding (fail) @@ -88,9 +88,9 @@ loadFonts = foldM addFont Map.empty . Map.toList flip (Map.insert name) output <$> cache loadFont objectId addFont output _ = return output -several :: Object -> [Object] -several (Direct (Array l)) = Direct <$> l -several object = [object] +several :: PDFContent m => Object -> m [Object] +several (Direct (Array l)) = mapM castObject l +several object = return [object] pagesList :: PDFContent m => m [ObjectId] pagesList = do @@ -109,7 +109,7 @@ getReferences objects = do extractText :: FontCache m => Object -> m [Text] extractText pageObj = do fonts <- loadFonts =<< getFontDictionary pageObj - objects <- several <$> pageObj >./ "Contents" + objects <- pageObj >./ "Contents" >>= several concat <$> mapM (loadContent fonts) objects where loadContent fonts object =