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

sile-typesetter / sile / 9307175333

30 May 2024 06:08PM UTC coverage: 70.644% (-3.5%) from 74.124%
9307175333

push

github

web-flow
Merge b18390e74 into 70ff5c335

1910 of 2592 new or added lines in 108 files covered. (73.69%)

901 existing lines in 52 files now uncovered.

12203 of 17274 relevant lines covered (70.64%)

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

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

69
local latinToArabic = function (s, useLapa)
70
   for i = 1, #transliteration do
×
71
      if useLapa then
×
72
         s = s:lower():gsub(transliteration[i].lapa or transliteration[i].la, transliteration[i].al)
×
73
      elseif not transliteration[i].lapa then
×
74
         s = s:lower():gsub(transliteration[i].la, transliteration[i].al)
×
75
      end
76
   end
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)
98
   t = SU.splitUtf8(t)
×
99
   local last = t[#t]
×
100
   local jointype = chardata[SU.codepoint(last)] and chardata[SU.codepoint(last)].arabic
×
101
   local joinable = jointype == "d" or jointype == "l"
×
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

120
SILE.hyphenator.languages.ug = function (n)
×
121
   local latin = arabicToLatin(n.text)
×
122
   SU.debug("uyghur", "Original:", n.text, "->", latin, "->")
×
123
   local state = n.options
×
124
   -- Make "Turkish" nodes
125
   local newoptions = pl.tablex.deepcopy(n.options)
×
126
   newoptions.language = "lt"
×
127
   if not SILE.hyphenators.lt then
×
128
      SILE.hyphenate(SILE.shaper:createNnodes(latin, newoptions))
×
129
   end
130
   local items = SILE._hyphenate(SILE.hyphenators["lt"], latin)
×
131
   if #items == 1 then
×
132
      SU.debug("uyghur", latin, "No hyphenation points")
×
133
      return { n }
×
134
   end
135
   -- Choose 1. Aim to split in middle.
136
   SU.debug("uyghur", function ()
×
137
      return SU.concat(items, "/") .. " -> "
×
138
   end)
139
   local splitpoint = math.ceil(#items / 2)
×
140
   local nitems = { "", "" }
×
141
   for i = 1, #items do
×
142
      if i <= splitpoint then
×
143
         nitems[1] = nitems[1] .. items[i]
×
144
      else
145
         nitems[2] = nitems[2] .. items[i]
×
146
      end
147
   end
148
   items = nitems
×
149
   SU.debug("uyghur", items[1], "/", items[2])
×
150
   state.language = "ug"
×
151
   items[1] = latinToArabic(items[1])
×
152
   items[2] = latinToArabic(items[2])
×
153
   local hyphen = SILE.settings:get("font.hyphenchar")
×
154
   local prebreak = SILE.shaper:createNnodes(items[1] .. (lastjoinable(items[1]) and zwj or ""), state)
×
155
   if SILE.settings:get("languages.ug.hyphenoffset") then
×
156
      local w = SILE.settings:get("languages.ug.hyphenoffset").width
×
NEW
157
      prebreak[#prebreak + 1] = SILE.types.node.kern({ width = w })
×
158
   end
159
   local hnodes = SILE.shaper:createNnodes(hyphen, state)
×
160
   prebreak[#prebreak + 1] = hnodes[1]
×
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