From 22cde370256ad2d76fea3740dcc157c4d17b1f9b Mon Sep 17 00:00:00 2001 From: Tissevert Date: Wed, 5 Feb 2020 14:42:51 +0100 Subject: [PATCH] Add a Font class type to allow text rendition schemes other than CMaps --- Hufflepdf.cabal | 1 + src/PDF/CMap.hs | 6 ++++++ src/PDF/Font.hs | 9 +++++++++ 3 files changed, 16 insertions(+) create mode 100644 src/PDF/Font.hs diff --git a/Hufflepdf.cabal b/Hufflepdf.cabal index 9186d7f..39ee5d7 100644 --- a/Hufflepdf.cabal +++ b/Hufflepdf.cabal @@ -27,6 +27,7 @@ library , PDF.Update other-modules: Data.ByteString.Char8.Util , PDF.Body + , PDF.Font -- other-extensions: build-depends: attoparsec , base >=4.9 && <4.13 diff --git a/src/PDF/CMap.hs b/src/PDF/CMap.hs index 51a48db..4a99f00 100644 --- a/src/PDF/CMap.hs +++ b/src/PDF/CMap.hs @@ -1,4 +1,6 @@ {-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE TypeSynonymInstances #-} module PDF.CMap ( CMap , CMappers @@ -19,6 +21,7 @@ import Data.ByteString.Char8.Util ( import Data.Map (Map, union) import qualified Data.Map as Map (adjust, empty, fromList, insertWith) import qualified PDF.EOL as EOL (charset, parser) +import PDF.Font (Font(..)) import PDF.Object ( DirectObject(..), Name, StringObject(..) , blank, directObject, integer, line, stringObject @@ -35,6 +38,9 @@ data CRange = CRange { type RangeSize = Int type CMap = Map RangeSize [CRange] +instance Font CMap where + decode = undefined + emptyCMap :: CMap emptyCMap = Map.empty diff --git a/src/PDF/Font.hs b/src/PDF/Font.hs new file mode 100644 index 0000000..0f23c7c --- /dev/null +++ b/src/PDF/Font.hs @@ -0,0 +1,9 @@ +module PDF.Font ( + Font(..) + ) where + +import Data.ByteString (ByteString) +import PDF.Object (StringObject) + +class Font a where + decode :: a -> StringObject -> ByteString