~jaro/balkon

ref: 96147a5add8883ebba8f2abc060636a623ba5fa5 balkon/test/Data/Text/ParagraphLayout/FontLoader.hs -rw-r--r-- 1.4 KiB
96147a5aJaro Allow polymorphism in writing golden tests. 1 year, 8 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Data.Text.ParagraphLayout.FontLoader
    (loadPlexSansArabicRegular
    ,loadSaralaRegular
    ,loadUbuntuRegular
    )
where

import Data.ByteString (readFile)
import Data.Text.Glyphize
    (Font
    ,FontOptions(optionPPEm, optionScale)
    ,createFace
    ,createFontWithOptions
    ,defaultFontOptions
    )
import Prelude (IO, Int, Maybe(Just), String, Word, return, ($))
import System.FilePath ((</>))

-- TODO: Figure out if this affects hinting!
testingPixelSize :: (Word, Word)
testingPixelSize = (24, 24)

-- This controls the output units.
-- The default is "unscaled", which uses the value of `faceUpem` in both axes.
testingScale :: (Int, Int)
testingScale = (1000, 1000)

loadPlexSansArabicRegular :: IO Font
loadPlexSansArabicRegular = loadFontFromFile $
    "assets" </> "fonts" </> "plex" </> "IBMPlexSansArabic-Regular.ttf"

loadSaralaRegular :: IO Font
loadSaralaRegular = loadFontFromFile $
    "assets" </> "fonts" </> "sarala" </> "Sarala-Regular.ttf"

loadUbuntuRegular :: IO Font
loadUbuntuRegular = loadFontFromFile $
    "assets" </> "fonts" </> "ubuntu" </> "Ubuntu-R.ttf"

loadFontFromFile :: String -> IO Font
loadFontFromFile path = do
    ttf <- readFile path
    let face = createFace ttf 0
    let font = createFontWithOptions (defaultFontOptions {
        optionPPEm = Just testingPixelSize,
        optionScale = Just testingScale
    }) face
    return font