{-# LANGUAGE OverloadedStrings #-} module PDF.TextRendering ( TextRendering(..) , update ) where import Data.ByteString.Lazy.Char8 (ByteString) import qualified Data.ByteString.Lazy.Char8 as BS (intercalate, pack, readInt, split) import Prelude hiding (unwords, words) data TextRendering = Fill | Stroke | FillStroke | Invisible | FillAddPath | StrokeAddPath | FillStrokeAddPath | AddPath deriving (Enum, Show) update :: (TextRendering -> TextRendering) -> ByteString -> ByteString update f = unwords . changeTextRendering . words where changeTextRendering l@[value, "Tr"] = case BS.readInt value of Just (n, _) -> [BS.pack . show . fromEnum . f $ toEnum n, "Tr"] _ -> l changeTextRendering l = l words = BS.split ' ' unwords = BS.intercalate " "