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)