module Wumpus.Basic.System.FontLoader.Datatypes
(
PSCharCode
, PSEncodingScheme
, AfmBoundingBox
, AfmKey
, GlobalInfo
, AfmFile(..)
, AfmGlyphMetrics(..)
, MonospaceDefaults(..)
, FontProps(..)
, buildMetricsOps
) where
import Wumpus.Basic.Kernel.Base.FontSupport
import Wumpus.Core
import qualified Data.IntMap as IM
import qualified Data.Map as M
type PSCharCode = Int
type PSEncodingScheme = String
type AfmBoundingBox = BoundingBox AfmUnit
type AfmKey = String
type GlobalInfo = M.Map AfmKey String
data AfmFile = AfmFile
{ afm_encoding :: Maybe String
, afm_letter_bbox :: Maybe AfmBoundingBox
, afm_cap_height :: Maybe AfmUnit
, afm_descender :: Maybe AfmUnit
, afm_underline_position :: Maybe AfmUnit
, afm_underline_thickness :: Maybe AfmUnit
, afm_glyph_metrics :: [AfmGlyphMetrics]
}
deriving (Show)
data AfmGlyphMetrics = AfmGlyphMetrics
{ afm_char_code :: !PSCharCode
, afm_width_vector :: !(Vec2 AfmUnit)
, afm_char_name :: !String
}
deriving (Eq,Show)
data MonospaceDefaults cu = MonospaceDefaults
{ default_letter_bbox :: BoundingBox cu
, default_cap_height :: cu
, default_descender :: cu
, default_underline_position :: cu
, default_underline_thickness :: cu
, default_char_width :: Vec2 cu
}
deriving (Eq,Show)
data FontProps cu = FontProps
{ fp_bounding_box :: BoundingBox cu
, fp_default_adv_vec :: Vec2 cu
, fp_adv_vecs :: IM.IntMap (Vec2 cu)
, fp_cap_height :: cu
, fp_descender :: cu
, fp_underline_position :: cu
, fp_underline_thickness :: cu
}
buildMetricsOps :: (FontSize -> cu -> Double) -> FontProps cu -> FontMetrics
buildMetricsOps fn font@(FontProps { fp_bounding_box = BBox ll ur
, fp_default_adv_vec = V2 vx vy }) =
FontMetrics
{ get_bounding_box = \sz -> BBox (scalePt sz ll) (scalePt sz ur)
, get_cw_table = \sz i ->
maybe (defaultAV sz) (scaleVec sz) $ IM.lookup i (fp_adv_vecs font)
, get_cap_height = \sz -> fn sz (fp_cap_height font)
, get_descender = \sz -> fn sz (fp_descender font)
, get_underline_position = \sz -> fn sz (fp_underline_position font)
, get_underline_thickness = \sz -> fn sz (fp_underline_thickness font)
}
where
defaultAV sz = V2 (fn sz vx) (fn sz vy)
scalePt sz (P2 cx cy) = P2 (fn sz cx) (fn sz cy)
scaleVec sz (V2 cx cy) = V2 (fn sz cx) (fn sz cy)