scrp-eth.lua /size: 3229 b    last modification: 2020-07-01 14:35
1if not modules then modules = { } end modules ['scrp-eth'] = {
2    version   = 1.001,
3    comment   = "companion to scrp-ini.mkiv",
4    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5    copyright = "PRAGMA ADE / ConTeXt Development Team",
6    license   = "see context related readme files"
7}
8
9-- at some point I will review the script code but for the moment we
10-- do it this way; so space settings like with cjk yet
11
12local nuts               = nodes.nuts
13
14local getnext            = nuts.getnext
15local ischar             = nuts.ischar
16local getattr            = nuts.getattr
17
18local nodecodes          = nodes.nodecodes
19local glyph_code         = nodecodes.glyph
20
21local getscriptstatus    = scripts.getstatus
22
23local inserters          = scripts.inserters
24local colors             = scripts.colors
25
26-- syllable [zerowidthspace] syllable
27-- syllable [zerowidthspace] word
28-- syllable [zerowidthspace] sentence
29-- word     [nobreakspace]   syllable
30-- word     [space]          word
31-- word     [space]          sentence
32-- sentence [nobreakspace]   syllable
33-- sentence [space]          word
34-- sentence [space]          sentence
35
36local injectors = { -- [previous] [current]
37    ethiopic_syllable = {
38        ethiopic_syllable = inserters.zerowidthspace_before,
39        ethiopic_word     = inserters.nobreakspace_before,
40        ethiopic_sentence = inserters.nobreakspace_before,
41    },
42    ethiopic_word = {
43        ethiopic_syllable = inserters.space_before,
44        ethiopic_word     = inserters.space_before,
45        ethiopic_sentence = inserters.space_before,
46    },
47    ethiopic_sentence = {
48        ethiopic_syllable = inserters.space_before,
49        ethiopic_word     = inserters.space_before,
50        ethiopic_sentence = inserters.space_before,
51    },
52}
53
54colors.ethiopic_syllable = "trace:1"
55colors.ethiopic_word     = "trace:2"
56colors.ethiopic_sentence = "trace:3"
57
58local function process(head,first,last)
59    if first ~= last then
60        local injector = false
61        local current = first
62        while current do
63            local char, id = ischar(current)
64            if char then
65                local category = getscriptstatus(current)
66                if injector then
67                    local action = injector[category]
68                    if action then
69                        action(head,current)
70                    end
71                end
72                injector = injectors[category]
73            end
74            if current == last then
75                break
76            else
77                current = getnext(current)
78            end
79        end
80    end
81end
82
83scripts.installmethod {
84    name     = "ethiopic",
85    injector = process,
86    datasets = {
87        default = {
88            inter_character_space_factor   = 1,
89            inter_character_stretch_factor = 1,
90            inter_character_shrink_factor  = 1,
91        },
92        half = {
93            inter_character_space_factor   = 0.5,
94            inter_character_stretch_factor = 0.5,
95            inter_character_shrink_factor  = 0.5,
96        },
97        quarter = {
98            inter_character_space_factor   = 0.25,
99            inter_character_stretch_factor = 0.25,
100            inter_character_shrink_factor  = 0.25,
101        },
102    },
103}
104