summaryrefslogtreecommitdiff
path: root/lib/Graphics/Fountainhead/Metrics.hs
blob: bb50b93fb021683eab7e094e5efda0ac889d82b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{- This Source Code Form is subject to the terms of the Mozilla Public License,
   v. 2.0. If a copy of the MPL was not distributed with this file, You can
   obtain one at https://mozilla.org/MPL/2.0/. -}

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

module Graphics.Fountainhead.Metrics
    ( FontMetrics(..)
    , afmFontMetrics
    ) where

import qualified Data.Text.Lazy.Builder as Text.Builder
import Data.Version (Version(..), showVersion)
import Graphics.Fountainhead.Type (newlineBuilder)

newtype FontMetrics = FontMetrics
    { version :: Version
    } deriving (Eq, Show)

afmKeyString :: Text.Builder.Builder -> String -> Text.Builder.Builder
afmKeyString key value = key <> Text.Builder.singleton '\t'
    <> Text.Builder.fromString value <> newlineBuilder

afmFontMetrics :: FontMetrics -> Text.Builder.Builder
afmFontMetrics FontMetrics{..}
    = afmKeyString "StartFontMetrics" (showVersion version)
    <> afmKeyString "Comment" "Generated by Fountainhead"
    <> "EndFontMetrics" <> newlineBuilder