diff --git a/Hufflepdf.cabal b/Hufflepdf.cabal index 2ae660b..cc3003e 100644 --- a/Hufflepdf.cabal +++ b/Hufflepdf.cabal @@ -78,7 +78,6 @@ executable getText , bytestring , containers , Hufflepdf - , mtl , text ghc-options: -Wall default-language: Haskell2010 diff --git a/examples/getText.hs b/examples/getText.hs index 4e88f67..3ec1136 100644 --- a/examples/getText.hs +++ b/examples/getText.hs @@ -1,7 +1,6 @@ {-# LANGUAGE FlexibleContexts #-} import Control.Monad ((>=>)) import Control.Monad.IO.Class (liftIO) -import Control.Monad.Reader (runReaderT) import qualified Data.ByteString.Char8 as BS (readFile) import Data.Id (Id(..), mapWithKey) import qualified Data.Map as Map (toList) @@ -34,11 +33,11 @@ displayPage n = withResources ( getAll :: Layer -> IO () getAll layer = Map.toList <$> r Pages layer - >>= flip runReaderT layer . cacheFonts . mapM_ (uncurry displayPage) + >>= cacheFonts layer . mapM_ (uncurry displayPage) get :: Int -> Layer -> IO () get n layer = - r (P n) layer >>= flip runReaderT layer . cacheFonts . displayPage n + r (P n) layer >>= cacheFonts layer . displayPage n onDoc :: FilePath -> (Layer -> IO ()) -> IO () onDoc inputFile f = do diff --git a/src/PDF/Pages.hs b/src/PDF/Pages.hs index 3bd84d2..0510287 100755 --- a/src/PDF/Pages.hs +++ b/src/PDF/Pages.hs @@ -149,8 +149,8 @@ instance Monad m => Box m Contents Page (OrderedMap (Id Object) Content) where r Contents = return . contents w _ contents page = return $ page {contents} -cacheFonts :: Monad m => StateT CachedFonts m a -> m a -cacheFonts = flip evalStateT Map.empty +cacheFonts :: Monad m => Layer -> FontCache m a -> m a +cacheFonts layer = flip runReaderT layer . flip evalStateT Map.empty withResources :: Except m => (Page -> ReaderT FontSet m b) -> Page -> FontCache m b withResources f p =