~alcinnz/fontconfig-pure

ref: 196a28a861cb1c498e32724568504b7f38edb621 fontconfig-pure/fontconfig-harfbuzz/Data/Text/Glyphize/Choose.hs -rw-r--r-- 1.2 KiB
196a28a8 — Adrian Cochrane Bugfixing regarding bridging over to Harfbuzz, exposing more FreeType info. 1 year, 10 months ago
                                                                                
866ea3d2 Adrian Cochrane
196a28a8 Adrian Cochrane
866ea3d2 Adrian Cochrane
196a28a8 Adrian Cochrane
866ea3d2 Adrian Cochrane
196a28a8 Adrian Cochrane
866ea3d2 Adrian Cochrane
196a28a8 Adrian Cochrane
866ea3d2 Adrian Cochrane
196a28a8 Adrian Cochrane
866ea3d2 Adrian Cochrane
196a28a8 Adrian Cochrane
866ea3d2 Adrian Cochrane
196a28a8 Adrian Cochrane
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
module Data.Text.Glyphize.Choose where

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

import System.IO.Unsafe (unsafePerformIO)
import Data.Maybe (fromMaybe)

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

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