• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sile-typesetter / sile / 9304049654

30 May 2024 02:12PM UTC coverage: 60.021% (-14.7%) from 74.707%
9304049654

push

github

web-flow
Merge 1a26b4f22 into a1fd105f8

6743 of 12900 new or added lines in 186 files covered. (52.27%)

347 existing lines in 49 files now uncovered.

10311 of 17179 relevant lines covered (60.02%)

3307.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/languages/ug.lua
1
-- Thanks to Tom Milo of Decotype for challenging me to implement
2
-- Uyghur support, providing the methodology and basic algorithms,
3
-- and preventing me from leaving the Granshan 2015 conference until
4
-- I had most of this working.
5

6
-- Uyghur is Turkish, right?
7
SILE.languageSupport.loadLanguage("tr")
×
8

9
local chardata = require("char-def")
×
10

11
SILE.settings:declare({
×
12
   parameter = "languages.ug.hyphenoffset",
13
   help = "Space added between text and hyphen",
14
   type = "glue or nil",
15
   default = SILE.types.node.glue("1pt"),
16
})
17

18
local transliteration = {
×
19
   -- I'm going to pretend that normalisation isn't a problem
NEW
20
   { al = "ئا", la = "a", lapa = "^a" },
×
NEW
21
   { al = "ا", la = "a" },
×
NEW
22
   { al = "ب", la = "b" },
×
NEW
23
   { al = "پ", la = "p" },
×
NEW
24
   { al = "ت", la = "t" },
×
NEW
25
   { al = "ج", la = "c" },
×
NEW
26
   { al = "چ", la = "ç" },
×
NEW
27
   { al = "د", la = "d" },
×
NEW
28
   { al = "ر", la = "r" },
×
NEW
29
   { al = "ژ", la = "j" },
×
NEW
30
   { al = "ز", la = "z" },
×
NEW
31
   { al = "ش", la = "ş" },
×
NEW
32
   { al = "س", la = "s" },
×
NEW
33
   { al = "غ", la = "ğ" },
×
NEW
34
   { al = "ف", la = "f" },
×
NEW
35
   { al = "ق", la = "q" },
×
NEW
36
   { al = "ك", la = "k" },
×
NEW
37
   { al = "گ", la = "g" },
×
NEW
38
   { al = "ڭ", la = "ġ" },
×
NEW
39
   { al = "ل", la = "l" },
×
NEW
40
   { al = "م", la = "m" },
×
NEW
41
   { al = "ن", la = "n" },
×
NEW
42
   { al = "ھ", la = "h" },
×
NEW
43
   { al = "ۋ", la = "w" },
×
NEW
44
   { al = "ئې", la = "e", lapa = "^e" },
×
NEW
45
   { al = "ې", la = "e" },
×
NEW
46
   { al = "ئە", la = "ä", lapa = "^ä" },
×
NEW
47
   { al = "ە", la = "ä" },
×
NEW
48
   { al = "ئى", la = "i", lapa = "^i" },
×
NEW
49
   { al = "ى", la = "i" },
×
NEW
50
   { al = "ي", la = "y" },
×
NEW
51
   { al = "ئو", la = "o", lapa = "^o" },
×
NEW
52
   { al = "و", la = "o" },
×
NEW
53
   { al = "ئۇ", la = "u", lapa = "^u" },
×
NEW
54
   { al = "ۇ", la = "u" },
×
NEW
55
   { al = "ئۆ", la = "ö", lapa = "^ö" },
×
NEW
56
   { al = "ۆ", la = "ö" },
×
NEW
57
   { al = "ئۈ", la = "ü", lapa = "^ü" },
×
NEW
58
   { al = "ۈ", la = "ü" },
×
NEW
59
   { al = "خ", la = "x" },
×
60
}
61

62
local arabicToLatin = function (s)
NEW
63
   for i = 1, #transliteration do
×
NEW
64
      s = s:gsub(transliteration[i].al, transliteration[i].la)
×
65
   end
NEW
66
   return s
×
67
end
68

69
local latinToArabic = function (s, useLapa)
NEW
70
   for i = 1, #transliteration do
×
NEW
71
      if useLapa then
×
NEW
72
         s = s:lower():gsub(transliteration[i].lapa or transliteration[i].la, transliteration[i].al)
×
NEW
73
      elseif not transliteration[i].lapa then
×
NEW
74
         s = s:lower():gsub(transliteration[i].la, transliteration[i].al)
×
75
      end
76
   end
NEW
77
   return s
×
78
end
79

80
local zwj = SU.utf8charfromcodepoint("U+200D")
×
81
-- local zwnj = SU.utf8charfromcodepoint("U+200C")
82

83
-- local dropLast = function(t)
84
--   local bt = SU.splitUtf8(t)
85
--   local n = ""
86
--   for i = 1,#bt-1 do n = n..bt[i] end
87
--   return n
88
-- end
89

90
-- local dropFirst = function(t)
91
--   local bt = SU.splitUtf8(t)
92
--   local n = ""
93
--   for i = 2,#bt do n = n..bt[i] end
94
--   return n
95
-- end
96

97
local lastjoinable = function (t)
NEW
98
   t = SU.splitUtf8(t)
×
NEW
99
   local last = t[#t]
×
NEW
100
   local jointype = chardata[SU.codepoint(last)] and chardata[SU.codepoint(last)].arabic
×
NEW
101
   local joinable = jointype == "d" or jointype == "l"
×
NEW
102
   return joinable
×
103
end
104

105
-- local firstjoinable = function (t)
106
--   local t = SU.splitUtf8(t)
107
--   local first = t[1]
108
--   local jointype = chardata[SU.codepoint(first)] and chardata[SU.codepoint(first)].arabic
109
--   local joinable = jointype == "d" or jointype=="r"
110
--   return joinable
111
-- end
112

113
-- function debugUyghur(word)
114
--   SILE.languageSupport.loadLanguage("ug")
115
--   print(SILE.showHyphenationPoints(word,"ug"))
116
--   local items = SILE._hyphenate(SILE.hyphenators["ug"],word)
117
--   print(reorderHyphenations(items,true))
118
-- end
119

NEW
120
SILE.hyphenator.languages.ug = function (n)
×
NEW
121
   local latin = arabicToLatin(n.text)
×
NEW
122
   SU.debug("uyghur", "Original:", n.text, "->", latin, "->")
×
NEW
123
   local state = n.options
×
124
   -- Make "Turkish" nodes
NEW
125
   local newoptions = pl.tablex.deepcopy(n.options)
×
NEW
126
   newoptions.language = "lt"
×
NEW
127
   if not SILE.hyphenators.lt then
×
NEW
128
      SILE.hyphenate(SILE.shaper:createNnodes(latin, newoptions))
×
129
   end
NEW
130
   local items = SILE._hyphenate(SILE.hyphenators["lt"], latin)
×
NEW
131
   if #items == 1 then
×
NEW
132
      SU.debug("uyghur", latin, "No hyphenation points")
×
NEW
133
      return { n }
×
134
   end
135
   -- Choose 1. Aim to split in middle.
NEW
136
   SU.debug("uyghur", function ()
×
NEW
137
      return SU.concat(items, "/") .. " -> "
×
138
   end)
NEW
139
   local splitpoint = math.ceil(#items / 2)
×
NEW
140
   local nitems = { "", "" }
×
NEW
141
   for i = 1, #items do
×
NEW
142
      if i <= splitpoint then
×
NEW
143
         nitems[1] = nitems[1] .. items[i]
×
144
      else
NEW
145
         nitems[2] = nitems[2] .. items[i]
×
146
      end
147
   end
NEW
148
   items = nitems
×
NEW
149
   SU.debug("uyghur", items[1], "/", items[2])
×
NEW
150
   state.language = "ug"
×
NEW
151
   items[1] = latinToArabic(items[1])
×
NEW
152
   items[2] = latinToArabic(items[2])
×
NEW
153
   local hyphen = SILE.settings:get("font.hyphenchar")
×
NEW
154
   local prebreak = SILE.shaper:createNnodes(items[1] .. (lastjoinable(items[1]) and zwj or ""), state)
×
NEW
155
   if SILE.settings:get("languages.ug.hyphenoffset") then
×
NEW
156
      local w = SILE.settings:get("languages.ug.hyphenoffset").width
×
NEW
157
      prebreak[#prebreak + 1] = SILE.types.node.kern({ width = w })
×
158
   end
NEW
159
   local hnodes = SILE.shaper:createNnodes(hyphen, state)
×
NEW
160
   prebreak[#prebreak + 1] = hnodes[1]
×
NEW
161
   local postbreak = SILE.shaper:createNnodes((lastjoinable(items[1]) and zwj or "") .. items[2], state)
×
NEW
162
   local d = SILE.types.node.discretionary({
×
163
      replacement = { n },
164
      prebreak = prebreak,
165
      postbreak = postbreak,
166
   })
NEW
167
   return { SILE.types.node.zerohbox(), d }
×
168
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc