From c8a5e2b191acb5d28cf2abdd4a009ecf62523184 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Tue, 17 Mar 2020 16:39:06 +0100 Subject: [PATCH] Wait, CachedFonts are indexed by Id Object so it could be an IdMap actually --- src/PDF/Pages.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/PDF/Pages.hs b/src/PDF/Pages.hs index e02d802..a78f709 100755 --- a/src/PDF/Pages.hs +++ b/src/PDF/Pages.hs @@ -20,9 +20,10 @@ import Control.Monad.Reader (ReaderT, runReaderT) import Control.Monad.State (StateT(..), evalStateT, execStateT, gets, modify) import Control.Monad.Trans (lift) import Data.ByteString.Lazy (toStrict) -import Data.Id (Id) +import Data.Id (Id, IdMap) +import qualified Data.Id as Id (empty, insert, lookup) import Data.Map (Map) -import qualified Data.Map as Map (empty, fromList, insert, lookup, toList) +import qualified Data.Map as Map (empty, fromList, insert, toList) import Data.OrderedMap (OrderedMap, build, mapi) import PDF.Box (Box(..), at, edit) import PDF.CMap (cMap) @@ -47,7 +48,7 @@ import Text.Printf (printf) type Except m = (Alternative m, MonadFail m) type InLayer m = ReaderT Layer m -type CachedFonts = Map (Id Object) Font +type CachedFonts = IdMap Object Font type FontCache m = StateT CachedFonts (InLayer m) data Page = Page { contents :: OrderedMap (Id Object) Content @@ -70,11 +71,11 @@ getFontDictionary pageObj = cache :: Except m => ((Id Object) -> FontCache m Font) -> (Id Object) -> FontCache m Font cache loader objectId = - gets (Map.lookup objectId) >>= maybe load return + gets (Id.lookup objectId) >>= maybe load return where load = do value <- loader objectId - modify $ Map.insert objectId value + modify $ Id.insert objectId value return value loadFont :: Except m => (Id Object) -> FontCache m Font @@ -150,7 +151,7 @@ instance Monad m => Box m Contents Page (OrderedMap (Id Object) Content) where w _ contents page = return $ page {contents} withFonts :: Monad m => (Layer -> FontCache m a) -> Layer -> m a -withFonts f layer = runReaderT (evalStateT (f layer) Map.empty) layer +withFonts f layer = runReaderT (evalStateT (f layer) Id.empty) layer withResources :: Except m => (Page -> ReaderT FontSet m b) -> Page -> FontCache m b withResources f p =