-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmushaffeatures.lua
293 lines (250 loc) · 8.76 KB
/
mushaffeatures.lua
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
local add_to_callback = luatexbase.add_to_callback
local direct = node.direct
local tonode = direct.tonode
local todirect = direct.todirect
local traverse = direct.traverse
local traverse_list = direct.traverse_list
local insertbefore = direct.insert_before
local insertafter = direct.insert_after
local protectglyph = direct.protect_glyph
local newnode = direct.new
local freenode = direct.free
local copynode = direct.copy
local removenode = direct.remove
local copynodelist = direct.copy_list
local ischar = direct.is_char
local uses_font = direct.uses_font
local length = direct.length
local getattrs = direct.getattributelist
local setattrs = direct.setattributelist
local getchar = direct.getchar
local setchar = direct.setchar
local getdirection = direct.getdirection
local getdisc = direct.getdisc
local setdisc = direct.setdisc
local getfont = direct.getfont
local getdata = direct.getdata
local setdata = direct.setdata
local getfont = direct.getfont
local setfont = direct.setfont
local getwhatsitfield = direct.getwhatsitfield or direct.getfield
local setwhatsitfield = direct.setwhatsitfield or direct.setfield
local getfield = direct.getfield
local setfield = direct.setfield
local getid = direct.getid
local getkern = direct.getkern
local setkern = direct.setkern
local getnext = direct.getnext
local setnext = direct.setnext
local getoffsets = direct.getoffsets
local setoffsets = direct.setoffsets
local getproperty = direct.getproperty
local setproperty = direct.setproperty
local getprev = direct.getprev
local setprev = direct.setprev
local getsubtype = direct.getsubtype
local setsubtype = direct.setsubtype
local getwidth = direct.getwidth
local setwidth = direct.setwidth
local setlist = direct.setlist
local is_char = direct.is_char
local tail = direct.tail
local getboth = direct.getboth
local setlink = direct.setlink
local dimensions = direct.dimensions
local properties = direct.get_properties_table()
local hlist_t = node.id("hlist")
local disc_t = node.id("disc")
local glue_t = node.id("glue")
local glyph_t = node.id("glyph")
local dir_t = node.id("dir")
local kern_t = node.id("kern")
local localpar_t = node.id("local_par")
local whatsit_t = node.id("whatsit")
local pdfliteral_t = node.subtype("pdf_literal")
local line_t = 1
local explicitdisc_t = 1
local firstdisc_t = 4
local seconddisc_t = 5
local fontkern_t = 0
local italiccorr_t = 3
local regulardisc_t = 3
local spaceskip_t = 13
local HLIST = node.id("hlist")
local VLIST = node.id("vlist")
local RULE = node.id("rule")
local GLUE = node.id("glue")
local KERN = node.id("kern")
local SAJDAATTR = luatexbase.attributes["sajdaatt"]
if not SAJDAATTR then
SAJDAATTR = luatexbase.new_attribute("sajdaatt")
end
local tajweedatt = luatexbase.attributes["tajweedatt"]
if not tajweedatt then
tajweedatt = luatexbase.new_attribute("tajweedatt")
end
local stringformat = string.format
local copynode = node.copy
local insertnodeafter = node.insert_after
local insertnodebefore = node.insert_before
local newnode = node.new
local traversenodes = node.traverse
local traversenodetype = node.traverse_id
local nodecodes = nodes.nodecodes
local glyph_t = nodecodes.glyph
local disc_t = nodecodes.disc
local hlist_t = nodecodes.hlist
local whatsit_t = nodecodes.whatsit
local pdf_literal_t = 16
local pdf_literal = newnode(whatsit_t, pdf_literal_t)
local justified_p = "digitalkhatt_justified"
-- Set and get properties.
local function setprop(n, prop, value)
local props = properties[n]
if not props then
props = {}
properties[n] = props
end
props[prop] = value
end
local function getprop(n, prop)
local props = properties[n]
if props then
return props[prop]
end
end
local get_colortaj = function (color)
local push = stringformat ("%.3g %.3g %.3g rg",
((color >> 24) & 0xff)/255,
((color >> 16) & 0xff)/255,
((color >> 8) & 0xff )/255)
local pop = "0 g"
return push, pop
end
local function good_item(item)
if item.id == GLUE and
(item.subtype == node.subtype("leftskip")
or item.subtype == node.subtype("rightskip")
or item.subtype == node.subtype("parfillskip")) then
return false
else
return true
end
end
local function sajdaline(head, order, ratio, sign)
local item = head
while item do
if node.has_attribute(item, SAJDAATTR) and good_item(item) then
local item_line = node.new(RULE)
item_line.height = tex.sp("1.15em")
--item_line.depth = tex.sp("-34.5pt")
item_line.depth = -item_line.height + tex.sp("1pt")
local end_node = item
node.unset_attribute(item,SAJDAATTR)
while end_node.next and
good_item(end_node.next) and
node.has_attribute(end_node.next, SAJDAATTR) do
node.unset_attribute(end_node.next,SAJDAATTR)
end_node = end_node.next
end
item_line.width = node.dimensions(ratio, sign, order, item, end_node.next)
local item_kern = node.new(KERN, 1)
item_kern.kern = -item_line.width
node.insert_after(head, end_node, item_kern)
node.insert_after(head, item_kern, item_line)
item = item_line.next
else
item = item.next
end
end
end
function set_sajdabar(head)
for line in node.traverse_id(HLIST, head) do
set_sajdabar(line.list)
sajdaline(line.list,line.glue_order, line.glue_set, line.glue_sign)
end
return head
end
local function tajweedcolor(head)
for line in node.traverse_id(HLIST, head) do
tajweedcolor(line.list)
local newhead = tajweed(line.list)
setlist(line,newhead)
end
return head
end
function tajweed(head)
if head == nil then
return head
end
-- TODO verify list head change
local headlist = head
local push, pop = copynode(pdf_literal), copynode(pdf_literal)
push.mode, push.data = 1, "0 g"
pop.mode, pop.data = 1, "0 g"
local item = headlist
while item do
local colatt = node.get_attribute(item, tajweedatt)
if item.id == glyph_t and colatt then
push.data = get_colortaj(colatt)
local before, after = copynode(push), copynode(pop)
headlist, before = insertnodebefore(headlist, item, before)
headlist, after = insertnodeafter (headlist, item, after)
item = after.next
else
item = item.next
end
end
return head or headlist
end
local function printnode(head, nested, notrecursive)
if not nested then
nested = ""
end
local id = getid(head)
local subtypes = node.subtypes(id)
io.write(nested .. "node=" .. head .. ',')
local id =
io.write("type=".. node.type(id).. ',')
io.write("width = " .. (getwidth(head) or 'nil').. ',')
io.write("glue_order = " .. (getfield(head, "glue_order") or 'nil').. ',')
io.write("glue_set = " .. (getfield(head, "glue_set") or 'nil').. ',')
io.write("glue_sign = " .. (getfield(head, "glue_sign") or 'nil').. ',')
print("subtype = " .. (subtypes and subtypes[getfield(head, "subtype")] or 'nil'))
if not notrecursive then
local list = getfield(head, "list")
if list then --and not getprop(head,justified_p) then
nested = nested .. "."
--for n in traverse(list) do
printnode(list, nested)
--end
--setprop(head,justified_p ,true)
end
local next = getnext(head)
if next then
printnode(next, nested)
end
end
end
digitalkhatt.printnode = printnode
local function post_process_print(head, groupcode, size, packtype, direction, attributelist)
print("groupcode=" .. (groupcode or "") .. ",size=" .. (size or "") .. ", packtype=" .. (packtype or "") .. ",direction=" .. (direction or ""))
for n in traverse(head) do
printnode(n)
if node.type(getid(head)) == "hlist" then
local list = getfield(n,'head')
if list then
print("nested list")
printnode(list)
else
print("list is nil")
end
end
end
return head
end
function addsajdacallback()
--add_to_callback("vpack_filter",set_sajdabar, "set_sajdabar")
end
add_to_callback("vpack_filter",tajweedcolor, "quran.tajweedcolor")
add_to_callback("vpack_filter",set_sajdabar, "set_sajdabar")