~alcinnz/harfbuzz-pure

ref: 2e079971838b7c0073bcf38ac0d5df56a5a6dbc5 harfbuzz-pure/Data/Text/Glyphize/Buffer.hs -rw-r--r-- 1.5 KiB
2e079971 — Adrian Cochrane Draft pure-functional Harfbuzz API. 2 years ago
                                                                                
2e079971 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Data.Text.Glyphize.Buffer where

import Data.Text.Lazy as Lazy
import Data.ByteString.Lazy as Lazy
import Data.Text.Short

data Buffer = Buffer {
    text :: Either Lazy.Text Lazy.ByteString,
    contentType :: Maybe ContentType,
    direction :: Maybe Direction,
    script :: Maybe ShortText,
    language :: Maybe ShortText,
    beginsText :: Bool,
    endsText :: Bool,
    preserveDefaultIgnorables :: Bool,
    removeDefaultIgnorables :: Bool,
    don'tInsertDottedCircle :: Bool,
    clusterLevel :: ClusterLevel,
    invisibleGlyph :: Char,
    notFoundGlyph :: Char,
    replacementCodepoint :: Char
}

data ContentType = ContentTypeUnicode | ContentTypeGlyphs deriving (Eq, Show)
data Direction = DirLTR | DirRTL | DirTTB | DirBTT deriving (Eq, Show)
data ClusterLevel = ClusterMonotoneGraphemes | ClusterMonotoneChars | ClusterChars deriving (Eq, Show)

data GlyphInfo = GlyphInfo {
    codepoint :: Int,
    cluster :: Int
}
data GlyphPos = GlyphPos {
    x_advance :: Int, y_advance :: Int,
    x_offset :: Int, y_offset :: Int
}

-- guessSegmentProperties :: Buffer -> Buffer
-- glyphInfo & glyphPositions to be zipped & return from shape function
-- scriptHorizontalDir :: ShortText -> Direction

dirReverse DirLTR = DirRTL
dirReverse DirRTL = DirLTR
dirReverse DirTTB = DirBTT
dirReverse DirBTT = DirTTB
dirBackward dir = dir `Prelude.elem` [DirRTL, DirBTT]
dirForward dir = dir `Prelude.elem` [DirLTR, DirTTB]
dirHorizontal dir = dir `Prelude.elem` [DirLTR, DirRTL]
dirVertical dir = dir `Prelude.elem` [DirTTB, DirBTT]