{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Graphics.PDF.Fonts.FontTypes
( GlyphSize(..)
, FontSize
, FontStructure(..)
, GlyphPair(..)
, GlyphCode(..)
, FontData(..)
, mkFlags
)
where
import Graphics.PDF.LowLevel.Types
import qualified Data.Map.Strict as M
import qualified Data.ByteString as B
import Data.Word
import Data.Bits hiding(bit)
type FontSize = Int
newtype GlyphSize = GlyphSize Int deriving(GlyphSize -> GlyphSize -> Bool
(GlyphSize -> GlyphSize -> Bool)
-> (GlyphSize -> GlyphSize -> Bool) -> Eq GlyphSize
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GlyphSize -> GlyphSize -> Bool
== :: GlyphSize -> GlyphSize -> Bool
$c/= :: GlyphSize -> GlyphSize -> Bool
/= :: GlyphSize -> GlyphSize -> Bool
Eq,Eq GlyphSize
Eq GlyphSize =>
(GlyphSize -> GlyphSize -> Ordering)
-> (GlyphSize -> GlyphSize -> Bool)
-> (GlyphSize -> GlyphSize -> Bool)
-> (GlyphSize -> GlyphSize -> Bool)
-> (GlyphSize -> GlyphSize -> Bool)
-> (GlyphSize -> GlyphSize -> GlyphSize)
-> (GlyphSize -> GlyphSize -> GlyphSize)
-> Ord GlyphSize
GlyphSize -> GlyphSize -> Bool
GlyphSize -> GlyphSize -> Ordering
GlyphSize -> GlyphSize -> GlyphSize
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: GlyphSize -> GlyphSize -> Ordering
compare :: GlyphSize -> GlyphSize -> Ordering
$c< :: GlyphSize -> GlyphSize -> Bool
< :: GlyphSize -> GlyphSize -> Bool
$c<= :: GlyphSize -> GlyphSize -> Bool
<= :: GlyphSize -> GlyphSize -> Bool
$c> :: GlyphSize -> GlyphSize -> Bool
> :: GlyphSize -> GlyphSize -> Bool
$c>= :: GlyphSize -> GlyphSize -> Bool
>= :: GlyphSize -> GlyphSize -> Bool
$cmax :: GlyphSize -> GlyphSize -> GlyphSize
max :: GlyphSize -> GlyphSize -> GlyphSize
$cmin :: GlyphSize -> GlyphSize -> GlyphSize
min :: GlyphSize -> GlyphSize -> GlyphSize
Ord,Integer -> GlyphSize
GlyphSize -> GlyphSize
GlyphSize -> GlyphSize -> GlyphSize
(GlyphSize -> GlyphSize -> GlyphSize)
-> (GlyphSize -> GlyphSize -> GlyphSize)
-> (GlyphSize -> GlyphSize -> GlyphSize)
-> (GlyphSize -> GlyphSize)
-> (GlyphSize -> GlyphSize)
-> (GlyphSize -> GlyphSize)
-> (Integer -> GlyphSize)
-> Num GlyphSize
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: GlyphSize -> GlyphSize -> GlyphSize
+ :: GlyphSize -> GlyphSize -> GlyphSize
$c- :: GlyphSize -> GlyphSize -> GlyphSize
- :: GlyphSize -> GlyphSize -> GlyphSize
$c* :: GlyphSize -> GlyphSize -> GlyphSize
* :: GlyphSize -> GlyphSize -> GlyphSize
$cnegate :: GlyphSize -> GlyphSize
negate :: GlyphSize -> GlyphSize
$cabs :: GlyphSize -> GlyphSize
abs :: GlyphSize -> GlyphSize
$csignum :: GlyphSize -> GlyphSize
signum :: GlyphSize -> GlyphSize
$cfromInteger :: Integer -> GlyphSize
fromInteger :: Integer -> GlyphSize
Num,Enum GlyphSize
Real GlyphSize
(Real GlyphSize, Enum GlyphSize) =>
(GlyphSize -> GlyphSize -> GlyphSize)
-> (GlyphSize -> GlyphSize -> GlyphSize)
-> (GlyphSize -> GlyphSize -> GlyphSize)
-> (GlyphSize -> GlyphSize -> GlyphSize)
-> (GlyphSize -> GlyphSize -> (GlyphSize, GlyphSize))
-> (GlyphSize -> GlyphSize -> (GlyphSize, GlyphSize))
-> (GlyphSize -> Integer)
-> Integral GlyphSize
GlyphSize -> Integer
GlyphSize -> GlyphSize -> (GlyphSize, GlyphSize)
GlyphSize -> GlyphSize -> GlyphSize
forall a.
(Real a, Enum a) =>
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> (a, a))
-> (a -> a -> (a, a))
-> (a -> Integer)
-> Integral a
$cquot :: GlyphSize -> GlyphSize -> GlyphSize
quot :: GlyphSize -> GlyphSize -> GlyphSize
$crem :: GlyphSize -> GlyphSize -> GlyphSize
rem :: GlyphSize -> GlyphSize -> GlyphSize
$cdiv :: GlyphSize -> GlyphSize -> GlyphSize
div :: GlyphSize -> GlyphSize -> GlyphSize
$cmod :: GlyphSize -> GlyphSize -> GlyphSize
mod :: GlyphSize -> GlyphSize -> GlyphSize
$cquotRem :: GlyphSize -> GlyphSize -> (GlyphSize, GlyphSize)
quotRem :: GlyphSize -> GlyphSize -> (GlyphSize, GlyphSize)
$cdivMod :: GlyphSize -> GlyphSize -> (GlyphSize, GlyphSize)
divMod :: GlyphSize -> GlyphSize -> (GlyphSize, GlyphSize)
$ctoInteger :: GlyphSize -> Integer
toInteger :: GlyphSize -> Integer
Integral,Int -> GlyphSize
GlyphSize -> Int
GlyphSize -> [GlyphSize]
GlyphSize -> GlyphSize
GlyphSize -> GlyphSize -> [GlyphSize]
GlyphSize -> GlyphSize -> GlyphSize -> [GlyphSize]
(GlyphSize -> GlyphSize)
-> (GlyphSize -> GlyphSize)
-> (Int -> GlyphSize)
-> (GlyphSize -> Int)
-> (GlyphSize -> [GlyphSize])
-> (GlyphSize -> GlyphSize -> [GlyphSize])
-> (GlyphSize -> GlyphSize -> [GlyphSize])
-> (GlyphSize -> GlyphSize -> GlyphSize -> [GlyphSize])
-> Enum GlyphSize
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: GlyphSize -> GlyphSize
succ :: GlyphSize -> GlyphSize
$cpred :: GlyphSize -> GlyphSize
pred :: GlyphSize -> GlyphSize
$ctoEnum :: Int -> GlyphSize
toEnum :: Int -> GlyphSize
$cfromEnum :: GlyphSize -> Int
fromEnum :: GlyphSize -> Int
$cenumFrom :: GlyphSize -> [GlyphSize]
enumFrom :: GlyphSize -> [GlyphSize]
$cenumFromThen :: GlyphSize -> GlyphSize -> [GlyphSize]
enumFromThen :: GlyphSize -> GlyphSize -> [GlyphSize]
$cenumFromTo :: GlyphSize -> GlyphSize -> [GlyphSize]
enumFromTo :: GlyphSize -> GlyphSize -> [GlyphSize]
$cenumFromThenTo :: GlyphSize -> GlyphSize -> GlyphSize -> [GlyphSize]
enumFromThenTo :: GlyphSize -> GlyphSize -> GlyphSize -> [GlyphSize]
Enum,Num GlyphSize
Ord GlyphSize
(Num GlyphSize, Ord GlyphSize) =>
(GlyphSize -> Rational) -> Real GlyphSize
GlyphSize -> Rational
forall a. (Num a, Ord a) => (a -> Rational) -> Real a
$ctoRational :: GlyphSize -> Rational
toRational :: GlyphSize -> Rational
Real,Int -> GlyphSize -> ShowS
[GlyphSize] -> ShowS
GlyphSize -> String
(Int -> GlyphSize -> ShowS)
-> (GlyphSize -> String)
-> ([GlyphSize] -> ShowS)
-> Show GlyphSize
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GlyphSize -> ShowS
showsPrec :: Int -> GlyphSize -> ShowS
$cshow :: GlyphSize -> String
show :: GlyphSize -> String
$cshowList :: [GlyphSize] -> ShowS
showList :: [GlyphSize] -> ShowS
Show)
data GlyphPair = GlyphPair !GlyphCode !GlyphCode deriving(GlyphPair -> GlyphPair -> Bool
(GlyphPair -> GlyphPair -> Bool)
-> (GlyphPair -> GlyphPair -> Bool) -> Eq GlyphPair
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: GlyphPair -> GlyphPair -> Bool
== :: GlyphPair -> GlyphPair -> Bool
$c/= :: GlyphPair -> GlyphPair -> Bool
/= :: GlyphPair -> GlyphPair -> Bool
Eq,Eq GlyphPair
Eq GlyphPair =>
(GlyphPair -> GlyphPair -> Ordering)
-> (GlyphPair -> GlyphPair -> Bool)
-> (GlyphPair -> GlyphPair -> Bool)
-> (GlyphPair -> GlyphPair -> Bool)
-> (GlyphPair -> GlyphPair -> Bool)
-> (GlyphPair -> GlyphPair -> GlyphPair)
-> (GlyphPair -> GlyphPair -> GlyphPair)
-> Ord GlyphPair
GlyphPair -> GlyphPair -> Bool
GlyphPair -> GlyphPair -> Ordering
GlyphPair -> GlyphPair -> GlyphPair
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: GlyphPair -> GlyphPair -> Ordering
compare :: GlyphPair -> GlyphPair -> Ordering
$c< :: GlyphPair -> GlyphPair -> Bool
< :: GlyphPair -> GlyphPair -> Bool
$c<= :: GlyphPair -> GlyphPair -> Bool
<= :: GlyphPair -> GlyphPair -> Bool
$c> :: GlyphPair -> GlyphPair -> Bool
> :: GlyphPair -> GlyphPair -> Bool
$c>= :: GlyphPair -> GlyphPair -> Bool
>= :: GlyphPair -> GlyphPair -> Bool
$cmax :: GlyphPair -> GlyphPair -> GlyphPair
max :: GlyphPair -> GlyphPair -> GlyphPair
$cmin :: GlyphPair -> GlyphPair -> GlyphPair
min :: GlyphPair -> GlyphPair -> GlyphPair
Ord,Int -> GlyphPair -> ShowS
[GlyphPair] -> ShowS
GlyphPair -> String
(Int -> GlyphPair -> ShowS)
-> (GlyphPair -> String)
-> ([GlyphPair] -> ShowS)
-> Show GlyphPair
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> GlyphPair -> ShowS
showsPrec :: Int -> GlyphPair -> ShowS
$cshow :: GlyphPair -> String
show :: GlyphPair -> String
$cshowList :: [GlyphPair] -> ShowS
showList :: [GlyphPair] -> ShowS
Show)
data FontStructure = FS { FontStructure -> String
baseFont :: String
, FontStructure -> GlyphSize
descent :: !GlyphSize
, FontStructure -> GlyphSize
ascent :: !GlyphSize
, FontStructure -> GlyphSize
height :: !GlyphSize
, FontStructure -> Map GlyphCode GlyphSize
widthData :: M.Map GlyphCode GlyphSize
, FontStructure -> Map GlyphPair GlyphSize
kernMetrics :: M.Map GlyphPair GlyphSize
, FontStructure -> Maybe GlyphCode
hyphen :: Maybe GlyphCode
, FontStructure -> GlyphCode
space :: !GlyphCode
, FontStructure -> Map Char GlyphCode
encoding :: M.Map Char GlyphCode
, FontStructure -> [PDFFloat]
fontBBox :: [PDFFloat]
, FontStructure -> PDFFloat
italicAngle :: !PDFFloat
, FontStructure -> GlyphSize
capHeight :: !GlyphSize
, FontStructure -> Bool
fixedPitch :: !Bool
, FontStructure -> Bool
serif :: !Bool
, FontStructure -> Bool
symbolic :: !Bool
, FontStructure -> Bool
script :: !Bool
, FontStructure -> Bool
nonSymbolic :: !Bool
, FontStructure -> Bool
italic :: !Bool
, FontStructure -> Bool
allCap :: !Bool
, FontStructure -> Bool
smallCap :: !Bool
, FontStructure -> Bool
forceBold :: !Bool
} deriving Int -> FontStructure -> ShowS
[FontStructure] -> ShowS
FontStructure -> String
(Int -> FontStructure -> ShowS)
-> (FontStructure -> String)
-> ([FontStructure] -> ShowS)
-> Show FontStructure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FontStructure -> ShowS
showsPrec :: Int -> FontStructure -> ShowS
$cshow :: FontStructure -> String
show :: FontStructure -> String
$cshowList :: [FontStructure] -> ShowS
showList :: [FontStructure] -> ShowS
Show
mkFlags :: FontStructure -> Word32
mkFlags :: FontStructure -> Word32
mkFlags FontStructure
fs = Bool -> Int -> Word32
forall {a}. (Bits a, Num a) => Bool -> Int -> a
bit (FontStructure -> Bool
fixedPitch FontStructure
fs) Int
1 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|.
Bool -> Int -> Word32
forall {a}. (Bits a, Num a) => Bool -> Int -> a
bit (FontStructure -> Bool
serif FontStructure
fs) Int
2 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|.
Bool -> Int -> Word32
forall {a}. (Bits a, Num a) => Bool -> Int -> a
bit (FontStructure -> Bool
symbolic FontStructure
fs) Int
3 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|.
Bool -> Int -> Word32
forall {a}. (Bits a, Num a) => Bool -> Int -> a
bit (FontStructure -> Bool
script FontStructure
fs) Int
4 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|.
Bool -> Int -> Word32
forall {a}. (Bits a, Num a) => Bool -> Int -> a
bit (FontStructure -> Bool
nonSymbolic FontStructure
fs) Int
6 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|.
Bool -> Int -> Word32
forall {a}. (Bits a, Num a) => Bool -> Int -> a
bit (FontStructure -> Bool
italic FontStructure
fs) Int
7 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|.
Bool -> Int -> Word32
forall {a}. (Bits a, Num a) => Bool -> Int -> a
bit (FontStructure -> Bool
allCap FontStructure
fs) Int
17 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|.
Bool -> Int -> Word32
forall {a}. (Bits a, Num a) => Bool -> Int -> a
bit (FontStructure -> Bool
smallCap FontStructure
fs) Int
18 Word32 -> Word32 -> Word32
forall a. Bits a => a -> a -> a
.|.
Bool -> Int -> Word32
forall {a}. (Bits a, Num a) => Bool -> Int -> a
bit (FontStructure -> Bool
forceBold FontStructure
fs) Int
19
where
bit :: Bool -> Int -> a
bit Bool
True Int
n = (a
1 a -> Int -> a
forall a. Bits a => a -> Int -> a
`shiftL` (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1))
bit Bool
False Int
_ = a
0
data FontData = Type1Data B.ByteString