From 6e245189fd6dc4d1a93339cb6455e14c9ede3344 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Thu, 5 Mar 2020 17:44:38 +0100 Subject: [PATCH] Add a simple Box instance that exposes IndexedInstructions within a Content --- src/PDF/Content.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PDF/Content.hs b/src/PDF/Content.hs index 7ebca2f..48346b5 100644 --- a/src/PDF/Content.hs +++ b/src/PDF/Content.hs @@ -2,6 +2,9 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE TypeSynonymInstances #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} module PDF.Content ( Content(..) , ContentUnit(..) @@ -20,13 +23,14 @@ import Data.Attoparsec.ByteString.Char8 (sepBy) import Data.ByteString (ByteString) import Data.Map (Map, (!)) import qualified Data.Map as Map (empty, insert, size) +import PDF.Box (Box(..)) import PDF.Content.Operator (Instruction, operator) import PDF.Object (blank, directObject) import PDF.Output (Output(..), line) import PDF.Parser (MonadParser, evalParser, string) newtype InstructionId = InstructionId Int deriving (Eq, Ord, Show) - +data Instructions = Instructions type IndexedInstructions = Map InstructionId Instruction data GraphicContextUnit = @@ -45,6 +49,11 @@ data Content = Content { type InstructionParser m = (MonadParser m, MonadState IndexedInstructions m) +instance Monad m => Box m Instructions Content IndexedInstructions where + r Instructions = return . indexedInstructions + w Instructions indexedInstructions someContent = + return $ someContent {indexedInstructions} + register :: MonadState IndexedInstructions m => Instruction -> m InstructionId register newInstruction = do newInstructionID <- gets (InstructionId . Map.size)