Fixed vicious bug introduced by 6096a1a237 (since follow is now automatic for references, it's not called explicitely but should in case of 'several' Content, which is an array of references, each of which should be expended) — TODO: add a unit test for that

This commit is contained in:
Tissevert 2020-03-04 18:14:33 +01:00
parent d288ecf0ac
commit 7cef65d799
2 changed files with 12 additions and 10 deletions

View File

@ -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

View File

@ -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 =