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 =