From 5027b079eb4338eff80f5dd9d28d516376267086 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Tue, 17 Mar 2020 08:36:02 +0100 Subject: [PATCH] Include page numbers in chunks label, needed for long documents with many pages --- examples/getText.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/getText.hs b/examples/getText.hs index 1d96951..4e88f67 100644 --- a/examples/getText.hs +++ b/examples/getText.hs @@ -19,8 +19,8 @@ import System.Exit (die) import System.IO (BufferMode(..), hSetBuffering, stdout) import Text.Printf (printf) -displayPage :: Page -> FontCache IO () -displayPage = withResources ( +displayPage :: Int -> Page -> FontCache IO () +displayPage n = withResources ( r Contents >=> sequence_ . mapi (\objectId -> r Chunks >=> sequence_ . mapWithKey (display objectId) @@ -29,15 +29,16 @@ displayPage = withResources ( where display a b v = liftIO . putStrLn $ - printf "%d@%d: %s" (getId a) (getId b) (Text.unpack v) + printf "p#%d obj#%d instr#%d: %s" n (getId a) (getId b) (Text.unpack v) getAll :: Layer -> IO () getAll layer = - r Pages layer - >>= flip runReaderT layer . cacheFonts . mapM_ (displayPage . snd) . Map.toList + Map.toList <$> r Pages layer + >>= flip runReaderT layer . cacheFonts . mapM_ (uncurry displayPage) get :: Int -> Layer -> IO () -get n layer = r (P n) layer >>= flip runReaderT layer . cacheFonts . displayPage +get n layer = + r (P n) layer >>= flip runReaderT layer . cacheFonts . displayPage n onDoc :: FilePath -> (Layer -> IO ()) -> IO () onDoc inputFile f = do