~alcinnz/fontconfig-pure

ref: 866ea3d2d38b232014081d67c198a73620f1414c fontconfig-pure/fontconfig-harfbuzz/Data/Text/Glyphize/Choose.hs -rw-r--r-- 1.1 KiB
866ea3d2 — Adrian Cochrane Start implementing a seperate bridge module to Harfbuzz. 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Data.Text.Glyphize.Choose where

import Data.Text.Glyphize (Font, createFace, createFontWithOptions,
                          Variation, FontOptions (..), defaultFontOptions)
import Graphics.Text.Font.Choose (Pattern, getValue0, getValue')
import qualified Data.ByteString as B

import System.IO.Unsafe (unsafePerformIO)

-- Warning: file-read sideeffect.
instantiatePattern :: Pattern -> [Variation] -> IO Font
instantiatePattern pat variations = createFontWithOptions options face
  where
    bytes = unsafePerformIO $ B.readFile $ getValue0 "file" pat
    face = createFace bytes $ fromMaybe 0 $ getValue' "index" pat
    options = foldl value2opt defaultFontOptions $ normalizePattern pat

    value2opt opts ("slant", (_, ValueInt x):_) = opts {optionSynthSlant = Just x}
    value2opt opts ("fontvariations", _:_) = opts {optionVariations = variations}
    value2opt opts ("size", (_, ValueDouble x):_) = opts {optionPtEm = Just x}
    value2opt opts ("pixelsize", (_, ValueDouble x):_) = opts {
        optionPPEm = Just (toEnum $ fromEnum x, toEnum $ fromEnum x)
      }