Debian Codegraph @

texmf-dist/tex/luatex/luaotfload/fontloader-reference.lua

raw
1 -- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua
2 -- parent file : c:/data/develop/context/sources/luatex-fonts.lua
3 -- merge date : 2023-09-26 18:19
4
5 do -- begin closure to overcome local limits and interference
6
7 if not modules then modules={} end modules ['l-lua']={
8 version=1.001,
9 comment="companion to luat-lib.mkiv",
10 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
11 copyright="PRAGMA ADE / ConTeXt Development Team",
12 license="see context related readme files"
13 }
14 local next,type,tonumber=next,type,tonumber
15 LUAMAJORVERSION,LUAMINORVERSION=string.match(_VERSION,"^[^%d]+(%d+)%.(%d+).*$")
16 LUAMAJORVERSION=tonumber(LUAMAJORVERSION) or 5
17 LUAMINORVERSION=tonumber(LUAMINORVERSION) or 1
18 LUAVERSION=LUAMAJORVERSION+LUAMINORVERSION/10
19 if LUAVERSION<5.2 and jit then
20 MINORVERSION=2
21 LUAVERSION=5.2
22 end
23 if not lpeg then
24 lpeg=require("lpeg")
25 end
26 if loadstring then
27 local loadnormal=load
28 function load(first,...)
29 if type(first)=="string" then
30 return loadstring(first,...)
31 else
32 return loadnormal(first,...)
33 end
34 end
35 else
36 loadstring=load
37 end
38 if not ipairs then
39 local function iterate(a,i)
40 i=i+1
41 local v=a[i]
42 if v~=nil then
43 return i,v
44 end
45 end
46 function ipairs(a)
47 return iterate,a,0
48 end
49 end
50 if not pairs then
51 function pairs(t)
52 return next,t
53 end
54 end
55 if not table.unpack then
56 table.unpack=_G.unpack
57 elseif not unpack then
58 _G.unpack=table.unpack
59 end
60 if not package.loaders then
61 package.loaders=package.searchers
62 end
63 local print,select,tostring=print,select,tostring
64 local inspectors={}
65 function setinspector(kind,inspector)
66 inspectors[kind]=inspector
67 end
68 function inspect(...)
69 for s=1,select("#",...) do
70 local value=select(s,...)
71 if value==nil then
72 print("nil")
73 else
74 local done=false
75 local kind=type(value)
76 local inspector=inspectors[kind]
77 if inspector then
78 done=inspector(value)
79 if done then
80 break
81 end
82 end
83 for kind,inspector in next,inspectors do
84 done=inspector(value)
85 if done then
86 break
87 end
88 end
89 if not done then
90 print(tostring(value))
91 end
92 end
93 end
94 end
95 local dummy=function() end
96 function optionalrequire(...)
97 local ok,result=xpcall(require,dummy,...)
98 if ok then
99 return result
100 end
101 end
102 local flush=io.flush
103 if flush then
104 local execute=os.execute if execute then function os.execute(...) flush() return execute(...) end end
105 local exec=os.exec if exec then function os.exec (...) flush() return exec (...) end end
106 local spawn=os.spawn if spawn then function os.spawn (...) flush() return spawn (...) end end
107 local popen=io.popen if popen then function io.popen (...) flush() return popen (...) end end
108 end
109 FFISUPPORTED=type(ffi)=="table" and ffi.os~="" and ffi.arch~="" and ffi.load
110 if not FFISUPPORTED then
111 local okay;okay,ffi=pcall(require,"ffi")
112 FFISUPPORTED=type(ffi)=="table" and ffi.os~="" and ffi.arch~="" and ffi.load
113 end
114 if not FFISUPPORTED then
115 ffi=nil
116 elseif not ffi.number then
117 ffi.number=tonumber
118 end
119 if LUAVERSION>5.3 then
120 end
121 if status and os.setenv then
122 os.setenv("engine",string.lower(status.luatex_engine or "unknown"))
123 end
124
125 end -- closure
126
127 do -- begin closure to overcome local limits and interference
128
129 if not modules then modules={} end modules ['l-lpeg']={
130 version=1.001,
131 comment="companion to luat-lib.mkiv",
132 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
133 copyright="PRAGMA ADE / ConTeXt Development Team",
134 license="see context related readme files"
135 }
136 lpeg=require("lpeg")
137 local lpeg=lpeg
138 if not lpeg.print then function lpeg.print(...) print(lpeg.pcode(...)) end end
139 local type,next,tostring=type,next,tostring
140 local byte,char,gmatch,format=string.byte,string.char,string.gmatch,string.format
141 local floor=math.floor
142 local P,R,S,V,Ct,C,Cs,Cc,Cp,Cmt=lpeg.P,lpeg.R,lpeg.S,lpeg.V,lpeg.Ct,lpeg.C,lpeg.Cs,lpeg.Cc,lpeg.Cp,lpeg.Cmt
143 local lpegtype,lpegmatch,lpegprint=lpeg.type,lpeg.match,lpeg.print
144 if setinspector then
145 setinspector("lpeg",function(v) if lpegtype(v) then lpegprint(v) return true end end)
146 end
147 lpeg.patterns=lpeg.patterns or {}
148 local patterns=lpeg.patterns
149 local anything=P(1)
150 local endofstring=P(-1)
151 local alwaysmatched=P(true)
152 patterns.anything=anything
153 patterns.endofstring=endofstring
154 patterns.beginofstring=alwaysmatched
155 patterns.alwaysmatched=alwaysmatched
156 local sign=S('+-')
157 local zero=P('0')
158 local digit=R('09')
159 local digits=digit^1
160 local octdigit=R("07")
161 local octdigits=octdigit^1
162 local lowercase=R("az")
163 local uppercase=R("AZ")
164 local underscore=P("_")
165 local hexdigit=digit+lowercase+uppercase
166 local hexdigits=hexdigit^1
167 local cr,lf,crlf=P("\r"),P("\n"),P("\r\n")
168 local newline=P("\r")*(P("\n")+P(true))+P("\n")
169 local escaped=P("\\")*anything
170 local squote=P("'")
171 local dquote=P('"')
172 local space=P(" ")
173 local period=P(".")
174 local comma=P(",")
175 local utfbom_32_be=P('\000\000\254\255')
176 local utfbom_32_le=P('\255\254\000\000')
177 local utfbom_16_be=P('\254\255')
178 local utfbom_16_le=P('\255\254')
179 local utfbom_8=P('\239\187\191')
180 local utfbom=utfbom_32_be+utfbom_32_le+utfbom_16_be+utfbom_16_le+utfbom_8
181 local utftype=utfbom_32_be*Cc("utf-32-be")+utfbom_32_le*Cc("utf-32-le")+utfbom_16_be*Cc("utf-16-be")+utfbom_16_le*Cc("utf-16-le")+utfbom_8*Cc("utf-8")+alwaysmatched*Cc("utf-8")
182 local utfstricttype=utfbom_32_be*Cc("utf-32-be")+utfbom_32_le*Cc("utf-32-le")+utfbom_16_be*Cc("utf-16-be")+utfbom_16_le*Cc("utf-16-le")+utfbom_8*Cc("utf-8")
183 local utfoffset=utfbom_32_be*Cc(4)+utfbom_32_le*Cc(4)+utfbom_16_be*Cc(2)+utfbom_16_le*Cc(2)+utfbom_8*Cc(3)+Cc(0)
184 local utf8next=R("\128\191")
185 patterns.utfbom_32_be=utfbom_32_be
186 patterns.utfbom_32_le=utfbom_32_le
187 patterns.utfbom_16_be=utfbom_16_be
188 patterns.utfbom_16_le=utfbom_16_le
189 patterns.utfbom_8=utfbom_8
190 patterns.utf_16_be_nl=P("\000\r\000\n")+P("\000\r")+P("\000\n")
191 patterns.utf_16_le_nl=P("\r\000\n\000")+P("\r\000")+P("\n\000")
192 patterns.utf_32_be_nl=P("\000\000\000\r\000\000\000\n")+P("\000\000\000\r")+P("\000\000\000\n")
193 patterns.utf_32_le_nl=P("\r\000\000\000\n\000\000\000")+P("\r\000\000\000")+P("\n\000\000\000")
194 patterns.utf8one=R("\000\127")
195 patterns.utf8two=R("\194\223")*utf8next
196 patterns.utf8three=R("\224\239")*utf8next*utf8next
197 patterns.utf8four=R("\240\244")*utf8next*utf8next*utf8next
198 patterns.utfbom=utfbom
199 patterns.utftype=utftype
200 patterns.utfstricttype=utfstricttype
201 patterns.utfoffset=utfoffset
202 local utf8char=patterns.utf8one+patterns.utf8two+patterns.utf8three+patterns.utf8four
203 local validutf8char=utf8char^0*endofstring*Cc(true)+Cc(false)
204 local utf8character=P(1)*R("\128\191")^0
205 patterns.utf8=utf8char
206 patterns.utf8char=utf8char
207 patterns.utf8character=utf8character
208 patterns.validutf8=validutf8char
209 patterns.validutf8char=validutf8char
210 local eol=S("\n\r")
211 local spacer=S(" \t\f\v")
212 local whitespace=eol+spacer
213 local nonspacer=1-spacer
214 local nonwhitespace=1-whitespace
215 patterns.eol=eol
216 patterns.spacer=spacer
217 patterns.whitespace=whitespace
218 patterns.nonspacer=nonspacer
219 patterns.nonwhitespace=nonwhitespace
220 local stripper=spacer^0*C((spacer^0*nonspacer^1)^0)
221 local fullstripper=whitespace^0*C((whitespace^0*nonwhitespace^1)^0)
222 local collapser=Cs(spacer^0/""*nonspacer^0*((spacer^0/" "*nonspacer^1)^0))
223 local nospacer=Cs((whitespace^1/""+nonwhitespace^1)^0)
224 local b_collapser=Cs(whitespace^0/""*(nonwhitespace^1+whitespace^1/" ")^0)
225 local m_collapser=Cs((nonwhitespace^1+whitespace^1/" ")^0)
226 local e_collapser=Cs((whitespace^1*endofstring/""+nonwhitespace^1+whitespace^1/" ")^0)
227 local x_collapser=Cs((nonwhitespace^1+whitespace^1/"" )^0)
228 local b_stripper=Cs(spacer^0/""*(nonspacer^1+spacer^1/" ")^0)
229 local m_stripper=Cs((nonspacer^1+spacer^1/" ")^0)
230 local e_stripper=Cs((spacer^1*endofstring/""+nonspacer^1+spacer^1/" ")^0)
231 local x_stripper=Cs((nonspacer^1+spacer^1/"" )^0)
232 patterns.stripper=stripper
233 patterns.fullstripper=fullstripper
234 patterns.collapser=collapser
235 patterns.nospacer=nospacer
236 patterns.b_collapser=b_collapser
237 patterns.m_collapser=m_collapser
238 patterns.e_collapser=e_collapser
239 patterns.x_collapser=x_collapser
240 patterns.b_stripper=b_stripper
241 patterns.m_stripper=m_stripper
242 patterns.e_stripper=e_stripper
243 patterns.x_stripper=x_stripper
244 patterns.lowercase=lowercase
245 patterns.uppercase=uppercase
246 patterns.letter=patterns.lowercase+patterns.uppercase
247 patterns.space=space
248 patterns.tab=P("\t")
249 patterns.spaceortab=patterns.space+patterns.tab
250 patterns.newline=newline
251 patterns.emptyline=newline^1
252 patterns.equal=P("=")
253 patterns.comma=comma
254 patterns.commaspacer=comma*spacer^0
255 patterns.period=period
256 patterns.colon=P(":")
257 patterns.semicolon=P(";")
258 patterns.underscore=underscore
259 patterns.escaped=escaped
260 patterns.squote=squote
261 patterns.dquote=dquote
262 patterns.nosquote=(escaped+(1-squote))^0
263 patterns.nodquote=(escaped+(1-dquote))^0
264 patterns.unsingle=(squote/"")*patterns.nosquote*(squote/"")
265 patterns.undouble=(dquote/"")*patterns.nodquote*(dquote/"")
266 patterns.unquoted=patterns.undouble+patterns.unsingle
267 patterns.unspacer=((patterns.spacer^1)/"")^0
268 patterns.singlequoted=squote*patterns.nosquote*squote
269 patterns.doublequoted=dquote*patterns.nodquote*dquote
270 patterns.quoted=patterns.doublequoted+patterns.singlequoted
271 patterns.digit=digit
272 patterns.digits=digits
273 patterns.octdigit=octdigit
274 patterns.octdigits=octdigits
275 patterns.hexdigit=hexdigit
276 patterns.hexdigits=hexdigits
277 patterns.sign=sign
278 patterns.cardinal=digits
279 patterns.integer=sign^-1*digits
280 patterns.unsigned=digit^0*period*digits
281 patterns.float=sign^-1*patterns.unsigned
282 patterns.cunsigned=digit^0*comma*digits
283 patterns.cpunsigned=digit^0*(period+comma)*digits
284 patterns.cfloat=sign^-1*patterns.cunsigned
285 patterns.cpfloat=sign^-1*patterns.cpunsigned
286 patterns.number=patterns.float+patterns.integer
287 patterns.cnumber=patterns.cfloat+patterns.integer
288 patterns.cpnumber=patterns.cpfloat+patterns.integer
289 patterns.oct=zero*octdigits
290 patterns.octal=patterns.oct
291 patterns.HEX=zero*P("X")*(digit+uppercase)^1
292 patterns.hex=zero*P("x")*(digit+lowercase)^1
293 patterns.hexadecimal=zero*S("xX")*hexdigits
294 patterns.hexafloat=sign^-1*zero*S("xX")*(hexdigit^0*period*hexdigits+hexdigits*period*hexdigit^0+hexdigits)*(S("pP")*sign^-1*hexdigits)^-1
295 patterns.decafloat=sign^-1*(digit^0*period*digits+digits*period*digit^0+digits)*S("eE")*sign^-1*digits
296 patterns.propername=(uppercase+lowercase+underscore)*(uppercase+lowercase+underscore+digit)^0*endofstring
297 patterns.somecontent=(anything-newline-space)^1
298 patterns.beginline=#(1-newline)
299 patterns.longtostring=Cs(whitespace^0/""*((patterns.quoted+nonwhitespace^1+whitespace^1/""*(endofstring+Cc(" ")))^0))
300 local function anywhere(pattern)
301 return (1-P(pattern))^0*P(pattern)
302 end
303 lpeg.anywhere=anywhere
304 function lpeg.instringchecker(p)
305 p=anywhere(p)
306 return function(str)
307 return lpegmatch(p,str) and true or false
308 end
309 end
310 function lpeg.splitter(pattern,action)
311 if action then
312 return (((1-P(pattern))^1)/action+1)^0
313 else
314 return (Cs((1-P(pattern))^1)+1)^0
315 end
316 end
317 function lpeg.tsplitter(pattern,action)
318 if action then
319 return Ct((((1-P(pattern))^1)/action+1)^0)
320 else
321 return Ct((Cs((1-P(pattern))^1)+1)^0)
322 end
323 end
324 local splitters_s,splitters_m,splitters_t={},{},{}
325 local function splitat(separator,single)
326 local splitter=(single and splitters_s[separator]) or splitters_m[separator]
327 if not splitter then
328 separator=P(separator)
329 local other=C((1-separator)^0)
330 if single then
331 local any=anything
332 splitter=other*(separator*C(any^0)+"")
333 splitters_s[separator]=splitter
334 else
335 splitter=other*(separator*other)^0
336 splitters_m[separator]=splitter
337 end
338 end
339 return splitter
340 end
341 local function tsplitat(separator)
342 local splitter=splitters_t[separator]
343 if not splitter then
344 splitter=Ct(splitat(separator))
345 splitters_t[separator]=splitter
346 end
347 return splitter
348 end
349 lpeg.splitat=splitat
350 lpeg.tsplitat=tsplitat
351 function string.splitup(str,separator)
352 if not separator then
353 separator=","
354 end
355 return lpegmatch(splitters_m[separator] or splitat(separator),str)
356 end
357 local cache={}
358 function lpeg.split(separator,str)
359 local c=cache[separator]
360 if not c then
361 c=tsplitat(separator)
362 cache[separator]=c
363 end
364 return lpegmatch(c,str)
365 end
366 function string.split(str,separator)
367 if separator then
368 local c=cache[separator]
369 if not c then
370 c=tsplitat(separator)
371 cache[separator]=c
372 end
373 return lpegmatch(c,str)
374 else
375 return { str }
376 end
377 end
378 local spacing=patterns.spacer^0*newline
379 local empty=spacing*Cc("")
380 local nonempty=Cs((1-spacing)^1)*spacing^-1
381 local content=(empty+nonempty)^1
382 patterns.textline=content
383 local linesplitter=tsplitat(newline)
384 patterns.linesplitter=linesplitter
385 function string.splitlines(str)
386 return lpegmatch(linesplitter,str)
387 end
388 local cache={}
389 function lpeg.checkedsplit(separator,str)
390 local c=cache[separator]
391 if not c then
392 separator=P(separator)
393 local other=C((1-separator)^1)
394 c=Ct(separator^0*other*(separator^1*other)^0)
395 cache[separator]=c
396 end
397 return lpegmatch(c,str)
398 end
399 function string.checkedsplit(str,separator)
400 local c=cache[separator]
401 if not c then
402 separator=P(separator)
403 local other=C((1-separator)^1)
404 c=Ct(separator^0*other*(separator^1*other)^0)
405 cache[separator]=c
406 end
407 return lpegmatch(c,str)
408 end
409 local function f2(s) local c1,c2=byte(s,1,2) return c1*64+c2-12416 end
410 local function f3(s) local c1,c2,c3=byte(s,1,3) return (c1*64+c2)*64+c3-925824 end
411 local function f4(s) local c1,c2,c3,c4=byte(s,1,4) return ((c1*64+c2)*64+c3)*64+c4-63447168 end
412 local utf8byte=patterns.utf8one/byte+patterns.utf8two/f2+patterns.utf8three/f3+patterns.utf8four/f4
413 patterns.utf8byte=utf8byte
414 local cache={}
415 function lpeg.stripper(str)
416 if type(str)=="string" then
417 local s=cache[str]
418 if not s then
419 s=Cs(((S(str)^1)/""+1)^0)
420 cache[str]=s
421 end
422 return s
423 else
424 return Cs(((str^1)/""+1)^0)
425 end
426 end
427 local cache={}
428 function lpeg.keeper(str)
429 if type(str)=="string" then
430 local s=cache[str]
431 if not s then
432 s=Cs((((1-S(str))^1)/""+1)^0)
433 cache[str]=s
434 end
435 return s
436 else
437 return Cs((((1-str)^1)/""+1)^0)
438 end
439 end
440 function lpeg.frontstripper(str)
441 return (P(str)+P(true))*Cs(anything^0)
442 end
443 function lpeg.endstripper(str)
444 return Cs((1-P(str)*endofstring)^0)
445 end
446 function lpeg.replacer(one,two,makefunction,isutf)
447 local pattern
448 local u=isutf and utf8char or 1
449 if type(one)=="table" then
450 local no=#one
451 local p=P(false)
452 if no==0 then
453 for k,v in next,one do
454 p=p+P(k)/v
455 end
456 pattern=Cs((p+u)^0)
457 elseif no==1 then
458 local o=one[1]
459 one,two=P(o[1]),o[2]
460 pattern=Cs((one/two+u)^0)
461 else
462 for i=1,no do
463 local o=one[i]
464 p=p+P(o[1])/o[2]
465 end
466 pattern=Cs((p+u)^0)
467 end
468 else
469 pattern=Cs((P(one)/(two or "")+u)^0)
470 end
471 if makefunction then
472 return function(str)
473 return lpegmatch(pattern,str)
474 end
475 else
476 return pattern
477 end
478 end
479 function lpeg.finder(lst,makefunction,isutf)
480 local pattern
481 if type(lst)=="table" then
482 pattern=P(false)
483 if #lst==0 then
484 for k,v in next,lst do
485 pattern=pattern+P(k)
486 end
487 else
488 for i=1,#lst do
489 pattern=pattern+P(lst[i])
490 end
491 end
492 else
493 pattern=P(lst)
494 end
495 if isutf then
496 pattern=((utf8char or 1)-pattern)^0*pattern
497 else
498 pattern=(1-pattern)^0*pattern
499 end
500 if makefunction then
501 return function(str)
502 return lpegmatch(pattern,str)
503 end
504 else
505 return pattern
506 end
507 end
508 local splitters_f,splitters_s={},{}
509 function lpeg.firstofsplit(separator)
510 local splitter=splitters_f[separator]
511 if not splitter then
512 local pattern=P(separator)
513 splitter=C((1-pattern)^0)
514 splitters_f[separator]=splitter
515 end
516 return splitter
517 end
518 function lpeg.secondofsplit(separator)
519 local splitter=splitters_s[separator]
520 if not splitter then
521 local pattern=P(separator)
522 splitter=(1-pattern)^0*pattern*C(anything^0)
523 splitters_s[separator]=splitter
524 end
525 return splitter
526 end
527 local splitters_s,splitters_p={},{}
528 function lpeg.beforesuffix(separator)
529 local splitter=splitters_s[separator]
530 if not splitter then
531 local pattern=P(separator)
532 splitter=C((1-pattern)^0)*pattern*endofstring
533 splitters_s[separator]=splitter
534 end
535 return splitter
536 end
537 function lpeg.afterprefix(separator)
538 local splitter=splitters_p[separator]
539 if not splitter then
540 local pattern=P(separator)
541 splitter=pattern*C(anything^0)
542 splitters_p[separator]=splitter
543 end
544 return splitter
545 end
546 function lpeg.balancer(left,right)
547 left,right=P(left),P(right)
548 return P { left*((1-left-right)+V(1))^0*right }
549 end
550 function lpeg.counter(pattern,action)
551 local n=0
552 local pattern=(P(pattern)/function() n=n+1 end+anything)^0
553 if action then
554 return function(str) n=0;lpegmatch(pattern,str);action(n) end
555 else
556 return function(str) n=0;lpegmatch(pattern,str);return n end
557 end
558 end
559 function lpeg.is_lpeg(p)
560 return p and lpegtype(p)=="pattern"
561 end
562 function lpeg.oneof(list,...)
563 if type(list)~="table" then
564 list={ list,... }
565 end
566 local p=P(list[1])
567 for l=2,#list do
568 p=p+P(list[l])
569 end
570 return p
571 end
572 local sort=table.sort
573 local function copyindexed(old)
574 local new={}
575 for i=1,#old do
576 new[i]=old
577 end
578 return new
579 end
580 local function sortedkeys(tab)
581 local keys,s={},0
582 for key,_ in next,tab do
583 s=s+1
584 keys[s]=key
585 end
586 sort(keys)
587 return keys
588 end
589 function lpeg.append(list,pp,delayed,checked)
590 local p=pp
591 if #list>0 then
592 local keys=copyindexed(list)
593 sort(keys)
594 for i=#keys,1,-1 do
595 local k=keys[i]
596 if p then
597 p=P(k)+p
598 else
599 p=P(k)
600 end
601 end
602 elseif delayed then
603 local keys=sortedkeys(list)
604 if p then
605 for i=1,#keys,1 do
606 local k=keys[i]
607 local v=list[k]
608 p=P(k)/list+p
609 end
610 else
611 for i=1,#keys do
612 local k=keys[i]
613 local v=list[k]
614 if p then
615 p=P(k)+p
616 else
617 p=P(k)
618 end
619 end
620 if p then
621 p=p/list
622 end
623 end
624 elseif checked then
625 local keys=sortedkeys(list)
626 for i=1,#keys do
627 local k=keys[i]
628 local v=list[k]
629 if p then
630 if k==v then
631 p=P(k)+p
632 else
633 p=P(k)/v+p
634 end
635 else
636 if k==v then
637 p=P(k)
638 else
639 p=P(k)/v
640 end
641 end
642 end
643 else
644 local keys=sortedkeys(list)
645 for i=1,#keys do
646 local k=keys[i]
647 local v=list[k]
648 if p then
649 p=P(k)/v+p
650 else
651 p=P(k)/v
652 end
653 end
654 end
655 return p
656 end
657 local p_false=P(false)
658 local p_true=P(true)
659 local lower=utf and utf.lower or string.lower
660 local upper=utf and utf.upper or string.upper
661 function lpeg.setutfcasers(l,u)
662 lower=l or lower
663 upper=u or upper
664 end
665 local function make1(t,rest)
666 local p=p_false
667 local keys=sortedkeys(t)
668 for i=1,#keys do
669 local k=keys[i]
670 if k~="" then
671 local v=t[k]
672 if v==true then
673 p=p+P(k)*p_true
674 elseif v==false then
675 else
676 p=p+P(k)*make1(v,v[""])
677 end
678 end
679 end
680 if rest then
681 p=p+p_true
682 end
683 return p
684 end
685 local function make2(t,rest)
686 local p=p_false
687 local keys=sortedkeys(t)
688 for i=1,#keys do
689 local k=keys[i]
690 if k~="" then
691 local v=t[k]
692 if v==true then
693 p=p+(P(lower(k))+P(upper(k)))*p_true
694 elseif v==false then
695 else
696 p=p+(P(lower(k))+P(upper(k)))*make2(v,v[""])
697 end
698 end
699 end
700 if rest then
701 p=p+p_true
702 end
703 return p
704 end
705 local function utfchartabletopattern(list,insensitive)
706 local tree={}
707 local n=#list
708 if n==0 then
709 for s in next,list do
710 local t=tree
711 local p,pk
712 for c in gmatch(s,".") do
713 if t==true then
714 t={ [c]=true,[""]=true }
715 p[pk]=t
716 p=t
717 t=false
718 elseif t==false then
719 t={ [c]=false }
720 p[pk]=t
721 p=t
722 t=false
723 else
724 local tc=t[c]
725 if not tc then
726 tc=false
727 t[c]=false
728 end
729 p=t
730 t=tc
731 end
732 pk=c
733 end
734 if t==false then
735 p[pk]=true
736 elseif t==true then
737 else
738 t[""]=true
739 end
740 end
741 else
742 for i=1,n do
743 local s=list[i]
744 local t=tree
745 local p,pk
746 for c in gmatch(s,".") do
747 if t==true then
748 t={ [c]=true,[""]=true }
749 p[pk]=t
750 p=t
751 t=false
752 elseif t==false then
753 t={ [c]=false }
754 p[pk]=t
755 p=t
756 t=false
757 else
758 local tc=t[c]
759 if not tc then
760 tc=false
761 t[c]=false
762 end
763 p=t
764 t=tc
765 end
766 pk=c
767 end
768 if t==false then
769 p[pk]=true
770 elseif t==true then
771 else
772 t[""]=true
773 end
774 end
775 end
776 return (insensitive and make2 or make1)(tree)
777 end
778 lpeg.utfchartabletopattern=utfchartabletopattern
779 function lpeg.utfreplacer(list,insensitive)
780 local pattern=Cs((utfchartabletopattern(list,insensitive)/list+utf8character)^0)
781 return function(str)
782 return lpegmatch(pattern,str) or str
783 end
784 end
785 patterns.containseol=lpeg.finder(eol)
786 local function nextstep(n,step,result)
787 local m=n%step
788 local d=floor(n/step)
789 if d>0 then
790 local v=V(tostring(step))
791 local s=result.start
792 for i=1,d do
793 if s then
794 s=v*s
795 else
796 s=v
797 end
798 end
799 result.start=s
800 end
801 if step>1 and result.start then
802 local v=V(tostring(step/2))
803 result[tostring(step)]=v*v
804 end
805 if step>0 then
806 return nextstep(m,step/2,result)
807 else
808 return result
809 end
810 end
811 function lpeg.times(pattern,n)
812 return P(nextstep(n,2^16,{ "start",["1"]=pattern }))
813 end
814 do
815 local trailingzeros=zero^0*-digit
816 local stripper=Cs((
817 digits*(
818 period*trailingzeros/""+period*(digit-trailingzeros)^1*(trailingzeros/"")
819 )+1
820 )^0)
821 lpeg.patterns.stripzeros=stripper
822 local nonzero=digit-zero
823 local trailingzeros=zero^1*endofstring
824 local stripper=Cs((1-period)^0*(
825 period*trailingzeros/""+period*(nonzero^1+(trailingzeros/"")+zero^1)^0+endofstring
826 ))
827 lpeg.patterns.stripzero=stripper
828 end
829 local byte_to_HEX={}
830 local byte_to_hex={}
831 local byte_to_dec={}
832 local hex_to_byte={}
833 for i=0,255 do
834 local H=format("%02X",i)
835 local h=format("%02x",i)
836 local d=format("%03i",i)
837 local c=char(i)
838 byte_to_HEX[c]=H
839 byte_to_hex[c]=h
840 byte_to_dec[c]=d
841 hex_to_byte[h]=c
842 hex_to_byte[H]=c
843 end
844 local hextobyte=P(2)/hex_to_byte
845 local bytetoHEX=P(1)/byte_to_HEX
846 local bytetohex=P(1)/byte_to_hex
847 local bytetodec=P(1)/byte_to_dec
848 local hextobytes=Cs(hextobyte^0)
849 local bytestoHEX=Cs(bytetoHEX^0)
850 local bytestohex=Cs(bytetohex^0)
851 local bytestodec=Cs(bytetodec^0)
852 patterns.hextobyte=hextobyte
853 patterns.bytetoHEX=bytetoHEX
854 patterns.bytetohex=bytetohex
855 patterns.bytetodec=bytetodec
856 patterns.hextobytes=hextobytes
857 patterns.bytestoHEX=bytestoHEX
858 patterns.bytestohex=bytestohex
859 patterns.bytestodec=bytestodec
860 function string.toHEX(s)
861 if not s or s=="" then
862 return s
863 else
864 return lpegmatch(bytestoHEX,s)
865 end
866 end
867 function string.tohex(s)
868 if not s or s=="" then
869 return s
870 else
871 return lpegmatch(bytestohex,s)
872 end
873 end
874 function string.todec(s)
875 if not s or s=="" then
876 return s
877 else
878 return lpegmatch(bytestodec,s)
879 end
880 end
881 function string.tobytes(s)
882 if not s or s=="" then
883 return s
884 else
885 return lpegmatch(hextobytes,s)
886 end
887 end
888 local patterns={}
889 local function containsws(what)
890 local p=patterns[what]
891 if not p then
892 local p1=P(what)*(whitespace+endofstring)*Cc(true)
893 local p2=whitespace*P(p1)
894 p=P(p1)+P(1-p2)^0*p2+Cc(false)
895 patterns[what]=p
896 end
897 return p
898 end
899 lpeg.containsws=containsws
900 function string.containsws(str,what)
901 return lpegmatch(patterns[what] or containsws(what),str)
902 end
903
904 end -- closure
905
906 do -- begin closure to overcome local limits and interference
907
908 if not modules then modules={} end modules ['l-functions']={
909 version=1.001,
910 comment="companion to luat-lib.mkiv",
911 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
912 copyright="PRAGMA ADE / ConTeXt Development Team",
913 license="see context related readme files"
914 }
915 functions=functions or {}
916 function functions.dummy() end
917
918 end -- closure
919
920 do -- begin closure to overcome local limits and interference
921
922 if not modules then modules={} end modules ['l-string']={
923 version=1.001,
924 comment="companion to luat-lib.mkiv",
925 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
926 copyright="PRAGMA ADE / ConTeXt Development Team",
927 license="see context related readme files"
928 }
929 local string=string
930 local sub,gmatch,format,char,byte,rep,lower,find=string.sub,string.gmatch,string.format,string.char,string.byte,string.rep,string.lower,string.find
931 local lpegmatch,patterns=lpeg.match,lpeg.patterns
932 local P,S,C,Ct,Cc,Cs=lpeg.P,lpeg.S,lpeg.C,lpeg.Ct,lpeg.Cc,lpeg.Cs
933 local unquoted=patterns.squote*C(patterns.nosquote)*patterns.squote+patterns.dquote*C(patterns.nodquote)*patterns.dquote
934 function string.unquoted(str)
935 return lpegmatch(unquoted,str) or str
936 end
937 function string.quoted(str)
938 return format("%q",str)
939 end
940 function string.count(str,pattern)
941 local n=0
942 local i=1
943 local l=#pattern
944 while true do
945 i=find(str,pattern,i)
946 if i then
947 n=n+1
948 i=i+l
949 else
950 break
951 end
952 end
953 return n
954 end
955 function string.limit(str,n,sentinel)
956 if #str>n then
957 sentinel=sentinel or "..."
958 return sub(str,1,(n-#sentinel))..sentinel
959 else
960 return str
961 end
962 end
963 local stripper=patterns.stripper
964 local fullstripper=patterns.fullstripper
965 local collapser=patterns.collapser
966 local nospacer=patterns.nospacer
967 local longtostring=patterns.longtostring
968 function string.strip(str)
969 return str and lpegmatch(stripper,str) or ""
970 end
971 function string.fullstrip(str)
972 return str and lpegmatch(fullstripper,str) or ""
973 end
974 function string.collapsespaces(str)
975 return str and lpegmatch(collapser,str) or ""
976 end
977 function string.nospaces(str)
978 return str and lpegmatch(nospacer,str) or ""
979 end
980 function string.longtostring(str)
981 return str and lpegmatch(longtostring,str) or ""
982 end
983 local pattern=P(" ")^0*P(-1)
984 function string.is_empty(str)
985 if not str or str=="" then
986 return true
987 else
988 return lpegmatch(pattern,str) and true or false
989 end
990 end
991 local anything=patterns.anything
992 local moreescapes=Cc("%")*S(".-+%?()[]*$^{}")
993 local allescapes=Cc("%")*S(".-+%?()[]*")
994 local someescapes=Cc("%")*S(".-+%()[]")
995 local matchescapes=Cc(".")*S("*?")
996 local pattern_m=Cs ((moreescapes+anything )^0 )
997 local pattern_a=Cs ((allescapes+anything )^0 )
998 local pattern_b=Cs ((someescapes+matchescapes+anything )^0 )
999 local pattern_c=Cs (Cc("^")*(someescapes+matchescapes+anything )^0*Cc("$") )
1000 function string.escapedpattern(str,simple)
1001 return lpegmatch(simple and pattern_b or pattern_a,str)
1002 end
1003 function string.topattern(str,lowercase,strict)
1004 if str=="" or type(str)~="string" then
1005 return ".*"
1006 elseif strict=="all" then
1007 str=lpegmatch(pattern_m,str)
1008 elseif strict then
1009 str=lpegmatch(pattern_c,str)
1010 else
1011 str=lpegmatch(pattern_b,str)
1012 end
1013 if lowercase then
1014 return lower(str)
1015 else
1016 return str
1017 end
1018 end
1019 function string.valid(str,default)
1020 return (type(str)=="string" and str~="" and str) or default or nil
1021 end
1022 string.itself=function(s) return s end
1023 local pattern_c=Ct(C(1)^0)
1024 local pattern_b=Ct((C(1)/byte)^0)
1025 function string.totable(str,bytes)
1026 return lpegmatch(bytes and pattern_b or pattern_c,str)
1027 end
1028 local replacer=lpeg.replacer("@","%%")
1029 function string.tformat(fmt,...)
1030 return format(lpegmatch(replacer,fmt),...)
1031 end
1032 string.quote=string.quoted
1033 string.unquote=string.unquoted
1034 if not string.bytetable then
1035 local limit=5000
1036 function string.bytetable(str)
1037 local n=#str
1038 if n>limit then
1039 local t={ byte(str,1,limit) }
1040 for i=limit+1,n do
1041 t[i]=byte(str,i)
1042 end
1043 return t
1044 else
1045 return { byte(str,1,n) }
1046 end
1047 end
1048 end
1049
1050 end -- closure
1051
1052 do -- begin closure to overcome local limits and interference
1053
1054 if not modules then modules={} end modules ['l-table']={
1055 version=1.001,
1056 comment="companion to luat-lib.mkiv",
1057 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
1058 copyright="PRAGMA ADE / ConTeXt Development Team",
1059 license="see context related readme files"
1060 }
1061 local type,next,tostring,tonumber,select,rawget=type,next,tostring,tonumber,select,rawget
1062 local table,string=table,string
1063 local concat,sort=table.concat,table.sort
1064 local format,lower,dump=string.format,string.lower,string.dump
1065 local getmetatable,setmetatable=getmetatable,setmetatable
1066 local lpegmatch,patterns=lpeg.match,lpeg.patterns
1067 local floor=math.floor
1068 local stripper=patterns.stripper
1069 function table.getn(t)
1070 return t and #t
1071 end
1072 function table.strip(tab)
1073 local lst={}
1074 local l=0
1075 for i=1,#tab do
1076 local s=lpegmatch(stripper,tab[i]) or ""
1077 if s=="" then
1078 else
1079 l=l+1
1080 lst[l]=s
1081 end
1082 end
1083 return lst
1084 end
1085 function table.keys(t)
1086 if t then
1087 local keys={}
1088 local k=0
1089 for key in next,t do
1090 k=k+1
1091 keys[k]=key
1092 end
1093 return keys
1094 else
1095 return {}
1096 end
1097 end
1098 local function compare(a,b)
1099 local ta=type(a)
1100 if ta=="number" then
1101 local tb=type(b)
1102 if ta==tb then
1103 return a<b
1104 elseif tb=="string" then
1105 return tostring(a)<b
1106 end
1107 elseif ta=="string" then
1108 local tb=type(b)
1109 if ta==tb then
1110 return a<b
1111 else
1112 return a<tostring(b)
1113 end
1114 end
1115 return tostring(a)<tostring(b)
1116 end
1117 local function sortedkeys(tab)
1118 if tab then
1119 local srt={}
1120 local category=0
1121 local s=0
1122 for key in next,tab do
1123 s=s+1
1124 srt[s]=key
1125 if category~=3 then
1126 local tkey=type(key)
1127 if category==1 then
1128 if tkey~="string" then
1129 category=3
1130 end
1131 elseif category==2 then
1132 if tkey~="number" then
1133 category=3
1134 end
1135 else
1136 if tkey=="string" then
1137 category=1
1138 elseif tkey=="number" then
1139 category=2
1140 else
1141 category=3
1142 end
1143 end
1144 end
1145 end
1146 if s<2 then
1147 elseif category==3 then
1148 sort(srt,compare)
1149 else
1150 sort(srt)
1151 end
1152 return srt
1153 else
1154 return {}
1155 end
1156 end
1157 local function sortedhashonly(tab)
1158 if tab then
1159 local srt={}
1160 local s=0
1161 for key in next,tab do
1162 if type(key)=="string" then
1163 s=s+1
1164 srt[s]=key
1165 end
1166 end
1167 if s>1 then
1168 sort(srt)
1169 end
1170 return srt
1171 else
1172 return {}
1173 end
1174 end
1175 local function sortedindexonly(tab)
1176 if tab then
1177 local srt={}
1178 local s=0
1179 for key in next,tab do
1180 if type(key)=="number" then
1181 s=s+1
1182 srt[s]=key
1183 end
1184 end
1185 if s>1 then
1186 sort(srt)
1187 end
1188 return srt
1189 else
1190 return {}
1191 end
1192 end
1193 local function sortedhashkeys(tab,cmp)
1194 if tab then
1195 local srt={}
1196 local s=0
1197 for key in next,tab do
1198 if key then
1199 s=s+1
1200 srt[s]=key
1201 end
1202 end
1203 if s>1 then
1204 sort(srt,cmp)
1205 end
1206 return srt
1207 else
1208 return {}
1209 end
1210 end
1211 function table.allkeys(t)
1212 local keys={}
1213 for k,v in next,t do
1214 for k in next,v do
1215 keys[k]=true
1216 end
1217 end
1218 return sortedkeys(keys)
1219 end
1220 table.sortedkeys=sortedkeys
1221 table.sortedhashonly=sortedhashonly
1222 table.sortedindexonly=sortedindexonly
1223 table.sortedhashkeys=sortedhashkeys
1224 local function nothing() end
1225 local function sortedhash(t,cmp)
1226 if t then
1227 local s
1228 if cmp then
1229 s=sortedhashkeys(t,function(a,b) return cmp(t,a,b) end)
1230 else
1231 s=sortedkeys(t)
1232 end
1233 local m=#s
1234 if m==1 then
1235 return next,t
1236 elseif m>0 then
1237 local n=0
1238 return function()
1239 if n<m then
1240 n=n+1
1241 local k=s[n]
1242 return k,t[k]
1243 end
1244 end
1245 end
1246 end
1247 return nothing
1248 end
1249 table.sortedhash=sortedhash
1250 table.sortedpairs=sortedhash
1251 function table.append(t,list)
1252 local n=#t
1253 for i=1,#list do
1254 n=n+1
1255 t[n]=list[i]
1256 end
1257 return t
1258 end
1259 function table.prepend(t,list)
1260 local nl=#list
1261 local nt=nl+#t
1262 for i=#t,1,-1 do
1263 t[nt]=t[i]
1264 nt=nt-1
1265 end
1266 for i=1,#list do
1267 t[i]=list[i]
1268 end
1269 return t
1270 end
1271 function table.merge(t,...)
1272 if not t then
1273 t={}
1274 end
1275 for i=1,select("#",...) do
1276 for k,v in next,(select(i,...)) do
1277 t[k]=v
1278 end
1279 end
1280 return t
1281 end
1282 function table.merged(...)
1283 local t={}
1284 for i=1,select("#",...) do
1285 for k,v in next,(select(i,...)) do
1286 t[k]=v
1287 end
1288 end
1289 return t
1290 end
1291 function table.imerge(t,...)
1292 local nt=#t
1293 for i=1,select("#",...) do
1294 local nst=select(i,...)
1295 for j=1,#nst do
1296 nt=nt+1
1297 t[nt]=nst[j]
1298 end
1299 end
1300 return t
1301 end
1302 function table.imerged(...)
1303 local tmp={}
1304 local ntmp=0
1305 for i=1,select("#",...) do
1306 local nst=select(i,...)
1307 for j=1,#nst do
1308 ntmp=ntmp+1
1309 tmp[ntmp]=nst[j]
1310 end
1311 end
1312 return tmp
1313 end
1314 local function fastcopy(old,metatabletoo)
1315 if old then
1316 local new={}
1317 for k,v in next,old do
1318 if type(v)=="table" then
1319 new[k]=fastcopy(v,metatabletoo)
1320 else
1321 new[k]=v
1322 end
1323 end
1324 if metatabletoo then
1325 local mt=getmetatable(old)
1326 if mt then
1327 setmetatable(new,mt)
1328 end
1329 end
1330 return new
1331 else
1332 return {}
1333 end
1334 end
1335 local function copy(t,tables)
1336 if not tables then
1337 tables={}
1338 end
1339 local tcopy={}
1340 if not tables[t] then
1341 tables[t]=tcopy
1342 end
1343 for i,v in next,t do
1344 if type(i)=="table" then
1345 if tables[i] then
1346 i=tables[i]
1347 else
1348 i=copy(i,tables)
1349 end
1350 end
1351 if type(v)~="table" then
1352 tcopy[i]=v
1353 elseif tables[v] then
1354 tcopy[i]=tables[v]
1355 else
1356 tcopy[i]=copy(v,tables)
1357 end
1358 end
1359 local mt=getmetatable(t)
1360 if mt then
1361 setmetatable(tcopy,mt)
1362 end
1363 return tcopy
1364 end
1365 table.fastcopy=fastcopy
1366 table.copy=copy
1367 function table.derive(parent)
1368 local child={}
1369 if parent then
1370 setmetatable(child,{ __index=parent })
1371 end
1372 return child
1373 end
1374 function table.tohash(t,value)
1375 local h={}
1376 if t then
1377 if value==nil then value=true end
1378 for _,v in next,t do
1379 h[v]=value
1380 end
1381 end
1382 return h
1383 end
1384 function table.fromhash(t)
1385 local hsh={}
1386 local h=0
1387 for k,v in next,t do
1388 if v then
1389 h=h+1
1390 hsh[h]=k
1391 end
1392 end
1393 return hsh
1394 end
1395 local noquotes,hexify,handle,compact,inline,functions,metacheck,accurate
1396 local reserved=table.tohash {
1397 'and','break','do','else','elseif','end','false','for','function','if',
1398 'in','local','nil','not','or','repeat','return','then','true','until','while',
1399 'NaN','goto','const',
1400 }
1401 local function is_simple_table(t,hexify,accurate)
1402 local nt=#t
1403 if nt>0 then
1404 local n=0
1405 for _,v in next,t do
1406 n=n+1
1407 if type(v)=="table" then
1408 return nil
1409 end
1410 end
1411 local haszero=rawget(t,0)
1412 if n==nt then
1413 local tt={}
1414 for i=1,nt do
1415 local v=t[i]
1416 local tv=type(v)
1417 if tv=="number" then
1418 if hexify then
1419 tt[i]=format("0x%X",v)
1420 elseif accurate then
1421 tt[i]=format("%q",v)
1422 else
1423 tt[i]=v
1424 end
1425 elseif tv=="string" then
1426 tt[i]=format("%q",v)
1427 elseif tv=="boolean" then
1428 tt[i]=v and "true" or "false"
1429 else
1430 return nil
1431 end
1432 end
1433 return tt
1434 elseif haszero and (n==nt+1) then
1435 local tt={}
1436 for i=0,nt do
1437 local v=t[i]
1438 local tv=type(v)
1439 if tv=="number" then
1440 if hexify then
1441 tt[i+1]=format("0x%X",v)
1442 elseif accurate then
1443 tt[i+1]=format("%q",v)
1444 else
1445 tt[i+1]=v
1446 end
1447 elseif tv=="string" then
1448 tt[i+1]=format("%q",v)
1449 elseif tv=="boolean" then
1450 tt[i+1]=v and "true" or "false"
1451 else
1452 return nil
1453 end
1454 end
1455 tt[1]="[0] = "..tt[1]
1456 return tt
1457 end
1458 end
1459 return nil
1460 end
1461 table.is_simple_table=is_simple_table
1462 local propername=patterns.propername
1463 local function dummy() end
1464 local function do_serialize(root,name,depth,level,indexed)
1465 if level>0 then
1466 depth=depth.." "
1467 if indexed then
1468 handle(format("%s{",depth))
1469 else
1470 local tn=type(name)
1471 if tn=="number" then
1472 if hexify then
1473 handle(format("%s[0x%X]={",depth,name))
1474 else
1475 handle(format("%s[%s]={",depth,name))
1476 end
1477 elseif tn=="string" then
1478 if noquotes and not reserved[name] and lpegmatch(propername,name) then
1479 handle(format("%s%s={",depth,name))
1480 else
1481 handle(format("%s[%q]={",depth,name))
1482 end
1483 elseif tn=="boolean" then
1484 handle(format("%s[%s]={",depth,name and "true" or "false"))
1485 else
1486 handle(format("%s{",depth))
1487 end
1488 end
1489 end
1490 if root and next(root)~=nil then
1491 local first=nil
1492 local last=0
1493 if compact then
1494 last=#root
1495 for k=1,last do
1496 if rawget(root,k)==nil then
1497 last=k-1
1498 break
1499 end
1500 end
1501 if last>0 then
1502 first=1
1503 end
1504 end
1505 local sk=sortedkeys(root)
1506 for i=1,#sk do
1507 local k=sk[i]
1508 local v=root[k]
1509 local tv=type(v)
1510 local tk=type(k)
1511 if compact and first and tk=="number" and k>=first and k<=last then
1512 if tv=="number" then
1513 if hexify then
1514 handle(format("%s 0x%X,",depth,v))
1515 elseif accurate then
1516 handle(format("%s %q,",depth,v))
1517 else
1518 handle(format("%s %s,",depth,v))
1519 end
1520 elseif tv=="string" then
1521 handle(format("%s %q,",depth,v))
1522 elseif tv=="table" then
1523 if next(v)==nil then
1524 handle(format("%s {},",depth))
1525 elseif inline then
1526 local st=is_simple_table(v,hexify,accurate)
1527 if st then
1528 handle(format("%s { %s },",depth,concat(st,", ")))
1529 else
1530 do_serialize(v,k,depth,level+1,true)
1531 end
1532 else
1533 do_serialize(v,k,depth,level+1,true)
1534 end
1535 elseif tv=="boolean" then
1536 handle(format("%s %s,",depth,v and "true" or "false"))
1537 elseif tv=="function" then
1538 if functions then
1539 handle(format('%s load(%q),',depth,dump(v)))
1540 else
1541 handle(format('%s "function",',depth))
1542 end
1543 else
1544 handle(format("%s %q,",depth,tostring(v)))
1545 end
1546 elseif k=="__p__" then
1547 if false then
1548 handle(format("%s __p__=nil,",depth))
1549 end
1550 elseif tv=="number" then
1551 if tk=="number" then
1552 if hexify then
1553 if accurate then
1554 handle(format("%s [0x%X]=%q,",depth,k,v))
1555 else
1556 handle(format("%s [0x%X]=%s,",depth,k,v))
1557 end
1558 elseif accurate then
1559 handle(format("%s [%s]=%q,",depth,k,v))
1560 else
1561 handle(format("%s [%s]=%s,",depth,k,v))
1562 end
1563 elseif tk=="boolean" then
1564 if hexify then
1565 if accurate then
1566 handle(format("%s [%s]=%q,",depth,k and "true" or "false",v))
1567 else
1568 handle(format("%s [%s]=%s,",depth,k and "true" or "false",v))
1569 end
1570 elseif accurate then
1571 handle(format("%s [%s]=%q,",depth,k and "true" or "false",v))
1572 else
1573 handle(format("%s [%s]=%s,",depth,k and "true" or "false",v))
1574 end
1575 elseif tk~="string" then
1576 elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
1577 if hexify then
1578 if accurate then
1579 handle(format("%s %s=%q,",depth,k,v))
1580 else
1581 handle(format("%s %s=0x%X,",depth,k,v))
1582 end
1583 elseif accurate then
1584 handle(format("%s %s=%q,",depth,k,v))
1585 else
1586 handle(format("%s %s=%s,",depth,k,v))
1587 end
1588 else
1589 if hexify then
1590 if accurate then
1591 handle(format("%s [%q]=%q,",depth,k,v))
1592 else
1593 handle(format("%s [%q]=0x%X,",depth,k,v))
1594 end
1595 elseif accurate then
1596 handle(format("%s [%q]=%q,",depth,k,v))
1597 else
1598 handle(format("%s [%q]=%s,",depth,k,v))
1599 end
1600 end
1601 elseif tv=="string" then
1602 if tk=="number" then
1603 if hexify then
1604 handle(format("%s [0x%X]=%q,",depth,k,v))
1605 elseif accurate then
1606 handle(format("%s [%q]=%q,",depth,k,v))
1607 else
1608 handle(format("%s [%s]=%q,",depth,k,v))
1609 end
1610 elseif tk=="boolean" then
1611 handle(format("%s [%s]=%q,",depth,k and "true" or "false",v))
1612 elseif tk~="string" then
1613 elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
1614 handle(format("%s %s=%q,",depth,k,v))
1615 else
1616 handle(format("%s [%q]=%q,",depth,k,v))
1617 end
1618 elseif tv=="table" then
1619 if next(v)==nil then
1620 if tk=="number" then
1621 if hexify then
1622 handle(format("%s [0x%X]={},",depth,k))
1623 elseif accurate then
1624 handle(format("%s [%q]={},",depth,k))
1625 else
1626 handle(format("%s [%s]={},",depth,k))
1627 end
1628 elseif tk=="boolean" then
1629 handle(format("%s [%s]={},",depth,k and "true" or "false"))
1630 elseif tk~="string" then
1631 elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
1632 handle(format("%s %s={},",depth,k))
1633 else
1634 handle(format("%s [%q]={},",depth,k))
1635 end
1636 elseif inline then
1637 local st=is_simple_table(v,hexify,accurate)
1638 if st then
1639 if tk=="number" then
1640 if hexify then
1641 handle(format("%s [0x%X]={ %s },",depth,k,concat(st,", ")))
1642 elseif accurate then
1643 handle(format("%s [%q]={ %s },",depth,k,concat(st,", ")))
1644 else
1645 handle(format("%s [%s]={ %s },",depth,k,concat(st,", ")))
1646 end
1647 elseif tk=="boolean" then
1648 handle(format("%s [%s]={ %s },",depth,k and "true" or "false",concat(st,", ")))
1649 elseif tk~="string" then
1650 elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
1651 handle(format("%s %s={ %s },",depth,k,concat(st,", ")))
1652 else
1653 handle(format("%s [%q]={ %s },",depth,k,concat(st,", ")))
1654 end
1655 else
1656 do_serialize(v,k,depth,level+1)
1657 end
1658 else
1659 do_serialize(v,k,depth,level+1)
1660 end
1661 elseif tv=="boolean" then
1662 if tk=="number" then
1663 if hexify then
1664 handle(format("%s [0x%X]=%s,",depth,k,v and "true" or "false"))
1665 elseif accurate then
1666 handle(format("%s [%q]=%s,",depth,k,v and "true" or "false"))
1667 else
1668 handle(format("%s [%s]=%s,",depth,k,v and "true" or "false"))
1669 end
1670 elseif tk=="boolean" then
1671 handle(format("%s [%s]=%s,",depth,tostring(k),v and "true" or "false"))
1672 elseif tk~="string" then
1673 elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
1674 handle(format("%s %s=%s,",depth,k,v and "true" or "false"))
1675 else
1676 handle(format("%s [%q]=%s,",depth,k,v and "true" or "false"))
1677 end
1678 elseif tv=="function" then
1679 if functions then
1680 local getinfo=debug and debug.getinfo
1681 if getinfo then
1682 local f=getinfo(v).what=="C" and dump(dummy) or dump(v)
1683 if tk=="number" then
1684 if hexify then
1685 handle(format("%s [0x%X]=load(%q),",depth,k,f))
1686 elseif accurate then
1687 handle(format("%s [%q]=load(%q),",depth,k,f))
1688 else
1689 handle(format("%s [%s]=load(%q),",depth,k,f))
1690 end
1691 elseif tk=="boolean" then
1692 handle(format("%s [%s]=load(%q),",depth,k and "true" or "false",f))
1693 elseif tk~="string" then
1694 elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
1695 handle(format("%s %s=load(%q),",depth,k,f))
1696 else
1697 handle(format("%s [%q]=load(%q),",depth,k,f))
1698 end
1699 end
1700 end
1701 else
1702 if tk=="number" then
1703 if hexify then
1704 handle(format("%s [0x%X]=%q,",depth,k,tostring(v)))
1705 elseif accurate then
1706 handle(format("%s [%q]=%q,",depth,k,tostring(v)))
1707 else
1708 handle(format("%s [%s]=%q,",depth,k,tostring(v)))
1709 end
1710 elseif tk=="boolean" then
1711 handle(format("%s [%s]=%q,",depth,k and "true" or "false",tostring(v)))
1712 elseif tk~="string" then
1713 elseif noquotes and not reserved[k] and lpegmatch(propername,k) then
1714 handle(format("%s %s=%q,",depth,k,tostring(v)))
1715 else
1716 handle(format("%s [%q]=%q,",depth,k,tostring(v)))
1717 end
1718 end
1719 end
1720 end
1721 if level>0 then
1722 handle(format("%s},",depth))
1723 end
1724 end
1725 local function serialize(_handle,root,name,specification)
1726 local tname=type(name)
1727 if type(specification)=="table" then
1728 noquotes=specification.noquotes
1729 hexify=specification.hexify
1730 accurate=specification.accurate
1731 handle=_handle or specification.handle or print
1732 functions=specification.functions
1733 compact=specification.compact
1734 inline=specification.inline and compact
1735 metacheck=specification.metacheck
1736 if functions==nil then
1737 functions=true
1738 end
1739 if compact==nil then
1740 compact=true
1741 end
1742 if inline==nil then
1743 inline=compact
1744 end
1745 if metacheck==nil then
1746 metacheck=true
1747 end
1748 else
1749 noquotes=false
1750 hexify=false
1751 handle=_handle or print
1752 compact=true
1753 inline=true
1754 functions=true
1755 metacheck=true
1756 end
1757 if tname=="string" then
1758 if name=="return" then
1759 handle("return {")
1760 else
1761 handle(name.."={")
1762 end
1763 elseif tname=="number" then
1764 if hexify then
1765 handle(format("[0x%X]={",name))
1766 else
1767 handle("["..name.."]={")
1768 end
1769 elseif tname=="boolean" then
1770 if name then
1771 handle("return {")
1772 else
1773 handle("{")
1774 end
1775 else
1776 handle("t={")
1777 end
1778 if root then
1779 if metacheck and getmetatable(root) then
1780 local dummy=root._w_h_a_t_e_v_e_r_
1781 root._w_h_a_t_e_v_e_r_=nil
1782 end
1783 if next(root)~=nil then
1784 do_serialize(root,name,"",0)
1785 end
1786 end
1787 handle("}")
1788 end
1789 function table.serialize(root,name,specification)
1790 local t={}
1791 local n=0
1792 local function flush(s)
1793 n=n+1
1794 t[n]=s
1795 end
1796 serialize(flush,root,name,specification)
1797 return concat(t,"\n")
1798 end
1799 table.tohandle=serialize
1800 local maxtab=2*1024
1801 function table.tofile(filename,root,name,specification)
1802 local f=io.open(filename,'w')
1803 if f then
1804 if maxtab>1 then
1805 local t={}
1806 local n=0
1807 local function flush(s)
1808 n=n+1
1809 t[n]=s
1810 if n>maxtab then
1811 f:write(concat(t,"\n"),"\n")
1812 t={}
1813 n=0
1814 end
1815 end
1816 serialize(flush,root,name,specification)
1817 f:write(concat(t,"\n"),"\n")
1818 else
1819 local function flush(s)
1820 f:write(s,"\n")
1821 end
1822 serialize(flush,root,name,specification)
1823 end
1824 f:close()
1825 io.flush()
1826 end
1827 end
1828 local function flattened(t,f,depth)
1829 if f==nil then
1830 f={}
1831 depth=0xFFFF
1832 elseif tonumber(f) then
1833 depth=f
1834 f={}
1835 elseif not depth then
1836 depth=0xFFFF
1837 end
1838 for k,v in next,t do
1839 if type(k)~="number" then
1840 if depth>0 and type(v)=="table" then
1841 flattened(v,f,depth-1)
1842 else
1843 f[#f+1]=v
1844 end
1845 end
1846 end
1847 for k=1,#t do
1848 local v=t[k]
1849 if depth>0 and type(v)=="table" then
1850 flattened(v,f,depth-1)
1851 else
1852 f[#f+1]=v
1853 end
1854 end
1855 return f
1856 end
1857 table.flattened=flattened
1858 local function collapsed(t,f,h)
1859 if f==nil then
1860 f={}
1861 h={}
1862 end
1863 for k=1,#t do
1864 local v=t[k]
1865 if type(v)=="table" then
1866 collapsed(v,f,h)
1867 elseif not h[v] then
1868 f[#f+1]=v
1869 h[v]=true
1870 end
1871 end
1872 return f
1873 end
1874 local function collapsedhash(t,h)
1875 if h==nil then
1876 h={}
1877 end
1878 for k=1,#t do
1879 local v=t[k]
1880 if type(v)=="table" then
1881 collapsedhash(v,h)
1882 else
1883 h[v]=true
1884 end
1885 end
1886 return h
1887 end
1888 table.collapsed=collapsed
1889 table.collapsedhash=collapsedhash
1890 local function unnest(t,f)
1891 if not f then
1892 f={}
1893 end
1894 for i=1,#t do
1895 local v=t[i]
1896 if type(v)=="table" then
1897 if type(v[1])=="table" then
1898 unnest(v,f)
1899 else
1900 f[#f+1]=v
1901 end
1902 else
1903 f[#f+1]=v
1904 end
1905 end
1906 return f
1907 end
1908 function table.unnest(t)
1909 return unnest(t)
1910 end
1911 local function are_equal(a,b,n,m)
1912 if a==b then
1913 return true
1914 elseif a and b and #a==#b then
1915 if not n then
1916 n=1
1917 end
1918 if not m then
1919 m=#a
1920 end
1921 for i=n,m do
1922 local ai,bi=a[i],b[i]
1923 if ai==bi then
1924 elseif type(ai)=="table" and type(bi)=="table" then
1925 if not are_equal(ai,bi) then
1926 return false
1927 end
1928 else
1929 return false
1930 end
1931 end
1932 return true
1933 else
1934 return false
1935 end
1936 end
1937 local function identical(a,b)
1938 if a~=b then
1939 for ka,va in next,a do
1940 local vb=b[ka]
1941 if va==vb then
1942 elseif type(va)=="table" and type(vb)=="table" then
1943 if not identical(va,vb) then
1944 return false
1945 end
1946 else
1947 return false
1948 end
1949 end
1950 end
1951 return true
1952 end
1953 table.identical=identical
1954 table.are_equal=are_equal
1955 local function sparse(old,nest,keeptables)
1956 local new={}
1957 for k,v in next,old do
1958 if not (v=="" or v==false) then
1959 if nest and type(v)=="table" then
1960 v=sparse(v,nest)
1961 if keeptables or next(v)~=nil then
1962 new[k]=v
1963 end
1964 else
1965 new[k]=v
1966 end
1967 end
1968 end
1969 return new
1970 end
1971 table.sparse=sparse
1972 function table.compact(t)
1973 return sparse(t,true,true)
1974 end
1975 function table.contains(t,v)
1976 if t then
1977 for i=1,#t do
1978 if t[i]==v then
1979 return i
1980 end
1981 end
1982 end
1983 return false
1984 end
1985 function table.count(t)
1986 local n=0
1987 for k,v in next,t do
1988 n=n+1
1989 end
1990 return n
1991 end
1992 function table.swapped(t,s)
1993 local n={}
1994 if s then
1995 for k,v in next,s do
1996 n[k]=v
1997 end
1998 end
1999 for k,v in next,t do
2000 n[v]=k
2001 end
2002 return n
2003 end
2004 function table.hashed(t)
2005 for i=1,#t do
2006 t[t[i]]=i
2007 end
2008 return t
2009 end
2010 function table.mirrored(t)
2011 local n={}
2012 for k,v in next,t do
2013 n[v]=k
2014 n[k]=v
2015 end
2016 return n
2017 end
2018 function table.reversed(t)
2019 if t then
2020 local tt={}
2021 local tn=#t
2022 if tn>0 then
2023 local ttn=0
2024 for i=tn,1,-1 do
2025 ttn=ttn+1
2026 tt[ttn]=t[i]
2027 end
2028 end
2029 return tt
2030 end
2031 end
2032 function table.reverse(t)
2033 if t then
2034 local n=#t
2035 local m=n+1
2036 for i=1,floor(n/2) do
2037 local j=m-i
2038 t[i],t[j]=t[j],t[i]
2039 end
2040 return t
2041 end
2042 end
2043 local function sequenced(t,sep,simple)
2044 if not t then
2045 return ""
2046 elseif type(t)~="table" then
2047 return t
2048 end
2049 local n=#t
2050 local s={}
2051 if n>0 then
2052 for i=1,n do
2053 local v=t[i]
2054 if type(v)=="table" then
2055 s[i]="{"..sequenced(v,sep,simple).."}"
2056 else
2057 s[i]=tostring(t[i])
2058 end
2059 end
2060 else
2061 n=0
2062 for k,v in sortedhash(t) do
2063 if simple then
2064 if v==true then
2065 n=n+1
2066 s[n]=k
2067 elseif v and v~="" then
2068 n=n+1
2069 if type(v)=="table" then
2070 s[n]=k.."={"..sequenced(v,sep,simple).."}"
2071 else
2072 s[n]=k.."="..tostring(v)
2073 end
2074 end
2075 else
2076 n=n+1
2077 if type(v)=="table" then
2078 s[n]=k.."={"..sequenced(v,sep,simple).."}"
2079 else
2080 s[n]=k.."="..tostring(v)
2081 end
2082 end
2083 end
2084 end
2085 if sep==true then
2086 return "{ "..concat(s,", ").." }"
2087 else
2088 return concat(s,sep or " | ")
2089 end
2090 end
2091 table.sequenced=sequenced
2092 function table.print(t,...)
2093 if type(t)~="table" then
2094 print(tostring(t))
2095 else
2096 serialize(print,t,...)
2097 end
2098 end
2099 if setinspector then
2100 setinspector("table",function(v) if type(v)=="table" then serialize(print,v,"table") return true end end)
2101 end
2102 function table.sub(t,i,j)
2103 return { unpack(t,i,j) }
2104 end
2105 function table.is_empty(t)
2106 return not t or next(t)==nil
2107 end
2108 function table.has_one_entry(t)
2109 return t and next(t,next(t))==nil
2110 end
2111 function table.loweredkeys(t)
2112 local l={}
2113 for k,v in next,t do
2114 l[lower(k)]=v
2115 end
2116 return l
2117 end
2118 function table.unique(old)
2119 local hash={}
2120 local new={}
2121 local n=0
2122 for i=1,#old do
2123 local oi=old[i]
2124 if not hash[oi] then
2125 n=n+1
2126 new[n]=oi
2127 hash[oi]=true
2128 end
2129 end
2130 return new
2131 end
2132 function table.sorted(t,...)
2133 sort(t,...)
2134 return t
2135 end
2136 function table.values(t,s)
2137 if t then
2138 local values={}
2139 local keys={}
2140 local v=0
2141 for key,value in next,t do
2142 if not keys[value] then
2143 v=v+1
2144 values[v]=value
2145 keys[k]=key
2146 end
2147 end
2148 if s then
2149 sort(values)
2150 end
2151 return values
2152 else
2153 return {}
2154 end
2155 end
2156 function table.filtered(t,pattern,sort,cmp)
2157 if t and type(pattern)=="string" then
2158 if sort then
2159 local s
2160 if cmp then
2161 s=sortedhashkeys(t,function(a,b) return cmp(t,a,b) end)
2162 else
2163 s=sortedkeys(t)
2164 end
2165 local n=0
2166 local m=#s
2167 local function kv(s)
2168 while n<m do
2169 n=n+1
2170 local k=s[n]
2171 if find(k,pattern) then
2172 return k,t[k]
2173 end
2174 end
2175 end
2176 return kv,s
2177 else
2178 local n=next(t)
2179 local function iterator()
2180 while n~=nil do
2181 local k=n
2182 n=next(t,k)
2183 if find(k,pattern) then
2184 return k,t[k]
2185 end
2186 end
2187 end
2188 return iterator,t
2189 end
2190 else
2191 return nothing
2192 end
2193 end
2194 if not table.move then
2195 function table.move(a1,f,e,t,a2)
2196 if a2 and a1~=a2 then
2197 for i=f,e do
2198 a2[t]=a1[i]
2199 t=t+1
2200 end
2201 return a2
2202 else
2203 t=t+e-f
2204 for i=e,f,-1 do
2205 a1[t]=a1[i]
2206 t=t-1
2207 end
2208 return a1
2209 end
2210 end
2211 end
2212
2213 end -- closure
2214
2215 do -- begin closure to overcome local limits and interference
2216
2217 if not modules then modules={} end modules ['l-io']={
2218 version=1.001,
2219 comment="companion to luat-lib.mkiv",
2220 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
2221 copyright="PRAGMA ADE / ConTeXt Development Team",
2222 license="see context related readme files"
2223 }
2224 local io=io
2225 local open,flush,write,read=io.open,io.flush,io.write,io.read
2226 local byte,find,gsub,format=string.byte,string.find,string.gsub,string.format
2227 local concat=table.concat
2228 local type=type
2229 if string.find(os.getenv("PATH") or "",";",1,true) then
2230 io.fileseparator,io.pathseparator="\\",";"
2231 else
2232 io.fileseparator,io.pathseparator="/",":"
2233 end
2234 local large=0x01000000
2235 local medium=0x00100000
2236 local small=0x00020000
2237 local function readall(f)
2238 local size=f:seek("end")
2239 if size>0 then
2240 f:seek("set",0)
2241 return f:read(size)
2242 else
2243 return ""
2244 end
2245 end
2246 io.readall=readall
2247 function io.loaddata(filename,textmode)
2248 local f=open(filename,(textmode and 'r') or 'rb')
2249 if f then
2250 local size=f:seek("end")
2251 local data=nil
2252 if size>0 then
2253 f:seek("set",0)
2254 data=f:read(size)
2255 end
2256 f:close()
2257 return data
2258 end
2259 end
2260 function io.copydata(source,target,action)
2261 local f=open(source,"rb")
2262 if f then
2263 local g=open(target,"wb")
2264 if g then
2265 local size=f:seek("end")
2266 if size>0 then
2267 f:seek("set",0)
2268 local data=f:read(size)
2269 if action then
2270 data=action(data)
2271 end
2272 if data then
2273 g:write(data)
2274 end
2275 end
2276 g:close()
2277 end
2278 f:close()
2279 flush()
2280 end
2281 end
2282 function io.savedata(filename,data,joiner,append)
2283 local f=open(filename,append and "ab" or "wb")
2284 if f then
2285 if append and joiner and f:seek("end")>0 then
2286 f:write(joiner)
2287 end
2288 if type(data)=="table" then
2289 f:write(concat(data,joiner or ""))
2290 elseif type(data)=="function" then
2291 data(f)
2292 else
2293 f:write(data or "")
2294 end
2295 f:close()
2296 flush()
2297 return true
2298 else
2299 return false
2300 end
2301 end
2302 if fio and fio.readline then
2303 local readline=fio.readline
2304 function io.loadlines(filename,n)
2305 local f=open(filename,'r')
2306 if not f then
2307 elseif n then
2308 local lines={}
2309 for i=1,n do
2310 local line=readline(f)
2311 if line then
2312 lines[i]=line
2313 else
2314 break
2315 end
2316 end
2317 f:close()
2318 lines=concat(lines,"\n")
2319 if #lines>0 then
2320 return lines
2321 end
2322 else
2323 local line=readline(f)
2324 f:close()
2325 if line and #line>0 then
2326 return line
2327 end
2328 end
2329 end
2330 else
2331 function io.loadlines(filename,n)
2332 local f=open(filename,'r')
2333 if not f then
2334 elseif n then
2335 local lines={}
2336 for i=1,n do
2337 local line=f:read("*lines")
2338 if line then
2339 lines[i]=line
2340 else
2341 break
2342 end
2343 end
2344 f:close()
2345 lines=concat(lines,"\n")
2346 if #lines>0 then
2347 return lines
2348 end
2349 else
2350 local line=f:read("*line") or ""
2351 f:close()
2352 if #line>0 then
2353 return line
2354 end
2355 end
2356 end
2357 end
2358 function io.loadchunk(filename,n)
2359 local f=open(filename,'rb')
2360 if f then
2361 local data=f:read(n or 1024)
2362 f:close()
2363 if #data>0 then
2364 return data
2365 end
2366 end
2367 end
2368 function io.exists(filename)
2369 local f=open(filename)
2370 if f==nil then
2371 return false
2372 else
2373 f:close()
2374 return true
2375 end
2376 end
2377 function io.size(filename)
2378 local f=open(filename)
2379 if f==nil then
2380 return 0
2381 else
2382 local s=f:seek("end")
2383 f:close()
2384 return s
2385 end
2386 end
2387 local function noflines(f)
2388 if type(f)=="string" then
2389 local f=open(filename)
2390 if f then
2391 local n=f and noflines(f) or 0
2392 f:close()
2393 return n
2394 else
2395 return 0
2396 end
2397 else
2398 local n=0
2399 for _ in f:lines() do
2400 n=n+1
2401 end
2402 f:seek('set',0)
2403 return n
2404 end
2405 end
2406 io.noflines=noflines
2407 local nextchar={
2408 [ 4]=function(f)
2409 return f:read(1,1,1,1)
2410 end,
2411 [ 2]=function(f)
2412 return f:read(1,1)
2413 end,
2414 [ 1]=function(f)
2415 return f:read(1)
2416 end,
2417 [-2]=function(f)
2418 local a,b=f:read(1,1)
2419 return b,a
2420 end,
2421 [-4]=function(f)
2422 local a,b,c,d=f:read(1,1,1,1)
2423 return d,c,b,a
2424 end
2425 }
2426 function io.characters(f,n)
2427 if f then
2428 return nextchar[n or 1],f
2429 end
2430 end
2431 local nextbyte={
2432 [4]=function(f)
2433 local a,b,c,d=f:read(1,1,1,1)
2434 if d then
2435 return byte(a),byte(b),byte(c),byte(d)
2436 end
2437 end,
2438 [3]=function(f)
2439 local a,b,c=f:read(1,1,1)
2440 if b then
2441 return byte(a),byte(b),byte(c)
2442 end
2443 end,
2444 [2]=function(f)
2445 local a,b=f:read(1,1)
2446 if b then
2447 return byte(a),byte(b)
2448 end
2449 end,
2450 [1]=function (f)
2451 local a=f:read(1)
2452 if a then
2453 return byte(a)
2454 end
2455 end,
2456 [-2]=function (f)
2457 local a,b=f:read(1,1)
2458 if b then
2459 return byte(b),byte(a)
2460 end
2461 end,
2462 [-3]=function(f)
2463 local a,b,c=f:read(1,1,1)
2464 if b then
2465 return byte(c),byte(b),byte(a)
2466 end
2467 end,
2468 [-4]=function(f)
2469 local a,b,c,d=f:read(1,1,1,1)
2470 if d then
2471 return byte(d),byte(c),byte(b),byte(a)
2472 end
2473 end
2474 }
2475 function io.bytes(f,n)
2476 if f then
2477 return nextbyte[n or 1],f
2478 else
2479 return nil,nil
2480 end
2481 end
2482 function io.ask(question,default,options)
2483 while true do
2484 write(question)
2485 if options then
2486 write(format(" [%s]",concat(options,"|")))
2487 end
2488 if default then
2489 write(format(" [%s]",default))
2490 end
2491 write(format(" "))
2492 flush()
2493 local answer=read()
2494 answer=gsub(answer,"^%s*(.*)%s*$","%1")
2495 if answer=="" and default then
2496 return default
2497 elseif not options then
2498 return answer
2499 else
2500 for k=1,#options do
2501 if options[k]==answer then
2502 return answer
2503 end
2504 end
2505 local pattern="^"..answer
2506 for k=1,#options do
2507 local v=options[k]
2508 if find(v,pattern) then
2509 return v
2510 end
2511 end
2512 end
2513 end
2514 end
2515 local function readnumber(f,n,m)
2516 if m then
2517 f:seek("set",n)
2518 n=m
2519 end
2520 if n==1 then
2521 return byte(f:read(1))
2522 elseif n==2 then
2523 local a,b=byte(f:read(2),1,2)
2524 return 0x100*a+b
2525 elseif n==3 then
2526 local a,b,c=byte(f:read(3),1,3)
2527 return 0x10000*a+0x100*b+c
2528 elseif n==4 then
2529 local a,b,c,d=byte(f:read(4),1,4)
2530 return 0x1000000*a+0x10000*b+0x100*c+d
2531 elseif n==8 then
2532 local a,b=readnumber(f,4),readnumber(f,4)
2533 return 0x100*a+b
2534 elseif n==12 then
2535 local a,b,c=readnumber(f,4),readnumber(f,4),readnumber(f,4)
2536 return 0x10000*a+0x100*b+c
2537 elseif n==-2 then
2538 local b,a=byte(f:read(2),1,2)
2539 return 0x100*a+b
2540 elseif n==-3 then
2541 local c,b,a=byte(f:read(3),1,3)
2542 return 0x10000*a+0x100*b+c
2543 elseif n==-4 then
2544 local d,c,b,a=byte(f:read(4),1,4)
2545 return 0x1000000*a+0x10000*b+0x100*c+d
2546 elseif n==-8 then
2547 local h,g,f,e,d,c,b,a=byte(f:read(8),1,8)
2548 return 0x100000000000000*a+0x1000000000000*b+0x10000000000*c+0x100000000*d+0x1000000*e+0x10000*f+0x100*g+h
2549 else
2550 return 0
2551 end
2552 end
2553 io.readnumber=readnumber
2554 function io.readstring(f,n,m)
2555 if m then
2556 f:seek("set",n)
2557 n=m
2558 end
2559 local str=gsub(f:read(n),"\000","")
2560 return str
2561 end
2562
2563 end -- closure
2564
2565 do -- begin closure to overcome local limits and interference
2566
2567 if not modules then modules={} end modules ['l-file']={
2568 version=1.001,
2569 comment="companion to luat-lib.mkiv",
2570 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
2571 copyright="PRAGMA ADE / ConTeXt Development Team",
2572 license="see context related readme files"
2573 }
2574 file=file or {}
2575 local file=file
2576 if not lfs then
2577 lfs=optionalrequire("lfs")
2578 end
2579 local insert,concat=table.insert,table.concat
2580 local match,find,gmatch=string.match,string.find,string.gmatch
2581 local lpegmatch=lpeg.match
2582 local getcurrentdir,attributes=lfs.currentdir,lfs.attributes
2583 local checkedsplit=string.checkedsplit
2584 local P,R,S,C,Cs,Cp,Cc,Ct=lpeg.P,lpeg.R,lpeg.S,lpeg.C,lpeg.Cs,lpeg.Cp,lpeg.Cc,lpeg.Ct
2585 local attributes=lfs.attributes
2586 function lfs.isdir(name)
2587 if name then
2588 return attributes(name,"mode")=="directory"
2589 end
2590 end
2591 function lfs.isfile(name)
2592 if name then
2593 local a=attributes(name,"mode")
2594 return a=="file" or a=="link" or nil
2595 end
2596 end
2597 function lfs.isfound(name)
2598 if name then
2599 local a=attributes(name,"mode")
2600 return (a=="file" or a=="link") and name or nil
2601 end
2602 end
2603 function lfs.modification(name)
2604 return name and attributes(name,"modification") or nil
2605 end
2606 if sandbox then
2607 sandbox.redefine(lfs.isfile,"lfs.isfile")
2608 sandbox.redefine(lfs.isdir,"lfs.isdir")
2609 sandbox.redefine(lfs.isfound,"lfs.isfound")
2610 end
2611 local colon=P(":")
2612 local period=P(".")
2613 local periods=P("..")
2614 local fwslash=P("/")
2615 local bwslash=P("\\")
2616 local slashes=S("\\/")
2617 local noperiod=1-period
2618 local noslashes=1-slashes
2619 local name=noperiod^1
2620 local suffix=period/""*(1-period-slashes)^1*-1
2621 local pattern=C((1-(slashes^1*noslashes^1*-1))^1)*P(1)
2622 local function pathpart(name,default)
2623 return name and lpegmatch(pattern,name) or default or ""
2624 end
2625 local pattern=(noslashes^0*slashes)^1*C(noslashes^1)*-1
2626 local function basename(name)
2627 return name and lpegmatch(pattern,name) or name
2628 end
2629 local pattern=(noslashes^0*slashes^1)^0*Cs((1-suffix)^1)*suffix^0
2630 local function nameonly(name)
2631 return name and lpegmatch(pattern,name) or name
2632 end
2633 local pattern=(noslashes^0*slashes)^0*(noperiod^1*period)^1*C(noperiod^1)*-1
2634 local function suffixonly(name)
2635 return name and lpegmatch(pattern,name) or ""
2636 end
2637 local pattern=(noslashes^0*slashes)^0*noperiod^1*((period*C(noperiod^1))^1)*-1+Cc("")
2638 local function suffixesonly(name)
2639 if name then
2640 return lpegmatch(pattern,name)
2641 else
2642 return ""
2643 end
2644 end
2645 file.pathpart=pathpart
2646 file.basename=basename
2647 file.nameonly=nameonly
2648 file.suffixonly=suffixonly
2649 file.suffix=suffixonly
2650 file.suffixesonly=suffixesonly
2651 file.suffixes=suffixesonly
2652 file.dirname=pathpart
2653 file.extname=suffixonly
2654 local drive=C(R("az","AZ"))*colon
2655 local path=C((noslashes^0*slashes)^0)
2656 local suffix=period*C(P(1-period)^0*P(-1))
2657 local base=C((1-suffix)^0)
2658 local rest=C(P(1)^0)
2659 drive=drive+Cc("")
2660 path=path+Cc("")
2661 base=base+Cc("")
2662 suffix=suffix+Cc("")
2663 local pattern_a=drive*path*base*suffix
2664 local pattern_b=path*base*suffix
2665 local pattern_c=C(drive*path)*C(base*suffix)
2666 local pattern_d=path*rest
2667 function file.splitname(str,splitdrive)
2668 if not str then
2669 elseif splitdrive then
2670 return lpegmatch(pattern_a,str)
2671 else
2672 return lpegmatch(pattern_b,str)
2673 end
2674 end
2675 function file.splitbase(str)
2676 if str then
2677 return lpegmatch(pattern_d,str)
2678 else
2679 return "",str
2680 end
2681 end
2682 function file.nametotable(str,splitdrive)
2683 if str then
2684 local path,drive,subpath,name,base,suffix=lpegmatch(pattern_c,str)
2685 if splitdrive then
2686 return {
2687 path=path,
2688 drive=drive,
2689 subpath=subpath,
2690 name=name,
2691 base=base,
2692 suffix=suffix,
2693 }
2694 else
2695 return {
2696 path=path,
2697 name=name,
2698 base=base,
2699 suffix=suffix,
2700 }
2701 end
2702 end
2703 end
2704 local pattern=Cs(((period*(1-period-slashes)^1*-1)/""+1)^1)
2705 function file.removesuffix(name)
2706 return name and lpegmatch(pattern,name)
2707 end
2708 local suffix=period/""*(1-period-slashes)^1*-1
2709 local pattern=Cs((noslashes^0*slashes^1)^0*((1-suffix)^1))*Cs(suffix)
2710 function file.addsuffix(filename,suffix,criterium)
2711 if not filename or not suffix or suffix=="" then
2712 return filename
2713 elseif criterium==true then
2714 return filename.."."..suffix
2715 elseif not criterium then
2716 local n,s=lpegmatch(pattern,filename)
2717 if not s or s=="" then
2718 return filename.."."..suffix
2719 else
2720 return filename
2721 end
2722 else
2723 local n,s=lpegmatch(pattern,filename)
2724 if s and s~="" then
2725 local t=type(criterium)
2726 if t=="table" then
2727 for i=1,#criterium do
2728 if s==criterium[i] then
2729 return filename
2730 end
2731 end
2732 elseif t=="string" then
2733 if s==criterium then
2734 return filename
2735 end
2736 end
2737 end
2738 return (n or filename).."."..suffix
2739 end
2740 end
2741 local suffix=period*(1-period-slashes)^1*-1
2742 local pattern=Cs((1-suffix)^0)
2743 function file.replacesuffix(name,suffix)
2744 if name and suffix and suffix~="" then
2745 return lpegmatch(pattern,name).."."..suffix
2746 else
2747 return name
2748 end
2749 end
2750 local reslasher=lpeg.replacer(P("\\"),"/")
2751 function file.reslash(str)
2752 return str and lpegmatch(reslasher,str)
2753 end
2754 if lfs.isreadablefile and lfs.iswritablefile then
2755 file.is_readable=lfs.isreadablefile
2756 file.is_writable=lfs.iswritablefile
2757 else
2758 function file.is_writable(name)
2759 if not name then
2760 elseif lfs.isdir(name) then
2761 name=name.."/m_t_x_t_e_s_t.tmp"
2762 local f=io.open(name,"wb")
2763 if f then
2764 f:close()
2765 os.remove(name)
2766 return true
2767 end
2768 elseif lfs.isfile(name) then
2769 local f=io.open(name,"ab")
2770 if f then
2771 f:close()
2772 return true
2773 end
2774 else
2775 local f=io.open(name,"ab")
2776 if f then
2777 f:close()
2778 os.remove(name)
2779 return true
2780 end
2781 end
2782 return false
2783 end
2784 local readable=P("r")*Cc(true)
2785 function file.is_readable(name)
2786 if name then
2787 local a=attributes(name)
2788 return a and lpegmatch(readable,a.permissions) or false
2789 else
2790 return false
2791 end
2792 end
2793 end
2794 file.isreadable=file.is_readable
2795 file.iswritable=file.is_writable
2796 function file.size(name)
2797 if name then
2798 local a=attributes(name)
2799 return a and a.size or 0
2800 else
2801 return 0
2802 end
2803 end
2804 function file.splitpath(str,separator)
2805 return str and checkedsplit(lpegmatch(reslasher,str),separator or io.pathseparator)
2806 end
2807 function file.joinpath(tab,separator)
2808 return tab and concat(tab,separator or io.pathseparator)
2809 end
2810 local someslash=S("\\/")
2811 local stripper=Cs(P(fwslash)^0/""*reslasher)
2812 local isnetwork=someslash*someslash*(1-someslash)+(1-fwslash-colon)^1*colon
2813 local isroot=fwslash^1*-1
2814 local hasroot=fwslash^1
2815 local reslasher=lpeg.replacer(S("\\/"),"/")
2816 local deslasher=lpeg.replacer(S("\\/")^1,"/")
2817 function file.join(one,two,three,...)
2818 if not two then
2819 return one=="" and one or lpegmatch(reslasher,one)
2820 end
2821 if not one or one=="" then
2822 return lpegmatch(stripper,three and concat({ two,three,... },"/") or two)
2823 end
2824 if lpegmatch(isnetwork,one) then
2825 local one=lpegmatch(reslasher,one)
2826 local two=lpegmatch(deslasher,three and concat({ two,three,... },"/") or two)
2827 if lpegmatch(hasroot,two) then
2828 return one..two
2829 else
2830 return one.."/"..two
2831 end
2832 elseif lpegmatch(isroot,one) then
2833 local two=lpegmatch(deslasher,three and concat({ two,three,... },"/") or two)
2834 if lpegmatch(hasroot,two) then
2835 return two
2836 else
2837 return "/"..two
2838 end
2839 else
2840 return lpegmatch(deslasher,concat({ one,two,three,... },"/"))
2841 end
2842 end
2843 local drivespec=R("az","AZ")^1*colon
2844 local anchors=fwslash+drivespec
2845 local untouched=periods+(1-period)^1*P(-1)
2846 local mswindrive=Cs(drivespec*(bwslash/"/"+fwslash)^0)
2847 local mswinuncpath=(bwslash+fwslash)*(bwslash+fwslash)*Cc("//")
2848 local splitstarter=(mswindrive+mswinuncpath+Cc(false))*Ct(lpeg.splitat(S("/\\")^1))
2849 local absolute=fwslash
2850 function file.collapsepath(str,anchor)
2851 if not str then
2852 return
2853 end
2854 if anchor==true and not lpegmatch(anchors,str) then
2855 str=getcurrentdir().."/"..str
2856 end
2857 if str=="" or str=="." then
2858 return "."
2859 elseif lpegmatch(untouched,str) then
2860 return lpegmatch(reslasher,str)
2861 end
2862 local starter,oldelements=lpegmatch(splitstarter,str)
2863 local newelements={}
2864 local i=#oldelements
2865 while i>0 do
2866 local element=oldelements[i]
2867 if element=='.' then
2868 elseif element=='..' then
2869 local n=i-1
2870 while n>0 do
2871 local element=oldelements[n]
2872 if element~='..' and element~='.' then
2873 oldelements[n]='.'
2874 break
2875 else
2876 n=n-1
2877 end
2878 end
2879 if n<1 then
2880 insert(newelements,1,'..')
2881 end
2882 elseif element~="" then
2883 insert(newelements,1,element)
2884 end
2885 i=i-1
2886 end
2887 if #newelements==0 then
2888 return starter or "."
2889 elseif starter then
2890 return starter..concat(newelements,'/')
2891 elseif lpegmatch(absolute,str) then
2892 return "/"..concat(newelements,'/')
2893 else
2894 newelements=concat(newelements,'/')
2895 if anchor=="." and find(str,"^%./") then
2896 return "./"..newelements
2897 else
2898 return newelements
2899 end
2900 end
2901 end
2902 local validchars=R("az","09","AZ","--","..")
2903 local pattern_a=lpeg.replacer(1-validchars)
2904 local pattern_a=Cs((validchars+P(1)/"-")^1)
2905 local whatever=P("-")^0/""
2906 local pattern_b=Cs(whatever*(1-whatever*-1)^1)
2907 function file.robustname(str,strict)
2908 if str then
2909 str=lpegmatch(pattern_a,str) or str
2910 if strict then
2911 return lpegmatch(pattern_b,str) or str
2912 else
2913 return str
2914 end
2915 end
2916 end
2917 local loaddata=io.loaddata
2918 local savedata=io.savedata
2919 file.readdata=loaddata
2920 file.savedata=savedata
2921 function file.copy(oldname,newname)
2922 if oldname and newname then
2923 local data=loaddata(oldname)
2924 if data and data~="" then
2925 savedata(newname,data)
2926 end
2927 end
2928 end
2929 local letter=R("az","AZ")+S("_-+")
2930 local separator=P("://")
2931 local qualified=period^0*fwslash+letter*colon+letter^1*separator+letter^1*fwslash
2932 local rootbased=fwslash+letter*colon
2933 lpeg.patterns.qualified=qualified
2934 lpeg.patterns.rootbased=rootbased
2935 function file.is_qualified_path(filename)
2936 return filename and lpegmatch(qualified,filename)~=nil
2937 end
2938 function file.is_rootbased_path(filename)
2939 return filename and lpegmatch(rootbased,filename)~=nil
2940 end
2941 function file.strip(name,dir)
2942 if name then
2943 local b,a=match(name,"^(.-)"..dir.."(.*)$")
2944 return a~="" and a or name
2945 end
2946 end
2947 function lfs.mkdirs(path)
2948 local full=""
2949 for sub in gmatch(path,"(/*[^\\/]+)") do
2950 full=full..sub
2951 lfs.mkdir(full)
2952 end
2953 end
2954 function file.withinbase(path)
2955 local l=0
2956 if not find(path,"^/") then
2957 path="/"..path
2958 end
2959 for dir in gmatch(path,"/([^/]+)") do
2960 if dir==".." then
2961 l=l-1
2962 elseif dir~="." then
2963 l=l+1
2964 end
2965 if l<0 then
2966 return false
2967 end
2968 end
2969 return true
2970 end
2971 do
2972 local symlinktarget=lfs.symlinktarget
2973 local symlinkattributes=lfs.symlinkattributes
2974 if symlinktarget then
2975 function lfs.readlink(name)
2976 local target=symlinktarget(name)
2977 return name~=target and name or nil
2978 end
2979 elseif symlinkattributes then
2980 function lfs.readlink(name)
2981 return symlinkattributes(name,"target") or nil
2982 end
2983 else
2984 function lfs.readlink(name)
2985 return nil
2986 end
2987 end
2988 end
2989
2990 end -- closure
2991
2992 do -- begin closure to overcome local limits and interference
2993
2994 if not modules then modules={} end modules ['l-boolean']={
2995 version=1.001,
2996 comment="companion to luat-lib.mkiv",
2997 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
2998 copyright="PRAGMA ADE / ConTeXt Development Team",
2999 license="see context related readme files"
3000 }
3001 local type,tonumber=type,tonumber
3002 boolean=boolean or {}
3003 local boolean=boolean
3004 function boolean.tonumber(b)
3005 if b then return 1 else return 0 end
3006 end
3007 function toboolean(str,tolerant)
3008 if str==nil then
3009 return false
3010 elseif str==false then
3011 return false
3012 elseif str==true then
3013 return true
3014 elseif str=="true" then
3015 return true
3016 elseif str=="false" then
3017 return false
3018 elseif not tolerant then
3019 return false
3020 elseif str==0 then
3021 return false
3022 elseif (tonumber(str) or 0)>0 then
3023 return true
3024 else
3025 return str=="yes" or str=="on" or str=="t"
3026 end
3027 end
3028 string.toboolean=toboolean
3029 function string.booleanstring(str)
3030 if str=="0" then
3031 return false
3032 elseif str=="1" then
3033 return true
3034 elseif str=="" then
3035 return false
3036 elseif str=="false" then
3037 return false
3038 elseif str=="true" then
3039 return true
3040 elseif (tonumber(str) or 0)>0 then
3041 return true
3042 else
3043 return str=="yes" or str=="on" or str=="t"
3044 end
3045 end
3046 function string.is_boolean(str,default,strict)
3047 if type(str)=="string" then
3048 if str=="true" or str=="yes" or str=="on" or str=="t" or (not strict and str=="1") then
3049 return true
3050 elseif str=="false" or str=="no" or str=="off" or str=="f" or (not strict and str=="0") then
3051 return false
3052 end
3053 end
3054 return default
3055 end
3056
3057 end -- closure
3058
3059 do -- begin closure to overcome local limits and interference
3060
3061 if not modules then modules={} end modules ['l-math']={
3062 version=1.001,
3063 comment="companion to luat-lib.mkiv",
3064 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
3065 copyright="PRAGMA ADE / ConTeXt Development Team",
3066 license="see context related readme files"
3067 }
3068 if not math.ceiling then
3069 math.ceiling=math.ceil
3070 end
3071 if not math.round then
3072 if xmath then
3073 math.round=xmath.round
3074 else
3075 local floor=math.floor
3076 function math.round(x)
3077 return x<0 and -floor(-x+0.5) or floor(x+0.5)
3078 end
3079 end
3080 end
3081 if not math.div then
3082 local floor=math.floor
3083 function math.div(n,m) return floor(n/m) end
3084 end
3085 if not math.mod then
3086 function math.mod(n,m) return n%m end
3087 end
3088 if not math.sind then
3089 local sin,cos,tan=math.sin,math.cos,math.tan
3090 local pipi=2*math.pi/360
3091 function math.sind(d) return sin(d*pipi) end
3092 function math.cosd(d) return cos(d*pipi) end
3093 function math.tand(d) return tan(d*pipi) end
3094 end
3095 if not math.odd then
3096 function math.odd (n) return n%2~=0 end
3097 function math.even(n) return n%2==0 end
3098 end
3099 if not math.cosh then
3100 local exp=math.exp
3101 function math.cosh(x)
3102 local xx=exp(x)
3103 return (xx+1/xx)/2
3104 end
3105 function math.sinh(x)
3106 local xx=exp(x)
3107 return (xx-1/xx)/2
3108 end
3109 function math.tanh(x)
3110 local xx=exp(x)
3111 return (xx-1/xx)/(xx+1/xx)
3112 end
3113 end
3114 if not math.pow then
3115 function math.pow(x,y)
3116 return x^y
3117 end
3118 end
3119 if not math.atan2 then
3120 math.atan2=math.atan
3121 end
3122 if not math.ldexp then
3123 function math.ldexp(x,e)
3124 return x*2.0^e
3125 end
3126 end
3127 if not math.log10 then
3128 local log=math.log
3129 function math.log10(x)
3130 return log(x,10)
3131 end
3132 end
3133 if not math.type then
3134 function math.type()
3135 return "float"
3136 end
3137 end
3138 if not math.tointeger then
3139 math.mininteger=-0x4FFFFFFFFFFF
3140 math.maxinteger=0x4FFFFFFFFFFF
3141 local floor=math.floor
3142 function math.tointeger(n)
3143 local f=floor(n)
3144 return f==n and f or nil
3145 end
3146 end
3147 if not math.ult then
3148 local floor=math.floor
3149 function math.ult(m,n)
3150 return floor(m)<floor(n)
3151 end
3152 end
3153
3154 end -- closure
3155
3156 do -- begin closure to overcome local limits and interference
3157
3158 if not modules then modules={} end modules ['util-str']={
3159 version=1.001,
3160 comment="companion to luat-lib.mkiv",
3161 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
3162 copyright="PRAGMA ADE / ConTeXt Development Team",
3163 license="see context related readme files"
3164 }
3165 utilities=utilities or {}
3166 utilities.strings=utilities.strings or {}
3167 local strings=utilities.strings
3168 local format,gsub,rep,sub,find,char=string.format,string.gsub,string.rep,string.sub,string.find,string.char
3169 local load,dump=load,string.dump
3170 local tonumber,type,tostring,next,setmetatable=tonumber,type,tostring,next,setmetatable
3171 local unpack,concat=table.unpack,table.concat
3172 local P,V,C,S,R,Ct,Cs,Cp,Carg,Cc=lpeg.P,lpeg.V,lpeg.C,lpeg.S,lpeg.R,lpeg.Ct,lpeg.Cs,lpeg.Cp,lpeg.Carg,lpeg.Cc
3173 local patterns,lpegmatch=lpeg.patterns,lpeg.match
3174 local tsplitat=lpeg.tsplitat
3175 local utfchar,utfbyte,utflen=utf.char,utf.byte,utf.len
3176 local loadstripped=function(str,shortcuts)
3177 if shortcuts then
3178 return load(dump(load(str),true),nil,nil,shortcuts)
3179 else
3180 return load(dump(load(str),true))
3181 end
3182 end
3183 if not number then number={} end
3184 local stripzero=patterns.stripzero
3185 local stripzeros=patterns.stripzeros
3186 local newline=patterns.newline
3187 local endofstring=patterns.endofstring
3188 local anything=patterns.anything
3189 local whitespace=patterns.whitespace
3190 local space=patterns.space
3191 local spacer=patterns.spacer
3192 local spaceortab=patterns.spaceortab
3193 local digit=patterns.digit
3194 local sign=patterns.sign
3195 local period=patterns.period
3196 local ptf=1/65536
3197 local bpf=(7200/7227)/65536
3198 local function points(n)
3199 if n==0 then
3200 return "0pt"
3201 end
3202 n=tonumber(n)
3203 if not n or n==0 then
3204 return "0pt"
3205 end
3206 n=n*ptf
3207 if n%1==0 then
3208 return format("%ipt",n)
3209 else
3210 return lpegmatch(stripzeros,format("%.5fpt",n))
3211 end
3212 end
3213 local function nupoints(n)
3214 if n==0 then
3215 return "0"
3216 end
3217 n=tonumber(n)
3218 if not n or n==0 then
3219 return "0"
3220 end
3221 n=n*ptf
3222 if n%1==0 then
3223 return format("%i",n)
3224 else
3225 return format("%.5f",n)
3226 end
3227 end
3228 local function basepoints(n)
3229 if n==0 then
3230 return "0bp"
3231 end
3232 n=tonumber(n)
3233 if not n or n==0 then
3234 return "0bp"
3235 end
3236 n=n*bpf
3237 if n%1==0 then
3238 return format("%ibp",n)
3239 else
3240 return lpegmatch(stripzeros,format("%.5fbp",n))
3241 end
3242 end
3243 local function nubasepoints(n)
3244 if n==0 then
3245 return "0"
3246 end
3247 n=tonumber(n)
3248 if not n or n==0 then
3249 return "0"
3250 end
3251 n=n*bpf
3252 if n%1==0 then
3253 return format("%i",n)
3254 else
3255 return format("%.5f",n)
3256 end
3257 end
3258 number.points=points
3259 number.nupoints=nupoints
3260 number.basepoints=basepoints
3261 number.nubasepoints=nubasepoints
3262 local rubish=spaceortab^0*newline
3263 local anyrubish=spaceortab+newline
3264 local stripped=(spaceortab^1/"")*newline
3265 local leading=rubish^0/""
3266 local trailing=(anyrubish^1*endofstring)/""
3267 local redundant=rubish^3/"\n"
3268 local pattern=Cs(leading*(trailing+redundant+stripped+anything)^0)
3269 function strings.collapsecrlf(str)
3270 return lpegmatch(pattern,str)
3271 end
3272 local repeaters={}
3273 function strings.newrepeater(str,offset)
3274 offset=offset or 0
3275 local s=repeaters[str]
3276 if not s then
3277 s={}
3278 repeaters[str]=s
3279 end
3280 local t=s[offset]
3281 if t then
3282 return t
3283 end
3284 t={}
3285 setmetatable(t,{ __index=function(t,k)
3286 if not k then
3287 return ""
3288 end
3289 local n=k+offset
3290 local s=n>0 and rep(str,n) or ""
3291 t[k]=s
3292 return s
3293 end })
3294 s[offset]=t
3295 return t
3296 end
3297 local extra,tab,start=0,0,4,0
3298 local nspaces=strings.newrepeater(" ")
3299 string.nspaces=nspaces
3300 local pattern=Carg(1)/function(t)
3301 extra,tab,start=0,t or 7,1
3302 end*Cs((
3303 Cp()*patterns.tab/function(position)
3304 local current=(position-start+1)+extra
3305 local spaces=tab-(current-1)%tab
3306 if spaces>0 then
3307 extra=extra+spaces-1
3308 return nspaces[spaces]
3309 else
3310 return ""
3311 end
3312 end+newline*Cp()/function(position)
3313 extra,start=0,position
3314 end+anything
3315 )^1)
3316 function strings.tabtospace(str,tab)
3317 return lpegmatch(pattern,str,1,tab or 7)
3318 end
3319 function string.utfpadding(s,n)
3320 if not n or n==0 then
3321 return ""
3322 end
3323 local l=utflen(s)
3324 if n>0 then
3325 return nspaces[n-l]
3326 else
3327 return nspaces[-n-l]
3328 end
3329 end
3330 local optionalspace=spacer^0
3331 local nospace=optionalspace/""
3332 local endofline=nospace*newline
3333 local stripend=(whitespace^1*endofstring)/""
3334 local normalline=(nospace*((1-optionalspace*(newline+endofstring))^1)*nospace)
3335 local stripempty=endofline^1/""
3336 local normalempty=endofline^1
3337 local singleempty=endofline*(endofline^0/"")
3338 local doubleempty=endofline*endofline^-1*(endofline^0/"")
3339 local stripstart=stripempty^0
3340 local intospace=whitespace^1/" "
3341 local noleading=whitespace^1/""
3342 local notrailing=noleading*endofstring
3343 local p_prune_normal=Cs (stripstart*(stripend+normalline+normalempty )^0 )
3344 local p_prune_collapse=Cs (stripstart*(stripend+normalline+doubleempty )^0 )
3345 local p_prune_noempty=Cs (stripstart*(stripend+normalline+singleempty )^0 )
3346 local p_prune_intospace=Cs (noleading*(notrailing+intospace+1 )^0 )
3347 local p_retain_normal=Cs ((normalline+normalempty )^0 )
3348 local p_retain_collapse=Cs ((normalline+doubleempty )^0 )
3349 local p_retain_noempty=Cs ((normalline+singleempty )^0 )
3350 local p_collapse_all=Cs (stripstart*(stripend+((whitespace+newline)^1/" ")+1)^0 )
3351 local striplinepatterns={
3352 ["prune"]=p_prune_normal,
3353 ["prune and collapse"]=p_prune_collapse,
3354 ["prune and no empty"]=p_prune_noempty,
3355 ["prune and to space"]=p_prune_intospace,
3356 ["retain"]=p_retain_normal,
3357 ["retain and collapse"]=p_retain_collapse,
3358 ["retain and no empty"]=p_retain_noempty,
3359 ["collapse all"]=p_collapse_all,
3360 ["collapse"]=patterns.collapser,
3361 }
3362 setmetatable(striplinepatterns,{ __index=function(t,k) return p_prune_collapse end })
3363 strings.striplinepatterns=striplinepatterns
3364 function strings.striplines(str,how)
3365 return str and lpegmatch(striplinepatterns[how],str) or str
3366 end
3367 function strings.collapse(str)
3368 return str and lpegmatch(p_prune_intospace,str) or str
3369 end
3370 strings.striplong=strings.striplines
3371 function strings.nice(str)
3372 str=gsub(str,"[:%-+_]+"," ")
3373 return str
3374 end
3375 local n=0
3376 local sequenced=table.sequenced
3377 function string.autodouble(s,sep)
3378 if s==nil then
3379 return '""'
3380 end
3381 local t=type(s)
3382 if t=="number" then
3383 return tostring(s)
3384 end
3385 if t=="table" then
3386 return ('"'..sequenced(s,sep or ",")..'"')
3387 end
3388 return ('"'..tostring(s)..'"')
3389 end
3390 function string.autosingle(s,sep)
3391 if s==nil then
3392 return "''"
3393 end
3394 local t=type(s)
3395 if t=="number" then
3396 return tostring(s)
3397 end
3398 if t=="table" then
3399 return ("'"..sequenced(s,sep or ",").."'")
3400 end
3401 return ("'"..tostring(s).."'")
3402 end
3403 local tracedchars={ [0]=
3404 "[null]","[soh]","[stx]","[etx]","[eot]","[enq]","[ack]","[bel]",
3405 "[bs]","[ht]","[lf]","[vt]","[ff]","[cr]","[so]","[si]",
3406 "[dle]","[dc1]","[dc2]","[dc3]","[dc4]","[nak]","[syn]","[etb]",
3407 "[can]","[em]","[sub]","[esc]","[fs]","[gs]","[rs]","[us]",
3408 "[space]",
3409 }
3410 string.tracedchars=tracedchars
3411 strings.tracers=tracedchars
3412 function string.tracedchar(b)
3413 if type(b)=="number" then
3414 return tracedchars[b] or (utfchar(b).." (U+"..format("%05X",b)..")")
3415 else
3416 local c=utfbyte(b)
3417 return tracedchars[c] or (b.." (U+"..(c and format("%05X",c) or "?????")..")")
3418 end
3419 end
3420 function number.signed(i)
3421 if i>0 then
3422 return "+",i
3423 else
3424 return "-",-i
3425 end
3426 end
3427 local two=digit*digit
3428 local three=two*digit
3429 local prefix=(Carg(1)*three)^1
3430 local splitter=Cs (
3431 (((1-(three^1*period))^1+C(three))*prefix+C((1-period)^1))*(anything/""*Carg(2))*C(2)
3432 )
3433 local splitter3=Cs (
3434 three*prefix*endofstring+two*prefix*endofstring+digit*prefix*endofstring+three+two+digit
3435 )
3436 patterns.formattednumber=splitter
3437 function number.formatted(n,sep1,sep2)
3438 if sep1==false then
3439 if type(n)=="number" then
3440 n=tostring(n)
3441 end
3442 return lpegmatch(splitter3,n,1,sep2 or ".")
3443 else
3444 if type(n)=="number" then
3445 n=format("%0.2f",n)
3446 end
3447 if sep1==true then
3448 return lpegmatch(splitter,n,1,".",",")
3449 elseif sep1=="." then
3450 return lpegmatch(splitter,n,1,sep1,sep2 or ",")
3451 elseif sep1=="," then
3452 return lpegmatch(splitter,n,1,sep1,sep2 or ".")
3453 else
3454 return lpegmatch(splitter,n,1,sep1 or ",",sep2 or ".")
3455 end
3456 end
3457 end
3458 local p=Cs(
3459 P("-")^0*(P("0")^1/"")^0*(1-period)^0*(period*P("0")^1*endofstring/""+period^0)*P(1-P("0")^1*endofstring)^0
3460 )
3461 function number.compactfloat(n,fmt)
3462 if n==0 then
3463 return "0"
3464 elseif n==1 then
3465 return "1"
3466 end
3467 n=lpegmatch(p,format(fmt or "%0.3f",n))
3468 if n=="." or n=="" or n=="-" then
3469 return "0"
3470 end
3471 return n
3472 end
3473 local zero=P("0")^1/""
3474 local plus=P("+")/""
3475 local minus=P("-")
3476 local separator=period
3477 local trailing=zero^1*#S("eE")
3478 local exponent=(S("eE")*(plus+Cs((minus*zero^0*endofstring)/"")+minus)*zero^0*(endofstring*Cc("0")+anything^1))
3479 local pattern_a=Cs(minus^0*digit^1*(separator/""*trailing+separator*(trailing+digit)^0)*exponent)
3480 local pattern_b=Cs((exponent+anything)^0)
3481 function number.sparseexponent(f,n)
3482 if not n then
3483 n=f
3484 f="%e"
3485 end
3486 local tn=type(n)
3487 if tn=="string" then
3488 local m=tonumber(n)
3489 if m then
3490 return lpegmatch((f=="%e" or f=="%E") and pattern_a or pattern_b,format(f,m))
3491 end
3492 elseif tn=="number" then
3493 return lpegmatch((f=="%e" or f=="%E") and pattern_a or pattern_b,format(f,n))
3494 end
3495 return tostring(n)
3496 end
3497 local hf={}
3498 local hs={}
3499 setmetatable(hf,{ __index=function(t,k)
3500 local v="%."..k.."f"
3501 t[k]=v
3502 return v
3503 end } )
3504 setmetatable(hs,{ __index=function(t,k)
3505 local v="%"..k.."s"
3506 t[k]=v
3507 return v
3508 end } )
3509 function number.formattedfloat(n,b,a)
3510 local s=format(hf[a],n)
3511 local l=(b or 0)+(a or 0)+1
3512 if #s<l then
3513 return format(hs[l],s)
3514 else
3515 return s
3516 end
3517 end
3518 local template=[[
3519 %s
3520 %s
3521 return function(%s) return %s end
3522 ]]
3523 local pattern=Cs(Cc('"')*(
3524 (1-S('"\\\n\r'))^1+P('"')/'\\"'+P('\\')/'\\\\'+P('\n')/'\\n'+P('\r')/'\\r'
3525 )^0*Cc('"'))
3526 patterns.escapedquotes=pattern
3527 function string.escapedquotes(s)
3528 return lpegmatch(pattern,s)
3529 end
3530 local pattern=(1-P("\\"))^1;pattern=Cs (
3531 pattern*((P("\\")/""*(digit^-3/function(s) return char(tonumber(s)) end))+pattern )^1
3532 )
3533 patterns.unescapedquotes=pattern
3534 function string.unescapedquotes(s)
3535 return lpegmatch(pattern,s) or s
3536 end
3537 string.texnewlines=lpeg.replacer(patterns.newline,"\r",true)
3538 local preamble=""
3539 local environment={
3540 global=global or _G,
3541 lpeg=lpeg,
3542 type=type,
3543 tostring=tostring,
3544 tonumber=tonumber,
3545 format=string.format,
3546 concat=table.concat,
3547 signed=number.signed,
3548 points=number.points,
3549 nupoints=number.nupoints,
3550 basepoints=number.basepoints,
3551 nubasepoints=number.nubasepoints,
3552 utfchar=utf.char,
3553 utfbyte=utf.byte,
3554 lpegmatch=lpeg.match,
3555 nspaces=string.nspaces,
3556 utfpadding=string.utfpadding,
3557 tracedchar=string.tracedchar,
3558 autosingle=string.autosingle,
3559 autodouble=string.autodouble,
3560 sequenced=table.sequenced,
3561 formattednumber=number.formatted,
3562 sparseexponent=number.sparseexponent,
3563 formattedfloat=number.formattedfloat,
3564 stripzero=patterns.stripzero,
3565 stripzeros=patterns.stripzeros,
3566 escapedquotes=string.escapedquotes,
3567 FORMAT=string.f6,
3568 }
3569 local arguments={ "a1" }
3570 setmetatable(arguments,{ __index=function(t,k)
3571 local v=t[k-1]..",a"..k
3572 t[k]=v
3573 return v
3574 end
3575 })
3576 local prefix_any=C((sign+space+period+digit)^0)
3577 local prefix_sub=(C((sign+digit)^0)+Cc(0))*period*(C((sign+digit)^0)+Cc(0))
3578 local prefix_tab=P("{")*C((1-P("}"))^0)*P("}")+C((1-R("az","AZ","09","%%"))^0)
3579 local format_s=function(f)
3580 n=n+1
3581 if f and f~="" then
3582 return format("format('%%%ss',a%s)",f,n)
3583 else
3584 return format("(a%s or '')",n)
3585 end
3586 end
3587 local format_S=function(f)
3588 n=n+1
3589 if f and f~="" then
3590 return format("format('%%%ss',tostring(a%s))",f,n)
3591 else
3592 return format("tostring(a%s)",n)
3593 end
3594 end
3595 local format_right=function(f)
3596 n=n+1
3597 f=tonumber(f)
3598 if not f or f==0 then
3599 return format("(a%s or '')",n)
3600 elseif f>0 then
3601 return format("utfpadding(a%s,%i)..a%s",n,f,n)
3602 else
3603 return format("a%s..utfpadding(a%s,%i)",n,n,f)
3604 end
3605 end
3606 local format_left=function(f)
3607 n=n+1
3608 f=tonumber(f)
3609 if not f or f==0 then
3610 return format("(a%s or '')",n)
3611 end
3612 if f<0 then
3613 return format("utfpadding(a%s,%i)..a%s",n,-f,n)
3614 else
3615 return format("a%s..utfpadding(a%s,%i)",n,n,-f)
3616 end
3617 end
3618 local format_q=JITSUPPORTED and function()
3619 n=n+1
3620 return format("(a%s ~= nil and format('%%q',tostring(a%s)) or '')",n,n)
3621 end or function()
3622 n=n+1
3623 return format("(a%s ~= nil and format('%%q',a%s) or '')",n,n)
3624 end
3625 local format_Q=function()
3626 n=n+1
3627 return format("escapedquotes(tostring(a%s))",n)
3628 end
3629 local format_i=function(f)
3630 n=n+1
3631 if f and f~="" then
3632 return format("format('%%%si',a%s)",f,n)
3633 else
3634 return format("format('%%i',a%s)",n)
3635 end
3636 end
3637 local format_d=format_i
3638 local format_I=function(f)
3639 n=n+1
3640 return format("format('%%s%%%si',signed(a%s))",f,n)
3641 end
3642 local format_f=function(f)
3643 n=n+1
3644 return format("format('%%%sf',a%s)",f,n)
3645 end
3646 local format_F=function(f)
3647 n=n+1
3648 if not f or f=="" then
3649 return format("(((a%s > -0.0000000005 and a%s < 0.0000000005) and '0') or format((a%s %% 1 == 0) and '%%i' or '%%.9f',a%s))",n,n,n,n)
3650 else
3651 return format("format((a%s %% 1 == 0) and '%%i' or '%%%sf',a%s)",n,f,n)
3652 end
3653 end
3654 local format_k=function(b,a)
3655 n=n+1
3656 return format("formattedfloat(a%s,%s,%s)",n,b or 0,a or 0)
3657 end
3658 local format_g=function(f)
3659 n=n+1
3660 return format("format('%%%sg',a%s)",f,n)
3661 end
3662 local format_G=function(f)
3663 n=n+1
3664 return format("format('%%%sG',a%s)",f,n)
3665 end
3666 local format_e=function(f)
3667 n=n+1
3668 return format("format('%%%se',a%s)",f,n)
3669 end
3670 local format_E=function(f)
3671 n=n+1
3672 return format("format('%%%sE',a%s)",f,n)
3673 end
3674 local format_j=function(f)
3675 n=n+1
3676 return format("sparseexponent('%%%se',a%s)",f,n)
3677 end
3678 local format_J=function(f)
3679 n=n+1
3680 return format("sparseexponent('%%%sE',a%s)",f,n)
3681 end
3682 local format_x=function(f)
3683 n=n+1
3684 return format("format('%%%sx',a%s)",f,n)
3685 end
3686 local format_X=function(f)
3687 n=n+1
3688 return format("format('%%%sX',a%s)",f,n)
3689 end
3690 local format_o=function(f)
3691 n=n+1
3692 return format("format('%%%so',a%s)",f,n)
3693 end
3694 local format_c=function()
3695 n=n+1
3696 return format("utfchar(a%s)",n)
3697 end
3698 local format_C=function()
3699 n=n+1
3700 return format("tracedchar(a%s)",n)
3701 end
3702 local format_r=function(f)
3703 n=n+1
3704 return format("format('%%%s.0f',a%s)",f,n)
3705 end
3706 local format_h=function(f)
3707 n=n+1
3708 if f=="-" then
3709 f=sub(f,2)
3710 return format("format('%%%sx',type(a%s) == 'number' and a%s or utfbyte(a%s))",f=="" and "05" or f,n,n,n)
3711 else
3712 return format("format('0x%%%sx',type(a%s) == 'number' and a%s or utfbyte(a%s))",f=="" and "05" or f,n,n,n)
3713 end
3714 end
3715 local format_H=function(f)
3716 n=n+1
3717 if f=="-" then
3718 f=sub(f,2)
3719 return format("format('%%%sX',type(a%s) == 'number' and a%s or utfbyte(a%s))",f=="" and "05" or f,n,n,n)
3720 else
3721 return format("format('0x%%%sX',type(a%s) == 'number' and a%s or utfbyte(a%s))",f=="" and "05" or f,n,n,n)
3722 end
3723 end
3724 local format_u=function(f)
3725 n=n+1
3726 if f=="-" then
3727 f=sub(f,2)
3728 return format("format('%%%sx',type(a%s) == 'number' and a%s or utfbyte(a%s))",f=="" and "05" or f,n,n,n)
3729 else
3730 return format("format('u+%%%sx',type(a%s) == 'number' and a%s or utfbyte(a%s))",f=="" and "05" or f,n,n,n)
3731 end
3732 end
3733 local format_U=function(f)
3734 n=n+1
3735 if f=="-" then
3736 f=sub(f,2)
3737 return format("format('%%%sX',type(a%s) == 'number' and a%s or utfbyte(a%s))",f=="" and "05" or f,n,n,n)
3738 else
3739 return format("format('U+%%%sX',type(a%s) == 'number' and a%s or utfbyte(a%s))",f=="" and "05" or f,n,n,n)
3740 end
3741 end
3742 local format_p=function()
3743 n=n+1
3744 return format("points(a%s)",n)
3745 end
3746 local format_P=function()
3747 n=n+1
3748 return format("nupoints(a%s)",n)
3749 end
3750 local format_b=function()
3751 n=n+1
3752 return format("basepoints(a%s)",n)
3753 end
3754 local format_B=function()
3755 n=n+1
3756 return format("nubasepoints(a%s)",n)
3757 end
3758 local format_t=function(f)
3759 n=n+1
3760 if f and f~="" then
3761 return format("concat(a%s,%q)",n,f)
3762 else
3763 return format("concat(a%s)",n)
3764 end
3765 end
3766 local format_T=function(f)
3767 n=n+1
3768 if f and f~="" then
3769 return format("sequenced(a%s,%q)",n,f)
3770 else
3771 return format("sequenced(a%s)",n)
3772 end
3773 end
3774 local format_l=function()
3775 n=n+1
3776 return format("(a%s and 'true' or 'false')",n)
3777 end
3778 local format_L=function()
3779 n=n+1
3780 return format("(a%s and 'TRUE' or 'FALSE')",n)
3781 end
3782 local format_n=function()
3783 n=n+1
3784 return format("((a%s %% 1 == 0) and format('%%i',a%s) or tostring(a%s))",n,n,n)
3785 end
3786 local format_N if environment.FORMAT then
3787 format_N=function(f)
3788 n=n+1
3789 if not f or f=="" then
3790 return format("FORMAT(a%s,'%%.9f')",n)
3791 elseif f==".6" or f=="0.6" then
3792 return format("FORMAT(a%s)",n)
3793 else
3794 return format("FORMAT(a%s,'%%%sf')",n,f)
3795 end
3796 end
3797 else
3798 format_N=function(f)
3799 n=n+1
3800 if not f or f=="" then
3801 f=".9"
3802 end
3803 return format("(((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripzero,format('%%%sf',a%s)))",n,n,f,n)
3804 end
3805 end
3806 local format_a=function(f)
3807 n=n+1
3808 if f and f~="" then
3809 return format("autosingle(a%s,%q)",n,f)
3810 else
3811 return format("autosingle(a%s)",n)
3812 end
3813 end
3814 local format_A=function(f)
3815 n=n+1
3816 if f and f~="" then
3817 return format("autodouble(a%s,%q)",n,f)
3818 else
3819 return format("autodouble(a%s)",n)
3820 end
3821 end
3822 local format_w=function(f)
3823 n=n+1
3824 f=tonumber(f)
3825 if f then
3826 return format("nspaces[%s+a%s]",f,n)
3827 else
3828 return format("nspaces[a%s]",n)
3829 end
3830 end
3831 local format_W=function(f)
3832 return format("nspaces[%s]",tonumber(f) or 0)
3833 end
3834 local format_m=function(f)
3835 n=n+1
3836 if not f or f=="" then
3837 f=","
3838 end
3839 if f=="0" then
3840 return format([[formattednumber(a%s,false)]],n)
3841 else
3842 return format([[formattednumber(a%s,%q,".")]],n,f)
3843 end
3844 end
3845 local format_M=function(f)
3846 n=n+1
3847 if not f or f=="" then
3848 f="."
3849 end
3850 if f=="0" then
3851 return format([[formattednumber(a%s,false)]],n)
3852 else
3853 return format([[formattednumber(a%s,%q,",")]],n,f)
3854 end
3855 end
3856 local format_z=function(f)
3857 n=n+(tonumber(f) or 1)
3858 return "''"
3859 end
3860 local format_rest=function(s)
3861 return format("%q",s)
3862 end
3863 local format_extension=function(extensions,f,name)
3864 local extension=extensions[name] or "tostring(%s)"
3865 local f=tonumber(f) or 1
3866 local w=find(extension,"%.%.%.")
3867 if f==0 then
3868 if w then
3869 extension=gsub(extension,"%.%.%.","")
3870 end
3871 return extension
3872 elseif f==1 then
3873 if w then
3874 extension=gsub(extension,"%.%.%.","%%s")
3875 end
3876 n=n+1
3877 local a="a"..n
3878 return format(extension,a,a)
3879 elseif f<0 then
3880 if w then
3881 extension=gsub(extension,"%.%.%.","")
3882 return extension
3883 else
3884 local a="a"..(n+f+1)
3885 return format(extension,a,a)
3886 end
3887 else
3888 if w then
3889 extension=gsub(extension,"%.%.%.",rep("%%s,",f-1).."%%s")
3890 end
3891 local t={}
3892 for i=1,f do
3893 n=n+1
3894 t[i]="a"..n
3895 end
3896 return format(extension,unpack(t))
3897 end
3898 end
3899 local builder=Cs { "start",
3900 start=(
3901 (
3902 P("%")/""*(
3903 V("!")
3904 +V("s")+V("q")+V("i")+V("d")+V("f")+V("F")+V("g")+V("G")+V("e")+V("E")+V("x")+V("X")+V("o")
3905 +V("c")+V("C")+V("S")
3906 +V("Q")
3907 +V("n")
3908 +V("N")
3909 +V("k")
3910 +V("r")+V("h")+V("H")+V("u")+V("U")+V("p")+V("P")+V("b")+V("B")+V("t")+V("T")+V("l")+V("L")+V("I")+V("w")
3911 +V("W")
3912 +V("a")
3913 +V("A")
3914 +V("j")+V("J")
3915 +V("m")+V("M")
3916 +V("z")
3917 +V(">")
3918 +V("<")
3919 )+V("*")
3920 )*(endofstring+Carg(1))
3921 )^0,
3922 ["s"]=(prefix_any*P("s"))/format_s,
3923 ["q"]=(prefix_any*P("q"))/format_q,
3924 ["i"]=(prefix_any*P("i"))/format_i,
3925 ["d"]=(prefix_any*P("d"))/format_d,
3926 ["f"]=(prefix_any*P("f"))/format_f,
3927 ["F"]=(prefix_any*P("F"))/format_F,
3928 ["g"]=(prefix_any*P("g"))/format_g,
3929 ["G"]=(prefix_any*P("G"))/format_G,
3930 ["e"]=(prefix_any*P("e"))/format_e,
3931 ["E"]=(prefix_any*P("E"))/format_E,
3932 ["x"]=(prefix_any*P("x"))/format_x,
3933 ["X"]=(prefix_any*P("X"))/format_X,
3934 ["o"]=(prefix_any*P("o"))/format_o,
3935 ["S"]=(prefix_any*P("S"))/format_S,
3936 ["Q"]=(prefix_any*P("Q"))/format_Q,
3937 ["n"]=(prefix_any*P("n"))/format_n,
3938 ["N"]=(prefix_any*P("N"))/format_N,
3939 ["k"]=(prefix_sub*P("k"))/format_k,
3940 ["c"]=(prefix_any*P("c"))/format_c,
3941 ["C"]=(prefix_any*P("C"))/format_C,
3942 ["r"]=(prefix_any*P("r"))/format_r,
3943 ["h"]=(prefix_any*P("h"))/format_h,
3944 ["H"]=(prefix_any*P("H"))/format_H,
3945 ["u"]=(prefix_any*P("u"))/format_u,
3946 ["U"]=(prefix_any*P("U"))/format_U,
3947 ["p"]=(prefix_any*P("p"))/format_p,
3948 ["P"]=(prefix_any*P("P"))/format_P,
3949 ["b"]=(prefix_any*P("b"))/format_b,
3950 ["B"]=(prefix_any*P("B"))/format_B,
3951 ["t"]=(prefix_tab*P("t"))/format_t,
3952 ["T"]=(prefix_tab*P("T"))/format_T,
3953 ["l"]=(prefix_any*P("l"))/format_l,
3954 ["L"]=(prefix_any*P("L"))/format_L,
3955 ["I"]=(prefix_any*P("I"))/format_I,
3956 ["w"]=(prefix_any*P("w"))/format_w,
3957 ["W"]=(prefix_any*P("W"))/format_W,
3958 ["j"]=(prefix_any*P("j"))/format_j,
3959 ["J"]=(prefix_any*P("J"))/format_J,
3960 ["m"]=(prefix_any*P("m"))/format_m,
3961 ["M"]=(prefix_any*P("M"))/format_M,
3962 ["z"]=(prefix_any*P("z"))/format_z,
3963 ["a"]=(prefix_any*P("a"))/format_a,
3964 ["A"]=(prefix_any*P("A"))/format_A,
3965 ["<"]=(prefix_any*P("<"))/format_left,
3966 [">"]=(prefix_any*P(">"))/format_right,
3967 ["*"]=Cs(((1-P("%"))^1+P("%%")/"%%")^1)/format_rest,
3968 ["?"]=Cs(((1-P("%"))^1 )^1)/format_rest,
3969 ["!"]=Carg(2)*prefix_any*P("!")*C((1-P("!"))^1)*P("!")/format_extension,
3970 }
3971 local xx=setmetatable({},{ __index=function(t,k) local v=format("%02x",k) t[k]=v return v end })
3972 local XX=setmetatable({},{ __index=function(t,k) local v=format("%02X",k) t[k]=v return v end })
3973 local preset={
3974 ["%02x"]=function(n) return xx[n] end,
3975 ["%02X"]=function(n) return XX[n] end,
3976 }
3977 local direct=P("%")*(sign+space+period+digit)^0*S("sqidfgGeExXo")*endofstring/[[local format = string.format return function(str) return format("%0",str) end]]
3978 local function make(t,str)
3979 local f=preset[str]
3980 if f then
3981 return f
3982 end
3983 local p=lpegmatch(direct,str)
3984 if p then
3985 f=loadstripped(p)()
3986 else
3987 n=0
3988 p=lpegmatch(builder,str,1,t._connector_,t._extensions_)
3989 if n>0 then
3990 p=format(template,preamble,t._preamble_,arguments[n],p)
3991 f=loadstripped(p,t._environment_)()
3992 else
3993 f=function() return str end
3994 end
3995 end
3996 t[str]=f
3997 return f
3998 end
3999 local function use(t,fmt,...)
4000 return t[fmt](...)
4001 end
4002 strings.formatters={}
4003 function strings.formatters.new(noconcat)
4004 local e={}
4005 for k,v in next,environment do
4006 e[k]=v
4007 end
4008 local t={
4009 _type_="formatter",
4010 _connector_=noconcat and "," or "..",
4011 _extensions_={},
4012 _preamble_="",
4013 _environment_=e,
4014 }
4015 setmetatable(t,{ __index=make,__call=use })
4016 return t
4017 end
4018 local formatters=strings.formatters.new()
4019 string.formatters=formatters
4020 string.formatter=function(str,...) return formatters[str](...) end
4021 local function add(t,name,template,preamble)
4022 if type(t)=="table" and t._type_=="formatter" then
4023 t._extensions_[name]=template or "%s"
4024 if type(preamble)=="string" then
4025 t._preamble_=preamble.."\n"..t._preamble_
4026 elseif type(preamble)=="table" then
4027 for k,v in next,preamble do
4028 t._environment_[k]=v
4029 end
4030 end
4031 end
4032 end
4033 strings.formatters.add=add
4034 patterns.xmlescape=Cs((P("<")/"&lt;"+P(">")/"&gt;"+P("&")/"&amp;"+P('"')/"&quot;"+anything)^0)
4035 patterns.texescape=Cs((C(S("#$%\\{}"))/"\\%1"+anything)^0)
4036 patterns.luaescape=Cs(((1-S('"\n'))^1+P('"')/'\\"'+P('\n')/'\\n"')^0)
4037 patterns.luaquoted=Cs(Cc('"')*((1-S('"\n'))^1+P('"')/'\\"'+P('\n')/'\\n"')^0*Cc('"'))
4038 add(formatters,"xml",[[lpegmatch(xmlescape,%s)]],{ xmlescape=patterns.xmlescape })
4039 add(formatters,"tex",[[lpegmatch(texescape,%s)]],{ texescape=patterns.texescape })
4040 add(formatters,"lua",[[lpegmatch(luaescape,%s)]],{ luaescape=patterns.luaescape })
4041 local dquote=patterns.dquote
4042 local equote=patterns.escaped+dquote/'\\"'+1
4043 local cquote=Cc('"')
4044 local pattern=Cs(dquote*(equote-P(-2))^0*dquote)
4045 +Cs(cquote*(equote-space)^0*space*equote^0*cquote)
4046 function string.optionalquoted(str)
4047 return lpegmatch(pattern,str) or str
4048 end
4049 local pattern=Cs((newline/(os.newline or "\r")+1)^0)
4050 function string.replacenewlines(str)
4051 return lpegmatch(pattern,str)
4052 end
4053 function strings.newcollector()
4054 local result,r={},0
4055 return
4056 function(fmt,str,...)
4057 r=r+1
4058 result[r]=str==nil and fmt or formatters[fmt](str,...)
4059 end,
4060 function(connector)
4061 if result then
4062 local str=concat(result,connector)
4063 result,r={},0
4064 return str
4065 end
4066 end
4067 end
4068 local f_16_16=formatters["%0.5N"]
4069 function number.to16dot16(n)
4070 return f_16_16(n/65536.0)
4071 end
4072 if not string.explode then
4073 local p_utf=patterns.utf8character
4074 local p_check=C(p_utf)*(P("+")*Cc(true))^0
4075 local p_split=Ct(C(p_utf)^0)
4076 local p_space=Ct((C(1-P(" ")^1)+P(" ")^1)^0)
4077 function string.explode(str,symbol)
4078 if symbol=="" then
4079 return lpegmatch(p_split,str)
4080 elseif symbol then
4081 local a,b=lpegmatch(p_check,symbol)
4082 if b then
4083 return lpegmatch(tsplitat(P(a)^1),str)
4084 else
4085 return lpegmatch(tsplitat(a),str)
4086 end
4087 else
4088 return lpegmatch(p_space,str)
4089 end
4090 end
4091 end
4092 do
4093 local p_whitespace=patterns.whitespace^1
4094 local cache=setmetatable({},{ __index=function(t,k)
4095 local p=tsplitat(p_whitespace*P(k)*p_whitespace)
4096 local v=function(s)
4097 return lpegmatch(p,s)
4098 end
4099 t[k]=v
4100 return v
4101 end })
4102 function string.wordsplitter(s)
4103 return cache[s]
4104 end
4105 end
4106 if CONTEXTLMTXMODE and CONTEXTLMTXMODE>0 then
4107 local t={
4108 ["#"]="#H",
4109 ["\n"]="#L",
4110 ['"']="#Q",
4111 ["\r"]="#R",
4112 [" "]="#S",
4113 ["\t"]="#T",
4114 ["\\"]="#X",
4115 }
4116 function string.texhashed(s)
4117 return (gsub(s,".",t))
4118 end
4119 end
4120
4121 end -- closure
4122
4123 do -- begin closure to overcome local limits and interference
4124
4125 if not modules then modules={} end modules ['util-fil']={
4126 version=1.001,
4127 optimize=true,
4128 comment="companion to luat-lib.mkiv",
4129 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
4130 copyright="PRAGMA ADE / ConTeXt Development Team",
4131 license="see context related readme files"
4132 }
4133 local tonumber=tonumber
4134 local byte=string.byte
4135 local char=string.char
4136 utilities=utilities or {}
4137 local files={}
4138 utilities.files=files
4139 local zerobased={}
4140 function files.open(filename,zb)
4141 local f=io.open(filename,"rb")
4142 if f then
4143 zerobased[f]=zb or false
4144 end
4145 return f
4146 end
4147 function files.close(f)
4148 zerobased[f]=nil
4149 f:close()
4150 end
4151 function files.size(f)
4152 local current=f:seek()
4153 local size=f:seek("end")
4154 f:seek("set",current)
4155 return size
4156 end
4157 files.getsize=files.size
4158 function files.setposition(f,n)
4159 if zerobased[f] then
4160 f:seek("set",n)
4161 else
4162 f:seek("set",n-1)
4163 end
4164 end
4165 function files.getposition(f)
4166 if zerobased[f] then
4167 return f:seek()
4168 else
4169 return f:seek()+1
4170 end
4171 end
4172 function files.look(f,n,chars)
4173 local p=f:seek()
4174 local s=f:read(n)
4175 f:seek("set",p)
4176 if chars then
4177 return s
4178 else
4179 return byte(s,1,#s)
4180 end
4181 end
4182 function files.skip(f,n)
4183 if n==1 then
4184 f:read(n)
4185 else
4186 f:seek("set",f:seek()+n)
4187 end
4188 end
4189 function files.readbyte(f)
4190 return byte(f:read(1))
4191 end
4192 function files.readbytes(f,n)
4193 return byte(f:read(n),1,n)
4194 end
4195 function files.readbytetable(f,n)
4196 local s=f:read(n or 1)
4197 return { byte(s,1,#s) }
4198 end
4199 function files.readchar(f)
4200 return f:read(1)
4201 end
4202 function files.readstring(f,n)
4203 return f:read(n or 1)
4204 end
4205 function files.readinteger1(f)
4206 local n=byte(f:read(1))
4207 if n>=0x80 then
4208 return n-0x100
4209 else
4210 return n
4211 end
4212 end
4213 files.readcardinal1=files.readbyte
4214 files.readcardinal=files.readcardinal1
4215 files.readinteger=files.readinteger1
4216 files.readsignedbyte=files.readinteger1
4217 function files.readcardinal2(f)
4218 local a,b=byte(f:read(2),1,2)
4219 return 0x100*a+b
4220 end
4221 function files.readcardinal2le(f)
4222 local b,a=byte(f:read(2),1,2)
4223 return 0x100*a+b
4224 end
4225 function files.readinteger2(f)
4226 local a,b=byte(f:read(2),1,2)
4227 if a>=0x80 then
4228 return 0x100*a+b-0x10000
4229 else
4230 return 0x100*a+b
4231 end
4232 end
4233 function files.readinteger2le(f)
4234 local b,a=byte(f:read(2),1,2)
4235 if a>=0x80 then
4236 return 0x100*a+b-0x10000
4237 else
4238 return 0x100*a+b
4239 end
4240 end
4241 function files.readcardinal3(f)
4242 local a,b,c=byte(f:read(3),1,3)
4243 return 0x10000*a+0x100*b+c
4244 end
4245 function files.readcardinal3le(f)
4246 local c,b,a=byte(f:read(3),1,3)
4247 return 0x10000*a+0x100*b+c
4248 end
4249 function files.readinteger3(f)
4250 local a,b,c=byte(f:read(3),1,3)
4251 if a>=0x80 then
4252 return 0x10000*a+0x100*b+c-0x1000000
4253 else
4254 return 0x10000*a+0x100*b+c
4255 end
4256 end
4257 function files.readinteger3le(f)
4258 local c,b,a=byte(f:read(3),1,3)
4259 if a>=0x80 then
4260 return 0x10000*a+0x100*b+c-0x1000000
4261 else
4262 return 0x10000*a+0x100*b+c
4263 end
4264 end
4265 function files.readcardinal4(f)
4266 local a,b,c,d=byte(f:read(4),1,4)
4267 return 0x1000000*a+0x10000*b+0x100*c+d
4268 end
4269 function files.readcardinal4le(f)
4270 local d,c,b,a=byte(f:read(4),1,4)
4271 return 0x1000000*a+0x10000*b+0x100*c+d
4272 end
4273 function files.readinteger4(f)
4274 local a,b,c,d=byte(f:read(4),1,4)
4275 if a>=0x80 then
4276 return 0x1000000*a+0x10000*b+0x100*c+d-0x100000000
4277 else
4278 return 0x1000000*a+0x10000*b+0x100*c+d
4279 end
4280 end
4281 function files.readinteger4le(f)
4282 local d,c,b,a=byte(f:read(4),1,4)
4283 if a>=0x80 then
4284 return 0x1000000*a+0x10000*b+0x100*c+d-0x100000000
4285 else
4286 return 0x1000000*a+0x10000*b+0x100*c+d
4287 end
4288 end
4289 function files.readfixed2(f)
4290 local n1,n2=byte(f:read(2),1,2)
4291 if n1>=0x80 then
4292 n1=n1-0x100
4293 end
4294 return n1+n2/0xFF
4295 end
4296 function files.readfixed4(f)
4297 local a,b,c,d=byte(f:read(4),1,4)
4298 local n1=0x100*a+b
4299 local n2=0x100*c+d
4300 if n1>=0x8000 then
4301 n1=n1-0x10000
4302 end
4303 return n1+n2/0xFFFF
4304 end
4305 if bit32 then
4306 local extract=bit32.extract
4307 local band=bit32.band
4308 function files.read2dot14(f)
4309 local a,b=byte(f:read(2),1,2)
4310 if a>=0x80 then
4311 local n=-(0x100*a+b)
4312 return-(extract(n,14,2)+(band(n,0x3FFF)/16384.0))
4313 else
4314 local n=0x100*a+b
4315 return (extract(n,14,2)+(band(n,0x3FFF)/16384.0))
4316 end
4317 end
4318 end
4319 function files.skipshort(f,n)
4320 f:read(2*(n or 1))
4321 end
4322 function files.skiplong(f,n)
4323 f:read(4*(n or 1))
4324 end
4325 if bit32 then
4326 local rshift=bit32.rshift
4327 function files.writecardinal2(f,n)
4328 local a=char(n%256)
4329 n=rshift(n,8)
4330 local b=char(n%256)
4331 f:write(b,a)
4332 end
4333 function files.writecardinal4(f,n)
4334 local a=char(n%256)
4335 n=rshift(n,8)
4336 local b=char(n%256)
4337 n=rshift(n,8)
4338 local c=char(n%256)
4339 n=rshift(n,8)
4340 local d=char(n%256)
4341 f:write(d,c,b,a)
4342 end
4343 function files.writecardinal2le(f,n)
4344 local a=char(n%256)
4345 n=rshift(n,8)
4346 local b=char(n%256)
4347 f:write(a,b)
4348 end
4349 function files.writecardinal4le(f,n)
4350 local a=char(n%256)
4351 n=rshift(n,8)
4352 local b=char(n%256)
4353 n=rshift(n,8)
4354 local c=char(n%256)
4355 n=rshift(n,8)
4356 local d=char(n%256)
4357 f:write(a,b,c,d)
4358 end
4359 else
4360 local floor=math.floor
4361 function files.writecardinal2(f,n)
4362 local a=char(n%256)
4363 n=floor(n/256)
4364 local b=char(n%256)
4365 f:write(b,a)
4366 end
4367 function files.writecardinal4(f,n)
4368 local a=char(n%256)
4369 n=floor(n/256)
4370 local b=char(n%256)
4371 n=floor(n/256)
4372 local c=char(n%256)
4373 n=floor(n/256)
4374 local d=char(n%256)
4375 f:write(d,c,b,a)
4376 end
4377 function files.writecardinal2le(f,n)
4378 local a=char(n%256)
4379 n=floor(n/256)
4380 local b=char(n%256)
4381 f:write(a,b)
4382 end
4383 function files.writecardinal4le(f,n)
4384 local a=char(n%256)
4385 n=floor(n/256)
4386 local b=char(n%256)
4387 n=floor(n/256)
4388 local c=char(n%256)
4389 n=floor(n/256)
4390 local d=char(n%256)
4391 f:write(a,b,c,d)
4392 end
4393 end
4394 function files.writestring(f,s)
4395 f:write(char(byte(s,1,#s)))
4396 end
4397 function files.writebyte(f,b)
4398 f:write(char(b))
4399 end
4400 if fio and fio.readcardinal1 then
4401 files.readcardinal1=fio.readcardinal1
4402 files.readcardinal2=fio.readcardinal2
4403 files.readcardinal3=fio.readcardinal3
4404 files.readcardinal4=fio.readcardinal4
4405 files.readcardinal1le=fio.readcardinal1le or files.readcardinal1le
4406 files.readcardinal2le=fio.readcardinal2le or files.readcardinal2le
4407 files.readcardinal3le=fio.readcardinal3le or files.readcardinal3le
4408 files.readcardinal4le=fio.readcardinal4le or files.readcardinal4le
4409 files.readinteger1=fio.readinteger1
4410 files.readinteger2=fio.readinteger2
4411 files.readinteger3=fio.readinteger3
4412 files.readinteger4=fio.readinteger4
4413 files.readinteger1le=fio.readinteger1le or files.readinteger1le
4414 files.readinteger2le=fio.readinteger2le or files.readinteger2le
4415 files.readinteger3le=fio.readinteger3le or files.readinteger3le
4416 files.readinteger4le=fio.readinteger4le or files.readinteger4le
4417 files.readfixed2=fio.readfixed2
4418 files.readfixed4=fio.readfixed4
4419 files.read2dot14=fio.read2dot14
4420 files.setposition=fio.setposition
4421 files.getposition=fio.getposition
4422 files.readbyte=files.readcardinal1
4423 files.readsignedbyte=files.readinteger1
4424 files.readcardinal=files.readcardinal1
4425 files.readinteger=files.readinteger1
4426 local skipposition=fio.skipposition
4427 files.skipposition=skipposition
4428 files.readbytes=fio.readbytes
4429 files.readbytetable=fio.readbytetable
4430 function files.skipshort(f,n)
4431 skipposition(f,2*(n or 1))
4432 end
4433 function files.skiplong(f,n)
4434 skipposition(f,4*(n or 1))
4435 end
4436 end
4437 if fio and fio.writecardinal1 then
4438 files.writecardinal1=fio.writecardinal1
4439 files.writecardinal2=fio.writecardinal2
4440 files.writecardinal3=fio.writecardinal3
4441 files.writecardinal4=fio.writecardinal4
4442 files.writecardinal1le=fio.writecardinal1le
4443 files.writecardinal2le=fio.writecardinal2le
4444 files.writecardinal3le=fio.writecardinal3le
4445 files.writecardinal4le=fio.writecardinal4le
4446 files.writeinteger1=fio.writeinteger1 or fio.writecardinal1
4447 files.writeinteger2=fio.writeinteger2 or fio.writecardinal2
4448 files.writeinteger3=fio.writeinteger3 or fio.writecardinal3
4449 files.writeinteger4=fio.writeinteger4 or fio.writecardinal4
4450 files.writeinteger1le=files.writeinteger1le or fio.writecardinal1le
4451 files.writeinteger2le=files.writeinteger2le or fio.writecardinal2le
4452 files.writeinteger3le=files.writeinteger3le or fio.writecardinal3le
4453 files.writeinteger4le=files.writeinteger4le or fio.writecardinal4le
4454 end
4455 if fio and fio.readcardinaltable then
4456 files.readcardinaltable=fio.readcardinaltable
4457 files.readintegertable=fio.readintegertable
4458 else
4459 local readcardinal1=files.readcardinal1
4460 local readcardinal2=files.readcardinal2
4461 local readcardinal3=files.readcardinal3
4462 local readcardinal4=files.readcardinal4
4463 function files.readcardinaltable(f,n,b)
4464 local t={}
4465 if b==1 then for i=1,n do t[i]=readcardinal1(f) end
4466 elseif b==2 then for i=1,n do t[i]=readcardinal2(f) end
4467 elseif b==3 then for i=1,n do t[i]=readcardinal3(f) end
4468 elseif b==4 then for i=1,n do t[i]=readcardinal4(f) end end
4469 return t
4470 end
4471 local readinteger1=files.readinteger1
4472 local readinteger2=files.readinteger2
4473 local readinteger3=files.readinteger3
4474 local readinteger4=files.readinteger4
4475 function files.readintegertable(f,n,b)
4476 local t={}
4477 if b==1 then for i=1,n do t[i]=readinteger1(f) end
4478 elseif b==2 then for i=1,n do t[i]=readinteger2(f) end
4479 elseif b==3 then for i=1,n do t[i]=readinteger3(f) end
4480 elseif b==4 then for i=1,n do t[i]=readinteger4(f) end end
4481 return t
4482 end
4483 end
4484
4485 end -- closure
4486
4487 do -- begin closure to overcome local limits and interference
4488
4489 if not modules then modules={} end modules ['luat-basics-gen']={
4490 version=1.100,
4491 comment="companion to luatex-*.tex",
4492 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
4493 copyright="PRAGMA ADE / ConTeXt Development Team",
4494 license="see context related readme files"
4495 }
4496 if context then
4497 --removed
4498
4499 end
4500 local match,gmatch,gsub,lower=string.match,string.gmatch,string.gsub,string.lower
4501 local formatters,split,format,dump=string.formatters,string.split,string.format,string.dump
4502 local loadfile,type=loadfile,type
4503 local setmetatable,getmetatable,collectgarbage=setmetatable,getmetatable,collectgarbage
4504 local floor=math.floor
4505 local dummyfunction=function()
4506 end
4507 local dummyreporter=function(c)
4508 return function(f,...)
4509 local r=texio.reporter or texio.write_nl
4510 if f then
4511 r(c.." : "..(formatters or format)(f,...))
4512 else
4513 r("")
4514 end
4515 end
4516 end
4517 local dummyreport=function(c,f,...)
4518 local r=texio.reporter or texio.write_nl
4519 if f then
4520 r(c.." : "..(formatters or format)(f,...))
4521 else
4522 r("")
4523 end
4524 end
4525 statistics={
4526 register=dummyfunction,
4527 starttiming=dummyfunction,
4528 stoptiming=dummyfunction,
4529 elapsedtime=nil,
4530 }
4531 directives={
4532 register=dummyfunction,
4533 enable=dummyfunction,
4534 disable=dummyfunction,
4535 }
4536 trackers={
4537 register=dummyfunction,
4538 enable=dummyfunction,
4539 disable=dummyfunction,
4540 }
4541 experiments={
4542 register=dummyfunction,
4543 enable=dummyfunction,
4544 disable=dummyfunction,
4545 }
4546 storage={
4547 register=dummyfunction,
4548 shared={},
4549 }
4550 logs={
4551 new=dummyreporter,
4552 reporter=dummyreporter,
4553 messenger=dummyreporter,
4554 report=dummyreport,
4555 }
4556 callbacks={
4557 register=function(n,f)
4558 return callback.register(n,f)
4559 end,
4560 }
4561 utilities=utilities or {}
4562 utilities.storage=utilities.storage or {
4563 allocate=function(t)
4564 return t or {}
4565 end,
4566 mark=function(t)
4567 return t or {}
4568 end,
4569 }
4570 utilities.parsers=utilities.parsers or {
4571 settings_to_array=function(s)
4572 return split(s,",")
4573 end,
4574 settings_to_hash=function(s)
4575 local t={}
4576 for k,v in gmatch((gsub(s,"^{(.*)}$","%1")),"([^%s,=]+)=([^%s,]+)") do
4577 t[k]=v
4578 end
4579 return t
4580 end,
4581 settings_to_hash_colon_too=function(s)
4582 local t={}
4583 for k,v in gmatch((gsub(s,"^{(.*)}$","%1")),"([^%s,=:]+)[=:]([^%s,]+)") do
4584 t[k]=v
4585 end
4586 return t
4587 end,
4588 }
4589 characters=characters or {
4590 data={}
4591 }
4592 texconfig.kpse_init=true
4593 resolvers=resolvers or {}
4594 local remapper={
4595 otf="opentype fonts",
4596 ttf="truetype fonts",
4597 ttc="truetype fonts",
4598 cid="cid maps",
4599 cidmap="cid maps",
4600 pfb="type1 fonts",
4601 afm="afm",
4602 enc="enc files",
4603 lua="tex",
4604 }
4605 function resolvers.findfile(name,fileformat)
4606 name=gsub(name,"\\","/")
4607 if not fileformat or fileformat=="" then
4608 fileformat=file.suffix(name)
4609 if fileformat=="" then
4610 fileformat="tex"
4611 end
4612 end
4613 fileformat=lower(fileformat)
4614 fileformat=remapper[fileformat] or fileformat
4615 local found=kpse.find_file(name,fileformat)
4616 if not found or found=="" then
4617 found=kpse.find_file(name,"other text files")
4618 end
4619 return found
4620 end
4621 resolvers.findbinfile=resolvers.findfile
4622 function resolvers.loadbinfile(filename,filetype)
4623 local data=io.loaddata(filename)
4624 return true,data,#data
4625 end
4626 function resolvers.resolve(s)
4627 return s
4628 end
4629 function resolvers.unresolve(s)
4630 return s
4631 end
4632 caches={}
4633 local writable=nil
4634 local readables={}
4635 local usingjit=jit
4636 if not caches.namespace or caches.namespace=="" or caches.namespace=="context" then
4637 caches.namespace='generic'
4638 end
4639 do
4640 local cachepaths=kpse.expand_var('$TEXMFCACHE') or ""
4641 if cachepaths=="" or cachepaths=="$TEXMFCACHE" then
4642 cachepaths=kpse.expand_var('$TEXMFVAR') or ""
4643 end
4644 if cachepaths=="" or cachepaths=="$TEXMFVAR" then
4645 cachepaths=kpse.expand_var('$VARTEXMF') or ""
4646 end
4647 if cachepaths=="" then
4648 local fallbacks={ "TMPDIR","TEMPDIR","TMP","TEMP","HOME","HOMEPATH" }
4649 for i=1,#fallbacks do
4650 cachepaths=os.getenv(fallbacks[i]) or ""
4651 if cachepath~="" and lfs.isdir(cachepath) then
4652 break
4653 end
4654 end
4655 end
4656 if cachepaths=="" then
4657 cachepaths="."
4658 end
4659 cachepaths=split(cachepaths,os.type=="windows" and ";" or ":")
4660 for i=1,#cachepaths do
4661 local cachepath=cachepaths[i]
4662 if not lfs.isdir(cachepath) then
4663 lfs.mkdirs(cachepath)
4664 if lfs.isdir(cachepath) then
4665 logs.report("system","creating cache path '%s'",cachepath)
4666 end
4667 end
4668 if file.is_writable(cachepath) then
4669 writable=file.join(cachepath,"luatex-cache")
4670 lfs.mkdir(writable)
4671 writable=file.join(writable,caches.namespace)
4672 lfs.mkdir(writable)
4673 break
4674 end
4675 end
4676 for i=1,#cachepaths do
4677 if file.is_readable(cachepaths[i]) then
4678 readables[#readables+1]=file.join(cachepaths[i],"luatex-cache",caches.namespace)
4679 end
4680 end
4681 if not writable then
4682 logs.report("system","no writeable cache path, quiting")
4683 os.exit()
4684 elseif #readables==0 then
4685 logs.report("system","no readable cache path, quiting")
4686 os.exit()
4687 elseif #readables==1 and readables[1]==writable then
4688 logs.report("system","using cache '%s'",writable)
4689 else
4690 logs.report("system","using write cache '%s'",writable)
4691 logs.report("system","using read cache '%s'",table.concat(readables," "))
4692 end
4693 end
4694 function caches.getwritablepath(category,subcategory)
4695 local path=file.join(writable,category)
4696 lfs.mkdir(path)
4697 path=file.join(path,subcategory)
4698 lfs.mkdir(path)
4699 return path
4700 end
4701 function caches.getreadablepaths(category,subcategory)
4702 local t={}
4703 for i=1,#readables do
4704 t[i]=file.join(readables[i],category,subcategory)
4705 end
4706 return t
4707 end
4708 local function makefullname(path,name)
4709 if path and path~="" then
4710 return file.addsuffix(file.join(path,name),"lua"),file.addsuffix(file.join(path,name),usingjit and "lub" or "luc")
4711 end
4712 end
4713 function caches.is_writable(path,name)
4714 local fullname=makefullname(path,name)
4715 return fullname and file.is_writable(fullname)
4716 end
4717 function caches.loaddata(readables,name,writable)
4718 for i=1,#readables do
4719 local path=readables[i]
4720 local loader=false
4721 local luaname,lucname=makefullname(path,name)
4722 if lfs.isfile(lucname) then
4723 logs.report("system","loading luc file '%s'",lucname)
4724 loader=loadfile(lucname)
4725 end
4726 if not loader and lfs.isfile(luaname) then
4727 local luacrap,lucname=makefullname(writable,name)
4728 logs.report("system","compiling luc file '%s'",lucname)
4729 if lfs.isfile(lucname) then
4730 loader=loadfile(lucname)
4731 end
4732 caches.compile(data,luaname,lucname)
4733 if lfs.isfile(lucname) then
4734 logs.report("system","loading luc file '%s'",lucname)
4735 loader=loadfile(lucname)
4736 else
4737 logs.report("system","error in loading luc file '%s'",lucname)
4738 end
4739 if not loader then
4740 logs.report("system","loading lua file '%s'",luaname)
4741 loader=loadfile(luaname)
4742 else
4743 logs.report("system","error in loading lua file '%s'",luaname)
4744 end
4745 end
4746 if loader then
4747 loader=loader()
4748 collectgarbage("step")
4749 return loader
4750 end
4751 end
4752 return false
4753 end
4754 function caches.savedata(path,name,data)
4755 local luaname,lucname=makefullname(path,name)
4756 if luaname then
4757 logs.report("system","saving lua file '%s'",luaname)
4758 table.tofile(luaname,data,true)
4759 if lucname and type(caches.compile)=="function" then
4760 os.remove(lucname)
4761 logs.report("system","saving luc file '%s'",lucname)
4762 caches.compile(data,luaname,lucname)
4763 end
4764 end
4765 end
4766 function caches.compile(data,luaname,lucname)
4767 local d=io.loaddata(luaname)
4768 if not d or d=="" then
4769 d=table.serialize(data,true)
4770 end
4771 if d and d~="" then
4772 local f=io.open(lucname,'wb')
4773 if f then
4774 local s=loadstring(d)
4775 if s then
4776 f:write(dump(s,true))
4777 end
4778 f:close()
4779 end
4780 end
4781 end
4782 function table.setmetatableindex(t,f)
4783 if type(t)~="table" then
4784 f,t=t,{}
4785 end
4786 local m=getmetatable(t)
4787 if f=="table" then
4788 f=function(t,k) local v={} t[k]=v return v end
4789 end
4790 if m then
4791 m.__index=f
4792 else
4793 setmetatable(t,{ __index=f })
4794 end
4795 return t
4796 end
4797 function table.makeweak(t)
4798 local m=getmetatable(t)
4799 if m then
4800 m.__mode="v"
4801 else
4802 setmetatable(t,{ __mode="v" })
4803 end
4804 return t
4805 end
4806 arguments={}
4807 if arg then
4808 for i=1,#arg do
4809 local k,v=match(arg[i],"^%-%-([^=]+)=?(.-)$")
4810 if k and v then
4811 arguments[k]=v
4812 end
4813 end
4814 end
4815 if not number.idiv then
4816 function number.idiv(i,d)
4817 return floor(i/d)
4818 end
4819 end
4820 local u=unicode and unicode.utf8
4821 if u then
4822 utf.lower=u.lower
4823 utf.upper=u.upper
4824 utf.char=u.char
4825 utf.byte=u.byte
4826 utf.len=u.len
4827 if lpeg.setutfcasers then
4828 lpeg.setutfcasers(u.lower,u.upper)
4829 end
4830 local bytepairs=string.bytepairs
4831 local utfchar=utf.char
4832 local concat=table.concat
4833 function utf.utf16_to_utf8_be(s)
4834 if not s then
4835 return nil
4836 elseif s=="" then
4837 return ""
4838 end
4839 local result,r,more={},0,0
4840 for left,right in bytepairs(s) do
4841 if right then
4842 local now=256*left+right
4843 if more>0 then
4844 now=(more-0xD800)*0x400+(now-0xDC00)+0x10000
4845 more=0
4846 r=r+1
4847 result[r]=utfchar(now)
4848 elseif now>=0xD800 and now<=0xDBFF then
4849 more=now
4850 else
4851 r=r+1
4852 result[r]=utfchar(now)
4853 end
4854 end
4855 end
4856 return concat(result)
4857 end
4858 local characters=string.utfcharacters
4859 function utf.split(str)
4860 local t,n={},0
4861 for s in characters(str) do
4862 n=n+1
4863 t[n]=s
4864 end
4865 return t
4866 end
4867 end
4868
4869 end -- closure
4870
4871 do -- begin closure to overcome local limits and interference
4872
4873 if not modules then modules={} end modules ['data-con']={
4874 version=1.100,
4875 comment="companion to luat-lib.mkiv",
4876 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
4877 copyright="PRAGMA ADE / ConTeXt Development Team",
4878 license="see context related readme files"
4879 }
4880 local setmetatable=setmetatable
4881 local format,lower,gsub=string.format,string.lower,string.gsub
4882 local trace_cache=false trackers.register("resolvers.cache",function(v) trace_cache=v end)
4883 local trace_containers=false trackers.register("resolvers.containers",function(v) trace_containers=v end)
4884 local trace_storage=false trackers.register("resolvers.storage",function(v) trace_storage=v end)
4885 containers=containers or {}
4886 local containers=containers
4887 containers.usecache=true
4888 local getwritablepath=caches.getwritablepath
4889 local getreadablepaths=caches.getreadablepaths
4890 local cacheiswritable=caches.is_writable
4891 local loaddatafromcache=caches.loaddata
4892 local savedataincache=caches.savedata
4893 local report_containers=logs.reporter("resolvers","containers")
4894 local allocated={}
4895 local mt={
4896 __index=function(t,k)
4897 if k=="writable" then
4898 local writable=getwritablepath(t.category,t.subcategory) or { "." }
4899 t.writable=writable
4900 return writable
4901 elseif k=="readables" then
4902 local readables=getreadablepaths(t.category,t.subcategory) or { "." }
4903 t.readables=readables
4904 return readables
4905 end
4906 end,
4907 __storage__=true
4908 }
4909 function containers.define(category,subcategory,version,enabled,reload)
4910 if category and subcategory then
4911 local c=allocated[category]
4912 if not c then
4913 c={}
4914 allocated[category]=c
4915 end
4916 local s=c[subcategory]
4917 if not s then
4918 s={
4919 category=category,
4920 subcategory=subcategory,
4921 storage={},
4922 enabled=enabled,
4923 reload=reload,
4924 version=version or math.pi,
4925 trace=false,
4926 }
4927 setmetatable(s,mt)
4928 c[subcategory]=s
4929 end
4930 return s
4931 end
4932 end
4933 function containers.is_usable(container,name)
4934 return container.enabled and caches and cacheiswritable(container.writable,name)
4935 end
4936 function containers.is_valid(container,name)
4937 if name and name~="" then
4938 local storage=container.storage[name]
4939 return storage and storage.cache_version==container.version
4940 else
4941 return false
4942 end
4943 end
4944 function containers.read(container,name)
4945 local storage=container.storage
4946 local reload=container.reload
4947 local stored=not reload and storage[name]
4948 if not stored and container.enabled and caches and containers.usecache then
4949 stored=loaddatafromcache(container.readables,name,container.writable)
4950 if stored and stored.cache_version==container.version then
4951 if trace_cache or trace_containers then
4952 report_containers("action %a, category %a, name %a","load",container.subcategory,name)
4953 end
4954 else
4955 stored=nil
4956 end
4957 storage[name]=stored
4958 elseif stored then
4959 if trace_cache or trace_containers then
4960 report_containers("action %a, category %a, name %a","reuse",container.subcategory,name)
4961 end
4962 end
4963 return stored
4964 end
4965 function containers.write(container,name,data,fast)
4966 if data then
4967 data.cache_version=container.version
4968 if container.enabled and caches then
4969 local unique=data.unique
4970 local shared=data.shared
4971 data.unique=nil
4972 data.shared=nil
4973 savedataincache(container.writable,name,data,fast)
4974 if trace_cache or trace_containers then
4975 report_containers("action %a, category %a, name %a","save",container.subcategory,name)
4976 end
4977 data.unique=unique
4978 data.shared=shared
4979 end
4980 if trace_cache or trace_containers then
4981 report_containers("action %a, category %a, name %a","store",container.subcategory,name)
4982 end
4983 container.storage[name]=data
4984 end
4985 return data
4986 end
4987 function containers.content(container,name)
4988 return container.storage[name]
4989 end
4990 function containers.cleanname(name)
4991 return (gsub(lower(name),"[^%w\128-\255]+","-"))
4992 end
4993
4994 end -- closure
4995
4996 do -- begin closure to overcome local limits and interference
4997
4998 if not modules then modules={} end modules ['luatex-fonts-nod']={
4999 version=1.001,
5000 comment="companion to luatex-fonts.lua",
5001 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
5002 copyright="PRAGMA ADE / ConTeXt Development Team",
5003 license="see context related readme files"
5004 }
5005 if context then
5006 --removed
5007
5008 end
5009 if tex.attribute[0]~=0 then
5010 texio.write_nl("log","!")
5011 texio.write_nl("log","! Attribute 0 is reserved for ConTeXt's font feature management and has to be")
5012 texio.write_nl("log","! set to zero. Also, some attributes in the range 1-255 are used for special")
5013 texio.write_nl("log","! purposes so setting them at the TeX end might break the font handler.")
5014 texio.write_nl("log","!")
5015 tex.attribute[0]=0
5016 end
5017 attributes=attributes or {}
5018 attributes.unsetvalue=-0x7FFFFFFF
5019 local numbers,last={},127
5020 attributes.private=attributes.private or function(name)
5021 local number=numbers[name]
5022 if not number then
5023 if last<255 then
5024 last=last+1
5025 end
5026 number=last
5027 numbers[name]=number
5028 end
5029 return number
5030 end
5031 nodes={}
5032 nodes.handlers={}
5033 local nodecodes={}
5034 local glyphcodes=node.subtypes("glyph")
5035 local disccodes=node.subtypes("disc")
5036 for k,v in next,node.types() do
5037 v=string.gsub(v,"_","")
5038 nodecodes[k]=v
5039 nodecodes[v]=k
5040 end
5041 for k,v in next,glyphcodes do
5042 glyphcodes[v]=k
5043 end
5044 for k,v in next,disccodes do
5045 disccodes[v]=k
5046 end
5047 nodes.nodecodes=nodecodes
5048 nodes.glyphcodes=glyphcodes
5049 nodes.disccodes=disccodes
5050 nodes.dirvalues={ lefttoright=0,righttoleft=1 }
5051 nodes.handlers.protectglyphs=node.protectglyphs or node.protect_glyphs
5052 nodes.handlers.unprotectglyphs=node.unprotectglyphs or node.unprotect_glyphs
5053 local direct=node.direct
5054 local nuts={}
5055 nodes.nuts=nuts
5056 local tonode=direct.tonode
5057 local tonut=direct.todirect
5058 nodes.tonode=tonode
5059 nodes.tonut=tonut
5060 nuts.tonode=tonode
5061 nuts.tonut=tonut
5062 nuts.getattr=direct.get_attribute
5063 nuts.getboth=direct.getboth
5064 nuts.getchar=direct.getchar
5065 nuts.getdirection=direct.getdirection
5066 nuts.getdisc=direct.getdisc
5067 nuts.getreplace=direct.getreplace
5068 nuts.getfield=direct.getfield
5069 nuts.getfont=direct.getfont
5070 nuts.getid=direct.getid
5071 nuts.getkern=direct.getkern
5072 nuts.getlist=direct.getlist
5073 nuts.getnext=direct.getnext
5074 nuts.getoffsets=direct.getoffsets
5075 nuts.getoptions=direct.getoptions or function() return 0 end
5076 nuts.getprev=direct.getprev
5077 nuts.getsubtype=direct.getsubtype
5078 nuts.getwidth=direct.getwidth
5079 nuts.setattr=direct.setfield
5080 nuts.setboth=direct.setboth
5081 nuts.setchar=direct.setchar
5082 nuts.setcomponents=direct.setcomponents
5083 nuts.setdirection=direct.setdirection
5084 nuts.setdisc=direct.setdisc
5085 nuts.setreplace=direct.setreplace
5086 nuts.setfield=direct.setfield
5087 nuts.setkern=direct.setkern
5088 nuts.setlink=direct.setlink
5089 nuts.setlist=direct.setlist
5090 nuts.setnext=direct.setnext
5091 nuts.setoffsets=direct.setoffsets
5092 nuts.setprev=direct.setprev
5093 nuts.setsplit=direct.setsplit
5094 nuts.setsubtype=direct.setsubtype
5095 nuts.setwidth=direct.setwidth
5096 nuts.getglyphdata=nuts.getattribute or nuts.getattr
5097 nuts.setglyphdata=nuts.setattribute or nuts.setattr
5098 nuts.ischar=direct.ischar or direct.is_char
5099 nuts.isglyph=direct.isglyph or direct.is_glyph
5100 nuts.copy=direct.copy
5101 nuts.copynode=direct.copy
5102 nuts.copylist=direct.copylist or direct.copy_list
5103 nuts.endofmath=direct.endofmath or direct.end_of_math
5104 nuts.flush=direct.flush
5105 nuts.flushlist=direct.flushlist or direct.flush_list
5106 nuts.flushnode=direct.flushnode or direct.flush_node
5107 nuts.free=direct.free
5108 nuts.insertafter=direct.insertafter or direct.insert_after
5109 nuts.insertbefore=direct.insertbefore or direct.insert_before
5110 nuts.isnode=direct.isnode or direct.is_node
5111 nuts.isdirect=direct.isdirect or direct.is_direct
5112 nuts.isnut=direct.isdirect or direct.is_direct
5113 nuts.kerning=direct.kerning
5114 nuts.ligaturing=direct.ligaturing
5115 nuts.new=direct.new
5116 nuts.remove=direct.remove
5117 nuts.tail=direct.tail
5118 nuts.traverse=direct.traverse
5119 nuts.traversechar=direct.traversechar or direct.traverse_char
5120 nuts.traverseglyph=direct.traverseglyph or direct.traverse_glyph
5121 nuts.traverseid=direct.traverseid or direct.traverse_id
5122 local propertydata=(direct.getpropertiestable or direct.get_properties_table)()
5123 nodes.properties={ data=propertydata }
5124 if direct.set_properties_mode then
5125 direct.set_properties_mode(true,true)
5126 function direct.set_properties_mode() end
5127 end
5128 nuts.getprop=function(n,k)
5129 local p=propertydata[n]
5130 if p then
5131 return p[k]
5132 end
5133 end
5134 nuts.setprop=function(n,k,v)
5135 if v then
5136 local p=propertydata[n]
5137 if p then
5138 p[k]=v
5139 else
5140 propertydata[n]={ [k]=v }
5141 end
5142 end
5143 end
5144 nodes.setprop=nodes.setproperty
5145 nodes.getprop=nodes.getproperty
5146 local setprev=nuts.setprev
5147 local setnext=nuts.setnext
5148 local getnext=nuts.getnext
5149 local setlink=nuts.setlink
5150 local getfield=nuts.getfield
5151 local setfield=nuts.setfield
5152 local getsubtype=nuts.getsubtype
5153 local isglyph=nuts.isglyph
5154 local find_tail=nuts.tail
5155 local flushlist=nuts.flushlist
5156 local flushnode=nuts.flushnode
5157 local traverseid=nuts.traverseid
5158 local copynode=nuts.copynode
5159 local glyph_code=nodes.nodecodes.glyph
5160 local ligature_code=nodes.glyphcodes.ligature
5161 do
5162 local p=nodecodes.localpar or nodecodes.local_par
5163 if p then
5164 nodecodes.par=p
5165 nodecodes[p]="par"
5166 nodecodes.localpar=p
5167 nodecodes.local_par=p
5168 end
5169 end
5170 do
5171 local getcomponents=node.direct.getcomponents
5172 local setcomponents=node.direct.setcomponents
5173 local function copynocomponents(g,copyinjection)
5174 local components=getcomponents(g)
5175 if components then
5176 setcomponents(g)
5177 local n=copynode(g)
5178 if copyinjection then
5179 copyinjection(n,g)
5180 end
5181 setcomponents(g,components)
5182 return n
5183 else
5184 local n=copynode(g)
5185 if copyinjection then
5186 copyinjection(n,g)
5187 end
5188 return n
5189 end
5190 end
5191 local function copyonlyglyphs(current)
5192 local head=nil
5193 local previous=nil
5194 for n in traverseid(glyph_code,current) do
5195 n=copynode(n)
5196 if head then
5197 setlink(previous,n)
5198 else
5199 head=n
5200 end
5201 previous=n
5202 end
5203 return head
5204 end
5205 local function countcomponents(start,marks)
5206 local char=isglyph(start)
5207 if char then
5208 if getsubtype(start)==ligature_code then
5209 local n=0
5210 local components=getcomponents(start)
5211 while components do
5212 n=n+countcomponents(components,marks)
5213 components=getnext(components)
5214 end
5215 return n
5216 elseif not marks[char] then
5217 return 1
5218 end
5219 end
5220 return 0
5221 end
5222 local function flushcomponents()
5223 end
5224 nuts.components={
5225 set=setcomponents,
5226 get=getcomponents,
5227 copyonlyglyphs=copyonlyglyphs,
5228 copynocomponents=copynocomponents,
5229 count=countcomponents,
5230 flush=flushcomponents,
5231 }
5232 end
5233 nuts.usesfont=direct.usesfont or direct.uses_font
5234 do
5235 local dummy=tonut(node.new("glyph"))
5236 nuts.traversers={
5237 glyph=nuts.traverseid(nodecodes.glyph,dummy),
5238 glue=nuts.traverseid(nodecodes.glue,dummy),
5239 disc=nuts.traverseid(nodecodes.disc,dummy),
5240 boundary=nuts.traverseid(nodecodes.boundary,dummy),
5241 char=nuts.traversechar(dummy),
5242 node=nuts.traverse(dummy),
5243 }
5244 end
5245 if not nuts.setreplace then
5246 local getdisc=nuts.getdisc
5247 local setfield=nuts.setfield
5248 function nuts.getreplace(n)
5249 local _,_,h,_,_,t=getdisc(n,true)
5250 return h,t
5251 end
5252 function nuts.setreplace(n,h)
5253 setfield(n,"replace",h)
5254 end
5255 end
5256 do
5257 local getsubtype=nuts.getsubtype
5258 function nuts.startofpar(n)
5259 local s=getsubtype(n)
5260 return s==0 or s==2
5261 end
5262 end
5263
5264 end -- closure
5265
5266 do -- begin closure to overcome local limits and interference
5267
5268
5269 characters=characters or {}
5270 characters.blockrange={}
5271 characters.classifiers={
5272 [768]=5,
5273 [769]=5,
5274 [770]=5,
5275 [771]=5,
5276 [772]=5,
5277 [773]=5,
5278 [774]=5,
5279 [775]=5,
5280 [776]=5,
5281 [777]=5,
5282 [778]=5,
5283 [779]=5,
5284 [780]=5,
5285 [781]=5,
5286 [782]=5,
5287 [783]=5,
5288 [784]=5,
5289 [785]=5,
5290 [786]=5,
5291 [787]=5,
5292 [788]=5,
5293 [789]=5,
5294 [790]=5,
5295 [791]=5,
5296 [792]=5,
5297 [793]=5,
5298 [794]=5,
5299 [795]=5,
5300 [796]=5,
5301 [797]=5,
5302 [798]=5,
5303 [799]=5,
5304 [800]=5,
5305 [801]=5,
5306 [802]=5,
5307 [803]=5,
5308 [804]=5,
5309 [805]=5,
5310 [806]=5,
5311 [807]=5,
5312 [808]=5,
5313 [809]=5,
5314 [810]=5,
5315 [811]=5,
5316 [812]=5,
5317 [813]=5,
5318 [814]=5,
5319 [815]=5,
5320 [816]=5,
5321 [817]=5,
5322 [818]=5,
5323 [819]=5,
5324 [820]=5,
5325 [821]=5,
5326 [822]=5,
5327 [823]=5,
5328 [824]=5,
5329 [825]=5,
5330 [826]=5,
5331 [827]=5,
5332 [828]=5,
5333 [829]=5,
5334 [830]=5,
5335 [831]=5,
5336 [832]=5,
5337 [833]=5,
5338 [834]=5,
5339 [835]=5,
5340 [836]=5,
5341 [837]=5,
5342 [838]=5,
5343 [839]=5,
5344 [840]=5,
5345 [841]=5,
5346 [842]=5,
5347 [843]=5,
5348 [844]=5,
5349 [845]=5,
5350 [846]=5,
5351 [847]=5,
5352 [848]=5,
5353 [849]=5,
5354 [850]=5,
5355 [851]=5,
5356 [852]=5,
5357 [853]=5,
5358 [854]=5,
5359 [855]=5,
5360 [856]=5,
5361 [857]=5,
5362 [858]=5,
5363 [859]=5,
5364 [860]=5,
5365 [861]=5,
5366 [862]=5,
5367 [863]=5,
5368 [864]=5,
5369 [865]=5,
5370 [866]=5,
5371 [867]=5,
5372 [868]=5,
5373 [869]=5,
5374 [870]=5,
5375 [871]=5,
5376 [872]=5,
5377 [873]=5,
5378 [874]=5,
5379 [875]=5,
5380 [876]=5,
5381 [877]=5,
5382 [878]=5,
5383 [879]=5,
5384 [1155]=5,
5385 [1156]=5,
5386 [1157]=5,
5387 [1158]=5,
5388 [1159]=5,
5389 [1425]=5,
5390 [1426]=5,
5391 [1427]=5,
5392 [1428]=5,
5393 [1429]=5,
5394 [1430]=5,
5395 [1431]=5,
5396 [1432]=5,
5397 [1433]=5,
5398 [1434]=5,
5399 [1435]=5,
5400 [1436]=5,
5401 [1437]=5,
5402 [1438]=5,
5403 [1439]=5,
5404 [1440]=5,
5405 [1441]=5,
5406 [1442]=5,
5407 [1443]=5,
5408 [1444]=5,
5409 [1445]=5,
5410 [1446]=5,
5411 [1447]=5,
5412 [1448]=5,
5413 [1449]=5,
5414 [1450]=5,
5415 [1451]=5,
5416 [1452]=5,
5417 [1453]=5,
5418 [1454]=5,
5419 [1455]=5,
5420 [1456]=5,
5421 [1457]=5,
5422 [1458]=5,
5423 [1459]=5,
5424 [1460]=5,
5425 [1461]=5,
5426 [1462]=5,
5427 [1463]=5,
5428 [1464]=5,
5429 [1465]=5,
5430 [1466]=5,
5431 [1467]=5,
5432 [1468]=5,
5433 [1469]=5,
5434 [1471]=5,
5435 [1473]=5,
5436 [1474]=5,
5437 [1476]=5,
5438 [1477]=5,
5439 [1479]=5,
5440 [1536]=4,
5441 [1537]=4,
5442 [1538]=4,
5443 [1539]=4,
5444 [1540]=4,
5445 [1541]=4,
5446 [1542]=6,
5447 [1543]=6,
5448 [1544]=4,
5449 [1545]=6,
5450 [1546]=6,
5451 [1547]=4,
5452 [1548]=6,
5453 [1549]=6,
5454 [1550]=6,
5455 [1551]=6,
5456 [1552]=5,
5457 [1553]=5,
5458 [1554]=5,
5459 [1555]=5,
5460 [1556]=5,
5461 [1557]=5,
5462 [1558]=5,
5463 [1559]=5,
5464 [1560]=5,
5465 [1561]=5,
5466 [1562]=5,
5467 [1563]=6,
5468 [1564]=6,
5469 [1565]=6,
5470 [1566]=6,
5471 [1567]=6,
5472 [1568]=2,
5473 [1569]=4,
5474 [1570]=3,
5475 [1571]=3,
5476 [1572]=3,
5477 [1573]=3,
5478 [1574]=2,
5479 [1575]=3,
5480 [1576]=2,
5481 [1577]=3,
5482 [1578]=2,
5483 [1579]=2,
5484 [1580]=2,
5485 [1581]=2,
5486 [1582]=2,
5487 [1583]=3,
5488 [1584]=3,
5489 [1585]=3,
5490 [1586]=3,
5491 [1587]=2,
5492 [1588]=2,
5493 [1589]=2,
5494 [1590]=2,
5495 [1591]=2,
5496 [1592]=2,
5497 [1593]=2,
5498 [1594]=2,
5499 [1595]=2,
5500 [1596]=2,
5501 [1597]=2,
5502 [1598]=2,
5503 [1599]=2,
5504 [1600]=2,
5505 [1601]=2,
5506 [1602]=2,
5507 [1603]=2,
5508 [1604]=2,
5509 [1605]=2,
5510 [1606]=2,
5511 [1607]=2,
5512 [1608]=3,
5513 [1609]=2,
5514 [1610]=2,
5515 [1611]=5,
5516 [1612]=5,
5517 [1613]=5,
5518 [1614]=5,
5519 [1615]=5,
5520 [1616]=5,
5521 [1617]=5,
5522 [1618]=5,
5523 [1619]=5,
5524 [1620]=5,
5525 [1621]=5,
5526 [1622]=5,
5527 [1623]=5,
5528 [1624]=5,
5529 [1625]=5,
5530 [1626]=5,
5531 [1627]=5,
5532 [1628]=5,
5533 [1629]=5,
5534 [1630]=5,
5535 [1631]=5,
5536 [1632]=6,
5537 [1633]=6,
5538 [1634]=6,
5539 [1635]=6,
5540 [1636]=6,
5541 [1637]=6,
5542 [1638]=6,
5543 [1639]=6,
5544 [1640]=6,
5545 [1641]=6,
5546 [1642]=6,
5547 [1643]=6,
5548 [1644]=6,
5549 [1645]=6,
5550 [1646]=2,
5551 [1647]=2,
5552 [1648]=5,
5553 [1649]=3,
5554 [1650]=3,
5555 [1651]=3,
5556 [1652]=4,
5557 [1653]=3,
5558 [1654]=3,
5559 [1655]=3,
5560 [1656]=2,
5561 [1657]=2,
5562 [1658]=2,
5563 [1659]=2,
5564 [1660]=2,
5565 [1661]=2,
5566 [1662]=2,
5567 [1663]=2,
5568 [1664]=2,
5569 [1665]=2,
5570 [1666]=2,
5571 [1667]=2,
5572 [1668]=2,
5573 [1669]=2,
5574 [1670]=2,
5575 [1671]=2,
5576 [1672]=3,
5577 [1673]=3,
5578 [1674]=3,
5579 [1675]=3,
5580 [1676]=3,
5581 [1677]=3,
5582 [1678]=3,
5583 [1679]=3,
5584 [1680]=3,
5585 [1681]=3,
5586 [1682]=3,
5587 [1683]=3,
5588 [1684]=3,
5589 [1685]=3,
5590 [1686]=3,
5591 [1687]=3,
5592 [1688]=3,
5593 [1689]=3,
5594 [1690]=2,
5595 [1691]=2,
5596 [1692]=2,
5597 [1693]=2,
5598 [1694]=2,
5599 [1695]=2,
5600 [1696]=2,
5601 [1697]=2,
5602 [1698]=2,
5603 [1699]=2,
5604 [1700]=2,
5605 [1701]=2,
5606 [1702]=2,
5607 [1703]=2,
5608 [1704]=2,
5609 [1705]=2,
5610 [1706]=2,
5611 [1707]=2,
5612 [1708]=2,
5613 [1709]=2,
5614 [1710]=2,
5615 [1711]=2,
5616 [1712]=2,
5617 [1713]=2,
5618 [1714]=2,
5619 [1715]=2,
5620 [1716]=2,
5621 [1717]=2,
5622 [1718]=2,
5623 [1719]=2,
5624 [1720]=2,
5625 [1721]=2,
5626 [1722]=2,
5627 [1723]=2,
5628 [1724]=2,
5629 [1725]=2,
5630 [1726]=2,
5631 [1727]=2,
5632 [1728]=3,
5633 [1729]=2,
5634 [1730]=2,
5635 [1731]=3,
5636 [1732]=3,
5637 [1733]=3,
5638 [1734]=3,
5639 [1735]=3,
5640 [1736]=3,
5641 [1737]=3,
5642 [1738]=3,
5643 [1739]=3,
5644 [1740]=2,
5645 [1741]=3,
5646 [1742]=2,
5647 [1743]=3,
5648 [1744]=2,
5649 [1745]=2,
5650 [1746]=3,
5651 [1747]=3,
5652 [1748]=6,
5653 [1749]=3,
5654 [1750]=5,
5655 [1751]=5,
5656 [1752]=5,
5657 [1753]=5,
5658 [1754]=5,
5659 [1755]=5,
5660 [1756]=5,
5661 [1757]=4,
5662 [1758]=6,
5663 [1759]=5,
5664 [1760]=5,
5665 [1761]=5,
5666 [1762]=5,
5667 [1763]=5,
5668 [1764]=5,
5669 [1765]=6,
5670 [1766]=6,
5671 [1767]=5,
5672 [1768]=5,
5673 [1769]=6,
5674 [1770]=5,
5675 [1771]=5,
5676 [1772]=5,
5677 [1773]=5,
5678 [1774]=3,
5679 [1775]=3,
5680 [1776]=6,
5681 [1777]=6,
5682 [1778]=6,
5683 [1779]=6,
5684 [1780]=6,
5685 [1781]=6,
5686 [1782]=6,
5687 [1783]=6,
5688 [1784]=6,
5689 [1785]=6,
5690 [1786]=2,
5691 [1787]=2,
5692 [1788]=2,
5693 [1789]=6,
5694 [1790]=6,
5695 [1791]=2,
5696 [1792]=6,
5697 [1793]=6,
5698 [1794]=6,
5699 [1795]=6,
5700 [1796]=6,
5701 [1797]=6,
5702 [1798]=6,
5703 [1799]=6,
5704 [1800]=6,
5705 [1801]=6,
5706 [1802]=6,
5707 [1803]=6,
5708 [1804]=6,
5709 [1805]=6,
5710 [1808]=3,
5711 [1809]=5,
5712 [1810]=2,
5713 [1811]=2,
5714 [1812]=2,
5715 [1813]=3,
5716 [1814]=3,
5717 [1815]=3,
5718 [1816]=3,
5719 [1817]=3,
5720 [1818]=2,
5721 [1819]=2,
5722 [1820]=2,
5723 [1821]=2,
5724 [1822]=3,
5725 [1823]=2,
5726 [1824]=2,
5727 [1825]=2,
5728 [1826]=2,
5729 [1827]=2,
5730 [1828]=2,
5731 [1829]=2,
5732 [1830]=2,
5733 [1831]=2,
5734 [1832]=3,
5735 [1833]=2,
5736 [1834]=3,
5737 [1835]=2,
5738 [1836]=3,
5739 [1837]=2,
5740 [1838]=2,
5741 [1839]=3,
5742 [1840]=5,
5743 [1841]=5,
5744 [1842]=5,
5745 [1843]=5,
5746 [1844]=5,
5747 [1845]=5,
5748 [1846]=5,
5749 [1847]=5,
5750 [1848]=5,
5751 [1849]=5,
5752 [1850]=5,
5753 [1851]=5,
5754 [1852]=5,
5755 [1853]=5,
5756 [1854]=5,
5757 [1855]=5,
5758 [1856]=5,
5759 [1857]=5,
5760 [1858]=5,
5761 [1859]=5,
5762 [1860]=5,
5763 [1861]=5,
5764 [1862]=5,
5765 [1863]=5,
5766 [1864]=5,
5767 [1865]=5,
5768 [1866]=5,
5769 [1869]=3,
5770 [1870]=2,
5771 [1871]=2,
5772 [1872]=2,
5773 [1873]=2,
5774 [1874]=2,
5775 [1875]=2,
5776 [1876]=2,
5777 [1877]=2,
5778 [1878]=2,
5779 [1879]=2,
5780 [1880]=2,
5781 [1881]=3,
5782 [1882]=3,
5783 [1883]=3,
5784 [1884]=2,
5785 [1885]=2,
5786 [1886]=2,
5787 [1887]=2,
5788 [1888]=2,
5789 [1889]=2,
5790 [1890]=2,
5791 [1891]=2,
5792 [1892]=2,
5793 [1893]=2,
5794 [1894]=2,
5795 [1895]=2,
5796 [1896]=2,
5797 [1897]=2,
5798 [1898]=2,
5799 [1899]=3,
5800 [1900]=3,
5801 [1901]=2,
5802 [1902]=2,
5803 [1903]=2,
5804 [1904]=2,
5805 [1905]=3,
5806 [1906]=2,
5807 [1907]=3,
5808 [1908]=3,
5809 [1909]=2,
5810 [1910]=2,
5811 [1911]=2,
5812 [1912]=3,
5813 [1913]=3,
5814 [1914]=2,
5815 [1915]=2,
5816 [1916]=2,
5817 [1917]=2,
5818 [1918]=2,
5819 [1919]=2,
5820 [1958]=5,
5821 [1959]=5,
5822 [1960]=5,
5823 [1961]=5,
5824 [1962]=5,
5825 [1963]=5,
5826 [1964]=5,
5827 [1965]=5,
5828 [1966]=5,
5829 [1967]=5,
5830 [1968]=5,
5831 [1984]=6,
5832 [1985]=6,
5833 [1986]=6,
5834 [1987]=6,
5835 [1988]=6,
5836 [1989]=6,
5837 [1990]=6,
5838 [1991]=6,
5839 [1992]=6,
5840 [1993]=6,
5841 [1994]=2,
5842 [1995]=2,
5843 [1996]=2,
5844 [1997]=2,
5845 [1998]=2,
5846 [1999]=2,
5847 [2000]=2,
5848 [2001]=2,
5849 [2002]=2,
5850 [2003]=2,
5851 [2004]=2,
5852 [2005]=2,
5853 [2006]=2,
5854 [2007]=2,
5855 [2008]=2,
5856 [2009]=2,
5857 [2010]=2,
5858 [2011]=2,
5859 [2012]=2,
5860 [2013]=2,
5861 [2014]=2,
5862 [2015]=2,
5863 [2016]=2,
5864 [2017]=2,
5865 [2018]=2,
5866 [2019]=2,
5867 [2020]=2,
5868 [2021]=2,
5869 [2022]=2,
5870 [2023]=2,
5871 [2024]=2,
5872 [2025]=2,
5873 [2026]=2,
5874 [2027]=5,
5875 [2028]=5,
5876 [2029]=5,
5877 [2030]=5,
5878 [2031]=5,
5879 [2032]=5,
5880 [2033]=5,
5881 [2034]=5,
5882 [2035]=5,
5883 [2036]=6,
5884 [2037]=6,
5885 [2038]=6,
5886 [2039]=6,
5887 [2040]=6,
5888 [2041]=6,
5889 [2042]=2,
5890 [2045]=5,
5891 [2046]=6,
5892 [2047]=6,
5893 [2070]=5,
5894 [2071]=5,
5895 [2072]=5,
5896 [2073]=5,
5897 [2075]=5,
5898 [2076]=5,
5899 [2077]=5,
5900 [2078]=5,
5901 [2079]=5,
5902 [2080]=5,
5903 [2081]=5,
5904 [2082]=5,
5905 [2083]=5,
5906 [2085]=5,
5907 [2086]=5,
5908 [2087]=5,
5909 [2089]=5,
5910 [2090]=5,
5911 [2091]=5,
5912 [2092]=5,
5913 [2093]=5,
5914 [2112]=3,
5915 [2113]=2,
5916 [2114]=2,
5917 [2115]=2,
5918 [2116]=2,
5919 [2117]=2,
5920 [2118]=3,
5921 [2119]=3,
5922 [2120]=2,
5923 [2121]=3,
5924 [2122]=2,
5925 [2123]=2,
5926 [2124]=2,
5927 [2125]=2,
5928 [2126]=2,
5929 [2127]=2,
5930 [2128]=2,
5931 [2129]=2,
5932 [2130]=2,
5933 [2131]=2,
5934 [2132]=3,
5935 [2133]=2,
5936 [2134]=3,
5937 [2135]=3,
5938 [2136]=3,
5939 [2137]=5,
5940 [2138]=5,
5941 [2139]=5,
5942 [2144]=2,
5943 [2145]=4,
5944 [2146]=2,
5945 [2147]=2,
5946 [2148]=2,
5947 [2149]=2,
5948 [2150]=4,
5949 [2151]=3,
5950 [2152]=2,
5951 [2153]=3,
5952 [2154]=3,
5953 [2160]=3,
5954 [2161]=3,
5955 [2162]=3,
5956 [2163]=3,
5957 [2164]=3,
5958 [2165]=3,
5959 [2166]=3,
5960 [2167]=3,
5961 [2168]=3,
5962 [2169]=3,
5963 [2170]=3,
5964 [2171]=3,
5965 [2172]=3,
5966 [2173]=3,
5967 [2174]=3,
5968 [2175]=3,
5969 [2176]=3,
5970 [2177]=3,
5971 [2178]=3,
5972 [2179]=2,
5973 [2180]=2,
5974 [2181]=2,
5975 [2182]=2,
5976 [2183]=4,
5977 [2184]=4,
5978 [2185]=2,
5979 [2186]=2,
5980 [2187]=2,
5981 [2188]=2,
5982 [2189]=2,
5983 [2190]=3,
5984 [2192]=4,
5985 [2193]=4,
5986 [2200]=5,
5987 [2201]=5,
5988 [2202]=5,
5989 [2203]=5,
5990 [2204]=5,
5991 [2205]=5,
5992 [2206]=5,
5993 [2207]=5,
5994 [2208]=2,
5995 [2209]=2,
5996 [2210]=2,
5997 [2211]=2,
5998 [2212]=2,
5999 [2213]=2,
6000 [2214]=2,
6001 [2215]=2,
6002 [2216]=2,
6003 [2217]=2,
6004 [2218]=3,
6005 [2219]=3,
6006 [2220]=3,
6007 [2221]=4,
6008 [2222]=3,
6009 [2223]=2,
6010 [2224]=2,
6011 [2225]=3,
6012 [2226]=3,
6013 [2227]=2,
6014 [2228]=2,
6015 [2229]=2,
6016 [2230]=2,
6017 [2231]=2,
6018 [2232]=2,
6019 [2233]=3,
6020 [2234]=2,
6021 [2235]=2,
6022 [2236]=2,
6023 [2237]=2,
6024 [2238]=2,
6025 [2239]=2,
6026 [2240]=2,
6027 [2241]=2,
6028 [2242]=2,
6029 [2243]=2,
6030 [2244]=2,
6031 [2245]=2,
6032 [2246]=2,
6033 [2247]=2,
6034 [2248]=2,
6035 [2250]=5,
6036 [2251]=5,
6037 [2252]=5,
6038 [2253]=5,
6039 [2254]=5,
6040 [2255]=5,
6041 [2256]=5,
6042 [2257]=5,
6043 [2258]=5,
6044 [2259]=5,
6045 [2260]=5,
6046 [2261]=5,
6047 [2262]=5,
6048 [2263]=5,
6049 [2264]=5,
6050 [2265]=5,
6051 [2266]=5,
6052 [2267]=5,
6053 [2268]=5,
6054 [2269]=5,
6055 [2270]=5,
6056 [2271]=5,
6057 [2272]=5,
6058 [2273]=5,
6059 [2274]=4,
6060 [2275]=5,
6061 [2276]=5,
6062 [2277]=5,
6063 [2278]=5,
6064 [2279]=5,
6065 [2280]=5,
6066 [2281]=5,
6067 [2282]=5,
6068 [2283]=5,
6069 [2284]=5,
6070 [2285]=5,
6071 [2286]=5,
6072 [2287]=5,
6073 [2288]=5,
6074 [2289]=5,
6075 [2290]=5,
6076 [2291]=5,
6077 [2292]=5,
6078 [2293]=5,
6079 [2294]=5,
6080 [2295]=5,
6081 [2296]=5,
6082 [2297]=5,
6083 [2298]=5,
6084 [2299]=5,
6085 [2300]=5,
6086 [2301]=5,
6087 [2302]=5,
6088 [2303]=5,
6089 [2304]=5,
6090 [2305]=5,
6091 [2306]=5,
6092 [2362]=5,
6093 [2364]=5,
6094 [2369]=5,
6095 [2370]=5,
6096 [2371]=5,
6097 [2372]=5,
6098 [2373]=5,
6099 [2374]=5,
6100 [2375]=5,
6101 [2376]=5,
6102 [2381]=5,
6103 [2385]=5,
6104 [2386]=5,
6105 [2387]=5,
6106 [2388]=5,
6107 [2389]=5,
6108 [2390]=5,
6109 [2391]=5,
6110 [2402]=5,
6111 [2403]=5,
6112 [2433]=5,
6113 [2492]=5,
6114 [2497]=5,
6115 [2498]=5,
6116 [2499]=5,
6117 [2500]=5,
6118 [2509]=5,
6119 [2530]=5,
6120 [2531]=5,
6121 [2558]=5,
6122 [2561]=5,
6123 [2562]=5,
6124 [2620]=5,
6125 [2625]=5,
6126 [2626]=5,
6127 [2631]=5,
6128 [2632]=5,
6129 [2635]=5,
6130 [2636]=5,
6131 [2637]=5,
6132 [2641]=5,
6133 [2672]=5,
6134 [2673]=5,
6135 [2677]=5,
6136 [2689]=5,
6137 [2690]=5,
6138 [2748]=5,
6139 [2753]=5,
6140 [2754]=5,
6141 [2755]=5,
6142 [2756]=5,
6143 [2757]=5,
6144 [2759]=5,
6145 [2760]=5,
6146 [2765]=5,
6147 [2786]=5,
6148 [2787]=5,
6149 [2810]=5,
6150 [2811]=5,
6151 [2812]=5,
6152 [2813]=5,
6153 [2814]=5,
6154 [2815]=5,
6155 [2817]=5,
6156 [2876]=5,
6157 [2879]=5,
6158 [2881]=5,
6159 [2882]=5,
6160 [2883]=5,
6161 [2884]=5,
6162 [2893]=5,
6163 [2901]=5,
6164 [2902]=5,
6165 [2914]=5,
6166 [2915]=5,
6167 [2946]=5,
6168 [3008]=5,
6169 [3021]=5,
6170 [3072]=5,
6171 [3076]=5,
6172 [3132]=5,
6173 [3134]=5,
6174 [3135]=5,
6175 [3136]=5,
6176 [3142]=5,
6177 [3143]=5,
6178 [3144]=5,
6179 [3146]=5,
6180 [3147]=5,
6181 [3148]=5,
6182 [3149]=5,
6183 [3157]=5,
6184 [3158]=5,
6185 [3170]=5,
6186 [3171]=5,
6187 [3201]=5,
6188 [3260]=5,
6189 [3263]=5,
6190 [3270]=5,
6191 [3276]=5,
6192 [3277]=5,
6193 [3298]=5,
6194 [3299]=5,
6195 [3328]=5,
6196 [3329]=5,
6197 [3387]=5,
6198 [3388]=5,
6199 [3393]=5,
6200 [3394]=5,
6201 [3395]=5,
6202 [3396]=5,
6203 [3405]=5,
6204 [3426]=5,
6205 [3427]=5,
6206 [3457]=5,
6207 [3530]=5,
6208 [3538]=5,
6209 [3539]=5,
6210 [3540]=5,
6211 [3542]=5,
6212 [3633]=5,
6213 [3636]=5,
6214 [3637]=5,
6215 [3638]=5,
6216 [3639]=5,
6217 [3640]=5,
6218 [3641]=5,
6219 [3642]=5,
6220 [3655]=5,
6221 [3656]=5,
6222 [3657]=5,
6223 [3658]=5,
6224 [3659]=5,
6225 [3660]=5,
6226 [3661]=5,
6227 [3662]=5,
6228 [3761]=5,
6229 [3764]=5,
6230 [3765]=5,
6231 [3766]=5,
6232 [3767]=5,
6233 [3768]=5,
6234 [3769]=5,
6235 [3770]=5,
6236 [3771]=5,
6237 [3772]=5,
6238 [3784]=5,
6239 [3785]=5,
6240 [3786]=5,
6241 [3787]=5,
6242 [3788]=5,
6243 [3789]=5,
6244 [3864]=5,
6245 [3865]=5,
6246 [3893]=5,
6247 [3895]=5,
6248 [3897]=5,
6249 [3953]=5,
6250 [3954]=5,
6251 [3955]=5,
6252 [3956]=5,
6253 [3957]=5,
6254 [3958]=5,
6255 [3959]=5,
6256 [3960]=5,
6257 [3961]=5,
6258 [3962]=5,
6259 [3963]=5,
6260 [3964]=5,
6261 [3965]=5,
6262 [3966]=5,
6263 [3968]=5,
6264 [3969]=5,
6265 [3970]=5,
6266 [3971]=5,
6267 [3972]=5,
6268 [3974]=5,
6269 [3975]=5,
6270 [3981]=5,
6271 [3982]=5,
6272 [3983]=5,
6273 [3984]=5,
6274 [3985]=5,
6275 [3986]=5,
6276 [3987]=5,
6277 [3988]=5,
6278 [3989]=5,
6279 [3990]=5,
6280 [3991]=5,
6281 [3993]=5,
6282 [3994]=5,
6283 [3995]=5,
6284 [3996]=5,
6285 [3997]=5,
6286 [3998]=5,
6287 [3999]=5,
6288 [4000]=5,
6289 [4001]=5,
6290 [4002]=5,
6291 [4003]=5,
6292 [4004]=5,
6293 [4005]=5,
6294 [4006]=5,
6295 [4007]=5,
6296 [4008]=5,
6297 [4009]=5,
6298 [4010]=5,
6299 [4011]=5,
6300 [4012]=5,
6301 [4013]=5,
6302 [4014]=5,
6303 [4015]=5,
6304 [4016]=5,
6305 [4017]=5,
6306 [4018]=5,
6307 [4019]=5,
6308 [4020]=5,
6309 [4021]=5,
6310 [4022]=5,
6311 [4023]=5,
6312 [4024]=5,
6313 [4025]=5,
6314 [4026]=5,
6315 [4027]=5,
6316 [4028]=5,
6317 [4038]=5,
6318 [4141]=5,
6319 [4142]=5,
6320 [4143]=5,
6321 [4144]=5,
6322 [4146]=5,
6323 [4147]=5,
6324 [4148]=5,
6325 [4149]=5,
6326 [4150]=5,
6327 [4151]=5,
6328 [4153]=5,
6329 [4154]=5,
6330 [4157]=5,
6331 [4158]=5,
6332 [4184]=5,
6333 [4185]=5,
6334 [4190]=5,
6335 [4191]=5,
6336 [4192]=5,
6337 [4209]=5,
6338 [4210]=5,
6339 [4211]=5,
6340 [4212]=5,
6341 [4226]=5,
6342 [4229]=5,
6343 [4230]=5,
6344 [4237]=5,
6345 [4253]=5,
6346 [4957]=5,
6347 [4958]=5,
6348 [4959]=5,
6349 [5906]=5,
6350 [5907]=5,
6351 [5908]=5,
6352 [5938]=5,
6353 [5939]=5,
6354 [5940]=5,
6355 [5970]=5,
6356 [5971]=5,
6357 [6002]=5,
6358 [6003]=5,
6359 [6071]=5,
6360 [6072]=5,
6361 [6073]=5,
6362 [6074]=5,
6363 [6075]=5,
6364 [6076]=5,
6365 [6077]=5,
6366 [6086]=5,
6367 [6089]=5,
6368 [6090]=5,
6369 [6091]=5,
6370 [6092]=5,
6371 [6093]=5,
6372 [6094]=5,
6373 [6095]=5,
6374 [6096]=5,
6375 [6097]=5,
6376 [6098]=5,
6377 [6099]=5,
6378 [6109]=5,
6379 [6150]=4,
6380 [6151]=2,
6381 [6154]=2,
6382 [6155]=5,
6383 [6156]=5,
6384 [6157]=5,
6385 [6158]=4,
6386 [6159]=5,
6387 [6176]=2,
6388 [6177]=2,
6389 [6178]=2,
6390 [6179]=2,
6391 [6180]=2,
6392 [6181]=2,
6393 [6182]=2,
6394 [6183]=2,
6395 [6184]=2,
6396 [6185]=2,
6397 [6186]=2,
6398 [6187]=2,
6399 [6188]=2,
6400 [6189]=2,
6401 [6190]=2,
6402 [6191]=2,
6403 [6192]=2,
6404 [6193]=2,
6405 [6194]=2,
6406 [6195]=2,
6407 [6196]=2,
6408 [6197]=2,
6409 [6198]=2,
6410 [6199]=2,
6411 [6200]=2,
6412 [6201]=2,
6413 [6202]=2,
6414 [6203]=2,
6415 [6204]=2,
6416 [6205]=2,
6417 [6206]=2,
6418 [6207]=2,
6419 [6208]=2,
6420 [6209]=2,
6421 [6210]=2,
6422 [6211]=2,
6423 [6212]=2,
6424 [6213]=2,
6425 [6214]=2,
6426 [6215]=2,
6427 [6216]=2,
6428 [6217]=2,
6429 [6218]=2,
6430 [6219]=2,
6431 [6220]=2,
6432 [6221]=2,
6433 [6222]=2,
6434 [6223]=2,
6435 [6224]=2,
6436 [6225]=2,
6437 [6226]=2,
6438 [6227]=2,
6439 [6228]=2,
6440 [6229]=2,
6441 [6230]=2,
6442 [6231]=2,
6443 [6232]=2,
6444 [6233]=2,
6445 [6234]=2,
6446 [6235]=2,
6447 [6236]=2,
6448 [6237]=2,
6449 [6238]=2,
6450 [6239]=2,
6451 [6240]=2,
6452 [6241]=2,
6453 [6242]=2,
6454 [6243]=2,
6455 [6244]=2,
6456 [6245]=2,
6457 [6246]=2,
6458 [6247]=2,
6459 [6248]=2,
6460 [6249]=2,
6461 [6250]=2,
6462 [6251]=2,
6463 [6252]=2,
6464 [6253]=2,
6465 [6254]=2,
6466 [6255]=2,
6467 [6256]=2,
6468 [6257]=2,
6469 [6258]=2,
6470 [6259]=2,
6471 [6260]=2,
6472 [6261]=2,
6473 [6262]=2,
6474 [6263]=2,
6475 [6264]=2,
6476 [6272]=4,
6477 [6273]=4,
6478 [6274]=4,
6479 [6275]=4,
6480 [6276]=4,
6481 [6279]=2,
6482 [6280]=2,
6483 [6281]=2,
6484 [6282]=2,
6485 [6283]=2,
6486 [6284]=2,
6487 [6285]=2,
6488 [6286]=2,
6489 [6287]=2,
6490 [6288]=2,
6491 [6289]=2,
6492 [6290]=2,
6493 [6291]=2,
6494 [6292]=2,
6495 [6293]=2,
6496 [6294]=2,
6497 [6295]=2,
6498 [6296]=2,
6499 [6297]=2,
6500 [6298]=2,
6501 [6299]=2,
6502 [6300]=2,
6503 [6301]=2,
6504 [6302]=2,
6505 [6303]=2,
6506 [6304]=2,
6507 [6305]=2,
6508 [6306]=2,
6509 [6307]=2,
6510 [6308]=2,
6511 [6309]=2,
6512 [6310]=2,
6513 [6311]=2,
6514 [6312]=2,
6515 [6313]=5,
6516 [6314]=2,
6517 [6432]=5,
6518 [6433]=5,
6519 [6434]=5,
6520 [6439]=5,
6521 [6440]=5,
6522 [6450]=5,
6523 [6457]=5,
6524 [6458]=5,
6525 [6459]=5,
6526 [6679]=5,
6527 [6680]=5,
6528 [6742]=5,
6529 [6744]=5,
6530 [6745]=5,
6531 [6746]=5,
6532 [6747]=5,
6533 [6748]=5,
6534 [6749]=5,
6535 [6750]=5,
6536 [6752]=5,
6537 [6754]=5,
6538 [6757]=5,
6539 [6758]=5,
6540 [6759]=5,
6541 [6760]=5,
6542 [6761]=5,
6543 [6762]=5,
6544 [6763]=5,
6545 [6764]=5,
6546 [6771]=5,
6547 [6772]=5,
6548 [6773]=5,
6549 [6774]=5,
6550 [6775]=5,
6551 [6776]=5,
6552 [6777]=5,
6553 [6778]=5,
6554 [6779]=5,
6555 [6780]=5,
6556 [6783]=5,
6557 [6832]=5,
6558 [6833]=5,
6559 [6834]=5,
6560 [6835]=5,
6561 [6836]=5,
6562 [6837]=5,
6563 [6838]=5,
6564 [6839]=5,
6565 [6840]=5,
6566 [6841]=5,
6567 [6842]=5,
6568 [6843]=5,
6569 [6844]=5,
6570 [6845]=5,
6571 [6847]=5,
6572 [6848]=5,
6573 [6849]=5,
6574 [6850]=5,
6575 [6851]=5,
6576 [6852]=5,
6577 [6853]=5,
6578 [6854]=5,
6579 [6855]=5,
6580 [6856]=5,
6581 [6857]=5,
6582 [6858]=5,
6583 [6859]=5,
6584 [6860]=5,
6585 [6861]=5,
6586 [6862]=5,
6587 [6912]=5,
6588 [6913]=5,
6589 [6914]=5,
6590 [6915]=5,
6591 [6964]=5,
6592 [6966]=5,
6593 [6967]=5,
6594 [6968]=5,
6595 [6969]=5,
6596 [6970]=5,
6597 [6972]=5,
6598 [6978]=5,
6599 [7019]=5,
6600 [7020]=5,
6601 [7021]=5,
6602 [7022]=5,
6603 [7023]=5,
6604 [7024]=5,
6605 [7025]=5,
6606 [7026]=5,
6607 [7027]=5,
6608 [7040]=5,
6609 [7041]=5,
6610 [7074]=5,
6611 [7075]=5,
6612 [7076]=5,
6613 [7077]=5,
6614 [7080]=5,
6615 [7081]=5,
6616 [7083]=5,
6617 [7142]=5,
6618 [7144]=5,
6619 [7145]=5,
6620 [7149]=5,
6621 [7151]=5,
6622 [7152]=5,
6623 [7153]=5,
6624 [7212]=5,
6625 [7213]=5,
6626 [7214]=5,
6627 [7215]=5,
6628 [7216]=5,
6629 [7217]=5,
6630 [7218]=5,
6631 [7219]=5,
6632 [7222]=5,
6633 [7223]=5,
6634 [7376]=5,
6635 [7377]=5,
6636 [7378]=5,
6637 [7380]=5,
6638 [7381]=5,
6639 [7382]=5,
6640 [7383]=5,
6641 [7384]=5,
6642 [7385]=5,
6643 [7386]=5,
6644 [7387]=5,
6645 [7388]=5,
6646 [7389]=5,
6647 [7390]=5,
6648 [7391]=5,
6649 [7392]=5,
6650 [7394]=5,
6651 [7395]=5,
6652 [7396]=5,
6653 [7397]=5,
6654 [7398]=5,
6655 [7399]=5,
6656 [7400]=5,
6657 [7405]=5,
6658 [7412]=5,
6659 [7416]=5,
6660 [7417]=5,
6661 [7616]=5,
6662 [7617]=5,
6663 [7618]=5,
6664 [7619]=5,
6665 [7620]=5,
6666 [7621]=5,
6667 [7622]=5,
6668 [7623]=5,
6669 [7624]=5,
6670 [7625]=5,
6671 [7626]=5,
6672 [7627]=5,
6673 [7628]=5,
6674 [7629]=5,
6675 [7630]=5,
6676 [7631]=5,
6677 [7632]=5,
6678 [7633]=5,
6679 [7634]=5,
6680 [7635]=5,
6681 [7636]=5,
6682 [7637]=5,
6683 [7638]=5,
6684 [7639]=5,
6685 [7640]=5,
6686 [7641]=5,
6687 [7642]=5,
6688 [7643]=5,
6689 [7644]=5,
6690 [7645]=5,
6691 [7646]=5,
6692 [7647]=5,
6693 [7648]=5,
6694 [7649]=5,
6695 [7650]=5,
6696 [7651]=5,
6697 [7652]=5,
6698 [7653]=5,
6699 [7654]=5,
6700 [7655]=5,
6701 [7656]=5,
6702 [7657]=5,
6703 [7658]=5,
6704 [7659]=5,
6705 [7660]=5,
6706 [7661]=5,
6707 [7662]=5,
6708 [7663]=5,
6709 [7664]=5,
6710 [7665]=5,
6711 [7666]=5,
6712 [7667]=5,
6713 [7668]=5,
6714 [7669]=5,
6715 [7670]=5,
6716 [7671]=5,
6717 [7672]=5,
6718 [7673]=5,
6719 [7674]=5,
6720 [7675]=5,
6721 [7676]=5,
6722 [7677]=5,
6723 [7678]=5,
6724 [7679]=5,
6725 [8204]=4,
6726 [8205]=2,
6727 [8239]=4,
6728 [8294]=4,
6729 [8295]=4,
6730 [8296]=4,
6731 [8297]=4,
6732 [8400]=5,
6733 [8401]=5,
6734 [8402]=5,
6735 [8403]=5,
6736 [8404]=5,
6737 [8405]=5,
6738 [8406]=5,
6739 [8407]=5,
6740 [8408]=5,
6741 [8409]=5,
6742 [8410]=5,
6743 [8411]=5,
6744 [8412]=5,
6745 [8417]=5,
6746 [8421]=5,
6747 [8422]=5,
6748 [8423]=5,
6749 [8424]=5,
6750 [8425]=5,
6751 [8426]=5,
6752 [8427]=5,
6753 [8428]=5,
6754 [8429]=5,
6755 [8430]=5,
6756 [8431]=5,
6757 [8432]=5,
6758 [11503]=5,
6759 [11504]=5,
6760 [11505]=5,
6761 [11647]=5,
6762 [11744]=5,
6763 [11745]=5,
6764 [11746]=5,
6765 [11747]=5,
6766 [11748]=5,
6767 [11749]=5,
6768 [11750]=5,
6769 [11751]=5,
6770 [11752]=5,
6771 [11753]=5,
6772 [11754]=5,
6773 [11755]=5,
6774 [11756]=5,
6775 [11757]=5,
6776 [11758]=5,
6777 [11759]=5,
6778 [11760]=5,
6779 [11761]=5,
6780 [11762]=5,
6781 [11763]=5,
6782 [11764]=5,
6783 [11765]=5,
6784 [11766]=5,
6785 [11767]=5,
6786 [11768]=5,
6787 [11769]=5,
6788 [11770]=5,
6789 [11771]=5,
6790 [11772]=5,
6791 [11773]=5,
6792 [11774]=5,
6793 [11775]=5,
6794 [12330]=5,
6795 [12331]=5,
6796 [12332]=5,
6797 [12333]=5,
6798 [12334]=5,
6799 [12335]=5,
6800 [12441]=5,
6801 [12442]=5,
6802 [42607]=5,
6803 [42612]=5,
6804 [42613]=5,
6805 [42614]=5,
6806 [42615]=5,
6807 [42616]=5,
6808 [42617]=5,
6809 [42618]=5,
6810 [42619]=5,
6811 [42620]=5,
6812 [42621]=5,
6813 [42654]=5,
6814 [42655]=5,
6815 [42736]=5,
6816 [42737]=5,
6817 [43014]=5,
6818 [43019]=5,
6819 [43045]=5,
6820 [43046]=5,
6821 [43052]=5,
6822 [43072]=2,
6823 [43073]=2,
6824 [43074]=2,
6825 [43075]=2,
6826 [43076]=2,
6827 [43077]=2,
6828 [43078]=2,
6829 [43079]=2,
6830 [43080]=2,
6831 [43081]=2,
6832 [43082]=2,
6833 [43083]=2,
6834 [43084]=2,
6835 [43085]=2,
6836 [43086]=2,
6837 [43087]=2,
6838 [43088]=2,
6839 [43089]=2,
6840 [43090]=2,
6841 [43091]=2,
6842 [43092]=2,
6843 [43093]=2,
6844 [43094]=2,
6845 [43095]=2,
6846 [43096]=2,
6847 [43097]=2,
6848 [43098]=2,
6849 [43099]=2,
6850 [43100]=2,
6851 [43101]=2,
6852 [43102]=2,
6853 [43103]=2,
6854 [43104]=2,
6855 [43105]=2,
6856 [43106]=2,
6857 [43107]=2,
6858 [43108]=2,
6859 [43109]=2,
6860 [43110]=2,
6861 [43111]=2,
6862 [43112]=2,
6863 [43113]=2,
6864 [43114]=2,
6865 [43115]=2,
6866 [43116]=2,
6867 [43117]=2,
6868 [43118]=2,
6869 [43119]=2,
6870 [43120]=2,
6871 [43121]=2,
6872 [43122]=1,
6873 [43123]=4,
6874 [43204]=5,
6875 [43205]=5,
6876 [43232]=5,
6877 [43233]=5,
6878 [43234]=5,
6879 [43235]=5,
6880 [43236]=5,
6881 [43237]=5,
6882 [43238]=5,
6883 [43239]=5,
6884 [43240]=5,
6885 [43241]=5,
6886 [43242]=5,
6887 [43243]=5,
6888 [43244]=5,
6889 [43245]=5,
6890 [43246]=5,
6891 [43247]=5,
6892 [43248]=5,
6893 [43249]=5,
6894 [43263]=5,
6895 [43302]=5,
6896 [43303]=5,
6897 [43304]=5,
6898 [43305]=5,
6899 [43306]=5,
6900 [43307]=5,
6901 [43308]=5,
6902 [43309]=5,
6903 [43335]=5,
6904 [43336]=5,
6905 [43337]=5,
6906 [43338]=5,
6907 [43339]=5,
6908 [43340]=5,
6909 [43341]=5,
6910 [43342]=5,
6911 [43343]=5,
6912 [43344]=5,
6913 [43345]=5,
6914 [43392]=5,
6915 [43393]=5,
6916 [43394]=5,
6917 [43443]=5,
6918 [43446]=5,
6919 [43447]=5,
6920 [43448]=5,
6921 [43449]=5,
6922 [43452]=5,
6923 [43493]=5,
6924 [43561]=5,
6925 [43562]=5,
6926 [43563]=5,
6927 [43564]=5,
6928 [43565]=5,
6929 [43566]=5,
6930 [43569]=5,
6931 [43570]=5,
6932 [43573]=5,
6933 [43574]=5,
6934 [43587]=5,
6935 [43596]=5,
6936 [43644]=5,
6937 [43696]=5,
6938 [43698]=5,
6939 [43699]=5,
6940 [43700]=5,
6941 [43703]=5,
6942 [43704]=5,
6943 [43710]=5,
6944 [43711]=5,
6945 [43713]=5,
6946 [43756]=5,
6947 [43757]=5,
6948 [43766]=5,
6949 [44005]=5,
6950 [44008]=5,
6951 [44013]=5,
6952 [64286]=5,
6953 [65056]=5,
6954 [65057]=5,
6955 [65058]=5,
6956 [65059]=5,
6957 [65060]=5,
6958 [65061]=5,
6959 [65062]=5,
6960 [65063]=5,
6961 [65064]=5,
6962 [65065]=5,
6963 [65066]=5,
6964 [65067]=5,
6965 [65068]=5,
6966 [65069]=5,
6967 [65070]=5,
6968 [65071]=5,
6969 [66045]=5,
6970 [66272]=5,
6971 [66422]=5,
6972 [66423]=5,
6973 [66424]=5,
6974 [66425]=5,
6975 [66426]=5,
6976 [68097]=5,
6977 [68098]=5,
6978 [68099]=5,
6979 [68101]=5,
6980 [68102]=5,
6981 [68108]=5,
6982 [68109]=5,
6983 [68110]=5,
6984 [68111]=5,
6985 [68152]=5,
6986 [68153]=5,
6987 [68154]=5,
6988 [68159]=5,
6989 [68288]=2,
6990 [68289]=2,
6991 [68290]=2,
6992 [68291]=2,
6993 [68292]=2,
6994 [68293]=3,
6995 [68294]=4,
6996 [68295]=3,
6997 [68296]=4,
6998 [68297]=3,
6999 [68298]=3,
7000 [68299]=4,
7001 [68300]=4,
7002 [68301]=1,
7003 [68302]=3,
7004 [68303]=3,
7005 [68304]=3,
7006 [68305]=3,
7007 [68306]=3,
7008 [68307]=2,
7009 [68308]=2,
7010 [68309]=2,
7011 [68310]=2,
7012 [68311]=1,
7013 [68312]=2,
7014 [68313]=2,
7015 [68314]=2,
7016 [68315]=2,
7017 [68316]=2,
7018 [68317]=3,
7019 [68318]=2,
7020 [68319]=2,
7021 [68320]=2,
7022 [68321]=3,
7023 [68322]=4,
7024 [68323]=4,
7025 [68324]=3,
7026 [68325]=5,
7027 [68326]=5,
7028 [68331]=2,
7029 [68332]=2,
7030 [68333]=2,
7031 [68334]=2,
7032 [68335]=3,
7033 [68480]=2,
7034 [68481]=3,
7035 [68482]=2,
7036 [68483]=3,
7037 [68484]=3,
7038 [68485]=3,
7039 [68486]=2,
7040 [68487]=2,
7041 [68488]=2,
7042 [68489]=3,
7043 [68490]=2,
7044 [68491]=2,
7045 [68492]=3,
7046 [68493]=2,
7047 [68494]=3,
7048 [68495]=3,
7049 [68496]=2,
7050 [68497]=3,
7051 [68521]=3,
7052 [68522]=3,
7053 [68523]=3,
7054 [68524]=3,
7055 [68525]=2,
7056 [68526]=2,
7057 [68527]=4,
7058 [68864]=1,
7059 [68865]=2,
7060 [68866]=2,
7061 [68867]=2,
7062 [68868]=2,
7063 [68869]=2,
7064 [68870]=2,
7065 [68871]=2,
7066 [68872]=2,
7067 [68873]=2,
7068 [68874]=2,
7069 [68875]=2,
7070 [68876]=2,
7071 [68877]=2,
7072 [68878]=2,
7073 [68879]=2,
7074 [68880]=2,
7075 [68881]=2,
7076 [68882]=2,
7077 [68883]=2,
7078 [68884]=2,
7079 [68885]=2,
7080 [68886]=2,
7081 [68887]=2,
7082 [68888]=2,
7083 [68889]=2,
7084 [68890]=2,
7085 [68891]=2,
7086 [68892]=2,
7087 [68893]=2,
7088 [68894]=2,
7089 [68895]=2,
7090 [68896]=2,
7091 [68897]=2,
7092 [68898]=3,
7093 [68899]=2,
7094 [68900]=5,
7095 [68901]=5,
7096 [68902]=5,
7097 [68903]=5,
7098 [69291]=5,
7099 [69292]=5,
7100 [69424]=2,
7101 [69425]=2,
7102 [69426]=2,
7103 [69427]=3,
7104 [69428]=2,
7105 [69429]=2,
7106 [69430]=2,
7107 [69431]=2,
7108 [69432]=2,
7109 [69433]=2,
7110 [69434]=2,
7111 [69435]=2,
7112 [69436]=2,
7113 [69437]=2,
7114 [69438]=2,
7115 [69439]=2,
7116 [69440]=2,
7117 [69441]=2,
7118 [69442]=2,
7119 [69443]=2,
7120 [69444]=2,
7121 [69445]=4,
7122 [69446]=5,
7123 [69447]=5,
7124 [69448]=5,
7125 [69449]=5,
7126 [69450]=5,
7127 [69451]=5,
7128 [69452]=5,
7129 [69453]=5,
7130 [69454]=5,
7131 [69455]=5,
7132 [69456]=5,
7133 [69457]=2,
7134 [69458]=2,
7135 [69459]=2,
7136 [69460]=3,
7137 [69488]=2,
7138 [69489]=2,
7139 [69490]=2,
7140 [69491]=2,
7141 [69492]=3,
7142 [69493]=3,
7143 [69494]=2,
7144 [69495]=2,
7145 [69496]=2,
7146 [69497]=2,
7147 [69498]=2,
7148 [69499]=2,
7149 [69500]=2,
7150 [69501]=2,
7151 [69502]=2,
7152 [69503]=2,
7153 [69504]=2,
7154 [69505]=2,
7155 [69506]=5,
7156 [69507]=5,
7157 [69508]=5,
7158 [69509]=5,
7159 [69552]=2,
7160 [69553]=4,
7161 [69554]=2,
7162 [69555]=2,
7163 [69556]=3,
7164 [69557]=3,
7165 [69558]=3,
7166 [69559]=4,
7167 [69560]=2,
7168 [69561]=3,
7169 [69562]=3,
7170 [69563]=2,
7171 [69564]=2,
7172 [69565]=3,
7173 [69566]=2,
7174 [69567]=2,
7175 [69568]=4,
7176 [69569]=2,
7177 [69570]=3,
7178 [69571]=3,
7179 [69572]=2,
7180 [69573]=4,
7181 [69574]=4,
7182 [69575]=4,
7183 [69576]=4,
7184 [69577]=3,
7185 [69578]=2,
7186 [69579]=1,
7187 [69633]=5,
7188 [69688]=5,
7189 [69689]=5,
7190 [69690]=5,
7191 [69691]=5,
7192 [69692]=5,
7193 [69693]=5,
7194 [69694]=5,
7195 [69695]=5,
7196 [69696]=5,
7197 [69697]=5,
7198 [69698]=5,
7199 [69699]=5,
7200 [69700]=5,
7201 [69701]=5,
7202 [69702]=5,
7203 [69744]=5,
7204 [69747]=5,
7205 [69748]=5,
7206 [69759]=5,
7207 [69760]=5,
7208 [69761]=5,
7209 [69811]=5,
7210 [69812]=5,
7211 [69813]=5,
7212 [69814]=5,
7213 [69817]=5,
7214 [69818]=5,
7215 [69821]=4,
7216 [69826]=5,
7217 [69837]=4,
7218 [69888]=5,
7219 [69889]=5,
7220 [69890]=5,
7221 [69927]=5,
7222 [69928]=5,
7223 [69929]=5,
7224 [69930]=5,
7225 [69931]=5,
7226 [69933]=5,
7227 [69934]=5,
7228 [69935]=5,
7229 [69936]=5,
7230 [69937]=5,
7231 [69938]=5,
7232 [69939]=5,
7233 [69940]=5,
7234 [70003]=5,
7235 [70016]=5,
7236 [70017]=5,
7237 [70070]=5,
7238 [70071]=5,
7239 [70072]=5,
7240 [70073]=5,
7241 [70074]=5,
7242 [70075]=5,
7243 [70076]=5,
7244 [70077]=5,
7245 [70078]=5,
7246 [70090]=5,
7247 [70091]=5,
7248 [70092]=5,
7249 [70095]=5,
7250 [70191]=5,
7251 [70192]=5,
7252 [70193]=5,
7253 [70196]=5,
7254 [70198]=5,
7255 [70199]=5,
7256 [70206]=5,
7257 [70367]=5,
7258 [70371]=5,
7259 [70372]=5,
7260 [70373]=5,
7261 [70374]=5,
7262 [70375]=5,
7263 [70376]=5,
7264 [70377]=5,
7265 [70378]=5,
7266 [70400]=5,
7267 [70401]=5,
7268 [70459]=5,
7269 [70460]=5,
7270 [70464]=5,
7271 [70502]=5,
7272 [70503]=5,
7273 [70504]=5,
7274 [70505]=5,
7275 [70506]=5,
7276 [70507]=5,
7277 [70508]=5,
7278 [70512]=5,
7279 [70513]=5,
7280 [70514]=5,
7281 [70515]=5,
7282 [70516]=5,
7283 [70712]=5,
7284 [70713]=5,
7285 [70714]=5,
7286 [70715]=5,
7287 [70716]=5,
7288 [70717]=5,
7289 [70718]=5,
7290 [70719]=5,
7291 [70722]=5,
7292 [70723]=5,
7293 [70724]=5,
7294 [70726]=5,
7295 [70750]=5,
7296 [70835]=5,
7297 [70836]=5,
7298 [70837]=5,
7299 [70838]=5,
7300 [70839]=5,
7301 [70840]=5,
7302 [70842]=5,
7303 [70847]=5,
7304 [70848]=5,
7305 [70850]=5,
7306 [70851]=5,
7307 [71090]=5,
7308 [71091]=5,
7309 [71092]=5,
7310 [71093]=5,
7311 [71100]=5,
7312 [71101]=5,
7313 [71103]=5,
7314 [71104]=5,
7315 [71132]=5,
7316 [71133]=5,
7317 [71219]=5,
7318 [71220]=5,
7319 [71221]=5,
7320 [71222]=5,
7321 [71223]=5,
7322 [71224]=5,
7323 [71225]=5,
7324 [71226]=5,
7325 [71229]=5,
7326 [71231]=5,
7327 [71232]=5,
7328 [71339]=5,
7329 [71341]=5,
7330 [71344]=5,
7331 [71345]=5,
7332 [71346]=5,
7333 [71347]=5,
7334 [71348]=5,
7335 [71349]=5,
7336 [71351]=5,
7337 [71453]=5,
7338 [71454]=5,
7339 [71455]=5,
7340 [71458]=5,
7341 [71459]=5,
7342 [71460]=5,
7343 [71461]=5,
7344 [71463]=5,
7345 [71464]=5,
7346 [71465]=5,
7347 [71466]=5,
7348 [71467]=5,
7349 [71727]=5,
7350 [71728]=5,
7351 [71729]=5,
7352 [71730]=5,
7353 [71731]=5,
7354 [71732]=5,
7355 [71733]=5,
7356 [71734]=5,
7357 [71735]=5,
7358 [71737]=5,
7359 [71738]=5,
7360 [71995]=5,
7361 [71996]=5,
7362 [71998]=5,
7363 [72003]=5,
7364 [72148]=5,
7365 [72149]=5,
7366 [72150]=5,
7367 [72151]=5,
7368 [72154]=5,
7369 [72155]=5,
7370 [72160]=5,
7371 [72193]=5,
7372 [72194]=5,
7373 [72195]=5,
7374 [72196]=5,
7375 [72197]=5,
7376 [72198]=5,
7377 [72201]=5,
7378 [72202]=5,
7379 [72243]=5,
7380 [72244]=5,
7381 [72245]=5,
7382 [72246]=5,
7383 [72247]=5,
7384 [72248]=5,
7385 [72251]=5,
7386 [72252]=5,
7387 [72253]=5,
7388 [72254]=5,
7389 [72263]=5,
7390 [72273]=5,
7391 [72274]=5,
7392 [72275]=5,
7393 [72276]=5,
7394 [72277]=5,
7395 [72278]=5,
7396 [72281]=5,
7397 [72282]=5,
7398 [72283]=5,
7399 [72330]=5,
7400 [72331]=5,
7401 [72332]=5,
7402 [72333]=5,
7403 [72334]=5,
7404 [72335]=5,
7405 [72336]=5,
7406 [72337]=5,
7407 [72338]=5,
7408 [72339]=5,
7409 [72340]=5,
7410 [72341]=5,
7411 [72342]=5,
7412 [72344]=5,
7413 [72345]=5,
7414 [72752]=5,
7415 [72753]=5,
7416 [72754]=5,
7417 [72755]=5,
7418 [72756]=5,
7419 [72757]=5,
7420 [72758]=5,
7421 [72760]=5,
7422 [72761]=5,
7423 [72762]=5,
7424 [72763]=5,
7425 [72764]=5,
7426 [72765]=5,
7427 [72767]=5,
7428 [72850]=5,
7429 [72851]=5,
7430 [72852]=5,
7431 [72853]=5,
7432 [72854]=5,
7433 [72855]=5,
7434 [72856]=5,
7435 [72857]=5,
7436 [72858]=5,
7437 [72859]=5,
7438 [72860]=5,
7439 [72861]=5,
7440 [72862]=5,
7441 [72863]=5,
7442 [72864]=5,
7443 [72865]=5,
7444 [72866]=5,
7445 [72867]=5,
7446 [72868]=5,
7447 [72869]=5,
7448 [72870]=5,
7449 [72871]=5,
7450 [72874]=5,
7451 [72875]=5,
7452 [72876]=5,
7453 [72877]=5,
7454 [72878]=5,
7455 [72879]=5,
7456 [72880]=5,
7457 [72882]=5,
7458 [72883]=5,
7459 [72885]=5,
7460 [72886]=5,
7461 [73009]=5,
7462 [73010]=5,
7463 [73011]=5,
7464 [73012]=5,
7465 [73013]=5,
7466 [73014]=5,
7467 [73018]=5,
7468 [73020]=5,
7469 [73021]=5,
7470 [73023]=5,
7471 [73024]=5,
7472 [73025]=5,
7473 [73026]=5,
7474 [73027]=5,
7475 [73028]=5,
7476 [73029]=5,
7477 [73031]=5,
7478 [73104]=5,
7479 [73105]=5,
7480 [73109]=5,
7481 [73111]=5,
7482 [73459]=5,
7483 [73460]=5,
7484 [92912]=5,
7485 [92913]=5,
7486 [92914]=5,
7487 [92915]=5,
7488 [92916]=5,
7489 [92976]=5,
7490 [92977]=5,
7491 [92978]=5,
7492 [92979]=5,
7493 [92980]=5,
7494 [92981]=5,
7495 [92982]=5,
7496 [94031]=5,
7497 [94095]=5,
7498 [94096]=5,
7499 [94097]=5,
7500 [94098]=5,
7501 [94180]=5,
7502 [113821]=5,
7503 [113822]=5,
7504 [118528]=5,
7505 [118529]=5,
7506 [118530]=5,
7507 [118531]=5,
7508 [118532]=5,
7509 [118533]=5,
7510 [118534]=5,
7511 [118535]=5,
7512 [118536]=5,
7513 [118537]=5,
7514 [118538]=5,
7515 [118539]=5,
7516 [118540]=5,
7517 [118541]=5,
7518 [118542]=5,
7519 [118543]=5,
7520 [118544]=5,
7521 [118545]=5,
7522 [118546]=5,
7523 [118547]=5,
7524 [118548]=5,
7525 [118549]=5,
7526 [118550]=5,
7527 [118551]=5,
7528 [118552]=5,
7529 [118553]=5,
7530 [118554]=5,
7531 [118555]=5,
7532 [118556]=5,
7533 [118557]=5,
7534 [118558]=5,
7535 [118559]=5,
7536 [118560]=5,
7537 [118561]=5,
7538 [118562]=5,
7539 [118563]=5,
7540 [118564]=5,
7541 [118565]=5,
7542 [118566]=5,
7543 [118567]=5,
7544 [118568]=5,
7545 [118569]=5,
7546 [118570]=5,
7547 [118571]=5,
7548 [118572]=5,
7549 [118573]=5,
7550 [118576]=5,
7551 [118577]=5,
7552 [118578]=5,
7553 [118579]=5,
7554 [118580]=5,
7555 [118581]=5,
7556 [118582]=5,
7557 [118583]=5,
7558 [118584]=5,
7559 [118585]=5,
7560 [118586]=5,
7561 [118587]=5,
7562 [118588]=5,
7563 [118589]=5,
7564 [118590]=5,
7565 [118591]=5,
7566 [118592]=5,
7567 [118593]=5,
7568 [118594]=5,
7569 [118595]=5,
7570 [118596]=5,
7571 [118597]=5,
7572 [118598]=5,
7573 [119143]=5,
7574 [119144]=5,
7575 [119145]=5,
7576 [119163]=5,
7577 [119164]=5,
7578 [119165]=5,
7579 [119166]=5,
7580 [119167]=5,
7581 [119168]=5,
7582 [119169]=5,
7583 [119170]=5,
7584 [119173]=5,
7585 [119174]=5,
7586 [119175]=5,
7587 [119176]=5,
7588 [119177]=5,
7589 [119178]=5,
7590 [119179]=5,
7591 [119210]=5,
7592 [119211]=5,
7593 [119212]=5,
7594 [119213]=5,
7595 [119362]=5,
7596 [119363]=5,
7597 [119364]=5,
7598 [121344]=5,
7599 [121345]=5,
7600 [121346]=5,
7601 [121347]=5,
7602 [121348]=5,
7603 [121349]=5,
7604 [121350]=5,
7605 [121351]=5,
7606 [121352]=5,
7607 [121353]=5,
7608 [121354]=5,
7609 [121355]=5,
7610 [121356]=5,
7611 [121357]=5,
7612 [121358]=5,
7613 [121359]=5,
7614 [121360]=5,
7615 [121361]=5,
7616 [121362]=5,
7617 [121363]=5,
7618 [121364]=5,
7619 [121365]=5,
7620 [121366]=5,
7621 [121367]=5,
7622 [121368]=5,
7623 [121369]=5,
7624 [121370]=5,
7625 [121371]=5,
7626 [121372]=5,
7627 [121373]=5,
7628 [121374]=5,
7629 [121375]=5,
7630 [121376]=5,
7631 [121377]=5,
7632 [121378]=5,
7633 [121379]=5,
7634 [121380]=5,
7635 [121381]=5,
7636 [121382]=5,
7637 [121383]=5,
7638 [121384]=5,
7639 [121385]=5,
7640 [121386]=5,
7641 [121387]=5,
7642 [121388]=5,
7643 [121389]=5,
7644 [121390]=5,
7645 [121391]=5,
7646 [121392]=5,
7647 [121393]=5,
7648 [121394]=5,
7649 [121395]=5,
7650 [121396]=5,
7651 [121397]=5,
7652 [121398]=5,
7653 [121403]=5,
7654 [121404]=5,
7655 [121405]=5,
7656 [121406]=5,
7657 [121407]=5,
7658 [121408]=5,
7659 [121409]=5,
7660 [121410]=5,
7661 [121411]=5,
7662 [121412]=5,
7663 [121413]=5,
7664 [121414]=5,
7665 [121415]=5,
7666 [121416]=5,
7667 [121417]=5,
7668 [121418]=5,
7669 [121419]=5,
7670 [121420]=5,
7671 [121421]=5,
7672 [121422]=5,
7673 [121423]=5,
7674 [121424]=5,
7675 [121425]=5,
7676 [121426]=5,
7677 [121427]=5,
7678 [121428]=5,
7679 [121429]=5,
7680 [121430]=5,
7681 [121431]=5,
7682 [121432]=5,
7683 [121433]=5,
7684 [121434]=5,
7685 [121435]=5,
7686 [121436]=5,
7687 [121437]=5,
7688 [121438]=5,
7689 [121439]=5,
7690 [121440]=5,
7691 [121441]=5,
7692 [121442]=5,
7693 [121443]=5,
7694 [121444]=5,
7695 [121445]=5,
7696 [121446]=5,
7697 [121447]=5,
7698 [121448]=5,
7699 [121449]=5,
7700 [121450]=5,
7701 [121451]=5,
7702 [121452]=5,
7703 [121461]=5,
7704 [121476]=5,
7705 [121499]=5,
7706 [121500]=5,
7707 [121501]=5,
7708 [121502]=5,
7709 [121503]=5,
7710 [121505]=5,
7711 [121506]=5,
7712 [121507]=5,
7713 [121508]=5,
7714 [121509]=5,
7715 [121510]=5,
7716 [121511]=5,
7717 [121512]=5,
7718 [121513]=5,
7719 [121514]=5,
7720 [121515]=5,
7721 [121516]=5,
7722 [121517]=5,
7723 [121518]=5,
7724 [121519]=5,
7725 [122880]=5,
7726 [122881]=5,
7727 [122882]=5,
7728 [122883]=5,
7729 [122884]=5,
7730 [122885]=5,
7731 [122886]=5,
7732 [122888]=5,
7733 [122889]=5,
7734 [122890]=5,
7735 [122891]=5,
7736 [122892]=5,
7737 [122893]=5,
7738 [122894]=5,
7739 [122895]=5,
7740 [122896]=5,
7741 [122897]=5,
7742 [122898]=5,
7743 [122899]=5,
7744 [122900]=5,
7745 [122901]=5,
7746 [122902]=5,
7747 [122903]=5,
7748 [122904]=5,
7749 [122907]=5,
7750 [122908]=5,
7751 [122909]=5,
7752 [122910]=5,
7753 [122911]=5,
7754 [122912]=5,
7755 [122913]=5,
7756 [122915]=5,
7757 [122916]=5,
7758 [122918]=5,
7759 [122919]=5,
7760 [122920]=5,
7761 [122921]=5,
7762 [122922]=5,
7763 [123184]=5,
7764 [123185]=5,
7765 [123186]=5,
7766 [123187]=5,
7767 [123188]=5,
7768 [123189]=5,
7769 [123190]=5,
7770 [123566]=5,
7771 [123628]=5,
7772 [123629]=5,
7773 [123630]=5,
7774 [123631]=5,
7775 [125136]=5,
7776 [125137]=5,
7777 [125138]=5,
7778 [125139]=5,
7779 [125140]=5,
7780 [125141]=5,
7781 [125142]=5,
7782 [125184]=2,
7783 [125185]=2,
7784 [125186]=2,
7785 [125187]=2,
7786 [125188]=2,
7787 [125189]=2,
7788 [125190]=2,
7789 [125191]=2,
7790 [125192]=2,
7791 [125193]=2,
7792 [125194]=2,
7793 [125195]=2,
7794 [125196]=2,
7795 [125197]=2,
7796 [125198]=2,
7797 [125199]=2,
7798 [125200]=2,
7799 [125201]=2,
7800 [125202]=2,
7801 [125203]=2,
7802 [125204]=2,
7803 [125205]=2,
7804 [125206]=2,
7805 [125207]=2,
7806 [125208]=2,
7807 [125209]=2,
7808 [125210]=2,
7809 [125211]=2,
7810 [125212]=2,
7811 [125213]=2,
7812 [125214]=2,
7813 [125215]=2,
7814 [125216]=2,
7815 [125217]=2,
7816 [125218]=2,
7817 [125219]=2,
7818 [125220]=2,
7819 [125221]=2,
7820 [125222]=2,
7821 [125223]=2,
7822 [125224]=2,
7823 [125225]=2,
7824 [125226]=2,
7825 [125227]=2,
7826 [125228]=2,
7827 [125229]=2,
7828 [125230]=2,
7829 [125231]=2,
7830 [125232]=2,
7831 [125233]=2,
7832 [125234]=2,
7833 [125235]=2,
7834 [125236]=2,
7835 [125237]=2,
7836 [125238]=2,
7837 [125239]=2,
7838 [125240]=2,
7839 [125241]=2,
7840 [125242]=2,
7841 [125243]=2,
7842 [125244]=2,
7843 [125245]=2,
7844 [125246]=2,
7845 [125247]=2,
7846 [125248]=2,
7847 [125249]=2,
7848 [125250]=2,
7849 [125251]=2,
7850 [125252]=5,
7851 [125253]=5,
7852 [125254]=5,
7853 [125255]=5,
7854 [125256]=5,
7855 [125257]=5,
7856 [125258]=5,
7857 [1042752]=5,
7858 }
7859 characters.indicgroups={
7860 ["above_mark"]={
7861 [2304]=true,
7862 [2305]=true,
7863 [2306]=true,
7864 [2362]=true,
7865 [2373]=true,
7866 [2374]=true,
7867 [2375]=true,
7868 [2376]=true,
7869 [2385]=true,
7870 [2387]=true,
7871 [2388]=true,
7872 [2389]=true,
7873 [2631]=true,
7874 [2632]=true,
7875 [2635]=true,
7876 [2636]=true,
7877 [2690]=true,
7878 [2757]=true,
7879 [2759]=true,
7880 [2760]=true,
7881 [2879]=true,
7882 [3008]=true,
7883 [3021]=true,
7884 [3134]=true,
7885 [3135]=true,
7886 [3136]=true,
7887 [3142]=true,
7888 [3143]=true,
7889 [3146]=true,
7890 [3147]=true,
7891 [3148]=true,
7892 [3149]=true,
7893 [3263]=true,
7894 [3270]=true,
7895 [3406]=true,
7896 [4141]=true,
7897 [4142]=true,
7898 [4146]=true,
7899 [4147]=true,
7900 [4148]=true,
7901 [4149]=true,
7902 [4150]=true,
7903 [4154]=true,
7904 [4209]=true,
7905 [4210]=true,
7906 [4211]=true,
7907 [4212]=true,
7908 [4229]=true,
7909 [4230]=true,
7910 [4253]=true,
7911 [43232]=true,
7912 [43233]=true,
7913 [43234]=true,
7914 [43235]=true,
7915 [43236]=true,
7916 [43237]=true,
7917 [43238]=true,
7918 [43239]=true,
7919 [43240]=true,
7920 [43241]=true,
7921 [43242]=true,
7922 [43243]=true,
7923 [43244]=true,
7924 [43245]=true,
7925 [43246]=true,
7926 [43247]=true,
7927 [43248]=true,
7928 [43249]=true,
7929 [43493]=true,
7930 [43644]=true,
7931 },
7932 ["after_half"]={},
7933 ["after_main"]={
7934 [2864]=true,
7935 [2879]=true,
7936 [2902]=true,
7937 [3376]=true,
7938 [5901]=true,
7939 },
7940 ["after_postscript"]={
7941 [2433]=true,
7942 [2494]=true,
7943 [2496]=true,
7944 [2519]=true,
7945 [2561]=true,
7946 [2562]=true,
7947 [2622]=true,
7948 [2624]=true,
7949 [2625]=true,
7950 [2626]=true,
7951 [2672]=true,
7952 [2673]=true,
7953 [2735]=true,
7954 [2750]=true,
7955 [2752]=true,
7956 [2753]=true,
7957 [2754]=true,
7958 [2755]=true,
7959 [2756]=true,
7960 [2761]=true,
7961 [2763]=true,
7962 [2764]=true,
7963 [2786]=true,
7964 [2787]=true,
7965 [2878]=true,
7966 [2880]=true,
7967 [2903]=true,
7968 [2992]=true,
7969 [3006]=true,
7970 [3007]=true,
7971 [3009]=true,
7972 [3010]=true,
7973 [3031]=true,
7974 [3120]=true,
7975 [3248]=true,
7976 [3390]=true,
7977 [3391]=true,
7978 [3392]=true,
7979 [3393]=true,
7980 [3394]=true,
7981 [3395]=true,
7982 [3415]=true,
7983 },
7984 ["after_subscript"]={
7985 [2366]=true,
7986 [2368]=true,
7987 [2369]=true,
7988 [2370]=true,
7989 [2371]=true,
7990 [2372]=true,
7991 [2373]=true,
7992 [2374]=true,
7993 [2375]=true,
7994 [2376]=true,
7995 [2377]=true,
7996 [2378]=true,
7997 [2379]=true,
7998 [2380]=true,
7999 [2402]=true,
8000 [2403]=true,
8001 [2480]=true,
8002 [2497]=true,
8003 [2498]=true,
8004 [2499]=true,
8005 [2500]=true,
8006 [2530]=true,
8007 [2531]=true,
8008 [2544]=true,
8009 [2631]=true,
8010 [2632]=true,
8011 [2635]=true,
8012 [2636]=true,
8013 [2757]=true,
8014 [2759]=true,
8015 [2760]=true,
8016 [2881]=true,
8017 [2882]=true,
8018 [2883]=true,
8019 [3008]=true,
8020 [3139]=true,
8021 [3140]=true,
8022 [3267]=true,
8023 [3268]=true,
8024 [3285]=true,
8025 [3286]=true,
8026 },
8027 ["anudatta"]={
8028 [2386]=true,
8029 },
8030 ["before_half"]={
8031 [2367]=true,
8032 [2382]=true,
8033 [2495]=true,
8034 [2503]=true,
8035 [2504]=true,
8036 [2623]=true,
8037 [2751]=true,
8038 [2887]=true,
8039 },
8040 ["before_main"]={
8041 [3014]=true,
8042 [3015]=true,
8043 [3016]=true,
8044 [3398]=true,
8045 [3399]=true,
8046 [3400]=true,
8047 },
8048 ["before_postscript"]={
8049 [2352]=true,
8050 [2736]=true,
8051 },
8052 ["before_subscript"]={
8053 [2608]=true,
8054 [2817]=true,
8055 [3134]=true,
8056 [3135]=true,
8057 [3136]=true,
8058 [3137]=true,
8059 [3138]=true,
8060 [3142]=true,
8061 [3143]=true,
8062 [3146]=true,
8063 [3147]=true,
8064 [3148]=true,
8065 [3157]=true,
8066 [3158]=true,
8067 [3262]=true,
8068 [3263]=true,
8069 [3265]=true,
8070 [3266]=true,
8071 [3270]=true,
8072 [3276]=true,
8073 [3298]=true,
8074 [3299]=true,
8075 },
8076 ["below_mark"]={
8077 [2364]=true,
8078 [2369]=true,
8079 [2370]=true,
8080 [2371]=true,
8081 [2372]=true,
8082 [2381]=true,
8083 [2386]=true,
8084 [2390]=true,
8085 [2391]=true,
8086 [2402]=true,
8087 [2403]=true,
8088 [2492]=true,
8089 [2497]=true,
8090 [2498]=true,
8091 [2499]=true,
8092 [2500]=true,
8093 [2509]=true,
8094 [2620]=true,
8095 [2625]=true,
8096 [2626]=true,
8097 [2637]=true,
8098 [2748]=true,
8099 [2753]=true,
8100 [2754]=true,
8101 [2755]=true,
8102 [2756]=true,
8103 [2765]=true,
8104 [2876]=true,
8105 [2881]=true,
8106 [2882]=true,
8107 [2883]=true,
8108 [2884]=true,
8109 [2893]=true,
8110 [2914]=true,
8111 [2915]=true,
8112 [3009]=true,
8113 [3010]=true,
8114 [3132]=true,
8115 [3170]=true,
8116 [3171]=true,
8117 [3260]=true,
8118 [3286]=true,
8119 [3298]=true,
8120 [3299]=true,
8121 [3426]=true,
8122 [3427]=true,
8123 [4143]=true,
8124 [4144]=true,
8125 [4151]=true,
8126 [4153]=true,
8127 [4157]=true,
8128 [4158]=true,
8129 [4184]=true,
8130 [4185]=true,
8131 [4190]=true,
8132 [4191]=true,
8133 [4192]=true,
8134 [4226]=true,
8135 [4237]=true,
8136 },
8137 ["consonant"]={
8138 [2325]=true,
8139 [2326]=true,
8140 [2327]=true,
8141 [2328]=true,
8142 [2329]=true,
8143 [2330]=true,
8144 [2331]=true,
8145 [2332]=true,
8146 [2333]=true,
8147 [2334]=true,
8148 [2335]=true,
8149 [2336]=true,
8150 [2337]=true,
8151 [2338]=true,
8152 [2339]=true,
8153 [2340]=true,
8154 [2341]=true,
8155 [2342]=true,
8156 [2343]=true,
8157 [2344]=true,
8158 [2345]=true,
8159 [2346]=true,
8160 [2347]=true,
8161 [2348]=true,
8162 [2349]=true,
8163 [2350]=true,
8164 [2351]=true,
8165 [2352]=true,
8166 [2353]=true,
8167 [2354]=true,
8168 [2355]=true,
8169 [2356]=true,
8170 [2357]=true,
8171 [2358]=true,
8172 [2359]=true,
8173 [2360]=true,
8174 [2361]=true,
8175 [2392]=true,
8176 [2393]=true,
8177 [2394]=true,
8178 [2395]=true,
8179 [2396]=true,
8180 [2397]=true,
8181 [2398]=true,
8182 [2399]=true,
8183 [2424]=true,
8184 [2425]=true,
8185 [2426]=true,
8186 [2453]=true,
8187 [2454]=true,
8188 [2455]=true,
8189 [2456]=true,
8190 [2457]=true,
8191 [2458]=true,
8192 [2459]=true,
8193 [2460]=true,
8194 [2461]=true,
8195 [2462]=true,
8196 [2463]=true,
8197 [2464]=true,
8198 [2465]=true,
8199 [2466]=true,
8200 [2467]=true,
8201 [2468]=true,
8202 [2469]=true,
8203 [2470]=true,
8204 [2471]=true,
8205 [2472]=true,
8206 [2474]=true,
8207 [2475]=true,
8208 [2476]=true,
8209 [2477]=true,
8210 [2478]=true,
8211 [2479]=true,
8212 [2480]=true,
8213 [2482]=true,
8214 [2486]=true,
8215 [2487]=true,
8216 [2488]=true,
8217 [2489]=true,
8218 [2510]=true,
8219 [2524]=true,
8220 [2525]=true,
8221 [2527]=true,
8222 [2581]=true,
8223 [2582]=true,
8224 [2583]=true,
8225 [2584]=true,
8226 [2585]=true,
8227 [2586]=true,
8228 [2587]=true,
8229 [2588]=true,
8230 [2589]=true,
8231 [2590]=true,
8232 [2591]=true,
8233 [2592]=true,
8234 [2593]=true,
8235 [2594]=true,
8236 [2595]=true,
8237 [2596]=true,
8238 [2597]=true,
8239 [2598]=true,
8240 [2599]=true,
8241 [2600]=true,
8242 [2602]=true,
8243 [2603]=true,
8244 [2604]=true,
8245 [2605]=true,
8246 [2606]=true,
8247 [2607]=true,
8248 [2608]=true,
8249 [2610]=true,
8250 [2611]=true,
8251 [2613]=true,
8252 [2614]=true,
8253 [2616]=true,
8254 [2617]=true,
8255 [2649]=true,
8256 [2650]=true,
8257 [2651]=true,
8258 [2652]=true,
8259 [2654]=true,
8260 [2709]=true,
8261 [2710]=true,
8262 [2711]=true,
8263 [2712]=true,
8264 [2713]=true,
8265 [2714]=true,
8266 [2715]=true,
8267 [2716]=true,
8268 [2717]=true,
8269 [2718]=true,
8270 [2719]=true,
8271 [2720]=true,
8272 [2721]=true,
8273 [2722]=true,
8274 [2723]=true,
8275 [2724]=true,
8276 [2725]=true,
8277 [2726]=true,
8278 [2727]=true,
8279 [2728]=true,
8280 [2730]=true,
8281 [2731]=true,
8282 [2732]=true,
8283 [2733]=true,
8284 [2734]=true,
8285 [2735]=true,
8286 [2736]=true,
8287 [2738]=true,
8288 [2739]=true,
8289 [2741]=true,
8290 [2742]=true,
8291 [2743]=true,
8292 [2744]=true,
8293 [2745]=true,
8294 [2837]=true,
8295 [2838]=true,
8296 [2839]=true,
8297 [2840]=true,
8298 [2841]=true,
8299 [2842]=true,
8300 [2843]=true,
8301 [2844]=true,
8302 [2845]=true,
8303 [2846]=true,
8304 [2847]=true,
8305 [2848]=true,
8306 [2849]=true,
8307 [2850]=true,
8308 [2851]=true,
8309 [2852]=true,
8310 [2853]=true,
8311 [2854]=true,
8312 [2855]=true,
8313 [2856]=true,
8314 [2858]=true,
8315 [2859]=true,
8316 [2860]=true,
8317 [2861]=true,
8318 [2862]=true,
8319 [2863]=true,
8320 [2864]=true,
8321 [2866]=true,
8322 [2867]=true,
8323 [2869]=true,
8324 [2870]=true,
8325 [2871]=true,
8326 [2872]=true,
8327 [2873]=true,
8328 [2908]=true,
8329 [2909]=true,
8330 [2929]=true,
8331 [2965]=true,
8332 [2969]=true,
8333 [2970]=true,
8334 [2972]=true,
8335 [2974]=true,
8336 [2975]=true,
8337 [2979]=true,
8338 [2980]=true,
8339 [2984]=true,
8340 [2985]=true,
8341 [2986]=true,
8342 [2990]=true,
8343 [2991]=true,
8344 [2992]=true,
8345 [2993]=true,
8346 [2994]=true,
8347 [2995]=true,
8348 [2996]=true,
8349 [2997]=true,
8350 [2998]=true,
8351 [2999]=true,
8352 [3000]=true,
8353 [3001]=true,
8354 [3093]=true,
8355 [3094]=true,
8356 [3095]=true,
8357 [3096]=true,
8358 [3097]=true,
8359 [3098]=true,
8360 [3099]=true,
8361 [3100]=true,
8362 [3101]=true,
8363 [3102]=true,
8364 [3103]=true,
8365 [3104]=true,
8366 [3105]=true,
8367 [3106]=true,
8368 [3107]=true,
8369 [3108]=true,
8370 [3109]=true,
8371 [3110]=true,
8372 [3111]=true,
8373 [3112]=true,
8374 [3114]=true,
8375 [3115]=true,
8376 [3116]=true,
8377 [3117]=true,
8378 [3118]=true,
8379 [3119]=true,
8380 [3120]=true,
8381 [3121]=true,
8382 [3122]=true,
8383 [3123]=true,
8384 [3124]=true,
8385 [3125]=true,
8386 [3126]=true,
8387 [3127]=true,
8388 [3128]=true,
8389 [3129]=true,
8390 [3133]=true,
8391 [3221]=true,
8392 [3222]=true,
8393 [3223]=true,
8394 [3224]=true,
8395 [3225]=true,
8396 [3226]=true,
8397 [3227]=true,
8398 [3228]=true,
8399 [3229]=true,
8400 [3230]=true,
8401 [3231]=true,
8402 [3232]=true,
8403 [3233]=true,
8404 [3234]=true,
8405 [3235]=true,
8406 [3236]=true,
8407 [3237]=true,
8408 [3238]=true,
8409 [3239]=true,
8410 [3240]=true,
8411 [3242]=true,
8412 [3243]=true,
8413 [3244]=true,
8414 [3245]=true,
8415 [3246]=true,
8416 [3247]=true,
8417 [3248]=true,
8418 [3249]=true,
8419 [3250]=true,
8420 [3251]=true,
8421 [3253]=true,
8422 [3254]=true,
8423 [3255]=true,
8424 [3256]=true,
8425 [3257]=true,
8426 [3294]=true,
8427 [3349]=true,
8428 [3350]=true,
8429 [3351]=true,
8430 [3352]=true,
8431 [3353]=true,
8432 [3354]=true,
8433 [3355]=true,
8434 [3356]=true,
8435 [3357]=true,
8436 [3358]=true,
8437 [3359]=true,
8438 [3360]=true,
8439 [3361]=true,
8440 [3362]=true,
8441 [3363]=true,
8442 [3364]=true,
8443 [3365]=true,
8444 [3366]=true,
8445 [3367]=true,
8446 [3368]=true,
8447 [3369]=true,
8448 [3370]=true,
8449 [3371]=true,
8450 [3372]=true,
8451 [3373]=true,
8452 [3374]=true,
8453 [3375]=true,
8454 [3376]=true,
8455 [3377]=true,
8456 [3378]=true,
8457 [3379]=true,
8458 [3380]=true,
8459 [3381]=true,
8460 [3382]=true,
8461 [3383]=true,
8462 [3384]=true,
8463 [3385]=true,
8464 [3386]=true,
8465 [4096]=true,
8466 [4097]=true,
8467 [4098]=true,
8468 [4099]=true,
8469 [4100]=true,
8470 [4101]=true,
8471 [4102]=true,
8472 [4103]=true,
8473 [4104]=true,
8474 [4105]=true,
8475 [4106]=true,
8476 [4107]=true,
8477 [4108]=true,
8478 [4109]=true,
8479 [4110]=true,
8480 [4111]=true,
8481 [4112]=true,
8482 [4113]=true,
8483 [4114]=true,
8484 [4115]=true,
8485 [4116]=true,
8486 [4117]=true,
8487 [4118]=true,
8488 [4119]=true,
8489 [4120]=true,
8490 [4121]=true,
8491 [4122]=true,
8492 [4123]=true,
8493 [4124]=true,
8494 [4125]=true,
8495 [4126]=true,
8496 [4127]=true,
8497 [4128]=true,
8498 [4155]=true,
8499 [4156]=true,
8500 [4157]=true,
8501 [4158]=true,
8502 [4159]=true,
8503 [4176]=true,
8504 [4177]=true,
8505 [4186]=true,
8506 [4187]=true,
8507 [4188]=true,
8508 [4189]=true,
8509 [4190]=true,
8510 [4191]=true,
8511 [4192]=true,
8512 [4193]=true,
8513 [4197]=true,
8514 [4198]=true,
8515 [4206]=true,
8516 [4207]=true,
8517 [4208]=true,
8518 [4213]=true,
8519 [4214]=true,
8520 [4215]=true,
8521 [4216]=true,
8522 [4217]=true,
8523 [4218]=true,
8524 [4219]=true,
8525 [4220]=true,
8526 [4221]=true,
8527 [4222]=true,
8528 [4223]=true,
8529 [4224]=true,
8530 [4225]=true,
8531 [4226]=true,
8532 [4238]=true,
8533 [5901]=true,
8534 [43488]=true,
8535 [43489]=true,
8536 [43490]=true,
8537 [43491]=true,
8538 [43492]=true,
8539 [43495]=true,
8540 [43496]=true,
8541 [43497]=true,
8542 [43498]=true,
8543 [43499]=true,
8544 [43500]=true,
8545 [43501]=true,
8546 [43502]=true,
8547 [43503]=true,
8548 [43514]=true,
8549 [43515]=true,
8550 [43516]=true,
8551 [43517]=true,
8552 [43518]=true,
8553 [43616]=true,
8554 [43617]=true,
8555 [43618]=true,
8556 [43619]=true,
8557 [43620]=true,
8558 [43621]=true,
8559 [43622]=true,
8560 [43623]=true,
8561 [43624]=true,
8562 [43625]=true,
8563 [43626]=true,
8564 [43628]=true,
8565 [43629]=true,
8566 [43630]=true,
8567 [43631]=true,
8568 [43633]=true,
8569 [43634]=true,
8570 [43635]=true,
8571 [43636]=true,
8572 [43637]=true,
8573 [43638]=true,
8574 [43642]=true,
8575 [43646]=true,
8576 [43647]=true,
8577 },
8578 ["dependent_vowel"]={
8579 [2362]=true,
8580 [2363]=true,
8581 [2366]=true,
8582 [2367]=true,
8583 [2368]=true,
8584 [2369]=true,
8585 [2370]=true,
8586 [2371]=true,
8587 [2372]=true,
8588 [2373]=true,
8589 [2374]=true,
8590 [2375]=true,
8591 [2376]=true,
8592 [2377]=true,
8593 [2378]=true,
8594 [2379]=true,
8595 [2380]=true,
8596 [2382]=true,
8597 [2383]=true,
8598 [2389]=true,
8599 [2390]=true,
8600 [2391]=true,
8601 [2402]=true,
8602 [2403]=true,
8603 [2494]=true,
8604 [2495]=true,
8605 [2497]=true,
8606 [2498]=true,
8607 [2499]=true,
8608 [2500]=true,
8609 [2503]=true,
8610 [2504]=true,
8611 [2507]=true,
8612 [2508]=true,
8613 [2622]=true,
8614 [2623]=true,
8615 [2624]=true,
8616 [2625]=true,
8617 [2626]=true,
8618 [2631]=true,
8619 [2632]=true,
8620 [2635]=true,
8621 [2636]=true,
8622 [2750]=true,
8623 [2751]=true,
8624 [2752]=true,
8625 [2753]=true,
8626 [2754]=true,
8627 [2755]=true,
8628 [2756]=true,
8629 [2757]=true,
8630 [2759]=true,
8631 [2760]=true,
8632 [2761]=true,
8633 [2763]=true,
8634 [2764]=true,
8635 [2878]=true,
8636 [2879]=true,
8637 [2880]=true,
8638 [2881]=true,
8639 [2882]=true,
8640 [2883]=true,
8641 [2884]=true,
8642 [2887]=true,
8643 [2888]=true,
8644 [2891]=true,
8645 [2892]=true,
8646 [2914]=true,
8647 [2915]=true,
8648 [3006]=true,
8649 [3007]=true,
8650 [3008]=true,
8651 [3009]=true,
8652 [3010]=true,
8653 [3014]=true,
8654 [3015]=true,
8655 [3016]=true,
8656 [3018]=true,
8657 [3019]=true,
8658 [3020]=true,
8659 [3134]=true,
8660 [3135]=true,
8661 [3136]=true,
8662 [3137]=true,
8663 [3138]=true,
8664 [3139]=true,
8665 [3140]=true,
8666 [3142]=true,
8667 [3143]=true,
8668 [3144]=true,
8669 [3146]=true,
8670 [3147]=true,
8671 [3148]=true,
8672 [3170]=true,
8673 [3171]=true,
8674 [3262]=true,
8675 [3263]=true,
8676 [3264]=true,
8677 [3265]=true,
8678 [3266]=true,
8679 [3267]=true,
8680 [3268]=true,
8681 [3270]=true,
8682 [3271]=true,
8683 [3272]=true,
8684 [3274]=true,
8685 [3275]=true,
8686 [3276]=true,
8687 [3285]=true,
8688 [3286]=true,
8689 [3298]=true,
8690 [3299]=true,
8691 [3390]=true,
8692 [3391]=true,
8693 [3392]=true,
8694 [3393]=true,
8695 [3394]=true,
8696 [3395]=true,
8697 [3396]=true,
8698 [3398]=true,
8699 [3399]=true,
8700 [3400]=true,
8701 [3402]=true,
8702 [3403]=true,
8703 [3404]=true,
8704 [3415]=true,
8705 [3426]=true,
8706 [3427]=true,
8707 [4139]=true,
8708 [4140]=true,
8709 [4141]=true,
8710 [4142]=true,
8711 [4143]=true,
8712 [4144]=true,
8713 [4145]=true,
8714 [4146]=true,
8715 [4147]=true,
8716 [4148]=true,
8717 [4149]=true,
8718 [4182]=true,
8719 [4183]=true,
8720 [4184]=true,
8721 [4185]=true,
8722 [4194]=true,
8723 [4199]=true,
8724 [4200]=true,
8725 [4209]=true,
8726 [4210]=true,
8727 [4211]=true,
8728 [4212]=true,
8729 [4227]=true,
8730 [4228]=true,
8731 [4229]=true,
8732 [4230]=true,
8733 [4252]=true,
8734 [4253]=true,
8735 [43493]=true,
8736 },
8737 ["halant"]={
8738 [2381]=true,
8739 [2509]=true,
8740 [2637]=true,
8741 [2765]=true,
8742 [2893]=true,
8743 [3021]=true,
8744 [3149]=true,
8745 [3277]=true,
8746 [3405]=true,
8747 },
8748 ["independent_vowel"]={
8749 [2308]=true,
8750 [2309]=true,
8751 [2310]=true,
8752 [2311]=true,
8753 [2312]=true,
8754 [2313]=true,
8755 [2314]=true,
8756 [2315]=true,
8757 [2316]=true,
8758 [2317]=true,
8759 [2318]=true,
8760 [2319]=true,
8761 [2320]=true,
8762 [2321]=true,
8763 [2322]=true,
8764 [2323]=true,
8765 [2324]=true,
8766 [2400]=true,
8767 [2401]=true,
8768 [2418]=true,
8769 [2419]=true,
8770 [2420]=true,
8771 [2421]=true,
8772 [2422]=true,
8773 [2423]=true,
8774 [2437]=true,
8775 [2438]=true,
8776 [2439]=true,
8777 [2440]=true,
8778 [2441]=true,
8779 [2442]=true,
8780 [2443]=true,
8781 [2444]=true,
8782 [2447]=true,
8783 [2448]=true,
8784 [2451]=true,
8785 [2452]=true,
8786 [2528]=true,
8787 [2529]=true,
8788 [2530]=true,
8789 [2531]=true,
8790 [2565]=true,
8791 [2566]=true,
8792 [2567]=true,
8793 [2568]=true,
8794 [2569]=true,
8795 [2570]=true,
8796 [2575]=true,
8797 [2576]=true,
8798 [2579]=true,
8799 [2580]=true,
8800 [2693]=true,
8801 [2694]=true,
8802 [2695]=true,
8803 [2696]=true,
8804 [2697]=true,
8805 [2698]=true,
8806 [2699]=true,
8807 [2700]=true,
8808 [2701]=true,
8809 [2703]=true,
8810 [2704]=true,
8811 [2705]=true,
8812 [2707]=true,
8813 [2708]=true,
8814 [2784]=true,
8815 [2785]=true,
8816 [2786]=true,
8817 [2787]=true,
8818 [2821]=true,
8819 [2822]=true,
8820 [2823]=true,
8821 [2824]=true,
8822 [2825]=true,
8823 [2826]=true,
8824 [2827]=true,
8825 [2828]=true,
8826 [2831]=true,
8827 [2832]=true,
8828 [2835]=true,
8829 [2836]=true,
8830 [2912]=true,
8831 [2913]=true,
8832 [2949]=true,
8833 [2950]=true,
8834 [2951]=true,
8835 [2952]=true,
8836 [2953]=true,
8837 [2954]=true,
8838 [2958]=true,
8839 [2959]=true,
8840 [2960]=true,
8841 [2962]=true,
8842 [2963]=true,
8843 [2964]=true,
8844 [3077]=true,
8845 [3078]=true,
8846 [3079]=true,
8847 [3080]=true,
8848 [3081]=true,
8849 [3082]=true,
8850 [3083]=true,
8851 [3084]=true,
8852 [3086]=true,
8853 [3087]=true,
8854 [3088]=true,
8855 [3090]=true,
8856 [3091]=true,
8857 [3092]=true,
8858 [3165]=true,
8859 [3168]=true,
8860 [3169]=true,
8861 [3205]=true,
8862 [3206]=true,
8863 [3207]=true,
8864 [3208]=true,
8865 [3209]=true,
8866 [3210]=true,
8867 [3211]=true,
8868 [3212]=true,
8869 [3214]=true,
8870 [3215]=true,
8871 [3216]=true,
8872 [3218]=true,
8873 [3219]=true,
8874 [3220]=true,
8875 [3293]=true,
8876 [3296]=true,
8877 [3297]=true,
8878 [3333]=true,
8879 [3334]=true,
8880 [3335]=true,
8881 [3336]=true,
8882 [3337]=true,
8883 [3338]=true,
8884 [3339]=true,
8885 [3340]=true,
8886 [3342]=true,
8887 [3343]=true,
8888 [3344]=true,
8889 [3346]=true,
8890 [3347]=true,
8891 [3348]=true,
8892 [3423]=true,
8893 [3424]=true,
8894 [3425]=true,
8895 [4129]=true,
8896 [4130]=true,
8897 [4131]=true,
8898 [4132]=true,
8899 [4133]=true,
8900 [4134]=true,
8901 [4135]=true,
8902 [4136]=true,
8903 [4137]=true,
8904 [4138]=true,
8905 [4178]=true,
8906 [4179]=true,
8907 [4180]=true,
8908 [4181]=true,
8909 },
8910 ["nukta"]={
8911 [2364]=true,
8912 [2492]=true,
8913 [2620]=true,
8914 [2748]=true,
8915 [2876]=true,
8916 [3132]=true,
8917 [3260]=true,
8918 },
8919 ["post_mark"]={
8920 [2307]=true,
8921 [2363]=true,
8922 [2366]=true,
8923 [2368]=true,
8924 [2377]=true,
8925 [2378]=true,
8926 [2379]=true,
8927 [2380]=true,
8928 [2383]=true,
8929 [2494]=true,
8930 [2496]=true,
8931 [2622]=true,
8932 [2624]=true,
8933 [2750]=true,
8934 [2752]=true,
8935 [2761]=true,
8936 [2763]=true,
8937 [2764]=true,
8938 [2878]=true,
8939 [2880]=true,
8940 [3006]=true,
8941 [3007]=true,
8942 [3137]=true,
8943 [3138]=true,
8944 [3139]=true,
8945 [3140]=true,
8946 [3262]=true,
8947 [3265]=true,
8948 [3266]=true,
8949 [3267]=true,
8950 [3268]=true,
8951 [3276]=true,
8952 [3285]=true,
8953 [3390]=true,
8954 [3391]=true,
8955 [3392]=true,
8956 [3393]=true,
8957 [3394]=true,
8958 [3395]=true,
8959 [3396]=true,
8960 [3415]=true,
8961 [4139]=true,
8962 [4140]=true,
8963 [4152]=true,
8964 [4155]=true,
8965 [4182]=true,
8966 [4183]=true,
8967 [4194]=true,
8968 [4195]=true,
8969 [4196]=true,
8970 [4199]=true,
8971 [4200]=true,
8972 [4201]=true,
8973 [4202]=true,
8974 [4203]=true,
8975 [4204]=true,
8976 [4205]=true,
8977 [4227]=true,
8978 [4231]=true,
8979 [4232]=true,
8980 [4233]=true,
8981 [4234]=true,
8982 [4235]=true,
8983 [4236]=true,
8984 [4239]=true,
8985 [4250]=true,
8986 [4251]=true,
8987 [4252]=true,
8988 [43643]=true,
8989 [43645]=true,
8990 },
8991 ["pre_mark"]={
8992 [2367]=true,
8993 [2382]=true,
8994 [2495]=true,
8995 [2503]=true,
8996 [2504]=true,
8997 [2623]=true,
8998 [2751]=true,
8999 [2887]=true,
9000 [3014]=true,
9001 [3015]=true,
9002 [3016]=true,
9003 [3398]=true,
9004 [3399]=true,
9005 [3400]=true,
9006 [4145]=true,
9007 [4228]=true,
9008 },
9009 ["ra"]={
9010 [2352]=true,
9011 [2480]=true,
9012 [2544]=true,
9013 [2608]=true,
9014 [2736]=true,
9015 [2864]=true,
9016 [2992]=true,
9017 [3120]=true,
9018 [3248]=true,
9019 [3376]=true,
9020 [5901]=true,
9021 },
9022 ["stress_tone_mark"]={
9023 [2385]=true,
9024 [2386]=true,
9025 [2387]=true,
9026 [2388]=true,
9027 [4151]=true,
9028 [4195]=true,
9029 [4196]=true,
9030 [4201]=true,
9031 [4202]=true,
9032 [4203]=true,
9033 [4204]=true,
9034 [4205]=true,
9035 [4231]=true,
9036 [4232]=true,
9037 [4233]=true,
9038 [4234]=true,
9039 [4235]=true,
9040 [4236]=true,
9041 [4237]=true,
9042 [4239]=true,
9043 [4250]=true,
9044 [4251]=true,
9045 [43643]=true,
9046 [43644]=true,
9047 [43645]=true,
9048 },
9049 ["twopart_mark"]={
9050 [2507]={ 2503,2494 },
9051 [2508]={ 2503,2519 },
9052 [2888]={ 2887,2902 },
9053 [2891]={ 2887,2878 },
9054 [2892]={ 2887,2903 },
9055 [3018]={ 3014,3006 },
9056 [3019]={ 3015,3006 },
9057 [3020]={ 3014,3031 },
9058 [3144]={ 3142,3158 },
9059 [3264]={ 3263,3285 },
9060 [3271]={ 3270,3285 },
9061 [3272]={ 3270,3286 },
9062 [3274]={ 3270,3266 },
9063 [3275]={ 3274,3285 },
9064 [3402]={ 3398,3390 },
9065 [3403]={ 3399,3390 },
9066 [3404]={ 3398,3415 },
9067 },
9068 ["vowel_modifier"]={
9069 [2304]=true,
9070 [2305]=true,
9071 [2306]=true,
9072 [2307]=true,
9073 [2433]=true,
9074 [3330]=true,
9075 [3331]=true,
9076 [4150]=true,
9077 [4152]=true,
9078 [4153]=true,
9079 [4154]=true,
9080 [43232]=true,
9081 [43233]=true,
9082 [43234]=true,
9083 [43235]=true,
9084 [43236]=true,
9085 [43237]=true,
9086 [43238]=true,
9087 [43239]=true,
9088 [43240]=true,
9089 [43241]=true,
9090 [43242]=true,
9091 [43243]=true,
9092 [43244]=true,
9093 [43245]=true,
9094 [43246]=true,
9095 [43247]=true,
9096 [43249]=true,
9097 },
9098 }
9099
9100 end -- closure
9101
9102 do -- begin closure to overcome local limits and interference
9103
9104 if not modules then modules={} end modules ['font-ini']={
9105 version=1.001,
9106 comment="companion to font-ini.mkiv",
9107 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
9108 copyright="PRAGMA ADE / ConTeXt Development Team",
9109 license="see context related readme files"
9110 }
9111 local allocate=utilities.storage.allocate
9112 local sortedhash=table.sortedhash
9113 fonts=fonts or {}
9114 local fonts=fonts
9115 local identifiers=allocate()
9116 fonts.hashes=fonts.hashes or { identifiers=identifiers }
9117 fonts.tables=fonts.tables or {}
9118 fonts.helpers=fonts.helpers or {}
9119 fonts.tracers=fonts.tracers or {}
9120 fonts.specifiers=fonts.specifiers or {}
9121 fonts.analyzers={}
9122 fonts.readers={}
9123 fonts.definers={ methods={} }
9124 fonts.loggers={ register=function() end }
9125 if context then
9126
9127 --removed
9128
9129 end
9130 fonts.privateoffsets={
9131 textbase=0xF0000,
9132 textextrabase=0xFD000,
9133 mathextrabase=0xFE000,
9134 mathbase=0xFF000,
9135 keepnames=false,
9136 }
9137 if node and not tex.getfontoffamily then
9138 tex.getfontoffamily=node.family_font
9139 end
9140
9141 end -- closure
9142
9143 do -- begin closure to overcome local limits and interference
9144
9145 if not modules then modules={} end modules ['luatex-font-mis']={
9146 version=1.001,
9147 comment="companion to luatex-*.tex",
9148 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
9149 copyright="PRAGMA ADE / ConTeXt Development Team",
9150 license="see context related readme files"
9151 }
9152 if context then
9153 --removed
9154
9155 end
9156 local currentfont=font.current
9157 local hashes=fonts.hashes
9158 local identifiers=hashes.identifiers or {}
9159 local marks=hashes.marks or {}
9160 hashes.identifiers=identifiers
9161 hashes.marks=marks
9162 table.setmetatableindex(marks,function(t,k)
9163 if k==true then
9164 return marks[currentfont()]
9165 else
9166 local resources=identifiers[k].resources or {}
9167 local marks=resources.marks or {}
9168 t[k]=marks
9169 return marks
9170 end
9171 end)
9172 function font.each()
9173 return table.sortedhash(fonts.hashes.identifiers)
9174 end
9175
9176 end -- closure
9177
9178 do -- begin closure to overcome local limits and interference
9179
9180 if not modules then modules={} end modules ['font-con']={
9181 version=1.001,
9182 comment="companion to font-ini.mkiv",
9183 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
9184 copyright="PRAGMA ADE / ConTeXt Development Team",
9185 license="see context related readme files"
9186 }
9187 local next,tostring,tonumber,rawget=next,tostring,tonumber,rawget
9188 local format,match,lower,gsub,find=string.format,string.match,string.lower,string.gsub,string.find
9189 local sort,insert,concat=table.sort,table.insert,table.concat
9190 local sortedkeys,sortedhash,serialize,fastcopy=table.sortedkeys,table.sortedhash,table.serialize,table.fastcopy
9191 local derivetable=table.derive
9192 local ioflush=io.flush
9193 local round=math.round
9194 local setmetatable,getmetatable,rawget,rawset=setmetatable,getmetatable,rawget,rawset
9195 local trace_defining=false trackers.register("fonts.defining",function(v) trace_defining=v end)
9196 local trace_scaling=false trackers.register("fonts.scaling",function(v) trace_scaling=v end)
9197 local report_defining=logs.reporter("fonts","defining")
9198 local fonts=fonts
9199 local constructors=fonts.constructors or {}
9200 fonts.constructors=constructors
9201 local handlers=fonts.handlers or {}
9202 fonts.handlers=handlers
9203 local allocate=utilities.storage.allocate
9204 local setmetatableindex=table.setmetatableindex
9205 constructors.dontembed=allocate()
9206 constructors.namemode="fullpath"
9207 constructors.version=1.01
9208 constructors.cache=containers.define("fonts","constructors",constructors.version,false)
9209 constructors.privateoffset=fonts.privateoffsets.textbase or 0xF0000
9210 constructors.cacheintex=true
9211 constructors.addtounicode=true
9212 constructors.fixprotrusion=true
9213 local designsizes=allocate()
9214 constructors.designsizes=designsizes
9215 local loadedfonts=allocate()
9216 constructors.loadedfonts=loadedfonts
9217 local factors={
9218 pt=65536.0,
9219 bp=65781.8,
9220 }
9221 function constructors.setfactor(f)
9222 constructors.factor=factors[f or 'pt'] or factors.pt
9223 end
9224 constructors.setfactor()
9225 function constructors.scaled(scaledpoints,designsize)
9226 if scaledpoints<0 then
9227 local factor=constructors.factor
9228 if designsize then
9229 if designsize>factor then
9230 return (- scaledpoints/1000)*designsize
9231 else
9232 return (- scaledpoints/1000)*designsize*factor
9233 end
9234 else
9235 return (- scaledpoints/1000)*10*factor
9236 end
9237 else
9238 return scaledpoints
9239 end
9240 end
9241 function constructors.getprivate(tfmdata)
9242 local properties=tfmdata.properties
9243 local private=properties.private
9244 properties.private=private+1
9245 return private
9246 end
9247 function constructors.setmathparameter(tfmdata,name,value)
9248 local m=tfmdata.mathparameters
9249 local c=tfmdata.MathConstants
9250 if m then
9251 m[name]=value
9252 end
9253 if c and c~=m then
9254 c[name]=value
9255 end
9256 end
9257 function constructors.getmathparameter(tfmdata,name)
9258 local p=tfmdata.mathparameters or tfmdata.MathConstants
9259 if p then
9260 return p[name]
9261 end
9262 end
9263 function constructors.cleanuptable(tfmdata)
9264 end
9265 function constructors.calculatescale(tfmdata,scaledpoints)
9266 local parameters=tfmdata.parameters
9267 if scaledpoints<0 then
9268 scaledpoints=(- scaledpoints/1000)*(tfmdata.designsize or parameters.designsize)
9269 end
9270 return scaledpoints,scaledpoints/(parameters.units or 1000)
9271 end
9272 local unscaled={
9273 ScriptPercentScaleDown=true,
9274 ScriptScriptPercentScaleDown=true,
9275 RadicalDegreeBottomRaisePercent=true,
9276 NoLimitSupFactor=true,
9277 NoLimitSubFactor=true,
9278 }
9279 function constructors.assignmathparameters(target,original)
9280 local mathparameters=original.mathparameters
9281 if mathparameters and next(mathparameters) then
9282 local targetparameters=target.parameters
9283 local targetproperties=target.properties
9284 local targetmathparameters={}
9285 local factor=targetproperties.math_is_scaled and 1 or targetparameters.factor
9286 for name,value in next,mathparameters do
9287 if unscaled[name] then
9288 targetmathparameters[name]=value
9289 else
9290 targetmathparameters[name]=value*factor
9291 end
9292 end
9293 if not targetmathparameters.FractionDelimiterSize then
9294 targetmathparameters.FractionDelimiterSize=1.01*targetparameters.size
9295 end
9296 if not mathparameters.FractionDelimiterDisplayStyleSize then
9297 targetmathparameters.FractionDelimiterDisplayStyleSize=2.40*targetparameters.size
9298 end
9299 if not targetmathparameters.SpaceBeforeScript then
9300 targetmathparameters.SpaceBeforeScript=targetmathparameters.SpaceAfterScript
9301 end
9302 target.mathparameters=targetmathparameters
9303 end
9304 end
9305 function constructors.beforecopyingcharacters(target,original)
9306 end
9307 function constructors.aftercopyingcharacters(target,original)
9308 end
9309 local nofinstances=0
9310 local instances=setmetatableindex(function(t,k)
9311 nofinstances=nofinstances+1
9312 t[k]=nofinstances
9313 return nofinstances
9314 end)
9315 function constructors.trytosharefont(target,tfmdata)
9316 local properties=target.properties
9317 local instance=properties.instance
9318 if instance then
9319 local fullname=target.fullname
9320 local fontname=target.fontname
9321 local psname=target.psname
9322 local format=tfmdata.properties.format
9323 if format=="opentype" then
9324 target.streamprovider=1
9325 elseif format=="truetype" then
9326 target.streamprovider=2
9327 else
9328 target.streamprovider=0
9329 end
9330 if target.streamprovider>0 then
9331 if fullname then
9332 fullname=fullname..":"..instances[instance]
9333 target.fullname=fullname
9334 end
9335 if fontname then
9336 fontname=fontname..":"..instances[instance]
9337 target.fontname=fontname
9338 end
9339 if psname then
9340 psname=psname..":"..instances[instance]
9341 target.psname=psname
9342 end
9343 end
9344 end
9345 end
9346 local synonyms={
9347 exheight="x_height",
9348 xheight="x_height",
9349 ex="x_height",
9350 emwidth="quad",
9351 em="quad",
9352 spacestretch="space_stretch",
9353 stretch="space_stretch",
9354 spaceshrink="space_shrink",
9355 shrink="space_shrink",
9356 extraspace="extra_space",
9357 xspace="extra_space",
9358 slantperpoint="slant",
9359 }
9360 function constructors.enhanceparameters(parameters)
9361 local mt=getmetatable(parameters)
9362 local getter=function(t,k)
9363 if not k then
9364 return nil
9365 end
9366 local s=synonyms[k]
9367 if s then
9368 return rawget(t,s) or (mt and mt[s]) or nil
9369 end
9370 if k=="spacing" then
9371 return {
9372 width=t.space,
9373 stretch=t.space_stretch,
9374 shrink=t.space_shrink,
9375 extra=t.extra_space,
9376 }
9377 end
9378 return mt and mt[k] or nil
9379 end
9380 local setter=function(t,k,v)
9381 if not k then
9382 return 0
9383 end
9384 local s=synonyms[k]
9385 if s then
9386 rawset(t,s,v)
9387 elseif k=="spacing" then
9388 if type(v)=="table" then
9389 rawset(t,"space",v.width or 0)
9390 rawset(t,"space_stretch",v.stretch or 0)
9391 rawset(t,"space_shrink",v.shrink or 0)
9392 rawset(t,"extra_space",v.extra or 0)
9393 end
9394 else
9395 rawset(t,k,v)
9396 end
9397 end
9398 setmetatable(parameters,{
9399 __index=getter,
9400 __newindex=setter,
9401 })
9402 end
9403 local function mathkerns(v,vdelta)
9404 local k={}
9405 for i=1,#v do
9406 local entry=v[i]
9407 local height=entry.height
9408 local kern=entry.kern
9409 k[i]={
9410 height=height and vdelta*height or 0,
9411 kern=kern and vdelta*kern or 0,
9412 }
9413 end
9414 return k
9415 end
9416 local psfake=0
9417 local function fixedpsname(psname,fallback)
9418 local usedname=psname
9419 if psname and psname~="" then
9420 if find(psname," ",1,true) then
9421 usedname=gsub(psname,"[%s]+","-")
9422 else
9423 end
9424 elseif not fallback or fallback=="" then
9425 psfake=psfake+1
9426 psname="fakename-"..psfake
9427 else
9428 psname=fallback
9429 usedname=gsub(psname,"[^a-zA-Z0-9]+","-")
9430 end
9431 return usedname,psname~=usedname
9432 end
9433 function constructors.scale(tfmdata,specification)
9434 local target={}
9435 if tonumber(specification) then
9436 specification={ size=specification }
9437 end
9438 target.specification=specification
9439 local scaledpoints=specification.size
9440 local relativeid=specification.relativeid
9441 local properties=tfmdata.properties or {}
9442 local goodies=tfmdata.goodies or {}
9443 local resources=tfmdata.resources or {}
9444 local descriptions=tfmdata.descriptions or {}
9445 local characters=tfmdata.characters or {}
9446 local changed=tfmdata.changed or {}
9447 local shared=tfmdata.shared or {}
9448 local parameters=tfmdata.parameters or {}
9449 local mathparameters=tfmdata.mathparameters or {}
9450 local targetcharacters={}
9451 local targetdescriptions=derivetable(descriptions)
9452 local targetparameters=derivetable(parameters)
9453 local targetproperties=derivetable(properties)
9454 local targetgoodies=goodies
9455 target.characters=targetcharacters
9456 target.descriptions=targetdescriptions
9457 target.parameters=targetparameters
9458 target.properties=targetproperties
9459 target.goodies=targetgoodies
9460 target.shared=shared
9461 target.resources=resources
9462 target.unscaled=tfmdata
9463 local mathsize=tonumber(specification.mathsize) or 0
9464 local textsize=tonumber(specification.textsize) or scaledpoints
9465 local extrafactor=tonumber(specification.factor ) or 1
9466 targetparameters.mathsize=mathsize
9467 targetparameters.textsize=textsize
9468 targetparameters.extrafactor=extrafactor
9469 local addtounicode=constructors.addtounicode
9470 local tounicode=fonts.mappings.tounicode
9471 local unknowncode=tounicode(0xFFFD)
9472 local defaultwidth=resources.defaultwidth or 0
9473 local defaultheight=resources.defaultheight or 0
9474 local defaultdepth=resources.defaultdepth or 0
9475 local units=parameters.units or 1000
9476 targetproperties.language=properties.language or "dflt"
9477 targetproperties.script=properties.script or "dflt"
9478 targetproperties.mode=properties.mode or "base"
9479 targetproperties.method=properties.method
9480 local askedscaledpoints=scaledpoints
9481 local scaledpoints,delta=constructors.calculatescale(tfmdata,scaledpoints,nil,specification)
9482 local hdelta=delta
9483 local vdelta=delta
9484 target.designsize=parameters.designsize
9485 target.units=units
9486 target.units_per_em=units
9487 local direction=properties.direction or tfmdata.direction or 0
9488 target.direction=direction
9489 properties.direction=direction
9490 target.size=scaledpoints
9491 target.encodingbytes=properties.encodingbytes or 1
9492 target.subfont=properties.subfont
9493 target.embedding=properties.embedding or "subset"
9494 target.tounicode=1
9495 target.cidinfo=properties.cidinfo
9496 target.format=properties.format
9497 target.cache=constructors.cacheintex and "yes" or "renew"
9498 local original=properties.original or tfmdata.original
9499 local fontname=properties.fontname or tfmdata.fontname
9500 local fullname=properties.fullname or tfmdata.fullname
9501 local filename=properties.filename or tfmdata.filename
9502 local psname=properties.psname or tfmdata.psname
9503 local name=properties.name or tfmdata.name
9504 local psname,psfixed=fixedpsname(psname,fontname or fullname or file.nameonly(filename))
9505 target.original=original
9506 target.fontname=fontname
9507 target.fullname=fullname
9508 target.filename=filename
9509 target.psname=psname
9510 target.name=name
9511 properties.fontname=fontname
9512 properties.fullname=fullname
9513 properties.filename=filename
9514 properties.psname=psname
9515 properties.name=name
9516 local expansion=parameters.expansion
9517 if expansion then
9518 target.stretch=expansion.stretch
9519 target.shrink=expansion.shrink
9520 target.step=expansion.step
9521 end
9522 local slantfactor=parameters.slantfactor or 0
9523 if slantfactor~=0 then
9524 target.slant=slantfactor*1000
9525 else
9526 target.slant=0
9527 end
9528 local extendfactor=parameters.extendfactor or 0
9529 if extendfactor~=0 and extendfactor~=1 then
9530 hdelta=hdelta*extendfactor
9531 target.extend=extendfactor*1000
9532 else
9533 target.extend=1000
9534 end
9535 local squeezefactor=parameters.squeezefactor or 0
9536 if squeezefactor~=0 and squeezefactor~=1 then
9537 vdelta=vdelta*squeezefactor
9538 target.squeeze=squeezefactor*1000
9539 else
9540 target.squeeze=1000
9541 end
9542 local mode=parameters.mode or 0
9543 if mode~=0 then
9544 target.mode=mode
9545 end
9546 local width=parameters.width or 0
9547 if width~=0 then
9548 target.width=width*delta*1000/655360
9549 end
9550 targetparameters.factor=delta
9551 targetparameters.hfactor=hdelta
9552 targetparameters.vfactor=vdelta
9553 targetparameters.size=scaledpoints
9554 targetparameters.units=units
9555 targetparameters.scaledpoints=askedscaledpoints
9556 targetparameters.mode=mode
9557 targetparameters.width=width
9558 local isvirtual=properties.virtualized or tfmdata.type=="virtual"
9559 local hasquality=parameters.expansion or parameters.protrusion
9560 local hasitalics=properties.hasitalics
9561 local autoitalicamount=properties.autoitalicamount
9562 local stackmath=not properties.nostackmath
9563 local haskerns=properties.haskerns or properties.mode=="base"
9564 local hasligatures=properties.hasligatures or properties.mode=="base"
9565 local realdimensions=properties.realdimensions
9566 local writingmode=properties.writingmode or "horizontal"
9567 local identity=properties.identity or "horizontal"
9568 local vfonts=target.fonts
9569 if vfonts and #vfonts>0 then
9570 target.fonts=fastcopy(vfonts)
9571 elseif isvirtual then
9572 target.fonts={ { id=0 } }
9573 end
9574 if changed and not next(changed) then
9575 changed=false
9576 end
9577 target.type=isvirtual and "virtual" or "real"
9578 target.writingmode=writingmode=="vertical" and "vertical" or "horizontal"
9579 target.identity=identity=="vertical" and "vertical" or "horizontal"
9580 target.postprocessors=tfmdata.postprocessors
9581 local targetslant=(parameters.slant or parameters[1] or 0)*factors.pt
9582 local targetspace=(parameters.space or parameters[2] or 0)*hdelta
9583 local targetspace_stretch=(parameters.space_stretch or parameters[3] or 0)*hdelta
9584 local targetspace_shrink=(parameters.space_shrink or parameters[4] or 0)*hdelta
9585 local targetx_height=(parameters.x_height or parameters[5] or 0)*vdelta
9586 local targetquad=(parameters.quad or parameters[6] or 0)*hdelta
9587 local targetextra_space=(parameters.extra_space or parameters[7] or 0)*hdelta
9588 targetparameters.slant=targetslant
9589 targetparameters.space=targetspace
9590 targetparameters.space_stretch=targetspace_stretch
9591 targetparameters.space_shrink=targetspace_shrink
9592 targetparameters.x_height=targetx_height
9593 targetparameters.quad=targetquad
9594 targetparameters.extra_space=targetextra_space
9595 local hshift=parameters.hshift
9596 if hshift then
9597 targetparameters.hshift=delta*hshift
9598 end
9599 local vshift=parameters.vshift
9600 if vshift then
9601 targetparameters.vshift=delta*vshift
9602 end
9603 local ascender=parameters.ascender
9604 if ascender then
9605 targetparameters.ascender=delta*ascender
9606 end
9607 local descender=parameters.descender
9608 if descender then
9609 targetparameters.descender=delta*descender
9610 end
9611 constructors.enhanceparameters(targetparameters)
9612 local protrusionfactor=constructors.fixprotrusion and ((targetquad~=0 and 1000/targetquad) or 1) or 1
9613 local scaledwidth=defaultwidth*hdelta
9614 local scaledheight=defaultheight*vdelta
9615 local scaleddepth=defaultdepth*vdelta
9616 local hasmath=(properties.hasmath or next(mathparameters)) and true
9617 if hasmath then
9618 constructors.assignmathparameters(target,tfmdata)
9619 properties.hasmath=true
9620 target.nomath=false
9621 target.MathConstants=target.mathparameters
9622 local oldmath=properties.oldmath
9623 targetproperties.oldmath=oldmath
9624 target.oldmath=oldmath
9625 else
9626 properties.hasmath=false
9627 target.nomath=true
9628 target.mathparameters=nil
9629 end
9630 if hasmath then
9631 local mathitalics=properties.mathitalics
9632 if mathitalics==false then
9633 if trace_defining then
9634 report_defining("%s italics %s for font %a, fullname %a, filename %a","math",hasitalics and "ignored" or "disabled",name,fullname,filename)
9635 end
9636 hasitalics=false
9637 autoitalicamount=false
9638 end
9639 else
9640 local textitalics=properties.textitalics
9641 if textitalics==false then
9642 if trace_defining then
9643 report_defining("%s italics %s for font %a, fullname %a, filename %a","text",hasitalics and "ignored" or "disabled",name,fullname,filename)
9644 end
9645 hasitalics=false
9646 autoitalicamount=false
9647 end
9648 end
9649 if trace_defining then
9650 report_defining("defining tfm, name %a, fullname %a, filename %a, %spsname %a, hscale %a, vscale %a, math %a, italics %a",
9651 name,fullname,filename,psfixed and "(fixed) " or "",psname,hdelta,vdelta,
9652 hasmath and "enabled" or "disabled",hasitalics and "enabled" or "disabled")
9653 end
9654 constructors.beforecopyingcharacters(target,tfmdata)
9655 local sharedkerns={}
9656 for unicode,character in next,characters do
9657 local chr,description,index
9658 if changed then
9659 local c=changed[unicode]
9660 if c and c~=unicode then
9661 if c then
9662 description=descriptions[c] or descriptions[unicode] or character
9663 character=characters[c] or character
9664 index=description.index or c
9665 else
9666 description=descriptions[unicode] or character
9667 index=description.index or unicode
9668 end
9669 else
9670 description=descriptions[unicode] or character
9671 index=description.index or unicode
9672 end
9673 else
9674 description=descriptions[unicode] or character
9675 index=description.index or unicode
9676 end
9677 local width=description.width
9678 local height=description.height
9679 local depth=description.depth
9680 local isunicode=description.unicode
9681 if realdimensions then
9682 if not height or height==0 then
9683 local bb=description.boundingbox
9684 local ht=bb[4]
9685 if ht~=0 then
9686 height=ht
9687 end
9688 if not depth or depth==0 then
9689 local dp=-bb[2]
9690 if dp~=0 then
9691 depth=dp
9692 end
9693 end
9694 elseif not depth or depth==0 then
9695 local dp=-description.boundingbox[2]
9696 if dp~=0 then
9697 depth=dp
9698 end
9699 end
9700 end
9701 if width then width=hdelta*width else width=scaledwidth end
9702 if height then height=vdelta*height else height=scaledheight end
9703 if depth and depth~=0 then
9704 depth=delta*depth
9705 if isunicode then
9706 chr={
9707 index=index,
9708 height=height,
9709 depth=depth,
9710 width=width,
9711 unicode=isunicode,
9712 }
9713 else
9714 chr={
9715 index=index,
9716 height=height,
9717 depth=depth,
9718 width=width,
9719 }
9720 end
9721 else
9722 if isunicode then
9723 chr={
9724 index=index,
9725 height=height,
9726 width=width,
9727 unicode=isunicode,
9728 }
9729 else
9730 chr={
9731 index=index,
9732 height=height,
9733 width=width,
9734 }
9735 end
9736 end
9737 if addtounicode then
9738 chr.tounicode=isunicode and tounicode(isunicode) or unknowncode
9739 end
9740 if hasquality then
9741 local ve=character.expansion_factor
9742 if ve then
9743 chr.expansion_factor=ve*1000
9744 end
9745 local vl=character.left_protruding
9746 if vl then
9747 chr.left_protruding=protrusionfactor*width*vl
9748 end
9749 local vr=character.right_protruding
9750 if vr then
9751 chr.right_protruding=protrusionfactor*width*vr
9752 end
9753 end
9754 if hasmath then
9755 local vn=character.next
9756 if vn then
9757 chr.next=vn
9758 else
9759 local vv=character.vert_variants
9760 if vv then
9761 local t={}
9762 for i=1,#vv do
9763 local vvi=vv[i]
9764 local s=vvi["start"] or 0
9765 local e=vvi["end"] or 0
9766 local a=vvi["advance"] or 0
9767 t[i]={
9768 ["start"]=s==0 and 0 or s*vdelta,
9769 ["end"]=e==0 and 0 or e*vdelta,
9770 ["advance"]=a==0 and 0 or a*vdelta,
9771 ["extender"]=vvi["extender"],
9772 ["glyph"]=vvi["glyph"],
9773 }
9774 end
9775 chr.vert_variants=t
9776 else
9777 local hv=character.horiz_variants
9778 if hv then
9779 local t={}
9780 for i=1,#hv do
9781 local hvi=hv[i]
9782 local s=hvi["start"] or 0
9783 local e=hvi["end"] or 0
9784 local a=hvi["advance"] or 0
9785 t[i]={
9786 ["start"]=s==0 and 0 or s*hdelta,
9787 ["end"]=e==0 and 0 or e*hdelta,
9788 ["advance"]=a==0 and 0 or a*hdelta,
9789 ["extender"]=hvi["extender"],
9790 ["glyph"]=hvi["glyph"],
9791 }
9792 end
9793 chr.horiz_variants=t
9794 end
9795 end
9796 end
9797 local vi=character.vert_italic
9798 if vi and vi~=0 then
9799 chr.vert_italic=vi*hdelta
9800 end
9801 local va=character.accent
9802 if va then
9803 chr.top_accent=vdelta*va
9804 end
9805 if stackmath then
9806 local mk=character.mathkerns
9807 if mk then
9808 local tr=mk.topright
9809 local tl=mk.topleft
9810 local br=mk.bottomright
9811 local bl=mk.bottomleft
9812 chr.mathkern={
9813 top_right=tr and mathkerns(tr,vdelta) or nil,
9814 top_left=tl and mathkerns(tl,vdelta) or nil,
9815 bottom_right=br and mathkerns(br,vdelta) or nil,
9816 bottom_left=bl and mathkerns(bl,vdelta) or nil,
9817 }
9818 end
9819 end
9820 if hasitalics then
9821 local vi=character.italic
9822 if vi and vi~=0 then
9823 chr.italic=vi*hdelta
9824 end
9825 end
9826 elseif autoitalicamount then
9827 local vi=description.italic
9828 if not vi then
9829 local bb=description.boundingbox
9830 if bb then
9831 local vi=bb[3]-description.width+autoitalicamount
9832 if vi>0 then
9833 chr.italic=vi*hdelta
9834 end
9835 else
9836 end
9837 elseif vi~=0 then
9838 chr.italic=vi*hdelta
9839 end
9840 elseif hasitalics then
9841 local vi=character.italic
9842 if vi and vi~=0 then
9843 chr.italic=vi*hdelta
9844 end
9845 end
9846 if haskerns then
9847 local vk=character.kerns
9848 if vk then
9849 local s=sharedkerns[vk]
9850 if not s then
9851 s={}
9852 for k,v in next,vk do s[k]=v*hdelta end
9853 sharedkerns[vk]=s
9854 end
9855 chr.kerns=s
9856 end
9857 end
9858 if hasligatures then
9859 local vl=character.ligatures
9860 if vl then
9861 if true then
9862 chr.ligatures=vl
9863 else
9864 local tt={}
9865 for i,l in next,vl do
9866 tt[i]=l
9867 end
9868 chr.ligatures=tt
9869 end
9870 end
9871 end
9872 if isvirtual then
9873 local vc=character.commands
9874 if vc then
9875 local ok=false
9876 for i=1,#vc do
9877 local key=vc[i][1]
9878 if key=="right" or key=="down" or key=="rule" then
9879 ok=true
9880 break
9881 end
9882 end
9883 if ok then
9884 local tt={}
9885 for i=1,#vc do
9886 local ivc=vc[i]
9887 local key=ivc[1]
9888 if key=="right" then
9889 tt[i]={ key,ivc[2]*hdelta }
9890 elseif key=="down" then
9891 tt[i]={ key,ivc[2]*vdelta }
9892 elseif key=="rule" then
9893 tt[i]={ key,ivc[2]*vdelta,ivc[3]*hdelta }
9894 else
9895 tt[i]=ivc
9896 end
9897 end
9898 chr.commands=tt
9899 else
9900 chr.commands=vc
9901 end
9902 end
9903 end
9904 targetcharacters[unicode]=chr
9905 end
9906 properties.setitalics=hasitalics
9907 constructors.aftercopyingcharacters(target,tfmdata)
9908 constructors.trytosharefont(target,tfmdata)
9909 local vfonts=target.fonts
9910 if isvirtual or target.type=="virtual" or properties.virtualized then
9911 properties.virtualized=true
9912 target.type="virtual"
9913 if not vfonts or #vfonts==0 then
9914 target.fonts={ { id=0 } }
9915 end
9916 elseif vfonts then
9917 properties.virtualized=true
9918 target.type="virtual"
9919 if #vfonts==0 then
9920 target.fonts={ { id=0 } }
9921 end
9922 end
9923 return target
9924 end
9925 function constructors.finalize(tfmdata)
9926 if tfmdata.properties and tfmdata.properties.finalized then
9927 return
9928 end
9929 if not tfmdata.characters then
9930 return nil
9931 end
9932 if not tfmdata.goodies then
9933 tfmdata.goodies={}
9934 end
9935 local parameters=tfmdata.parameters
9936 if not parameters then
9937 return nil
9938 end
9939 if not parameters.expansion then
9940 parameters.expansion={
9941 stretch=tfmdata.stretch or 0,
9942 shrink=tfmdata.shrink or 0,
9943 step=tfmdata.step or 0,
9944 }
9945 end
9946 if not parameters.size then
9947 parameters.size=tfmdata.size
9948 end
9949 if not parameters.mode then
9950 parameters.mode=0
9951 end
9952 if not parameters.width then
9953 parameters.width=0
9954 end
9955 if not parameters.slantfactor then
9956 parameters.slantfactor=(tfmdata.slant or 0)/1000
9957 end
9958 if not parameters.extendfactor then
9959 parameters.extendfactor=(tfmdata.extend or 1000)/1000
9960 end
9961 if not parameters.squeezefactor then
9962 parameters.squeezefactor=(tfmdata.squeeze or 1000)/1000
9963 end
9964 local designsize=parameters.designsize
9965 if designsize then
9966 parameters.minsize=tfmdata.minsize or designsize
9967 parameters.maxsize=tfmdata.maxsize or designsize
9968 else
9969 designsize=factors.pt*10
9970 parameters.designsize=designsize
9971 parameters.minsize=designsize
9972 parameters.maxsize=designsize
9973 end
9974 parameters.minsize=tfmdata.minsize or parameters.designsize
9975 parameters.maxsize=tfmdata.maxsize or parameters.designsize
9976 if not parameters.units then
9977 parameters.units=tfmdata.units or tfmdata.units_per_em or 1000
9978 end
9979 if not tfmdata.descriptions then
9980 local descriptions={}
9981 setmetatableindex(descriptions,function(t,k) local v={} t[k]=v return v end)
9982 tfmdata.descriptions=descriptions
9983 end
9984 local properties=tfmdata.properties
9985 if not properties then
9986 properties={}
9987 tfmdata.properties=properties
9988 end
9989 if not properties.virtualized then
9990 properties.virtualized=tfmdata.type=="virtual"
9991 end
9992 properties.fontname=properties.fontname or tfmdata.fontname
9993 properties.filename=properties.filename or tfmdata.filename
9994 properties.fullname=properties.fullname or tfmdata.fullname
9995 properties.name=properties.name or tfmdata.name
9996 properties.psname=properties.psname or tfmdata.psname
9997 properties.encodingbytes=tfmdata.encodingbytes or 1
9998 properties.subfont=tfmdata.subfont or nil
9999 properties.embedding=tfmdata.embedding or "subset"
10000 properties.tounicode=tfmdata.tounicode or 1
10001 properties.cidinfo=tfmdata.cidinfo or nil
10002 properties.format=tfmdata.format or "type1"
10003 properties.direction=tfmdata.direction or 0
10004 properties.writingmode=tfmdata.writingmode or "horizontal"
10005 properties.identity=tfmdata.identity or "horizontal"
10006 properties.usedbitmap=tfmdata.usedbitmap
10007 if not tfmdata.resources then
10008 tfmdata.resources={}
10009 end
10010 if not tfmdata.shared then
10011 tfmdata.shared={}
10012 end
10013 if not properties.hasmath then
10014 properties.hasmath=not tfmdata.nomath
10015 end
10016 tfmdata.MathConstants=nil
10017 tfmdata.postprocessors=nil
10018 tfmdata.fontname=nil
10019 tfmdata.filename=nil
10020 tfmdata.fullname=nil
10021 tfmdata.name=nil
10022 tfmdata.psname=nil
10023 tfmdata.encodingbytes=nil
10024 tfmdata.subfont=nil
10025 tfmdata.embedding=nil
10026 tfmdata.tounicode=nil
10027 tfmdata.cidinfo=nil
10028 tfmdata.format=nil
10029 tfmdata.direction=nil
10030 tfmdata.type=nil
10031 tfmdata.nomath=nil
10032 tfmdata.designsize=nil
10033 tfmdata.size=nil
10034 tfmdata.stretch=nil
10035 tfmdata.shrink=nil
10036 tfmdata.step=nil
10037 tfmdata.slant=nil
10038 tfmdata.extend=nil
10039 tfmdata.squeeze=nil
10040 tfmdata.mode=nil
10041 tfmdata.width=nil
10042 tfmdata.units=nil
10043 tfmdata.units_per_em=nil
10044 tfmdata.cache=nil
10045 properties.finalized=true
10046 return tfmdata
10047 end
10048 local hashmethods={}
10049 constructors.hashmethods=hashmethods
10050 function constructors.hashfeatures(specification)
10051 local features=specification.features
10052 if features then
10053 local t,n={},0
10054 for category,list in sortedhash(features) do
10055 if next(list) then
10056 local hasher=hashmethods[category]
10057 if hasher then
10058 local hash=hasher(list)
10059 if hash then
10060 n=n+1
10061 t[n]=category..":"..hash
10062 end
10063 end
10064 end
10065 end
10066 if n>0 then
10067 return concat(t," & ")
10068 end
10069 end
10070 return "unknown"
10071 end
10072 hashmethods.normal=function(list)
10073 local s={}
10074 local n=0
10075 for k,v in next,list do
10076 if not k then
10077 elseif k=="number" or k=="features" then
10078 else
10079 n=n+1
10080 if type(v)=="table" then
10081 local t={}
10082 local m=0
10083 for k,v in next,v do
10084 m=m+1
10085 t[m]=k..'='..tostring(v)
10086 end
10087 sort(t)
10088 s[n]=k..'={'..concat(t,",").."}"
10089 else
10090 s[n]=k..'='..tostring(v)
10091 end
10092 end
10093 end
10094 if n>0 then
10095 sort(s)
10096 return concat(s,"+")
10097 end
10098 end
10099 function constructors.hashinstance(specification,force)
10100 local hash=specification.hash
10101 local size=specification.size
10102 local fallbacks=specification.fallbacks
10103 if force or not hash then
10104 hash=constructors.hashfeatures(specification)
10105 specification.hash=hash
10106 end
10107 if size<1000 and designsizes[hash] then
10108 size=round(constructors.scaled(size,designsizes[hash]))
10109 else
10110 size=round(size)
10111 end
10112 specification.size=size
10113 if fallbacks then
10114 return hash..' @ '..size..' @ '..fallbacks
10115 else
10116 return hash..' @ '..size
10117 end
10118 end
10119 function constructors.setname(tfmdata,specification)
10120 if constructors.namemode=="specification" then
10121 local specname=specification.specification
10122 if specname then
10123 tfmdata.properties.name=specname
10124 if trace_defining then
10125 report_otf("overloaded fontname %a",specname)
10126 end
10127 end
10128 end
10129 end
10130 function constructors.checkedfilename(data)
10131 local foundfilename=data.foundfilename
10132 if not foundfilename then
10133 local askedfilename=data.filename or ""
10134 if askedfilename~="" then
10135 askedfilename=resolvers.resolve(askedfilename)
10136 foundfilename=resolvers.findbinfile(askedfilename,"") or ""
10137 if foundfilename=="" then
10138 report_defining("source file %a is not found",askedfilename)
10139 foundfilename=resolvers.findbinfile(file.basename(askedfilename),"") or ""
10140 if foundfilename~="" then
10141 report_defining("using source file %a due to cache mismatch",foundfilename)
10142 end
10143 end
10144 end
10145 data.foundfilename=foundfilename
10146 end
10147 return foundfilename
10148 end
10149 local formats=allocate()
10150 fonts.formats=formats
10151 setmetatableindex(formats,function(t,k)
10152 local l=lower(k)
10153 if rawget(t,k) then
10154 t[k]=l
10155 return l
10156 end
10157 return rawget(t,file.suffix(l))
10158 end)
10159 do
10160 local function setindeed(mode,source,target,group,name,position)
10161 local action=source[mode]
10162 if not action then
10163 return
10164 end
10165 local t=target[mode]
10166 if not t then
10167 report_defining("fatal error in setting feature %a, group %a, mode %a",name,group,mode)
10168 os.exit()
10169 elseif position then
10170 insert(t,position,{ name=name,action=action })
10171 else
10172 for i=1,#t do
10173 local ti=t[i]
10174 if ti.name==name then
10175 ti.action=action
10176 return
10177 end
10178 end
10179 insert(t,{ name=name,action=action })
10180 end
10181 end
10182 local function set(group,name,target,source)
10183 target=target[group]
10184 if not target then
10185 report_defining("fatal target error in setting feature %a, group %a",name,group)
10186 os.exit()
10187 end
10188 local source=source[group]
10189 if not source then
10190 report_defining("fatal source error in setting feature %a, group %a",name,group)
10191 os.exit()
10192 end
10193 local position=source.position
10194 setindeed("node",source,target,group,name,position)
10195 setindeed("base",source,target,group,name,position)
10196 setindeed("plug",source,target,group,name,position)
10197 end
10198 local function register(where,specification)
10199 local name=specification.name
10200 if name and name~="" then
10201 local default=specification.default
10202 local description=specification.description
10203 local initializers=specification.initializers
10204 local processors=specification.processors
10205 local manipulators=specification.manipulators
10206 local modechecker=specification.modechecker
10207 if default then
10208 where.defaults[name]=default
10209 end
10210 if description and description~="" then
10211 where.descriptions[name]=description
10212 end
10213 if initializers then
10214 set('initializers',name,where,specification)
10215 end
10216 if processors then
10217 set('processors',name,where,specification)
10218 end
10219 if manipulators then
10220 set('manipulators',name,where,specification)
10221 end
10222 if modechecker then
10223 where.modechecker=modechecker
10224 end
10225 end
10226 end
10227 constructors.registerfeature=register
10228 function constructors.getfeatureaction(what,where,mode,name)
10229 what=handlers[what].features
10230 if what then
10231 where=what[where]
10232 if where then
10233 mode=where[mode]
10234 if mode then
10235 for i=1,#mode do
10236 local m=mode[i]
10237 if m.name==name then
10238 return m.action
10239 end
10240 end
10241 end
10242 end
10243 end
10244 end
10245 local newfeatures={}
10246 constructors.newfeatures=newfeatures
10247 constructors.features=newfeatures
10248 local function setnewfeatures(what)
10249 local handler=handlers[what]
10250 local features=handler.features
10251 if not features then
10252 local tables=handler.tables
10253 local statistics=handler.statistics
10254 features=allocate {
10255 defaults={},
10256 descriptions=tables and tables.features or {},
10257 used=statistics and statistics.usedfeatures or {},
10258 initializers={ base={},node={},plug={} },
10259 processors={ base={},node={},plug={} },
10260 manipulators={ base={},node={},plug={} },
10261 }
10262 features.register=function(specification) return register(features,specification) end
10263 handler.features=features
10264 end
10265 return features
10266 end
10267 setmetatable(newfeatures,{
10268 __call=function(t,k) local v=t[k] return v end,
10269 __index=function(t,k) local v=setnewfeatures(k) t[k]=v return v end,
10270 })
10271 end
10272 do
10273 local newhandler={}
10274 constructors.handlers=newhandler
10275 constructors.newhandler=newhandler
10276 local function setnewhandler(what)
10277 local handler=handlers[what]
10278 if not handler then
10279 handler={}
10280 handlers[what]=handler
10281 end
10282 return handler
10283 end
10284 setmetatable(newhandler,{
10285 __call=function(t,k) local v=t[k] return v end,
10286 __index=function(t,k) local v=setnewhandler(k) t[k]=v return v end,
10287 })
10288 end
10289 do
10290 local newenhancer={}
10291 constructors.enhancers=newenhancer
10292 constructors.newenhancer=newenhancer
10293 local function setnewenhancer(format)
10294 local handler=handlers[format]
10295 local enhancers=handler.enhancers
10296 if not enhancers then
10297 local actions=allocate()
10298 local before=allocate()
10299 local after=allocate()
10300 local order=allocate()
10301 local known={}
10302 local nofsteps=0
10303 local patches={ before=before,after=after }
10304 local trace=false
10305 local report=logs.reporter("fonts",format.." enhancing")
10306 trackers.register(format..".loading",function(v) trace=v end)
10307 local function enhance(name,data,filename,raw)
10308 local enhancer=actions[name]
10309 if enhancer then
10310 if trace then
10311 report("apply enhancement %a to file %a",name,filename)
10312 ioflush()
10313 end
10314 enhancer(data,filename,raw)
10315 else
10316 end
10317 end
10318 local function apply(data,filename,raw)
10319 local basename=file.basename(lower(filename))
10320 if trace then
10321 report("%s enhancing file %a","start",filename)
10322 end
10323 ioflush()
10324 for e=1,nofsteps do
10325 local enhancer=order[e]
10326 local b=before[enhancer]
10327 if b then
10328 for pattern,action in next,b do
10329 if find(basename,pattern) then
10330 action(data,filename,raw)
10331 end
10332 end
10333 end
10334 enhance(enhancer,data,filename,raw)
10335 local a=after[enhancer]
10336 if a then
10337 for pattern,action in next,a do
10338 if find(basename,pattern) then
10339 action(data,filename,raw)
10340 end
10341 end
10342 end
10343 ioflush()
10344 end
10345 if trace then
10346 report("%s enhancing file %a","stop",filename)
10347 end
10348 ioflush()
10349 end
10350 local function register(what,action)
10351 if action then
10352 if actions[what] then
10353 else
10354 nofsteps=nofsteps+1
10355 order[nofsteps]=what
10356 known[what]=nofsteps
10357 end
10358 actions[what]=action
10359 else
10360 report("bad enhancer %a",what)
10361 end
10362 end
10363 local function patch(what,where,pattern,action)
10364 local pw=patches[what]
10365 if pw then
10366 local ww=pw[where]
10367 if ww then
10368 ww[pattern]=action
10369 else
10370 pw[where]={ [pattern]=action }
10371 if not known[where] then
10372 nofsteps=nofsteps+1
10373 order[nofsteps]=where
10374 known[where]=nofsteps
10375 end
10376 end
10377 end
10378 end
10379 enhancers={
10380 register=register,
10381 apply=apply,
10382 patch=patch,
10383 report=report,
10384 patches={
10385 register=patch,
10386 report=report,
10387 },
10388 }
10389 handler.enhancers=enhancers
10390 end
10391 return enhancers
10392 end
10393 setmetatable(newenhancer,{
10394 __call=function(t,k) local v=t[k] return v end,
10395 __index=function(t,k) local v=setnewenhancer(k) t[k]=v return v end,
10396 })
10397 end
10398 function constructors.checkedfeatures(what,features)
10399 local defaults=handlers[what].features.defaults
10400 if features and next(features) then
10401 features=fastcopy(features)
10402 for key,value in next,defaults do
10403 if features[key]==nil then
10404 features[key]=value
10405 end
10406 end
10407 return features
10408 else
10409 return fastcopy(defaults)
10410 end
10411 end
10412 function constructors.initializefeatures(what,tfmdata,features,trace,report)
10413 if features and next(features) then
10414 local properties=tfmdata.properties or {}
10415 local whathandler=handlers[what]
10416 local whatfeatures=whathandler.features
10417 local whatmodechecker=whatfeatures.modechecker
10418 local mode=properties.mode or (whatmodechecker and whatmodechecker(tfmdata,features,features.mode)) or features.mode or "base"
10419 properties.mode=mode
10420 features.mode=mode
10421 local done={}
10422 while true do
10423 local redo=false
10424 local initializers=whatfeatures.initializers[mode]
10425 if initializers then
10426 for i=1,#initializers do
10427 local step=initializers[i]
10428 local feature=step.name
10429 local value=features[feature]
10430 if not value then
10431 elseif done[feature] then
10432 else
10433 local action=step.action
10434 if trace then
10435 report("initializing feature %a to %a for mode %a for font %a",feature,
10436 value,mode,tfmdata.properties.fullname)
10437 end
10438 action(tfmdata,value,features)
10439 if mode~=properties.mode or mode~=features.mode then
10440 if whatmodechecker then
10441 properties.mode=whatmodechecker(tfmdata,features,properties.mode)
10442 features.mode=properties.mode
10443 end
10444 if mode~=properties.mode then
10445 mode=properties.mode
10446 redo=true
10447 end
10448 end
10449 done[feature]=true
10450 end
10451 if redo then
10452 break
10453 end
10454 end
10455 if not redo then
10456 break
10457 end
10458 else
10459 break
10460 end
10461 end
10462 properties.mode=mode
10463 return true
10464 else
10465 return false
10466 end
10467 end
10468 function constructors.collectprocessors(what,tfmdata,features,trace,report)
10469 local processes={}
10470 local nofprocesses=0
10471 if features and next(features) then
10472 local properties=tfmdata.properties
10473 local whathandler=handlers[what]
10474 local whatfeatures=whathandler.features
10475 local whatprocessors=whatfeatures.processors
10476 local mode=properties.mode
10477 local processors=whatprocessors[mode]
10478 if processors then
10479 for i=1,#processors do
10480 local step=processors[i]
10481 local feature=step.name
10482 if features[feature] then
10483 local action=step.action
10484 if trace then
10485 report("installing feature processor %a for mode %a for font %a",feature,mode,tfmdata.properties.fullname)
10486 end
10487 if action then
10488 nofprocesses=nofprocesses+1
10489 processes[nofprocesses]=action
10490 end
10491 end
10492 end
10493 elseif trace then
10494 report("no feature processors for mode %a for font %a",mode,properties.fullname)
10495 end
10496 end
10497 return processes
10498 end
10499 function constructors.applymanipulators(what,tfmdata,features,trace,report)
10500 if features and next(features) then
10501 local properties=tfmdata.properties
10502 local whathandler=handlers[what]
10503 local whatfeatures=whathandler.features
10504 local whatmanipulators=whatfeatures.manipulators
10505 local mode=properties.mode
10506 local manipulators=whatmanipulators[mode]
10507 if manipulators then
10508 for i=1,#manipulators do
10509 local step=manipulators[i]
10510 local feature=step.name
10511 local value=features[feature]
10512 if value then
10513 local action=step.action
10514 if trace then
10515 report("applying feature manipulator %a for mode %a for font %a",feature,mode,properties.fullname)
10516 end
10517 if action then
10518 action(tfmdata,feature,value)
10519 end
10520 end
10521 end
10522 end
10523 end
10524 end
10525 function constructors.addcoreunicodes(unicodes)
10526 if not unicodes then
10527 unicodes={}
10528 end
10529 unicodes.space=0x0020
10530 unicodes.hyphen=0x002D
10531 unicodes.zwj=0x200D
10532 unicodes.zwnj=0x200C
10533 return unicodes
10534 end
10535
10536 end -- closure
10537
10538 do -- begin closure to overcome local limits and interference
10539
10540 if not modules then modules={} end modules ['luatex-font-enc']={
10541 version=1.001,
10542 comment="companion to luatex-*.tex",
10543 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
10544 copyright="PRAGMA ADE / ConTeXt Development Team",
10545 license="see context related readme files"
10546 }
10547 if context then
10548 --removed
10549
10550 end
10551 local fonts=fonts
10552 local encodings={}
10553 fonts.encodings=encodings
10554 encodings.agl={}
10555 encodings.known={}
10556 encodings.glyphlistfilename="font-age.lua"
10557 setmetatable(encodings.agl,{ __index=function(t,k)
10558 if k=="unicodes" then
10559 logs.report("fonts","loading (extended) adobe glyph list")
10560 local foundname=resolvers.findfile(encodings.glyphlistfilename) or ""
10561 local unicodes=foundname~="" and dofile(foundname)
10562 if type(unicodes)~="table" then
10563 logs.report("fonts","missing or invalid (extended) adobe glyph list")
10564 unicodes={}
10565 end
10566 encodings.agl={ unicodes=unicodes }
10567 return unicodes
10568 else
10569 return nil
10570 end
10571 end })
10572 encodings.cache=containers.define("fonts","enc",encodings.version,true)
10573 function encodings.load(filename)
10574 local name=file.removesuffix(filename)
10575 local data=containers.read(encodings.cache,name)
10576 if data then
10577 return data
10578 end
10579 local vector,tag,hash,unicodes={},"",{},{}
10580 local foundname=resolvers.findfile(filename,'enc')
10581 if foundname and foundname~="" then
10582 local ok,encoding,size=resolvers.loadbinfile(foundname)
10583 if ok and encoding then
10584 encoding=string.gsub(encoding,"%%(.-)\n","")
10585 local unicoding=encodings.agl.unicodes
10586 local tag,vec=string.match(encoding,"/(%w+)%s*%[(.*)%]%s*def")
10587 local i=0
10588 for ch in string.gmatch(vec,"/([%a%d%.]+)") do
10589 if ch~=".notdef" then
10590 vector[i]=ch
10591 if not hash[ch] then
10592 hash[ch]=i
10593 else
10594 end
10595 local u=unicoding[ch]
10596 if u then
10597 unicodes[u]=i
10598 end
10599 end
10600 i=i+1
10601 end
10602 end
10603 end
10604 local data={
10605 name=name,
10606 tag=tag,
10607 vector=vector,
10608 hash=hash,
10609 unicodes=unicodes
10610 }
10611 return containers.write(encodings.cache,name,data)
10612 end
10613
10614 end -- closure
10615
10616 do -- begin closure to overcome local limits and interference
10617
10618 if not modules then modules={} end modules ['font-cid']={
10619 version=1.001,
10620 comment="companion to font-ini.mkiv",
10621 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
10622 copyright="PRAGMA ADE / ConTeXt Development Team",
10623 license="see context related readme files"
10624 }
10625 local format,match,lower=string.format,string.match,string.lower
10626 local tonumber=tonumber
10627 local P,S,R,C,V,lpegmatch=lpeg.P,lpeg.S,lpeg.R,lpeg.C,lpeg.V,lpeg.match
10628 local fonts,logs,trackers=fonts,logs,trackers
10629 local trace_loading=false trackers.register("otf.loading",function(v) trace_loading=v end)
10630 local report_otf=logs.reporter("fonts","otf loading")
10631 local cid={}
10632 fonts.cid=cid
10633 local cidmap={}
10634 local cidmax=10
10635 local number=C(R("09","af","AF")^1)
10636 local space=S(" \n\r\t")
10637 local spaces=space^0
10638 local period=P(".")
10639 local periods=period*period
10640 local name=P("/")*C((1-space)^1)
10641 local unicodes,names={},{}
10642 local function do_one(a,b)
10643 unicodes[tonumber(a)]=tonumber(b,16)
10644 end
10645 local function do_range(a,b,c)
10646 c=tonumber(c,16)
10647 for i=tonumber(a),tonumber(b) do
10648 unicodes[i]=c
10649 c=c+1
10650 end
10651 end
10652 local function do_name(a,b)
10653 names[tonumber(a)]=b
10654 end
10655 local grammar=P { "start",
10656 start=number*spaces*number*V("series"),
10657 series=(spaces*(V("one")+V("range")+V("named")))^1,
10658 one=(number*spaces*number)/do_one,
10659 range=(number*periods*number*spaces*number)/do_range,
10660 named=(number*spaces*name)/do_name
10661 }
10662 local function loadcidfile(filename)
10663 local data=io.loaddata(filename)
10664 if data then
10665 unicodes,names={},{}
10666 lpegmatch(grammar,data)
10667 local supplement,registry,ordering=match(filename,"^(.-)%-(.-)%-()%.(.-)$")
10668 return {
10669 supplement=supplement,
10670 registry=registry,
10671 ordering=ordering,
10672 filename=filename,
10673 unicodes=unicodes,
10674 names=names,
10675 }
10676 end
10677 end
10678 cid.loadfile=loadcidfile
10679 local template="%s-%s-%s.cidmap"
10680 local function locate(registry,ordering,supplement)
10681 local filename=format(template,registry,ordering,supplement)
10682 local hashname=lower(filename)
10683 local found=cidmap[hashname]
10684 if not found then
10685 if trace_loading then
10686 report_otf("checking cidmap, registry %a, ordering %a, supplement %a, filename %a",registry,ordering,supplement,filename)
10687 end
10688 local fullname=resolvers.findfile(filename,'cid') or ""
10689 if fullname~="" then
10690 found=loadcidfile(fullname)
10691 if found then
10692 if trace_loading then
10693 report_otf("using cidmap file %a",filename)
10694 end
10695 cidmap[hashname]=found
10696 found.usedname=file.basename(filename)
10697 end
10698 end
10699 end
10700 return found
10701 end
10702 function cid.getmap(specification)
10703 if not specification then
10704 report_otf("invalid cidinfo specification, table expected")
10705 return
10706 end
10707 local registry=specification.registry
10708 local ordering=specification.ordering
10709 local supplement=specification.supplement
10710 local filename=format(registry,ordering,supplement)
10711 local lowername=lower(filename)
10712 local found=cidmap[lowername]
10713 if found then
10714 return found
10715 end
10716 if ordering=="Identity" then
10717 local found={
10718 supplement=supplement,
10719 registry=registry,
10720 ordering=ordering,
10721 filename=filename,
10722 unicodes={},
10723 names={},
10724 }
10725 cidmap[lowername]=found
10726 return found
10727 end
10728 if trace_loading then
10729 report_otf("cidmap needed, registry %a, ordering %a, supplement %a",registry,ordering,supplement)
10730 end
10731 found=locate(registry,ordering,supplement)
10732 if not found then
10733 local supnum=tonumber(supplement)
10734 local cidnum=nil
10735 if supnum<cidmax then
10736 for s=supnum+1,cidmax do
10737 local c=locate(registry,ordering,s)
10738 if c then
10739 found,cidnum=c,s
10740 break
10741 end
10742 end
10743 end
10744 if not found and supnum>0 then
10745 for s=supnum-1,0,-1 do
10746 local c=locate(registry,ordering,s)
10747 if c then
10748 found,cidnum=c,s
10749 break
10750 end
10751 end
10752 end
10753 registry=lower(registry)
10754 ordering=lower(ordering)
10755 if found and cidnum>0 then
10756 for s=0,cidnum-1 do
10757 local filename=format(template,registry,ordering,s)
10758 if not cidmap[filename] then
10759 cidmap[filename]=found
10760 end
10761 end
10762 end
10763 end
10764 return found
10765 end
10766
10767 end -- closure
10768
10769 do -- begin closure to overcome local limits and interference
10770
10771 if not modules then modules={} end modules ['font-map']={
10772 version=1.001,
10773 optimize=true,
10774 comment="companion to font-ini.mkiv",
10775 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
10776 copyright="PRAGMA ADE / ConTeXt Development Team",
10777 license="see context related readme files"
10778 }
10779 local tonumber,next,type=tonumber,next,type
10780 local match,format,find,concat,gsub,lower=string.match,string.format,string.find,table.concat,string.gsub,string.lower
10781 local P,R,S,C,Ct,Cc,lpegmatch=lpeg.P,lpeg.R,lpeg.S,lpeg.C,lpeg.Ct,lpeg.Cc,lpeg.match
10782 local formatters=string.formatters
10783 local sortedhash,sortedkeys=table.sortedhash,table.sortedkeys
10784 local idiv=number.idiv
10785 local trace_loading=false trackers.register("fonts.loading",function(v) trace_loading=v end)
10786 local trace_mapping=false trackers.register("fonts.mapping",function(v) trace_mapping=v end)
10787 local report_fonts=logs.reporter("fonts","loading")
10788 local force_ligatures=false directives.register("fonts.mapping.forceligatures",function(v) force_ligatures=v end)
10789 local fonts=fonts or {}
10790 local mappings=fonts.mappings or {}
10791 fonts.mappings=mappings
10792 local allocate=utilities.storage.allocate
10793 local hex=R("AF","af","09")
10794 local hexfour=(hex*hex*hex^-2)/function(s) return tonumber(s,16) end
10795 local hexsix=(hex*hex*hex^-4)/function(s) return tonumber(s,16) end
10796 local dec=(R("09")^1)/tonumber
10797 local period=P(".")
10798 local unicode=(P("uni")+P("UNI"))*(hexfour*(period+P(-1))*Cc(false)+Ct(hexfour^1)*Cc(true))
10799 local ucode=(P("u")+P("U") )*(hexsix*(period+P(-1))*Cc(false)+Ct(hexsix^1)*Cc(true))
10800 local index=P("index")*dec*Cc(false)
10801 local parser=unicode+ucode+index
10802 local parsers={}
10803 local function makenameparser(str)
10804 if not str or str=="" then
10805 return parser
10806 else
10807 local p=parsers[str]
10808 if not p then
10809 p=P(str)*period*dec*Cc(false)
10810 parsers[str]=p
10811 end
10812 return p
10813 end
10814 end
10815 local f_single=formatters["%04X"]
10816 local f_double=formatters["%04X%04X"]
10817 local s_unknown="FFFD"
10818 local function tounicode16(unicode)
10819 if unicode<0xD7FF or (unicode>0xDFFF and unicode<=0xFFFF) then
10820 return f_single(unicode)
10821 elseif unicode>=0x00E000 and unicode<=0x00F8FF then
10822 return s_unknown
10823 elseif unicode>=0x0F0000 and unicode<=0x0FFFFF then
10824 return s_unknown
10825 elseif unicode>=0x100000 and unicode<=0x10FFFF then
10826 return s_unknown
10827 elseif unicode>=0x00D800 and unicode<=0x00DFFF then
10828 return s_unknown
10829 else
10830 unicode=unicode-0x10000
10831 return f_double(idiv(unicode,0x400)+0xD800,unicode%0x400+0xDC00)
10832 end
10833 end
10834 local function tounicode16sequence(unicodes)
10835 local t={}
10836 for l=1,#unicodes do
10837 local u=unicodes[l]
10838 if u<0xD7FF or (u>0xDFFF and u<=0xFFFF) then
10839 t[l]=f_single(u)
10840 elseif unicode>=0x00E000 and unicode<=0x00F8FF then
10841 t[l]=s_unknown
10842 elseif unicode>=0x0F0000 and unicode<=0x0FFFFF then
10843 t[l]=s_unknown
10844 elseif unicode>=0x100000 and unicode<=0x10FFFF then
10845 t[l]=s_unknown
10846 elseif unicode>=0x00D7FF and unicode<=0x00DFFF then
10847 t[l]=s_unknown
10848 else
10849 u=u-0x10000
10850 t[l]=f_double(idiv(u,0x400)+0xD800,u%0x400+0xDC00)
10851 end
10852 end
10853 return concat(t)
10854 end
10855 local hash={}
10856 local conc={}
10857 table.setmetatableindex(hash,function(t,k)
10858 local v
10859 if k<0xD7FF or (k>0xDFFF and k<=0xFFFF) then
10860 v=f_single(k)
10861 else
10862 local k=k-0x10000
10863 v=f_double(idiv(k,0x400)+0xD800,k%0x400+0xDC00)
10864 end
10865 t[k]=v
10866 return v
10867 end)
10868 local function tounicode(k)
10869 if type(k)=="table" then
10870 local n=#k
10871 for l=1,n do
10872 conc[l]=hash[k[l]]
10873 end
10874 return concat(conc,"",1,n)
10875 elseif k>=0x00E000 and k<=0x00F8FF then
10876 return s_unknown
10877 elseif k>=0x0F0000 and k<=0x0FFFFF then
10878 return s_unknown
10879 elseif k>=0x100000 and k<=0x10FFFF then
10880 return s_unknown
10881 elseif k>=0x00D7FF and k<=0x00DFFF then
10882 return s_unknown
10883 else
10884 return hash[k]
10885 end
10886 end
10887 local function fromunicode16(str)
10888 if #str==4 then
10889 return tonumber(str,16)
10890 else
10891 local l,r=match(str,"(....)(....)")
10892 return 0x10000+(tonumber(l,16)-0xD800)*0x400+tonumber(r,16)-0xDC00
10893 end
10894 end
10895 mappings.makenameparser=makenameparser
10896 mappings.tounicode=tounicode
10897 mappings.tounicode16=tounicode16
10898 mappings.tounicode16sequence=tounicode16sequence
10899 mappings.fromunicode16=fromunicode16
10900 local ligseparator=P("_")
10901 local varseparator=P(".")
10902 local namesplitter=Ct(C((1-ligseparator-varseparator)^1)*(ligseparator*C((1-ligseparator-varseparator)^1))^0)
10903 do
10904 local overloads={
10905 IJ={ name="I_J",unicode={ 0x49,0x4A },mess=0x0132 },
10906 ij={ name="i_j",unicode={ 0x69,0x6A },mess=0x0133 },
10907 ff={ name="f_f",unicode={ 0x66,0x66 },mess=0xFB00 },
10908 fi={ name="f_i",unicode={ 0x66,0x69 },mess=0xFB01 },
10909 fl={ name="f_l",unicode={ 0x66,0x6C },mess=0xFB02 },
10910 ffi={ name="f_f_i",unicode={ 0x66,0x66,0x69 },mess=0xFB03 },
10911 ffl={ name="f_f_l",unicode={ 0x66,0x66,0x6C },mess=0xFB04 },
10912 fj={ name="f_j",unicode={ 0x66,0x6A } },
10913 fk={ name="f_k",unicode={ 0x66,0x6B } },
10914 }
10915 local o=allocate {}
10916 for k,v in next,overloads do
10917 local name=v.name
10918 local mess=v.mess
10919 if name then
10920 o[name]=v
10921 end
10922 if mess then
10923 o[mess]=v
10924 end
10925 o[k]=v
10926 end
10927 mappings.overloads=o
10928 end
10929 function mappings.addtounicode(data,filename,checklookups,forceligatures)
10930 local resources=data.resources
10931 local unicodes=resources.unicodes
10932 if not unicodes then
10933 if trace_mapping then
10934 report_fonts("no unicode list, quitting tounicode for %a",filename)
10935 end
10936 return
10937 end
10938 local properties=data.properties
10939 local descriptions=data.descriptions
10940 local overloads=mappings.overloads
10941 unicodes['space']=unicodes['space'] or 32
10942 unicodes['hyphen']=unicodes['hyphen'] or 45
10943 unicodes['zwj']=unicodes['zwj'] or 0x200D
10944 unicodes['zwnj']=unicodes['zwnj'] or 0x200C
10945 local private=fonts.constructors and fonts.constructors.privateoffset or 0xF0000
10946 local unicodevector=fonts.encodings.agl.unicodes or {}
10947 local contextvector=fonts.encodings.agl.ctxcodes or {}
10948 local missing={}
10949 local nofmissing=0
10950 local oparser=nil
10951 local cidnames=nil
10952 local cidcodes=nil
10953 local cidinfo=properties.cidinfo
10954 local usedmap=cidinfo and fonts.cid.getmap(cidinfo)
10955 local uparser=makenameparser()
10956 if usedmap then
10957 oparser=usedmap and makenameparser(cidinfo.ordering)
10958 cidnames=usedmap.names
10959 cidcodes=usedmap.unicodes
10960 end
10961 local ns=0
10962 local nl=0
10963 local dlist=sortedkeys(descriptions)
10964 for i=1,#dlist do
10965 local du=dlist[i]
10966 local glyph=descriptions[du]
10967 local name=glyph.name
10968 if name then
10969 local overload=overloads[name] or overloads[du]
10970 if overload then
10971 glyph.unicode=overload.unicode
10972 else
10973 local gu=glyph.unicode
10974 if not gu or gu==-1 or du>=private or (du>=0xE000 and du<=0xF8FF) or du==0xFFFE or du==0xFFFF then
10975 local unicode=unicodevector[name] or contextvector[name]
10976 if unicode then
10977 glyph.unicode=unicode
10978 ns=ns+1
10979 end
10980 if (not unicode) and usedmap then
10981 local foundindex=lpegmatch(oparser,name)
10982 if foundindex then
10983 unicode=cidcodes[foundindex]
10984 if unicode then
10985 glyph.unicode=unicode
10986 ns=ns+1
10987 else
10988 local reference=cidnames[foundindex]
10989 if reference then
10990 local foundindex=lpegmatch(oparser,reference)
10991 if foundindex then
10992 unicode=cidcodes[foundindex]
10993 if unicode then
10994 glyph.unicode=unicode
10995 ns=ns+1
10996 end
10997 end
10998 if not unicode or unicode=="" then
10999 local foundcodes,multiple=lpegmatch(uparser,reference)
11000 if foundcodes then
11001 glyph.unicode=foundcodes
11002 if multiple then
11003 nl=nl+1
11004 unicode=true
11005 else
11006 ns=ns+1
11007 unicode=foundcodes
11008 end
11009 end
11010 end
11011 end
11012 end
11013 end
11014 end
11015 if not unicode or unicode=="" then
11016 local split=lpegmatch(namesplitter,name)
11017 local nsplit=split and #split or 0
11018 if nsplit==0 then
11019 elseif nsplit==1 then
11020 local base=split[1]
11021 local u=unicodes[base] or unicodevector[base] or contextvector[name]
11022 if not u then
11023 elseif type(u)=="table" then
11024 if u[1]<private then
11025 unicode=u
11026 glyph.unicode=unicode
11027 end
11028 elseif u<private then
11029 unicode=u
11030 glyph.unicode=unicode
11031 end
11032 else
11033 local t={}
11034 local n=0
11035 for l=1,nsplit do
11036 local base=split[l]
11037 local u=unicodes[base] or unicodevector[base] or contextvector[name]
11038 if not u then
11039 break
11040 elseif type(u)=="table" then
11041 if u[1]>=private then
11042 break
11043 end
11044 n=n+1
11045 t[n]=u[1]
11046 else
11047 if u>=private then
11048 break
11049 end
11050 n=n+1
11051 t[n]=u
11052 end
11053 end
11054 if n>0 then
11055 if n==1 then
11056 unicode=t[1]
11057 else
11058 unicode=t
11059 end
11060 glyph.unicode=unicode
11061 end
11062 end
11063 nl=nl+1
11064 end
11065 if not unicode or unicode=="" then
11066 local foundcodes,multiple=lpegmatch(uparser,name)
11067 if foundcodes then
11068 glyph.unicode=foundcodes
11069 if multiple then
11070 nl=nl+1
11071 unicode=true
11072 else
11073 ns=ns+1
11074 unicode=foundcodes
11075 end
11076 end
11077 end
11078 local r=overloads[unicode]
11079 if r then
11080 unicode=r.unicode
11081 glyph.unicode=unicode
11082 end
11083 if not unicode then
11084 missing[du]=true
11085 nofmissing=nofmissing+1
11086 end
11087 else
11088 end
11089 end
11090 else
11091 local overload=overloads[du]
11092 if overload then
11093 glyph.unicode=overload.unicode
11094 elseif not glyph.unicode then
11095 missing[du]=true
11096 nofmissing=nofmissing+1
11097 end
11098 end
11099 end
11100 if type(checklookups)=="function" then
11101 checklookups(data,missing,nofmissing)
11102 end
11103 local unicoded=0
11104 local collected=fonts.handlers.otf.readers.getcomponents(data)
11105 local function resolve(glyph,u)
11106 local n=#u
11107 for i=1,n do
11108 if u[i]>private then
11109 n=0
11110 break
11111 end
11112 end
11113 if n>0 then
11114 if n>1 then
11115 glyph.unicode=u
11116 else
11117 glyph.unicode=u[1]
11118 end
11119 unicoded=unicoded+1
11120 end
11121 end
11122 if not collected then
11123 elseif forceligatures or force_ligatures then
11124 for i=1,#dlist do
11125 local du=dlist[i]
11126 if du>=private or (du>=0xE000 and du<=0xF8FF) then
11127 local u=collected[du]
11128 if u then
11129 resolve(descriptions[du],u)
11130 end
11131 end
11132 end
11133 else
11134 for i=1,#dlist do
11135 local du=dlist[i]
11136 if du>=private or (du>=0xE000 and du<=0xF8FF) then
11137 local glyph=descriptions[du]
11138 if glyph.class=="ligature" and not glyph.unicode then
11139 local u=collected[du]
11140 if u then
11141 resolve(glyph,u)
11142 end
11143 end
11144 end
11145 end
11146 end
11147 if trace_mapping and unicoded>0 then
11148 report_fonts("%n ligature tounicode mappings deduced from gsub ligature features",unicoded)
11149 end
11150 if trace_mapping then
11151 for i=1,#dlist do
11152 local du=dlist[i]
11153 local glyph=descriptions[du]
11154 local name=glyph.name or "-"
11155 local index=glyph.index or 0
11156 local unicode=glyph.unicode
11157 if unicode then
11158 if type(unicode)=="table" then
11159 local unicodes={}
11160 for i=1,#unicode do
11161 unicodes[i]=formatters("%U",unicode[i])
11162 end
11163 report_fonts("internal slot %U, name %a, unicode %U, tounicode % t",index,name,du,unicodes)
11164 else
11165 report_fonts("internal slot %U, name %a, unicode %U, tounicode %U",index,name,du,unicode)
11166 end
11167 else
11168 report_fonts("internal slot %U, name %a, unicode %U",index,name,du)
11169 end
11170 end
11171 end
11172 if trace_loading and (ns>0 or nl>0) then
11173 report_fonts("%s tounicode entries added, ligatures %s",nl+ns,ns)
11174 end
11175 end
11176
11177 end -- closure
11178
11179 do -- begin closure to overcome local limits and interference
11180
11181 if not modules then modules={} end modules ['luatex-fonts-syn']={
11182 version=1.001,
11183 comment="companion to luatex-*.tex",
11184 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
11185 copyright="PRAGMA ADE / ConTeXt Development Team",
11186 license="see context related readme files"
11187 }
11188 if context then
11189 --removed
11190
11191 end
11192 local fonts=fonts
11193 fonts.names=fonts.names or {}
11194 fonts.names.version=1.001
11195 fonts.names.basename="luatex-fonts-names"
11196 fonts.names.cache=containers.define("fonts","data",fonts.names.version,true)
11197 local data=nil
11198 local loaded=false
11199 local fileformats={ "lua","tex","other text files" }
11200 function fonts.names.reportmissingbase()
11201 logs.report("fonts","missing font database, run: mtxrun --script fonts --reload --simple")
11202 fonts.names.reportmissingbase=nil
11203 end
11204 function fonts.names.reportmissingname()
11205 logs.report("fonts","unknown font in font database, run: mtxrun --script fonts --reload --simple")
11206 fonts.names.reportmissingname=nil
11207 end
11208 function fonts.names.resolve(name,sub)
11209 if not loaded then
11210 local basename=fonts.names.basename
11211 if basename and basename~="" then
11212 data=containers.read(fonts.names.cache,basename)
11213 if not data then
11214 basename=file.addsuffix(basename,"lua")
11215 for i=1,#fileformats do
11216 local format=fileformats[i]
11217 local foundname=resolvers.findfile(basename,format) or ""
11218 if foundname~="" then
11219 data=dofile(foundname)
11220 logs.report("fonts","font database '%s' loaded",foundname)
11221 break
11222 end
11223 end
11224 end
11225 end
11226 loaded=true
11227 end
11228 if type(data)=="table" and data.version==fonts.names.version then
11229 local condensed=string.gsub(string.lower(name),"[^%a%d]","")
11230 local found=data.mappings and data.mappings[condensed]
11231 if found then
11232 local fontname,filename,subfont=found[1],found[2],found[3]
11233 if subfont then
11234 return filename,fontname
11235 else
11236 return filename,false
11237 end
11238 elseif fonts.names.reportmissingname then
11239 fonts.names.reportmissingname()
11240 return name,false
11241 end
11242 elseif fonts.names.reportmissingbase then
11243 fonts.names.reportmissingbase()
11244 end
11245 end
11246 fonts.names.resolvespec=fonts.names.resolve
11247 function fonts.names.getfilename(askedname,suffix)
11248 return ""
11249 end
11250 function fonts.names.ignoredfile(filename)
11251 return false
11252 end
11253
11254 end -- closure
11255
11256 do -- begin closure to overcome local limits and interference
11257
11258 if not modules then modules={} end modules ['font-vfc']={
11259 version=1.001,
11260 comment="companion to font-ini.mkiv and hand-ini.mkiv",
11261 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
11262 copyright="PRAGMA ADE / ConTeXt Development Team",
11263 license="see context related readme files"
11264 }
11265 local select,type=select,type
11266 local insert=table.insert
11267 local fonts=fonts
11268 local helpers=fonts.helpers
11269 local setmetatableindex=table.setmetatableindex
11270 local push={ "push" }
11271 local pop={ "pop" }
11272 local dummy={ "comment" }
11273 function helpers.prependcommands(commands,...)
11274 insert(commands,1,push)
11275 for i=select("#",...),1,-1 do
11276 local s=(select(i,...))
11277 if s then
11278 insert(commands,1,s)
11279 end
11280 end
11281 insert(commands,pop)
11282 return commands
11283 end
11284 function helpers.appendcommands(commands,...)
11285 insert(commands,1,push)
11286 insert(commands,pop)
11287 for i=1,select("#",...) do
11288 local s=(select(i,...))
11289 if s then
11290 insert(commands,s)
11291 end
11292 end
11293 return commands
11294 end
11295 function helpers.prependcommandtable(commands,t)
11296 insert(commands,1,push)
11297 for i=#t,1,-1 do
11298 local s=t[i]
11299 if s then
11300 insert(commands,1,s)
11301 end
11302 end
11303 insert(commands,pop)
11304 return commands
11305 end
11306 function helpers.appendcommandtable(commands,t)
11307 insert(commands,1,push)
11308 insert(commands,pop)
11309 for i=1,#t do
11310 local s=t[i]
11311 if s then
11312 insert(commands,s)
11313 end
11314 end
11315 return commands
11316 end
11317 local char=setmetatableindex(function(t,k)
11318 local v={ "slot",0,k }
11319 t[k]=v
11320 return v
11321 end)
11322 local right=setmetatableindex(function(t,k)
11323 local v={ "right",k }
11324 t[k]=v
11325 return v
11326 end)
11327 local left=setmetatableindex(function(t,k)
11328 local v={ "right",-k }
11329 t[k]=v
11330 return v
11331 end)
11332 local down=setmetatableindex(function(t,k)
11333 local v={ "down",k }
11334 t[k]=v
11335 return v
11336 end)
11337 local up=setmetatableindex(function(t,k)
11338 local v={ "down",-k }
11339 t[k]=v
11340 return v
11341 end)
11342 helpers.commands=utilities.storage.allocate {
11343 char=char,
11344 right=right,
11345 left=left,
11346 down=down,
11347 up=up,
11348 push=push,
11349 pop=pop,
11350 dummy=dummy,
11351 }
11352
11353 end -- closure
11354
11355 do -- begin closure to overcome local limits and interference
11356
11357 if not modules then modules={} end modules ['font-otr']={
11358 version=1.001,
11359 optimize=true,
11360 comment="companion to font-ini.mkiv",
11361 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
11362 copyright="PRAGMA ADE / ConTeXt Development Team",
11363 license="see context related readme files"
11364 }
11365 local number=number
11366 local next,type,tonumber,rawget=next,type,tonumber,rawget
11367 local byte,lower,char,gsub=string.byte,string.lower,string.char,string.gsub
11368 local fullstrip=string.fullstrip
11369 local floor,round=math.floor,math.round
11370 local P,R,S,C,Cs,Cc,Ct,Carg,Cmt=lpeg.P,lpeg.R,lpeg.S,lpeg.C,lpeg.Cs,lpeg.Cc,lpeg.Ct,lpeg.Carg,lpeg.Cmt
11371 local lpegmatch=lpeg.match
11372 local rshift=bit32.rshift
11373 local setmetatableindex=table.setmetatableindex
11374 local sortedkeys=table.sortedkeys
11375 local sortedhash=table.sortedhash
11376 local stripstring=string.nospaces
11377 local utf16_to_utf8_be=utf.utf16_to_utf8_be
11378 local report=logs.reporter("otf reader")
11379 local report_cmap=logs.reporter("otf reader","cmap")
11380 local trace_cmap=false trackers.register("otf.cmap",function(v) trace_cmap=v end)
11381 local trace_cmap_details=false trackers.register("otf.cmap.details",function(v) trace_cmap_details=v end)
11382 fonts=fonts or {}
11383 local handlers=fonts.handlers or {}
11384 fonts.handlers=handlers
11385 local otf=handlers.otf or {}
11386 handlers.otf=otf
11387 local readers=otf.readers or {}
11388 otf.readers=readers
11389 local streamreader=utilities.files
11390 local streamwriter=utilities.files
11391 readers.streamreader=streamreader
11392 readers.streamwriter=streamwriter
11393 local openfile=streamreader.open
11394 local closefile=streamreader.close
11395 local setposition=streamreader.setposition
11396 local skipshort=streamreader.skipshort
11397 local readbytes=streamreader.readbytes
11398 local readstring=streamreader.readstring
11399 local readbyte=streamreader.readcardinal1
11400 local readushort=streamreader.readcardinal2
11401 local readuint=streamreader.readcardinal3
11402 local readulong=streamreader.readcardinal4
11403 local readshort=streamreader.readinteger2
11404 local readlong=streamreader.readinteger4
11405 local readfixed=streamreader.readfixed4
11406 local read2dot14=streamreader.read2dot14
11407 local readfword=readshort
11408 local readufword=readushort
11409 local readoffset=readushort
11410 local readcardinaltable=streamreader.readcardinaltable
11411 local readintegertable=streamreader.readintegertable
11412 function streamreader.readtag(f)
11413 return lower(stripstring(readstring(f,4)))
11414 end
11415 local short=2
11416 local ushort=2
11417 local ulong=4
11418 directives.register("fonts.streamreader",function()
11419 streamreader=utilities.streams
11420 openfile=streamreader.open
11421 closefile=streamreader.close
11422 setposition=streamreader.setposition
11423 skipshort=streamreader.skipshort
11424 readbytes=streamreader.readbytes
11425 readstring=streamreader.readstring
11426 readbyte=streamreader.readcardinal1
11427 readushort=streamreader.readcardinal2
11428 readuint=streamreader.readcardinal3
11429 readulong=streamreader.readcardinal4
11430 readshort=streamreader.readinteger2
11431 readlong=streamreader.readinteger4
11432 readfixed=streamreader.readfixed4
11433 read2dot14=streamreader.read2dot14
11434 readfword=readshort
11435 readufword=readushort
11436 readoffset=readushort
11437 readcardinaltable=streamreader.readcardinaltable
11438 readintegertable=streamreader.readintegertable
11439 function streamreader.readtag(f)
11440 return lower(stripstring(readstring(f,4)))
11441 end
11442 end)
11443 local function readlongdatetime(f)
11444 local a,b,c,d,e,f,g,h=readbytes(f,8)
11445 return 0x100000000*d+0x1000000*e+0x10000*f+0x100*g+h
11446 end
11447 local tableversion=0.004
11448 readers.tableversion=tableversion
11449 local privateoffset=fonts.constructors and fonts.constructors.privateoffset or 0xF0000
11450 local reservednames={ [0]="copyright",
11451 "family",
11452 "subfamily",
11453 "uniqueid",
11454 "fullname",
11455 "version",
11456 "postscriptname",
11457 "trademark",
11458 "manufacturer",
11459 "designer",
11460 "description",
11461 "vendorurl",
11462 "designerurl",
11463 "license",
11464 "licenseurl",
11465 "reserved",
11466 "typographicfamily",
11467 "typographicsubfamily",
11468 "compatiblefullname",
11469 "sampletext",
11470 "cidfindfontname",
11471 "wwsfamily",
11472 "wwssubfamily",
11473 "lightbackgroundpalette",
11474 "darkbackgroundpalette",
11475 "variationspostscriptnameprefix",
11476 }
11477 local platforms={ [0]="unicode",
11478 "macintosh",
11479 "iso",
11480 "windows",
11481 "custom",
11482 }
11483 local encodings={
11484 unicode={ [0]="unicode 1.0 semantics",
11485 "unicode 1.1 semantics",
11486 "iso/iec 10646",
11487 "unicode 2.0 bmp",
11488 "unicode 2.0 full",
11489 "unicode variation sequences",
11490 "unicode full repertoire",
11491 },
11492 macintosh={ [0]="roman","japanese","chinese (traditional)","korean","arabic","hebrew","greek","russian",
11493 "rsymbol","devanagari","gurmukhi","gujarati","oriya","bengali","tamil","telugu","kannada",
11494 "malayalam","sinhalese","burmese","khmer","thai","laotian","georgian","armenian",
11495 "chinese (simplified)","tibetan","mongolian","geez","slavic","vietnamese","sindhi",
11496 "uninterpreted",
11497 },
11498 iso={ [0]="7-bit ascii",
11499 "iso 10646",
11500 "iso 8859-1",
11501 },
11502 windows={ [0]="symbol",
11503 "unicode bmp",
11504 "shiftjis",
11505 "prc",
11506 "big5",
11507 "wansung",
11508 "johab",
11509 "reserved 7",
11510 "reserved 8",
11511 "reserved 9",
11512 "unicode ucs-4",
11513 },
11514 custom={
11515 }
11516 }
11517 local decoders={
11518 unicode={},
11519 macintosh={},
11520 iso={},
11521 windows={
11522 ["unicode semantics"]=utf16_to_utf8_be,
11523 ["unicode bmp"]=utf16_to_utf8_be,
11524 ["unicode full"]=utf16_to_utf8_be,
11525 ["unicode 1.0 semantics"]=utf16_to_utf8_be,
11526 ["unicode 1.1 semantics"]=utf16_to_utf8_be,
11527 ["unicode 2.0 bmp"]=utf16_to_utf8_be,
11528 ["unicode 2.0 full"]=utf16_to_utf8_be,
11529 ["unicode variation sequences"]=utf16_to_utf8_be,
11530 ["unicode full repertoire"]=utf16_to_utf8_be,
11531 },
11532 custom={},
11533 }
11534 local languages={
11535 unicode={
11536 [ 0]="english",
11537 },
11538 macintosh={
11539 [ 0]="english",
11540 },
11541 iso={},
11542 windows={
11543 [0x0409]="english - united states",
11544 },
11545 custom={},
11546 }
11547 local standardromanencoding={ [0]=
11548 "notdef",".null","nonmarkingreturn","space","exclam","quotedbl",
11549 "numbersign","dollar","percent","ampersand","quotesingle","parenleft",
11550 "parenright","asterisk","plus","comma","hyphen","period","slash",
11551 "zero","one","two","three","four","five","six","seven","eight",
11552 "nine","colon","semicolon","less","equal","greater","question","at",
11553 "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O",
11554 "P","Q","R","S","T","U","V","W","X","Y","Z","bracketleft",
11555 "backslash","bracketright","asciicircum","underscore","grave","a","b",
11556 "c","d","e","f","g","h","i","j","k","l","m","n","o","p","q",
11557 "r","s","t","u","v","w","x","y","z","braceleft","bar",
11558 "braceright","asciitilde","Adieresis","Aring","Ccedilla","Eacute",
11559 "Ntilde","Odieresis","Udieresis","aacute","agrave","acircumflex",
11560 "adieresis","atilde","aring","ccedilla","eacute","egrave",
11561 "ecircumflex","edieresis","iacute","igrave","icircumflex","idieresis",
11562 "ntilde","oacute","ograve","ocircumflex","odieresis","otilde","uacute",
11563 "ugrave","ucircumflex","udieresis","dagger","degree","cent","sterling",
11564 "section","bullet","paragraph","germandbls","registered","copyright",
11565 "trademark","acute","dieresis","notequal","AE","Oslash","infinity",
11566 "plusminus","lessequal","greaterequal","yen","mu","partialdiff",
11567 "summation","product","pi","integral","ordfeminine","ordmasculine",
11568 "Omega","ae","oslash","questiondown","exclamdown","logicalnot",
11569 "radical","florin","approxequal","Delta","guillemotleft",
11570 "guillemotright","ellipsis","nonbreakingspace","Agrave","Atilde",
11571 "Otilde","OE","oe","endash","emdash","quotedblleft","quotedblright",
11572 "quoteleft","quoteright","divide","lozenge","ydieresis","Ydieresis",
11573 "fraction","currency","guilsinglleft","guilsinglright","fi","fl",
11574 "daggerdbl","periodcentered","quotesinglbase","quotedblbase",
11575 "perthousand","Acircumflex","Ecircumflex","Aacute","Edieresis","Egrave",
11576 "Iacute","Icircumflex","Idieresis","Igrave","Oacute","Ocircumflex",
11577 "apple","Ograve","Uacute","Ucircumflex","Ugrave","dotlessi",
11578 "circumflex","tilde","macron","breve","dotaccent","ring","cedilla",
11579 "hungarumlaut","ogonek","caron","Lslash","lslash","Scaron","scaron",
11580 "Zcaron","zcaron","brokenbar","Eth","eth","Yacute","yacute","Thorn",
11581 "thorn","minus","multiply","onesuperior","twosuperior","threesuperior",
11582 "onehalf","onequarter","threequarters","franc","Gbreve","gbreve",
11583 "Idotaccent","Scedilla","scedilla","Cacute","cacute","Ccaron","ccaron",
11584 "dcroat",
11585 }
11586 local weights={
11587 [100]="thin",
11588 [200]="extralight",
11589 [300]="light",
11590 [400]="normal",
11591 [500]="medium",
11592 [600]="semibold",
11593 [700]="bold",
11594 [800]="extrabold",
11595 [900]="black",
11596 }
11597 local widths={
11598 "ultracondensed",
11599 "extracondensed",
11600 "condensed",
11601 "semicondensed",
11602 "normal",
11603 "semiexpanded",
11604 "expanded",
11605 "extraexpanded",
11606 "ultraexpanded",
11607 }
11608 setmetatableindex(weights,function(t,k)
11609 local r=floor((k+50)/100)*100
11610 local v=(r>900 and "black") or rawget(t,r) or "normal"
11611 return v
11612 end)
11613 setmetatableindex(widths,function(t,k)
11614 return "normal"
11615 end)
11616 local panoseweights={ [0]="normal",
11617 "normal",
11618 "verylight",
11619 "light",
11620 "thin",
11621 "book",
11622 "medium",
11623 "demi",
11624 "bold",
11625 "heavy",
11626 "black",
11627 }
11628 local panosewidths={ [0]="normal",
11629 "normal",
11630 "normal",
11631 "normal",
11632 "normal",
11633 "expanded",
11634 "condensed",
11635 "veryexpanded",
11636 "verycondensed",
11637 "monospaced",
11638 }
11639 local helpers={}
11640 readers.helpers=helpers
11641 local function gotodatatable(f,fontdata,tag,criterium)
11642 if criterium and f then
11643 local tables=fontdata.tables
11644 if tables then
11645 local datatable=tables[tag]
11646 if datatable then
11647 local tableoffset=datatable.offset
11648 setposition(f,tableoffset)
11649 return tableoffset
11650 end
11651 else
11652 report("no tables")
11653 end
11654 end
11655 end
11656 local function reportskippedtable(f,fontdata,tag,criterium)
11657 if criterium and f then
11658 local tables=fontdata.tables
11659 if tables then
11660 local datatable=tables[tag]
11661 if datatable then
11662 report("loading of table %a skipped",tag)
11663 end
11664 else
11665 report("no tables")
11666 end
11667 end
11668 end
11669 local function setvariabledata(fontdata,tag,data)
11670 local variabledata=fontdata.variabledata
11671 if variabledata then
11672 variabledata[tag]=data
11673 else
11674 fontdata.variabledata={ [tag]=data }
11675 end
11676 end
11677 helpers.gotodatatable=gotodatatable
11678 helpers.setvariabledata=setvariabledata
11679 helpers.reportskippedtable=reportskippedtable
11680 local platformnames={
11681 postscriptname=true,
11682 fullname=true,
11683 family=true,
11684 subfamily=true,
11685 typographicfamily=true,
11686 typographicsubfamily=true,
11687 compatiblefullname=true,
11688 }
11689 local platformextras={
11690 uniqueid=true,
11691 version=true,
11692 copyright=true,
11693 license=true,
11694 licenseurl=true,
11695 manufacturer=true,
11696 vendorurl=true,
11697 }
11698 function readers.name(f,fontdata,specification)
11699 local tableoffset=gotodatatable(f,fontdata,"name",true)
11700 if tableoffset then
11701 local format=readushort(f)
11702 local nofnames=readushort(f)
11703 local offset=readushort(f)
11704 local start=tableoffset+offset
11705 local namelists={
11706 unicode={},
11707 windows={},
11708 macintosh={},
11709 }
11710 for i=1,nofnames do
11711 local platform=platforms[readushort(f)]
11712 if platform then
11713 local namelist=namelists[platform]
11714 if namelist then
11715 local encoding=readushort(f)
11716 local language=readushort(f)
11717 local encodings=encodings[platform]
11718 local languages=languages[platform]
11719 if encodings and languages then
11720 local encoding=encodings[encoding]
11721 local language=languages[language]
11722 if encoding and language then
11723 local index=readushort(f)
11724 local name=reservednames[index]
11725 namelist[#namelist+1]={
11726 platform=platform,
11727 encoding=encoding,
11728 language=language,
11729 name=name,
11730 index=index,
11731 length=readushort(f),
11732 offset=start+readushort(f),
11733 }
11734 else
11735 skipshort(f,3)
11736 end
11737 else
11738 skipshort(f,3)
11739 end
11740 else
11741 skipshort(f,5)
11742 end
11743 else
11744 skipshort(f,5)
11745 end
11746 end
11747 local names={}
11748 local done={}
11749 local extras={}
11750 local function decoded(platform,encoding,content)
11751 local decoder=decoders[platform]
11752 if decoder then
11753 decoder=decoder[encoding]
11754 end
11755 if decoder then
11756 return decoder(content)
11757 else
11758 return content
11759 end
11760 end
11761 local function filter(platform,e,l)
11762 local namelist=namelists[platform]
11763 for i=1,#namelist do
11764 local name=namelist[i]
11765 local nametag=name.name
11766 local index=name.index
11767 if not done[nametag or i] then
11768 local encoding=name.encoding
11769 local language=name.language
11770 if (not e or encoding==e) and (not l or language==l) then
11771 setposition(f,name.offset)
11772 local content=decoded(platform,encoding,readstring(f,name.length))
11773 if nametag then
11774 names[nametag]={
11775 content=content,
11776 platform=platform,
11777 encoding=encoding,
11778 language=language,
11779 }
11780 end
11781 extras[index]=content
11782 done[nametag or i]=true
11783 end
11784 end
11785 end
11786 end
11787 filter("windows","unicode bmp","english - united states")
11788 filter("macintosh","roman","english")
11789 filter("windows")
11790 filter("macintosh")
11791 filter("unicode")
11792 fontdata.names=names
11793 fontdata.extras=extras
11794 if specification.platformnames then
11795 local collected={}
11796 local platformextras=specification.platformextras and platformextras
11797 for platform,namelist in next,namelists do
11798 local filtered=false
11799 for i=1,#namelist do
11800 local entry=namelist[i]
11801 local name=entry.name
11802 if platformnames[name] or (platformextras and platformextras[name]) then
11803 setposition(f,entry.offset)
11804 local content=decoded(platform,entry.encoding,readstring(f,entry.length))
11805 if filtered then
11806 filtered[name]=content
11807 else
11808 filtered={ [name]=content }
11809 end
11810 end
11811 end
11812 if filtered then
11813 collected[platform]=filtered
11814 end
11815 end
11816 fontdata.platformnames=collected
11817 end
11818 else
11819 fontdata.names={}
11820 end
11821 end
11822 local validutf=lpeg.patterns.validutf8
11823 local function getname(fontdata,key)
11824 local names=fontdata.names
11825 if names then
11826 local value=names[key]
11827 if value then
11828 local content=value.content
11829 return lpegmatch(validutf,content) and content or nil
11830 end
11831 end
11832 end
11833 readers["os/2"]=function(f,fontdata)
11834 local tableoffset=gotodatatable(f,fontdata,"os/2",true)
11835 if tableoffset then
11836 local version=readushort(f)
11837 local windowsmetrics={
11838 version=version,
11839 averagewidth=readshort(f),
11840 weightclass=readushort(f),
11841 widthclass=readushort(f),
11842 fstype=readushort(f),
11843 subscriptxsize=readshort(f),
11844 subscriptysize=readshort(f),
11845 subscriptxoffset=readshort(f),
11846 subscriptyoffset=readshort(f),
11847 superscriptxsize=readshort(f),
11848 superscriptysize=readshort(f),
11849 superscriptxoffset=readshort(f),
11850 superscriptyoffset=readshort(f),
11851 strikeoutsize=readshort(f),
11852 strikeoutpos=readshort(f),
11853 familyclass=readshort(f),
11854 panose={ readbytes(f,10) },
11855 unicoderanges={ readulong(f),readulong(f),readulong(f),readulong(f) },
11856 vendor=readstring(f,4),
11857 fsselection=readushort(f),
11858 firstcharindex=readushort(f),
11859 lastcharindex=readushort(f),
11860 typoascender=readshort(f),
11861 typodescender=readshort(f),
11862 typolinegap=readshort(f),
11863 winascent=readushort(f),
11864 windescent=readushort(f),
11865 }
11866 if version>=1 then
11867 windowsmetrics.codepageranges={ readulong(f),readulong(f) }
11868 end
11869 if version>=2 then
11870 windowsmetrics.xheight=readshort(f)
11871 windowsmetrics.capheight=readshort(f)
11872 windowsmetrics.defaultchar=readushort(f)
11873 windowsmetrics.breakchar=readushort(f)
11874 end
11875 windowsmetrics.weight=windowsmetrics.weightclass and weights[windowsmetrics.weightclass]
11876 windowsmetrics.width=windowsmetrics.widthclass and widths [windowsmetrics.widthclass]
11877 windowsmetrics.panoseweight=panoseweights[windowsmetrics.panose[3]]
11878 windowsmetrics.panosewidth=panosewidths [windowsmetrics.panose[4]]
11879 fontdata.windowsmetrics=windowsmetrics
11880 else
11881 fontdata.windowsmetrics={}
11882 end
11883 end
11884 readers.head=function(f,fontdata)
11885 local tableoffset=gotodatatable(f,fontdata,"head",true)
11886 if tableoffset then
11887 local version=readulong(f)
11888 local fontversion=readulong(f)
11889 local fontheader={
11890 version=version,
11891 fontversion=number.to16dot16(fontversion),
11892 fontversionnumber=fontversion,
11893 checksum=readushort(f)*0x10000+readushort(f),
11894 magic=readulong(f),
11895 flags=readushort(f),
11896 units=readushort(f),
11897 created=readlongdatetime(f),
11898 modified=readlongdatetime(f),
11899 xmin=readshort(f),
11900 ymin=readshort(f),
11901 xmax=readshort(f),
11902 ymax=readshort(f),
11903 macstyle=readushort(f),
11904 smallpixels=readushort(f),
11905 directionhint=readshort(f),
11906 indextolocformat=readshort(f),
11907 glyphformat=readshort(f),
11908 }
11909 fontdata.fontheader=fontheader
11910 else
11911 fontdata.fontheader={}
11912 end
11913 fontdata.nofglyphs=0
11914 end
11915 readers.hhea=function(f,fontdata,specification)
11916 local tableoffset=gotodatatable(f,fontdata,"hhea",specification.details)
11917 if tableoffset then
11918 fontdata.horizontalheader={
11919 version=readulong(f),
11920 ascender=readfword(f),
11921 descender=readfword(f),
11922 linegap=readfword(f),
11923 maxadvancewidth=readufword(f),
11924 minleftsidebearing=readfword(f),
11925 minrightsidebearing=readfword(f),
11926 maxextent=readfword(f),
11927 caretsloperise=readshort(f),
11928 caretsloperun=readshort(f),
11929 caretoffset=readshort(f),
11930 reserved_1=readshort(f),
11931 reserved_2=readshort(f),
11932 reserved_3=readshort(f),
11933 reserved_4=readshort(f),
11934 metricdataformat=readshort(f),
11935 nofmetrics=readushort(f),
11936 }
11937 else
11938 fontdata.horizontalheader={
11939 nofmetrics=0,
11940 }
11941 end
11942 end
11943 readers.vhea=function(f,fontdata,specification)
11944 local tableoffset=gotodatatable(f,fontdata,"vhea",specification.details)
11945 if tableoffset then
11946 fontdata.verticalheader={
11947 version=readulong(f),
11948 ascender=readfword(f),
11949 descender=readfword(f),
11950 linegap=readfword(f),
11951 maxadvanceheight=readufword(f),
11952 mintopsidebearing=readfword(f),
11953 minbottomsidebearing=readfword(f),
11954 maxextent=readfword(f),
11955 caretsloperise=readshort(f),
11956 caretsloperun=readshort(f),
11957 caretoffset=readshort(f),
11958 reserved_1=readshort(f),
11959 reserved_2=readshort(f),
11960 reserved_3=readshort(f),
11961 reserved_4=readshort(f),
11962 metricdataformat=readshort(f),
11963 nofmetrics=readushort(f),
11964 }
11965 else
11966 fontdata.verticalheader={
11967 nofmetrics=0,
11968 }
11969 end
11970 end
11971 readers.maxp=function(f,fontdata,specification)
11972 local tableoffset=gotodatatable(f,fontdata,"maxp",specification.details)
11973 if tableoffset then
11974 local version=readulong(f)
11975 local nofglyphs=readushort(f)
11976 fontdata.nofglyphs=nofglyphs
11977 if version==0x00005000 then
11978 fontdata.maximumprofile={
11979 version=version,
11980 nofglyphs=nofglyphs,
11981 }
11982 elseif version==0x00010000 then
11983 fontdata.maximumprofile={
11984 version=version,
11985 nofglyphs=nofglyphs,
11986 points=readushort(f),
11987 contours=readushort(f),
11988 compositepoints=readushort(f),
11989 compositecontours=readushort(f),
11990 zones=readushort(f),
11991 twilightpoints=readushort(f),
11992 storage=readushort(f),
11993 functiondefs=readushort(f),
11994 instructiondefs=readushort(f),
11995 stackelements=readushort(f),
11996 sizeofinstructions=readushort(f),
11997 componentelements=readushort(f),
11998 componentdepth=readushort(f),
11999 }
12000 else
12001 fontdata.maximumprofile={
12002 version=version,
12003 nofglyphs=0,
12004 }
12005 end
12006 end
12007 end
12008 readers.hmtx=function(f,fontdata,specification)
12009 local tableoffset=gotodatatable(f,fontdata,"hmtx",specification.glyphs)
12010 if tableoffset then
12011 local horizontalheader=fontdata.horizontalheader
12012 local nofmetrics=horizontalheader.nofmetrics
12013 local glyphs=fontdata.glyphs
12014 local nofglyphs=fontdata.nofglyphs
12015 local width=0
12016 local leftsidebearing=0
12017 for i=0,nofmetrics-1 do
12018 local glyph=glyphs[i]
12019 width=readshort(f)
12020 leftsidebearing=readshort(f)
12021 if width~=0 then
12022 glyph.width=width
12023 end
12024 end
12025 for i=nofmetrics,nofglyphs-1 do
12026 local glyph=glyphs[i]
12027 if width~=0 then
12028 glyph.width=width
12029 end
12030 end
12031 end
12032 end
12033 readers.vmtx=function(f,fontdata,specification)
12034 local tableoffset=gotodatatable(f,fontdata,"vmtx",specification.glyphs)
12035 if tableoffset then
12036 local verticalheader=fontdata.verticalheader
12037 local nofmetrics=verticalheader.nofmetrics
12038 local glyphs=fontdata.glyphs
12039 local nofglyphs=fontdata.nofglyphs
12040 local vheight=0
12041 local vdefault=verticalheader.ascender-verticalheader.descender
12042 local topsidebearing=0
12043 for i=0,nofmetrics-1 do
12044 local glyph=glyphs[i]
12045 vheight=readushort(f)
12046 topsidebearing=readshort(f)
12047 if vheight~=0 and vheight~=vdefault then
12048 glyph.vheight=vheight
12049 end
12050 if topsidebearing~=0 then
12051 glyph.tsb=topsidebearing
12052 end
12053 end
12054 for i=nofmetrics,nofglyphs-1 do
12055 local glyph=glyphs[i]
12056 if vheight~=0 and vheight~=vdefault then
12057 glyph.vheight=vheight
12058 end
12059 end
12060 end
12061 end
12062 readers.vorg=function(f,fontdata,specification)
12063 reportskippedtable(f,fontdata,"vorg",specification.glyphs)
12064 end
12065 readers.post=function(f,fontdata,specification)
12066 local tableoffset=gotodatatable(f,fontdata,"post",true)
12067 if tableoffset then
12068 local version=readulong(f)
12069 fontdata.postscript={
12070 version=version,
12071 italicangle=readfixed(f),
12072 underlineposition=readfword(f),
12073 underlinethickness=readfword(f),
12074 monospaced=readulong(f),
12075 minmemtype42=readulong(f),
12076 maxmemtype42=readulong(f),
12077 minmemtype1=readulong(f),
12078 maxmemtype1=readulong(f),
12079 }
12080 if not specification.glyphs then
12081 elseif version==0x00010000 then
12082 for index=0,#standardromanencoding do
12083 glyphs[index].name=standardromanencoding[index]
12084 end
12085 elseif version==0x00020000 then
12086 local glyphs=fontdata.glyphs
12087 local nofglyphs=readushort(f)
12088 local indices={}
12089 local names={}
12090 local maxnames=0
12091 for i=0,nofglyphs-1 do
12092 local nameindex=readushort(f)
12093 if nameindex>=258 then
12094 maxnames=maxnames+1
12095 nameindex=nameindex-257
12096 indices[nameindex]=i
12097 else
12098 glyphs[i].name=standardromanencoding[nameindex]
12099 end
12100 end
12101 for i=1,maxnames do
12102 local mapping=indices[i]
12103 if not mapping then
12104 report("quit post name fetching at %a of %a: %s",i,maxnames,"no index")
12105 break
12106 else
12107 local length=readbyte(f)
12108 if length>0 then
12109 glyphs[mapping].name=readstring(f,length)
12110 else
12111 end
12112 end
12113 end
12114 end
12115 else
12116 fontdata.postscript={}
12117 end
12118 end
12119 readers.cff=function(f,fontdata,specification)
12120 reportskippedtable(f,fontdata,"cff",specification.glyphs)
12121 end
12122 local formatreaders={}
12123 local duplicatestoo=true
12124 local sequence={
12125 { 3,1,4 },
12126 { 3,10,12 },
12127 { 0,3,4 },
12128 { 0,3,12 },
12129 { 0,1,4 },
12130 { 0,1,12 },
12131 { 0,0,6 },
12132 { 3,0,6 },
12133 { 3,0,4 },
12134 { 0,5,14 },
12135 { 0,4,12 },
12136 { 3,10,13 },
12137 }
12138 local supported={}
12139 for i=1,#sequence do
12140 local si=sequence[i]
12141 local sp,se,sf=si[1],si[2],si[3]
12142 local p=supported[sp]
12143 if not p then
12144 p={}
12145 supported[sp]=p
12146 end
12147 local e=p[se]
12148 if not e then
12149 e={}
12150 p[se]=e
12151 end
12152 e[sf]=true
12153 end
12154 formatreaders[4]=function(f,fontdata,offset)
12155 setposition(f,offset+2)
12156 local length=readushort(f)
12157 local language=readushort(f)
12158 local nofsegments=readushort(f)/2
12159 skipshort(f,3)
12160 local mapping=fontdata.mapping
12161 local glyphs=fontdata.glyphs
12162 local duplicates=fontdata.duplicates
12163 local nofdone=0
12164 local endchars=readcardinaltable(f,nofsegments,ushort)
12165 local reserved=readushort(f)
12166 local startchars=readcardinaltable(f,nofsegments,ushort)
12167 local deltas=readcardinaltable(f,nofsegments,ushort)
12168 local offsets=readcardinaltable(f,nofsegments,ushort)
12169 local size=(length-2*2-5*2-4*2*nofsegments)/2
12170 local indices=readcardinaltable(f,size-1,ushort)
12171 for segment=1,nofsegments do
12172 local startchar=startchars[segment]
12173 local endchar=endchars[segment]
12174 local offset=offsets[segment]
12175 local delta=deltas[segment]
12176 if startchar==0xFFFF and endchar==0xFFFF then
12177 elseif startchar==0xFFFF and offset==0 then
12178 elseif offset==0xFFFF then
12179 elseif offset==0 then
12180 if trace_cmap_details then
12181 report("format 4.%i segment %2i from %C upto %C at index %H",1,segment,startchar,endchar,(startchar+delta)%65536)
12182 end
12183 for unicode=startchar,endchar do
12184 local index=(unicode+delta)%65536
12185 if index and index>0 then
12186 local glyph=glyphs[index]
12187 if glyph then
12188 local gu=glyph.unicode
12189 if not gu then
12190 glyph.unicode=unicode
12191 nofdone=nofdone+1
12192 elseif gu~=unicode then
12193 if duplicatestoo then
12194 local d=duplicates[gu]
12195 if d then
12196 d[unicode]=true
12197 else
12198 duplicates[gu]={ [unicode]=true }
12199 end
12200 else
12201 report("duplicate case 1: %C %04i %s",unicode,index,glyphs[index].name)
12202 end
12203 end
12204 if not mapping[index] then
12205 mapping[index]=unicode
12206 end
12207 end
12208 end
12209 end
12210 else
12211 local shift=(segment-nofsegments+offset/2)-startchar
12212 if trace_cmap_details then
12213 report_cmap("format 4.%i segment %2i from %C upto %C at index %H",0,segment,startchar,endchar,(startchar+delta)%65536)
12214 end
12215 for unicode=startchar,endchar do
12216 local slot=shift+unicode
12217 local index=indices[slot]
12218 if index and index>0 then
12219 index=(index+delta)%65536
12220 local glyph=glyphs[index]
12221 if glyph then
12222 local gu=glyph.unicode
12223 if not gu then
12224 glyph.unicode=unicode
12225 nofdone=nofdone+1
12226 elseif gu~=unicode then
12227 if duplicatestoo then
12228 local d=duplicates[gu]
12229 if d then
12230 d[unicode]=true
12231 else
12232 duplicates[gu]={ [unicode]=true }
12233 end
12234 else
12235 report("duplicate case 2: %C %04i %s",unicode,index,glyphs[index].name)
12236 end
12237 end
12238 if not mapping[index] then
12239 mapping[index]=unicode
12240 end
12241 end
12242 end
12243 end
12244 end
12245 end
12246 return nofdone
12247 end
12248 formatreaders[6]=function(f,fontdata,offset)
12249 setposition(f,offset)
12250 local format=readushort(f)
12251 local length=readushort(f)
12252 local language=readushort(f)
12253 local mapping=fontdata.mapping
12254 local glyphs=fontdata.glyphs
12255 local duplicates=fontdata.duplicates
12256 local start=readushort(f)
12257 local count=readushort(f)
12258 local stop=start+count-1
12259 local nofdone=0
12260 if trace_cmap_details then
12261 report_cmap("format 6 from %C to %C",2,start,stop)
12262 end
12263 for unicode=start,stop do
12264 local index=readushort(f)
12265 if index>0 then
12266 local glyph=glyphs[index]
12267 if glyph then
12268 local gu=glyph.unicode
12269 if not gu then
12270 glyph.unicode=unicode
12271 nofdone=nofdone+1
12272 elseif gu~=unicode then
12273 end
12274 if not mapping[index] then
12275 mapping[index]=unicode
12276 end
12277 end
12278 end
12279 end
12280 return nofdone
12281 end
12282 formatreaders[12]=function(f,fontdata,offset)
12283 setposition(f,offset+2+2+4+4)
12284 local mapping=fontdata.mapping
12285 local glyphs=fontdata.glyphs
12286 local duplicates=fontdata.duplicates
12287 local nofgroups=readulong(f)
12288 local nofdone=0
12289 for i=1,nofgroups do
12290 local first=readulong(f)
12291 local last=readulong(f)
12292 local index=readulong(f)
12293 if trace_cmap_details then
12294 report_cmap("format 12 from %C to %C starts at index %i",first,last,index)
12295 end
12296 for unicode=first,last do
12297 local glyph=glyphs[index]
12298 if glyph then
12299 local gu=glyph.unicode
12300 if not gu then
12301 glyph.unicode=unicode
12302 nofdone=nofdone+1
12303 elseif gu~=unicode then
12304 local d=duplicates[gu]
12305 if d then
12306 d[unicode]=true
12307 else
12308 duplicates[gu]={ [unicode]=true }
12309 end
12310 end
12311 if not mapping[index] then
12312 mapping[index]=unicode
12313 end
12314 end
12315 index=index+1
12316 end
12317 end
12318 return nofdone
12319 end
12320 formatreaders[13]=function(f,fontdata,offset)
12321 setposition(f,offset+2+2+4+4)
12322 local mapping=fontdata.mapping
12323 local glyphs=fontdata.glyphs
12324 local duplicates=fontdata.duplicates
12325 local nofgroups=readulong(f)
12326 local nofdone=0
12327 for i=1,nofgroups do
12328 local first=readulong(f)
12329 local last=readulong(f)
12330 local index=readulong(f)
12331 if first<privateoffset then
12332 if trace_cmap_details then
12333 report_cmap("format 13 from %C to %C get index %i",first,last,index)
12334 end
12335 local glyph=glyphs[index]
12336 local unicode=glyph.unicode
12337 if not unicode then
12338 unicode=first
12339 glyph.unicode=unicode
12340 first=first+1
12341 end
12342 local list=duplicates[unicode]
12343 mapping[index]=unicode
12344 if not list then
12345 list={}
12346 duplicates[unicode]=list
12347 end
12348 if last>=privateoffset then
12349 local limit=privateoffset-1
12350 report("format 13 from %C to %C pruned to %C",first,last,limit)
12351 last=limit
12352 end
12353 for unicode=first,last do
12354 list[unicode]=true
12355 end
12356 nofdone=nofdone+last-first+1
12357 else
12358 report("format 13 from %C to %C ignored",first,last)
12359 end
12360 end
12361 return nofdone
12362 end
12363 formatreaders[14]=function(f,fontdata,offset)
12364 if offset and offset~=0 then
12365 setposition(f,offset)
12366 local format=readushort(f)
12367 local length=readulong(f)
12368 local nofrecords=readulong(f)
12369 local records={}
12370 local variants={}
12371 local nofdone=0
12372 fontdata.variants=variants
12373 for i=1,nofrecords do
12374 records[i]={
12375 selector=readuint(f),
12376 default=readulong(f),
12377 other=readulong(f),
12378 }
12379 end
12380 for i=1,nofrecords do
12381 local record=records[i]
12382 local selector=record.selector
12383 local default=record.default
12384 local other=record.other
12385 local other=record.other
12386 if other~=0 then
12387 setposition(f,offset+other)
12388 local mapping={}
12389 local count=readulong(f)
12390 for i=1,count do
12391 mapping[readuint(f)]=readushort(f)
12392 end
12393 nofdone=nofdone+count
12394 variants[selector]=mapping
12395 end
12396 end
12397 return nofdone
12398 else
12399 return 0
12400 end
12401 end
12402 local function checkcmap(f,fontdata,records,platform,encoding,format)
12403 local pdata=records[platform]
12404 if not pdata then
12405 if trace_cmap_details then
12406 report_cmap("skipped, %s, p=%i e=%i f=%i","no platform",platform,encoding,format)
12407 end
12408 return 0
12409 end
12410 local edata=pdata[encoding]
12411 if not edata then
12412 if trace_cmap_details then
12413 report_cmap("skipped, %s, p=%i e=%i f=%i","no encoding",platform,encoding,format)
12414 end
12415 return 0
12416 end
12417 local fdata=edata[format]
12418 if not fdata then
12419 if trace_cmap_details then
12420 report_cmap("skipped, %s, p=%i e=%i f=%i","no format",platform,encoding,format)
12421 end
12422 return 0
12423 elseif type(fdata)~="number" then
12424 if trace_cmap_details then
12425 report_cmap("skipped, %s, p=%i e=%i f=%i","already done",platform,encoding,format)
12426 end
12427 return 0
12428 end
12429 edata[format]=true
12430 local reader=formatreaders[format]
12431 if not reader then
12432 if trace_cmap_details then
12433 report_cmap("skipped, %s, p=%i e=%i f=%i","unsupported format",platform,encoding,format)
12434 end
12435 return 0
12436 end
12437 local n=reader(f,fontdata,fdata) or 0
12438 if trace_cmap_details or trace_cmap then
12439 local p=platforms[platform]
12440 local e=encodings[p]
12441 report_cmap("checked, platform %i (%s), encoding %i (%s), format %i, new unicodes %i",
12442 platform,p,encoding,e and e[encoding] or "?",format,n)
12443 end
12444 return n
12445 end
12446 function readers.cmap(f,fontdata,specification)
12447 local tableoffset=gotodatatable(f,fontdata,"cmap",specification.glyphs)
12448 if tableoffset then
12449 local version=readushort(f)
12450 local noftables=readushort(f)
12451 local records={}
12452 local unicodecid=false
12453 local variantcid=false
12454 local variants={}
12455 local duplicates=fontdata.duplicates or {}
12456 fontdata.duplicates=duplicates
12457 for i=1,noftables do
12458 local platform=readushort(f)
12459 local encoding=readushort(f)
12460 local offset=readulong(f)
12461 local record=records[platform]
12462 if not record then
12463 records[platform]={
12464 [encoding]={
12465 offsets={ offset },
12466 formats={},
12467 }
12468 }
12469 else
12470 local subtables=record[encoding]
12471 if not subtables then
12472 record[encoding]={
12473 offsets={ offset },
12474 formats={},
12475 }
12476 else
12477 local offsets=subtables.offsets
12478 offsets[#offsets+1]=offset
12479 end
12480 end
12481 end
12482 if trace_cmap then
12483 report("found cmaps:")
12484 end
12485 for platform,record in sortedhash(records) do
12486 local p=platforms[platform]
12487 local e=encodings[p]
12488 local sp=supported[platform]
12489 local ps=p or "?"
12490 if trace_cmap then
12491 if sp then
12492 report(" platform %i: %s",platform,ps)
12493 else
12494 report(" platform %i: %s (unsupported)",platform,ps)
12495 end
12496 end
12497 for encoding,subtables in sortedhash(record) do
12498 local se=sp and sp[encoding]
12499 local es=e and e[encoding] or "?"
12500 if trace_cmap then
12501 if se then
12502 report(" encoding %i: %s",encoding,es)
12503 else
12504 report(" encoding %i: %s (unsupported)",encoding,es)
12505 end
12506 end
12507 local offsets=subtables.offsets
12508 local formats=subtables.formats
12509 for i=1,#offsets do
12510 local offset=tableoffset+offsets[i]
12511 setposition(f,offset)
12512 formats[readushort(f)]=offset
12513 end
12514 record[encoding]=formats
12515 if trace_cmap then
12516 local list=sortedkeys(formats)
12517 for i=1,#list do
12518 if not (se and se[list[i]]) then
12519 list[i]=list[i].." (unsupported)"
12520 end
12521 end
12522 report(" formats: % t",list)
12523 end
12524 end
12525 end
12526 local ok=false
12527 for i=1,#sequence do
12528 local si=sequence[i]
12529 local sp,se,sf=si[1],si[2],si[3]
12530 if checkcmap(f,fontdata,records,sp,se,sf)>0 then
12531 ok=true
12532 end
12533 end
12534 if not ok then
12535 report("no useable unicode cmap found")
12536 end
12537 fontdata.cidmaps={
12538 version=version,
12539 noftables=noftables,
12540 records=records,
12541 }
12542 else
12543 fontdata.cidmaps={}
12544 end
12545 end
12546 function readers.loca(f,fontdata,specification)
12547 reportskippedtable(f,fontdata,"loca",specification.glyphs)
12548 end
12549 function readers.glyf(f,fontdata,specification)
12550 reportskippedtable(f,fontdata,"glyf",specification.glyphs)
12551 end
12552 function readers.colr(f,fontdata,specification)
12553 reportskippedtable(f,fontdata,"colr",specification.glyphs)
12554 end
12555 function readers.cpal(f,fontdata,specification)
12556 reportskippedtable(f,fontdata,"cpal",specification.glyphs)
12557 end
12558 function readers.svg(f,fontdata,specification)
12559 reportskippedtable(f,fontdata,"svg",specification.glyphs)
12560 end
12561 function readers.sbix(f,fontdata,specification)
12562 reportskippedtable(f,fontdata,"sbix",specification.glyphs)
12563 end
12564 function readers.cbdt(f,fontdata,specification)
12565 reportskippedtable(f,fontdata,"cbdt",specification.glyphs)
12566 end
12567 function readers.cblc(f,fontdata,specification)
12568 reportskippedtable(f,fontdata,"cblc",specification.glyphs)
12569 end
12570 function readers.ebdt(f,fontdata,specification)
12571 reportskippedtable(f,fontdata,"ebdt",specification.glyphs)
12572 end
12573 function readers.ebsc(f,fontdata,specification)
12574 reportskippedtable(f,fontdata,"ebsc",specification.glyphs)
12575 end
12576 function readers.eblc(f,fontdata,specification)
12577 reportskippedtable(f,fontdata,"eblc",specification.glyphs)
12578 end
12579 function readers.kern(f,fontdata,specification)
12580 local tableoffset=gotodatatable(f,fontdata,"kern",specification.kerns)
12581 if tableoffset then
12582 local version=readushort(f)
12583 local noftables=readushort(f)
12584 for i=1,noftables do
12585 local version=readushort(f)
12586 local length=readushort(f)
12587 local coverage=readushort(f)
12588 local format=rshift(coverage,8)
12589 if format==0 then
12590 local nofpairs=readushort(f)
12591 local searchrange=readushort(f)
12592 local entryselector=readushort(f)
12593 local rangeshift=readushort(f)
12594 local kerns={}
12595 local glyphs=fontdata.glyphs
12596 for i=1,nofpairs do
12597 local left=readushort(f)
12598 local right=readushort(f)
12599 local kern=readfword(f)
12600 local glyph=glyphs[left]
12601 local kerns=glyph.kerns
12602 if kerns then
12603 kerns[right]=kern
12604 else
12605 glyph.kerns={ [right]=kern }
12606 end
12607 end
12608 elseif format==2 then
12609 report("todo: kern classes")
12610 else
12611 report("todo: kerns")
12612 end
12613 end
12614 end
12615 end
12616 function readers.gdef(f,fontdata,specification)
12617 reportskippedtable(f,fontdata,"gdef",specification.details)
12618 end
12619 function readers.gsub(f,fontdata,specification)
12620 reportskippedtable(f,fontdata,"gsub",specification.details)
12621 end
12622 function readers.gpos(f,fontdata,specification)
12623 reportskippedtable(f,fontdata,"gpos",specification.details)
12624 end
12625 function readers.math(f,fontdata,specification)
12626 reportskippedtable(f,fontdata,"math",specification.details)
12627 end
12628 local function getinfo(maindata,sub,platformnames,rawfamilynames,metricstoo,instancenames)
12629 local fontdata=sub and maindata.subfonts and maindata.subfonts[sub] or maindata
12630 local names=fontdata.names
12631 local info=nil
12632 if names then
12633 local metrics=fontdata.windowsmetrics or {}
12634 local postscript=fontdata.postscript or {}
12635 local fontheader=fontdata.fontheader or {}
12636 local cffinfo=fontdata.cffinfo or {}
12637 local verticalheader=fontdata.verticalheader or {}
12638 local filename=fontdata.filename
12639 local weight=getname(fontdata,"weight") or (cffinfo and cffinfo.weight) or (metrics and metrics.weight)
12640 local width=getname(fontdata,"width") or (cffinfo and cffinfo.width ) or (metrics and metrics.width )
12641 local fontname=getname(fontdata,"postscriptname")
12642 local fullname=getname(fontdata,"fullname")
12643 local family=getname(fontdata,"family")
12644 local subfamily=getname(fontdata,"subfamily")
12645 local familyname=getname(fontdata,"typographicfamily")
12646 local subfamilyname=getname(fontdata,"typographicsubfamily")
12647 local compatiblename=getname(fontdata,"compatiblefullname")
12648 if rawfamilynames then
12649 else
12650 if not familyname then familyname=family end
12651 if not subfamilyname then subfamilyname=subfamily end
12652 end
12653 if platformnames then
12654 platformnames=fontdata.platformnames
12655 end
12656 if instancenames then
12657 local variabledata=fontdata.variabledata
12658 if variabledata then
12659 local instances=variabledata and variabledata.instances
12660 if instances then
12661 instancenames={}
12662 for i=1,#instances do
12663 instancenames[i]=lower(stripstring(instances[i].subfamily))
12664 end
12665 else
12666 instancenames=nil
12667 end
12668 else
12669 instancenames=nil
12670 end
12671 end
12672 info={
12673 subfontindex=fontdata.subfontindex or sub or 0,
12674 version=getname(fontdata,"version"),
12675 fontname=fontname,
12676 fullname=fullname,
12677 family=family,
12678 subfamily=subfamily,
12679 familyname=familyname,
12680 subfamilyname=subfamilyname,
12681 compatiblename=compatiblename,
12682 weight=weight and lower(weight),
12683 width=width and lower(width),
12684 pfmweight=metrics.weightclass or 400,
12685 pfmwidth=metrics.widthclass or 5,
12686 panosewidth=metrics.panosewidth,
12687 panoseweight=metrics.panoseweight,
12688 fstype=metrics.fstype or 0,
12689 italicangle=postscript.italicangle or 0,
12690 units=fontheader.units or 0,
12691 designsize=fontdata.designsize,
12692 minsize=fontdata.minsize,
12693 maxsize=fontdata.maxsize,
12694 boundingbox=fontheader and { fontheader.xmin or 0,fontheader.ymin or 0,fontheader.xmax or 0,fontheader.ymax or 0 } or nil,
12695 monospaced=(tonumber(postscript.monospaced or 0)>0) or metrics.panosewidth=="monospaced",
12696 averagewidth=metrics.averagewidth,
12697 xheight=metrics.xheight,
12698 capheight=metrics.capheight or fontdata.maxy,
12699 ascender=metrics.typoascender,
12700 descender=metrics.typodescender,
12701 platformnames=platformnames or nil,
12702 instancenames=instancenames or nil,
12703 tableoffsets=fontdata.tableoffsets,
12704 defaultvheight=(verticalheader.ascender or 0)-(verticalheader.descender or 0)
12705 }
12706 if metricstoo then
12707 local keys={
12708 "version",
12709 "ascender","descender","linegap",
12710 "maxadvancewidth","maxadvanceheight","maxextent",
12711 "minbottomsidebearing","mintopsidebearing",
12712 }
12713 local h=fontdata.horizontalheader or {}
12714 local v=fontdata.verticalheader or {}
12715 if h then
12716 local th={}
12717 local tv={}
12718 for i=1,#keys do
12719 local key=keys[i]
12720 th[key]=h[key] or 0
12721 tv[key]=v[key] or 0
12722 end
12723 info.horizontalmetrics=th
12724 info.verticalmetrics=tv
12725 end
12726 end
12727 elseif n then
12728 info={
12729 filename=fontdata.filename,
12730 comment="there is no info for subfont "..n,
12731 }
12732 else
12733 info={
12734 filename=fontdata.filename,
12735 comment="there is no info",
12736 }
12737 end
12738 return info
12739 end
12740 local function loadtables(f,specification,offset)
12741 if offset then
12742 setposition(f,offset)
12743 end
12744 local tables={}
12745 local basename=file.basename(specification.filename)
12746 local filesize=specification.filesize
12747 local filetime=specification.filetime
12748 local fontdata={
12749 filename=basename,
12750 filesize=filesize,
12751 filetime=filetime,
12752 version=readstring(f,4),
12753 noftables=readushort(f),
12754 searchrange=readushort(f),
12755 entryselector=readushort(f),
12756 rangeshift=readushort(f),
12757 tables=tables,
12758 foundtables=false,
12759 }
12760 for i=1,fontdata.noftables do
12761 local tag=lower(stripstring(readstring(f,4)))
12762 local checksum=readushort(f)*0x10000+readushort(f)
12763 local offset=readulong(f)
12764 local length=readulong(f)
12765 if offset+length>filesize then
12766 report("bad %a table in file %a",tag,basename)
12767 end
12768 tables[tag]={
12769 checksum=checksum,
12770 offset=offset,
12771 length=length,
12772 }
12773 end
12774 fontdata.foundtables=sortedkeys(tables)
12775 if tables.cff or tables.cff2 then
12776 fontdata.format="opentype"
12777 else
12778 fontdata.format="truetype"
12779 end
12780 return fontdata,tables
12781 end
12782 local function prepareglyps(fontdata)
12783 local glyphs=setmetatableindex(function(t,k)
12784 local v={
12785 index=k,
12786 }
12787 t[k]=v
12788 return v
12789 end)
12790 fontdata.glyphs=glyphs
12791 fontdata.mapping={}
12792 end
12793 local function readtable(tag,f,fontdata,specification,...)
12794 local reader=readers[tag]
12795 if reader then
12796 reader(f,fontdata,specification,...)
12797 end
12798 end
12799 local function readdata(f,offset,specification)
12800 local fontdata,tables=loadtables(f,specification,offset)
12801 if specification.glyphs then
12802 prepareglyps(fontdata)
12803 end
12804 fontdata.temporary={}
12805 readtable("name",f,fontdata,specification)
12806 local askedname=specification.askedname
12807 if askedname then
12808 local fullname=getname(fontdata,"fullname") or ""
12809 local cleanname=gsub(askedname,"[^a-zA-Z0-9]","")
12810 local foundname=gsub(fullname,"[^a-zA-Z0-9]","")
12811 if lower(cleanname)~=lower(foundname) then
12812 return
12813 end
12814 end
12815 readtable("stat",f,fontdata,specification)
12816 readtable("avar",f,fontdata,specification)
12817 readtable("fvar",f,fontdata,specification)
12818 local variabledata=fontdata.variabledata
12819 if variabledata then
12820 local instances=variabledata.instances
12821 local axis=variabledata.axis
12822 if axis and (not instances or #instances==0) then
12823 instances={}
12824 variabledata.instances=instances
12825 local function add(n,subfamily,value)
12826 local values={}
12827 for i=1,#axis do
12828 local a=axis[i]
12829 values[i]={
12830 axis=a.tag,
12831 value=i==n and value or a.default,
12832 }
12833 end
12834 instances[#instances+1]={
12835 subfamily=subfamily,
12836 values=values,
12837 }
12838 end
12839 for i=1,#axis do
12840 local a=axis[i]
12841 local tag=a.tag
12842 add(i,"default"..tag,a.default)
12843 add(i,"minimum"..tag,a.minimum)
12844 add(i,"maximum"..tag,a.maximum)
12845 end
12846 end
12847 end
12848 if not specification.factors then
12849 local instance=specification.instance
12850 if type(instance)=="string" then
12851 local factors=helpers.getfactors(fontdata,instance)
12852 if factors then
12853 specification.factors=factors
12854 fontdata.factors=factors
12855 fontdata.instance=instance
12856 report("user instance: %s, factors: % t",instance,factors)
12857 else
12858 report("user instance: %s, bad factors",instance)
12859 end
12860 end
12861 end
12862 if not fontdata.factors then
12863 if fontdata.variabledata then
12864 local factors=helpers.getfactors(fontdata,true)
12865 if factors then
12866 specification.factors=factors
12867 fontdata.factors=factors
12868 end
12869 else
12870 end
12871 end
12872 readtable("os/2",f,fontdata,specification)
12873 readtable("head",f,fontdata,specification)
12874 readtable("maxp",f,fontdata,specification)
12875 readtable("hhea",f,fontdata,specification)
12876 readtable("vhea",f,fontdata,specification)
12877 readtable("hmtx",f,fontdata,specification)
12878 readtable("vmtx",f,fontdata,specification)
12879 readtable("vorg",f,fontdata,specification)
12880 readtable("post",f,fontdata,specification)
12881 readtable("mvar",f,fontdata,specification)
12882 readtable("hvar",f,fontdata,specification)
12883 readtable("vvar",f,fontdata,specification)
12884 readtable("gdef",f,fontdata,specification)
12885 readtable("cff",f,fontdata,specification)
12886 readtable("cff2",f,fontdata,specification)
12887 readtable("cmap",f,fontdata,specification)
12888 readtable("loca",f,fontdata,specification)
12889 readtable("glyf",f,fontdata,specification)
12890 readtable("colr",f,fontdata,specification)
12891 readtable("cpal",f,fontdata,specification)
12892 readtable("svg",f,fontdata,specification)
12893 readtable("sbix",f,fontdata,specification)
12894 readtable("cbdt",f,fontdata,specification)
12895 readtable("cblc",f,fontdata,specification)
12896 readtable("ebdt",f,fontdata,specification)
12897 readtable("eblc",f,fontdata,specification)
12898 readtable("kern",f,fontdata,specification)
12899 readtable("gsub",f,fontdata,specification)
12900 readtable("gpos",f,fontdata,specification)
12901 readtable("math",f,fontdata,specification)
12902 fontdata.locations=nil
12903 fontdata.cidmaps=nil
12904 fontdata.dictionaries=nil
12905 if specification.tableoffsets then
12906 fontdata.tableoffsets=tables
12907 setmetatableindex(tables,{
12908 version=fontdata.version,
12909 noftables=fontdata.noftables,
12910 searchrange=fontdata.searchrange,
12911 entryselector=fontdata.entryselector,
12912 rangeshift=fontdata.rangeshift,
12913 })
12914 end
12915 return fontdata
12916 end
12917 local function loadfontdata(specification)
12918 local filename=specification.filename
12919 local fileattr=lfs.attributes(filename)
12920 local filesize=fileattr and fileattr.size or 0
12921 local filetime=fileattr and fileattr.modification or 0
12922 local f=openfile(filename,true)
12923 if not f then
12924 report("unable to open %a",filename)
12925 elseif filesize==0 then
12926 report("empty file %a",filename)
12927 closefile(f)
12928 else
12929 specification.filesize=filesize
12930 specification.filetime=filetime
12931 local version=readstring(f,4)
12932 local fontdata=nil
12933 if version=="OTTO" or version=="true" or version=="\0\1\0\0" then
12934 fontdata=readdata(f,0,specification)
12935 elseif version=="ttcf" then
12936 local subfont=tonumber(specification.subfont)
12937 local ttcversion=readulong(f)
12938 local nofsubfonts=readulong(f)
12939 local offsets=readcardinaltable(f,nofsubfonts,ulong)
12940 if subfont then
12941 if subfont>=1 and subfont<=nofsubfonts then
12942 fontdata=readdata(f,offsets[subfont],specification)
12943 else
12944 report("no subfont %a in file %a",subfont,filename)
12945 end
12946 else
12947 subfont=specification.subfont
12948 if type(subfont)=="string" and subfont~="" then
12949 specification.askedname=subfont
12950 for i=1,nofsubfonts do
12951 fontdata=readdata(f,offsets[i],specification)
12952 if fontdata then
12953 fontdata.subfontindex=i
12954 report("subfont named %a has index %a",subfont,i)
12955 break
12956 end
12957 end
12958 if not fontdata then
12959 report("no subfont named %a",subfont)
12960 end
12961 else
12962 local subfonts={}
12963 fontdata={
12964 filename=filename,
12965 filesize=filesize,
12966 filetime=filetime,
12967 version=version,
12968 subfonts=subfonts,
12969 ttcversion=ttcversion,
12970 nofsubfonts=nofsubfonts,
12971 }
12972 for i=1,nofsubfonts do
12973 subfonts[i]=readdata(f,offsets[i],specification)
12974 end
12975 end
12976 end
12977 else
12978 report("unknown version %a in file %a",version,filename)
12979 end
12980 closefile(f)
12981 return fontdata or {}
12982 end
12983 end
12984 local function loadfont(specification,n,instance)
12985 if type(specification)=="string" then
12986 specification={
12987 filename=specification,
12988 info=true,
12989 details=true,
12990 glyphs=true,
12991 shapes=true,
12992 kerns=true,
12993 variable=true,
12994 globalkerns=true,
12995 lookups=true,
12996 subfont=n or true,
12997 tounicode=false,
12998 instance=instance
12999 }
13000 end
13001 if specification.shapes or specification.lookups or specification.kerns then
13002 specification.glyphs=true
13003 end
13004 if specification.glyphs then
13005 specification.details=true
13006 end
13007 if specification.details then
13008 specification.info=true
13009 end
13010 if specification.platformnames then
13011 specification.platformnames=true
13012 end
13013 if specification.instance or instance then
13014 specification.variable=true
13015 specification.instance=specification.instance or instance
13016 end
13017 local function message(str)
13018 report("fatal error in file %a: %s\n%s",specification.filename,str,debug and debug.traceback())
13019 end
13020 local ok,result=xpcall(loadfontdata,message,specification)
13021 if ok then
13022 return result
13023 end
13024 end
13025 function readers.loadshapes(filename,n,instance,streams)
13026 local fontdata=loadfont {
13027 filename=filename,
13028 shapes=true,
13029 streams=streams,
13030 variable=true,
13031 subfont=n,
13032 instance=instance,
13033 }
13034 if fontdata then
13035 for k,v in next,fontdata.glyphs do
13036 v.class=nil
13037 v.index=nil
13038 v.math=nil
13039 end
13040 local names=fontdata.names
13041 if names then
13042 for k,v in next,names do
13043 names[k]=fullstrip(v.content)
13044 end
13045 end
13046 end
13047 return fontdata and {
13048 filename=filename,
13049 format=fontdata.format,
13050 glyphs=fontdata.glyphs,
13051 units=fontdata.fontheader.units,
13052 cffinfo=fontdata.cffinfo,
13053 fontheader=fontdata.fontheader,
13054 horizontalheader=fontdata.horizontalheader,
13055 verticalheader=fontdata.verticalheader,
13056 maximumprofile=fontdata.maximumprofile,
13057 names=fontdata.names,
13058 postscript=fontdata.postscript,
13059 } or {
13060 filename=filename,
13061 format="unknown",
13062 glyphs={},
13063 units=0,
13064 }
13065 end
13066 function readers.loadfont(filename,n,instance)
13067 local fontdata=loadfont {
13068 filename=filename,
13069 glyphs=true,
13070 shapes=false,
13071 lookups=true,
13072 variable=true,
13073 subfont=n,
13074 instance=instance,
13075 }
13076 if fontdata then
13077 return {
13078 tableversion=tableversion,
13079 creator="context mkiv",
13080 size=fontdata.filesize,
13081 time=fontdata.filetime,
13082 glyphs=fontdata.glyphs,
13083 descriptions=fontdata.descriptions,
13084 format=fontdata.format,
13085 goodies={},
13086 metadata=getinfo(fontdata,n,false,false,true,true),
13087 properties={
13088 hasitalics=fontdata.hasitalics or false,
13089 maxcolorclass=fontdata.maxcolorclass,
13090 hascolor=fontdata.hascolor or false,
13091 instance=fontdata.instance,
13092 factors=fontdata.factors,
13093 nofsubfonts=fontdata.subfonts and #fontdata.subfonts or nil,
13094 },
13095 resources={
13096 filename=filename,
13097 private=privateoffset,
13098 duplicates=fontdata.duplicates or {},
13099 features=fontdata.features or {},
13100 sublookups=fontdata.sublookups or {},
13101 marks=fontdata.marks or {},
13102 markclasses=fontdata.markclasses or {},
13103 marksets=fontdata.marksets or {},
13104 sequences=fontdata.sequences or {},
13105 variants=fontdata.variants,
13106 version=getname(fontdata,"version"),
13107 cidinfo=fontdata.cidinfo,
13108 mathconstants=fontdata.mathconstants,
13109 colorpalettes=fontdata.colorpalettes,
13110 colorpaintdata=fontdata.colorpaintdata,
13111 colorpaintlist=fontdata.colorpaintlist,
13112 colorlinesdata=fontdata.colorlinesdata,
13113 coloraffinedata=fontdata.coloraffinedata,
13114 svgshapes=fontdata.svgshapes,
13115 pngshapes=fontdata.pngshapes,
13116 variabledata=fontdata.variabledata,
13117 foundtables=fontdata.foundtables,
13118 },
13119 }
13120 end
13121 end
13122 function readers.getinfo(filename,specification)
13123 local subfont=nil
13124 local platformnames=false
13125 local rawfamilynames=false
13126 local instancenames=true
13127 local tableoffsets=false
13128 if type(specification)=="table" then
13129 subfont=tonumber(specification.subfont)
13130 platformnames=specification.platformnames
13131 rawfamilynames=specification.rawfamilynames
13132 tableoffsets=specification.tableoffsets
13133 else
13134 subfont=tonumber(specification)
13135 end
13136 local fontdata=loadfont {
13137 filename=filename,
13138 details=true,
13139 platformnames=platformnames,
13140 instancenames=true,
13141 tableoffsets=tableoffsets,
13142 }
13143 if fontdata then
13144 local subfonts=fontdata.subfonts
13145 if not subfonts then
13146 return getinfo(fontdata,nil,platformnames,rawfamilynames,false,instancenames)
13147 elseif not subfont then
13148 local info={}
13149 for i=1,#subfonts do
13150 info[i]=getinfo(fontdata,i,platformnames,rawfamilynames,false,instancenames)
13151 end
13152 return info
13153 elseif subfont>=1 and subfont<=#subfonts then
13154 return getinfo(fontdata,subfont,platformnames,rawfamilynames,false,instancenames)
13155 else
13156 return {
13157 filename=filename,
13158 comment="there is no subfont "..subfont.." in this file"
13159 }
13160 end
13161 else
13162 return {
13163 filename=filename,
13164 comment="the file cannot be opened for reading",
13165 }
13166 end
13167 end
13168 function readers.rehash()
13169 report("the %a helper is not yet implemented","rehash")
13170 end
13171 function readers.checkhash()
13172 report("the %a helper is not yet implemented","checkhash")
13173 end
13174 function readers.pack()
13175 report("the %a helper is not yet implemented","pack")
13176 end
13177 function readers.unpack(fontdata)
13178 report("the %a helper is not yet implemented","unpack")
13179 end
13180 function readers.expand(fontdata)
13181 report("the %a helper is not yet implemented","unpack")
13182 end
13183 function readers.compact(fontdata)
13184 report("the %a helper is not yet implemented","compact")
13185 end
13186 function readers.condense(fontdata)
13187 report("the %a helper is not yet implemented","condense")
13188 end
13189 local extenders={}
13190 function readers.registerextender(extender)
13191 extenders[#extenders+1]=extender
13192 end
13193 function readers.extend(fontdata)
13194 for i=1,#extenders do
13195 local extender=extenders[i]
13196 local name=extender.name or "unknown"
13197 local action=extender.action
13198 if action then
13199 action(fontdata)
13200 end
13201 end
13202 end
13203
13204 end -- closure
13205
13206 do -- begin closure to overcome local limits and interference
13207
13208 if not modules then modules={} end modules ['font-cff']={
13209 version=1.001,
13210 optimize=true,
13211 comment="companion to font-ini.mkiv",
13212 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
13213 copyright="PRAGMA ADE / ConTeXt Development Team",
13214 license="see context related readme files"
13215 }
13216 local next,type,tonumber,rawget=next,type,tonumber,rawget
13217 local byte,char,gmatch,sub=string.byte,string.char,string.gmatch,string.sub
13218 local concat,insert,remove,unpack=table.concat,table.insert,table.remove,table.unpack
13219 local floor,abs,round,ceil,min,max=math.floor,math.abs,math.round,math.ceil,math.min,math.max
13220 local P,C,R,S,C,Cs,Ct=lpeg.P,lpeg.C,lpeg.R,lpeg.S,lpeg.C,lpeg.Cs,lpeg.Ct
13221 local lpegmatch=lpeg.match
13222 local formatters=string.formatters
13223 local bytetable=string.bytetable
13224 local idiv=number.idiv
13225 local rshift,band,extract=bit32.rshift,bit32.band,bit32.extract
13226 local readers=fonts.handlers.otf.readers
13227 local streamreader=readers.streamreader
13228 local readstring=streamreader.readstring
13229 local readbyte=streamreader.readcardinal1
13230 local readushort=streamreader.readcardinal2
13231 local readuint=streamreader.readcardinal3
13232 local readulong=streamreader.readcardinal4
13233 local setposition=streamreader.setposition
13234 local getposition=streamreader.getposition
13235 local readbytetable=streamreader.readbytetable
13236 directives.register("fonts.streamreader",function()
13237 streamreader=utilities.streams
13238 readstring=streamreader.readstring
13239 readbyte=streamreader.readcardinal1
13240 readushort=streamreader.readcardinal2
13241 readuint=streamreader.readcardinal3
13242 readulong=streamreader.readcardinal4
13243 setposition=streamreader.setposition
13244 getposition=streamreader.getposition
13245 readbytetable=streamreader.readbytetable
13246 end)
13247 local setmetatableindex=table.setmetatableindex
13248 local trace_charstrings=false trackers.register("fonts.cff.charstrings",function(v) trace_charstrings=v end)
13249 local report=logs.reporter("otf reader","cff")
13250 local parsedictionaries
13251 local parsecharstring
13252 local parsecharstrings
13253 local resetcharstrings
13254 local parseprivates
13255 local startparsing
13256 local stopparsing
13257 local defaultstrings={ [0]=
13258 ".notdef","space","exclam","quotedbl","numbersign","dollar","percent",
13259 "ampersand","quoteright","parenleft","parenright","asterisk","plus",
13260 "comma","hyphen","period","slash","zero","one","two","three","four",
13261 "five","six","seven","eight","nine","colon","semicolon","less",
13262 "equal","greater","question","at","A","B","C","D","E","F","G","H",
13263 "I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W",
13264 "X","Y","Z","bracketleft","backslash","bracketright","asciicircum",
13265 "underscore","quoteleft","a","b","c","d","e","f","g","h","i","j",
13266 "k","l","m","n","o","p","q","r","s","t","u","v","w","x","y",
13267 "z","braceleft","bar","braceright","asciitilde","exclamdown","cent",
13268 "sterling","fraction","yen","florin","section","currency",
13269 "quotesingle","quotedblleft","guillemotleft","guilsinglleft",
13270 "guilsinglright","fi","fl","endash","dagger","daggerdbl",
13271 "periodcentered","paragraph","bullet","quotesinglbase","quotedblbase",
13272 "quotedblright","guillemotright","ellipsis","perthousand","questiondown",
13273 "grave","acute","circumflex","tilde","macron","breve","dotaccent",
13274 "dieresis","ring","cedilla","hungarumlaut","ogonek","caron","emdash",
13275 "AE","ordfeminine","Lslash","Oslash","OE","ordmasculine","ae",
13276 "dotlessi","lslash","oslash","oe","germandbls","onesuperior",
13277 "logicalnot","mu","trademark","Eth","onehalf","plusminus","Thorn",
13278 "onequarter","divide","brokenbar","degree","thorn","threequarters",
13279 "twosuperior","registered","minus","eth","multiply","threesuperior",
13280 "copyright","Aacute","Acircumflex","Adieresis","Agrave","Aring",
13281 "Atilde","Ccedilla","Eacute","Ecircumflex","Edieresis","Egrave",
13282 "Iacute","Icircumflex","Idieresis","Igrave","Ntilde","Oacute",
13283 "Ocircumflex","Odieresis","Ograve","Otilde","Scaron","Uacute",
13284 "Ucircumflex","Udieresis","Ugrave","Yacute","Ydieresis","Zcaron",
13285 "aacute","acircumflex","adieresis","agrave","aring","atilde",
13286 "ccedilla","eacute","ecircumflex","edieresis","egrave","iacute",
13287 "icircumflex","idieresis","igrave","ntilde","oacute","ocircumflex",
13288 "odieresis","ograve","otilde","scaron","uacute","ucircumflex",
13289 "udieresis","ugrave","yacute","ydieresis","zcaron","exclamsmall",
13290 "Hungarumlautsmall","dollaroldstyle","dollarsuperior","ampersandsmall",
13291 "Acutesmall","parenleftsuperior","parenrightsuperior","twodotenleader",
13292 "onedotenleader","zerooldstyle","oneoldstyle","twooldstyle",
13293 "threeoldstyle","fouroldstyle","fiveoldstyle","sixoldstyle",
13294 "sevenoldstyle","eightoldstyle","nineoldstyle","commasuperior",
13295 "threequartersemdash","periodsuperior","questionsmall","asuperior",
13296 "bsuperior","centsuperior","dsuperior","esuperior","isuperior",
13297 "lsuperior","msuperior","nsuperior","osuperior","rsuperior","ssuperior",
13298 "tsuperior","ff","ffi","ffl","parenleftinferior","parenrightinferior",
13299 "Circumflexsmall","hyphensuperior","Gravesmall","Asmall","Bsmall",
13300 "Csmall","Dsmall","Esmall","Fsmall","Gsmall","Hsmall","Ismall",
13301 "Jsmall","Ksmall","Lsmall","Msmall","Nsmall","Osmall","Psmall",
13302 "Qsmall","Rsmall","Ssmall","Tsmall","Usmall","Vsmall","Wsmall",
13303 "Xsmall","Ysmall","Zsmall","colonmonetary","onefitted","rupiah",
13304 "Tildesmall","exclamdownsmall","centoldstyle","Lslashsmall",
13305 "Scaronsmall","Zcaronsmall","Dieresissmall","Brevesmall","Caronsmall",
13306 "Dotaccentsmall","Macronsmall","figuredash","hypheninferior",
13307 "Ogoneksmall","Ringsmall","Cedillasmall","questiondownsmall","oneeighth",
13308 "threeeighths","fiveeighths","seveneighths","onethird","twothirds",
13309 "zerosuperior","foursuperior","fivesuperior","sixsuperior",
13310 "sevensuperior","eightsuperior","ninesuperior","zeroinferior",
13311 "oneinferior","twoinferior","threeinferior","fourinferior",
13312 "fiveinferior","sixinferior","seveninferior","eightinferior",
13313 "nineinferior","centinferior","dollarinferior","periodinferior",
13314 "commainferior","Agravesmall","Aacutesmall","Acircumflexsmall",
13315 "Atildesmall","Adieresissmall","Aringsmall","AEsmall","Ccedillasmall",
13316 "Egravesmall","Eacutesmall","Ecircumflexsmall","Edieresissmall",
13317 "Igravesmall","Iacutesmall","Icircumflexsmall","Idieresissmall",
13318 "Ethsmall","Ntildesmall","Ogravesmall","Oacutesmall","Ocircumflexsmall",
13319 "Otildesmall","Odieresissmall","OEsmall","Oslashsmall","Ugravesmall",
13320 "Uacutesmall","Ucircumflexsmall","Udieresissmall","Yacutesmall",
13321 "Thornsmall","Ydieresissmall","001.000","001.001","001.002","001.003",
13322 "Black","Bold","Book","Light","Medium","Regular","Roman","Semibold",
13323 }
13324 local standardnames={ [0]=
13325 false,false,false,false,false,false,false,false,false,false,false,
13326 false,false,false,false,false,false,false,false,false,false,false,
13327 false,false,false,false,false,false,false,false,false,false,
13328 "space","exclam","quotedbl","numbersign","dollar","percent",
13329 "ampersand","quoteright","parenleft","parenright","asterisk","plus",
13330 "comma","hyphen","period","slash","zero","one","two","three","four",
13331 "five","six","seven","eight","nine","colon","semicolon","less",
13332 "equal","greater","question","at","A","B","C","D","E","F","G","H",
13333 "I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W",
13334 "X","Y","Z","bracketleft","backslash","bracketright","asciicircum",
13335 "underscore","quoteleft","a","b","c","d","e","f","g","h","i","j",
13336 "k","l","m","n","o","p","q","r","s","t","u","v","w","x","y",
13337 "z","braceleft","bar","braceright","asciitilde",false,false,false,
13338 false,false,false,false,false,false,false,false,false,false,false,
13339 false,false,false,false,false,false,false,false,false,false,false,
13340 false,false,false,false,false,false,false,false,false,"exclamdown",
13341 "cent","sterling","fraction","yen","florin","section","currency",
13342 "quotesingle","quotedblleft","guillemotleft","guilsinglleft",
13343 "guilsinglright","fi","fl",false,"endash","dagger","daggerdbl",
13344 "periodcentered",false,"paragraph","bullet","quotesinglbase",
13345 "quotedblbase","quotedblright","guillemotright","ellipsis","perthousand",
13346 false,"questiondown",false,"grave","acute","circumflex","tilde",
13347 "macron","breve","dotaccent","dieresis",false,"ring","cedilla",false,
13348 "hungarumlaut","ogonek","caron","emdash",false,false,false,false,
13349 false,false,false,false,false,false,false,false,false,false,false,
13350 false,"AE",false,"ordfeminine",false,false,false,false,"Lslash",
13351 "Oslash","OE","ordmasculine",false,false,false,false,false,"ae",
13352 false,false,false,"dotlessi",false,false,"lslash","oslash","oe",
13353 "germandbls",false,false,false,false
13354 }
13355 local cffreaders={
13356 readbyte,
13357 readushort,
13358 readuint,
13359 readulong,
13360 }
13361 directives.register("fonts.streamreader",function()
13362 cffreaders={
13363 readbyte,
13364 readushort,
13365 readuint,
13366 readulong,
13367 }
13368 end)
13369 local function readheader(f)
13370 local offset=getposition(f)
13371 local major=readbyte(f)
13372 local header={
13373 offset=offset,
13374 major=major,
13375 minor=readbyte(f),
13376 size=readbyte(f),
13377 }
13378 if major==1 then
13379 header.dsize=readbyte(f)
13380 elseif major==2 then
13381 header.dsize=readushort(f)
13382 else
13383 end
13384 setposition(f,offset+header.size)
13385 return header
13386 end
13387 local function readlengths(f,longcount)
13388 local count=longcount and readulong(f) or readushort(f)
13389 if count==0 then
13390 return {}
13391 end
13392 local osize=readbyte(f)
13393 local read=cffreaders[osize]
13394 if not read then
13395 report("bad offset size: %i",osize)
13396 return {}
13397 end
13398 local lengths={}
13399 local previous=read(f)
13400 for i=1,count do
13401 local offset=read(f)
13402 local length=offset-previous
13403 if length<0 then
13404 report("bad offset: %i",length)
13405 length=0
13406 end
13407 lengths[i]=length
13408 previous=offset
13409 end
13410 return lengths
13411 end
13412 local function readfontnames(f)
13413 local names=readlengths(f)
13414 for i=1,#names do
13415 names[i]=readstring(f,names[i])
13416 end
13417 return names
13418 end
13419 local function readtopdictionaries(f)
13420 local dictionaries=readlengths(f)
13421 for i=1,#dictionaries do
13422 dictionaries[i]=readstring(f,dictionaries[i])
13423 end
13424 return dictionaries
13425 end
13426 local function readstrings(f)
13427 local lengths=readlengths(f)
13428 local strings=setmetatableindex({},defaultstrings)
13429 local index=#defaultstrings
13430 for i=1,#lengths do
13431 index=index+1
13432 strings[index]=readstring(f,lengths[i])
13433 end
13434 return strings
13435 end
13436 do
13437 local stack={}
13438 local top=0
13439 local result={}
13440 local strings={}
13441 local p_single=P("\00")/function()
13442 result.version=strings[stack[top]] or "unset"
13443 top=0
13444 end+P("\01")/function()
13445 result.notice=strings[stack[top]] or "unset"
13446 top=0
13447 end+P("\02")/function()
13448 result.fullname=strings[stack[top]] or "unset"
13449 top=0
13450 end+P("\03")/function()
13451 result.familyname=strings[stack[top]] or "unset"
13452 top=0
13453 end+P("\04")/function()
13454 result.weight=strings[stack[top]] or "unset"
13455 top=0
13456 end+P("\05")/function()
13457 result.fontbbox={ unpack(stack,1,4) }
13458 top=0
13459 end+P("\06")/function()
13460 result.bluevalues={ unpack(stack,1,top) }
13461 top=0
13462 end+P("\07")/function()
13463 result.otherblues={ unpack(stack,1,top) }
13464 top=0
13465 end+P("\08")/function()
13466 result.familyblues={ unpack(stack,1,top) }
13467 top=0
13468 end+P("\09")/function()
13469 result.familyotherblues={ unpack(stack,1,top) }
13470 top=0
13471 end+P("\10")/function()
13472 result.stdhw=stack[top]
13473 top=0
13474 end+P("\11")/function()
13475 result.stdvw=stack[top]
13476 top=0
13477 end+P("\13")/function()
13478 result.uniqueid=stack[top]
13479 top=0
13480 end+P("\14")/function()
13481 result.xuid=concat(stack,"",1,top)
13482 top=0
13483 end+P("\15")/function()
13484 result.charset=stack[top]
13485 top=0
13486 end+P("\16")/function()
13487 result.encoding=stack[top]
13488 top=0
13489 end+P("\17")/function()
13490 result.charstrings=stack[top]
13491 top=0
13492 end+P("\18")/function()
13493 result.private={
13494 size=stack[top-1],
13495 offset=stack[top],
13496 }
13497 top=0
13498 end+P("\19")/function()
13499 result.subroutines=stack[top]
13500 top=0
13501 end+P("\20")/function()
13502 result.defaultwidthx=stack[top]
13503 top=0
13504 end+P("\21")/function()
13505 result.nominalwidthx=stack[top]
13506 top=0
13507 end
13508 +P("\24")/function()
13509 result.vstore=stack[top]
13510 top=0
13511 end+P("\25")/function()
13512 result.maxstack=stack[top]
13513 top=0
13514 end
13515 local p_double=P("\12")*(
13516 P("\00")/function()
13517 result.copyright=stack[top]
13518 top=0
13519 end+P("\01")/function()
13520 result.monospaced=stack[top]==1 and true or false
13521 top=0
13522 end+P("\02")/function()
13523 result.italicangle=stack[top]
13524 top=0
13525 end+P("\03")/function()
13526 result.underlineposition=stack[top]
13527 top=0
13528 end+P("\04")/function()
13529 result.underlinethickness=stack[top]
13530 top=0
13531 end+P("\05")/function()
13532 result.painttype=stack[top]
13533 top=0
13534 end+P("\06")/function()
13535 result.charstringtype=stack[top]
13536 top=0
13537 end+P("\07")/function()
13538 result.fontmatrix={ unpack(stack,1,6) }
13539 top=0
13540 end+P("\08")/function()
13541 result.strokewidth=stack[top]
13542 top=0
13543 end+P("\09")/function()
13544 result.bluescale=stack[top]
13545 top=0
13546 end+P("\10")/function()
13547 result.blueshift=stack[top]
13548 top=0
13549 end+P("\11")/function()
13550 result.bluefuzz=stack[top]
13551 top=0
13552 end+P("\12")/function()
13553 result.stemsnaph={ unpack(stack,1,top) }
13554 top=0
13555 end+P("\13")/function()
13556 result.stemsnapv={ unpack(stack,1,top) }
13557 top=0
13558 end+P("\20")/function()
13559 result.syntheticbase=stack[top]
13560 top=0
13561 end+P("\21")/function()
13562 result.postscript=strings[stack[top]] or "unset"
13563 top=0
13564 end+P("\22")/function()
13565 result.basefontname=strings[stack[top]] or "unset"
13566 top=0
13567 end+P("\21")/function()
13568 result.basefontblend=stack[top]
13569 top=0
13570 end+P("\30")/function()
13571 result.cid.registry=strings[stack[top-2]] or "unset"
13572 result.cid.ordering=strings[stack[top-1]] or "unset"
13573 result.cid.supplement=stack[top]
13574 top=0
13575 end+P("\31")/function()
13576 result.cid.fontversion=stack[top]
13577 top=0
13578 end+P("\32")/function()
13579 result.cid.fontrevision=stack[top]
13580 top=0
13581 end+P("\33")/function()
13582 result.cid.fonttype=stack[top]
13583 top=0
13584 end+P("\34")/function()
13585 result.cid.count=stack[top]
13586 top=0
13587 end+P("\35")/function()
13588 result.cid.uidbase=stack[top]
13589 top=0
13590 end+P("\36")/function()
13591 result.cid.fdarray=stack[top]
13592 top=0
13593 end+P("\37")/function()
13594 result.cid.fdselect=stack[top]
13595 top=0
13596 end+P("\38")/function()
13597 result.cid.fontname=strings[stack[top]] or "unset"
13598 top=0
13599 end
13600 )
13601 local remap_1={
13602 ["\x00"]="00",["\x01"]="01",["\x02"]="02",["\x03"]="03",["\x04"]="04",["\x05"]="05",["\x06"]="06",["\x07"]="07",["\x08"]="08",["\x09"]="09",["\x0A"]="0.",["\x0B"]="0E",["\x0C"]="0E-",["\x0D"]="0",["\x0E"]="0-",["\x0F"]="0",
13603 ["\x10"]="10",["\x11"]="11",["\x12"]="12",["\x13"]="13",["\x14"]="14",["\x15"]="15",["\x16"]="16",["\x17"]="17",["\x18"]="18",["\x19"]="19",["\x1A"]="1.",["\x1B"]="1E",["\x1C"]="1E-",["\x1D"]="1",["\x1E"]="1-",["\x1F"]="1",
13604 ["\x20"]="20",["\x21"]="21",["\x22"]="22",["\x23"]="23",["\x24"]="24",["\x25"]="25",["\x26"]="26",["\x27"]="27",["\x28"]="28",["\x29"]="29",["\x2A"]="2.",["\x2B"]="2E",["\x2C"]="2E-",["\x2D"]="2",["\x2E"]="2-",["\x2F"]="2",
13605 ["\x30"]="30",["\x31"]="31",["\x32"]="32",["\x33"]="33",["\x34"]="34",["\x35"]="35",["\x36"]="36",["\x37"]="37",["\x38"]="38",["\x39"]="39",["\x3A"]="3.",["\x3B"]="3E",["\x3C"]="3E-",["\x3D"]="3",["\x3E"]="3-",["\x3F"]="3",
13606 ["\x40"]="40",["\x41"]="41",["\x42"]="42",["\x43"]="43",["\x44"]="44",["\x45"]="45",["\x46"]="46",["\x47"]="47",["\x48"]="48",["\x49"]="49",["\x4A"]="4.",["\x4B"]="4E",["\x4C"]="4E-",["\x4D"]="4",["\x4E"]="4-",["\x4F"]="4",
13607 ["\x50"]="50",["\x51"]="51",["\x52"]="52",["\x53"]="53",["\x54"]="54",["\x55"]="55",["\x56"]="56",["\x57"]="57",["\x58"]="58",["\x59"]="59",["\x5A"]="5.",["\x5B"]="5E",["\x5C"]="5E-",["\x5D"]="5",["\x5E"]="5-",["\x5F"]="5",
13608 ["\x60"]="60",["\x61"]="61",["\x62"]="62",["\x63"]="63",["\x64"]="64",["\x65"]="65",["\x66"]="66",["\x67"]="67",["\x68"]="68",["\x69"]="69",["\x6A"]="6.",["\x6B"]="6E",["\x6C"]="6E-",["\x6D"]="6",["\x6E"]="6-",["\x6F"]="6",
13609 ["\x70"]="70",["\x71"]="71",["\x72"]="72",["\x73"]="73",["\x74"]="74",["\x75"]="75",["\x76"]="76",["\x77"]="77",["\x78"]="78",["\x79"]="79",["\x7A"]="7.",["\x7B"]="7E",["\x7C"]="7E-",["\x7D"]="7",["\x7E"]="7-",["\x7F"]="7",
13610 ["\x80"]="80",["\x81"]="81",["\x82"]="82",["\x83"]="83",["\x84"]="84",["\x85"]="85",["\x86"]="86",["\x87"]="87",["\x88"]="88",["\x89"]="89",["\x8A"]="8.",["\x8B"]="8E",["\x8C"]="8E-",["\x8D"]="8",["\x8E"]="8-",["\x8F"]="8",
13611 ["\x90"]="90",["\x91"]="91",["\x92"]="92",["\x93"]="93",["\x94"]="94",["\x95"]="95",["\x96"]="96",["\x97"]="97",["\x98"]="98",["\x99"]="99",["\x9A"]="9.",["\x9B"]="9E",["\x9C"]="9E-",["\x9D"]="9",["\x9E"]="9-",["\x9F"]="9",
13612 ["\xA0"]=".0",["\xA1"]=".1",["\xA2"]=".2",["\xA3"]=".3",["\xA4"]=".4",["\xA5"]=".5",["\xA6"]=".6",["\xA7"]=".7",["\xA8"]=".8",["\xA9"]=".9",["\xAA"]="..",["\xAB"]=".E",["\xAC"]=".E-",["\xAD"]=".",["\xAE"]=".-",["\xAF"]=".",
13613 ["\xB0"]="E0",["\xB1"]="E1",["\xB2"]="E2",["\xB3"]="E3",["\xB4"]="E4",["\xB5"]="E5",["\xB6"]="E6",["\xB7"]="E7",["\xB8"]="E8",["\xB9"]="E9",["\xBA"]="E.",["\xBB"]="EE",["\xBC"]="EE-",["\xBD"]="E",["\xBE"]="E-",["\xBF"]="E",
13614 ["\xC0"]="E-0",["\xC1"]="E-1",["\xC2"]="E-2",["\xC3"]="E-3",["\xC4"]="E-4",["\xC5"]="E-5",["\xC6"]="E-6",["\xC7"]="E-7",["\xC8"]="E-8",["\xC9"]="E-9",["\xCA"]="E-.",["\xCB"]="E-E",["\xCC"]="E-E-",["\xCD"]="E-",["\xCE"]="E--",["\xCF"]="E-",
13615 ["\xD0"]="-0",["\xD1"]="-1",["\xD2"]="-2",["\xD3"]="-3",["\xD4"]="-4",["\xD5"]="-5",["\xD6"]="-6",["\xD7"]="-7",["\xD8"]="-8",["\xD9"]="-9",["\xDA"]="-.",["\xDB"]="-E",["\xDC"]="-E-",["\xDD"]="-",["\xDE"]="--",["\xDF"]="-",
13616 }
13617 local remap_2={
13618 ["\x0F"]="0",["\x1F"]="1",["\x2F"]="2",["\x3F"]="3",["\x4F"]="4",
13619 ["\x5F"]="5",["\x6F"]="6",["\x7F"]="7",["\x8F"]="8",["\x9F"]="9",
13620 }
13621 local p_last_1=S("\x0F\x1F\x2F\x3F\x4F\x5F\x6F\x7F\x8F\x9F\xAF\xBF")
13622 local p_last_2=R("\xF0\xFF")
13623 local p_nibbles=P("\30")*Cs(((1-(p_last_1+p_last_2))/remap_1)^0*(p_last_1/remap_2+p_last_2/""))/function(n)
13624 top=top+1
13625 stack[top]=tonumber(n) or 0
13626 end
13627 local p_byte=C(R("\32\246"))/function(b0)
13628 top=top+1
13629 stack[top]=byte(b0)-139
13630 end
13631 local p_positive=C(R("\247\250"))*C(1)/function(b0,b1)
13632 top=top+1
13633 stack[top]=(byte(b0)-247)*256+byte(b1)+108
13634 end
13635 local p_negative=C(R("\251\254"))*C(1)/function(b0,b1)
13636 top=top+1
13637 stack[top]=-(byte(b0)-251)*256-byte(b1)-108
13638 end
13639 local p_short=P("\28")*C(1)*C(1)/function(b1,b2)
13640 top=top+1
13641 local n=0x100*byte(b1)+byte(b2)
13642 if n>=0x8000 then
13643 stack[top]=n-0xFFFF-1
13644 else
13645 stack[top]=n
13646 end
13647 end
13648 local p_long=P("\29")*C(1)*C(1)*C(1)*C(1)/function(b1,b2,b3,b4)
13649 top=top+1
13650 local n=0x1000000*byte(b1)+0x10000*byte(b2)+0x100*byte(b3)+byte(b4)
13651 if n>=0x8000000 then
13652 stack[top]=n-0xFFFFFFFF-1
13653 else
13654 stack[top]=n
13655 end
13656 end
13657 local p_unsupported=P(1)/function(detail)
13658 top=0
13659 end
13660 local p_dictionary=(
13661 p_byte+p_positive+p_negative+p_short+p_long+p_nibbles+p_single+p_double
13662 +p_unsupported
13663 )^1
13664 parsedictionaries=function(data,dictionaries,version)
13665 stack={}
13666 strings=data.strings
13667 if trace_charstrings then
13668 report("charstring format %a",version)
13669 end
13670 for i=1,#dictionaries do
13671 top=0
13672 result=version=="cff" and {
13673 monospaced=false,
13674 italicangle=0,
13675 underlineposition=-100,
13676 underlinethickness=50,
13677 painttype=0,
13678 charstringtype=2,
13679 fontmatrix={ 0.001,0,0,0.001,0,0 },
13680 fontbbox={ 0,0,0,0 },
13681 strokewidth=0,
13682 charset=0,
13683 encoding=0,
13684 cid={
13685 fontversion=0,
13686 fontrevision=0,
13687 fonttype=0,
13688 count=8720,
13689 }
13690 } or {
13691 charstringtype=2,
13692 charset=0,
13693 vstore=0,
13694 cid={
13695 },
13696 }
13697 lpegmatch(p_dictionary,dictionaries[i])
13698 dictionaries[i]=result
13699 end
13700 result={}
13701 top=0
13702 stack={}
13703 end
13704 parseprivates=function(data,dictionaries)
13705 stack={}
13706 strings=data.strings
13707 for i=1,#dictionaries do
13708 local private=dictionaries[i].private
13709 if private and private.data then
13710 top=0
13711 result={
13712 forcebold=false,
13713 languagegroup=0,
13714 expansionfactor=0.06,
13715 initialrandomseed=0,
13716 subroutines=0,
13717 defaultwidthx=0,
13718 nominalwidthx=0,
13719 cid={
13720 },
13721 }
13722 lpegmatch(p_dictionary,private.data)
13723 private.data=result
13724 end
13725 end
13726 result={}
13727 top=0
13728 stack={}
13729 end
13730 local x=0
13731 local y=0
13732 local width=false
13733 local lsb=0
13734 local result={}
13735 local r=0
13736 local stems=0
13737 local globalbias=0
13738 local localbias=0
13739 local nominalwidth=0
13740 local defaultwidth=0
13741 local charset=false
13742 local globals=false
13743 local locals=false
13744 local depth=1
13745 local xmin=0
13746 local xmax=0
13747 local ymin=0
13748 local ymax=0
13749 local checked=false
13750 local keepcurve=false
13751 local version=2
13752 local regions=false
13753 local nofregions=0
13754 local region=false
13755 local factors=false
13756 local axis=false
13757 local vsindex=0
13758 local justpass=false
13759 local seacs={}
13760 local procidx=nil
13761 local function showstate(where,i,n)
13762 if i then
13763 local j=i+n-1
13764 report("%w%-10s : [%s] step",depth*2+2,where,concat(stack," ",i,j<=top and j or top))
13765 else
13766 report("%w%-10s : [%s] n=%i",depth*2,where,concat(stack," ",1,top),top)
13767 end
13768 end
13769 local function showvalue(where,value,showstack)
13770 if showstack then
13771 report("%w%-10s : %s : [%s] n=%i",depth*2,where,tostring(value),concat(stack," ",1,top),top)
13772 else
13773 report("%w%-10s : %s",depth*2,where,tostring(value))
13774 end
13775 end
13776 local function xymoveto()
13777 if keepcurve then
13778 r=r+1
13779 result[r]={ x,y,"m" }
13780 end
13781 if checked then
13782 if x>xmax then xmax=x elseif x<xmin then xmin=x end
13783 if y>ymax then ymax=y elseif y<ymin then ymin=y end
13784 else
13785 xmin=x
13786 ymin=y
13787 xmax=x
13788 ymax=y
13789 checked=true
13790 end
13791 end
13792 local function xmoveto()
13793 if keepcurve then
13794 r=r+1
13795 result[r]={ x,y,"m" }
13796 end
13797 if not checked then
13798 xmin=x
13799 ymin=y
13800 xmax=x
13801 ymax=y
13802 checked=true
13803 elseif x>xmax then
13804 xmax=x
13805 elseif x<xmin then
13806 xmin=x
13807 end
13808 end
13809 local function ymoveto()
13810 if keepcurve then
13811 r=r+1
13812 result[r]={ x,y,"m" }
13813 end
13814 if not checked then
13815 xmin=x
13816 ymin=y
13817 xmax=x
13818 ymax=y
13819 checked=true
13820 elseif y>ymax then
13821 ymax=y
13822 elseif y<ymin then
13823 ymin=y
13824 end
13825 end
13826 local function moveto()
13827 if trace_charstrings then
13828 showstate("moveto")
13829 end
13830 top=0
13831 xymoveto()
13832 end
13833 local function xylineto()
13834 if keepcurve then
13835 r=r+1
13836 result[r]={ x,y,"l" }
13837 end
13838 if checked then
13839 if x>xmax then xmax=x elseif x<xmin then xmin=x end
13840 if y>ymax then ymax=y elseif y<ymin then ymin=y end
13841 else
13842 xmin=x
13843 ymin=y
13844 xmax=x
13845 ymax=y
13846 checked=true
13847 end
13848 end
13849 local function xlineto()
13850 if keepcurve then
13851 r=r+1
13852 result[r]={ x,y,"l" }
13853 end
13854 if not checked then
13855 xmin=x
13856 ymin=y
13857 xmax=x
13858 ymax=y
13859 checked=true
13860 elseif x>xmax then
13861 xmax=x
13862 elseif x<xmin then
13863 xmin=x
13864 end
13865 end
13866 local function ylineto()
13867 if keepcurve then
13868 r=r+1
13869 result[r]={ x,y,"l" }
13870 end
13871 if not checked then
13872 xmin=x
13873 ymin=y
13874 xmax=x
13875 ymax=y
13876 checked=true
13877 elseif y>ymax then
13878 ymax=y
13879 elseif y<ymin then
13880 ymin=y
13881 end
13882 end
13883 local function xycurveto(x1,y1,x2,y2,x3,y3,i,n)
13884 if trace_charstrings then
13885 showstate("curveto",i,n)
13886 end
13887 if keepcurve then
13888 r=r+1
13889 result[r]={ x1,y1,x2,y2,x3,y3,"c" }
13890 end
13891 if checked then
13892 if x1>xmax then xmax=x1 elseif x1<xmin then xmin=x1 end
13893 if y1>ymax then ymax=y1 elseif y1<ymin then ymin=y1 end
13894 else
13895 xmin=x1
13896 ymin=y1
13897 xmax=x1
13898 ymax=y1
13899 checked=true
13900 end
13901 if x2>xmax then xmax=x2 elseif x2<xmin then xmin=x2 end
13902 if y2>ymax then ymax=y2 elseif y2<ymin then ymin=y2 end
13903 if x3>xmax then xmax=x3 elseif x3<xmin then xmin=x3 end
13904 if y3>ymax then ymax=y3 elseif y3<ymin then ymin=y3 end
13905 end
13906 local function rmoveto()
13907 if not width then
13908 if top>2 then
13909 width=stack[1]
13910 if trace_charstrings then
13911 showvalue("backtrack width",width)
13912 end
13913 else
13914 width=true
13915 end
13916 end
13917 if trace_charstrings then
13918 showstate("rmoveto")
13919 end
13920 x=x+stack[top-1]
13921 y=y+stack[top]
13922 top=0
13923 xymoveto()
13924 end
13925 local function hmoveto()
13926 if not width then
13927 if top>1 then
13928 width=stack[1]
13929 if trace_charstrings then
13930 showvalue("backtrack width",width)
13931 end
13932 else
13933 width=true
13934 end
13935 end
13936 if trace_charstrings then
13937 showstate("hmoveto")
13938 end
13939 x=x+stack[top]
13940 top=0
13941 xmoveto()
13942 end
13943 local function vmoveto()
13944 if not width then
13945 if top>1 then
13946 width=stack[1]
13947 if trace_charstrings then
13948 showvalue("backtrack width",width)
13949 end
13950 else
13951 width=true
13952 end
13953 end
13954 if trace_charstrings then
13955 showstate("vmoveto")
13956 end
13957 y=y+stack[top]
13958 top=0
13959 ymoveto()
13960 end
13961 local function rlineto()
13962 if trace_charstrings then
13963 showstate("rlineto")
13964 end
13965 for i=1,top,2 do
13966 x=x+stack[i]
13967 y=y+stack[i+1]
13968 xylineto()
13969 end
13970 top=0
13971 end
13972 local function hlineto()
13973 if trace_charstrings then
13974 showstate("hlineto")
13975 end
13976 if top==1 then
13977 x=x+stack[1]
13978 xlineto()
13979 else
13980 local swap=true
13981 for i=1,top do
13982 if swap then
13983 x=x+stack[i]
13984 xlineto()
13985 swap=false
13986 else
13987 y=y+stack[i]
13988 ylineto()
13989 swap=true
13990 end
13991 end
13992 end
13993 top=0
13994 end
13995 local function vlineto()
13996 if trace_charstrings then
13997 showstate("vlineto")
13998 end
13999 if top==1 then
14000 y=y+stack[1]
14001 ylineto()
14002 else
14003 local swap=false
14004 for i=1,top do
14005 if swap then
14006 x=x+stack[i]
14007 xlineto()
14008 swap=false
14009 else
14010 y=y+stack[i]
14011 ylineto()
14012 swap=true
14013 end
14014 end
14015 end
14016 top=0
14017 end
14018 local function rrcurveto()
14019 if trace_charstrings then
14020 showstate("rrcurveto")
14021 end
14022 if top==6 then
14023 local ax=x+stack[1]
14024 local ay=y+stack[2]
14025 local bx=ax+stack[3]
14026 local by=ay+stack[4]
14027 x=bx+stack[5]
14028 y=by+stack[6]
14029 xycurveto(ax,ay,bx,by,x,y,1,6)
14030 else
14031 for i=1,top,6 do
14032 local ax=x+stack[i]
14033 local ay=y+stack[i+1]
14034 local bx=ax+stack[i+2]
14035 local by=ay+stack[i+3]
14036 x=bx+stack[i+4]
14037 y=by+stack[i+5]
14038 xycurveto(ax,ay,bx,by,x,y,i,6)
14039 end
14040 end
14041 top=0
14042 end
14043 local function hhcurveto()
14044 if trace_charstrings then
14045 showstate("hhcurveto")
14046 end
14047 local s=1
14048 if top%2~=0 then
14049 y=y+stack[1]
14050 s=2
14051 end
14052 if top==4 then
14053 local ax=x+stack[1]
14054 local ay=y
14055 local bx=ax+stack[2]
14056 local by=ay+stack[3]
14057 x=bx+stack[4]
14058 y=by
14059 xycurveto(ax,ay,bx,by,x,y,1,4)
14060 else
14061 for i=s,top,4 do
14062 local ax=x+stack[i]
14063 local ay=y
14064 local bx=ax+stack[i+1]
14065 local by=ay+stack[i+2]
14066 x=bx+stack[i+3]
14067 y=by
14068 xycurveto(ax,ay,bx,by,x,y,i,4)
14069 end
14070 end
14071 top=0
14072 end
14073 local function vvcurveto()
14074 if trace_charstrings then
14075 showstate("vvcurveto")
14076 end
14077 local s=1
14078 local d=0
14079 if top%2~=0 then
14080 d=stack[1]
14081 s=2
14082 end
14083 if top==4 then
14084 local ax=x+d
14085 local ay=y+stack[1]
14086 local bx=ax+stack[2]
14087 local by=ay+stack[3]
14088 x=bx
14089 y=by+stack[4]
14090 xycurveto(ax,ay,bx,by,x,y,1,4)
14091 d=0
14092 else
14093 for i=s,top,4 do
14094 local ax=x+d
14095 local ay=y+stack[i]
14096 local bx=ax+stack[i+1]
14097 local by=ay+stack[i+2]
14098 x=bx
14099 y=by+stack[i+3]
14100 xycurveto(ax,ay,bx,by,x,y,i,4)
14101 d=0
14102 end
14103 end
14104 top=0
14105 end
14106 local function xxcurveto(swap)
14107 local last=top%4~=0 and stack[top]
14108 if last then
14109 top=top-1
14110 end
14111 if top==4 then
14112 local ax,ay,bx,by
14113 if swap then
14114 ax=x+stack[1]
14115 ay=y
14116 bx=ax+stack[2]
14117 by=ay+stack[3]
14118 y=by+stack[4]
14119 if last then
14120 x=bx+last
14121 else
14122 x=bx
14123 end
14124 else
14125 ax=x
14126 ay=y+stack[1]
14127 bx=ax+stack[2]
14128 by=ay+stack[3]
14129 x=bx+stack[4]
14130 if last then
14131 y=by+last
14132 else
14133 y=by
14134 end
14135 end
14136 xycurveto(ax,ay,bx,by,x,y,1,4)
14137 else
14138 for i=1,top,4 do
14139 local ax,ay,bx,by
14140 if swap then
14141 ax=x+stack[i]
14142 ay=y
14143 bx=ax+stack[i+1]
14144 by=ay+stack[i+2]
14145 y=by+stack[i+3]
14146 if last and i+3==top then
14147 x=bx+last
14148 else
14149 x=bx
14150 end
14151 swap=false
14152 else
14153 ax=x
14154 ay=y+stack[i]
14155 bx=ax+stack[i+1]
14156 by=ay+stack[i+2]
14157 x=bx+stack[i+3]
14158 if last and i+3==top then
14159 y=by+last
14160 else
14161 y=by
14162 end
14163 swap=true
14164 end
14165 xycurveto(ax,ay,bx,by,x,y,i,4)
14166 end
14167 end
14168 top=0
14169 end
14170 local function hvcurveto()
14171 if trace_charstrings then
14172 showstate("hvcurveto")
14173 end
14174 xxcurveto(true)
14175 end
14176 local function vhcurveto()
14177 if trace_charstrings then
14178 showstate("vhcurveto")
14179 end
14180 xxcurveto(false)
14181 end
14182 local function rcurveline()
14183 if trace_charstrings then
14184 showstate("rcurveline")
14185 end
14186 for i=1,top-2,6 do
14187 local ax=x+stack[i]
14188 local ay=y+stack[i+1]
14189 local bx=ax+stack[i+2]
14190 local by=ay+stack[i+3]
14191 x=bx+stack[i+4]
14192 y=by+stack[i+5]
14193 xycurveto(ax,ay,bx,by,x,y,i,6)
14194 end
14195 x=x+stack[top-1]
14196 y=y+stack[top]
14197 xylineto()
14198 top=0
14199 end
14200 local function rlinecurve()
14201 if trace_charstrings then
14202 showstate("rlinecurve")
14203 end
14204 if top>6 then
14205 for i=1,top-6,2 do
14206 x=x+stack[i]
14207 y=y+stack[i+1]
14208 xylineto()
14209 end
14210 end
14211 local ax=x+stack[top-5]
14212 local ay=y+stack[top-4]
14213 local bx=ax+stack[top-3]
14214 local by=ay+stack[top-2]
14215 x=bx+stack[top-1]
14216 y=by+stack[top]
14217 xycurveto(ax,ay,bx,by,x,y)
14218 top=0
14219 end
14220 local function flex()
14221 if trace_charstrings then
14222 showstate("flex")
14223 end
14224 local ax=x+stack[1]
14225 local ay=y+stack[2]
14226 local bx=ax+stack[3]
14227 local by=ay+stack[4]
14228 local cx=bx+stack[5]
14229 local cy=by+stack[6]
14230 xycurveto(ax,ay,bx,by,cx,cy)
14231 local dx=cx+stack[7]
14232 local dy=cy+stack[8]
14233 local ex=dx+stack[9]
14234 local ey=dy+stack[10]
14235 x=ex+stack[11]
14236 y=ey+stack[12]
14237 xycurveto(dx,dy,ex,ey,x,y)
14238 top=0
14239 end
14240 local function hflex()
14241 if trace_charstrings then
14242 showstate("hflex")
14243 end
14244 local ax=x+stack[1]
14245 local ay=y
14246 local bx=ax+stack[2]
14247 local by=ay+stack[3]
14248 local cx=bx+stack[4]
14249 local cy=by
14250 xycurveto(ax,ay,bx,by,cx,cy)
14251 local dx=cx+stack[5]
14252 local dy=by
14253 local ex=dx+stack[6]
14254 local ey=y
14255 x=ex+stack[7]
14256 xycurveto(dx,dy,ex,ey,x,y)
14257 top=0
14258 end
14259 local function hflex1()
14260 if trace_charstrings then
14261 showstate("hflex1")
14262 end
14263 local ax=x+stack[1]
14264 local ay=y+stack[2]
14265 local bx=ax+stack[3]
14266 local by=ay+stack[4]
14267 local cx=bx+stack[5]
14268 local cy=by
14269 xycurveto(ax,ay,bx,by,cx,cy)
14270 local dx=cx+stack[6]
14271 local dy=by
14272 local ex=dx+stack[7]
14273 local ey=dy+stack[8]
14274 x=ex+stack[9]
14275 xycurveto(dx,dy,ex,ey,x,y)
14276 top=0
14277 end
14278 local function flex1()
14279 if trace_charstrings then
14280 showstate("flex1")
14281 end
14282 local ax=x+stack[1]
14283 local ay=y+stack[2]
14284 local bx=ax+stack[3]
14285 local by=ay+stack[4]
14286 local cx=bx+stack[5]
14287 local cy=by+stack[6]
14288 xycurveto(ax,ay,bx,by,cx,cy)
14289 local dx=cx+stack[7]
14290 local dy=cy+stack[8]
14291 local ex=dx+stack[9]
14292 local ey=dy+stack[10]
14293 if abs(ex-x)>abs(ey-y) then
14294 x=ex+stack[11]
14295 else
14296 y=ey+stack[11]
14297 end
14298 xycurveto(dx,dy,ex,ey,x,y)
14299 top=0
14300 end
14301 local function getstem()
14302 if top==0 then
14303 elseif top%2~=0 then
14304 if width then
14305 remove(stack,1)
14306 else
14307 width=remove(stack,1)
14308 if trace_charstrings then
14309 showvalue("width",width)
14310 end
14311 end
14312 top=top-1
14313 end
14314 if trace_charstrings then
14315 showstate("stem")
14316 end
14317 stems=stems+idiv(top,2)
14318 top=0
14319 end
14320 local function getmask()
14321 if top==0 then
14322 elseif top%2~=0 then
14323 if width then
14324 remove(stack,1)
14325 else
14326 width=remove(stack,1)
14327 if trace_charstrings then
14328 showvalue("width",width)
14329 end
14330 end
14331 top=top-1
14332 end
14333 if trace_charstrings then
14334 showstate(operator==19 and "hintmark" or "cntrmask")
14335 end
14336 stems=stems+idiv(top,2)
14337 top=0
14338 if stems==0 then
14339 elseif stems<=8 then
14340 return 1
14341 else
14342 return idiv(stems+7,8)
14343 end
14344 end
14345 local function unsupported(t)
14346 if trace_charstrings then
14347 showstate("unsupported "..t)
14348 end
14349 top=0
14350 end
14351 local function unsupportedsub(t)
14352 if trace_charstrings then
14353 showstate("unsupported sub "..t)
14354 end
14355 top=0
14356 end
14357 local function getstem3()
14358 if trace_charstrings then
14359 showstate("stem3")
14360 end
14361 top=0
14362 end
14363 local function divide()
14364 if version=="cff" then
14365 local d=stack[top]
14366 top=top-1
14367 stack[top]=stack[top]/d
14368 end
14369 end
14370 local function closepath()
14371 if version=="cff" then
14372 if trace_charstrings then
14373 showstate("closepath")
14374 end
14375 end
14376 top=0
14377 end
14378 local function hsbw()
14379 if version=="cff" then
14380 if trace_charstrings then
14381 showstate("hsbw")
14382 end
14383 lsb=stack[top-1] or 0
14384 width=stack[top]
14385 end
14386 top=0
14387 end
14388 local function sbw()
14389 if version=="cff" then
14390 if trace_charstrings then
14391 showstate("sbw")
14392 end
14393 lsb=stack[top-3]
14394 width=stack[top-1]
14395 end
14396 top=0
14397 end
14398 local function seac()
14399 if version=="cff" then
14400 if trace_charstrings then
14401 showstate("seac")
14402 end
14403 end
14404 top=0
14405 end
14406 local popped=3
14407 local hints=3
14408 local function callothersubr()
14409 if version=="cff" then
14410 if trace_charstrings then
14411 showstate("callothersubr")
14412 end
14413 if stack[top]==hints then
14414 popped=stack[top-2]
14415 else
14416 popped=3
14417 end
14418 local t=stack[top-1]
14419 if t then
14420 top=top-(t+2)
14421 if top<0 then
14422 top=0
14423 end
14424 else
14425 top=0
14426 end
14427 else
14428 top=0
14429 end
14430 end
14431 local function pop()
14432 if version=="cff" then
14433 if trace_charstrings then
14434 showstate("pop")
14435 end
14436 top=top+1
14437 stack[top]=popped
14438 else
14439 top=0
14440 end
14441 end
14442 local function setcurrentpoint()
14443 if version=="cff" then
14444 if trace_charstrings then
14445 showstate("setcurrentpoint (unsupported)")
14446 end
14447 x=x+stack[top-1]
14448 y=y+stack[top]
14449 end
14450 top=0
14451 end
14452 local reginit=false
14453 local function updateregions(n)
14454 if regions then
14455 local current=regions[n+1] or regions[1]
14456 nofregions=#current
14457 if axis and n~=reginit then
14458 factors={}
14459 for i=1,nofregions do
14460 local region=current[i]
14461 local s=1
14462 for j=1,#axis do
14463 local f=axis[j]
14464 local r=region[j]
14465 local start=r.start
14466 local peak=r.peak
14467 local stop=r.stop
14468 if start>peak or peak>stop then
14469 elseif start<0 and stop>0 and peak~=0 then
14470 elseif peak==0 then
14471 elseif f<start or f>stop then
14472 s=0
14473 break
14474 elseif f<peak then
14475 s=s*(f-start)/(peak-start)
14476 elseif f>peak then
14477 s=s*(stop-f)/(stop-peak)
14478 else
14479 end
14480 end
14481 factors[i]=s
14482 end
14483 end
14484 end
14485 reginit=n
14486 end
14487 local function setvsindex()
14488 local vsindex=stack[top]
14489 if trace_charstrings then
14490 showstate(formatters["vsindex %i"](vsindex))
14491 end
14492 updateregions(vsindex)
14493 top=top-1
14494 end
14495 local function blend()
14496 local n=stack[top]
14497 top=top-1
14498 if axis then
14499 if trace_charstrings then
14500 local t=top-nofregions*n
14501 local m=t-n
14502 for i=1,n do
14503 local k=m+i
14504 local d=m+n+(i-1)*nofregions
14505 local old=stack[k]
14506 local new=old
14507 for r=1,nofregions do
14508 new=new+stack[d+r]*factors[r]
14509 end
14510 stack[k]=new
14511 showstate(formatters["blend %i of %i: %s -> %s"](i,n,old,new))
14512 end
14513 top=t
14514 elseif n==1 then
14515 top=top-nofregions
14516 local v=stack[top]
14517 for r=1,nofregions do
14518 v=v+stack[top+r]*factors[r]
14519 end
14520 stack[top]=v
14521 else
14522 top=top-nofregions*n
14523 local d=top
14524 local k=top-n
14525 for i=1,n do
14526 k=k+1
14527 local v=stack[k]
14528 for r=1,nofregions do
14529 v=v+stack[d+r]*factors[r]
14530 end
14531 stack[k]=v
14532 d=d+nofregions
14533 end
14534 end
14535 else
14536 top=top-nofregions*n
14537 end
14538 end
14539 local actions={ [0]=unsupported,
14540 getstem,
14541 unsupported,
14542 getstem,
14543 vmoveto,
14544 rlineto,
14545 hlineto,
14546 vlineto,
14547 rrcurveto,
14548 unsupported,
14549 unsupported,
14550 unsupported,
14551 unsupported,
14552 hsbw,
14553 unsupported,
14554 setvsindex,
14555 blend,
14556 unsupported,
14557 getstem,
14558 getmask,
14559 getmask,
14560 rmoveto,
14561 hmoveto,
14562 getstem,
14563 rcurveline,
14564 rlinecurve,
14565 vvcurveto,
14566 hhcurveto,
14567 unsupported,
14568 unsupported,
14569 vhcurveto,
14570 hvcurveto,
14571 }
14572 local reverse={ [0]="unsupported",
14573 "getstem",
14574 "unsupported",
14575 "getstem",
14576 "vmoveto",
14577 "rlineto",
14578 "hlineto",
14579 "vlineto",
14580 "rrcurveto",
14581 "unsupported",
14582 "unsupported",
14583 "unsupported",
14584 "unsupported",
14585 "hsbw",
14586 "unsupported",
14587 "setvsindex",
14588 "blend",
14589 "unsupported",
14590 "getstem",
14591 "getmask",
14592 "getmask",
14593 "rmoveto",
14594 "hmoveto",
14595 "getstem",
14596 "rcurveline",
14597 "rlinecurve",
14598 "vvcurveto",
14599 "hhcurveto",
14600 "unsupported",
14601 "unsupported",
14602 "vhcurveto",
14603 "hvcurveto",
14604 }
14605 local subactions={
14606 [000]=dotsection,
14607 [001]=getstem3,
14608 [002]=getstem3,
14609 [006]=seac,
14610 [007]=sbw,
14611 [012]=divide,
14612 [016]=callothersubr,
14613 [017]=pop,
14614 [033]=setcurrentpoint,
14615 [034]=hflex,
14616 [035]=flex,
14617 [036]=hflex1,
14618 [037]=flex1,
14619 }
14620 local chars=setmetatableindex(function (t,k)
14621 local v=char(k)
14622 t[k]=v
14623 return v
14624 end)
14625 local c_endchar=chars[14]
14626 local encode={}
14627 local typeone=false
14628 setmetatableindex(encode,function(t,i)
14629 for i=-2048,-1130 do
14630 t[i]=char(28,band(rshift(i,8),0xFF),band(i,0xFF))
14631 end
14632 for i=-1131,-108 do
14633 local v=0xFB00-i-108
14634 t[i]=char(band(rshift(v,8),0xFF),band(v,0xFF))
14635 end
14636 for i=-107,107 do
14637 t[i]=chars[i+139]
14638 end
14639 for i=108,1131 do
14640 local v=0xF700+i-108
14641 t[i]=char(extract(v,8,8),extract(v,0,8))
14642 end
14643 for i=1132,2048 do
14644 t[i]=char(28,band(rshift(i,8),0xFF),band(i,0xFF))
14645 end
14646 setmetatableindex(encode,function(t,k)
14647 local r=round(k)
14648 local v=rawget(t,r)
14649 if v then
14650 return v
14651 end
14652 local v1=floor(k)
14653 local v2=floor((k-v1)*0x10000)
14654 return char(255,extract(v1,8,8),extract(v1,0,8),extract(v2,8,8),extract(v2,0,8))
14655 end)
14656 return t[i]
14657 end)
14658 readers.cffencoder=encode
14659 local function p_setvsindex()
14660 local vsindex=stack[top]
14661 updateregions(vsindex)
14662 top=top-1
14663 end
14664 local function p_blend()
14665 local n=stack[top]
14666 top=top-1
14667 if not axis then
14668 elseif n==1 then
14669 top=top-nofregions
14670 local v=stack[top]
14671 for r=1,nofregions do
14672 v=v+stack[top+r]*factors[r]
14673 end
14674 stack[top]=round(v)
14675 else
14676 top=top-nofregions*n
14677 local d=top
14678 local k=top-n
14679 for i=1,n do
14680 k=k+1
14681 local v=stack[k]
14682 for r=1,nofregions do
14683 v=v+stack[d+r]*factors[r]
14684 end
14685 stack[k]=round(v)
14686 d=d+nofregions
14687 end
14688 end
14689 end
14690 local function p_getstem()
14691 local n=0
14692 if top%2~=0 then
14693 n=1
14694 end
14695 if top>n then
14696 stems=stems+idiv(top-n,2)
14697 end
14698 end
14699 local function p_getmask()
14700 local n=0
14701 if top%2~=0 then
14702 n=1
14703 end
14704 if top>n then
14705 stems=stems+idiv(top-n,2)
14706 end
14707 if stems==0 then
14708 return 0
14709 elseif stems<=8 then
14710 return 1
14711 else
14712 return idiv(stems+7,8)
14713 end
14714 end
14715 local process
14716 local function call(scope,list,bias)
14717 depth=depth+1
14718 if top==0 then
14719 showstate(formatters["unknown %s call %s, case %s"](scope,"?",1))
14720 top=0
14721 else
14722 local index=stack[top]+bias
14723 top=top-1
14724 if trace_charstrings then
14725 showvalue(scope,index,true)
14726 end
14727 local tab=list[index]
14728 if tab then
14729 process(tab)
14730 else
14731 showstate(formatters["unknown %s call %s, case %s"](scope,index,2))
14732 top=0
14733 end
14734 end
14735 depth=depth-1
14736 end
14737 process=function(tab)
14738 local i=1
14739 local n=#tab
14740 while i<=n do
14741 local t=tab[i]
14742 if t>=32 then
14743 top=top+1
14744 if t<=246 then
14745 stack[top]=t-139
14746 i=i+1
14747 elseif t<=250 then
14748 stack[top]=t*256-63124+tab[i+1]
14749 i=i+2
14750 elseif t<=254 then
14751 stack[top]=-t*256+64148-tab[i+1]
14752 i=i+2
14753 elseif typeone then
14754 local n=0x1000000*tab[i+1]+0x10000*tab[i+2]+0x100*tab[i+3]+tab[i+4]
14755 if n>=0x8000000 then
14756 n=n-0xFFFFFFFF-1
14757 end
14758 stack[top]=n
14759 i=i+5
14760 else
14761 local n1=0x100*tab[i+1]+tab[i+2]
14762 local n2=0x100*tab[i+3]+tab[i+4]
14763 if n1>=0x8000 then
14764 n1=n1-0x10000
14765 end
14766 stack[top]=n1+n2/0xFFFF
14767 i=i+5
14768 end
14769 elseif t==28 then
14770 top=top+1
14771 local n=0x100*tab[i+1]+tab[i+2]
14772 if n>=0x8000 then
14773 stack[top]=n-0x10000
14774 else
14775 stack[top]=n
14776 end
14777 i=i+3
14778 elseif t==11 then
14779 if trace_charstrings then
14780 showstate("return")
14781 end
14782 return
14783 elseif t==10 then
14784 call("local",locals,localbias)
14785 i=i+1
14786 elseif t==14 then
14787 if width then
14788 elseif top>0 then
14789 width=stack[1]
14790 if trace_charstrings then
14791 showvalue("width",width)
14792 end
14793 else
14794 width=true
14795 end
14796 if trace_charstrings then
14797 showstate("endchar")
14798 end
14799 return
14800 elseif t==29 then
14801 call("global",globals,globalbias)
14802 i=i+1
14803 elseif t==12 then
14804 i=i+1
14805 local t=tab[i]
14806 if justpass then
14807 if t>=34 and t<=37 then
14808 for i=1,top do
14809 r=r+1;result[r]=encode[stack[i]]
14810 end
14811 r=r+1;result[r]=chars[12]
14812 r=r+1;result[r]=chars[t]
14813 top=0
14814 elseif t==6 then
14815 seacs[procidx]={
14816 asb=stack[1],
14817 adx=stack[2],
14818 ady=stack[3],
14819 base=stack[4],
14820 accent=stack[5],
14821 width=width,
14822 lsb=lsb,
14823 }
14824 top=0
14825 else
14826 local a=subactions[t]
14827 if a then
14828 a(t)
14829 else
14830 top=0
14831 end
14832 end
14833 else
14834 local a=subactions[t]
14835 if a then
14836 a(t)
14837 else
14838 if trace_charstrings then
14839 showvalue("<subaction>",t)
14840 end
14841 top=0
14842 end
14843 end
14844 i=i+1
14845 elseif justpass then
14846 if t==15 then
14847 p_setvsindex()
14848 i=i+1
14849 elseif t==16 then
14850 local s=p_blend() or 0
14851 i=i+s+1
14852 elseif t==1 or t==3 or t==18 or operation==23 then
14853 p_getstem()
14854 if version=="cff" then
14855 if top>0 then
14856 for i=1,top do
14857 r=r+1;result[r]=encode[stack[i]]
14858 end
14859 top=0
14860 end
14861 r=r+1;result[r]=chars[t]
14862 else
14863 top=0
14864 end
14865 i=i+1
14866 elseif t==19 or t==20 then
14867 local s=p_getmask() or 0
14868 if true then
14869 if top>0 then
14870 for i=1,top do
14871 r=r+1;result[r]=encode[stack[i]]
14872 end
14873 top=0
14874 end
14875 r=r+1;result[r]=chars[t]
14876 for j=1,s do
14877 i=i+1
14878 r=r+1;result[r]=chars[tab[i]]
14879 end
14880 else
14881 i=i+s
14882 top=0
14883 end
14884 i=i+1
14885 elseif t==9 then
14886 top=0
14887 i=i+1
14888 elseif t==13 then
14889 hsbw()
14890 if true then
14891 r=r+1;result[r]=encode[lsb]
14892 r=r+1;result[r]=chars[22]
14893 else
14894 end
14895 i=i+1
14896 else
14897 if trace_charstrings then
14898 showstate(reverse[t] or "<action>")
14899 end
14900 if top>0 then
14901 if t==8 and top>48 then
14902 local n=0
14903 for i=1,top do
14904 if n==48 then
14905 r=r+1;result[r]=chars[t]
14906 n=1
14907 else
14908 n=n+1
14909 end
14910 r=r+1;result[r]=encode[stack[i]]
14911 end
14912 else
14913 for i=1,top do
14914 r=r+1;result[r]=encode[stack[i]]
14915 end
14916 end
14917 top=0
14918 end
14919 r=r+1;result[r]=chars[t]
14920 i=i+1
14921 end
14922 else
14923 local a=actions[t]
14924 if a then
14925 local s=a(t)
14926 if s then
14927 i=i+s+1
14928 else
14929 i=i+1
14930 end
14931 else
14932 if trace_charstrings then
14933 showstate(reverse[t] or "<action>")
14934 end
14935 top=0
14936 i=i+1
14937 end
14938 end
14939 end
14940 end
14941 local function setbias(globals,locals,nobias)
14942 if nobias then
14943 return 0,0
14944 else
14945 local g=#globals
14946 local l=#locals
14947 return
14948 ((g<1240 and 107) or (g<33900 and 1131) or 32768)+1,
14949 ((l<1240 and 107) or (l<33900 and 1131) or 32768)+1
14950 end
14951 end
14952 local function processshape(glyphs,tab,index,hack)
14953 if not tab then
14954 glyphs[index]={
14955 boundingbox={ 0,0,0,0 },
14956 width=0,
14957 name=charset and charset[index] or nil,
14958 }
14959 return
14960 end
14961 tab=bytetable(tab)
14962 x=0
14963 y=0
14964 width=false
14965 lsb=0
14966 r=0
14967 top=0
14968 stems=0
14969 result={}
14970 popped=3
14971 procidx=index
14972 xmin=0
14973 xmax=0
14974 ymin=0
14975 ymax=0
14976 checked=false
14977 if trace_charstrings then
14978 report("glyph: %i",index)
14979 report("data : % t",tab)
14980 end
14981 if regions then
14982 updateregions(vsindex)
14983 end
14984 process(tab)
14985 if hack then
14986 return x,y
14987 end
14988 local boundingbox={
14989 round(xmin),
14990 round(ymin),
14991 round(xmax),
14992 round(ymax),
14993 }
14994 if width==true or width==false then
14995 width=defaultwidth
14996 else
14997 width=nominalwidth+width
14998 end
14999 local glyph=glyphs[index]
15000 if justpass then
15001 r=r+1
15002 result[r]=c_endchar
15003 local stream=concat(result)
15004 result=nil
15005 if glyph then
15006 glyph.stream=stream
15007 glyph.width=width
15008 else
15009 glyphs[index]={ stream=stream,width=width }
15010 end
15011 elseif glyph then
15012 glyph.segments=keepcurve~=false and result or nil
15013 glyph.boundingbox=boundingbox
15014 if not glyph.width then
15015 glyph.width=width
15016 end
15017 if charset and not glyph.name then
15018 glyph.name=charset[index]
15019 end
15020 elseif keepcurve then
15021 glyphs[index]={
15022 segments=result,
15023 boundingbox=boundingbox,
15024 width=width,
15025 name=charset and charset[index] or nil,
15026 }
15027 result=nil
15028 else
15029 glyphs[index]={
15030 boundingbox=boundingbox,
15031 width=width,
15032 name=charset and charset[index] or nil,
15033 }
15034 end
15035 if trace_charstrings then
15036 report("width : %s",tostring(width))
15037 report("boundingbox: % t",boundingbox)
15038 end
15039 end
15040 startparsing=function(fontdata,data,streams)
15041 reginit=false
15042 axis=false
15043 regions=data.regions
15044 justpass=streams==true
15045 popped=3
15046 seacs={}
15047 if regions then
15048 regions={}
15049 local deltas=data.deltas
15050 for i=1,#deltas do
15051 regions[i]=deltas[i].regions
15052 end
15053 axis=data.factors or false
15054 end
15055 end
15056 stopparsing=function(fontdata,data)
15057 stack={}
15058 glyphs=false
15059 result={}
15060 top=0
15061 locals=false
15062 globals=false
15063 strings=false
15064 popped=3
15065 seacs={}
15066 end
15067 local function setwidths(private)
15068 if not private then
15069 return 0,0
15070 end
15071 local privatedata=private.data
15072 if not privatedata then
15073 return 0,0
15074 end
15075 return privatedata.nominalwidthx or 0,privatedata.defaultwidthx or 0
15076 end
15077 parsecharstrings=function(fontdata,data,glphs,doshapes,tversion,streams,nobias,istypeone)
15078 local dictionary=data.dictionaries[1]
15079 local charstrings=dictionary.charstrings
15080 keepcurve=doshapes
15081 version=tversion
15082 typeone=istypeone or false
15083 strings=data.strings
15084 globals=data.routines or {}
15085 locals=dictionary.subroutines or {}
15086 charset=dictionary.charset
15087 vsindex=dictionary.vsindex or 0
15088 local glyphs=glphs or {}
15089 globalbias,localbias=setbias(globals,locals,nobias)
15090 nominalwidth,defaultwidth=setwidths(dictionary.private)
15091 if charstrings then
15092 startparsing(fontdata,data,streams)
15093 for index=1,#charstrings do
15094 processshape(glyphs,charstrings[index],index-1)
15095 end
15096 if justpass and next(seacs) then
15097 local charset=data.dictionaries[1].charset
15098 if charset then
15099 local lookup=table.swapped(charset)
15100 for index,v in next,seacs do
15101 local bindex=lookup[standardnames[v.base]]
15102 local aindex=lookup[standardnames[v.accent]]
15103 local bglyph=bindex and glyphs[bindex]
15104 local aglyph=aindex and glyphs[aindex]
15105 if bglyph and aglyph then
15106 local jp=justpass
15107 justpass=false
15108 local x,y=processshape(glyphs,charstrings[bindex+1],bindex,true)
15109 justpass=jp
15110 local base=bglyph.stream
15111 local accent=aglyph.stream
15112 local moveto=encode[-x-v.asb+v.adx]..chars[22]..encode[-y+v.ady]..chars[ 4]
15113 base=sub(base,1,#base-1)
15114 glyphs[index].stream=base..moveto..accent
15115 end
15116 end
15117 end
15118 end
15119 stopparsing(fontdata,data)
15120 else
15121 report("no charstrings")
15122 end
15123 return glyphs
15124 end
15125 parsecharstring=function(fontdata,data,dictionary,tab,glphs,index,doshapes,tversion,streams)
15126 keepcurve=doshapes
15127 version=tversion
15128 strings=data.strings
15129 globals=data.routines or {}
15130 locals=dictionary.subroutines or {}
15131 charset=false
15132 vsindex=dictionary.vsindex or 0
15133 local glyphs=glphs or {}
15134 justpass=streams==true
15135 seacs={}
15136 globalbias,localbias=setbias(globals,locals,nobias)
15137 nominalwidth,defaultwidth=setwidths(dictionary.private)
15138 processshape(glyphs,tab,index-1)
15139 return glyphs[index]
15140 end
15141 end
15142 local function readglobals(f,data,version)
15143 local routines=readlengths(f,version=="cff2")
15144 for i=1,#routines do
15145 routines[i]=readbytetable(f,routines[i])
15146 end
15147 data.routines=routines
15148 end
15149 local function readencodings(f,data)
15150 data.encodings={}
15151 end
15152 local function readcharsets(f,data,dictionary)
15153 local header=data.header
15154 local strings=data.strings
15155 local nofglyphs=data.nofglyphs
15156 local charsetoffset=dictionary.charset
15157 if charsetoffset and charsetoffset~=0 then
15158 setposition(f,header.offset+charsetoffset)
15159 local format=readbyte(f)
15160 local charset={ [0]=".notdef" }
15161 dictionary.charset=charset
15162 if format==0 then
15163 for i=1,nofglyphs do
15164 charset[i]=strings[readushort(f)]
15165 end
15166 elseif format==1 or format==2 then
15167 local readcount=format==1 and readbyte or readushort
15168 local i=1
15169 while i<=nofglyphs do
15170 local sid=readushort(f)
15171 local n=readcount(f)
15172 for s=sid,sid+n do
15173 charset[i]=strings[s]
15174 i=i+1
15175 if i>nofglyphs then
15176 break
15177 end
15178 end
15179 end
15180 else
15181 report("cff parser: unsupported charset format %a",format)
15182 end
15183 else
15184 dictionary.nocharset=true
15185 dictionary.charset=nil
15186 end
15187 end
15188 local function readprivates(f,data)
15189 local header=data.header
15190 local dictionaries=data.dictionaries
15191 local private=dictionaries[1].private
15192 if private then
15193 setposition(f,header.offset+private.offset)
15194 private.data=readstring(f,private.size)
15195 end
15196 end
15197 local function readlocals(f,data,dictionary,version)
15198 local header=data.header
15199 local private=dictionary.private
15200 if private then
15201 local subroutineoffset=private.data.subroutines
15202 if subroutineoffset~=0 then
15203 setposition(f,header.offset+private.offset+subroutineoffset)
15204 local subroutines=readlengths(f,version=="cff2")
15205 for i=1,#subroutines do
15206 subroutines[i]=readbytetable(f,subroutines[i])
15207 end
15208 dictionary.subroutines=subroutines
15209 private.data.subroutines=nil
15210 else
15211 dictionary.subroutines={}
15212 end
15213 else
15214 dictionary.subroutines={}
15215 end
15216 end
15217 local function readcharstrings(f,data,version)
15218 local header=data.header
15219 local dictionaries=data.dictionaries
15220 local dictionary=dictionaries[1]
15221 local stringtype=dictionary.charstringtype
15222 local offset=dictionary.charstrings
15223 if type(offset)~="number" then
15224 elseif stringtype==2 then
15225 setposition(f,header.offset+offset)
15226 local charstrings=readlengths(f,version=="cff2")
15227 local nofglyphs=#charstrings
15228 for i=1,nofglyphs do
15229 charstrings[i]=readstring(f,charstrings[i])
15230 end
15231 data.nofglyphs=nofglyphs
15232 dictionary.charstrings=charstrings
15233 else
15234 report("unsupported charstr type %i",stringtype)
15235 data.nofglyphs=0
15236 dictionary.charstrings={}
15237 end
15238 end
15239 local function readcidprivates(f,data)
15240 local header=data.header
15241 local dictionaries=data.dictionaries[1].cid.dictionaries
15242 for i=1,#dictionaries do
15243 local dictionary=dictionaries[i]
15244 local private=dictionary.private
15245 if private then
15246 setposition(f,header.offset+private.offset)
15247 private.data=readstring(f,private.size)
15248 end
15249 end
15250 parseprivates(data,dictionaries)
15251 end
15252 readers.parsecharstrings=parsecharstrings
15253 local function readnoselect(f,fontdata,data,glyphs,doshapes,version,streams)
15254 local dictionaries=data.dictionaries
15255 local dictionary=dictionaries[1]
15256 local cid=not dictionary.private and dictionary.cid
15257 readglobals(f,data,version)
15258 readcharstrings(f,data,version)
15259 if version=="cff2" then
15260 dictionary.charset=nil
15261 else
15262 readencodings(f,data)
15263 readcharsets(f,data,dictionary)
15264 end
15265 if cid then
15266 local fdarray=cid.fdarray
15267 if fdarray then
15268 setposition(f,data.header.offset+fdarray)
15269 local dictionaries=readlengths(f,version=="cff2")
15270 local nofdictionaries=#dictionaries
15271 if nofdictionaries>0 then
15272 for i=1,nofdictionaries do
15273 dictionaries[i]=readstring(f,dictionaries[i])
15274 end
15275 parsedictionaries(data,dictionaries)
15276 dictionary.private=dictionaries[1].private
15277 if nofdictionaries>1 then
15278 report("ignoring dictionaries > 1 in cid font")
15279 end
15280 end
15281 end
15282 end
15283 readprivates(f,data)
15284 parseprivates(data,data.dictionaries)
15285 readlocals(f,data,dictionary,version)
15286 startparsing(fontdata,data,streams)
15287 parsecharstrings(fontdata,data,glyphs,doshapes,version,streams,false)
15288 stopparsing(fontdata,data)
15289 end
15290 local function readfdselect(f,fontdata,data,glyphs,doshapes,version,streams)
15291 local header=data.header
15292 local dictionaries=data.dictionaries
15293 local dictionary=dictionaries[1]
15294 local cid=dictionary.cid
15295 local cidselect=cid and cid.fdselect
15296 readglobals(f,data,version)
15297 readcharstrings(f,data,version)
15298 if version~="cff2" then
15299 readencodings(f,data)
15300 end
15301 local charstrings=dictionary.charstrings
15302 local fdindex={}
15303 local nofglyphs=data.nofglyphs
15304 local maxindex=-1
15305 setposition(f,header.offset+cidselect)
15306 local format=readbyte(f)
15307 if format==1 then
15308 for i=0,nofglyphs do
15309 local index=readbyte(f)
15310 fdindex[i]=index
15311 if index>maxindex then
15312 maxindex=index
15313 end
15314 end
15315 elseif format==3 then
15316 local nofranges=readushort(f)
15317 local first=readushort(f)
15318 local index=readbyte(f)
15319 while true do
15320 local last=readushort(f)
15321 if index>maxindex then
15322 maxindex=index
15323 end
15324 for i=first,last do
15325 fdindex[i]=index
15326 end
15327 if last>=nofglyphs then
15328 break
15329 else
15330 first=last+1
15331 index=readbyte(f)
15332 end
15333 end
15334 else
15335 report("unsupported fd index format %i",format)
15336 end
15337 if maxindex>=0 then
15338 local cidarray=cid.fdarray
15339 if cidarray then
15340 setposition(f,header.offset+cidarray)
15341 local dictionaries=readlengths(f,version=="cff2")
15342 if #dictionaries>0 then
15343 for i=1,#dictionaries do
15344 dictionaries[i]=readstring(f,dictionaries[i])
15345 end
15346 parsedictionaries(data,dictionaries)
15347 cid.dictionaries=dictionaries
15348 readcidprivates(f,data)
15349 for i=1,#dictionaries do
15350 readlocals(f,data,dictionaries[i],version)
15351 end
15352 startparsing(fontdata,data,streams)
15353 for i=1,#charstrings do
15354 local dictionary=dictionaries[fdindex[i]+1]
15355 if dictionary then
15356 parsecharstring(fontdata,data,dictionary,charstrings[i],glyphs,i,doshapes,version,streams)
15357 else
15358 end
15359 end
15360 stopparsing(fontdata,data)
15361 else
15362 report("no cid dictionaries")
15363 end
15364 else
15365 report("no cid array")
15366 end
15367 end
15368 end
15369 local gotodatatable=readers.helpers.gotodatatable
15370 local function cleanup(data,dictionaries)
15371 end
15372 function readers.cff(f,fontdata,specification)
15373 local tableoffset=gotodatatable(f,fontdata,"cff",specification.details or specification.glyphs)
15374 if tableoffset then
15375 local header=readheader(f)
15376 if header.major~=1 then
15377 report("only version %s is supported for table %a",1,"cff")
15378 return
15379 end
15380 local glyphs=fontdata.glyphs
15381 local names=readfontnames(f)
15382 local dictionaries=readtopdictionaries(f)
15383 local strings=readstrings(f)
15384 local data={
15385 header=header,
15386 names=names,
15387 dictionaries=dictionaries,
15388 strings=strings,
15389 nofglyphs=fontdata.nofglyphs,
15390 }
15391 parsedictionaries(data,dictionaries,"cff")
15392 local dic=dictionaries[1]
15393 local cid=dic.cid
15394 local cffinfo={
15395 familyname=dic.familyname,
15396 fullname=dic.fullname,
15397 boundingbox=dic.boundingbox,
15398 weight=dic.weight,
15399 italicangle=dic.italicangle,
15400 underlineposition=dic.underlineposition,
15401 underlinethickness=dic.underlinethickness,
15402 defaultwidth=dic.defaultwidthx,
15403 nominalwidth=dic.nominalwidthx,
15404 monospaced=dic.monospaced,
15405 }
15406 fontdata.cidinfo=cid and {
15407 registry=cid.registry,
15408 ordering=cid.ordering,
15409 supplement=cid.supplement,
15410 }
15411 fontdata.cffinfo=cffinfo
15412 local all=specification.shapes or specification.streams or false
15413 if specification.glyphs or all then
15414 if cid and cid.fdselect then
15415 readfdselect(f,fontdata,data,glyphs,all,"cff",specification.streams)
15416 else
15417 readnoselect(f,fontdata,data,glyphs,all,"cff",specification.streams)
15418 end
15419 end
15420 local private=dic.private
15421 if private then
15422 local data=private.data
15423 if type(data)=="table" then
15424 cffinfo.defaultwidth=data.defaultwidthx or cffinfo.defaultwidth
15425 cffinfo.nominalwidth=data.nominalwidthx or cffinfo.nominalwidth
15426 cffinfo.bluevalues=data.bluevalues
15427 cffinfo.otherblues=data.otherblues
15428 cffinfo.familyblues=data.familyblues
15429 cffinfo.familyotherblues=data.familyotherblues
15430 cffinfo.bluescale=data.bluescale
15431 cffinfo.blueshift=data.blueshift
15432 cffinfo.bluefuzz=data.bluefuzz
15433 cffinfo.stdhw=data.stdhw
15434 cffinfo.stdvw=data.stdvw
15435 cffinfo.stemsnaph=data.stemsnaph
15436 cffinfo.stemsnapv=data.stemsnapv
15437 end
15438 end
15439 cleanup(data,dictionaries)
15440 end
15441 end
15442 function readers.cff2(f,fontdata,specification)
15443 local tableoffset=gotodatatable(f,fontdata,"cff2",specification.glyphs)
15444 if tableoffset then
15445 local header=readheader(f)
15446 if header.major~=2 then
15447 report("only version %s is supported for table %a",2,"cff2")
15448 return
15449 end
15450 local glyphs=fontdata.glyphs
15451 local dictionaries={ readstring(f,header.dsize) }
15452 local data={
15453 header=header,
15454 dictionaries=dictionaries,
15455 nofglyphs=fontdata.nofglyphs,
15456 }
15457 parsedictionaries(data,dictionaries,"cff2")
15458 local offset=dictionaries[1].vstore
15459 if offset>0 then
15460 local storeoffset=dictionaries[1].vstore+data.header.offset+2
15461 local regions,deltas=readers.helpers.readvariationdata(f,storeoffset,factors)
15462 data.regions=regions
15463 data.deltas=deltas
15464 else
15465 data.regions={}
15466 data.deltas={}
15467 end
15468 data.factors=specification.factors
15469 local cid=data.dictionaries[1].cid
15470 local all=specification.shapes or specification.streams or false
15471 if cid and cid.fdselect then
15472 readfdselect(f,fontdata,data,glyphs,all,"cff2",specification.streams)
15473 else
15474 readnoselect(f,fontdata,data,glyphs,all,"cff2",specification.streams)
15475 end
15476 cleanup(data,dictionaries)
15477 end
15478 end
15479
15480 end -- closure
15481
15482 do -- begin closure to overcome local limits and interference
15483
15484 if not modules then modules={} end modules ['font-ttf']={
15485 version=1.001,
15486 optimize=true,
15487 comment="companion to font-ini.mkiv",
15488 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
15489 copyright="PRAGMA ADE / ConTeXt Development Team",
15490 license="see context related readme files"
15491 }
15492 local next,type,unpack=next,type,unpack
15493 local band,rshift=bit32.band,bit32.rshift
15494 local sqrt,round,abs,min,max=math.sqrt,math.round,math.abs,math.min,math.max
15495 local char,rep=string.char,string.rep
15496 local concat=table.concat
15497 local idiv=number.idiv
15498 local setmetatableindex=table.setmetatableindex
15499 local report=logs.reporter("otf reader","ttf")
15500 local trace_deltas=false
15501 local readers=fonts.handlers.otf.readers
15502 local streamreader=readers.streamreader
15503 local setposition=streamreader.setposition
15504 local getposition=streamreader.getposition
15505 local skipbytes=streamreader.skip
15506 local readbyte=streamreader.readcardinal1
15507 local readushort=streamreader.readcardinal2
15508 local readulong=streamreader.readcardinal4
15509 local readchar=streamreader.readinteger1
15510 local readshort=streamreader.readinteger2
15511 local read2dot14=streamreader.read2dot14
15512 local readinteger=streamreader.readinteger1
15513 local readcardinaltable=streamreader.readcardinaltable
15514 local readintegertable=streamreader.readintegertable
15515 directives.register("fonts.streamreader",function()
15516 streamreader=utilities.streams
15517 setposition=streamreader.setposition
15518 getposition=streamreader.getposition
15519 skipbytes=streamreader.skip
15520 readbyte=streamreader.readcardinal1
15521 readushort=streamreader.readcardinal2
15522 readulong=streamreader.readcardinal4
15523 readchar=streamreader.readinteger1
15524 readshort=streamreader.readinteger2
15525 read2dot14=streamreader.read2dot14
15526 readinteger=streamreader.readinteger1
15527 readcardinaltable=streamreader.readcardinaltable
15528 readintegertable=streamreader.readintegertable
15529 end)
15530 local short=2
15531 local ushort=2
15532 local ulong=4
15533 local helpers=readers.helpers
15534 local gotodatatable=helpers.gotodatatable
15535 local function mergecomposites(glyphs,shapes)
15536 local function merge(index,shape,components)
15537 local contours={}
15538 local points={}
15539 local nofcontours=0
15540 local nofpoints=0
15541 local offset=0
15542 local deltas=shape.deltas
15543 for i=1,#components do
15544 local component=components[i]
15545 local subindex=component.index
15546 local subshape=shapes[subindex]
15547 local subcontours=subshape.contours
15548 local subpoints=subshape.points
15549 if not subcontours then
15550 local subcomponents=subshape.components
15551 if subcomponents then
15552 subcontours,subpoints=merge(subindex,subshape,subcomponents)
15553 end
15554 end
15555 if subpoints then
15556 local matrix=component.matrix
15557 local xscale=matrix[1]
15558 local xrotate=matrix[2]
15559 local yrotate=matrix[3]
15560 local yscale=matrix[4]
15561 local xoffset=matrix[5]
15562 local yoffset=matrix[6]
15563 local count=#subpoints
15564 if xscale==1 and yscale==1 and xrotate==0 and yrotate==0 then
15565 for i=1,count do
15566 local p=subpoints[i]
15567 nofpoints=nofpoints+1
15568 points[nofpoints]={
15569 p[1]+xoffset,
15570 p[2]+yoffset,
15571 p[3]
15572 }
15573 end
15574 else
15575 for i=1,count do
15576 local p=subpoints[i]
15577 local x=p[1]
15578 local y=p[2]
15579 nofpoints=nofpoints+1
15580 points[nofpoints]={
15581 xscale*x+xrotate*y+xoffset,
15582 yscale*y+yrotate*x+yoffset,
15583 p[3]
15584 }
15585 end
15586 end
15587 local subcount=#subcontours
15588 if subcount==1 then
15589 nofcontours=nofcontours+1
15590 contours[nofcontours]=offset+subcontours[1]
15591 else
15592 for i=1,#subcontours do
15593 nofcontours=nofcontours+1
15594 contours[nofcontours]=offset+subcontours[i]
15595 end
15596 end
15597 offset=offset+count
15598 else
15599 report("missing contours composite %s, component %s of %s, glyph %s",index,i,#components,subindex)
15600 end
15601 end
15602 shape.points=points
15603 shape.contours=contours
15604 shape.components=nil
15605 return contours,points
15606 end
15607 for index=0,#glyphs do
15608 local shape=shapes[index]
15609 if shape then
15610 local components=shape.components
15611 if components then
15612 merge(index,shape,components)
15613 end
15614 end
15615 end
15616 end
15617 local function readnothing(f)
15618 return {
15619 type="nothing",
15620 }
15621 end
15622 local function curveto(m_x,m_y,l_x,l_y,r_x,r_y)
15623 return
15624 l_x+2/3*(m_x-l_x),l_y+2/3*(m_y-l_y),
15625 r_x+2/3*(m_x-r_x),r_y+2/3*(m_y-r_y),
15626 r_x,r_y,"c"
15627 end
15628 local xv={}
15629 local yv={}
15630 local function applyaxis(glyph,shape,deltas,dowidth)
15631 local points=shape.points
15632 if points then
15633 local nofpoints=#points
15634 local dw=0
15635 local dl=0
15636 for i=1,#deltas do
15637 local deltaset=deltas[i]
15638 local xvalues=deltaset.xvalues
15639 local yvalues=deltaset.yvalues
15640 if xvalues and yvalues then
15641 local dpoints=deltaset.points
15642 local factor=deltaset.factor
15643 if dpoints then
15644 local cnt=#dpoints
15645 if dowidth then
15646 cnt=cnt-4
15647 end
15648 if cnt>0 then
15649 local contours=shape.contours
15650 local nofcontours=#contours
15651 local first=1
15652 local firstindex=1
15653 for contour=1,nofcontours do
15654 local last=contours[contour]
15655 if last>=first then
15656 local lastindex=cnt
15657 if firstindex<cnt then
15658 for currentindex=firstindex,cnt do
15659 local found=dpoints[currentindex]
15660 if found<=first then
15661 firstindex=currentindex
15662 end
15663 if found==last then
15664 lastindex=currentindex
15665 break
15666 elseif found>last then
15667 while lastindex>1 and dpoints[lastindex]>last do
15668 lastindex=lastindex-1
15669 end
15670 break
15671 end
15672 end
15673 end
15674 local function find(i)
15675 local prv=lastindex
15676 for j=firstindex,lastindex do
15677 local nxt=dpoints[j]
15678 if nxt==i then
15679 return false,j,false
15680 elseif nxt>i then
15681 return prv,false,j
15682 end
15683 prv=j
15684 end
15685 return prv,false,firstindex
15686 end
15687 for point=first,last do
15688 local d1,d2,d3=find(point)
15689 local p2=points[point]
15690 if d2 then
15691 xv[point]=xvalues[d2]
15692 yv[point]=yvalues[d2]
15693 else
15694 local n1=dpoints[d1]
15695 local n3=dpoints[d3]
15696 if n1>nofpoints then
15697 n1=nofpoints
15698 end
15699 if n3>nofpoints then
15700 n3=nofpoints
15701 end
15702 local p1=points[n1]
15703 local p3=points[n3]
15704 local p1x=p1[1]
15705 local p2x=p2[1]
15706 local p3x=p3[1]
15707 local p1y=p1[2]
15708 local p2y=p2[2]
15709 local p3y=p3[2]
15710 local x1=xvalues[d1]
15711 local y1=yvalues[d1]
15712 local x3=xvalues[d3]
15713 local y3=yvalues[d3]
15714 local fx
15715 local fy
15716 if p1x==p3x then
15717 if x1==x3 then
15718 fx=x1
15719 else
15720 fx=0
15721 end
15722 elseif p2x<=min(p1x,p3x) then
15723 if p1x<p3x then
15724 fx=x1
15725 else
15726 fx=x3
15727 end
15728 elseif p2x>=max(p1x,p3x) then
15729 if p1x>p3x then
15730 fx=x1
15731 else
15732 fx=x3
15733 end
15734 else
15735 fx=(p2x-p1x)/(p3x-p1x)
15736 fx=(1-fx)*x1+fx*x3
15737 end
15738 if p1y==p3y then
15739 if y1==y3 then
15740 fy=y1
15741 else
15742 fy=0
15743 end
15744 elseif p2y<=min(p1y,p3y) then
15745 if p1y<p3y then
15746 fy=y1
15747 else
15748 fy=y3
15749 end
15750 elseif p2y>=max(p1y,p3y) then
15751 if p1y>p3y then
15752 fy=y1
15753 else
15754 fy=y3
15755 end
15756 else
15757 fy=(p2y-p1y)/(p3y-p1y)
15758 fy=(1-fy)*y1+fy*y3
15759 end
15760 xv[point]=fx
15761 yv[point]=fy
15762 end
15763 end
15764 if lastindex<cnt then
15765 firstindex=lastindex+1
15766 end
15767 end
15768 first=last+1
15769 end
15770 for i=1,nofpoints do
15771 local pi=points[i]
15772 local fx=xv[i]
15773 local fy=yv[i]
15774 if fx~=0 then
15775 pi[1]=pi[1]+factor*fx
15776 end
15777 if fy~=0 then
15778 pi[2]=pi[2]+factor*fy
15779 end
15780 end
15781 else
15782 report("bad deltapoint data, maybe a missing hvar table")
15783 end
15784 else
15785 for i=1,nofpoints do
15786 local p=points[i]
15787 local x=xvalues[i]
15788 if x then
15789 local y=yvalues[i]
15790 if x~=0 then
15791 p[1]=p[1]+factor*x
15792 end
15793 if y~=0 then
15794 p[2]=p[2]+factor*y
15795 end
15796 else
15797 break
15798 end
15799 end
15800 end
15801 if dowidth then
15802 local h=nofpoints+2
15803 local l=nofpoints+1
15804 local x=xvalues[h]
15805 if x then
15806 dw=dw+factor*x
15807 end
15808 local x=xvalues[l]
15809 if x then
15810 dl=dl+factor*x
15811 end
15812 end
15813 end
15814 end
15815 if dowidth then
15816 local width=glyph.width or 0
15817 glyph.width=width+dw-dl
15818 end
15819 else
15820 report("no points for glyph %a",glyph.name)
15821 end
15822 end
15823 local quadratic=false
15824 local function contours2outlines_normal(glyphs,shapes)
15825 for index=0,#glyphs-1 do
15826 local shape=shapes[index]
15827 if shape then
15828 local glyph=glyphs[index]
15829 local contours=shape.contours
15830 local points=shape.points
15831 if contours then
15832 local nofcontours=#contours
15833 local segments={}
15834 local nofsegments=0
15835 glyph.segments=segments
15836 if nofcontours>0 then
15837 local px=0
15838 local py=0
15839 local first=1
15840 for i=1,nofcontours do
15841 local last=contours[i]
15842 if last>=first then
15843 local first_pt=points[first]
15844 local first_on=first_pt[3]
15845 if first==last then
15846 first_pt[3]="m"
15847 nofsegments=nofsegments+1
15848 segments[nofsegments]=first_pt
15849 else
15850 local first_on=first_pt[3]
15851 local last_pt=points[last]
15852 local last_on=last_pt[3]
15853 local start=1
15854 local control_pt=false
15855 if first_on then
15856 start=2
15857 else
15858 if last_on then
15859 first_pt=last_pt
15860 else
15861 first_pt={ (first_pt[1]+last_pt[1])/2,(first_pt[2]+last_pt[2])/2,false }
15862 end
15863 control_pt=first_pt
15864 end
15865 local x=first_pt[1]
15866 local y=first_pt[2]
15867 if not done then
15868 xmin=x
15869 ymin=y
15870 xmax=x
15871 ymax=y
15872 done=true
15873 end
15874 nofsegments=nofsegments+1
15875 segments[nofsegments]={ x,y,"m" }
15876 if not quadratic then
15877 px=x
15878 py=y
15879 end
15880 local previous_pt=first_pt
15881 for i=first,last do
15882 local current_pt=points[i]
15883 local current_on=current_pt[3]
15884 local previous_on=previous_pt[3]
15885 if previous_on then
15886 if current_on then
15887 local x,y=current_pt[1],current_pt[2]
15888 nofsegments=nofsegments+1
15889 segments[nofsegments]={ x,y,"l" }
15890 if not quadratic then
15891 px,py=x,y
15892 end
15893 else
15894 control_pt=current_pt
15895 end
15896 elseif current_on then
15897 local x1=control_pt[1]
15898 local y1=control_pt[2]
15899 local x2=current_pt[1]
15900 local y2=current_pt[2]
15901 nofsegments=nofsegments+1
15902 if quadratic then
15903 segments[nofsegments]={ x1,y1,x2,y2,"q" }
15904 else
15905 x1,y1,x2,y2,px,py=curveto(x1,y1,px,py,x2,y2)
15906 segments[nofsegments]={ x1,y1,x2,y2,px,py,"c" }
15907 end
15908 control_pt=false
15909 else
15910 local x2=(previous_pt[1]+current_pt[1])/2
15911 local y2=(previous_pt[2]+current_pt[2])/2
15912 local x1=control_pt[1]
15913 local y1=control_pt[2]
15914 nofsegments=nofsegments+1
15915 if quadratic then
15916 segments[nofsegments]={ x1,y1,x2,y2,"q" }
15917 else
15918 x1,y1,x2,y2,px,py=curveto(x1,y1,px,py,x2,y2)
15919 segments[nofsegments]={ x1,y1,x2,y2,px,py,"c" }
15920 end
15921 control_pt=current_pt
15922 end
15923 previous_pt=current_pt
15924 end
15925 if first_pt==last_pt then
15926 else
15927 nofsegments=nofsegments+1
15928 local x2=first_pt[1]
15929 local y2=first_pt[2]
15930 if not control_pt then
15931 segments[nofsegments]={ x2,y2,"l" }
15932 elseif quadratic then
15933 local x1=control_pt[1]
15934 local y1=control_pt[2]
15935 segments[nofsegments]={ x1,y1,x2,y2,"q" }
15936 else
15937 local x1=control_pt[1]
15938 local y1=control_pt[2]
15939 x1,y1,x2,y2,px,py=curveto(x1,y1,px,py,x2,y2)
15940 segments[nofsegments]={ x1,y1,x2,y2,px,py,"c" }
15941 end
15942 end
15943 end
15944 end
15945 first=last+1
15946 end
15947 end
15948 end
15949 end
15950 end
15951 end
15952 local function contours2outlines_shaped(glyphs,shapes,keepcurve)
15953 for index=0,#glyphs-1 do
15954 local shape=shapes[index]
15955 if shape then
15956 local glyph=glyphs[index]
15957 local contours=shape.contours
15958 local points=shape.points
15959 if contours then
15960 local nofcontours=#contours
15961 local segments=keepcurve and {} or nil
15962 local nofsegments=0
15963 if keepcurve then
15964 glyph.segments=segments
15965 end
15966 if nofcontours>0 then
15967 local xmin,ymin,xmax,ymax,done=0,0,0,0,false
15968 local px,py=0,0
15969 local first=1
15970 for i=1,nofcontours do
15971 local last=contours[i]
15972 if last>=first then
15973 local first_pt=points[first]
15974 local first_on=first_pt[3]
15975 if first==last then
15976 if keepcurve then
15977 first_pt[3]="m"
15978 nofsegments=nofsegments+1
15979 segments[nofsegments]=first_pt
15980 end
15981 else
15982 local first_on=first_pt[3]
15983 local last_pt=points[last]
15984 local last_on=last_pt[3]
15985 local start=1
15986 local control_pt=false
15987 if first_on then
15988 start=2
15989 else
15990 if last_on then
15991 first_pt=last_pt
15992 else
15993 first_pt={ (first_pt[1]+last_pt[1])/2,(first_pt[2]+last_pt[2])/2,false }
15994 end
15995 control_pt=first_pt
15996 end
15997 local x=first_pt[1]
15998 local y=first_pt[2]
15999 if not done then
16000 xmin,ymin,xmax,ymax=x,y,x,y
16001 done=true
16002 else
16003 if x<xmin then xmin=x elseif x>xmax then xmax=x end
16004 if y<ymin then ymin=y elseif y>ymax then ymax=y end
16005 end
16006 if keepcurve then
16007 nofsegments=nofsegments+1
16008 segments[nofsegments]={ x,y,"m" }
16009 end
16010 if not quadratic then
16011 px=x
16012 py=y
16013 end
16014 local previous_pt=first_pt
16015 for i=first,last do
16016 local current_pt=points[i]
16017 local current_on=current_pt[3]
16018 local previous_on=previous_pt[3]
16019 if previous_on then
16020 if current_on then
16021 local x=current_pt[1]
16022 local y=current_pt[2]
16023 if x<xmin then xmin=x elseif x>xmax then xmax=x end
16024 if y<ymin then ymin=y elseif y>ymax then ymax=y end
16025 if keepcurve then
16026 nofsegments=nofsegments+1
16027 segments[nofsegments]={ x,y,"l" }
16028 end
16029 if not quadratic then
16030 px=x
16031 py=y
16032 end
16033 else
16034 control_pt=current_pt
16035 end
16036 elseif current_on then
16037 local x1=control_pt[1]
16038 local y1=control_pt[2]
16039 local x2=current_pt[1]
16040 local y2=current_pt[2]
16041 if quadratic then
16042 if x1<xmin then xmin=x1 elseif x1>xmax then xmax=x1 end
16043 if y1<ymin then ymin=y1 elseif y1>ymax then ymax=y1 end
16044 if keepcurve then
16045 nofsegments=nofsegments+1
16046 segments[nofsegments]={ x1,y1,x2,y2,"q" }
16047 end
16048 else
16049 x1,y1,x2,y2,px,py=curveto(x1,y1,px,py,x2,y2)
16050 if x1<xmin then xmin=x1 elseif x1>xmax then xmax=x1 end
16051 if y1<ymin then ymin=y1 elseif y1>ymax then ymax=y1 end
16052 if x2<xmin then xmin=x2 elseif x2>xmax then xmax=x2 end
16053 if y2<ymin then ymin=y2 elseif y2>ymax then ymax=y2 end
16054 if px<xmin then xmin=px elseif px>xmax then xmax=px end
16055 if py<ymin then ymin=py elseif py>ymax then ymax=py end
16056 if keepcurve then
16057 nofsegments=nofsegments+1
16058 segments[nofsegments]={ x1,y1,x2,y2,px,py,"c" }
16059 end
16060 end
16061 control_pt=false
16062 else
16063 local x2=(previous_pt[1]+current_pt[1])/2
16064 local y2=(previous_pt[2]+current_pt[2])/2
16065 local x1=control_pt[1]
16066 local y1=control_pt[2]
16067 if quadratic then
16068 if x1<xmin then xmin=x1 elseif x1>xmax then xmax=x1 end
16069 if y1<ymin then ymin=y1 elseif y1>ymax then ymax=y1 end
16070 if keepcurve then
16071 nofsegments=nofsegments+1
16072 segments[nofsegments]={ x1,y1,x2,y2,"q" }
16073 end
16074 else
16075 x1,y1,x2,y2,px,py=curveto(x1,y1,px,py,x2,y2)
16076 if x1<xmin then xmin=x1 elseif x1>xmax then xmax=x1 end
16077 if y1<ymin then ymin=y1 elseif y1>ymax then ymax=y1 end
16078 if x2<xmin then xmin=x2 elseif x2>xmax then xmax=x2 end
16079 if y2<ymin then ymin=y2 elseif y2>ymax then ymax=y2 end
16080 if px<xmin then xmin=px elseif px>xmax then xmax=px end
16081 if py<ymin then ymin=py elseif py>ymax then ymax=py end
16082 if keepcurve then
16083 nofsegments=nofsegments+1
16084 segments[nofsegments]={ x1,y1,x2,y2,px,py,"c" }
16085 end
16086 end
16087 control_pt=current_pt
16088 end
16089 previous_pt=current_pt
16090 end
16091 if first_pt==last_pt then
16092 elseif not control_pt then
16093 if keepcurve then
16094 nofsegments=nofsegments+1
16095 segments[nofsegments]={ first_pt[1],first_pt[2],"l" }
16096 end
16097 else
16098 local x1=control_pt[1]
16099 local y1=control_pt[2]
16100 local x2=first_pt[1]
16101 local y2=first_pt[2]
16102 if x1<xmin then xmin=x1 elseif x1>xmax then xmax=x1 end
16103 if y1<ymin then ymin=y1 elseif y1>ymax then ymax=y1 end
16104 if quadratic then
16105 if keepcurve then
16106 nofsegments=nofsegments+1
16107 segments[nofsegments]={ x1,y1,x2,y2,"q" }
16108 end
16109 else
16110 x1,y1,x2,y2,px,py=curveto(x1,y1,px,py,x2,y2)
16111 if x2<xmin then xmin=x2 elseif x2>xmax then xmax=x2 end
16112 if y2<ymin then ymin=y2 elseif y2>ymax then ymax=y2 end
16113 if px<xmin then xmin=px elseif px>xmax then xmax=px end
16114 if py<ymin then ymin=py elseif py>ymax then ymax=py end
16115 if keepcurve then
16116 nofsegments=nofsegments+1
16117 segments[nofsegments]={ x1,y1,x2,y2,px,py,"c" }
16118 end
16119 end
16120 end
16121 end
16122 end
16123 first=last+1
16124 end
16125 xmin=glyph.boundingbox[1]
16126 local dlsb=glyph.dlsb
16127 if dlsb then
16128 xmin=xmin+dlsb
16129 glyph.dlsb=nil
16130 end
16131 glyph.boundingbox={ round(xmin),round(ymin),round(xmax),round(ymax) }
16132 end
16133 end
16134 end
16135 end
16136 end
16137 local c_zero=char(0)
16138 local s_zero=char(0,0)
16139 local function toushort(n)
16140 return char(band(rshift(n,8),0xFF),band(n,0xFF))
16141 end
16142 local function toshort(n)
16143 if n<0 then
16144 n=n+0x10000
16145 end
16146 return char(band(rshift(n,8),0xFF),band(n,0xFF))
16147 end
16148 local chars=setmetatableindex(function(t,k)
16149 for i=0,255 do local v=char(i) t[i]=v end return t[k]
16150 end)
16151 local function repackpoints(glyphs,shapes)
16152 local noboundingbox={ 0,0,0,0 }
16153 local result={}
16154 local xpoints={}
16155 local ypoints={}
16156 for index=0,#glyphs do
16157 local shape=shapes[index]
16158 if shape then
16159 local r=0
16160 local glyph=glyphs[index]
16161 local contours=shape.contours
16162 local nofcontours=contours and #contours or 0
16163 local boundingbox=glyph.boundingbox or noboundingbox
16164 r=r+1 result[r]=toshort(nofcontours)
16165 r=r+1 result[r]=toshort(boundingbox[1])
16166 r=r+1 result[r]=toshort(boundingbox[2])
16167 r=r+1 result[r]=toshort(boundingbox[3])
16168 r=r+1 result[r]=toshort(boundingbox[4])
16169 if nofcontours>0 then
16170 for i=1,nofcontours do
16171 r=r+1 result[r]=toshort(contours[i]-1)
16172 end
16173 r=r+1 result[r]=s_zero
16174 local points=shape.points
16175 local currentx=0
16176 local currenty=0
16177 local x=0
16178 local y=0
16179 local lastflag=nil
16180 local nofflags=0
16181 for i=1,#points do
16182 local pt=points[i]
16183 local px=pt[1]
16184 local py=pt[2]
16185 local fl=pt[3] and 0x01 or 0x00
16186 if px==currentx then
16187 fl=fl+0x10
16188 else
16189 local dx=round(px-currentx)
16190 x=x+1
16191 if dx<-255 or dx>255 then
16192 xpoints[x]=toshort(dx)
16193 elseif dx<0 then
16194 fl=fl+0x02
16195 xpoints[x]=chars[-dx]
16196 elseif dx>0 then
16197 fl=fl+0x12
16198 xpoints[x]=chars[dx]
16199 else
16200 fl=fl+0x02
16201 xpoints[x]=c_zero
16202 end
16203 end
16204 if py==currenty then
16205 fl=fl+0x20
16206 else
16207 local dy=round(py-currenty)
16208 y=y+1
16209 if dy<-255 or dy>255 then
16210 ypoints[y]=toshort(dy)
16211 elseif dy<0 then
16212 fl=fl+0x04
16213 ypoints[y]=chars[-dy]
16214 elseif dy>0 then
16215 fl=fl+0x24
16216 ypoints[y]=chars[dy]
16217 else
16218 fl=fl+0x04
16219 ypoints[y]=c_zero
16220 end
16221 end
16222 currentx=px
16223 currenty=py
16224 if lastflag==fl then
16225 if nofflags==255 then
16226 lastflag=lastflag+0x08
16227 r=r+1 result[r]=char(lastflag,nofflags-1)
16228 nofflags=1
16229 lastflag=fl
16230 else
16231 nofflags=nofflags+1
16232 end
16233 else
16234 if nofflags==1 then
16235 r=r+1 result[r]=chars[lastflag]
16236 elseif nofflags==2 then
16237 r=r+1 result[r]=char(lastflag,lastflag)
16238 elseif nofflags>2 then
16239 lastflag=lastflag+0x08
16240 r=r+1 result[r]=char(lastflag,nofflags-1)
16241 end
16242 nofflags=1
16243 lastflag=fl
16244 end
16245 end
16246 if nofflags==1 then
16247 r=r+1 result[r]=chars[lastflag]
16248 elseif nofflags==2 then
16249 r=r+1 result[r]=char(lastflag,lastflag)
16250 elseif nofflags>2 then
16251 lastflag=lastflag+0x08
16252 r=r+1 result[r]=char(lastflag,nofflags-1)
16253 end
16254 r=r+1 result[r]=concat(xpoints,"",1,x)
16255 r=r+1 result[r]=concat(ypoints,"",1,y)
16256 end
16257 local stream=concat(result,"",1,r)
16258 local length=#stream
16259 local padding=idiv(length+3,4)*4-length
16260 if padding>0 then
16261 if padding==1 then
16262 padding="\0"
16263 elseif padding==2 then
16264 padding="\0\0"
16265 else
16266 padding="\0\0\0"
16267 end
16268 padding=stream..padding
16269 end
16270 glyph.stream=stream
16271 end
16272 end
16273 end
16274 local flags={}
16275 local function readglyph(f,nofcontours)
16276 local points={}
16277 local contours={}
16278 for i=1,nofcontours do
16279 contours[i]=readshort(f)+1
16280 end
16281 local nofpoints=contours[nofcontours]
16282 local nofinstructions=readushort(f)
16283 skipbytes(f,nofinstructions)
16284 local i=1
16285 while i<=nofpoints do
16286 local flag=readbyte(f)
16287 flags[i]=flag
16288 if band(flag,0x08)~=0 then
16289 local n=readbyte(f)
16290 if n==1 then
16291 i=i+1
16292 flags[i]=flag
16293 else
16294 for j=1,n do
16295 i=i+1
16296 flags[i]=flag
16297 end
16298 end
16299 end
16300 i=i+1
16301 end
16302 local x=0
16303 for i=1,nofpoints do
16304 local flag=flags[i]
16305 if band(flag,0x02)~=0 then
16306 if band(flag,0x10)~=0 then
16307 x=x+readbyte(f)
16308 else
16309 x=x-readbyte(f)
16310 end
16311 elseif band(flag,0x10)~=0 then
16312 else
16313 x=x+readshort(f)
16314 end
16315 points[i]={ x,0,band(flag,0x01)~=0 }
16316 end
16317 local y=0
16318 for i=1,nofpoints do
16319 local flag=flags[i]
16320 if band(flag,0x04)~=0 then
16321 if band(flag,0x20)~=0 then
16322 y=y+readbyte(f)
16323 else
16324 y=y-readbyte(f)
16325 end
16326 elseif band(flag,0x20)~=0 then
16327 else
16328 y=y+readshort(f)
16329 end
16330 points[i][2]=y
16331 end
16332 return {
16333 type="glyph",
16334 points=points,
16335 contours=contours,
16336 nofpoints=nofpoints,
16337 }
16338 end
16339 local function readcomposite(f)
16340 local components={}
16341 local nofcomponents=0
16342 local instructions=false
16343 while true do
16344 local flags=readushort(f)
16345 local index=readushort(f)
16346 local f_xyarg=band(flags,0x0002)~=0
16347 local f_offset=band(flags,0x0800)~=0
16348 local xscale=1
16349 local xrotate=0
16350 local yrotate=0
16351 local yscale=1
16352 local xoffset=0
16353 local yoffset=0
16354 local base=false
16355 local reference=false
16356 if f_xyarg then
16357 if band(flags,0x0001)~=0 then
16358 xoffset=readshort(f)
16359 yoffset=readshort(f)
16360 else
16361 xoffset=readchar(f)
16362 yoffset=readchar(f)
16363 end
16364 else
16365 if band(flags,0x0001)~=0 then
16366 base=readshort(f)
16367 reference=readshort(f)
16368 else
16369 base=readchar(f)
16370 reference=readchar(f)
16371 end
16372 end
16373 if band(flags,0x0008)~=0 then
16374 xscale=read2dot14(f)
16375 yscale=xscale
16376 if f_xyarg and f_offset then
16377 xoffset=xoffset*xscale
16378 yoffset=yoffset*yscale
16379 end
16380 elseif band(flags,0x0040)~=0 then
16381 xscale=read2dot14(f)
16382 yscale=read2dot14(f)
16383 if f_xyarg and f_offset then
16384 xoffset=xoffset*xscale
16385 yoffset=yoffset*yscale
16386 end
16387 elseif band(flags,0x0080)~=0 then
16388 xscale=read2dot14(f)
16389 xrotate=read2dot14(f)
16390 yrotate=read2dot14(f)
16391 yscale=read2dot14(f)
16392 if f_xyarg and f_offset then
16393 xoffset=xoffset*sqrt(xscale^2+yrotate^2)
16394 yoffset=yoffset*sqrt(xrotate^2+yscale^2)
16395 end
16396 end
16397 nofcomponents=nofcomponents+1
16398 components[nofcomponents]={
16399 index=index,
16400 usemine=band(flags,0x0200)~=0,
16401 round=band(flags,0x0006)~=0,
16402 base=base,
16403 reference=reference,
16404 matrix={ xscale,xrotate,yrotate,yscale,xoffset,yoffset },
16405 }
16406 if band(flags,0x0100)~=0 then
16407 instructions=true
16408 end
16409 if band(flags,0x0020)==0 then
16410 break
16411 end
16412 end
16413 return {
16414 type="composite",
16415 components=components,
16416 }
16417 end
16418 function readers.loca(f,fontdata,specification)
16419 if specification.glyphs then
16420 local datatable=fontdata.tables.loca
16421 if datatable then
16422 local offset=fontdata.tables.glyf.offset
16423 local format=fontdata.fontheader.indextolocformat
16424 local profile=fontdata.maximumprofile
16425 local nofglyphs=profile and profile.nofglyphs
16426 local locations={}
16427 setposition(f,datatable.offset)
16428 if format==1 then
16429 if not nofglyphs then
16430 nofglyphs=idiv(datatable.length,4)-1
16431 end
16432 for i=0,nofglyphs do
16433 locations[i]=offset+readulong(f)
16434 end
16435 fontdata.nofglyphs=nofglyphs
16436 else
16437 if not nofglyphs then
16438 nofglyphs=idiv(datatable.length,2)-1
16439 end
16440 for i=0,nofglyphs do
16441 locations[i]=offset+readushort(f)*2
16442 end
16443 end
16444 fontdata.nofglyphs=nofglyphs
16445 fontdata.locations=locations
16446 end
16447 end
16448 end
16449 function readers.glyf(f,fontdata,specification)
16450 local tableoffset=gotodatatable(f,fontdata,"glyf",specification.glyphs)
16451 if tableoffset then
16452 local locations=fontdata.locations
16453 if locations then
16454 local glyphs=fontdata.glyphs
16455 local nofglyphs=fontdata.nofglyphs
16456 local filesize=fontdata.filesize
16457 local nothing={ 0,0,0,0 }
16458 local shapes={}
16459 local loadshapes=specification.shapes or specification.instance or specification.streams
16460 for index=0,nofglyphs-1 do
16461 local location=locations[index]
16462 local length=locations[index+1]-location
16463 if location>=filesize then
16464 report("discarding %s glyphs due to glyph location bug",nofglyphs-index+1)
16465 fontdata.nofglyphs=index-1
16466 fontdata.badfont=true
16467 break
16468 elseif length>0 then
16469 setposition(f,location)
16470 local nofcontours=readshort(f)
16471 glyphs[index].boundingbox={
16472 readshort(f),
16473 readshort(f),
16474 readshort(f),
16475 readshort(f),
16476 }
16477 if not loadshapes then
16478 elseif nofcontours==0 then
16479 shapes[index]=readnothing(f)
16480 elseif nofcontours>0 then
16481 shapes[index]=readglyph(f,nofcontours)
16482 else
16483 shapes[index]=readcomposite(f,nofcontours)
16484 end
16485 else
16486 if loadshapes then
16487 shapes[index]=readnothing(f)
16488 end
16489 glyphs[index].boundingbox=nothing
16490 end
16491 end
16492 if loadshapes then
16493 if readers.gvar then
16494 readers.gvar(f,fontdata,specification,glyphs,shapes)
16495 end
16496 mergecomposites(glyphs,shapes)
16497 if specification.instance then
16498 if specification.streams then
16499 repackpoints(glyphs,shapes)
16500 else
16501 contours2outlines_shaped(glyphs,shapes,specification.shapes)
16502 end
16503 elseif specification.shapes then
16504 if specification.streams then
16505 repackpoints(glyphs,shapes)
16506 else
16507 contours2outlines_normal(glyphs,shapes)
16508 end
16509 elseif specification.streams then
16510 repackpoints(glyphs,shapes)
16511 end
16512 end
16513 end
16514 end
16515 end
16516 local function readtuplerecord(f,nofaxis)
16517 local record={}
16518 for i=1,nofaxis do
16519 record[i]=read2dot14(f)
16520 end
16521 return record
16522 end
16523 local function readpoints(f)
16524 local count=readbyte(f)
16525 if count==0 then
16526 return nil,0
16527 else
16528 if count<128 then
16529 elseif band(count,0x80)~=0 then
16530 count=band(count,0x7F)*256+readbyte(f)
16531 else
16532 end
16533 local points={}
16534 local p=0
16535 local n=1
16536 while p<count do
16537 local control=readbyte(f)
16538 local runreader=band(control,0x80)~=0 and readushort or readbyte
16539 local runlength=band(control,0x7F)
16540 for i=1,runlength+1 do
16541 n=n+runreader(f)
16542 p=p+1
16543 points[p]=n
16544 end
16545 end
16546 return points,p
16547 end
16548 end
16549 local function readdeltas(f,nofpoints)
16550 local deltas={}
16551 local p=0
16552 while nofpoints>0 do
16553 local control=readbyte(f)
16554 if control then
16555 local allzero=band(control,0x80)~=0
16556 local runlength=band(control,0x3F)+1
16557 if allzero then
16558 for i=1,runlength do
16559 p=p+1
16560 deltas[p]=0
16561 end
16562 else
16563 local runreader=band(control,0x40)~=0 and readshort or readinteger
16564 for i=1,runlength do
16565 p=p+1
16566 deltas[p]=runreader(f)
16567 end
16568 end
16569 nofpoints=nofpoints-runlength
16570 else
16571 break
16572 end
16573 end
16574 if p>0 then
16575 return deltas
16576 else
16577 end
16578 end
16579 function readers.gvar(f,fontdata,specification,glyphdata,shapedata)
16580 local instance=specification.instance
16581 if not instance then
16582 return
16583 end
16584 local factors=specification.factors
16585 if not factors then
16586 return
16587 end
16588 local tableoffset=gotodatatable(f,fontdata,"gvar",specification.variable or specification.shapes)
16589 if tableoffset then
16590 local version=readulong(f)
16591 local nofaxis=readushort(f)
16592 local noftuples=readushort(f)
16593 local tupleoffset=tableoffset+readulong(f)
16594 local nofglyphs=readushort(f)
16595 local flags=readushort(f)
16596 local dataoffset=tableoffset+readulong(f)
16597 local data={}
16598 local tuples={}
16599 local glyphdata=fontdata.glyphs
16600 local dowidth=not fontdata.variabledata.hvarwidths
16601 if band(flags,0x0001)~=0 then
16602 for i=1,nofglyphs+1 do
16603 data[i]=dataoffset+readulong(f)
16604 end
16605 else
16606 for i=1,nofglyphs+1 do
16607 data[i]=dataoffset+2*readushort(f)
16608 end
16609 end
16610 if noftuples>0 then
16611 setposition(f,tupleoffset)
16612 for i=1,noftuples do
16613 tuples[i]=readtuplerecord(f,nofaxis)
16614 end
16615 end
16616 local nextoffset=false
16617 local startoffset=data[1]
16618 for i=1,nofglyphs do
16619 nextoffset=data[i+1]
16620 local glyph=glyphdata[i-1]
16621 local name=trace_deltas and glyph.name
16622 if startoffset==nextoffset then
16623 if name then
16624 report("no deltas for glyph %a",name)
16625 end
16626 else
16627 local shape=shapedata[i-1]
16628 if not shape then
16629 if name then
16630 report("no shape for glyph %a",name)
16631 end
16632 else
16633 lastoffset=startoffset
16634 setposition(f,startoffset)
16635 local flags=readushort(f)
16636 local count=band(flags,0x0FFF)
16637 local offset=startoffset+readushort(f)
16638 local deltas={}
16639 local allpoints=(shape.nofpoints or 0)
16640 local shared=false
16641 local nofshared=0
16642 if band(flags,0x8000)~=0 then
16643 local current=getposition(f)
16644 setposition(f,offset)
16645 shared,nofshared=readpoints(f)
16646 offset=getposition(f)
16647 setposition(f,current)
16648 end
16649 for j=1,count do
16650 local size=readushort(f)
16651 local flags=readushort(f)
16652 local index=band(flags,0x0FFF)
16653 local haspeak=band(flags,0x8000)~=0
16654 local intermediate=band(flags,0x4000)~=0
16655 local private=band(flags,0x2000)~=0
16656 local peak=nil
16657 local start=nil
16658 local stop=nil
16659 local xvalues=nil
16660 local yvalues=nil
16661 local points=shared
16662 local nofpoints=nofshared
16663 if haspeak then
16664 peak=readtuplerecord(f,nofaxis)
16665 else
16666 if index+1>#tuples then
16667 report("error, bad tuple index",index)
16668 end
16669 peak=tuples[index+1]
16670 end
16671 if intermediate then
16672 start=readtuplerecord(f,nofaxis)
16673 stop=readtuplerecord(f,nofaxis)
16674 end
16675 if size>0 then
16676 local current=getposition(f)
16677 setposition(f,offset)
16678 if private then
16679 points,nofpoints=readpoints(f)
16680 end
16681 if nofpoints==0 then
16682 nofpoints=allpoints+4
16683 end
16684 if nofpoints>0 then
16685 xvalues=readdeltas(f,nofpoints)
16686 yvalues=readdeltas(f,nofpoints)
16687 end
16688 offset=offset+size
16689 setposition(f,current)
16690 end
16691 if not xvalues and not yvalues then
16692 points=nil
16693 end
16694 local s=1
16695 for i=1,nofaxis do
16696 local f=factors[i]
16697 local peak=peak and peak [i] or 0
16698 local start=start and start[i] or (peak<0 and peak or 0)
16699 local stop=stop and stop [i] or (peak>0 and peak or 0)
16700 if start>peak or peak>stop then
16701 elseif start<0 and stop>0 and peak~=0 then
16702 elseif peak==0 then
16703 elseif f<start or f>stop then
16704 s=0
16705 break
16706 elseif f<peak then
16707 s=s*(f-start)/(peak-start)
16708 elseif f>peak then
16709 s=s*(stop-f)/(stop-peak)
16710 else
16711 end
16712 end
16713 if s==0 then
16714 if name then
16715 report("no deltas applied for glyph %a",name)
16716 end
16717 else
16718 deltas[#deltas+1]={
16719 factor=s,
16720 points=points,
16721 xvalues=xvalues,
16722 yvalues=yvalues,
16723 }
16724 end
16725 end
16726 if shape.type=="glyph" then
16727 applyaxis(glyph,shape,deltas,dowidth)
16728 else
16729 shape.deltas=deltas
16730 end
16731 end
16732 end
16733 startoffset=nextoffset
16734 end
16735 end
16736 end
16737
16738 end -- closure
16739
16740 do -- begin closure to overcome local limits and interference
16741
16742 if not modules then modules={} end modules ['font-dsp']={
16743 version=1.001,
16744 optimize=true,
16745 comment="companion to font-ini.mkiv",
16746 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
16747 copyright="PRAGMA ADE / ConTeXt Development Team",
16748 license="see context related readme files"
16749 }
16750 local next,type,tonumber=next,type,tonumber
16751 local band=bit32.band
16752 local extract=bit32.extract
16753 local bor=bit32.bor
16754 local lshift=bit32.lshift
16755 local rshift=bit32.rshift
16756 local gsub=string.gsub
16757 local lower=string.lower
16758 local sub=string.sub
16759 local strip=string.strip
16760 local tohash=table.tohash
16761 local concat=table.concat
16762 local copy=table.copy
16763 local reversed=table.reversed
16764 local sort=table.sort
16765 local insert=table.insert
16766 local round=math.round
16767 local settings_to_hash=utilities.parsers.settings_to_hash_colon_too
16768 local setmetatableindex=table.setmetatableindex
16769 local formatters=string.formatters
16770 local sortedkeys=table.sortedkeys
16771 local sortedhash=table.sortedhash
16772 local sequenced=table.sequenced
16773 local report=logs.reporter("otf reader")
16774 local readers=fonts.handlers.otf.readers
16775 local streamreader=readers.streamreader
16776 local setposition=streamreader.setposition
16777 local getposition=streamreader.getposition
16778 local readuinteger=streamreader.readcardinal1
16779 local readushort=streamreader.readcardinal2
16780 local readulong=streamreader.readcardinal4
16781 local readinteger=streamreader.readinteger1
16782 local readshort=streamreader.readinteger2
16783 local readstring=streamreader.readstring
16784 local readtag=streamreader.readtag
16785 local readbytes=streamreader.readbytes
16786 local readfixed=streamreader.readfixed4
16787 local read2dot14=streamreader.read2dot14
16788 local skipshort=streamreader.skipshort
16789 local skipbytes=streamreader.skip
16790 local readbytetable=streamreader.readbytetable
16791 local readbyte=streamreader.readbyte
16792 local readcardinaltable=streamreader.readcardinaltable
16793 local readintegertable=streamreader.readintegertable
16794 local readfword=readshort
16795 local short=2
16796 local ushort=2
16797 local ulong=4
16798 directives.register("fonts.streamreader",function()
16799 streamreader=utilities.streams
16800 setposition=streamreader.setposition
16801 getposition=streamreader.getposition
16802 readuinteger=streamreader.readcardinal1
16803 readushort=streamreader.readcardinal2
16804 readulong=streamreader.readcardinal4
16805 readinteger=streamreader.readinteger1
16806 readshort=streamreader.readinteger2
16807 readstring=streamreader.readstring
16808 readtag=streamreader.readtag
16809 readbytes=streamreader.readbytes
16810 readfixed=streamreader.readfixed4
16811 read2dot14=streamreader.read2dot14
16812 skipshort=streamreader.skipshort
16813 skipbytes=streamreader.skip
16814 readbytetable=streamreader.readbytetable
16815 readbyte=streamreader.readbyte
16816 readcardinaltable=streamreader.readcardinaltable
16817 readintegertable=streamreader.readintegertable
16818 readfword=readshort
16819 end)
16820 local gsubhandlers={}
16821 local gposhandlers={}
16822 readers.gsubhandlers=gsubhandlers
16823 readers.gposhandlers=gposhandlers
16824 local helpers=readers.helpers
16825 local gotodatatable=helpers.gotodatatable
16826 local setvariabledata=helpers.setvariabledata
16827 local lookupidoffset=-1
16828 local classes={
16829 "base",
16830 "ligature",
16831 "mark",
16832 "component",
16833 }
16834 local gsubtypes={
16835 "single",
16836 "multiple",
16837 "alternate",
16838 "ligature",
16839 "context",
16840 "chainedcontext",
16841 "extension",
16842 "reversechainedcontextsingle",
16843 }
16844 local gpostypes={
16845 "single",
16846 "pair",
16847 "cursive",
16848 "marktobase",
16849 "marktoligature",
16850 "marktomark",
16851 "context",
16852 "chainedcontext",
16853 "extension",
16854 }
16855 local chaindirections={
16856 context=0,
16857 chainedcontext=1,
16858 reversechainedcontextsingle=-1,
16859 }
16860 local function setmetrics(data,where,tag,d)
16861 local w=data[where]
16862 if w then
16863 local v=w[tag]
16864 if v then
16865 w[tag]=v+d
16866 end
16867 end
16868 end
16869 local variabletags={
16870 hasc=function(data,d) setmetrics(data,"windowsmetrics","typoascender",d) end,
16871 hdsc=function(data,d) setmetrics(data,"windowsmetrics","typodescender",d) end,
16872 hlgp=function(data,d) setmetrics(data,"windowsmetrics","typolinegap",d) end,
16873 hcla=function(data,d) setmetrics(data,"windowsmetrics","winascent",d) end,
16874 hcld=function(data,d) setmetrics(data,"windowsmetrics","windescent",d) end,
16875 vasc=function(data,d) setmetrics(data,"vhea not done","ascent",d) end,
16876 vdsc=function(data,d) setmetrics(data,"vhea not done","descent",d) end,
16877 vlgp=function(data,d) setmetrics(data,"vhea not done","linegap",d) end,
16878 xhgt=function(data,d) setmetrics(data,"windowsmetrics","xheight",d) end,
16879 cpht=function(data,d) setmetrics(data,"windowsmetrics","capheight",d) end,
16880 sbxs=function(data,d) setmetrics(data,"windowsmetrics","subscriptxsize",d) end,
16881 sbys=function(data,d) setmetrics(data,"windowsmetrics","subscriptysize",d) end,
16882 sbxo=function(data,d) setmetrics(data,"windowsmetrics","subscriptxoffset",d) end,
16883 sbyo=function(data,d) setmetrics(data,"windowsmetrics","subscriptyoffset",d) end,
16884 spxs=function(data,d) setmetrics(data,"windowsmetrics","superscriptxsize",d) end,
16885 spys=function(data,d) setmetrics(data,"windowsmetrics","superscriptysize",d) end,
16886 spxo=function(data,d) setmetrics(data,"windowsmetrics","superscriptxoffset",d) end,
16887 spyo=function(data,d) setmetrics(data,"windowsmetrics","superscriptyoffset",d) end,
16888 strs=function(data,d) setmetrics(data,"windowsmetrics","strikeoutsize",d) end,
16889 stro=function(data,d) setmetrics(data,"windowsmetrics","strikeoutpos",d) end,
16890 unds=function(data,d) setmetrics(data,"postscript","underlineposition",d) end,
16891 undo=function(data,d) setmetrics(data,"postscript","underlinethickness",d) end,
16892 }
16893 local read_cardinal={
16894 streamreader.readcardinal1,
16895 streamreader.readcardinal2,
16896 streamreader.readcardinal3,
16897 streamreader.readcardinal4,
16898 }
16899 local read_integer={
16900 streamreader.readinteger1,
16901 streamreader.readinteger2,
16902 streamreader.readinteger3,
16903 streamreader.readinteger4,
16904 }
16905 directives.register("fonts.streamreader",function()
16906 read_cardinal={
16907 streamreader.readcardinal1,
16908 streamreader.readcardinal2,
16909 streamreader.readcardinal3,
16910 streamreader.readcardinal4,
16911 }
16912 read_integer={
16913 streamreader.readinteger1,
16914 streamreader.readinteger2,
16915 streamreader.readinteger3,
16916 streamreader.readinteger4,
16917 }
16918 end)
16919 local lookupnames={
16920 gsub={
16921 single="gsub_single",
16922 multiple="gsub_multiple",
16923 alternate="gsub_alternate",
16924 ligature="gsub_ligature",
16925 context="gsub_context",
16926 chainedcontext="gsub_contextchain",
16927 reversechainedcontextsingle="gsub_reversecontextchain",
16928 },
16929 gpos={
16930 single="gpos_single",
16931 pair="gpos_pair",
16932 cursive="gpos_cursive",
16933 marktobase="gpos_mark2base",
16934 marktoligature="gpos_mark2ligature",
16935 marktomark="gpos_mark2mark",
16936 context="gpos_context",
16937 chainedcontext="gpos_contextchain",
16938 }
16939 }
16940 local lookupflags=setmetatableindex(function(t,k)
16941 local v={
16942 band(k,0x0008)~=0 and true or false,
16943 band(k,0x0004)~=0 and true or false,
16944 band(k,0x0002)~=0 and true or false,
16945 band(k,0x0001)~=0 and true or false,
16946 }
16947 t[k]=v
16948 return v
16949 end)
16950 local function axistofactors(str)
16951 local t=settings_to_hash(str)
16952 for k,v in next,t do
16953 t[k]=tonumber(v) or v
16954 end
16955 return t
16956 end
16957 local hash=table.setmetatableindex(function(t,k)
16958 local v=sequenced(axistofactors(k),",")
16959 t[k]=v
16960 return v
16961 end)
16962 helpers.normalizedaxishash=hash
16963 local cleanname=fonts.names and fonts.names.cleanname or function(name)
16964 return name and (gsub(lower(name),"[^%a%d]","")) or nil
16965 end
16966 helpers.cleanname=cleanname
16967 function helpers.normalizedaxis(str)
16968 return hash[str] or str
16969 end
16970 local function getaxisscale(segments,minimum,default,maximum,user)
16971 if not minimum or not default or not maximum then
16972 return false
16973 end
16974 if user<minimum then
16975 user=minimum
16976 elseif user>maximum then
16977 user=maximum
16978 end
16979 if user<default then
16980 default=- (default-user)/(default-minimum)
16981 elseif user>default then
16982 default=(user-default)/(maximum-default)
16983 else
16984 default=0
16985 end
16986 if not segments then
16987 return default
16988 end
16989 local e
16990 for i=1,#segments do
16991 local s=segments[i]
16992 if type(s)~="number" then
16993 return default
16994 elseif s[1]>=default then
16995 if s[2]==default then
16996 return default
16997 else
16998 e=i
16999 break
17000 end
17001 end
17002 end
17003 if e then
17004 local b=segments[e-1]
17005 local e=segments[e]
17006 return b[2]+(e[2]-b[2])*(default-b[1])/(e[1]-b[1])
17007 else
17008 return false
17009 end
17010 end
17011 local function getfactors(data,instancespec)
17012 if instancespec==true then
17013 elseif type(instancespec)~="string" or instancespec=="" then
17014 return
17015 end
17016 local variabledata=data.variabledata
17017 if not variabledata then
17018 return
17019 end
17020 local instances=variabledata.instances
17021 local axis=variabledata.axis
17022 local segments=variabledata.segments
17023 if instances and axis then
17024 local values
17025 if instancespec==true then
17026 values={}
17027 for i=1,#axis do
17028 values[i]={
17029 value=axis[i].default,
17030 }
17031 end
17032 else
17033 for i=1,#instances do
17034 local instance=instances[i]
17035 if cleanname(instance.subfamily)==instancespec then
17036 values=instance.values
17037 break
17038 end
17039 end
17040 end
17041 if values then
17042 local factors={}
17043 for i=1,#axis do
17044 local a=axis[i]
17045 factors[i]=getaxisscale(segments,a.minimum,a.default,a.maximum,values[i].value)
17046 end
17047 return factors
17048 end
17049 local values=axistofactors(hash[instancespec] or instancespec)
17050 if values then
17051 local factors={}
17052 for i=1,#axis do
17053 local a=axis[i]
17054 local d=a.default
17055 factors[i]=getaxisscale(segments,a.minimum,d,a.maximum,values[a.name or a.tag] or d)
17056 end
17057 return factors
17058 end
17059 end
17060 end
17061 local function getscales(regions,factors)
17062 local scales={}
17063 for i=1,#regions do
17064 local region=regions[i]
17065 local s=1
17066 for j=1,#region do
17067 local axis=region[j]
17068 local f=factors[j]
17069 local start=axis.start
17070 local peak=axis.peak
17071 local stop=axis.stop
17072 if start>peak or peak>stop then
17073 elseif start<0 and stop>0 and peak~=0 then
17074 elseif peak==0 then
17075 elseif f<start or f>stop then
17076 s=0
17077 break
17078 elseif f<peak then
17079 s=s*(f-start)/(peak-start)
17080 elseif f>peak then
17081 s=s*(stop-f)/(stop-peak)
17082 else
17083 end
17084 end
17085 scales[i]=s
17086 end
17087 return scales
17088 end
17089 helpers.getaxisscale=getaxisscale
17090 helpers.getfactors=getfactors
17091 helpers.getscales=getscales
17092 helpers.axistofactors=axistofactors
17093 local function readvariationdata(f,storeoffset,factors)
17094 local position=getposition(f)
17095 setposition(f,storeoffset)
17096 local format=readushort(f)
17097 local regionoffset=storeoffset+readulong(f)
17098 local nofdeltadata=readushort(f)
17099 local deltadata=readcardinaltable(f,nofdeltadata,ulong)
17100 setposition(f,regionoffset)
17101 local nofaxis=readushort(f)
17102 local nofregions=readushort(f)
17103 local regions={}
17104 for i=1,nofregions do
17105 local t={}
17106 for i=1,nofaxis do
17107 t[i]={
17108 start=read2dot14(f),
17109 peak=read2dot14(f),
17110 stop=read2dot14(f),
17111 }
17112 end
17113 regions[i]=t
17114 end
17115 for i=1,nofdeltadata do
17116 setposition(f,storeoffset+deltadata[i])
17117 local nofdeltasets=readushort(f)
17118 local nofshorts=readushort(f)
17119 local nofregions=readushort(f)
17120 local usedregions={}
17121 local deltas={}
17122 for i=1,nofregions do
17123 usedregions[i]=regions[readushort(f)+1]
17124 end
17125 for i=1,nofdeltasets do
17126 local t=readintegertable(f,nofshorts,short)
17127 for i=nofshorts+1,nofregions do
17128 t[i]=readinteger(f)
17129 end
17130 deltas[i]=t
17131 end
17132 deltadata[i]={
17133 regions=usedregions,
17134 deltas=deltas,
17135 scales=factors and getscales(usedregions,factors) or nil,
17136 }
17137 end
17138 setposition(f,position)
17139 return regions,deltadata
17140 end
17141 helpers.readvariationdata=readvariationdata
17142 local function readcoverage(f,offset,simple)
17143 setposition(f,offset)
17144 local coverageformat=readushort(f)
17145 if coverageformat==1 then
17146 local nofcoverage=readushort(f)
17147 if simple then
17148 if nofcoverage==1 then
17149 return { readushort(f) }
17150 elseif nofcoverage==2 then
17151 return { readushort(f),readushort(f) }
17152 else
17153 return readcardinaltable(f,nofcoverage,ushort)
17154 end
17155 elseif nofcoverage==1 then
17156 return { [readushort(f)]=0 }
17157 elseif nofcoverage==2 then
17158 return { [readushort(f)]=0,[readushort(f)]=1 }
17159 else
17160 local coverage={}
17161 for i=0,nofcoverage-1 do
17162 coverage[readushort(f)]=i
17163 end
17164 return coverage
17165 end
17166 elseif coverageformat==2 then
17167 local nofranges=readushort(f)
17168 local coverage={}
17169 local n=simple and 1 or 0
17170 for i=1,nofranges do
17171 local firstindex=readushort(f)
17172 local lastindex=readushort(f)
17173 local coverindex=readushort(f)
17174 if simple then
17175 for i=firstindex,lastindex do
17176 coverage[n]=i
17177 n=n+1
17178 end
17179 else
17180 for i=firstindex,lastindex do
17181 coverage[i]=n
17182 n=n+1
17183 end
17184 end
17185 end
17186 return coverage
17187 else
17188 report("unknown coverage format %a ",coverageformat)
17189 return {}
17190 end
17191 end
17192 local function readclassdef(f,offset,preset)
17193 setposition(f,offset)
17194 local classdefformat=readushort(f)
17195 local classdef={}
17196 if type(preset)=="number" then
17197 for k=0,preset-1 do
17198 classdef[k]=1
17199 end
17200 end
17201 if classdefformat==1 then
17202 local index=readushort(f)
17203 local nofclassdef=readushort(f)
17204 for i=1,nofclassdef do
17205 classdef[index]=readushort(f)+1
17206 index=index+1
17207 end
17208 elseif classdefformat==2 then
17209 local nofranges=readushort(f)
17210 local n=0
17211 for i=1,nofranges do
17212 local firstindex=readushort(f)
17213 local lastindex=readushort(f)
17214 local class=readushort(f)+1
17215 for i=firstindex,lastindex do
17216 classdef[i]=class
17217 end
17218 end
17219 else
17220 report("unknown classdef format %a ",classdefformat)
17221 end
17222 if type(preset)=="table" then
17223 for k in next,preset do
17224 if not classdef[k] then
17225 classdef[k]=1
17226 end
17227 end
17228 end
17229 return classdef
17230 end
17231 local function classtocoverage(defs)
17232 if defs then
17233 local list={}
17234 for index,class in next,defs do
17235 local c=list[class]
17236 if c then
17237 c[#c+1]=index
17238 else
17239 list[class]={ index }
17240 end
17241 end
17242 return list
17243 end
17244 end
17245 local skips={ [0]=0,
17246 1,
17247 1,
17248 2,
17249 1,
17250 2,
17251 2,
17252 3,
17253 2,
17254 2,
17255 3,
17256 2,
17257 3,
17258 3,
17259 4,
17260 }
17261 local function readvariation(f,offset)
17262 local p=getposition(f)
17263 setposition(f,offset)
17264 local outer=readushort(f)
17265 local inner=readushort(f)
17266 local format=readushort(f)
17267 setposition(f,p)
17268 if format==0x8000 then
17269 return outer,inner
17270 end
17271 end
17272 local function readposition(f,format,mainoffset,getdelta)
17273 if format==0 then
17274 return false
17275 end
17276 if format==0x04 then
17277 local h=readshort(f)
17278 if h==0 then
17279 return true
17280 else
17281 return { 0,0,h,0 }
17282 end
17283 end
17284 if format==0x05 then
17285 local x=readshort(f)
17286 local h=readshort(f)
17287 if x==0 and h==0 then
17288 return true
17289 else
17290 return { x,0,h,0 }
17291 end
17292 end
17293 if format==0x44 then
17294 local h=readshort(f)
17295 if getdelta then
17296 local d=readshort(f)
17297 if d>0 then
17298 local outer,inner=readvariation(f,mainoffset+d)
17299 if outer then
17300 h=h+getdelta(outer,inner)
17301 end
17302 end
17303 else
17304 skipshort(f,1)
17305 end
17306 if h==0 then
17307 return true
17308 else
17309 return { 0,0,h,0 }
17310 end
17311 end
17312 local x=band(format,0x1)~=0 and readshort(f) or 0
17313 local y=band(format,0x2)~=0 and readshort(f) or 0
17314 local h=band(format,0x4)~=0 and readshort(f) or 0
17315 local v=band(format,0x8)~=0 and readshort(f) or 0
17316 if format>=0x10 then
17317 local X=band(format,0x10)~=0 and skipshort(f) or 0
17318 local Y=band(format,0x20)~=0 and skipshort(f) or 0
17319 local H=band(format,0x40)~=0 and skipshort(f) or 0
17320 local V=band(format,0x80)~=0 and skipshort(f) or 0
17321 local s=skips[extract(format,4,4)]
17322 if s>0 then
17323 skipshort(f,s)
17324 end
17325 if getdelta then
17326 if X>0 then
17327 local outer,inner=readvariation(f,mainoffset+X)
17328 if outer then
17329 x=x+getdelta(outer,inner)
17330 end
17331 end
17332 if Y>0 then
17333 local outer,inner=readvariation(f,mainoffset+Y)
17334 if outer then
17335 y=y+getdelta(outer,inner)
17336 end
17337 end
17338 if H>0 then
17339 local outer,inner=readvariation(f,mainoffset+H)
17340 if outer then
17341 h=h+getdelta(outer,inner)
17342 end
17343 end
17344 if V>0 then
17345 local outer,inner=readvariation(f,mainoffset+V)
17346 if outer then
17347 v=v+getdelta(outer,inner)
17348 end
17349 end
17350 end
17351 return { x,y,h,v }
17352 elseif x==0 and y==0 and h==0 and v==0 then
17353 return true
17354 else
17355 return { x,y,h,v }
17356 end
17357 end
17358 local function readanchor(f,offset,getdelta)
17359 if not offset or offset==0 then
17360 return nil
17361 end
17362 setposition(f,offset)
17363 local format=readshort(f)
17364 local x=readshort(f)
17365 local y=readshort(f)
17366 if format==3 then
17367 if getdelta then
17368 local X=readshort(f)
17369 local Y=readshort(f)
17370 if X>0 then
17371 local outer,inner=readvariation(f,offset+X)
17372 if outer then
17373 x=x+getdelta(outer,inner)
17374 end
17375 end
17376 if Y>0 then
17377 local outer,inner=readvariation(f,offset+Y)
17378 if outer then
17379 y=y+getdelta(outer,inner)
17380 end
17381 end
17382 else
17383 skipshort(f,2)
17384 end
17385 return { x,y }
17386 else
17387 return { x,y }
17388 end
17389 end
17390 local function readfirst(f,offset)
17391 if offset then
17392 setposition(f,offset)
17393 end
17394 return { readushort(f) }
17395 end
17396 local function readarray(f,offset)
17397 if offset then
17398 setposition(f,offset)
17399 end
17400 local n=readushort(f)
17401 if n==1 then
17402 return { readushort(f) },1
17403 elseif n>0 then
17404 return readcardinaltable(f,n,ushort),n
17405 end
17406 end
17407 local function readcoveragearray(f,offset,t,simple)
17408 if not t then
17409 return nil
17410 end
17411 local n=#t
17412 if n==0 then
17413 return nil
17414 end
17415 for i=1,n do
17416 t[i]=readcoverage(f,offset+t[i],simple)
17417 end
17418 return t
17419 end
17420 local function covered(subset,all)
17421 local used,u
17422 for i=1,#subset do
17423 local s=subset[i]
17424 if all[s] then
17425 if used then
17426 u=u+1
17427 used[u]=s
17428 else
17429 u=1
17430 used={ s }
17431 end
17432 end
17433 end
17434 return used
17435 end
17436 local function readlookuparray(f,noflookups,nofcurrent)
17437 local lookups={}
17438 if noflookups>0 then
17439 local length=0
17440 for i=1,noflookups do
17441 local index=readushort(f)+1
17442 if index>length then
17443 length=index
17444 end
17445 local lookup=readushort(f)+1
17446 local list=lookups[index]
17447 if list then
17448 list[#list+1]=lookup
17449 else
17450 lookups[index]={ lookup }
17451 end
17452 end
17453 for index=1,length do
17454 if not lookups[index] then
17455 lookups[index]=false
17456 end
17457 end
17458 end
17459 return lookups
17460 end
17461 local function unchainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,what)
17462 local tableoffset=lookupoffset+offset
17463 setposition(f,tableoffset)
17464 local subtype=readushort(f)
17465 if subtype==1 then
17466 local coverage=readushort(f)
17467 local subclasssets=readarray(f)
17468 local rules={}
17469 if subclasssets then
17470 coverage=readcoverage(f,tableoffset+coverage,true)
17471 for i=1,#subclasssets do
17472 local offset=subclasssets[i]
17473 if offset>0 then
17474 local firstcoverage=coverage[i]
17475 local rulesoffset=tableoffset+offset
17476 local subclassrules=readarray(f,rulesoffset)
17477 for rule=1,#subclassrules do
17478 setposition(f,rulesoffset+subclassrules[rule])
17479 local nofcurrent=readushort(f)
17480 local noflookups=readushort(f)
17481 local current={ { firstcoverage } }
17482 for i=2,nofcurrent do
17483 current[i]={ readushort(f) }
17484 end
17485 local lookups=readlookuparray(f,noflookups,nofcurrent)
17486 rules[#rules+1]={
17487 current=current,
17488 lookups=lookups
17489 }
17490 end
17491 end
17492 end
17493 else
17494 report("empty subclassset in %a subtype %i","unchainedcontext",subtype)
17495 end
17496 return {
17497 format="glyphs",
17498 rules=rules,
17499 }
17500 elseif subtype==2 then
17501 local coverage=readushort(f)
17502 local currentclassdef=readushort(f)
17503 local subclasssets=readarray(f)
17504 local rules={}
17505 if subclasssets then
17506 coverage=readcoverage(f,tableoffset+coverage)
17507 currentclassdef=readclassdef(f,tableoffset+currentclassdef,coverage)
17508 local currentclasses=classtocoverage(currentclassdef,fontdata.glyphs)
17509 for class=1,#subclasssets do
17510 local offset=subclasssets[class]
17511 if offset>0 then
17512 local firstcoverage=currentclasses[class]
17513 if firstcoverage then
17514 firstcoverage=covered(firstcoverage,coverage)
17515 if firstcoverage then
17516 local rulesoffset=tableoffset+offset
17517 local subclassrules=readarray(f,rulesoffset)
17518 for rule=1,#subclassrules do
17519 setposition(f,rulesoffset+subclassrules[rule])
17520 local nofcurrent=readushort(f)
17521 local noflookups=readushort(f)
17522 local current={ firstcoverage }
17523 for i=2,nofcurrent do
17524 current[i]=currentclasses[readushort(f)+1]
17525 end
17526 local lookups=readlookuparray(f,noflookups,nofcurrent)
17527 rules[#rules+1]={
17528 current=current,
17529 lookups=lookups
17530 }
17531 end
17532 else
17533 report("no coverage")
17534 end
17535 else
17536 report("no coverage class")
17537 end
17538 end
17539 end
17540 else
17541 report("empty subclassset in %a subtype %i","unchainedcontext",subtype)
17542 end
17543 return {
17544 format="class",
17545 rules=rules,
17546 }
17547 elseif subtype==3 then
17548 local nofglyphs=readushort(f)
17549 local noflookups=readushort(f)
17550 local current=readcardinaltable(f,nofglyphs,ushort)
17551 local lookups=readlookuparray(f,noflookups,#current)
17552 current=readcoveragearray(f,tableoffset,current,true)
17553 return {
17554 format="coverage",
17555 rules={
17556 {
17557 current=current,
17558 lookups=lookups,
17559 }
17560 }
17561 }
17562 else
17563 report("unsupported subtype %a in %a %s",subtype,"unchainedcontext",what)
17564 end
17565 end
17566 local function chainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,what)
17567 local tableoffset=lookupoffset+offset
17568 setposition(f,tableoffset)
17569 local subtype=readushort(f)
17570 if subtype==1 then
17571 local coverage=readushort(f)
17572 local subclasssets=readarray(f)
17573 local rules={}
17574 if subclasssets then
17575 coverage=readcoverage(f,tableoffset+coverage,true)
17576 for i=1,#subclasssets do
17577 local offset=subclasssets[i]
17578 if offset>0 then
17579 local firstcoverage=coverage[i]
17580 local rulesoffset=tableoffset+offset
17581 local subclassrules=readarray(f,rulesoffset)
17582 for rule=1,#subclassrules do
17583 setposition(f,rulesoffset+subclassrules[rule])
17584 local nofbefore=readushort(f)
17585 local before
17586 if nofbefore>0 then
17587 before={}
17588 for i=1,nofbefore do
17589 before[i]={ readushort(f) }
17590 end
17591 end
17592 local nofcurrent=readushort(f)
17593 local current={ { firstcoverage } }
17594 for i=2,nofcurrent do
17595 current[i]={ readushort(f) }
17596 end
17597 local nofafter=readushort(f)
17598 local after
17599 if nofafter>0 then
17600 after={}
17601 for i=1,nofafter do
17602 after[i]={ readushort(f) }
17603 end
17604 end
17605 local noflookups=readushort(f)
17606 local lookups=readlookuparray(f,noflookups,nofcurrent)
17607 rules[#rules+1]={
17608 before=before,
17609 current=current,
17610 after=after,
17611 lookups=lookups,
17612 }
17613 end
17614 end
17615 end
17616 else
17617 report("empty subclassset in %a subtype %i","chainedcontext",subtype)
17618 end
17619 return {
17620 format="glyphs",
17621 rules=rules,
17622 }
17623 elseif subtype==2 then
17624 local coverage=readushort(f)
17625 local beforeclassdef=readushort(f)
17626 local currentclassdef=readushort(f)
17627 local afterclassdef=readushort(f)
17628 local subclasssets=readarray(f)
17629 local rules={}
17630 if subclasssets then
17631 local coverage=readcoverage(f,tableoffset+coverage)
17632 local beforeclassdef=readclassdef(f,tableoffset+beforeclassdef,nofglyphs)
17633 local currentclassdef=readclassdef(f,tableoffset+currentclassdef,coverage)
17634 local afterclassdef=readclassdef(f,tableoffset+afterclassdef,nofglyphs)
17635 local beforeclasses=classtocoverage(beforeclassdef,fontdata.glyphs)
17636 local currentclasses=classtocoverage(currentclassdef,fontdata.glyphs)
17637 local afterclasses=classtocoverage(afterclassdef,fontdata.glyphs)
17638 for class=1,#subclasssets do
17639 local offset=subclasssets[class]
17640 if offset>0 then
17641 local firstcoverage=currentclasses[class]
17642 if firstcoverage then
17643 firstcoverage=covered(firstcoverage,coverage)
17644 if firstcoverage then
17645 local rulesoffset=tableoffset+offset
17646 local subclassrules=readarray(f,rulesoffset)
17647 for rule=1,#subclassrules do
17648 setposition(f,rulesoffset+subclassrules[rule])
17649 local nofbefore=readushort(f)
17650 local before
17651 if nofbefore>0 then
17652 before={}
17653 for i=1,nofbefore do
17654 before[i]=beforeclasses[readushort(f)+1]
17655 end
17656 end
17657 local nofcurrent=readushort(f)
17658 local current={ firstcoverage }
17659 for i=2,nofcurrent do
17660 current[i]=currentclasses[readushort(f)+1]
17661 end
17662 local nofafter=readushort(f)
17663 local after
17664 if nofafter>0 then
17665 after={}
17666 for i=1,nofafter do
17667 after[i]=afterclasses[readushort(f)+1]
17668 end
17669 end
17670 local noflookups=readushort(f)
17671 local lookups=readlookuparray(f,noflookups,nofcurrent)
17672 rules[#rules+1]={
17673 before=before,
17674 current=current,
17675 after=after,
17676 lookups=lookups,
17677 }
17678 end
17679 else
17680 report("no coverage")
17681 end
17682 else
17683 report("class is not covered")
17684 end
17685 end
17686 end
17687 else
17688 report("empty subclassset in %a subtype %i","chainedcontext",subtype)
17689 end
17690 return {
17691 format="class",
17692 rules=rules,
17693 }
17694 elseif subtype==3 then
17695 local before=readarray(f)
17696 local current=readarray(f)
17697 local after=readarray(f)
17698 local noflookups=readushort(f)
17699 local lookups=readlookuparray(f,noflookups,#current)
17700 before=readcoveragearray(f,tableoffset,before,true)
17701 current=readcoveragearray(f,tableoffset,current,true)
17702 after=readcoveragearray(f,tableoffset,after,true)
17703 return {
17704 format="coverage",
17705 rules={
17706 {
17707 before=before,
17708 current=current,
17709 after=after,
17710 lookups=lookups,
17711 }
17712 }
17713 }
17714 else
17715 report("unsupported subtype %a in %a %s",subtype,"chainedcontext",what)
17716 end
17717 end
17718 local function extension(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,types,handlers,what)
17719 local tableoffset=lookupoffset+offset
17720 setposition(f,tableoffset)
17721 local subtype=readushort(f)
17722 if subtype==1 then
17723 local lookuptype=types[readushort(f)]
17724 local faroffset=readulong(f)
17725 local handler=handlers[lookuptype]
17726 if handler then
17727 return handler(f,fontdata,lookupid,tableoffset+faroffset,0,glyphs,nofglyphs),lookuptype
17728 else
17729 report("no handler for lookuptype %a subtype %a in %s %s",lookuptype,subtype,what,"extension")
17730 end
17731 else
17732 report("unsupported subtype %a in %s %s",subtype,what,"extension")
17733 end
17734 end
17735 function gsubhandlers.single(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
17736 local tableoffset=lookupoffset+offset
17737 setposition(f,tableoffset)
17738 local subtype=readushort(f)
17739 if subtype==1 then
17740 local coverage=readushort(f)
17741 local delta=readshort(f)
17742 local coverage=readcoverage(f,tableoffset+coverage)
17743 for index in next,coverage do
17744 local newindex=(index+delta)%65536
17745 if index>nofglyphs or newindex>nofglyphs then
17746 report("invalid index in %s format %i: %i -> %i (max %i)","single",subtype,index,newindex,nofglyphs)
17747 coverage[index]=nil
17748 else
17749 coverage[index]=newindex
17750 end
17751 end
17752 return {
17753 coverage=coverage
17754 }
17755 elseif subtype==2 then
17756 local coverage=readushort(f)
17757 local nofreplacements=readushort(f)
17758 local replacements=readcardinaltable(f,nofreplacements,ushort)
17759 local coverage=readcoverage(f,tableoffset+coverage)
17760 for index,newindex in next,coverage do
17761 newindex=newindex+1
17762 if index>nofglyphs or newindex>nofglyphs then
17763 report("invalid index in %s format %i: %i -> %i (max %i)","single",subtype,index,newindex,nofglyphs)
17764 coverage[index]=nil
17765 else
17766 coverage[index]=replacements[newindex]
17767 end
17768 end
17769 return {
17770 coverage=coverage
17771 }
17772 else
17773 report("unsupported subtype %a in %a substitution",subtype,"single")
17774 end
17775 end
17776 local function sethandler(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,what)
17777 local tableoffset=lookupoffset+offset
17778 setposition(f,tableoffset)
17779 local subtype=readushort(f)
17780 if subtype==1 then
17781 local coverage=readushort(f)
17782 local nofsequence=readushort(f)
17783 local sequences=readcardinaltable(f,nofsequence,ushort)
17784 for i=1,nofsequence do
17785 setposition(f,tableoffset+sequences[i])
17786 sequences[i]=readcardinaltable(f,readushort(f),ushort)
17787 end
17788 local coverage=readcoverage(f,tableoffset+coverage)
17789 for index,newindex in next,coverage do
17790 newindex=newindex+1
17791 if index>nofglyphs or newindex>nofglyphs then
17792 report("invalid index in %s format %i: %i -> %i (max %i)",what,subtype,index,newindex,nofglyphs)
17793 coverage[index]=nil
17794 else
17795 coverage[index]=sequences[newindex]
17796 end
17797 end
17798 return {
17799 coverage=coverage
17800 }
17801 else
17802 report("unsupported subtype %a in %a substitution",subtype,what)
17803 end
17804 end
17805 function gsubhandlers.multiple(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
17806 return sethandler(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,"multiple")
17807 end
17808 function gsubhandlers.alternate(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
17809 return sethandler(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,"alternate")
17810 end
17811 function gsubhandlers.ligature(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
17812 local tableoffset=lookupoffset+offset
17813 setposition(f,tableoffset)
17814 local subtype=readushort(f)
17815 if subtype==1 then
17816 local coverage=readushort(f)
17817 local nofsets=readushort(f)
17818 local ligatures=readcardinaltable(f,nofsets,ushort)
17819 for i=1,nofsets do
17820 local offset=lookupoffset+offset+ligatures[i]
17821 setposition(f,offset)
17822 local n=readushort(f)
17823 if n==1 then
17824 ligatures[i]={ offset+readushort(f) }
17825 else
17826 local l={}
17827 for i=1,n do
17828 l[i]=offset+readushort(f)
17829 end
17830 ligatures[i]=l
17831 end
17832 end
17833 local coverage=readcoverage(f,tableoffset+coverage)
17834 for index,newindex in next,coverage do
17835 local hash={}
17836 local ligatures=ligatures[newindex+1]
17837 for i=1,#ligatures do
17838 local offset=ligatures[i]
17839 setposition(f,offset)
17840 local lig=readushort(f)
17841 local cnt=readushort(f)
17842 local hsh=hash
17843 for i=2,cnt do
17844 local c=readushort(f)
17845 local h=hsh[c]
17846 if not h then
17847 h={}
17848 hsh[c]=h
17849 end
17850 hsh=h
17851 end
17852 hsh.ligature=lig
17853 end
17854 coverage[index]=hash
17855 end
17856 return {
17857 coverage=coverage
17858 }
17859 else
17860 report("unsupported subtype %a in %a substitution",subtype,"ligature")
17861 end
17862 end
17863 function gsubhandlers.context(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
17864 return unchainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,"substitution"),"context"
17865 end
17866 function gsubhandlers.chainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
17867 return chainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,"substitution"),"chainedcontext"
17868 end
17869 function gsubhandlers.extension(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
17870 return extension(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,gsubtypes,gsubhandlers,"substitution")
17871 end
17872 function gsubhandlers.reversechainedcontextsingle(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
17873 local tableoffset=lookupoffset+offset
17874 setposition(f,tableoffset)
17875 local subtype=readushort(f)
17876 if subtype==1 then
17877 local current=readfirst(f)
17878 local before=readarray(f)
17879 local after=readarray(f)
17880 local replacements=readarray(f)
17881 current=readcoveragearray(f,tableoffset,current,true)
17882 before=readcoveragearray(f,tableoffset,before,true)
17883 after=readcoveragearray(f,tableoffset,after,true)
17884 return {
17885 format="reversecoverage",
17886 rules={
17887 {
17888 before=before,
17889 current=current,
17890 after=after,
17891 replacements=replacements,
17892 }
17893 }
17894 },"reversechainedcontextsingle"
17895 else
17896 report("unsupported subtype %a in %a substitution",subtype,"reversechainedcontextsingle")
17897 end
17898 end
17899 local function readpairsets(f,tableoffset,sets,format1,format2,mainoffset,getdelta)
17900 local done={}
17901 for i=1,#sets do
17902 local offset=sets[i]
17903 local reused=done[offset]
17904 if not reused then
17905 offset=tableoffset+offset
17906 setposition(f,offset)
17907 local n=readushort(f)
17908 reused={}
17909 for i=1,n do
17910 reused[i]={
17911 readushort(f),
17912 readposition(f,format1,offset,getdelta),
17913 readposition(f,format2,offset,getdelta),
17914 }
17915 end
17916 done[offset]=reused
17917 end
17918 sets[i]=reused
17919 end
17920 return sets
17921 end
17922 local function readpairclasssets(f,nofclasses1,nofclasses2,format1,format2,mainoffset,getdelta)
17923 local classlist1={}
17924 for i=1,nofclasses1 do
17925 local classlist2={}
17926 classlist1[i]=classlist2
17927 for j=1,nofclasses2 do
17928 local one=readposition(f,format1,mainoffset,getdelta)
17929 local two=readposition(f,format2,mainoffset,getdelta)
17930 if one or two then
17931 classlist2[j]={ one,two }
17932 else
17933 classlist2[j]=false
17934 end
17935 end
17936 end
17937 return classlist1
17938 end
17939 function gposhandlers.single(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
17940 local tableoffset=lookupoffset+offset
17941 setposition(f,tableoffset)
17942 local subtype=readushort(f)
17943 local getdelta=fontdata.temporary.getdelta
17944 if subtype==1 then
17945 local coverage=readushort(f)
17946 local format=readushort(f)
17947 local value=readposition(f,format,tableoffset,getdelta)
17948 local coverage=readcoverage(f,tableoffset+coverage)
17949 for index,newindex in next,coverage do
17950 coverage[index]=value
17951 end
17952 return {
17953 format="single",
17954 coverage=coverage,
17955 }
17956 elseif subtype==2 then
17957 local coverage=readushort(f)
17958 local format=readushort(f)
17959 local nofvalues=readushort(f)
17960 local values={}
17961 for i=1,nofvalues do
17962 values[i]=readposition(f,format,tableoffset,getdelta)
17963 end
17964 local coverage=readcoverage(f,tableoffset+coverage)
17965 for index,newindex in next,coverage do
17966 coverage[index]=values[newindex+1]
17967 end
17968 return {
17969 format="single",
17970 coverage=coverage,
17971 }
17972 else
17973 report("unsupported subtype %a in %a positioning",subtype,"single")
17974 end
17975 end
17976 function gposhandlers.pair(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
17977 local tableoffset=lookupoffset+offset
17978 setposition(f,tableoffset)
17979 local subtype=readushort(f)
17980 local getdelta=fontdata.temporary.getdelta
17981 if subtype==1 then
17982 local coverage=readushort(f)
17983 local format1=readushort(f)
17984 local format2=readushort(f)
17985 local sets=readarray(f)
17986 sets=readpairsets(f,tableoffset,sets,format1,format2,mainoffset,getdelta)
17987 coverage=readcoverage(f,tableoffset+coverage)
17988 local shared={}
17989 for index,newindex in next,coverage do
17990 local set=sets[newindex+1]
17991 local hash={}
17992 for i=1,#set do
17993 local value=set[i]
17994 if value then
17995 local other=value[1]
17996 local share=shared[value]
17997 if share==nil then
17998 local first=value[2]
17999 local second=value[3]
18000 if first or second then
18001 share={ first,second or nil }
18002 else
18003 share=false
18004 end
18005 shared[value]=share
18006 end
18007 hash[other]=share or nil
18008 end
18009 end
18010 coverage[index]=hash
18011 end
18012 return {
18013 shared=shared and true or nil,
18014 format="pair",
18015 coverage=coverage,
18016 }
18017 elseif subtype==2 then
18018 local coverage=readushort(f)
18019 local format1=readushort(f)
18020 local format2=readushort(f)
18021 local classdef1=readushort(f)
18022 local classdef2=readushort(f)
18023 local nofclasses1=readushort(f)
18024 local nofclasses2=readushort(f)
18025 local classlist=readpairclasssets(f,nofclasses1,nofclasses2,format1,format2,tableoffset,getdelta)
18026 coverage=readcoverage(f,tableoffset+coverage)
18027 classdef1=readclassdef(f,tableoffset+classdef1,coverage)
18028 classdef2=readclassdef(f,tableoffset+classdef2,nofglyphs)
18029 local usedcoverage={}
18030 local shared={}
18031 for g1,c1 in next,classdef1 do
18032 if coverage[g1] then
18033 local l1=classlist[c1]
18034 if l1 then
18035 local hash={}
18036 for paired,class in next,classdef2 do
18037 local offsets=l1[class]
18038 if offsets then
18039 local first=offsets[1]
18040 local second=offsets[2]
18041 if first or second then
18042 local s1=shared[first]
18043 if s1==nil then
18044 s1={}
18045 shared[first]=s1
18046 end
18047 local s2=s1[second]
18048 if s2==nil then
18049 s2={ first,second or nil }
18050 s1[second]=s2
18051 end
18052 hash[paired]=s2
18053 end
18054 end
18055 end
18056 usedcoverage[g1]=hash
18057 end
18058 end
18059 end
18060 return {
18061 shared=shared and true or nil,
18062 format="pair",
18063 coverage=usedcoverage,
18064 }
18065 elseif subtype==3 then
18066 report("yet unsupported subtype %a in %a positioning",subtype,"pair")
18067 else
18068 report("unsupported subtype %a in %a positioning",subtype,"pair")
18069 end
18070 end
18071 function gposhandlers.cursive(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
18072 local tableoffset=lookupoffset+offset
18073 setposition(f,tableoffset)
18074 local subtype=readushort(f)
18075 local getdelta=fontdata.temporary.getdelta
18076 if subtype==1 then
18077 local coverage=tableoffset+readushort(f)
18078 local nofrecords=readushort(f)
18079 local records={}
18080 for i=1,nofrecords do
18081 local entry=readushort(f)
18082 local exit=readushort(f)
18083 records[i]={
18084 entry~=0 and (tableoffset+entry) or false,
18085 exit~=0 and (tableoffset+exit ) or nil,
18086 }
18087 end
18088 local cc=(fontdata.temporary.cursivecount or 0)+1
18089 fontdata.temporary.cursivecount=cc
18090 cc="cc-"..cc
18091 coverage=readcoverage(f,coverage)
18092 for i=1,nofrecords do
18093 local r=records[i]
18094 records[i]={
18095 cc,
18096 readanchor(f,r[1],getdelta) or false,
18097 readanchor(f,r[2],getdelta) or nil,
18098 }
18099 end
18100 for index,newindex in next,coverage do
18101 coverage[index]=records[newindex+1]
18102 end
18103 return {
18104 coverage=coverage,
18105 }
18106 else
18107 report("unsupported subtype %a in %a positioning",subtype,"cursive")
18108 end
18109 end
18110 local function handlemark(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,ligature)
18111 local tableoffset=lookupoffset+offset
18112 setposition(f,tableoffset)
18113 local subtype=readushort(f)
18114 local getdelta=fontdata.temporary.getdelta
18115 if subtype==1 then
18116 local markcoverage=tableoffset+readushort(f)
18117 local basecoverage=tableoffset+readushort(f)
18118 local nofclasses=readushort(f)
18119 local markoffset=tableoffset+readushort(f)
18120 local baseoffset=tableoffset+readushort(f)
18121 local markcoverage=readcoverage(f,markcoverage)
18122 local basecoverage=readcoverage(f,basecoverage,true)
18123 setposition(f,markoffset)
18124 local markclasses={}
18125 local nofmarkclasses=readushort(f)
18126 local lastanchor=fontdata.lastanchor or 0
18127 local usedanchors={}
18128 for i=1,nofmarkclasses do
18129 local class=readushort(f)+1
18130 local offset=readushort(f)
18131 if offset==0 then
18132 markclasses[i]=false
18133 else
18134 markclasses[i]={ class,markoffset+offset }
18135 end
18136 usedanchors[class]=true
18137 end
18138 for i=1,nofmarkclasses do
18139 local mc=markclasses[i]
18140 if mc then
18141 mc[2]=readanchor(f,mc[2],getdelta)
18142 end
18143 end
18144 setposition(f,baseoffset)
18145 local nofbaserecords=readushort(f)
18146 local baserecords={}
18147 if ligature then
18148 for i=1,nofbaserecords do
18149 local offset=readushort(f)
18150 if offset==0 then
18151 baserecords[i]=false
18152 else
18153 baserecords[i]=baseoffset+offset
18154 end
18155 end
18156 for i=1,nofbaserecords do
18157 local recordoffset=baserecords[i]
18158 if recordoffset then
18159 setposition(f,recordoffset)
18160 local nofcomponents=readushort(f)
18161 local components={}
18162 for i=1,nofcomponents do
18163 local classes={}
18164 for i=1,nofclasses do
18165 local offset=readushort(f)
18166 if offset~=0 then
18167 classes[i]=recordoffset+offset
18168 else
18169 classes[i]=false
18170 end
18171 end
18172 components[i]=classes
18173 end
18174 baserecords[i]=components
18175 end
18176 end
18177 local baseclasses={}
18178 for i=1,nofclasses do
18179 baseclasses[i]={}
18180 end
18181 for i=1,nofbaserecords do
18182 local components=baserecords[i]
18183 if components then
18184 local b=basecoverage[i]
18185 for c=1,#components do
18186 local classes=components[c]
18187 if classes then
18188 for i=1,nofclasses do
18189 local anchor=readanchor(f,classes[i],getdelta)
18190 local bclass=baseclasses[i]
18191 local bentry=bclass[b]
18192 if bentry then
18193 bentry[c]=anchor
18194 else
18195 bclass[b]={ [c]=anchor }
18196 end
18197 end
18198 end
18199 end
18200 end
18201 end
18202 for index,newindex in next,markcoverage do
18203 markcoverage[index]=markclasses[newindex+1] or nil
18204 end
18205 return {
18206 format="ligature",
18207 baseclasses=baseclasses,
18208 coverage=markcoverage,
18209 }
18210 else
18211 for i=1,nofbaserecords do
18212 local r={}
18213 for j=1,nofclasses do
18214 local offset=readushort(f)
18215 if offset==0 then
18216 r[j]=false
18217 else
18218 r[j]=baseoffset+offset
18219 end
18220 end
18221 baserecords[i]=r
18222 end
18223 local baseclasses={}
18224 for i=1,nofclasses do
18225 baseclasses[i]={}
18226 end
18227 for i=1,nofbaserecords do
18228 local r=baserecords[i]
18229 local b=basecoverage[i]
18230 for j=1,nofclasses do
18231 baseclasses[j][b]=readanchor(f,r[j],getdelta)
18232 end
18233 end
18234 for index,newindex in next,markcoverage do
18235 markcoverage[index]=markclasses[newindex+1] or nil
18236 end
18237 return {
18238 format="base",
18239 baseclasses=baseclasses,
18240 coverage=markcoverage,
18241 }
18242 end
18243 else
18244 report("unsupported subtype %a in",subtype)
18245 end
18246 end
18247 function gposhandlers.marktobase(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
18248 return handlemark(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
18249 end
18250 function gposhandlers.marktoligature(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
18251 return handlemark(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,true)
18252 end
18253 function gposhandlers.marktomark(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
18254 return handlemark(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
18255 end
18256 function gposhandlers.context(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
18257 return unchainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,"positioning"),"context"
18258 end
18259 function gposhandlers.chainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
18260 return chainedcontext(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,"positioning"),"chainedcontext"
18261 end
18262 function gposhandlers.extension(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs)
18263 return extension(f,fontdata,lookupid,lookupoffset,offset,glyphs,nofglyphs,gpostypes,gposhandlers,"positioning")
18264 end
18265 do
18266 local plugins={}
18267 function plugins.size(f,fontdata,tableoffset,feature)
18268 if fontdata.designsize then
18269 else
18270 local function check(offset)
18271 setposition(f,offset)
18272 local designsize=readushort(f)
18273 if designsize>0 then
18274 local fontstyleid=readushort(f)
18275 local guimenuid=readushort(f)
18276 local minsize=readushort(f)
18277 local maxsize=readushort(f)
18278 if minsize==0 and maxsize==0 and fontstyleid==0 and guimenuid==0 then
18279 minsize=designsize
18280 maxsize=designsize
18281 end
18282 if designsize>=minsize and designsize<=maxsize then
18283 return minsize,maxsize,designsize
18284 end
18285 end
18286 end
18287 local minsize,maxsize,designsize=check(tableoffset+feature.offset+feature.parameters)
18288 if not designsize then
18289 minsize,maxsize,designsize=check(tableoffset+feature.parameters)
18290 if designsize then
18291 report("bad size feature in %a, falling back to wrong offset",fontdata.filename or "?")
18292 else
18293 report("bad size feature in %a,",fontdata.filename or "?")
18294 end
18295 end
18296 if designsize then
18297 fontdata.minsize=minsize
18298 fontdata.maxsize=maxsize
18299 fontdata.designsize=designsize
18300 end
18301 end
18302 end
18303 local function reorderfeatures(fontdata,scripts,features)
18304 local scriptlangs={}
18305 local featurehash={}
18306 local featureorder={}
18307 for script,languages in next,scripts do
18308 for language,record in next,languages do
18309 local hash={}
18310 local list=record.featureindices
18311 for k=1,#list do
18312 local index=list[k]
18313 local feature=features[index]
18314 local lookups=feature.lookups
18315 local tag=feature.tag
18316 if tag then
18317 hash[tag]=true
18318 end
18319 if lookups then
18320 for i=1,#lookups do
18321 local lookup=lookups[i]
18322 local o=featureorder[lookup]
18323 if o then
18324 local okay=true
18325 for i=1,#o do
18326 if o[i]==tag then
18327 okay=false
18328 break
18329 end
18330 end
18331 if okay then
18332 o[#o+1]=tag
18333 end
18334 else
18335 featureorder[lookup]={ tag }
18336 end
18337 local f=featurehash[lookup]
18338 if f then
18339 local h=f[tag]
18340 if h then
18341 local s=h[script]
18342 if s then
18343 s[language]=true
18344 else
18345 h[script]={ [language]=true }
18346 end
18347 else
18348 f[tag]={ [script]={ [language]=true } }
18349 end
18350 else
18351 featurehash[lookup]={ [tag]={ [script]={ [language]=true } } }
18352 end
18353 local h=scriptlangs[tag]
18354 if h then
18355 local s=h[script]
18356 if s then
18357 s[language]=true
18358 else
18359 h[script]={ [language]=true }
18360 end
18361 else
18362 scriptlangs[tag]={ [script]={ [language]=true } }
18363 end
18364 end
18365 end
18366 end
18367 end
18368 end
18369 return scriptlangs,featurehash,featureorder
18370 end
18371 local function readscriplan(f,fontdata,scriptoffset)
18372 setposition(f,scriptoffset)
18373 local nofscripts=readushort(f)
18374 local scripts={}
18375 for i=1,nofscripts do
18376 scripts[readtag(f)]=scriptoffset+readushort(f)
18377 end
18378 local languagesystems=setmetatableindex("table")
18379 for script,offset in next,scripts do
18380 setposition(f,offset)
18381 local defaultoffset=readushort(f)
18382 local noflanguages=readushort(f)
18383 local languages={}
18384 if defaultoffset>0 then
18385 languages.dflt=languagesystems[offset+defaultoffset]
18386 end
18387 for i=1,noflanguages do
18388 local language=readtag(f)
18389 local offset=offset+readushort(f)
18390 languages[language]=languagesystems[offset]
18391 end
18392 scripts[script]=languages
18393 end
18394 for offset,usedfeatures in next,languagesystems do
18395 if offset>0 then
18396 setposition(f,offset)
18397 local featureindices={}
18398 usedfeatures.featureindices=featureindices
18399 usedfeatures.lookuporder=readushort(f)
18400 usedfeatures.requiredindex=readushort(f)
18401 local noffeatures=readushort(f)
18402 for i=1,noffeatures do
18403 featureindices[i]=readushort(f)+1
18404 end
18405 end
18406 end
18407 return scripts
18408 end
18409 local function readfeatures(f,fontdata,featureoffset)
18410 setposition(f,featureoffset)
18411 local features={}
18412 local noffeatures=readushort(f)
18413 for i=1,noffeatures do
18414 features[i]={
18415 tag=readtag(f),
18416 offset=readushort(f)
18417 }
18418 end
18419 for i=1,noffeatures do
18420 local feature=features[i]
18421 local offset=featureoffset+feature.offset
18422 setposition(f,offset)
18423 local parameters=readushort(f)
18424 local noflookups=readushort(f)
18425 if noflookups>0 then
18426 local lookups=readcardinaltable(f,noflookups,ushort)
18427 feature.lookups=lookups
18428 for j=1,noflookups do
18429 lookups[j]=lookups[j]+1
18430 end
18431 end
18432 if parameters>0 then
18433 feature.parameters=parameters
18434 local plugin=plugins[feature.tag]
18435 if plugin then
18436 plugin(f,fontdata,featureoffset,feature)
18437 end
18438 end
18439 end
18440 return features
18441 end
18442 local function readlookups(f,lookupoffset,lookuptypes,featurehash,featureorder,nofmarkclasses)
18443 setposition(f,lookupoffset)
18444 local noflookups=readushort(f)
18445 local lookups=readcardinaltable(f,noflookups,ushort)
18446 for lookupid=1,noflookups do
18447 local offset=lookups[lookupid]
18448 setposition(f,lookupoffset+offset)
18449 local subtables={}
18450 local typebits=readushort(f)
18451 local flagbits=readushort(f)
18452 local lookuptype=lookuptypes[typebits]
18453 local lookupflags=lookupflags[flagbits]
18454 local nofsubtables=readushort(f)
18455 for j=1,nofsubtables do
18456 subtables[j]=offset+readushort(f)
18457 end
18458 local markclass=band(flagbits,0x0010)~=0
18459 local markset=rshift(flagbits,8)
18460 if markclass then
18461 markclass=readushort(f)
18462 end
18463 if markset>0 then
18464 markclass=nofmarkclasses+markset
18465 end
18466 lookups[lookupid]={
18467 type=lookuptype,
18468 flags=lookupflags,
18469 name=lookupid,
18470 subtables=subtables,
18471 markclass=markclass,
18472 features=featurehash[lookupid],
18473 order=featureorder[lookupid],
18474 }
18475 end
18476 return lookups
18477 end
18478 local f_lookupname=formatters["%s_%s_%s"]
18479 local function resolvelookups(f,lookupoffset,fontdata,lookups,lookuptypes,lookuphandlers,what,tableoffset)
18480 local sequences=fontdata.sequences or {}
18481 local sublookuplist=fontdata.sublookups or {}
18482 fontdata.sequences=sequences
18483 fontdata.sublookups=sublookuplist
18484 local nofsublookups=#sublookuplist
18485 local nofsequences=#sequences
18486 local lastsublookup=nofsublookups
18487 local lastsequence=nofsequences
18488 local lookupnames=lookupnames[what]
18489 local sublookuphash={}
18490 local sublookupcheck={}
18491 local glyphs=fontdata.glyphs
18492 local nofglyphs=fontdata.nofglyphs or #glyphs
18493 local noflookups=#lookups
18494 local lookupprefix=sub(what,2,2)
18495 local usedlookups=false
18496 local allsteps={}
18497 for lookupid=1,noflookups do
18498 local lookup=lookups[lookupid]
18499 local lookuptype=lookup.type
18500 local subtables=lookup.subtables
18501 local features=lookup.features
18502 local handler=lookuphandlers[lookuptype]
18503 if handler then
18504 local nofsubtables=#subtables
18505 local order=lookup.order
18506 local flags=lookup.flags
18507 if flags[1] then flags[1]="mark" end
18508 if flags[2] then flags[2]="ligature" end
18509 if flags[3] then flags[3]="base" end
18510 local markclass=lookup.markclass
18511 if nofsubtables>0 then
18512 local steps={}
18513 local nofsteps=0
18514 local oldtype=nil
18515 for s=1,nofsubtables do
18516 local step,lt=handler(f,fontdata,lookupid,lookupoffset,subtables[s],glyphs,nofglyphs)
18517 if lt then
18518 lookuptype=lt
18519 if oldtype and lt~=oldtype then
18520 report("messy %s lookup type %a and %a",what,lookuptype,oldtype)
18521 end
18522 oldtype=lookuptype
18523 end
18524 if not step then
18525 report("unsupported %s lookup type %a",what,lookuptype)
18526 else
18527 nofsteps=nofsteps+1
18528 steps[nofsteps]=step
18529 local rules=step.rules
18530 if rules then
18531 allsteps[#allsteps+1]=step
18532 for i=1,#rules do
18533 local rule=rules[i]
18534 local before=rule.before
18535 local current=rule.current
18536 local after=rule.after
18537 local replacements=rule.replacements
18538 if before then
18539 for i=1,#before do
18540 before[i]=tohash(before[i])
18541 end
18542 rule.before=reversed(before)
18543 end
18544 if current then
18545 if replacements then
18546 local first=current[1]
18547 local hash={}
18548 local repl={}
18549 for i=1,#first do
18550 local c=first[i]
18551 hash[c]=true
18552 repl[c]=replacements[i]
18553 end
18554 rule.current={ hash }
18555 rule.replacements=repl
18556 else
18557 for i=1,#current do
18558 current[i]=tohash(current[i])
18559 end
18560 end
18561 else
18562 end
18563 if after then
18564 for i=1,#after do
18565 after[i]=tohash(after[i])
18566 end
18567 end
18568 if usedlookups then
18569 local lookups=rule.lookups
18570 if lookups then
18571 for k,v in next,lookups do
18572 if v then
18573 for k,v in next,v do
18574 usedlookups[v]=usedlookups[v]+1
18575 end
18576 end
18577 end
18578 end
18579 end
18580 end
18581 end
18582 end
18583 end
18584 if nofsteps~=nofsubtables then
18585 report("bogus subtables removed in %s lookup type %a",what,lookuptype)
18586 end
18587 lookuptype=lookupnames[lookuptype] or lookuptype
18588 if features then
18589 nofsequences=nofsequences+1
18590 local l={
18591 index=nofsequences,
18592 name=f_lookupname(lookupprefix,"s",lookupid+lookupidoffset),
18593 steps=steps,
18594 nofsteps=nofsteps,
18595 type=lookuptype,
18596 markclass=markclass or nil,
18597 flags=flags,
18598 order=order,
18599 features=features,
18600 }
18601 sequences[nofsequences]=l
18602 lookup.done=l
18603 else
18604 nofsublookups=nofsublookups+1
18605 local l={
18606 index=nofsublookups,
18607 name=f_lookupname(lookupprefix,"l",lookupid+lookupidoffset),
18608 steps=steps,
18609 nofsteps=nofsteps,
18610 type=lookuptype,
18611 markclass=markclass or nil,
18612 flags=flags,
18613 }
18614 sublookuplist[nofsublookups]=l
18615 sublookuphash[lookupid]=nofsublookups
18616 sublookupcheck[lookupid]=0
18617 lookup.done=l
18618 end
18619 else
18620 report("no subtables for lookup %a",lookupid)
18621 end
18622 else
18623 report("no handler for lookup %a with type %a",lookupid,lookuptype)
18624 end
18625 end
18626 if usedlookups then
18627 report("used %s lookups: % t",what,sortedkeys(usedlookups))
18628 end
18629 local reported={}
18630 local function report_issue(i,what,step,kind)
18631 report("rule %i in step %i of %s has %s lookups",i,step,what,kind)
18632 end
18633 for s=1,#allsteps do
18634 local step=allsteps[s]
18635 local rules=step.rules
18636 if rules then
18637 for i=1,#rules do
18638 local rule=rules[i]
18639 local rlookups=rule.lookups
18640 if not rlookups then
18641 report_issue(i,what,s,"no")
18642 elseif not next(rlookups) then
18643 rule.lookups=nil
18644 else
18645 local length=#rlookups
18646 for index=1,length do
18647 local lookuplist=rlookups[index]
18648 if lookuplist then
18649 local length=#lookuplist
18650 local found={}
18651 local noffound=0
18652 for index=1,length do
18653 local lookupid=lookuplist[index]
18654 if lookupid then
18655 local h=sublookuphash[lookupid]
18656 if not h then
18657 local lookup=lookups[lookupid]
18658 if lookup then
18659 local d=lookup.done
18660 if d then
18661 nofsublookups=nofsublookups+1
18662 local l={
18663 index=nofsublookups,
18664 name=f_lookupname(lookupprefix,"d",lookupid+lookupidoffset),
18665 derived=true,
18666 steps=d.steps,
18667 nofsteps=d.nofsteps,
18668 type=d.lookuptype or "gsub_single",
18669 markclass=d.markclass or nil,
18670 flags=d.flags,
18671 }
18672 sublookuplist[nofsublookups]=copy(l)
18673 sublookuphash[lookupid]=nofsublookups
18674 sublookupcheck[lookupid]=1
18675 h=nofsublookups
18676 else
18677 report_issue(i,what,s,"missing")
18678 rule.lookups=nil
18679 break
18680 end
18681 else
18682 report_issue(i,what,s,"bad")
18683 rule.lookups=nil
18684 break
18685 end
18686 else
18687 sublookupcheck[lookupid]=sublookupcheck[lookupid]+1
18688 end
18689 if h then
18690 noffound=noffound+1
18691 found[noffound]=h
18692 end
18693 end
18694 end
18695 rlookups[index]=noffound>0 and found or false
18696 else
18697 rlookups[index]=false
18698 end
18699 end
18700 end
18701 end
18702 end
18703 end
18704 for i,n in sortedhash(sublookupcheck) do
18705 local l=lookups[i]
18706 local t=l.type
18707 if n==0 and t~="extension" then
18708 local d=l.done
18709 report("%s lookup %s of type %a is not used",what,d and d.name or l.name,t)
18710 end
18711 end
18712 end
18713 local function loadvariations(f,fontdata,variationsoffset,lookuptypes,featurehash,featureorder)
18714 setposition(f,variationsoffset)
18715 local version=readulong(f)
18716 local nofrecords=readulong(f)
18717 local records={}
18718 for i=1,nofrecords do
18719 records[i]={
18720 conditions=readulong(f),
18721 substitutions=readulong(f),
18722 }
18723 end
18724 for i=1,nofrecords do
18725 local record=records[i]
18726 local offset=record.conditions
18727 if offset==0 then
18728 record.condition=nil
18729 record.matchtype="always"
18730 else
18731 local offset=variationsoffset+offset
18732 setposition(f,offset)
18733 local nofconditions=readushort(f)
18734 local conditions={}
18735 for i=1,nofconditions do
18736 conditions[i]=offset+readulong(f)
18737 end
18738 record.conditions=conditions
18739 record.matchtype="condition"
18740 end
18741 end
18742 for i=1,nofrecords do
18743 local record=records[i]
18744 if record.matchtype=="condition" then
18745 local conditions=record.conditions
18746 for i=1,#conditions do
18747 setposition(f,conditions[i])
18748 conditions[i]={
18749 format=readushort(f),
18750 axis=readushort(f),
18751 minvalue=read2dot14(f),
18752 maxvalue=read2dot14(f),
18753 }
18754 end
18755 end
18756 end
18757 for i=1,nofrecords do
18758 local record=records[i]
18759 local offset=record.substitutions
18760 if offset==0 then
18761 record.substitutions={}
18762 else
18763 setposition(f,variationsoffset+offset)
18764 local version=readulong(f)
18765 local nofsubstitutions=readushort(f)
18766 local substitutions={}
18767 for i=1,nofsubstitutions do
18768 substitutions[readushort(f)]=readulong(f)
18769 end
18770 for index,alternates in sortedhash(substitutions) do
18771 if index==0 then
18772 record.substitutions=false
18773 else
18774 local tableoffset=variationsoffset+offset+alternates
18775 setposition(f,tableoffset)
18776 local parameters=readulong(f)
18777 local noflookups=readushort(f)
18778 local lookups=readcardinaltable(f,noflookups,ushort)
18779 record.substitutions=lookups
18780 end
18781 end
18782 end
18783 end
18784 setvariabledata(fontdata,"features",records)
18785 end
18786 local function readscripts(f,fontdata,what,lookuptypes,lookuphandlers,lookupstoo)
18787 local tableoffset=gotodatatable(f,fontdata,what,true)
18788 if tableoffset then
18789 local version=readulong(f)
18790 local scriptoffset=tableoffset+readushort(f)
18791 local featureoffset=tableoffset+readushort(f)
18792 local lookupoffset=tableoffset+readushort(f)
18793 local variationsoffset=version>0x00010000 and readulong(f) or 0
18794 if not scriptoffset then
18795 return
18796 end
18797 local scripts=readscriplan(f,fontdata,scriptoffset)
18798 local features=readfeatures(f,fontdata,featureoffset)
18799 local scriptlangs,featurehash,featureorder=reorderfeatures(fontdata,scripts,features)
18800 if fontdata.features then
18801 fontdata.features[what]=scriptlangs
18802 else
18803 fontdata.features={ [what]=scriptlangs }
18804 end
18805 if not lookupstoo then
18806 return
18807 end
18808 local nofmarkclasses=(fontdata.markclasses and #fontdata.markclasses or 0)-(fontdata.marksets and #fontdata.marksets or 0)
18809 local lookups=readlookups(f,lookupoffset,lookuptypes,featurehash,featureorder,nofmarkclasses)
18810 if lookups then
18811 resolvelookups(f,lookupoffset,fontdata,lookups,lookuptypes,lookuphandlers,what,tableoffset)
18812 end
18813 if variationsoffset>0 then
18814 loadvariations(f,fontdata,tableoffset+variationsoffset,lookuptypes,featurehash,featureorder)
18815 end
18816 end
18817 end
18818 local function checkkerns(f,fontdata,specification)
18819 local datatable=fontdata.tables.kern
18820 if not datatable then
18821 return
18822 end
18823 local features=fontdata.features
18824 local gposfeatures=features and features.gpos
18825 local name
18826 if not gposfeatures or not gposfeatures.kern then
18827 name="kern"
18828 elseif specification.globalkerns then
18829 name="globalkern"
18830 else
18831 report("ignoring global kern table, using gpos kern feature")
18832 return
18833 end
18834 setposition(f,datatable.offset)
18835 local version=readushort(f)
18836 local noftables=readushort(f)
18837 if noftables>1 then
18838 report("adding global kern table as gpos feature %a",name)
18839 local kerns=setmetatableindex("table")
18840 for i=1,noftables do
18841 local version=readushort(f)
18842 local length=readushort(f)
18843 local coverage=readushort(f)
18844 local format=rshift(coverage,8)
18845 if format==0 then
18846 local nofpairs=readushort(f)
18847 local searchrange=readushort(f)
18848 local entryselector=readushort(f)
18849 local rangeshift=readushort(f)
18850 for i=1,nofpairs do
18851 kerns[readushort(f)][readushort(f)]=readfword(f)
18852 end
18853 elseif format==2 then
18854 else
18855 end
18856 end
18857 local feature={ dflt={ dflt=true } }
18858 if not features then
18859 fontdata.features={ gpos={ [name]=feature } }
18860 elseif not gposfeatures then
18861 fontdata.features.gpos={ [name]=feature }
18862 else
18863 gposfeatures[name]=feature
18864 end
18865 local sequences=fontdata.sequences
18866 if not sequences then
18867 sequences={}
18868 fontdata.sequences=sequences
18869 end
18870 local nofsequences=#sequences+1
18871 sequences[nofsequences]={
18872 index=nofsequences,
18873 name=name,
18874 steps={
18875 {
18876 coverage=kerns,
18877 format="kern",
18878 },
18879 },
18880 nofsteps=1,
18881 type="gpos_pair",
18882 flags={ false,false,false,false },
18883 order={ name },
18884 features={ [name]=feature },
18885 }
18886 else
18887 report("ignoring empty kern table of feature %a",name)
18888 end
18889 end
18890 function readers.gsub(f,fontdata,specification)
18891 if specification.details then
18892 readscripts(f,fontdata,"gsub",gsubtypes,gsubhandlers,specification.lookups)
18893 end
18894 end
18895 function readers.gpos(f,fontdata,specification)
18896 if specification.details then
18897 readscripts(f,fontdata,"gpos",gpostypes,gposhandlers,specification.lookups)
18898 if specification.lookups then
18899 checkkerns(f,fontdata,specification)
18900 end
18901 end
18902 end
18903 end
18904 function readers.gdef(f,fontdata,specification)
18905 if not specification.glyphs then
18906 return
18907 end
18908 local datatable=fontdata.tables.gdef
18909 if datatable then
18910 local tableoffset=datatable.offset
18911 setposition(f,tableoffset)
18912 local version=readulong(f)
18913 local classoffset=readushort(f)
18914 local attachmentoffset=readushort(f)
18915 local ligaturecarets=readushort(f)
18916 local markclassoffset=readushort(f)
18917 local marksetsoffset=version>=0x00010002 and readushort(f) or 0
18918 local varsetsoffset=version>=0x00010003 and readulong(f) or 0
18919 local glyphs=fontdata.glyphs
18920 local marks={}
18921 local markclasses=setmetatableindex("table")
18922 local marksets=setmetatableindex("table")
18923 fontdata.marks=marks
18924 fontdata.markclasses=markclasses
18925 fontdata.marksets=marksets
18926 if classoffset~=0 then
18927 setposition(f,tableoffset+classoffset)
18928 local classformat=readushort(f)
18929 if classformat==1 then
18930 local firstindex=readushort(f)
18931 local lastindex=firstindex+readushort(f)-1
18932 for index=firstindex,lastindex do
18933 local class=classes[readushort(f)]
18934 if class=="mark" then
18935 marks[index]=true
18936 end
18937 glyphs[index].class=class
18938 end
18939 elseif classformat==2 then
18940 local nofranges=readushort(f)
18941 for i=1,nofranges do
18942 local firstindex=readushort(f)
18943 local lastindex=readushort(f)
18944 local class=classes[readushort(f)]
18945 if class then
18946 for index=firstindex,lastindex do
18947 glyphs[index].class=class
18948 if class=="mark" then
18949 marks[index]=true
18950 end
18951 end
18952 end
18953 end
18954 end
18955 end
18956 if markclassoffset~=0 then
18957 setposition(f,tableoffset+markclassoffset)
18958 local classformat=readushort(f)
18959 if classformat==1 then
18960 local firstindex=readushort(f)
18961 local lastindex=firstindex+readushort(f)-1
18962 for index=firstindex,lastindex do
18963 markclasses[readushort(f)][index]=true
18964 end
18965 elseif classformat==2 then
18966 local nofranges=readushort(f)
18967 for i=1,nofranges do
18968 local firstindex=readushort(f)
18969 local lastindex=readushort(f)
18970 local class=markclasses[readushort(f)]
18971 for index=firstindex,lastindex do
18972 class[index]=true
18973 end
18974 end
18975 end
18976 end
18977 if marksetsoffset~=0 then
18978 local nofmarkclasses=fontdata.markclasses and #fontdata.markclasses or 0
18979 marksetsoffset=tableoffset+marksetsoffset
18980 setposition(f,marksetsoffset)
18981 local format=readushort(f)
18982 if format==1 then
18983 local nofsets=readushort(f)
18984 local sets=readcardinaltable(f,nofsets,ulong)
18985 for i=1,nofsets do
18986 local offset=sets[i]
18987 if offset~=0 then
18988 markclasses[nofmarkclasses+i]=readcoverage(f,marksetsoffset+offset)
18989 marksets[i]={}
18990 end
18991 end
18992 end
18993 end
18994 local factors=specification.factors
18995 if (specification.variable or factors) and varsetsoffset~=0 then
18996 local regions,deltas=readvariationdata(f,tableoffset+varsetsoffset,factors)
18997 if factors then
18998 fontdata.temporary.getdelta=function(outer,inner)
18999 local delta=deltas[outer+1]
19000 if delta then
19001 local d=delta.deltas[inner+1]
19002 if d then
19003 local scales=delta.scales
19004 local dd=0
19005 for i=1,#scales do
19006 local di=d[i]
19007 if di then
19008 dd=dd+scales[i]*di
19009 else
19010 break
19011 end
19012 end
19013 return round(dd)
19014 end
19015 end
19016 return 0
19017 end
19018 end
19019 end
19020 end
19021 end
19022 local function readmathvalue(f)
19023 local v=readshort(f)
19024 skipshort(f,1)
19025 return v
19026 end
19027 local function readmathconstants(f,fontdata,offset)
19028 setposition(f,offset)
19029 fontdata.mathconstants={
19030 ScriptPercentScaleDown=readshort(f),
19031 ScriptScriptPercentScaleDown=readshort(f),
19032 DelimitedSubFormulaMinHeight=readushort(f),
19033 DisplayOperatorMinHeight=readushort(f),
19034 MathLeading=readmathvalue(f),
19035 AxisHeight=readmathvalue(f),
19036 AccentBaseHeight=readmathvalue(f),
19037 FlattenedAccentBaseHeight=readmathvalue(f),
19038 SubscriptShiftDown=readmathvalue(f),
19039 SubscriptTopMax=readmathvalue(f),
19040 SubscriptBaselineDropMin=readmathvalue(f),
19041 SuperscriptShiftUp=readmathvalue(f),
19042 SuperscriptShiftUpCramped=readmathvalue(f),
19043 SuperscriptBottomMin=readmathvalue(f),
19044 SuperscriptBaselineDropMax=readmathvalue(f),
19045 SubSuperscriptGapMin=readmathvalue(f),
19046 SuperscriptBottomMaxWithSubscript=readmathvalue(f),
19047 SpaceAfterScript=readmathvalue(f),
19048 UpperLimitGapMin=readmathvalue(f),
19049 UpperLimitBaselineRiseMin=readmathvalue(f),
19050 LowerLimitGapMin=readmathvalue(f),
19051 LowerLimitBaselineDropMin=readmathvalue(f),
19052 StackTopShiftUp=readmathvalue(f),
19053 StackTopDisplayStyleShiftUp=readmathvalue(f),
19054 StackBottomShiftDown=readmathvalue(f),
19055 StackBottomDisplayStyleShiftDown=readmathvalue(f),
19056 StackGapMin=readmathvalue(f),
19057 StackDisplayStyleGapMin=readmathvalue(f),
19058 StretchStackTopShiftUp=readmathvalue(f),
19059 StretchStackBottomShiftDown=readmathvalue(f),
19060 StretchStackGapAboveMin=readmathvalue(f),
19061 StretchStackGapBelowMin=readmathvalue(f),
19062 FractionNumeratorShiftUp=readmathvalue(f),
19063 FractionNumeratorDisplayStyleShiftUp=readmathvalue(f),
19064 FractionDenominatorShiftDown=readmathvalue(f),
19065 FractionDenominatorDisplayStyleShiftDown=readmathvalue(f),
19066 FractionNumeratorGapMin=readmathvalue(f),
19067 FractionNumeratorDisplayStyleGapMin=readmathvalue(f),
19068 FractionRuleThickness=readmathvalue(f),
19069 FractionDenominatorGapMin=readmathvalue(f),
19070 FractionDenominatorDisplayStyleGapMin=readmathvalue(f),
19071 SkewedFractionHorizontalGap=readmathvalue(f),
19072 SkewedFractionVerticalGap=readmathvalue(f),
19073 OverbarVerticalGap=readmathvalue(f),
19074 OverbarRuleThickness=readmathvalue(f),
19075 OverbarExtraAscender=readmathvalue(f),
19076 UnderbarVerticalGap=readmathvalue(f),
19077 UnderbarRuleThickness=readmathvalue(f),
19078 UnderbarExtraDescender=readmathvalue(f),
19079 RadicalVerticalGap=readmathvalue(f),
19080 RadicalDisplayStyleVerticalGap=readmathvalue(f),
19081 RadicalRuleThickness=readmathvalue(f),
19082 RadicalExtraAscender=readmathvalue(f),
19083 RadicalKernBeforeDegree=readmathvalue(f),
19084 RadicalKernAfterDegree=readmathvalue(f),
19085 RadicalDegreeBottomRaisePercent=readshort(f),
19086 }
19087 end
19088 local function readmathglyphinfo(f,fontdata,offset)
19089 setposition(f,offset)
19090 local italics=readushort(f)
19091 local accents=readushort(f)
19092 local extensions=readushort(f)
19093 local kerns=readushort(f)
19094 local glyphs=fontdata.glyphs
19095 if italics~=0 then
19096 setposition(f,offset+italics)
19097 local coverage=readushort(f)
19098 local nofglyphs=readushort(f)
19099 coverage=readcoverage(f,offset+italics+coverage,true)
19100 setposition(f,offset+italics+4)
19101 for i=1,nofglyphs do
19102 local italic=readmathvalue(f)
19103 if italic~=0 then
19104 local glyph=glyphs[coverage[i]]
19105 local math=glyph.math
19106 if not math then
19107 glyph.math={ italic=italic }
19108 else
19109 math.italic=italic
19110 end
19111 end
19112 end
19113 fontdata.hasitalics=true
19114 end
19115 if accents~=0 then
19116 setposition(f,offset+accents)
19117 local coverage=readushort(f)
19118 local nofglyphs=readushort(f)
19119 coverage=readcoverage(f,offset+accents+coverage,true)
19120 setposition(f,offset+accents+4)
19121 for i=1,nofglyphs do
19122 local accent=readmathvalue(f)
19123 if accent~=0 then
19124 local glyph=glyphs[coverage[i]]
19125 local math=glyph.math
19126 if not math then
19127 glyph.math={ accent=accent }
19128 else
19129 math.accent=accent
19130 end
19131 end
19132 end
19133 end
19134 if extensions~=0 then
19135 setposition(f,offset+extensions)
19136 end
19137 if kerns~=0 then
19138 local kernoffset=offset+kerns
19139 setposition(f,kernoffset)
19140 local coverage=readushort(f)
19141 local nofglyphs=readushort(f)
19142 if nofglyphs>0 then
19143 local function get(offset)
19144 setposition(f,kernoffset+offset)
19145 local n=readushort(f)
19146 if n==0 then
19147 local k=readmathvalue(f)
19148 if k==0 then
19149 else
19150 return { { kern=k } }
19151 end
19152 else
19153 local l={}
19154 for i=1,n do
19155 l[i]={ height=readmathvalue(f) }
19156 end
19157 for i=1,n do
19158 l[i].kern=readmathvalue(f)
19159 end
19160 l[n+1]={ kern=readmathvalue(f) }
19161 return l
19162 end
19163 end
19164 local kernsets={}
19165 for i=1,nofglyphs do
19166 local topright=readushort(f)
19167 local topleft=readushort(f)
19168 local bottomright=readushort(f)
19169 local bottomleft=readushort(f)
19170 kernsets[i]={
19171 topright=topright~=0 and topright or nil,
19172 topleft=topleft~=0 and topleft or nil,
19173 bottomright=bottomright~=0 and bottomright or nil,
19174 bottomleft=bottomleft~=0 and bottomleft or nil,
19175 }
19176 end
19177 coverage=readcoverage(f,kernoffset+coverage,true)
19178 for i=1,nofglyphs do
19179 local kernset=kernsets[i]
19180 if next(kernset) then
19181 local k=kernset.topright if k then kernset.topright=get(k) end
19182 local k=kernset.topleft if k then kernset.topleft=get(k) end
19183 local k=kernset.bottomright if k then kernset.bottomright=get(k) end
19184 local k=kernset.bottomleft if k then kernset.bottomleft=get(k) end
19185 if next(kernset) then
19186 local glyph=glyphs[coverage[i]]
19187 local math=glyph.math
19188 if math then
19189 math.kerns=kernset
19190 else
19191 glyph.math={ kerns=kernset }
19192 end
19193 end
19194 end
19195 end
19196 end
19197 end
19198 end
19199 local function readmathvariants(f,fontdata,offset)
19200 setposition(f,offset)
19201 local glyphs=fontdata.glyphs
19202 local minoverlap=readushort(f)
19203 local vcoverage=readushort(f)
19204 local hcoverage=readushort(f)
19205 local vnofglyphs=readushort(f)
19206 local hnofglyphs=readushort(f)
19207 local vconstruction=readcardinaltable(f,vnofglyphs,ushort)
19208 local hconstruction=readcardinaltable(f,hnofglyphs,ushort)
19209 fontdata.mathconstants.MinConnectorOverlap=minoverlap
19210 local function get(offset,coverage,nofglyphs,construction,kvariants,kparts,kitalic,korientation,orientation)
19211 if coverage~=0 and nofglyphs>0 then
19212 local coverage=readcoverage(f,offset+coverage,true)
19213 for i=1,nofglyphs do
19214 local c=construction[i]
19215 if c~=0 then
19216 local index=coverage[i]
19217 local glyph=glyphs[index]
19218 local math=glyph.math
19219 setposition(f,offset+c)
19220 local assembly=readushort(f)
19221 local nofvariants=readushort(f)
19222 if nofvariants>0 then
19223 local variants,v=nil,0
19224 for i=1,nofvariants do
19225 local variant=readushort(f)
19226 if variant==index then
19227 elseif variants then
19228 v=v+1
19229 variants[v]=variant
19230 else
19231 v=1
19232 variants={ variant }
19233 end
19234 skipshort(f)
19235 end
19236 if not variants then
19237 elseif not math then
19238 math={ [kvariants]=variants }
19239 glyph.math=math
19240 else
19241 math[kvariants]=variants
19242 end
19243 end
19244 if assembly~=0 then
19245 setposition(f,offset+c+assembly)
19246 local italic=readmathvalue(f)
19247 local nofparts=readushort(f)
19248 local parts={}
19249 for i=1,nofparts do
19250 local p={
19251 glyph=readushort(f),
19252 start=readushort(f),
19253 ["end"]=readushort(f),
19254 advance=readushort(f),
19255 }
19256 local flags=readushort(f)
19257 if band(flags,0x0001)~=0 then
19258 p.extender=1
19259 end
19260 parts[i]=p
19261 end
19262 if not math then
19263 math={
19264 [kparts]=parts
19265 }
19266 glyph.math=math
19267 else
19268 math[kparts]=parts
19269 end
19270 if italic and italic~=0 then
19271 math[kitalic]=italic
19272 end
19273 if orientation then
19274 math[korientation]=orientation
19275 end
19276 end
19277 end
19278 end
19279 end
19280 end
19281 if CONTEXTLMTXMODE and CONTEXTLMTXMODE>0 then
19282 get(offset,hcoverage,hnofglyphs,hconstruction,"variants","parts","partsitalic","partsorientation","horizontal")
19283 get(offset,vcoverage,vnofglyphs,vconstruction,"variants","parts","partsitalic","partsorientation","vertical")
19284 else
19285 get(offset,vcoverage,vnofglyphs,vconstruction,"vvariants","vparts","vitalic")
19286 get(offset,hcoverage,hnofglyphs,hconstruction,"hvariants","hparts","hitalic")
19287 end
19288 end
19289 function readers.math(f,fontdata,specification)
19290 local tableoffset=gotodatatable(f,fontdata,"math",specification.glyphs)
19291 if tableoffset then
19292 local version=readulong(f)
19293 local constants=readushort(f)
19294 local glyphinfo=readushort(f)
19295 local variants=readushort(f)
19296 if constants==0 then
19297 report("the math table of %a has no constants",fontdata.filename)
19298 else
19299 readmathconstants(f,fontdata,tableoffset+constants)
19300 end
19301 if glyphinfo~=0 then
19302 readmathglyphinfo(f,fontdata,tableoffset+glyphinfo)
19303 end
19304 if variants~=0 then
19305 readmathvariants(f,fontdata,tableoffset+variants)
19306 end
19307 end
19308 end
19309 function readers.colr(f,fontdata,specification)
19310 local tableoffset=gotodatatable(f,fontdata,"colr",specification.glyphs)
19311 if tableoffset then
19312 local version=readushort(f)
19313 if version~=0 and version~=1 then
19314 report("table version %a of %a is not supported (yet), maybe font %s is bad",version,"colr",fontdata.filename)
19315 return
19316 else
19317 end
19318 if not fontdata.tables.cpal then
19319 report("color table %a in font %a has no mandate %a table","colr",fontdata.filename,"cpal")
19320 fontdata.colorpalettes={}
19321 end
19322 local glyphs=fontdata.glyphs
19323 local nofglyphs=readushort(f)
19324 local baseoffset=readulong(f)
19325 local layeroffset=readulong(f)
19326 local noflayers=readushort(f)
19327 local layerrecords={}
19328 local maxclass=0
19329 setposition(f,tableoffset+layeroffset)
19330 for i=1,noflayers do
19331 local slot=readushort(f)
19332 local class=readushort(f)
19333 if class<0xFFFF then
19334 class=class+1
19335 if class>maxclass then
19336 maxclass=class
19337 end
19338 end
19339 layerrecords[i]={
19340 slot=slot,
19341 class=class,
19342 }
19343 end
19344 fontdata.maxcolorclass=maxclass
19345 setposition(f,tableoffset+baseoffset)
19346 for i=0,nofglyphs-1 do
19347 local glyphindex=readushort(f)
19348 local firstlayer=readushort(f)
19349 local noflayers=readushort(f)
19350 local t={}
19351 for i=1,noflayers do
19352 t[i]=layerrecords[firstlayer+i]
19353 end
19354 glyphs[glyphindex].colors=t
19355 end
19356 end
19357 fontdata.hascolor=true
19358 end
19359 function readers.cpal(f,fontdata,specification)
19360 local tableoffset=gotodatatable(f,fontdata,"cpal",specification.glyphs)
19361 if tableoffset then
19362 local version=readushort(f)
19363 local nofpaletteentries=readushort(f)
19364 local nofpalettes=readushort(f)
19365 local nofcolorrecords=readushort(f)
19366 local firstcoloroffset=readulong(f)
19367 local colorrecords={}
19368 local palettes=readcardinaltable(f,nofpalettes,ushort)
19369 if version==1 then
19370 local palettettypesoffset=readulong(f)
19371 local palettelabelsoffset=readulong(f)
19372 local paletteentryoffset=readulong(f)
19373 end
19374 setposition(f,tableoffset+firstcoloroffset)
19375 for i=1,nofcolorrecords do
19376 local b,g,r,a=readbytes(f,4)
19377 colorrecords[i]={
19378 r,g,b,a~=255 and a or nil,
19379 }
19380 end
19381 for i=1,nofpalettes do
19382 local p={}
19383 local o=palettes[i]
19384 for j=1,nofpaletteentries do
19385 p[j]=colorrecords[o+j]
19386 end
19387 palettes[i]=p
19388 end
19389 fontdata.colorpalettes=palettes
19390 end
19391 end
19392 local compress=gzip and gzip.compress
19393 local compressed=compress and gzip.compressed
19394 function readers.svg(f,fontdata,specification)
19395 local tableoffset=gotodatatable(f,fontdata,"svg",specification.glyphs)
19396 if tableoffset then
19397 local version=readushort(f)
19398 local glyphs=fontdata.glyphs
19399 local indexoffset=tableoffset+readulong(f)
19400 local reserved=readulong(f)
19401 setposition(f,indexoffset)
19402 local nofentries=readushort(f)
19403 local entries={}
19404 for i=1,nofentries do
19405 entries[i]={
19406 first=readushort(f),
19407 last=readushort(f),
19408 offset=indexoffset+readulong(f),
19409 length=readulong(f),
19410 }
19411 end
19412 for i=1,nofentries do
19413 local entry=entries[i]
19414 setposition(f,entry.offset)
19415 local data=readstring(f,entry.length)
19416 if compressed and not compressed(data) then
19417 data=compress(data)
19418 end
19419 entries[i]={
19420 first=entry.first,
19421 last=entry.last,
19422 data=data
19423 }
19424 end
19425 fontdata.svgshapes=entries
19426 end
19427 fontdata.hascolor=true
19428 end
19429 function readers.sbix(f,fontdata,specification)
19430 local tableoffset=gotodatatable(f,fontdata,"sbix",specification.glyphs)
19431 if tableoffset then
19432 local version=readushort(f)
19433 local flags=readushort(f)
19434 local nofstrikes=readulong(f)
19435 local strikes={}
19436 local nofglyphs=fontdata.nofglyphs
19437 for i=1,nofstrikes do
19438 strikes[i]=readulong(f)
19439 end
19440 local shapes={}
19441 local done=0
19442 for i=1,nofstrikes do
19443 local strikeoffset=strikes[i]+tableoffset
19444 setposition(f,strikeoffset)
19445 strikes[i]={
19446 ppem=readushort(f),
19447 ppi=readushort(f),
19448 offset=strikeoffset
19449 }
19450 end
19451 sort(strikes,function(a,b)
19452 if b.ppem==a.ppem then
19453 return b.ppi<a.ppi
19454 else
19455 return b.ppem<a.ppem
19456 end
19457 end)
19458 local glyphs={}
19459 local delayed=CONTEXTLMTXMODE and CONTEXTLMTXMODE>0 or fonts.handlers.typethree
19460 for i=1,nofstrikes do
19461 local strike=strikes[i]
19462 local strikeppem=strike.ppem
19463 local strikeppi=strike.ppi
19464 local strikeoffset=strike.offset
19465 setposition(f,strikeoffset)
19466 for i=0,nofglyphs do
19467 glyphs[i]=readulong(f)
19468 end
19469 local glyphoffset=glyphs[0]
19470 for i=0,nofglyphs-1 do
19471 local nextoffset=glyphs[i+1]
19472 if not shapes[i] then
19473 local datasize=nextoffset-glyphoffset
19474 if datasize>0 then
19475 setposition(f,strikeoffset+glyphoffset)
19476 local x=readshort(f)
19477 local y=readshort(f)
19478 local tag=readtag(f)
19479 local size=datasize-8
19480 local data=nil
19481 local offset=nil
19482 if delayed then
19483 offset=getposition(f)
19484 data=nil
19485 else
19486 data=readstring(f,size)
19487 size=nil
19488 end
19489 shapes[i]={
19490 x=x,
19491 y=y,
19492 o=offset,
19493 s=size,
19494 data=data,
19495 }
19496 done=done+1
19497 if done==nofglyphs then
19498 break
19499 end
19500 end
19501 end
19502 glyphoffset=nextoffset
19503 end
19504 end
19505 fontdata.pngshapes=shapes
19506 end
19507 end
19508 do
19509 local function getmetrics(f)
19510 return {
19511 ascender=readinteger(f),
19512 descender=readinteger(f),
19513 widthmax=readuinteger(f),
19514 caretslopedumerator=readinteger(f),
19515 caretslopedenominator=readinteger(f),
19516 caretoffset=readinteger(f),
19517 minorigin=readinteger(f),
19518 minadvance=readinteger(f),
19519 maxbefore=readinteger(f),
19520 minafter=readinteger(f),
19521 pad1=readinteger(f),
19522 pad2=readinteger(f),
19523 }
19524 end
19525 local function getbigmetrics(f)
19526 return {
19527 height=readuinteger(f),
19528 width=readuinteger(f),
19529 horiBearingX=readinteger(f),
19530 horiBearingY=readinteger(f),
19531 horiAdvance=readuinteger(f),
19532 vertBearingX=readinteger(f),
19533 vertBearingY=readinteger(f),
19534 vertAdvance=readuinteger(f),
19535 }
19536 end
19537 local function getsmallmetrics(f)
19538 return {
19539 height=readuinteger(f),
19540 width=readuinteger(f),
19541 bearingX=readinteger(f),
19542 bearingY=readinteger(f),
19543 advance=readuinteger(f),
19544 }
19545 end
19546 function readers.cblc(f,fontdata,specification)
19547 local ctdttableoffset=gotodatatable(f,fontdata,"cbdt",specification.glyphs)
19548 if not ctdttableoffset then
19549 return
19550 end
19551 local cblctableoffset=gotodatatable(f,fontdata,"cblc",specification.glyphs)
19552 if cblctableoffset then
19553 local majorversion=readushort(f)
19554 local minorversion=readushort(f)
19555 local nofsizetables=readulong(f)
19556 local sizetables={}
19557 local shapes={}
19558 local subtables={}
19559 for i=1,nofsizetables do
19560 sizetables[i]={
19561 subtables=readulong(f),
19562 indexsize=readulong(f),
19563 nofsubtables=readulong(f),
19564 colorref=readulong(f),
19565 hormetrics=getmetrics(f),
19566 vermetrics=getmetrics(f),
19567 firstindex=readushort(f),
19568 lastindex=readushort(f),
19569 ppemx=readbyte(f),
19570 ppemy=readbyte(f),
19571 bitdepth=readbyte(f),
19572 flags=readbyte(f),
19573 }
19574 end
19575 sort(sizetables,function(a,b)
19576 if b.ppemx==a.ppemx then
19577 return b.bitdepth<a.bitdepth
19578 else
19579 return b.ppemx<a.ppemx
19580 end
19581 end)
19582 for i=1,nofsizetables do
19583 local s=sizetables[i]
19584 local d=false
19585 for j=s.firstindex,s.lastindex do
19586 if not shapes[j] then
19587 shapes[j]=i
19588 d=true
19589 end
19590 end
19591 if d then
19592 s.used=true
19593 end
19594 end
19595 for i=1,nofsizetables do
19596 local s=sizetables[i]
19597 if s.used then
19598 local offset=s.subtables
19599 setposition(f,cblctableoffset+offset)
19600 for j=1,s.nofsubtables do
19601 local firstindex=readushort(f)
19602 local lastindex=readushort(f)
19603 local tableoffset=readulong(f)+offset
19604 for k=firstindex,lastindex do
19605 if shapes[k]==i then
19606 local s=subtables[tableoffset]
19607 if not s then
19608 s={
19609 firstindex=firstindex,
19610 lastindex=lastindex,
19611 }
19612 subtables[tableoffset]=s
19613 end
19614 shapes[k]=s
19615 end
19616 end
19617 end
19618 end
19619 end
19620 for offset,subtable in sortedhash(subtables) do
19621 local tabletype=readushort(f)
19622 subtable.format=readushort(f)
19623 local baseoffset=readulong(f)+ctdttableoffset
19624 local offsets={}
19625 local metrics=nil
19626 if tabletype==1 then
19627 for i=subtable.firstindex,subtable.lastindex do
19628 offsets[i]=readulong(f)+baseoffset
19629 end
19630 skipbytes(f,4)
19631 elseif tabletype==2 then
19632 local size=readulong(f)
19633 local done=baseoffset
19634 metrics=getbigmetrics(f)
19635 for i=subtable.firstindex,subtable.lastindex do
19636 offsets[i]=done
19637 done=done+size
19638 end
19639 elseif tabletype==3 then
19640 local n=subtable.lastindex-subtable.firstindex+2
19641 for i=subtable.firstindex,subtable.lastindex do
19642 offsets[i]=readushort(f)+baseoffset
19643 end
19644 if math.odd(n) then
19645 skipbytes(f,4)
19646 else
19647 skipbytes(f,2)
19648 end
19649 elseif tabletype==4 then
19650 for i=1,readulong(f) do
19651 offsets[readushort(f)]=readushort(f)+baseoffset
19652 end
19653 elseif tabletype==5 then
19654 local size=readulong(f)
19655 local done=baseoffset
19656 metrics=getbigmetrics(f)
19657 local n=readulong(f)
19658 for i=1,n do
19659 offsets[readushort(f)]=done
19660 done=done+size
19661 end
19662 if math.odd(n) then
19663 skipbytes(f,2)
19664 end
19665 else
19666 return
19667 end
19668 subtable.offsets=offsets
19669 subtable.metrics=metrics
19670 end
19671 local default={ width=0,height=0 }
19672 local glyphs=fontdata.glyphs
19673 local delayed=CONTEXTLMTXMODE and CONTEXTLMTXMODE>0 or fonts.handlers.typethree
19674 for index,subtable in sortedhash(shapes) do
19675 if type(subtable)=="table" then
19676 local data=nil
19677 local size=nil
19678 local metrics=default
19679 local format=subtable.format
19680 local offset=subtable.offsets[index]
19681 setposition(f,offset)
19682 if format==17 then
19683 metrics=getsmallmetrics(f)
19684 size=true
19685 elseif format==18 then
19686 metrics=getbigmetrics(f)
19687 size=true
19688 elseif format==19 then
19689 metrics=subtable.metrics
19690 size=true
19691 else
19692 end
19693 if size then
19694 size=readulong(f)
19695 if delayed then
19696 offset=getposition(f)
19697 data=nil
19698 else
19699 offset=nil
19700 data=readstring(f,size)
19701 size=nil
19702 end
19703 else
19704 offset=nil
19705 end
19706 local x=metrics.width
19707 local y=metrics.height
19708 shapes[index]={
19709 x=x,
19710 y=y,
19711 o=offset,
19712 s=size,
19713 data=data,
19714 }
19715 local glyph=glyphs[index]
19716 if not glyph.boundingbox then
19717 local width=glyph.width
19718 local height=width*y/x
19719 glyph.boundingbox={ 0,0,width,height }
19720 end
19721 else
19722 shapes[index]={
19723 x=0,
19724 y=0,
19725 data="",
19726 }
19727 end
19728 end
19729 fontdata.pngshapes=shapes
19730 end
19731 end
19732 function readers.cbdt(f,fontdata,specification)
19733 end
19734 end
19735 function readers.stat(f,fontdata,specification)
19736 local tableoffset=gotodatatable(f,fontdata,"stat",true)
19737 if tableoffset then
19738 local extras=fontdata.extras
19739 local version=readulong(f)
19740 local axissize=readushort(f)
19741 local nofaxis=readushort(f)
19742 local axisoffset=readulong(f)
19743 local nofvalues=readushort(f)
19744 local valuesoffset=readulong(f)
19745 local fallbackname=extras[readushort(f)]
19746 local axis={}
19747 local values={}
19748 setposition(f,tableoffset+axisoffset)
19749 for i=1,nofaxis do
19750 local tag=readtag(f)
19751 axis[i]={
19752 tag=tag,
19753 name=lower(extras[readushort(f)] or tag),
19754 ordering=readushort(f),
19755 variants={}
19756 }
19757 end
19758 setposition(f,tableoffset+valuesoffset)
19759 for i=1,nofvalues do
19760 values[i]=readushort(f)
19761 end
19762 for i=1,nofvalues do
19763 setposition(f,tableoffset+valuesoffset+values[i])
19764 local format=readushort(f)
19765 local index=readushort(f)+1
19766 local flags=readushort(f)
19767 local name=lower(extras[readushort(f)] or "no name")
19768 local value=readfixed(f)
19769 local variant
19770 if format==1 then
19771 variant={
19772 flags=flags,
19773 name=name,
19774 value=value,
19775 }
19776 elseif format==2 then
19777 variant={
19778 flags=flags,
19779 name=name,
19780 value=value,
19781 minimum=readfixed(f),
19782 maximum=readfixed(f),
19783 }
19784 elseif format==3 then
19785 variant={
19786 flags=flags,
19787 name=name,
19788 value=value,
19789 link=readfixed(f),
19790 }
19791 end
19792 insert(axis[index].variants,variant)
19793 end
19794 sort(axis,function(a,b)
19795 return a.ordering<b.ordering
19796 end)
19797 for i=1,#axis do
19798 local a=axis[i]
19799 sort(a.variants,function(a,b)
19800 return a.name<b.name
19801 end)
19802 a.ordering=nil
19803 end
19804 setvariabledata(fontdata,"designaxis",axis)
19805 setvariabledata(fontdata,"fallbackname",fallbackname)
19806 end
19807 end
19808 function readers.avar(f,fontdata,specification)
19809 local tableoffset=gotodatatable(f,fontdata,"avar",true)
19810 if tableoffset then
19811 local function collect()
19812 local nofvalues=readushort(f)
19813 local values={}
19814 local lastfrom=false
19815 local lastto=false
19816 for i=1,nofvalues do
19817 local from=read2dot14(f)
19818 local to=read2dot14(f)
19819 if lastfrom and from<=lastfrom then
19820 elseif lastto and to>=lastto then
19821 else
19822 values[#values+1]={ from,to }
19823 lastfrom,lastto=from,to
19824 end
19825 end
19826 nofvalues=#values
19827 if nofvalues>2 then
19828 local some=values[1]
19829 if some[1]==-1 and some[2]==-1 then
19830 some=values[nofvalues]
19831 if some[1]==1 and some[2]==1 then
19832 for i=2,nofvalues-1 do
19833 some=values[i]
19834 if some[1]==0 and some[2]==0 then
19835 return values
19836 end
19837 end
19838 end
19839 end
19840 end
19841 return false
19842 end
19843 local version=readulong(f)
19844 local reserved=readushort(f)
19845 local nofaxis=readushort(f)
19846 local segments={}
19847 for i=1,nofaxis do
19848 segments[i]=collect()
19849 end
19850 setvariabledata(fontdata,"segments",segments)
19851 end
19852 end
19853 function readers.fvar(f,fontdata,specification)
19854 local tableoffset=gotodatatable(f,fontdata,"fvar",true)
19855 if tableoffset then
19856 local version=readulong(f)
19857 local offsettoaxis=tableoffset+readushort(f)
19858 local reserved=skipshort(f)
19859 local nofaxis=readushort(f)
19860 local sizeofaxis=readushort(f)
19861 local nofinstances=readushort(f)
19862 local sizeofinstances=readushort(f)
19863 local extras=fontdata.extras
19864 local axis={}
19865 local instances={}
19866 setposition(f,offsettoaxis)
19867 for i=1,nofaxis do
19868 axis[i]={
19869 tag=readtag(f),
19870 minimum=readfixed(f),
19871 default=readfixed(f),
19872 maximum=readfixed(f),
19873 flags=readushort(f),
19874 name=lower(extras[readushort(f)] or "bad name"),
19875 }
19876 local n=sizeofaxis-20
19877 if n>0 then
19878 skipbytes(f,n)
19879 elseif n<0 then
19880 end
19881 end
19882 local nofbytes=2+2+2+nofaxis*4
19883 local readpsname=nofbytes<=sizeofinstances
19884 local skippable=sizeofinstances-nofbytes
19885 for i=1,nofinstances do
19886 local subfamid=readushort(f)
19887 local flags=readushort(f)
19888 local values={}
19889 for i=1,nofaxis do
19890 values[i]={
19891 axis=axis[i].tag,
19892 value=readfixed(f),
19893 }
19894 end
19895 local psnameid=readpsname and readushort(f) or 0xFFFF
19896 if subfamid==2 or subfamid==17 then
19897 elseif subfamid==0xFFFF then
19898 subfamid=nil
19899 elseif subfamid<=256 or subfamid>=32768 then
19900 subfamid=nil
19901 end
19902 if psnameid==6 then
19903 elseif psnameid==0xFFFF then
19904 psnameid=nil
19905 elseif psnameid<=256 or psnameid>=32768 then
19906 psnameid=nil
19907 end
19908 instances[i]={
19909 subfamily=extras[subfamid],
19910 psname=psnameid and extras[psnameid] or nil,
19911 values=values,
19912 }
19913 if skippable>0 then
19914 skipbytes(f,skippable)
19915 end
19916 end
19917 setvariabledata(fontdata,"axis",axis)
19918 setvariabledata(fontdata,"instances",instances)
19919 end
19920 end
19921 function readers.hvar(f,fontdata,specification)
19922 local factors=specification.factors
19923 if not factors then
19924 return
19925 end
19926 local tableoffset=gotodatatable(f,fontdata,"hvar",specification.variable)
19927 if not tableoffset then
19928 return
19929 end
19930 local version=readulong(f)
19931 local variationoffset=tableoffset+readulong(f)
19932 local advanceoffset=tableoffset+readulong(f)
19933 local lsboffset=tableoffset+readulong(f)
19934 local rsboffset=tableoffset+readulong(f)
19935 local regions={}
19936 local variations={}
19937 local innerindex={}
19938 local outerindex={}
19939 local deltas={}
19940 if variationoffset>0 then
19941 regions,deltas=readvariationdata(f,variationoffset,factors)
19942 end
19943 if not regions then
19944 return
19945 end
19946 if advanceoffset>0 then
19947 setposition(f,advanceoffset)
19948 local format=readushort(f)
19949 local mapcount=readushort(f)
19950 local entrysize=rshift(band(format,0x0030),4)+1
19951 local nofinnerbits=band(format,0x000F)+1
19952 local innermask=lshift(1,nofinnerbits)-1
19953 local readcardinal=read_cardinal[entrysize]
19954 for i=0,mapcount-1 do
19955 local mapdata=readcardinal(f)
19956 outerindex[i]=rshift(mapdata,nofinnerbits)
19957 innerindex[i]=band(mapdata,innermask)
19958 end
19959 setvariabledata(fontdata,"hvarwidths",true)
19960 local glyphs=fontdata.glyphs
19961 for i=0,fontdata.nofglyphs-1 do
19962 local glyph=glyphs[i]
19963 local width=glyph.width
19964 if width then
19965 local outer=outerindex[i] or 0
19966 local inner=innerindex[i] or i
19967 if outer and inner then
19968 local delta=deltas[outer+1]
19969 if delta then
19970 local d=delta.deltas[inner+1]
19971 if d then
19972 local scales=delta.scales
19973 local deltaw=0
19974 for i=1,#scales do
19975 local di=d[i]
19976 if di then
19977 deltaw=deltaw+scales[i]*di
19978 else
19979 break
19980 end
19981 end
19982 glyph.width=width+round(deltaw)
19983 end
19984 end
19985 end
19986 end
19987 end
19988 end
19989 end
19990 function readers.vvar(f,fontdata,specification)
19991 if not specification.variable then
19992 return
19993 end
19994 end
19995 function readers.mvar(f,fontdata,specification)
19996 local tableoffset=gotodatatable(f,fontdata,"mvar",specification.variable)
19997 if tableoffset then
19998 local version=readulong(f)
19999 local reserved=skipshort(f,1)
20000 local recordsize=readushort(f)
20001 local nofrecords=readushort(f)
20002 local offsettostore=tableoffset+readushort(f)
20003 local dimensions={}
20004 local factors=specification.factors
20005 if factors then
20006 local regions,deltas=readvariationdata(f,offsettostore,factors)
20007 for i=1,nofrecords do
20008 local tag=readtag(f)
20009 local var=variabletags[tag]
20010 if var then
20011 local outer=readushort(f)
20012 local inner=readushort(f)
20013 local delta=deltas[outer+1]
20014 if delta then
20015 local d=delta.deltas[inner+1]
20016 if d then
20017 local scales=delta.scales
20018 local dd=0
20019 for i=1,#scales do
20020 dd=dd+scales[i]*d[i]
20021 end
20022 var(fontdata,round(dd))
20023 end
20024 end
20025 else
20026 skipshort(f,2)
20027 end
20028 if recordsize>8 then
20029 skipbytes(recordsize-8)
20030 end
20031 end
20032 end
20033 end
20034 end
20035
20036 end -- closure
20037
20038 do -- begin closure to overcome local limits and interference
20039
20040 if not modules then modules={} end modules ['font-oti']={
20041 version=1.001,
20042 comment="companion to font-ini.mkiv",
20043 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
20044 copyright="PRAGMA ADE / ConTeXt Development Team",
20045 license="see context related readme files"
20046 }
20047 local lower=string.lower
20048 local fonts=fonts
20049 local constructors=fonts.constructors
20050 local otf=constructors.handlers.otf
20051 local otffeatures=constructors.features.otf
20052 local registerotffeature=otffeatures.register
20053 local otftables=otf.tables or {}
20054 otf.tables=otftables
20055 local allocate=utilities.storage.allocate
20056 registerotffeature {
20057 name="features",
20058 description="initialization of feature handler",
20059 default=true,
20060 }
20061 local function setmode(tfmdata,value)
20062 if value then
20063 tfmdata.properties.mode=lower(value)
20064 end
20065 end
20066 otf.modeinitializer=setmode
20067 local function setlanguage(tfmdata,value)
20068 if value then
20069 local cleanvalue=lower(value)
20070 local languages=otftables and otftables.languages
20071 local properties=tfmdata.properties
20072 if not languages then
20073 properties.language=cleanvalue
20074 elseif languages[value] then
20075 properties.language=cleanvalue
20076 else
20077 properties.language="dflt"
20078 end
20079 end
20080 end
20081 local function setscript(tfmdata,value)
20082 if value then
20083 local cleanvalue=lower(value)
20084 local scripts=otftables and otftables.scripts
20085 local properties=tfmdata.properties
20086 if not scripts then
20087 properties.script=cleanvalue
20088 elseif scripts[value] then
20089 properties.script=cleanvalue
20090 else
20091 properties.script="dflt"
20092 end
20093 end
20094 end
20095 registerotffeature {
20096 name="mode",
20097 description="mode",
20098 initializers={
20099 base=setmode,
20100 node=setmode,
20101 plug=setmode,
20102 }
20103 }
20104 registerotffeature {
20105 name="language",
20106 description="language",
20107 initializers={
20108 base=setlanguage,
20109 node=setlanguage,
20110 plug=setlanguage,
20111 }
20112 }
20113 registerotffeature {
20114 name="script",
20115 description="script",
20116 initializers={
20117 base=setscript,
20118 node=setscript,
20119 plug=setscript,
20120 }
20121 }
20122 otftables.featuretypes=allocate {
20123 gpos_single="position",
20124 gpos_pair="position",
20125 gpos_cursive="position",
20126 gpos_mark2base="position",
20127 gpos_mark2ligature="position",
20128 gpos_mark2mark="position",
20129 gpos_context="position",
20130 gpos_contextchain="position",
20131 gsub_single="substitution",
20132 gsub_multiple="substitution",
20133 gsub_alternate="substitution",
20134 gsub_ligature="substitution",
20135 gsub_context="substitution",
20136 gsub_contextchain="substitution",
20137 gsub_reversecontextchain="substitution",
20138 gsub_reversesub="substitution",
20139 }
20140 function otffeatures.checkeddefaultscript(featuretype,autoscript,scripts)
20141 if featuretype=="position" then
20142 local default=scripts.dflt
20143 if default then
20144 if autoscript=="position" or autoscript==true then
20145 return default
20146 else
20147 report_otf("script feature %s not applied, enable default positioning")
20148 end
20149 else
20150 end
20151 elseif featuretype=="substitution" then
20152 local default=scripts.dflt
20153 if default then
20154 if autoscript=="substitution" or autoscript==true then
20155 return default
20156 end
20157 end
20158 end
20159 end
20160 function otffeatures.checkeddefaultlanguage(featuretype,autolanguage,languages)
20161 if featuretype=="position" then
20162 local default=languages.dflt
20163 if default then
20164 if autolanguage=="position" or autolanguage==true then
20165 return default
20166 else
20167 report_otf("language feature %s not applied, enable default positioning")
20168 end
20169 else
20170 end
20171 elseif featuretype=="substitution" then
20172 local default=languages.dflt
20173 if default then
20174 if autolanguage=="substitution" or autolanguage==true then
20175 return default
20176 end
20177 end
20178 end
20179 end
20180
20181 end -- closure
20182
20183 do -- begin closure to overcome local limits and interference
20184
20185 if not modules then modules={} end modules ["font-ott"]={
20186 version=1.001,
20187 comment="companion to font-ini.mkiv",
20188 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
20189 copyright="PRAGMA ADE / ConTeXt Development Team",
20190 license="see context related readme files",
20191 }
20192 local type,next,tonumber,tostring,rawget,rawset=type,next,tonumber,tostring,rawget,rawset
20193 local gsub,lower,format,match,gmatch,find=string.gsub,string.lower,string.format,string.match,string.gmatch,string.find
20194 local sequenced=table.sequenced
20195 local is_boolean=string.is_boolean
20196 local setmetatableindex=table.setmetatableindex
20197 local setmetatablenewindex=table.setmetatablenewindex
20198 local allocate=utilities.storage.allocate
20199 local fonts=fonts
20200 local otf=fonts.handlers.otf
20201 local otffeatures=otf.features
20202 local tables=otf.tables or {}
20203 otf.tables=tables
20204 local statistics=otf.statistics or {}
20205 otf.statistics=statistics
20206 local scripts=allocate {
20207 ["adlm"]="adlam",
20208 ["aghb"]="caucasian albanian",
20209 ["ahom"]="ahom",
20210 ["arab"]="arabic",
20211 ["armi"]="imperial aramaic",
20212 ["armn"]="armenian",
20213 ["avst"]="avestan",
20214 ["bali"]="balinese",
20215 ["bamu"]="bamum",
20216 ["bass"]="bassa vah",
20217 ["batk"]="batak",
20218 ["beng"]="bengali",
20219 ["bhks"]="bhaiksuki",
20220 ["bng2"]="bengali variant 2",
20221 ["bopo"]="bopomofo",
20222 ["brah"]="brahmi",
20223 ["brai"]="braille",
20224 ["bugi"]="buginese",
20225 ["buhd"]="buhid",
20226 ["byzm"]="byzantine music",
20227 ["cakm"]="chakma",
20228 ["cans"]="canadian syllabics",
20229 ["cari"]="carian",
20230 ["cham"]="cham",
20231 ["cher"]="cherokee",
20232 ["chrs"]="chorasmian",
20233 ["copt"]="coptic",
20234 ["cpmn"]="cypro-minoan",
20235 ["cprt"]="cypriot syllabary",
20236 ["cyrl"]="cyrillic",
20237 ["dev2"]="devanagari variant 2",
20238 ["deva"]="devanagari",
20239 ["diak"]="dives akuru",
20240 ["dogr"]="dogra",
20241 ["dsrt"]="deseret",
20242 ["dupl"]="duployan",
20243 ["egyp"]="egyptian heiroglyphs",
20244 ["elba"]="elbasan",
20245 ["elym"]="elymaic",
20246 ["ethi"]="ethiopic",
20247 ["geor"]="georgian",
20248 ["gjr2"]="gujarati variant 2",
20249 ["glag"]="glagolitic",
20250 ["gong"]="gunjala gondi",
20251 ["gonm"]="masaram gondi",
20252 ["goth"]="gothic",
20253 ["gran"]="grantha",
20254 ["grek"]="greek",
20255 ["gujr"]="gujarati",
20256 ["gur2"]="gurmukhi variant 2",
20257 ["guru"]="gurmukhi",
20258 ["hang"]="hangul",
20259 ["hani"]="cjk ideographic",
20260 ["hano"]="hanunoo",
20261 ["hatr"]="hatran",
20262 ["hebr"]="hebrew",
20263 ["hluw"]="anatolian hieroglyphs",
20264 ["hmng"]="pahawh hmong",
20265 ["hmnp"]="nyiakeng puachue hmong",
20266 ["hung"]="old hungarian",
20267 ["ital"]="old italic",
20268 ["jamo"]="hangul jamo",
20269 ["java"]="javanese",
20270 ["kali"]="kayah li",
20271 ["kana"]="hiragana and katakana",
20272 ["khar"]="kharosthi",
20273 ["khmr"]="khmer",
20274 ["khoj"]="khojki",
20275 ["kits"]="khitan small script",
20276 ["knd2"]="kannada variant 2",
20277 ["knda"]="kannada",
20278 ["kthi"]="kaithi",
20279 ["lana"]="tai tham",
20280 ["lao" ]="lao",
20281 ["latn"]="latin",
20282 ["lepc"]="lepcha",
20283 ["limb"]="limbu",
20284 ["lina"]="linear a",
20285 ["linb"]="linear b",
20286 ["lisu"]="lisu",
20287 ["lyci"]="lycian",
20288 ["lydi"]="lydian",
20289 ["mahj"]="mahajani",
20290 ["maka"]="makasar",
20291 ["mand"]="mandaic and mandaean",
20292 ["mani"]="manichaean",
20293 ["marc"]="marchen",
20294 ["math"]="mathematical alphanumeric symbols",
20295 ["medf"]="medefaidrin",
20296 ["mend"]="mende kikakui",
20297 ["merc"]="meroitic cursive",
20298 ["mero"]="meroitic hieroglyphs",
20299 ["mlm2"]="malayalam variant 2",
20300 ["mlym"]="malayalam",
20301 ["modi"]="modi",
20302 ["mong"]="mongolian",
20303 ["mroo"]="mro",
20304 ["mtei"]="meitei Mayek",
20305 ["mult"]="multani",
20306 ["musc"]="musical symbols",
20307 ["mym2"]="myanmar variant 2",
20308 ["mymr"]="myanmar",
20309 ["nand"]="nandinagari",
20310 ["narb"]="old north arabian",
20311 ["nbat"]="nabataean",
20312 ["newa"]="newa",
20313 ["nko" ]='n"ko',
20314 ["nshu"]="nüshu",
20315 ["ogam"]="ogham",
20316 ["olck"]="ol chiki",
20317 ["orkh"]="old turkic and orkhon runic",
20318 ["ory2"]="odia variant 2",
20319 ["orya"]="odia",
20320 ["osge"]="osage",
20321 ["osma"]="osmanya",
20322 ["ougr"]="old uyghur",
20323 ["palm"]="palmyrene",
20324 ["pauc"]="pau cin hau",
20325 ["perm"]="old permic",
20326 ["phag"]="phags-pa",
20327 ["phli"]="inscriptional pahlavi",
20328 ["phlp"]="psalter pahlavi",
20329 ["phnx"]="phoenician",
20330 ["plrd"]="miao",
20331 ["prti"]="inscriptional parthian",
20332 ["rjng"]="rejang",
20333 ["rohg"]="hanifi rohingya",
20334 ["runr"]="runic",
20335 ["samr"]="samaritan",
20336 ["sarb"]="old south arabian",
20337 ["saur"]="saurashtra",
20338 ["sgnw"]="sign writing",
20339 ["shaw"]="shavian",
20340 ["shrd"]="sharada",
20341 ["sidd"]="siddham",
20342 ["sind"]="khudawadi",
20343 ["sinh"]="sinhala",
20344 ["sogd"]="sogdian",
20345 ["sogo"]="old sogdian",
20346 ["sora"]="sora sompeng",
20347 ["soyo"]="soyombo",
20348 ["sund"]="sundanese",
20349 ["sylo"]="syloti nagri",
20350 ["syrc"]="syriac",
20351 ["tagb"]="tagbanwa",
20352 ["takr"]="takri",
20353 ["tale"]="tai le",
20354 ["talu"]="new tai lue",
20355 ["taml"]="tamil",
20356 ["tang"]="tangut",
20357 ["tavt"]="tai viet",
20358 ["tel2"]="telugu variant 2",
20359 ["telu"]="telugu",
20360 ["tfng"]="tifinagh",
20361 ["tglg"]="tagalog",
20362 ["thaa"]="thaana",
20363 ["thai"]="thai",
20364 ["tibt"]="tibetan",
20365 ["tirh"]="tirhuta",
20366 ["tnsa"]="tangsa",
20367 ["tml2"]="tamil variant 2",
20368 ["toto"]="toto",
20369 ["ugar"]="ugaritic cuneiform",
20370 ["vai" ]="vai",
20371 ["wara"]="warang citi",
20372 ["wcho"]="wancho",
20373 ["xpeo"]="old persian cuneiform",
20374 ["xsux"]="sumero-akkadian cuneiform",
20375 ["yezi"]="yezidi",
20376 ["yi" ]="yi",
20377 ["zanb"]="zanabazar square",
20378 }
20379 local languages=allocate {
20380 ["aba" ]="abaza",
20381 ["abk" ]="abkhazian",
20382 ["ach" ]="acholi",
20383 ["acr" ]="achi",
20384 ["ady" ]="adyghe",
20385 ["afk" ]="afrikaans",
20386 ["afr" ]="afar",
20387 ["agw" ]="agaw",
20388 ["aio" ]="aiton",
20389 ["aka" ]="akan",
20390 ["akb" ]="batak angkola",
20391 ["als" ]="alsatian",
20392 ["alt" ]="altai",
20393 ["amh" ]="amharic",
20394 ["ang" ]="anglo-saxon",
20395 ["apph"]="phonetic transcription—americanist conventions",
20396 ["ara" ]="arabic",
20397 ["arg" ]="aragonese",
20398 ["ari" ]="aari",
20399 ["ark" ]="rakhine",
20400 ["asm" ]="assamese",
20401 ["ast" ]="asturian",
20402 ["ath" ]="athapaskan",
20403 ["avn" ]="avatime",
20404 ["avr" ]="avar",
20405 ["awa" ]="awadhi",
20406 ["aym" ]="aymara",
20407 ["azb" ]="torki",
20408 ["aze" ]="azerbaijani",
20409 ["bad" ]="badaga",
20410 ["bad0"]="banda",
20411 ["bag" ]="baghelkhandi",
20412 ["bal" ]="balkar",
20413 ["ban" ]="balinese",
20414 ["bar" ]="bavarian",
20415 ["bau" ]="baulé",
20416 ["bbc" ]="batak toba",
20417 ["bbr" ]="berber",
20418 ["bch" ]="bench",
20419 ["bcr" ]="bible cree",
20420 ["bdy" ]="bandjalang",
20421 ["bel" ]="belarussian",
20422 ["bem" ]="bemba",
20423 ["ben" ]="bengali",
20424 ["bgc" ]="haryanvi",
20425 ["bgq" ]="bagri",
20426 ["bgr" ]="bulgarian",
20427 ["bhi" ]="bhili",
20428 ["bho" ]="bhojpuri",
20429 ["bik" ]="bikol",
20430 ["bil" ]="bilen",
20431 ["bis" ]="bislama",
20432 ["bjj" ]="kanauji",
20433 ["bkf" ]="blackfoot",
20434 ["bli" ]="baluchi",
20435 ["blk" ]="pa'o karen",
20436 ["bln" ]="balante",
20437 ["blt" ]="balti",
20438 ["bmb" ]="bambara (bamanankan)",
20439 ["bml" ]="bamileke",
20440 ["bos" ]="bosnian",
20441 ["bpy" ]="bishnupriya manipuri",
20442 ["bre" ]="breton",
20443 ["brh" ]="brahui",
20444 ["bri" ]="braj bhasha",
20445 ["brm" ]="burmese",
20446 ["brx" ]="bodo",
20447 ["bsh" ]="bashkir",
20448 ["bsk" ]="burushaski",
20449 ["bta" ]="batak alas kluet",
20450 ["btd" ]="batak dairi (pakpak)",
20451 ["bti" ]="beti",
20452 ["btm" ]="batak mandailing",
20453 ["bts" ]="batak simalungun",
20454 ["btx" ]="batak karo",
20455 ["bug" ]="bugis",
20456 ["byv" ]="medumba",
20457 ["cak" ]="kaqchikel",
20458 ["cat" ]="catalan",
20459 ["cbk" ]="zamboanga chavacano",
20460 ["cchn"]="chinantec",
20461 ["ceb" ]="cebuano",
20462 ["cgg" ]="chiga",
20463 ["cha" ]="chamorro",
20464 ["che" ]="chechen",
20465 ["chg" ]="chaha gurage",
20466 ["chh" ]="chattisgarhi",
20467 ["chi" ]="chichewa (chewa, nyanja)",
20468 ["chk" ]="chukchi",
20469 ["chk0"]="chuukese",
20470 ["cho" ]="choctaw",
20471 ["chp" ]="chipewyan",
20472 ["chr" ]="cherokee",
20473 ["chu" ]="chuvash",
20474 ["chy" ]="cheyenne",
20475 ["cja" ]="western cham",
20476 ["cjm" ]="eastern cham",
20477 ["cmr" ]="comorian",
20478 ["cop" ]="coptic",
20479 ["cor" ]="cornish",
20480 ["cos" ]="corsican",
20481 ["cpp" ]="creoles",
20482 ["cre" ]="cree",
20483 ["crr" ]="carrier",
20484 ["crt" ]="crimean tatar",
20485 ["csb" ]="kashubian",
20486 ["csl" ]="church slavonic",
20487 ["csy" ]="czech",
20488 ["ctg" ]="chittagonian",
20489 ["ctt" ]="wayanad chetti",
20490 ["cuk" ]="san blas kuna",
20491 ["dag" ]="dagbani",
20492 ["dan" ]="danish",
20493 ["dar" ]="dargwa",
20494 ["dax" ]="dayi",
20495 ["dcr" ]="woods cree",
20496 ["deu" ]="german",
20497 ["dgo" ]="dogri (individual language)",
20498 ["dgr" ]="dogri (macro language)",
20499 ["dhg" ]="dhangu",
20500 ["dhv" ]="divehi (dhivehi, maldivian)",
20501 ["diq" ]="dimli",
20502 ["div" ]="divehi (dhivehi, maldivian)",
20503 ["djr" ]="zarma",
20504 ["djr0"]="djambarrpuyngu",
20505 ["dng" ]="dangme",
20506 ["dnj" ]="dan",
20507 ["dnk" ]="dinka",
20508 ["dri" ]="dari",
20509 ["duj" ]="dhuwal",
20510 ["dun" ]="dungan",
20511 ["dzn" ]="dzongkha",
20512 ["ebi" ]="ebira",
20513 ["ecr" ]="eastern cree",
20514 ["edo" ]="edo",
20515 ["efi" ]="efik",
20516 ["ell" ]="greek",
20517 ["emk" ]="eastern maninkakan",
20518 ["eng" ]="english",
20519 ["erz" ]="erzya",
20520 ["esp" ]="spanish",
20521 ["esu" ]="central yupik",
20522 ["eti" ]="estonian",
20523 ["euq" ]="basque",
20524 ["evk" ]="evenki",
20525 ["evn" ]="even",
20526 ["ewe" ]="ewe",
20527 ["fan" ]="french antillean",
20528 ["fan0"]=" fang",
20529 ["far" ]="persian",
20530 ["fat" ]="fanti",
20531 ["fin" ]="finnish",
20532 ["fji" ]="fijian",
20533 ["fle" ]="dutch (flemish)",
20534 ["fmp" ]="fe’fe’",
20535 ["fne" ]="forest nenets",
20536 ["fon" ]="fon",
20537 ["fos" ]="faroese",
20538 ["fra" ]="french",
20539 ["frc" ]="cajun french",
20540 ["fri" ]="frisian",
20541 ["frl" ]="friulian",
20542 ["frp" ]="arpitan",
20543 ["fta" ]="futa",
20544 ["ful" ]="fulah",
20545 ["fuv" ]="nigerian fulfulde",
20546 ["gad" ]="ga",
20547 ["gae" ]="scottish gaelic (gaelic)",
20548 ["gag" ]="gagauz",
20549 ["gal" ]="galician",
20550 ["gar" ]="garshuni",
20551 ["gaw" ]="garhwali",
20552 ["gez" ]="ge'ez",
20553 ["gih" ]="githabul",
20554 ["gil" ]="gilyak",
20555 ["gil0"]="kiribati (gilbertese)",
20556 ["gkp" ]="kpelle (guinea)",
20557 ["glk" ]="gilaki",
20558 ["gmz" ]="gumuz",
20559 ["gnn" ]="gumatj",
20560 ["gog" ]="gogo",
20561 ["gon" ]="gondi",
20562 ["grn" ]="greenlandic",
20563 ["gro" ]="garo",
20564 ["gua" ]="guarani",
20565 ["guc" ]="wayuu",
20566 ["guf" ]="gupapuyngu",
20567 ["guj" ]="gujarati",
20568 ["guz" ]="gusii",
20569 ["hai" ]="haitian (haitian creole)",
20570 ["hai0"]="haida",
20571 ["hal" ]="halam",
20572 ["har" ]="harauti",
20573 ["hau" ]="hausa",
20574 ["haw" ]="hawaiian",
20575 ["hay" ]="haya",
20576 ["haz" ]="hazaragi",
20577 ["hmz" ]="hmong shuat",
20578 ["hbn" ]="hammer-banna",
20579 ["hei" ]="heiltsuk",
20580 ["her" ]="herero",
20581 ["hil" ]="hiligaynon",
20582 ["hin" ]="hindi",
20583 ["hma" ]="high mari",
20584 ["hmn" ]="hmong",
20585 ["hmo" ]="hiri motu",
20586 ["hnd" ]="hindko",
20587 ["ho" ]="ho",
20588 ["hri" ]="harari",
20589 ["hrv" ]="croatian",
20590 ["hun" ]="hungarian",
20591 ["hye" ]="armenian",
20592 ["hye0"]="armenian east",
20593 ["iba" ]="iban",
20594 ["ibb" ]="ibibio",
20595 ["ibo" ]="igbo",
20596 ["ido" ]="ido",
20597 ["ijo" ]="ijo languages",
20598 ["ile" ]="interlingue",
20599 ["ilo" ]="ilokano",
20600 ["ina" ]="interlingua",
20601 ["ind" ]="indonesian",
20602 ["ing" ]="ingush",
20603 ["inu" ]="inuktitut",
20604 ["inuk"]="nunavik inuktitut",
20605 ["ipk" ]="inupiat",
20606 ["ipph"]="phonetic transcription—ipa conventions",
20607 ["iri" ]="irish",
20608 ["irt" ]="irish traditional",
20609 ["uri" ]="irula",
20610 ["isl" ]="icelandic",
20611 ["ism" ]="inari sami",
20612 ["ita" ]="italian",
20613 ["iwr" ]="hebrew",
20614 ["jam" ]="jamaican creole",
20615 ["jan" ]="japanese",
20616 ["jav" ]="javanese",
20617 ["jbo" ]="lojban",
20618 ["jct" ]="krymchak",
20619 ["jii" ]="yiddish",
20620 ["jud" ]="ladino",
20621 ["jul" ]="jula",
20622 ["kab" ]="kabardian",
20623 ["kab0"]="kabyle",
20624 ["kac" ]="kachchi",
20625 ["kal" ]="kalenjin",
20626 ["kan" ]="kannada",
20627 ["kar" ]="karachay",
20628 ["kat" ]="georgian",
20629 ["kaw" ]="kawi (old javanese)",
20630 ["kaz" ]="kazakh",
20631 ["kde" ]="makonde",
20632 ["kea" ]="kabuverdianu (crioulo)",
20633 ["keb" ]="kebena",
20634 ["kek" ]="kekchi",
20635 ["kge" ]="khutsuri georgian",
20636 ["kha" ]="khakass",
20637 ["khk" ]="khanty-kazim",
20638 ["khm" ]="khmer",
20639 ["khs" ]="khanty-shurishkar",
20640 ["kht" ]="khamti shan",
20641 ["khv" ]="khanty-vakhi",
20642 ["khw" ]="khowar",
20643 ["kik" ]="kikuyu (gikuyu)",
20644 ["kir" ]="kirghiz (kyrgyz)",
20645 ["kis" ]="kisii",
20646 ["kiu" ]="kirmanjki",
20647 ["kjd" ]="southern kiwai",
20648 ["kjp" ]="eastern pwo karen",
20649 ["kjz" ]="bumthangkha",
20650 ["kkn" ]="kokni",
20651 ["klm" ]="kalmyk",
20652 ["kmb" ]="kamba",
20653 ["kmn" ]="kumaoni",
20654 ["kmo" ]="komo",
20655 ["kms" ]="komso",
20656 ["kmz" ]="khorasani turkic",
20657 ["knr" ]="kanuri",
20658 ["kod" ]="kodagu",
20659 ["koh" ]="korean old hangul",
20660 ["kok" ]="konkani",
20661 ["kom" ]="komi",
20662 ["kon" ]="kikongo",
20663 ["kon0"]="kongo",
20664 ["kop" ]="komi-permyak",
20665 ["kor" ]="korean",
20666 ["kos" ]="kosraean",
20667 ["koz" ]="komi-zyrian",
20668 ["kpl" ]="kpelle",
20669 ["kri" ]="krio",
20670 ["krk" ]="karakalpak",
20671 ["krl" ]="karelian",
20672 ["krm" ]="karaim",
20673 ["krn" ]="karen",
20674 ["krt" ]="koorete",
20675 ["ksh" ]="kashmiri",
20676 ["ksh0"]="ripuarian",
20677 ["ksi" ]="khasi",
20678 ["ksm" ]="kildin sami",
20679 ["ksw" ]="s’gaw karen",
20680 ["kua" ]="kuanyama",
20681 ["kui" ]="kui",
20682 ["kul" ]="kulvi",
20683 ["kum" ]="kumyk",
20684 ["kur" ]="kurdish",
20685 ["kuu" ]="kurukh",
20686 ["kuy" ]="kuy",
20687 ["kwk" ]="kwakʼwala",
20688 ["kyk" ]="koryak",
20689 ["kyu" ]="western kayah",
20690 ["lad" ]="ladin",
20691 ["lah" ]="lahuli",
20692 ["lak" ]="lak",
20693 ["lam" ]="lambani",
20694 ["lao" ]="lao",
20695 ["lat" ]="latin",
20696 ["laz" ]="laz",
20697 ["lcr" ]="l-cree",
20698 ["ldk" ]="ladakhi",
20699 ["lef" ]="lelemi",
20700 ["lez" ]="lezgi",
20701 ["lij" ]="ligurian",
20702 ["lim" ]="limburgish",
20703 ["lin" ]="lingala",
20704 ["lis" ]="lisu",
20705 ["ljp" ]="lampung",
20706 ["lki" ]="laki",
20707 ["lma" ]="low mari",
20708 ["lmb" ]="limbu",
20709 ["lmo" ]="lombard",
20710 ["lmw" ]="lomwe",
20711 ["lom" ]="loma",
20712 ["lpo" ]="lipo",
20713 ["lrc" ]="luri",
20714 ["lsb" ]="lower sorbian",
20715 ["lsm" ]="lule sami",
20716 ["lth" ]="lithuanian",
20717 ["ltz" ]="luxembourgish",
20718 ["lua" ]="luba-lulua",
20719 ["lub" ]="luba-katanga",
20720 ["lug" ]="ganda",
20721 ["luh" ]="luyia",
20722 ["luo" ]="luo",
20723 ["lvi" ]="latvian",
20724 ["mad" ]="madura",
20725 ["mag" ]="magahi",
20726 ["mah" ]="marshallese",
20727 ["maj" ]="majang",
20728 ["mak" ]="makhuwa",
20729 ["mal" ]="malayalam",
20730 ["mam" ]="mam",
20731 ["man" ]="mansi",
20732 ["map" ]="mapudungun",
20733 ["mar" ]="marathi",
20734 ["maw" ]="marwari",
20735 ["mbn" ]="mbundu",
20736 ["mbo" ]="mbo",
20737 ["mch" ]="manchu",
20738 ["mcr" ]="moose cree",
20739 ["mde" ]="mende",
20740 ["mdr" ]="mandar",
20741 ["men" ]="me'en",
20742 ["mer" ]="meru",
20743 ["mfa" ]="pattani malay",
20744 ["mfe" ]="morisyen",
20745 ["min" ]="minangkabau",
20746 ["miz" ]="mizo",
20747 ["mkd" ]="macedonian",
20748 ["mkr" ]="makasar",
20749 ["mkw" ]="kituba",
20750 ["mle" ]="male",
20751 ["mlg" ]="malagasy",
20752 ["mln" ]="malinke",
20753 ["mlr" ]="malayalam reformed",
20754 ["mly" ]="malay",
20755 ["mnd" ]="mandinka",
20756 ["mng" ]="mongolian",
20757 ["mni" ]="manipuri",
20758 ["mnk" ]="maninka",
20759 ["mnx" ]="manx",
20760 ["moh" ]="mohawk",
20761 ["mok" ]="moksha",
20762 ["mol" ]="moldavian",
20763 ["mon" ]="mon",
20764 ["mnw" ]="thailand mon",
20765 ["mor" ]="moroccan",
20766 ["mos" ]="mossi",
20767 ["mri" ]="maori",
20768 ["mth" ]="maithili",
20769 ["mts" ]="maltese",
20770 ["mun" ]="mundari",
20771 ["mus" ]="muscogee",
20772 ["mwl" ]="mirandese",
20773 ["mww" ]="hmong daw",
20774 ["myn" ]="mayan",
20775 ["mzn" ]="mazanderani",
20776 ["nag" ]="naga-assamese",
20777 ["nah" ]="nahuatl",
20778 ["nan" ]="nanai",
20779 ["nap" ]="neapolitan",
20780 ["nas" ]="naskapi",
20781 ["nau" ]="nauruan",
20782 ["nav" ]="navajo",
20783 ["ncr" ]="n-cree",
20784 ["ndb" ]="ndebele",
20785 ["ndc" ]="ndau",
20786 ["ndg" ]="ndonga",
20787 ["nds" ]="low saxon",
20788 ["nep" ]="nepali",
20789 ["new" ]="newari",
20790 ["nga" ]="ngbaka",
20791 ["ngr" ]="nagari",
20792 ["nhc" ]="norway house cree",
20793 ["nis" ]="nisi",
20794 ["niu" ]="niuean",
20795 ["nkl" ]="nyankole",
20796 ["nko" ]="n'ko",
20797 ["nld" ]="dutch",
20798 ["noe" ]="nimadi",
20799 ["nog" ]="nogai",
20800 ["nor" ]="norwegian",
20801 ["nov" ]="novial",
20802 ["nsm" ]="northern sami",
20803 ["nso" ]="northern sotho",
20804 ["nta" ]="northern tai",
20805 ["nto" ]="esperanto",
20806 ["nym" ]="nyamwezi",
20807 ["nyn" ]="norwegian nynorsk",
20808 ["nza" ]="mbembe tigon",
20809 ["oci" ]="occitan",
20810 ["ocr" ]="oji-cree",
20811 ["ojb" ]="ojibway",
20812 ["ori" ]="odia",
20813 ["oro" ]="oromo",
20814 ["oss" ]="ossetian",
20815 ["paa" ]="palestinian aramaic",
20816 ["pag" ]="pangasinan",
20817 ["pal" ]="pali",
20818 ["pam" ]="pampangan",
20819 ["pan" ]="punjabi",
20820 ["pap" ]="palpa",
20821 ["pap0"]="papiamentu",
20822 ["pas" ]="pashto",
20823 ["pau" ]="palauan",
20824 ["pcc" ]="bouyei",
20825 ["pcd" ]="picard",
20826 ["pdc" ]="pennsylvania german",
20827 ["pgr" ]="polytonic greek",
20828 ["phk" ]="phake",
20829 ["pih" ]="norfolk",
20830 ["pil" ]="filipino",
20831 ["plg" ]="palaung",
20832 ["plk" ]="polish",
20833 ["pms" ]="piemontese",
20834 ["pnb" ]="western panjabi",
20835 ["poh" ]="pocomchi",
20836 ["pon" ]="pohnpeian",
20837 ["pro" ]="provencal",
20838 ["ptg" ]="portuguese",
20839 ["pwo" ]="western pwo karen",
20840 ["qin" ]="chin",
20841 ["quc" ]="k’iche’",
20842 ["quh" ]="quechua (bolivia)",
20843 ["quz" ]="quechua",
20844 ["qvi" ]="quechua (ecuador)",
20845 ["qwh" ]="quechua (peru)",
20846 ["raj" ]="rajasthani",
20847 ["rar" ]="rarotongan",
20848 ["rbu" ]="russian buriat",
20849 ["rcr" ]="r-cree",
20850 ["rej" ]="rejang",
20851 ["rhg" ]="rohingya",
20852 ["ria" ]="riang",
20853 ["rif" ]="tarifit",
20854 ["rit" ]="ritarungo",
20855 ["rkw" ]="arakwal",
20856 ["rms" ]="romansh",
20857 ["rmy" ]="vlax romani",
20858 ["rom" ]="romanian",
20859 ["roy" ]="romany",
20860 ["rsy" ]="rusyn",
20861 ["rtm" ]="rotuman",
20862 ["rua" ]="kinyarwanda",
20863 ["run" ]="rundi",
20864 ["rup" ]="aromanian",
20865 ["rus" ]="russian",
20866 ["sad" ]="sadri",
20867 ["san" ]="sanskrit",
20868 ["sas" ]="sasak",
20869 ["sat" ]="santali",
20870 ["say" ]="sayisi",
20871 ["scn" ]="sicilian",
20872 ["sco" ]="scots",
20873 ["scs" ]="north slavey",
20874 ["sek" ]="sekota",
20875 ["sel" ]="selkup",
20876 ["sfm" ]="small flowery miao",
20877 ["sga" ]="old irish",
20878 ["sgo" ]="sango",
20879 ["sgs" ]="samogitian",
20880 ["shi" ]="tachelhit",
20881 ["shn" ]="shan",
20882 ["sib" ]="sibe",
20883 ["sid" ]="sidamo",
20884 ["sig" ]="silte gurage",
20885 ["sks" ]="skolt sami",
20886 ["sky" ]="slovak",
20887 ["sla" ]="slavey",
20888 ["slv" ]="slovenian",
20889 ["sml" ]="somali",
20890 ["smo" ]="samoan",
20891 ["sna" ]="sena",
20892 ["sna0"]="shona",
20893 ["snd" ]="sindhi",
20894 ["snh" ]="sinhala (sinhalese)",
20895 ["snk" ]="soninke",
20896 ["sog" ]="sodo gurage",
20897 ["sop" ]="songe",
20898 ["sot" ]="southern sotho",
20899 ["sqi" ]="albanian",
20900 ["srb" ]="serbian",
20901 ["srd" ]="sardinian",
20902 ["srk" ]="saraiki",
20903 ["srr" ]="serer",
20904 ["ssl" ]="south slavey",
20905 ["ssm" ]="southern sami",
20906 ["stq" ]="saterland frisian",
20907 ["suk" ]="sukuma",
20908 ["sun" ]="sundanese",
20909 ["sur" ]="suri",
20910 ["sva" ]="svan",
20911 ["sve" ]="swedish",
20912 ["swa" ]="swadaya aramaic",
20913 ["swk" ]="swahili",
20914 ["swz" ]="swati",
20915 ["sxt" ]="sutu",
20916 ["sxu" ]="upper saxon",
20917 ["syl" ]="sylheti",
20918 ["syr" ]="syriac",
20919 ["syre"]="estrangela syriac",
20920 ["syrj"]="western syriac",
20921 ["syrn"]="eastern syriac",
20922 ["szl" ]="silesian",
20923 ["tab" ]="tabasaran",
20924 ["taj" ]="tajiki",
20925 ["tam" ]="tamil",
20926 ["tat" ]="tatar",
20927 ["tcr" ]="th-cree",
20928 ["tdd" ]="dehong dai",
20929 ["tel" ]="telugu",
20930 ["tet" ]="tetum",
20931 ["tgl" ]="tagalog",
20932 ["tgn" ]="tongan",
20933 ["tgr" ]="tigre",
20934 ["tgy" ]="tigrinya",
20935 ["tha" ]="thai",
20936 ["tht" ]="tahitian",
20937 ["tib" ]="tibetan",
20938 ["tiv" ]="tiv",
20939 ["tj;" ]="tai laing",
20940 ["tkm" ]="turkmen",
20941 ["tli" ]="tlingit",
20942 ["tmh" ]="tamashek",
20943 ["tmn" ]="temne",
20944 ["tna" ]="tswana",
20945 ["tne" ]="tundra nenets",
20946 ["tng" ]="tonga",
20947 ["tod" ]="todo",
20948 ["tod0"]="toma",
20949 ["tpi" ]="tok pisin",
20950 ["trk" ]="turkish",
20951 ["tsg" ]="tsonga",
20952 ["tsj" ]="tshangla",
20953 ["tua" ]="turoyo aramaic",
20954 ["tul" ]="tulu",
20955 ["tum" ]="tumbuka",
20956 ["tuv" ]="tuvin",
20957 ["tvl" ]="tuvalu",
20958 ["twi" ]="twi",
20959 ["tyz" ]="tày",
20960 ["tzm" ]="tamazight",
20961 ["tzo" ]="tzotzil",
20962 ["udm" ]="udmurt",
20963 ["ukr" ]="ukrainian",
20964 ["umb" ]="umbundu",
20965 ["urd" ]="urdu",
20966 ["usb" ]="upper sorbian",
20967 ["uyg" ]="uyghur",
20968 ["uzb" ]="uzbek",
20969 ["vec" ]="venetian",
20970 ["ven" ]="venda",
20971 ["vit" ]="vietnamese",
20972 ["vol" ]="volapük",
20973 ["vro" ]="võro",
20974 ["wa" ]="wa",
20975 ["wag" ]="wagdi",
20976 ["war" ]="waray-waray",
20977 ["wci" ]="waci gbe",
20978 ["wcr" ]="west-cree",
20979 ["wel" ]="welsh",
20980 ["wlf" ]="wolof",
20981 ["wln" ]="walloon",
20982 ["wtm" ]="mewati",
20983 ["xbd" ]="lü",
20984 ["xhs" ]="xhosa",
20985 ["xjb" ]="minjangbal",
20986 ["xkf" ]="khengkha",
20987 ["xog" ]="soga",
20988 ["xpe" ]="kpelle (liberia)",
20989 ["xub" ]="bette kuruma",
20990 ["xuj" ]="jennu kuruma",
20991 ["yak" ]="sakha",
20992 ["yao" ]="yao",
20993 ["yap" ]="yapese",
20994 ["yba" ]="yoruba",
20995 ["ycr" ]="y-cree",
20996 ["ygp" ]="gepo",
20997 ["yic" ]="yi classic",
20998 ["yim" ]="yi modern",
20999 ["yna" ]="aluo",
21000 ["ywq" ]="wuding-luquan",
21001 ["zea" ]="zealandic",
21002 ["zgh" ]="standard morrocan tamazigh",
21003 ["zha" ]="zhuang",
21004 ["zhh" ]="chinese, hong kong sar",
21005 ["zho" ]="chinese traditional, macao",
21006 ["zhp" ]="chinese phonetic",
21007 ["zhs" ]="chinese simplified",
21008 ["zht" ]="chinese traditional",
21009 ["znd" ]="zande",
21010 ["zul" ]="zulu",
21011 ["zza" ]="zazaki",
21012 }
21013 local features=allocate {
21014 ["aalt"]="access all alternates",
21015 ["abvf"]="above-base forms",
21016 ["abvm"]="above-base mark positioning",
21017 ["abvs"]="above-base substitutions",
21018 ["afrc"]="alternative fractions",
21019 ["akhn"]="akhands",
21020 ["blwf"]="below-base forms",
21021 ["blwm"]="below-base mark positioning",
21022 ["blws"]="below-base substitutions",
21023 ["c2pc"]="petite capitals from capitals",
21024 ["c2sc"]="small capitals from capitals",
21025 ["calt"]="contextual alternates",
21026 ["case"]="case-sensitive forms",
21027 ["ccmp"]="glyph composition/decomposition",
21028 ["cfar"]="conjunct form after ro",
21029 ["chws"]="contextual half-width spacing",
21030 ["cjct"]="conjunct forms",
21031 ["clig"]="contextual ligatures",
21032 ["cpct"]="centered cjk punctuation",
21033 ["cpsp"]="capital spacing",
21034 ["cswh"]="contextual swash",
21035 ["curs"]="cursive positioning",
21036 ["dflt"]="default processing",
21037 ["dist"]="distances",
21038 ["dlig"]="discretionary ligatures",
21039 ["dnom"]="denominators",
21040 ["dtls"]="dotless forms",
21041 ["expt"]="expert forms",
21042 ["falt"]="final glyph alternates",
21043 ["fin2"]="terminal forms #2",
21044 ["fin3"]="terminal forms #3",
21045 ["fina"]="terminal forms",
21046 ["flac"]="flattened accents over capitals",
21047 ["frac"]="fractions",
21048 ["fwid"]="full width",
21049 ["half"]="half forms",
21050 ["haln"]="halant forms",
21051 ["halt"]="alternate half width",
21052 ["hist"]="historical forms",
21053 ["hkna"]="horizontal kana alternates",
21054 ["hlig"]="historical ligatures",
21055 ["hngl"]="hangul",
21056 ["hojo"]="hojo kanji forms",
21057 ["hwid"]="half width",
21058 ["init"]="initial forms",
21059 ["isol"]="isolated forms",
21060 ["ital"]="italics",
21061 ["jalt"]="justification alternatives",
21062 ["jp04"]="jis2004 forms",
21063 ["jp78"]="jis78 forms",
21064 ["jp83"]="jis83 forms",
21065 ["jp90"]="jis90 forms",
21066 ["kern"]="kerning",
21067 ["lfbd"]="left bounds",
21068 ["liga"]="standard ligatures",
21069 ["ljmo"]="leading jamo forms",
21070 ["lnum"]="lining figures",
21071 ["locl"]="localized forms",
21072 ["ltra"]="left-to-right alternates",
21073 ["ltrm"]="left-to-right mirrored forms",
21074 ["mark"]="mark positioning",
21075 ["med2"]="medial forms #2",
21076 ["medi"]="medial forms",
21077 ["mgrk"]="mathematical greek",
21078 ["mkmk"]="mark to mark positioning",
21079 ["mset"]="mark positioning via substitution",
21080 ["nalt"]="alternate annotation forms",
21081 ["nlck"]="nlc kanji forms",
21082 ["nukt"]="nukta forms",
21083 ["numr"]="numerators",
21084 ["onum"]="old style figures",
21085 ["opbd"]="optical bounds",
21086 ["ordn"]="ordinals",
21087 ["ornm"]="ornaments",
21088 ["palt"]="proportional alternate width",
21089 ["pcap"]="petite capitals",
21090 ["pkna"]="proportional kana",
21091 ["pnum"]="proportional figures",
21092 ["pref"]="pre-base forms",
21093 ["pres"]="pre-base substitutions",
21094 ["pstf"]="post-base forms",
21095 ["psts"]="post-base substitutions",
21096 ["pwid"]="proportional widths",
21097 ["qwid"]="quarter widths",
21098 ["rand"]="randomize",
21099 ["rclt"]="required contextual alternates",
21100 ["rkrf"]="rakar forms",
21101 ["rlig"]="required ligatures",
21102 ["rphf"]="reph form",
21103 ["rtbd"]="right bounds",
21104 ["rtla"]="right-to-left alternates",
21105 ["rtlm"]="right to left mirrored forms",
21106 ["ruby"]="ruby notation forms",
21107 ["rvrn"]="required variation alternates",
21108 ["salt"]="stylistic alternates",
21109 ["sinf"]="scientific inferiors",
21110 ["size"]="optical size",
21111 ["smcp"]="small capitals",
21112 ["smpl"]="simplified forms",
21113 ["ssty"]="script style",
21114 ["stch"]="stretching glyph decomposition",
21115 ["subs"]="subscript",
21116 ["sups"]="superscript",
21117 ["swsh"]="swash",
21118 ["titl"]="titling",
21119 ["tjmo"]="trailing jamo forms",
21120 ["tnam"]="traditional name forms",
21121 ["tnum"]="tabular figures",
21122 ["trad"]="traditional forms",
21123 ["twid"]="third widths",
21124 ["unic"]="unicase",
21125 ["valt"]="alternate vertical metrics",
21126 ["vatu"]="vattu variants",
21127 ["vchw"]="vertical contextual half-width spacing",
21128 ["vert"]="vertical writing",
21129 ["vhal"]="alternate vertical half metrics",
21130 ["vjmo"]="vowel jamo forms",
21131 ["vkna"]="vertical kana alternates",
21132 ["vkrn"]="vertical kerning",
21133 ["vpal"]="proportional alternate vertical metrics",
21134 ["vrtr"]="vertical alternates for rotation",
21135 ["vrt2"]="vertical rotation",
21136 ["zero"]="slashed zero",
21137 ["trep"]="traditional tex replacements",
21138 ["tlig"]="traditional tex ligatures",
21139 ["ss.."]="stylistic set ..",
21140 ["cv.."]="character variant ..",
21141 ["js.."]="justification ..",
21142 ["dv.."]="devanagari ..",
21143 ["ml.."]="malayalam ..",
21144 }
21145 local baselines=allocate {
21146 ["hang"]="hanging baseline",
21147 ["icfb"]="ideographic character face bottom edge baseline",
21148 ["icft"]="ideographic character face tope edige baseline",
21149 ["ideo"]="ideographic em-box bottom edge baseline",
21150 ["idtp"]="ideographic em-box top edge baseline",
21151 ["math"]="mathematical centered baseline",
21152 ["romn"]="roman baseline"
21153 }
21154 tables.scripts=scripts
21155 tables.languages=languages
21156 tables.features=features
21157 tables.baselines=baselines
21158 local acceptscripts=true directives.register("otf.acceptscripts",function(v) acceptscripts=v end)
21159 local acceptlanguages=true directives.register("otf.acceptlanguages",function(v) acceptlanguages=v end)
21160 local report_checks=logs.reporter("fonts","checks")
21161 if otffeatures.features then
21162 for k,v in next,otffeatures.features do
21163 features[k]=v
21164 end
21165 otffeatures.features=features
21166 end
21167 local function swapped(h)
21168 local r={}
21169 for k,v in next,h do
21170 r[gsub(v,"[^a-z0-9]","")]=k
21171 end
21172 return r
21173 end
21174 local verbosescripts=allocate(swapped(scripts ))
21175 local verboselanguages=allocate(swapped(languages))
21176 local verbosefeatures=allocate(swapped(features ))
21177 local verbosebaselines=allocate(swapped(baselines))
21178 local function resolve(t,k)
21179 if k then
21180 k=gsub(lower(k),"[^a-z0-9]","")
21181 local v=rawget(t,k)
21182 if v then
21183 return v
21184 end
21185 end
21186 end
21187 setmetatableindex(verbosescripts,resolve)
21188 setmetatableindex(verboselanguages,resolve)
21189 setmetatableindex(verbosefeatures,resolve)
21190 setmetatableindex(verbosebaselines,resolve)
21191 setmetatableindex(scripts,function(t,k)
21192 if k then
21193 k=lower(k)
21194 if k=="dflt" then
21195 return k
21196 end
21197 local v=rawget(t,k)
21198 if v then
21199 return v
21200 end
21201 k=gsub(k," ","")
21202 v=rawget(t,v)
21203 if v then
21204 return v
21205 elseif acceptscripts then
21206 report_checks("registering extra script %a",k)
21207 rawset(t,k,k)
21208 return k
21209 end
21210 end
21211 return "dflt"
21212 end)
21213 setmetatableindex(languages,function(t,k)
21214 if k then
21215 k=lower(k)
21216 if k=="dflt" then
21217 return k
21218 end
21219 local v=rawget(t,k)
21220 if v then
21221 return v
21222 end
21223 k=gsub(k," ","")
21224 v=rawget(t,v)
21225 if v then
21226 return v
21227 elseif acceptlanguages then
21228 report_checks("registering extra language %a",k)
21229 rawset(t,k,k)
21230 return k
21231 end
21232 end
21233 return "dflt"
21234 end)
21235 if setmetatablenewindex then
21236 setmetatablenewindex(languages,"ignore")
21237 setmetatablenewindex(scripts,"ignore")
21238 setmetatablenewindex(baselines,"ignore")
21239 end
21240 local function resolve(t,k)
21241 if k then
21242 k=lower(k)
21243 local v=rawget(t,k)
21244 if v then
21245 return v
21246 end
21247 k=gsub(k," ","")
21248 local v=rawget(t,k)
21249 if v then
21250 return v
21251 end
21252 local tag,dd=match(k,"(..)(%d+)")
21253 if tag and dd then
21254 local v=rawget(t,tag)
21255 if v then
21256 return v
21257 else
21258 local v=rawget(t,tag.."..")
21259 if v then
21260 return (gsub(v,"%.%.",tonumber(dd)))
21261 end
21262 end
21263 end
21264 end
21265 return k
21266 end
21267 setmetatableindex(features,resolve)
21268 local function assign(t,k,v)
21269 if k and v then
21270 v=lower(v)
21271 rawset(t,k,v)
21272 end
21273 end
21274 if setmetatablenewindex then
21275 setmetatablenewindex(features,assign)
21276 end
21277 local checkers={
21278 rand=function(v)
21279 return v==true and "random" or v
21280 end
21281 }
21282 if not storage then
21283 return
21284 end
21285 local usedfeatures=statistics.usedfeatures or {}
21286 statistics.usedfeatures=usedfeatures
21287 table.setmetatableindex(usedfeatures,function(t,k) if k then local v={} t[k]=v return v end end)
21288 storage.register("fonts/otf/usedfeatures",usedfeatures,"fonts.handlers.otf.statistics.usedfeatures" )
21289 local normalizedaxis=otf.readers.helpers.normalizedaxis or function(s) return s end
21290 function otffeatures.normalize(features,wrap)
21291 if features then
21292 local h={}
21293 for key,value in next,features do
21294 local k=lower(key)
21295 if k=="language" then
21296 local v=gsub(lower(value),"[^a-z0-9]","")
21297 h.language=rawget(verboselanguages,v) or (languages[v] and v) or "dflt"
21298 elseif k=="script" then
21299 local v=gsub(lower(value),"[^a-z0-9]","")
21300 h.script=rawget(verbosescripts,v) or (scripts[v] and v) or "dflt"
21301 elseif k=="axis" then
21302 h[k]=normalizedaxis(value)
21303 else
21304 local uk=usedfeatures[key]
21305 local uv=uk[value]
21306 if uv then
21307 else
21308 uv=tonumber(value)
21309 if uv then
21310 elseif type(value)=="string" then
21311 local b=is_boolean(value)
21312 if type(b)=="nil" then
21313 if wrap and find(value,",") then
21314 uv="{"..lower(value).."}"
21315 else
21316 uv=lower(value)
21317 end
21318 else
21319 uv=b
21320 end
21321 elseif type(value)=="table" then
21322 uv=sequenced(t,",")
21323 else
21324 uv=value
21325 end
21326 if not rawget(features,k) then
21327 k=rawget(verbosefeatures,k) or k
21328 end
21329 local c=checkers[k]
21330 if c then
21331 uv=c(uv) or vc
21332 end
21333 uk[value]=uv
21334 end
21335 h[k]=uv
21336 end
21337 end
21338 return h
21339 end
21340 end
21341
21342 end -- closure
21343
21344 do -- begin closure to overcome local limits and interference
21345
21346 if not modules then modules={} end modules ['font-otl']={
21347 version=1.001,
21348 comment="companion to font-ini.mkiv",
21349 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
21350 copyright="PRAGMA ADE / ConTeXt Development Team",
21351 license="see context related readme files",
21352 }
21353 local lower=string.lower
21354 local type,next,tonumber,tostring,unpack=type,next,tonumber,tostring,unpack
21355 local abs=math.abs
21356 local derivetable,sortedhash=table.derive,table.sortedhash
21357 local formatters=string.formatters
21358 local setmetatableindex=table.setmetatableindex
21359 local allocate=utilities.storage.allocate
21360 local registertracker=trackers.register
21361 local registerdirective=directives.register
21362 local starttiming=statistics.starttiming
21363 local stoptiming=statistics.stoptiming
21364 local elapsedtime=statistics.elapsedtime
21365 local findbinfile=resolvers.findbinfile
21366 local trace_loading=false registertracker("otf.loading",function(v) trace_loading=v end)
21367 local trace_features=false registertracker("otf.features",function(v) trace_features=v end)
21368 local trace_defining=false registertracker("fonts.defining",function(v) trace_defining=v end)
21369 local report_otf=logs.reporter("fonts","otf loading")
21370 local fonts=fonts
21371 local otf=fonts.handlers.otf
21372 otf.version=3.134
21373 otf.cache=containers.define("fonts","otl",otf.version,true)
21374 otf.svgcache=containers.define("fonts","svg",otf.version,true)
21375 otf.pngcache=containers.define("fonts","png",otf.version,true)
21376 otf.pdfcache=containers.define("fonts","pdf",otf.version,true)
21377 otf.mpscache=containers.define("fonts","mps",otf.version,true)
21378 otf.svgenabled=false
21379 otf.pngenabled=false
21380 local otfreaders=otf.readers
21381 local hashes=fonts.hashes
21382 local definers=fonts.definers
21383 local readers=fonts.readers
21384 local constructors=fonts.constructors
21385 local otffeatures=constructors.features.otf
21386 local registerotffeature=otffeatures.register
21387 local otfenhancers=constructors.enhancers.otf
21388 local registerotfenhancer=otfenhancers.register
21389 local forceload=false
21390 local cleanup=0
21391 local syncspace=true
21392 local forcenotdef=false
21393 local privateoffset=fonts.constructors and fonts.constructors.privateoffset or 0xF0000
21394 local applyruntimefixes=fonts.treatments and fonts.treatments.applyfixes
21395 local wildcard="*"
21396 local default="dflt"
21397 local formats=fonts.formats
21398 formats.otf="opentype"
21399 formats.ttf="truetype"
21400 formats.ttc="truetype"
21401 registerdirective("fonts.otf.loader.cleanup",function(v) cleanup=tonumber(v) or (v and 1) or 0 end)
21402 registerdirective("fonts.otf.loader.force",function(v) forceload=v end)
21403 registerdirective("fonts.otf.loader.syncspace",function(v) syncspace=v end)
21404 registerdirective("fonts.otf.loader.forcenotdef",function(v) forcenotdef=v end)
21405 registerotfenhancer("check extra features",function() end)
21406 local checkmemory=utilities.lua and utilities.lua.checkmemory
21407 local threshold=100
21408 local tracememory=false
21409 registertracker("fonts.otf.loader.memory",function(v) tracememory=v end)
21410 if not checkmemory then
21411 local collectgarbage=collectgarbage
21412 checkmemory=function(previous,threshold)
21413 local current=collectgarbage("count")
21414 if previous then
21415 local checked=(threshold or 64)*1024
21416 if current-previous>checked then
21417 collectgarbage("collect")
21418 current=collectgarbage("count")
21419 end
21420 end
21421 return current
21422 end
21423 end
21424 function otf.load(filename,sub,instance)
21425 local base=file.basename(file.removesuffix(filename))
21426 local name=file.removesuffix(base)
21427 local attr=lfs.attributes(filename)
21428 local size=attr and attr.size or 0
21429 local time=attr and attr.modification or 0
21430 if sub=="" then
21431 sub=false
21432 end
21433 local hash=name
21434 if sub then
21435 hash=hash.."-"..sub
21436 end
21437 if instance then
21438 hash=hash.."-"..instance
21439 end
21440 hash=containers.cleanname(hash)
21441 local data=containers.read(otf.cache,hash)
21442 local reload=not data or data.size~=size or data.time~=time or data.tableversion~=otfreaders.tableversion
21443 if forceload then
21444 report_otf("forced reload of %a due to hard coded flag",filename)
21445 reload=true
21446 end
21447 if reload then
21448 report_otf("loading %a, hash %a",filename,hash)
21449 starttiming(otfreaders,true)
21450 data=otfreaders.loadfont(filename,sub or 1,instance)
21451 if data then
21452 local used=checkmemory()
21453 local resources=data.resources
21454 local svgshapes=resources.svgshapes
21455 local pngshapes=resources.pngshapes
21456 if cleanup==0 then
21457 checkmemory(used,threshold,tracememory)
21458 end
21459 if svgshapes then
21460 resources.svgshapes=nil
21461 if otf.svgenabled then
21462 local timestamp=os.date()
21463 containers.write(otf.svgcache,hash,{
21464 svgshapes=svgshapes,
21465 timestamp=timestamp,
21466 })
21467 data.properties.svg={
21468 hash=hash,
21469 timestamp=timestamp,
21470 }
21471 end
21472 if cleanup>1 then
21473 collectgarbage("collect")
21474 else
21475 checkmemory(used,threshold,tracememory)
21476 end
21477 end
21478 if pngshapes then
21479 resources.pngshapes=nil
21480 if otf.pngenabled then
21481 local timestamp=os.date()
21482 containers.write(otf.pngcache,hash,{
21483 pngshapes=pngshapes,
21484 timestamp=timestamp,
21485 })
21486 data.properties.png={
21487 hash=hash,
21488 timestamp=timestamp,
21489 }
21490 end
21491 if cleanup>1 then
21492 collectgarbage("collect")
21493 else
21494 checkmemory(used,threshold,tracememory)
21495 end
21496 end
21497 otfreaders.compact(data)
21498 if cleanup==0 then
21499 checkmemory(used,threshold,tracememory)
21500 end
21501 otfreaders.rehash(data,"unicodes")
21502 otfreaders.addunicodetable(data)
21503 otfreaders.extend(data)
21504 if cleanup==0 then
21505 checkmemory(used,threshold,tracememory)
21506 end
21507 if context then
21508 otfreaders.condense(data)
21509 end
21510 otfreaders.pack(data)
21511 report_otf("loading done")
21512 report_otf("saving %a in cache",filename)
21513 data=containers.write(otf.cache,hash,data)
21514 if cleanup>1 then
21515 collectgarbage("collect")
21516 else
21517 checkmemory(used,threshold,tracememory)
21518 end
21519 stoptiming(otfreaders)
21520 if elapsedtime then
21521 report_otf("loading, optimizing, packing and caching time %s",elapsedtime(otfreaders))
21522 end
21523 if cleanup>3 then
21524 collectgarbage("collect")
21525 else
21526 checkmemory(used,threshold,tracememory)
21527 end
21528 data=containers.read(otf.cache,hash)
21529 if cleanup>2 then
21530 collectgarbage("collect")
21531 else
21532 checkmemory(used,threshold,tracememory)
21533 end
21534 else
21535 stoptiming(otfreaders)
21536 data=nil
21537 report_otf("loading failed due to read error")
21538 end
21539 end
21540 if data then
21541 if trace_defining then
21542 report_otf("loading from cache using hash %a",hash)
21543 end
21544 otfreaders.unpack(data)
21545 otfreaders.expand(data)
21546 otfreaders.addunicodetable(data)
21547 otfenhancers.apply(data,filename,data)
21548 if applyruntimefixes then
21549 applyruntimefixes(filename,data)
21550 end
21551 data.metadata.math=data.resources.mathconstants
21552 local classes=data.resources.classes
21553 if not classes then
21554 local descriptions=data.descriptions
21555 classes=setmetatableindex(function(t,k)
21556 local d=descriptions[k]
21557 local v=(d and d.class or "base") or false
21558 t[k]=v
21559 return v
21560 end)
21561 data.resources.classes=classes
21562 end
21563 end
21564 return data
21565 end
21566 function otf.setfeatures(tfmdata,features)
21567 local okay=constructors.initializefeatures("otf",tfmdata,features,trace_features,report_otf)
21568 if okay then
21569 return constructors.collectprocessors("otf",tfmdata,features,trace_features,report_otf)
21570 else
21571 return {}
21572 end
21573 end
21574 local function copytotfm(data,cache_id)
21575 if data then
21576 local metadata=data.metadata
21577 local properties=derivetable(data.properties)
21578 local descriptions=derivetable(data.descriptions)
21579 local goodies=derivetable(data.goodies)
21580 local characters={}
21581 local parameters={}
21582 local mathparameters={}
21583 local resources=data.resources
21584 local unicodes=resources.unicodes
21585 local spaceunits=500
21586 local spacer="space"
21587 local designsize=metadata.designsize or 100
21588 local minsize=metadata.minsize or designsize
21589 local maxsize=metadata.maxsize or designsize
21590 local mathspecs=metadata.math
21591 if designsize==0 then
21592 designsize=100
21593 minsize=100
21594 maxsize=100
21595 end
21596 if mathspecs then
21597 for name,value in next,mathspecs do
21598 mathparameters[name]=value
21599 end
21600 end
21601 for unicode in next,data.descriptions do
21602 characters[unicode]={}
21603 end
21604 if mathspecs then
21605 for unicode,character in next,characters do
21606 local d=descriptions[unicode]
21607 local m=d.math
21608 if m then
21609 local italic=m.italic
21610 local vitalic=m.vitalic
21611 local variants=m.hvariants
21612 local parts=m.hparts
21613 if variants then
21614 local c=character
21615 for i=1,#variants do
21616 local un=variants[i]
21617 c.next=un
21618 c=characters[un]
21619 end
21620 c.horiz_variants=parts
21621 elseif parts then
21622 character.horiz_variants=parts
21623 italic=m.hitalic
21624 end
21625 local variants=m.vvariants
21626 local parts=m.vparts
21627 if variants then
21628 local c=character
21629 for i=1,#variants do
21630 local un=variants[i]
21631 c.next=un
21632 c=characters[un]
21633 end
21634 c.vert_variants=parts
21635 elseif parts then
21636 character.vert_variants=parts
21637 end
21638 if italic and italic~=0 then
21639 character.italic=italic
21640 end
21641 if vitalic and vitalic~=0 then
21642 character.vert_italic=vitalic
21643 end
21644 local accent=m.accent
21645 if accent then
21646 character.accent=accent
21647 end
21648 local kerns=m.kerns
21649 if kerns then
21650 character.mathkerns=kerns
21651 end
21652 end
21653 end
21654 end
21655 local filename=constructors.checkedfilename(resources)
21656 local fontname=metadata.fontname
21657 local fullname=metadata.fullname or fontname
21658 local psname=fontname or fullname
21659 local subfont=metadata.subfontindex
21660 local units=metadata.units or 1000
21661 if units==0 then
21662 units=1000
21663 metadata.units=1000
21664 report_otf("changing %a units to %a",0,units)
21665 end
21666 local monospaced=metadata.monospaced
21667 local charwidth=metadata.averagewidth
21668 local charxheight=metadata.xheight
21669 local italicangle=metadata.italicangle
21670 local hasitalics=metadata.hasitalics
21671 properties.monospaced=monospaced
21672 properties.hasitalics=hasitalics
21673 parameters.italicangle=italicangle
21674 parameters.charwidth=charwidth
21675 parameters.charxheight=charxheight
21676 local space=0x0020
21677 local emdash=0x2014
21678 if monospaced then
21679 if descriptions[space] then
21680 spaceunits,spacer=descriptions[space].width,"space"
21681 end
21682 if not spaceunits and descriptions[emdash] then
21683 spaceunits,spacer=descriptions[emdash].width,"emdash"
21684 end
21685 if not spaceunits and charwidth then
21686 spaceunits,spacer=charwidth,"charwidth"
21687 end
21688 else
21689 if descriptions[space] then
21690 spaceunits,spacer=descriptions[space].width,"space"
21691 end
21692 if not spaceunits and descriptions[emdash] then
21693 spaceunits,spacer=descriptions[emdash].width/2,"emdash/2"
21694 end
21695 if not spaceunits and charwidth then
21696 spaceunits,spacer=charwidth,"charwidth"
21697 end
21698 end
21699 spaceunits=tonumber(spaceunits) or units/2
21700 parameters.slant=0
21701 parameters.space=spaceunits
21702 parameters.space_stretch=1*units/2
21703 parameters.space_shrink=1*units/3
21704 parameters.x_height=2*units/5
21705 parameters.quad=units
21706 if spaceunits<2*units/5 then
21707 end
21708 if italicangle and italicangle~=0 then
21709 parameters.italicangle=italicangle
21710 parameters.italicfactor=math.cos(math.rad(90+italicangle))
21711 parameters.slant=- math.tan(italicangle*math.pi/180)
21712 end
21713 if monospaced then
21714 parameters.space_stretch=0
21715 parameters.space_shrink=0
21716 elseif syncspace then
21717 parameters.space_stretch=spaceunits/2
21718 parameters.space_shrink=spaceunits/3
21719 end
21720 parameters.extra_space=parameters.space_shrink
21721 if charxheight then
21722 parameters.x_height=charxheight
21723 else
21724 local x=0x0078
21725 if x then
21726 local x=descriptions[x]
21727 if x then
21728 parameters.x_height=x.height
21729 end
21730 end
21731 end
21732 parameters.designsize=(designsize/10)*65536
21733 parameters.minsize=(minsize/10)*65536
21734 parameters.maxsize=(maxsize/10)*65536
21735 parameters.ascender=abs(metadata.ascender or 0)
21736 parameters.descender=abs(metadata.descender or 0)
21737 parameters.units=units
21738 parameters.vheight=metadata.defaultvheight
21739 properties.space=spacer
21740 properties.format=data.format or formats.otf
21741 properties.filename=filename
21742 properties.fontname=fontname
21743 properties.fullname=fullname
21744 properties.psname=psname
21745 properties.name=filename or fullname
21746 properties.subfont=subfont
21747 if not CONTEXTLMTXMODE or CONTEXTLMTXMODE==0 then
21748 properties.encodingbytes=2
21749 elseif CONTEXTLMTXMODE then
21750 local duplicates=resources and resources.duplicates
21751 if duplicates then
21752 local maxindex=data.nofglyphs or metadata.nofglyphs
21753 if maxindex then
21754 for u,d in sortedhash(duplicates) do
21755 local du=descriptions[u]
21756 if du then
21757 for uu in sortedhash(d) do
21758 maxindex=maxindex+1
21759 descriptions[uu].dupindex=du.index
21760 descriptions[uu].index=maxindex
21761 end
21762 else
21763 end
21764 end
21765 end
21766 end
21767 end
21768 properties.private=properties.private or data.private or privateoffset
21769 return {
21770 characters=characters,
21771 descriptions=descriptions,
21772 parameters=parameters,
21773 mathparameters=mathparameters,
21774 resources=resources,
21775 properties=properties,
21776 goodies=goodies,
21777 }
21778 end
21779 end
21780 local converters={
21781 woff={
21782 cachename="webfonts",
21783 action=otf.readers.woff2otf,
21784 }
21785 }
21786 local function checkconversion(specification)
21787 local filename=specification.filename
21788 local converter=converters[lower(file.suffix(filename))]
21789 if converter then
21790 local base=file.basename(filename)
21791 local name=file.removesuffix(base)
21792 local attr=lfs.attributes(filename)
21793 local size=attr and attr.size or 0
21794 local time=attr and attr.modification or 0
21795 if size>0 then
21796 local cleanname=containers.cleanname(name)
21797 local cachename=caches.setfirstwritablefile(cleanname,converter.cachename)
21798 if not io.exists(cachename) or (time~=lfs.attributes(cachename).modification) then
21799 report_otf("caching font %a in %a",filename,cachename)
21800 converter.action(filename,cachename)
21801 lfs.touch(cachename,time,time)
21802 end
21803 specification.filename=cachename
21804 end
21805 end
21806 end
21807 local function otftotfm(specification)
21808 local cache_id=specification.hash
21809 local tfmdata=containers.read(constructors.cache,cache_id)
21810 if not tfmdata then
21811 checkconversion(specification)
21812 local name=specification.name
21813 local sub=specification.sub
21814 local subindex=specification.subindex
21815 local filename=specification.filename
21816 local features=specification.features.normal
21817 local instance=specification.instance or (features and features.axis)
21818 local rawdata=otf.load(filename,sub,instance)
21819 if rawdata and next(rawdata) then
21820 local descriptions=rawdata.descriptions
21821 rawdata.lookuphash={}
21822 tfmdata=copytotfm(rawdata,cache_id)
21823 if tfmdata and next(tfmdata) then
21824 local features=constructors.checkedfeatures("otf",features)
21825 local shared=tfmdata.shared
21826 if not shared then
21827 shared={}
21828 tfmdata.shared=shared
21829 end
21830 shared.rawdata=rawdata
21831 shared.dynamics={}
21832 tfmdata.changed={}
21833 shared.features=features
21834 shared.processes=otf.setfeatures(tfmdata,features)
21835 end
21836 end
21837 containers.write(constructors.cache,cache_id,tfmdata)
21838 end
21839 return tfmdata
21840 end
21841 local function read_from_otf(specification)
21842 local tfmdata=otftotfm(specification)
21843 if tfmdata then
21844 tfmdata.properties.name=specification.name
21845 tfmdata.properties.sub=specification.sub
21846 tfmdata.properties.id=specification.id
21847 tfmdata=constructors.scale(tfmdata,specification)
21848 local allfeatures=tfmdata.shared.features or specification.features.normal
21849 constructors.applymanipulators("otf",tfmdata,allfeatures,trace_features,report_otf)
21850 constructors.setname(tfmdata,specification)
21851 fonts.loggers.register(tfmdata,file.suffix(specification.filename),specification)
21852 end
21853 return tfmdata
21854 end
21855 function otf.collectlookups(rawdata,kind,script,language)
21856 if not kind then
21857 return
21858 end
21859 if not script then
21860 script=default
21861 end
21862 if not language then
21863 language=default
21864 end
21865 local lookupcache=rawdata.lookupcache
21866 if not lookupcache then
21867 lookupcache={}
21868 rawdata.lookupcache=lookupcache
21869 end
21870 local kindlookup=lookupcache[kind]
21871 if not kindlookup then
21872 kindlookup={}
21873 lookupcache[kind]=kindlookup
21874 end
21875 local scriptlookup=kindlookup[script]
21876 if not scriptlookup then
21877 scriptlookup={}
21878 kindlookup[script]=scriptlookup
21879 end
21880 local languagelookup=scriptlookup[language]
21881 if not languagelookup then
21882 local sequences=rawdata.resources.sequences
21883 local featuremap={}
21884 local featurelist={}
21885 if sequences then
21886 for s=1,#sequences do
21887 local sequence=sequences[s]
21888 local features=sequence.features
21889 if features then
21890 features=features[kind]
21891 if features then
21892 features=features[script] or features[wildcard]
21893 if features then
21894 features=features[language] or features[wildcard]
21895 if features then
21896 if not featuremap[sequence] then
21897 featuremap[sequence]=true
21898 featurelist[#featurelist+1]=sequence
21899 end
21900 end
21901 end
21902 end
21903 end
21904 end
21905 if #featurelist==0 then
21906 featuremap,featurelist=false,false
21907 end
21908 else
21909 featuremap,featurelist=false,false
21910 end
21911 languagelookup={ featuremap,featurelist }
21912 scriptlookup[language]=languagelookup
21913 end
21914 return unpack(languagelookup)
21915 end
21916 local function getgsub(tfmdata,k,kind,value)
21917 local shared=tfmdata.shared
21918 local rawdata=shared and shared.rawdata
21919 if rawdata then
21920 local sequences=rawdata.resources.sequences
21921 if sequences then
21922 local properties=tfmdata.properties
21923 local validlookups,lookuplist=otf.collectlookups(rawdata,kind,properties.script,properties.language)
21924 if validlookups then
21925 for i=1,#lookuplist do
21926 local lookup=lookuplist[i]
21927 local steps=lookup.steps
21928 local nofsteps=lookup.nofsteps
21929 for i=1,nofsteps do
21930 local coverage=steps[i].coverage
21931 if coverage then
21932 local found=coverage[k]
21933 if found then
21934 return found,lookup.type
21935 end
21936 end
21937 end
21938 end
21939 end
21940 end
21941 end
21942 end
21943 otf.getgsub=getgsub
21944 function otf.getsubstitution(tfmdata,k,kind,value)
21945 local found,kind=getgsub(tfmdata,k,kind,value)
21946 if not found then
21947 elseif kind=="gsub_single" then
21948 return found
21949 elseif kind=="gsub_alternate" then
21950 local choice=tonumber(value) or 1
21951 return found[choice] or found[1] or k
21952 end
21953 return k
21954 end
21955 otf.getalternate=otf.getsubstitution
21956 function otf.getmultiple(tfmdata,k,kind)
21957 local found,kind=getgsub(tfmdata,k,kind)
21958 if found and kind=="gsub_multiple" then
21959 return found
21960 end
21961 return { k }
21962 end
21963 function otf.getkern(tfmdata,left,right,kind)
21964 local kerns=getgsub(tfmdata,left,kind or "kern",true)
21965 if kerns then
21966 local found=kerns[right]
21967 local kind=type(found)
21968 if kind=="table" then
21969 found=found[1][3]
21970 elseif kind~="number" then
21971 found=false
21972 end
21973 if found then
21974 return found*tfmdata.parameters.factor
21975 end
21976 end
21977 return 0
21978 end
21979 local function check_otf(forced,specification,suffix)
21980 local name=specification.name
21981 if forced then
21982 name=specification.forcedname
21983 end
21984 local fullname=findbinfile(name,suffix) or ""
21985 if fullname=="" then
21986 fullname=fonts.names.getfilename(name,suffix) or ""
21987 end
21988 if fullname~="" and not fonts.names.ignoredfile(fullname) then
21989 specification.filename=fullname
21990 return read_from_otf(specification)
21991 end
21992 end
21993 local function opentypereader(specification,suffix)
21994 local forced=specification.forced or ""
21995 if formats[forced] then
21996 return check_otf(true,specification,forced)
21997 else
21998 return check_otf(false,specification,suffix)
21999 end
22000 end
22001 readers.opentype=opentypereader
22002 function readers.otf(specification) return opentypereader(specification,"otf") end
22003 function readers.ttf(specification) return opentypereader(specification,"ttf") end
22004 function readers.ttc(specification) return opentypereader(specification,"ttf") end
22005 function readers.woff(specification)
22006 checkconversion(specification)
22007 opentypereader(specification,"")
22008 end
22009 function otf.scriptandlanguage(tfmdata,attr)
22010 local properties=tfmdata.properties
22011 return properties.script or "dflt",properties.language or "dflt"
22012 end
22013 local function justset(coverage,unicode,replacement)
22014 coverage[unicode]=replacement
22015 end
22016 otf.coverup={
22017 stepkey="steps",
22018 actions={
22019 chainsubstitution=justset,
22020 chainposition=justset,
22021 substitution=justset,
22022 alternate=justset,
22023 multiple=justset,
22024 kern=justset,
22025 pair=justset,
22026 single=justset,
22027 ligature=function(coverage,unicode,ligature)
22028 local first=ligature[1]
22029 local tree=coverage[first]
22030 if not tree then
22031 tree={}
22032 coverage[first]=tree
22033 end
22034 for i=2,#ligature do
22035 local l=ligature[i]
22036 local t=tree[l]
22037 if not t then
22038 t={}
22039 tree[l]=t
22040 end
22041 tree=t
22042 end
22043 tree.ligature=unicode
22044 end,
22045 },
22046 register=function(coverage,featuretype,format)
22047 return {
22048 format=format,
22049 coverage=coverage,
22050 }
22051 end
22052 }
22053
22054 end -- closure
22055
22056 do -- begin closure to overcome local limits and interference
22057
22058 if not modules then modules={} end modules ['font-oto']={
22059 version=1.001,
22060 comment="companion to font-ini.mkiv",
22061 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
22062 copyright="PRAGMA ADE / ConTeXt Development Team",
22063 license="see context related readme files"
22064 }
22065 local concat,unpack=table.concat,table.unpack
22066 local insert,remove=table.insert,table.remove
22067 local format,gmatch,gsub,find,match,lower,strip=string.format,string.gmatch,string.gsub,string.find,string.match,string.lower,string.strip
22068 local type,next,tonumber,tostring=type,next,tonumber,tostring
22069 local trace_baseinit=false trackers.register("otf.baseinit",function(v) trace_baseinit=v end)
22070 local trace_singles=false trackers.register("otf.singles",function(v) trace_singles=v end)
22071 local trace_multiples=false trackers.register("otf.multiples",function(v) trace_multiples=v end)
22072 local trace_alternatives=false trackers.register("otf.alternatives",function(v) trace_alternatives=v end)
22073 local trace_ligatures=false trackers.register("otf.ligatures",function(v) trace_ligatures=v end)
22074 local trace_kerns=false trackers.register("otf.kerns",function(v) trace_kerns=v end)
22075 local trace_preparing=false trackers.register("otf.preparing",function(v) trace_preparing=v end)
22076 local report_prepare=logs.reporter("fonts","otf prepare")
22077 local fonts=fonts
22078 local otf=fonts.handlers.otf
22079 local otffeatures=otf.features
22080 local registerotffeature=otffeatures.register
22081 otf.defaultbasealternate="none"
22082 local getprivate=fonts.constructors.getprivate
22083 local wildcard="*"
22084 local default="dflt"
22085 local formatters=string.formatters
22086 local f_unicode=formatters["%U"]
22087 local f_uniname=formatters["%U (%s)"]
22088 local f_unilist=formatters["% t (% t)"]
22089 local function gref(descriptions,n)
22090 if type(n)=="number" then
22091 local name=descriptions[n].name
22092 if name then
22093 return f_uniname(n,name)
22094 else
22095 return f_unicode(n)
22096 end
22097 elseif n then
22098 local num={}
22099 local nam={}
22100 local j=0
22101 for i=1,#n do
22102 local ni=n[i]
22103 if tonumber(ni) then
22104 j=j+1
22105 local di=descriptions[ni]
22106 num[j]=f_unicode(ni)
22107 nam[j]=di and di.name or "-"
22108 end
22109 end
22110 return f_unilist(num,nam)
22111 else
22112 return "<error in base mode tracing>"
22113 end
22114 end
22115 local function cref(feature,sequence)
22116 return formatters["feature %a, type %a, (chain) lookup %a"](feature,sequence.type,sequence.name)
22117 end
22118 local function report_substitution(feature,sequence,descriptions,unicode,substitution)
22119 if unicode==substitution then
22120 report_prepare("%s: base substitution %s maps onto itself",
22121 cref(feature,sequence),
22122 gref(descriptions,unicode))
22123 else
22124 report_prepare("%s: base substitution %s => %S",
22125 cref(feature,sequence),
22126 gref(descriptions,unicode),
22127 gref(descriptions,substitution))
22128 end
22129 end
22130 local function report_alternate(feature,sequence,descriptions,unicode,replacement,value,comment)
22131 if unicode==replacement then
22132 report_prepare("%s: base alternate %s maps onto itself",
22133 cref(feature,sequence),
22134 gref(descriptions,unicode))
22135 else
22136 report_prepare("%s: base alternate %s => %s (%S => %S)",
22137 cref(feature,sequence),
22138 gref(descriptions,unicode),
22139 replacement and gref(descriptions,replacement),
22140 value,
22141 comment)
22142 end
22143 end
22144 local function report_ligature(feature,sequence,descriptions,unicode,ligature)
22145 report_prepare("%s: base ligature %s => %S",
22146 cref(feature,sequence),
22147 gref(descriptions,ligature),
22148 gref(descriptions,unicode))
22149 end
22150 local function report_kern(feature,sequence,descriptions,unicode,otherunicode,value)
22151 report_prepare("%s: base kern %s + %s => %S",
22152 cref(feature,sequence),
22153 gref(descriptions,unicode),
22154 gref(descriptions,otherunicode),
22155 value)
22156 end
22157 local basehash,basehashes,applied={},1,{}
22158 local function registerbasehash(tfmdata)
22159 local properties=tfmdata.properties
22160 local hash=concat(applied," ")
22161 local base=basehash[hash]
22162 if not base then
22163 basehashes=basehashes+1
22164 base=basehashes
22165 basehash[hash]=base
22166 end
22167 properties.basehash=base
22168 properties.fullname=(properties.fullname or properties.name).."-"..base
22169 applied={}
22170 end
22171 local function registerbasefeature(feature,value)
22172 applied[#applied+1]=feature.."="..tostring(value)
22173 end
22174 local function makefake(tfmdata,name,present)
22175 local private=getprivate(tfmdata)
22176 local character={ intermediate=true,ligatures={} }
22177 tfmdata.resources.unicodes[name]=private
22178 tfmdata.characters[private]=character
22179 tfmdata.descriptions[private]={ name=name }
22180 present[name]=private
22181 return character
22182 end
22183 local function make_1(present,tree,name)
22184 if tonumber(tree) then
22185 present[name]=v
22186 else
22187 for k,v in next,tree do
22188 if k=="ligature" then
22189 present[name]=v
22190 else
22191 make_1(present,v,name.."_"..k)
22192 end
22193 end
22194 end
22195 end
22196 local function make_3(present,tfmdata,characters,tree,name,preceding,unicode,done,v)
22197 local character=characters[preceding]
22198 if not character then
22199 if trace_baseinit then
22200 report_prepare("weird ligature in lookup %a, current %C, preceding %C",sequence.name,v,preceding)
22201 end
22202 character=makefake(tfmdata,name,present)
22203 end
22204 local ligatures=character.ligatures
22205 if ligatures then
22206 ligatures[unicode]={ char=v }
22207 else
22208 character.ligatures={ [unicode]={ char=v } }
22209 end
22210 if done then
22211 local d=done[name]
22212 if not d then
22213 done[name]={ "dummy",v }
22214 else
22215 d[#d+1]=v
22216 end
22217 end
22218 end
22219 local function make_2(present,tfmdata,characters,tree,name,preceding,unicode,done)
22220 if tonumber(tree) then
22221 make_3(present,tfmdata,characters,tree,name,preceding,unicode,done,tree)
22222 else
22223 for k,v in next,tree do
22224 if k=="ligature" then
22225 make_3(present,tfmdata,characters,tree,name,preceding,unicode,done,v)
22226 else
22227 local code=present[name] or unicode
22228 local name=name.."_"..k
22229 make_2(present,tfmdata,characters,v,name,code,k,done)
22230 end
22231 end
22232 end
22233 end
22234 local function preparesubstitutions(tfmdata,feature,value,validlookups,lookuplist)
22235 local characters=tfmdata.characters
22236 local descriptions=tfmdata.descriptions
22237 local resources=tfmdata.resources
22238 local changed=tfmdata.changed
22239 local ligatures={}
22240 local alternate=tonumber(value) or true and 1
22241 local defaultalt=otf.defaultbasealternate
22242 local trace_singles=trace_baseinit and trace_singles
22243 local trace_alternatives=trace_baseinit and trace_alternatives
22244 local trace_ligatures=trace_baseinit and trace_ligatures
22245 if not changed then
22246 changed={}
22247 tfmdata.changed=changed
22248 end
22249 for i=1,#lookuplist do
22250 local sequence=lookuplist[i]
22251 local steps=sequence.steps
22252 local kind=sequence.type
22253 if kind=="gsub_single" then
22254 for i=1,#steps do
22255 for unicode,data in next,steps[i].coverage do
22256 if unicode~=data then
22257 changed[unicode]=data
22258 end
22259 if trace_singles then
22260 report_substitution(feature,sequence,descriptions,unicode,data)
22261 end
22262 end
22263 end
22264 elseif kind=="gsub_alternate" then
22265 for i=1,#steps do
22266 for unicode,data in next,steps[i].coverage do
22267 local replacement=data[alternate]
22268 if replacement then
22269 if unicode~=replacement then
22270 changed[unicode]=replacement
22271 end
22272 if trace_alternatives then
22273 report_alternate(feature,sequence,descriptions,unicode,replacement,value,"normal")
22274 end
22275 elseif defaultalt=="first" then
22276 replacement=data[1]
22277 if unicode~=replacement then
22278 changed[unicode]=replacement
22279 end
22280 if trace_alternatives then
22281 report_alternate(feature,sequence,descriptions,unicode,replacement,value,defaultalt)
22282 end
22283 elseif defaultalt=="last" then
22284 replacement=data[#data]
22285 if unicode~=replacement then
22286 changed[unicode]=replacement
22287 end
22288 if trace_alternatives then
22289 report_alternate(feature,sequence,descriptions,unicode,replacement,value,defaultalt)
22290 end
22291 else
22292 if trace_alternatives then
22293 report_alternate(feature,sequence,descriptions,unicode,replacement,value,"unknown")
22294 end
22295 end
22296 end
22297 end
22298 elseif kind=="gsub_ligature" then
22299 for i=1,#steps do
22300 for unicode,data in next,steps[i].coverage do
22301 ligatures[#ligatures+1]={ unicode,data,"" }
22302 if trace_ligatures then
22303 report_ligature(feature,sequence,descriptions,unicode,data)
22304 end
22305 end
22306 end
22307 end
22308 end
22309 local nofligatures=#ligatures
22310 if nofligatures>0 then
22311 local characters=tfmdata.characters
22312 local present={}
22313 local done=trace_baseinit and trace_ligatures and {}
22314 for i=1,nofligatures do
22315 local ligature=ligatures[i]
22316 local unicode=ligature[1]
22317 local tree=ligature[2]
22318 make_1(present,tree,"ctx_"..unicode)
22319 end
22320 for i=1,nofligatures do
22321 local ligature=ligatures[i]
22322 local unicode=ligature[1]
22323 local tree=ligature[2]
22324 local lookupname=ligature[3]
22325 make_2(present,tfmdata,characters,tree,"ctx_"..unicode,unicode,unicode,done,sequence)
22326 end
22327 end
22328 end
22329 local function preparepositionings(tfmdata,feature,value,validlookups,lookuplist)
22330 local characters=tfmdata.characters
22331 local descriptions=tfmdata.descriptions
22332 local resources=tfmdata.resources
22333 local properties=tfmdata.properties
22334 local traceindeed=trace_baseinit and trace_kerns
22335 for i=1,#lookuplist do
22336 local sequence=lookuplist[i]
22337 local steps=sequence.steps
22338 local kind=sequence.type
22339 local format=sequence.format
22340 if kind=="gpos_pair" then
22341 for i=1,#steps do
22342 local step=steps[i]
22343 local format=step.format
22344 if format=="kern" or format=="move" then
22345 for unicode,data in next,steps[i].coverage do
22346 local character=characters[unicode]
22347 local kerns=character.kerns
22348 if not kerns then
22349 kerns={}
22350 character.kerns=kerns
22351 end
22352 if traceindeed then
22353 for otherunicode,kern in next,data do
22354 if not kerns[otherunicode] and kern~=0 then
22355 kerns[otherunicode]=kern
22356 report_kern(feature,sequence,descriptions,unicode,otherunicode,kern)
22357 end
22358 end
22359 else
22360 for otherunicode,kern in next,data do
22361 if not kerns[otherunicode] and kern~=0 then
22362 kerns[otherunicode]=kern
22363 end
22364 end
22365 end
22366 end
22367 else
22368 for unicode,data in next,steps[i].coverage do
22369 local character=characters[unicode]
22370 local kerns=character.kerns
22371 for otherunicode,kern in next,data do
22372 local other=kern[2]
22373 if other==true or (not other and not (kerns and kerns[otherunicode])) then
22374 local kern=kern[1]
22375 if kern==true then
22376 elseif kern[1]~=0 or kern[2]~=0 or kern[4]~=0 then
22377 else
22378 kern=kern[3]
22379 if kern~=0 then
22380 if kerns then
22381 kerns[otherunicode]=kern
22382 else
22383 kerns={ [otherunicode]=kern }
22384 character.kerns=kerns
22385 end
22386 if traceindeed then
22387 report_kern(feature,sequence,descriptions,unicode,otherunicode,kern)
22388 end
22389 end
22390 end
22391 end
22392 end
22393 end
22394 end
22395 end
22396 end
22397 end
22398 end
22399 local function initializehashes(tfmdata)
22400 end
22401 local function checkmathreplacements(tfmdata,fullname,fixitalics)
22402 if tfmdata.mathparameters then
22403 local characters=tfmdata.characters
22404 local changed=tfmdata.changed
22405 if next(changed) then
22406 if trace_preparing or trace_baseinit then
22407 report_prepare("checking math replacements for %a",fullname)
22408 end
22409 for unicode,replacement in next,changed do
22410 local u=characters[unicode]
22411 local r=characters[replacement]
22412 if u and r then
22413 local n=u.next
22414 local v=u.vert_variants
22415 local h=u.horiz_variants
22416 if fixitalics then
22417 local ui=u.italic
22418 if ui and not r.italic then
22419 if trace_preparing then
22420 report_prepare("using %i units of italic correction from %C for %U",ui,unicode,replacement)
22421 end
22422 r.italic=ui
22423 end
22424 end
22425 if n and not r.next then
22426 if trace_preparing then
22427 report_prepare("forcing %s for %C substituted by %U","incremental step",unicode,replacement)
22428 end
22429 r.next=n
22430 end
22431 if v and not r.vert_variants then
22432 if trace_preparing then
22433 report_prepare("forcing %s for %C substituted by %U","vertical variants",unicode,replacement)
22434 end
22435 r.vert_variants=v
22436 end
22437 if h and not r.horiz_variants then
22438 if trace_preparing then
22439 report_prepare("forcing %s for %C substituted by %U","horizontal variants",unicode,replacement)
22440 end
22441 r.horiz_variants=h
22442 end
22443 else
22444 if trace_preparing then
22445 report_prepare("error replacing %C by %U",unicode,replacement)
22446 end
22447 end
22448 end
22449 end
22450 end
22451 end
22452 local function featuresinitializer(tfmdata,value)
22453 if true then
22454 local starttime=trace_preparing and os.clock()
22455 local features=tfmdata.shared.features
22456 local fullname=tfmdata.properties.fullname or "?"
22457 if features then
22458 initializehashes(tfmdata)
22459 local collectlookups=otf.collectlookups
22460 local rawdata=tfmdata.shared.rawdata
22461 local properties=tfmdata.properties
22462 local script=properties.script
22463 local language=properties.language
22464 local rawresources=rawdata.resources
22465 local rawfeatures=rawresources and rawresources.features
22466 local basesubstitutions=rawfeatures and rawfeatures.gsub
22467 local basepositionings=rawfeatures and rawfeatures.gpos
22468 local substitutionsdone=false
22469 local positioningsdone=false
22470 if basesubstitutions or basepositionings then
22471 local sequences=tfmdata.resources.sequences
22472 for s=1,#sequences do
22473 local sequence=sequences[s]
22474 local sfeatures=sequence.features
22475 if sfeatures then
22476 local order=sequence.order
22477 if order then
22478 for i=1,#order do
22479 local feature=order[i]
22480 local value=features[feature]
22481 if value then
22482 local validlookups,lookuplist=collectlookups(rawdata,feature,script,language)
22483 if not validlookups then
22484 elseif basesubstitutions and basesubstitutions[feature] then
22485 if trace_preparing then
22486 report_prepare("filtering base %s feature %a for %a with value %a","sub",feature,fullname,value)
22487 end
22488 preparesubstitutions(tfmdata,feature,value,validlookups,lookuplist)
22489 registerbasefeature(feature,value)
22490 substitutionsdone=true
22491 elseif basepositionings and basepositionings[feature] then
22492 if trace_preparing then
22493 report_prepare("filtering base %a feature %a for %a with value %a","pos",feature,fullname,value)
22494 end
22495 preparepositionings(tfmdata,feature,value,validlookups,lookuplist)
22496 registerbasefeature(feature,value)
22497 positioningsdone=true
22498 end
22499 end
22500 end
22501 end
22502 end
22503 end
22504 end
22505 if substitutionsdone then
22506 checkmathreplacements(tfmdata,fullname,features.fixitalics)
22507 end
22508 registerbasehash(tfmdata)
22509 end
22510 if trace_preparing then
22511 report_prepare("preparation time is %0.3f seconds for %a",os.clock()-starttime,fullname)
22512 end
22513 end
22514 end
22515 registerotffeature {
22516 name="features",
22517 description="features",
22518 default=true,
22519 initializers={
22520 base=featuresinitializer,
22521 }
22522 }
22523 otf.basemodeinitializer=featuresinitializer
22524
22525 end -- closure
22526
22527 do -- begin closure to overcome local limits and interference
22528
22529 if not modules then modules={} end modules ['font-otj']={
22530 version=1.001,
22531 optimize=true,
22532 comment="companion to font-lib.mkiv",
22533 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
22534 copyright="PRAGMA ADE / ConTeXt Development Team",
22535 license="see context related readme files",
22536 }
22537 if not nodes.properties then return end
22538 local next,rawget,tonumber=next,rawget,tonumber
22539 local fastcopy=table.fastcopy
22540 local registertracker=trackers.register
22541 local registerdirective=directives.register
22542 local trace_injections=false registertracker("fonts.injections",function(v) trace_injections=v end)
22543 local trace_marks=false registertracker("fonts.injections.marks",function(v) trace_marks=v end)
22544 local trace_cursive=false registertracker("fonts.injections.cursive",function(v) trace_cursive=v end)
22545 local trace_spaces=false registertracker("fonts.injections.spaces",function(v) trace_spaces=v end)
22546 local report_injections=logs.reporter("fonts","injections")
22547 local report_spaces=logs.reporter("fonts","spaces")
22548 local attributes,nodes,node=attributes,nodes,node
22549 fonts=fonts
22550 local hashes=fonts.hashes
22551 local fontdata=hashes.identifiers
22552 local fontmarks=hashes.marks
22553 nodes.injections=nodes.injections or {}
22554 local injections=nodes.injections
22555 local tracers=nodes.tracers
22556 local setcolor=tracers and tracers.colors.set
22557 local resetcolor=tracers and tracers.colors.reset
22558 local nodecodes=nodes.nodecodes
22559 local glyph_code=nodecodes.glyph
22560 local disc_code=nodecodes.disc
22561 local kern_code=nodecodes.kern
22562 local glue_code=nodecodes.glue
22563 local nuts=nodes.nuts
22564 local nodepool=nuts.pool
22565 local tonode=nuts.tonode
22566 local tonut=nuts.tonut
22567 local setfield=nuts.setfield
22568 local getnext=nuts.getnext
22569 local getprev=nuts.getprev
22570 local getid=nuts.getid
22571 local getfont=nuts.getfont
22572 local getchar=nuts.getchar
22573 local getoffsets=nuts.getoffsets
22574 local getboth=nuts.getboth
22575 local getdisc=nuts.getdisc
22576 local setdisc=nuts.setdisc
22577 local getreplace=nuts.getreplace
22578 local setreplace=nuts.setreplace
22579 local setoffsets=nuts.setoffsets
22580 local ischar=nuts.ischar
22581 local getkern=nuts.getkern
22582 local setkern=nuts.setkern
22583 local setlink=nuts.setlink
22584 local setwidth=nuts.setwidth
22585 local getwidth=nuts.getwidth
22586 local nextchar=nuts.traversers.char
22587 local nextglue=nuts.traversers.glue
22588 local insertnodebefore=nuts.insertbefore
22589 local insertnodeafter=nuts.insertafter
22590 local properties=nodes.properties.data
22591 local fontkern=nuts.pool and nuts.pool.fontkern
22592 local italickern=nuts.pool and nuts.pool.italickern
22593 local useitalickerns=false
22594 directives.register("fonts.injections.useitalics",function(v)
22595 if v then
22596 report_injections("using italics for space kerns (tracing only)")
22597 end
22598 useitalickerns=v
22599 end)
22600 if not fontkern then
22601 local thekern=nuts.new("kern",0)
22602 local setkern=nuts.setkern
22603 local copy_node=nuts.copy
22604 fontkern=function(k)
22605 local n=copy_node(thekern)
22606 setkern(n,k)
22607 return n
22608 end
22609 end
22610 if not italickern then
22611 local thekern=nuts.new("kern",3)
22612 local setkern=nuts.setkern
22613 local copy_node=nuts.copy
22614 italickern=function(k)
22615 local n=copy_node(thekern)
22616 setkern(n,k)
22617 return n
22618 end
22619 end
22620 function injections.installnewkern() end
22621 local nofregisteredkerns=0
22622 local nofregisteredpositions=0
22623 local nofregisteredmarks=0
22624 local nofregisteredcursives=0
22625 local keepregisteredcounts=false
22626 function injections.keepcounts()
22627 keepregisteredcounts=true
22628 end
22629 function injections.resetcounts()
22630 nofregisteredkerns=0
22631 nofregisteredpositions=0
22632 nofregisteredmarks=0
22633 nofregisteredcursives=0
22634 keepregisteredcounts=false
22635 end
22636 function injections.reset(n)
22637 local p=rawget(properties,n)
22638 if p then
22639 p.injections=false
22640 else
22641 properties[n]=false
22642 end
22643 end
22644 function injections.copy(target,source)
22645 local sp=rawget(properties,source)
22646 if sp then
22647 local tp=rawget(properties,target)
22648 local si=sp.injections
22649 if si then
22650 si=fastcopy(si)
22651 if tp then
22652 tp.injections=si
22653 else
22654 properties[target]={
22655 injections=si,
22656 }
22657 end
22658 elseif tp then
22659 tp.injections=false
22660 else
22661 properties[target]={ injections={} }
22662 end
22663 else
22664 local tp=rawget(properties,target)
22665 if tp then
22666 tp.injections=false
22667 else
22668 properties[target]=false
22669 end
22670 end
22671 end
22672 function injections.setligaindex(n,index)
22673 local p=rawget(properties,n)
22674 if p then
22675 local i=p.injections
22676 if i then
22677 i.ligaindex=index
22678 else
22679 p.injections={
22680 ligaindex=index
22681 }
22682 end
22683 else
22684 properties[n]={
22685 injections={
22686 ligaindex=index
22687 }
22688 }
22689 end
22690 end
22691 function injections.getligaindex(n,default)
22692 local p=rawget(properties,n)
22693 if p then
22694 local i=p.injections
22695 if i then
22696 return i.ligaindex or default
22697 end
22698 end
22699 return default
22700 end
22701 function injections.setcursive(start,nxt,factor,rlmode,exit,entry,tfmstart,tfmnext,r2lflag)
22702 local dx=factor*(exit[1]-entry[1])
22703 local dy=-factor*(exit[2]-entry[2])
22704 local ws=tfmstart.width
22705 local wn=tfmnext.width
22706 nofregisteredcursives=nofregisteredcursives+1
22707 if rlmode<0 then
22708 dx=-(dx+wn)
22709 else
22710 dx=dx-ws
22711 end
22712 if dx==0 then
22713 dx=0
22714 end
22715 local p=rawget(properties,start)
22716 if p then
22717 local i=p.injections
22718 if i then
22719 i.cursiveanchor=true
22720 else
22721 p.injections={
22722 cursiveanchor=true,
22723 }
22724 end
22725 else
22726 properties[start]={
22727 injections={
22728 cursiveanchor=true,
22729 },
22730 }
22731 end
22732 local p=rawget(properties,nxt)
22733 if p then
22734 local i=p.injections
22735 if i then
22736 i.cursivex=dx
22737 i.cursivey=dy
22738 else
22739 p.injections={
22740 cursivex=dx,
22741 cursivey=dy,
22742 }
22743 end
22744 else
22745 properties[nxt]={
22746 injections={
22747 cursivex=dx,
22748 cursivey=dy,
22749 },
22750 }
22751 end
22752 return dx,dy,nofregisteredcursives
22753 end
22754 function injections.setposition(kind,current,factor,rlmode,spec,injection)
22755 local x=factor*(spec[1] or 0)
22756 local y=factor*(spec[2] or 0)
22757 local w=factor*(spec[3] or 0)
22758 local h=factor*(spec[4] or 0)
22759 if x~=0 or w~=0 or y~=0 or h~=0 then
22760 local yoffset=y-h
22761 local leftkern=x
22762 local rightkern=w-x
22763 if leftkern~=0 or rightkern~=0 or yoffset~=0 then
22764 nofregisteredpositions=nofregisteredpositions+1
22765 if rlmode and rlmode<0 then
22766 leftkern,rightkern=rightkern,leftkern
22767 end
22768 if not injection then
22769 injection="injections"
22770 end
22771 local p=rawget(properties,current)
22772 if p then
22773 local i=p[injection]
22774 if i then
22775 if leftkern~=0 then
22776 i.leftkern=(i.leftkern or 0)+leftkern
22777 end
22778 if rightkern~=0 then
22779 i.rightkern=(i.rightkern or 0)+rightkern
22780 end
22781 if yoffset~=0 then
22782 i.yoffset=(i.yoffset or 0)+yoffset
22783 end
22784 elseif leftkern~=0 or rightkern~=0 then
22785 p[injection]={
22786 leftkern=leftkern,
22787 rightkern=rightkern,
22788 yoffset=yoffset,
22789 }
22790 else
22791 p[injection]={
22792 yoffset=yoffset,
22793 }
22794 end
22795 elseif leftkern~=0 or rightkern~=0 then
22796 properties[current]={
22797 [injection]={
22798 leftkern=leftkern,
22799 rightkern=rightkern,
22800 yoffset=yoffset,
22801 },
22802 }
22803 else
22804 properties[current]={
22805 [injection]={
22806 yoffset=yoffset,
22807 },
22808 }
22809 end
22810 return x,y,w,h,nofregisteredpositions
22811 end
22812 end
22813 return x,y,w,h
22814 end
22815 function injections.setkern(current,factor,rlmode,x,injection)
22816 local dx=factor*x
22817 if dx~=0 then
22818 nofregisteredkerns=nofregisteredkerns+1
22819 local p=rawget(properties,current)
22820 if not injection then
22821 injection="injections"
22822 end
22823 if p then
22824 local i=p[injection]
22825 if i then
22826 i.leftkern=dx+(i.leftkern or 0)
22827 else
22828 p[injection]={
22829 leftkern=dx,
22830 }
22831 end
22832 else
22833 properties[current]={
22834 [injection]={
22835 leftkern=dx,
22836 },
22837 }
22838 end
22839 return dx,nofregisteredkerns
22840 else
22841 return 0,0
22842 end
22843 end
22844 function injections.setmove(current,factor,rlmode,x,injection)
22845 local dx=factor*x
22846 if dx~=0 then
22847 nofregisteredkerns=nofregisteredkerns+1
22848 local p=rawget(properties,current)
22849 if not injection then
22850 injection="injections"
22851 end
22852 if rlmode and rlmode<0 then
22853 if p then
22854 local i=p[injection]
22855 if i then
22856 i.rightkern=dx+(i.rightkern or 0)
22857 else
22858 p[injection]={
22859 rightkern=dx,
22860 }
22861 end
22862 else
22863 properties[current]={
22864 [injection]={
22865 rightkern=dx,
22866 },
22867 }
22868 end
22869 else
22870 if p then
22871 local i=p[injection]
22872 if i then
22873 i.leftkern=dx+(i.leftkern or 0)
22874 else
22875 p[injection]={
22876 leftkern=dx,
22877 }
22878 end
22879 else
22880 properties[current]={
22881 [injection]={
22882 leftkern=dx,
22883 },
22884 }
22885 end
22886 end
22887 return dx,nofregisteredkerns
22888 else
22889 return 0,0
22890 end
22891 end
22892 function injections.setmark(start,base,factor,rlmode,ba,ma,tfmbase,mkmk,checkmark)
22893 local dx=factor*(ba[1]-ma[1])
22894 local dy=factor*(ba[2]-ma[2])
22895 nofregisteredmarks=nofregisteredmarks+1
22896 if rlmode>=0 then
22897 dx=tfmbase.width-dx
22898 end
22899 local p=rawget(properties,start)
22900 if p then
22901 local i=p.injections
22902 if i then
22903 if i.markmark then
22904 else
22905 i.markx=dx
22906 i.marky=dy
22907 i.markdir=rlmode or 0
22908 i.markbase=nofregisteredmarks
22909 i.markbasenode=base
22910 i.markmark=mkmk
22911 i.checkmark=checkmark
22912 end
22913 else
22914 p.injections={
22915 markx=dx,
22916 marky=dy,
22917 markdir=rlmode or 0,
22918 markbase=nofregisteredmarks,
22919 markbasenode=base,
22920 markmark=mkmk,
22921 checkmark=checkmark,
22922 }
22923 end
22924 else
22925 properties[start]={
22926 injections={
22927 markx=dx,
22928 marky=dy,
22929 markdir=rlmode or 0,
22930 markbase=nofregisteredmarks,
22931 markbasenode=base,
22932 markmark=mkmk,
22933 checkmark=checkmark,
22934 },
22935 }
22936 end
22937 return dx,dy,nofregisteredmarks
22938 end
22939 local function dir(n)
22940 return (n and n<0 and "r-to-l") or (n and n>0 and "l-to-r") or "unset"
22941 end
22942 local function showchar(n,nested)
22943 local char=getchar(n)
22944 report_injections("%wfont %s, char %U, glyph %c",nested and 2 or 0,getfont(n),char,char)
22945 end
22946 local function show(n,what,nested,symbol)
22947 if n then
22948 local p=rawget(properties,n)
22949 if p then
22950 local i=p[what]
22951 if i then
22952 local leftkern=i.leftkern or 0
22953 local rightkern=i.rightkern or 0
22954 local yoffset=i.yoffset or 0
22955 local markx=i.markx or 0
22956 local marky=i.marky or 0
22957 local markdir=i.markdir or 0
22958 local markbase=i.markbase or 0
22959 local cursivex=i.cursivex or 0
22960 local cursivey=i.cursivey or 0
22961 local ligaindex=i.ligaindex or 0
22962 local cursbase=i.cursiveanchor
22963 local margin=nested and 4 or 2
22964 if rightkern~=0 or yoffset~=0 then
22965 report_injections("%w%s pair: lx %p, rx %p, dy %p",margin,symbol,leftkern,rightkern,yoffset)
22966 elseif leftkern~=0 then
22967 report_injections("%w%s kern: dx %p",margin,symbol,leftkern)
22968 end
22969 if markx~=0 or marky~=0 or markbase~=0 then
22970 report_injections("%w%s mark: dx %p, dy %p, dir %s, base %s",margin,symbol,markx,marky,markdir,markbase~=0 and "yes" or "no")
22971 end
22972 if cursivex~=0 or cursivey~=0 then
22973 if cursbase then
22974 report_injections("%w%s curs: base dx %p, dy %p",margin,symbol,cursivex,cursivey)
22975 else
22976 report_injections("%w%s curs: dx %p, dy %p",margin,symbol,cursivex,cursivey)
22977 end
22978 elseif cursbase then
22979 report_injections("%w%s curs: base",margin,symbol)
22980 end
22981 if ligaindex~=0 then
22982 report_injections("%w%s liga: index %i",margin,symbol,ligaindex)
22983 end
22984 end
22985 end
22986 end
22987 end
22988 local function showsub(n,what,where)
22989 report_injections("begin subrun: %s",where)
22990 for n in nextchar,n do
22991 showchar(n,where)
22992 show(n,what,where," ")
22993 end
22994 report_injections("end subrun")
22995 end
22996 local function trace(head,where)
22997 report_injections()
22998 report_injections("begin run %s: %s kerns, %s positions, %s marks and %s cursives registered",
22999 where or "",nofregisteredkerns,nofregisteredpositions,nofregisteredmarks,nofregisteredcursives)
23000 local n=head
23001 while n do
23002 local id=getid(n)
23003 if id==glyph_code then
23004 showchar(n)
23005 show(n,"injections",false," ")
23006 show(n,"preinjections",false,"<")
23007 show(n,"postinjections",false,">")
23008 show(n,"replaceinjections",false,"=")
23009 show(n,"emptyinjections",false,"*")
23010 elseif id==disc_code then
23011 local pre,post,replace=getdisc(n)
23012 if pre then
23013 showsub(pre,"preinjections","pre")
23014 end
23015 if post then
23016 showsub(post,"postinjections","post")
23017 end
23018 if replace then
23019 showsub(replace,"replaceinjections","replace")
23020 end
23021 show(n,"emptyinjections",false,"*")
23022 end
23023 n=getnext(n)
23024 end
23025 report_injections("end run")
23026 end
23027 local function show_result(head)
23028 local current=head
23029 local skipping=false
23030 while current do
23031 local id=getid(current)
23032 if id==glyph_code then
23033 local w=getwidth(current)
23034 local x,y=getoffsets(current)
23035 report_injections("char: %C, width %p, xoffset %p, yoffset %p",getchar(current),w,x,y)
23036 skipping=false
23037 elseif id==kern_code then
23038 report_injections("kern: %p",getkern(current))
23039 skipping=false
23040 elseif not skipping then
23041 report_injections()
23042 skipping=true
23043 end
23044 current=getnext(current)
23045 end
23046 report_injections()
23047 end
23048 local function inject_kerns_only(head,where)
23049 if trace_injections then
23050 trace(head,"kerns")
23051 end
23052 local current=head
23053 local prev=nil
23054 local next=nil
23055 local prevdisc=nil
23056 local pre=nil
23057 local post=nil
23058 local replace=nil
23059 local pretail=nil
23060 local posttail=nil
23061 local replacetail=nil
23062 while current do
23063 local next=getnext(current)
23064 local char,id=ischar(current)
23065 if char then
23066 local p=rawget(properties,current)
23067 if p then
23068 local i=p.injections
23069 if i then
23070 local leftkern=i.leftkern
23071 if leftkern and leftkern~=0 then
23072 if prev and getid(prev)==glue_code then
23073 if useitalickerns then
23074 head=insertnodebefore(head,current,italickern(leftkern))
23075 else
23076 setwidth(prev,getwidth(prev)+leftkern)
23077 end
23078 else
23079 head=insertnodebefore(head,current,fontkern(leftkern))
23080 end
23081 end
23082 end
23083 if prevdisc then
23084 local done=false
23085 if post then
23086 local i=p.postinjections
23087 if i then
23088 local leftkern=i.leftkern
23089 if leftkern and leftkern~=0 then
23090 setlink(posttail,fontkern(leftkern))
23091 done=true
23092 end
23093 end
23094 end
23095 if replace then
23096 local i=p.replaceinjections
23097 if i then
23098 local leftkern=i.leftkern
23099 if leftkern and leftkern~=0 then
23100 setlink(replacetail,fontkern(leftkern))
23101 done=true
23102 end
23103 end
23104 else
23105 local i=p.emptyinjections
23106 if i then
23107 local leftkern=i.leftkern
23108 if leftkern and leftkern~=0 then
23109 replace=fontkern(leftkern)
23110 done=true
23111 end
23112 end
23113 end
23114 if done then
23115 setdisc(prevdisc,pre,post,replace)
23116 end
23117 end
23118 end
23119 prevdisc=nil
23120 elseif char==false then
23121 prevdisc=nil
23122 elseif id==disc_code then
23123 pre,post,replace,pretail,posttail,replacetail=getdisc(current,true)
23124 local done=false
23125 if pre then
23126 for n in nextchar,pre do
23127 local p=rawget(properties,n)
23128 if p then
23129 local i=p.injections or p.preinjections
23130 if i then
23131 local leftkern=i.leftkern
23132 if leftkern and leftkern~=0 then
23133 pre=insertnodebefore(pre,n,fontkern(leftkern))
23134 done=true
23135 end
23136 end
23137 end
23138 end
23139 end
23140 if post then
23141 for n in nextchar,post do
23142 local p=rawget(properties,n)
23143 if p then
23144 local i=p.injections or p.postinjections
23145 if i then
23146 local leftkern=i.leftkern
23147 if leftkern and leftkern~=0 then
23148 post=insertnodebefore(post,n,fontkern(leftkern))
23149 done=true
23150 end
23151 end
23152 end
23153 end
23154 end
23155 if replace then
23156 for n in nextchar,replace do
23157 local p=rawget(properties,n)
23158 if p then
23159 local i=p.injections or p.replaceinjections
23160 if i then
23161 local leftkern=i.leftkern
23162 if leftkern and leftkern~=0 then
23163 replace=insertnodebefore(replace,n,fontkern(leftkern))
23164 done=true
23165 end
23166 end
23167 end
23168 end
23169 end
23170 if done then
23171 setdisc(current,pre,post,replace)
23172 end
23173 prevdisc=current
23174 else
23175 prevdisc=nil
23176 end
23177 prev=current
23178 current=next
23179 end
23180 if keepregisteredcounts then
23181 keepregisteredcounts=false
23182 else
23183 nofregisteredkerns=0
23184 end
23185 if trace_injections then
23186 show_result(head)
23187 end
23188 return head
23189 end
23190 local function inject_positions_only(head,where)
23191 if trace_injections then
23192 trace(head,"positions")
23193 end
23194 local current=head
23195 local prev=nil
23196 local next=nil
23197 local prevdisc=nil
23198 local prevglyph=nil
23199 local pre=nil
23200 local post=nil
23201 local replace=nil
23202 local pretail=nil
23203 local posttail=nil
23204 local replacetail=nil
23205 while current do
23206 local next=getnext(current)
23207 local char,id=ischar(current)
23208 if char then
23209 local p=rawget(properties,current)
23210 if p then
23211 local i=p.injections
23212 if i then
23213 local yoffset=i.yoffset
23214 if yoffset and yoffset~=0 then
23215 setoffsets(current,false,yoffset)
23216 end
23217 local leftkern=i.leftkern
23218 local rightkern=i.rightkern
23219 if leftkern and leftkern~=0 then
23220 if rightkern and leftkern==-rightkern then
23221 setoffsets(current,leftkern,false)
23222 rightkern=0
23223 elseif prev and getid(prev)==glue_code then
23224 if useitalickerns then
23225 head=insertnodebefore(head,current,italickern(leftkern))
23226 else
23227 setwidth(prev,getwidth(prev)+leftkern)
23228 end
23229 else
23230 head=insertnodebefore(head,current,fontkern(leftkern))
23231 end
23232 end
23233 if rightkern and rightkern~=0 then
23234 if next and getid(next)==glue_code then
23235 if useitalickerns then
23236 insertnodeafter(head,current,italickern(rightkern))
23237 else
23238 setwidth(next,getwidth(next)+rightkern)
23239 end
23240 else
23241 insertnodeafter(head,current,fontkern(rightkern))
23242 end
23243 end
23244 elseif next then
23245 local i=p.emptyinjections
23246 if i then
23247 local rightkern=i.rightkern
23248 if rightkern and rightkern~=0 and getid(next)==disc_code then
23249 local replace=getreplace(next)
23250 if replace then
23251 else
23252 setreplace(next,fontkern(rightkern))
23253 end
23254 end
23255 end
23256 end
23257 if prevdisc then
23258 local done=false
23259 if post then
23260 local i=p.postinjections
23261 if i then
23262 local leftkern=i.leftkern
23263 if leftkern and leftkern~=0 then
23264 setlink(posttail,fontkern(leftkern))
23265 done=true
23266 end
23267 end
23268 end
23269 if replace then
23270 local i=p.replaceinjections
23271 if i then
23272 local leftkern=i.leftkern
23273 if leftkern and leftkern~=0 then
23274 setlink(replacetail,fontkern(leftkern))
23275 done=true
23276 end
23277 end
23278 else
23279 local i=p.emptyinjections
23280 if i then
23281 local leftkern=i.leftkern
23282 if leftkern and leftkern~=0 then
23283 replace=fontkern(leftkern)
23284 done=true
23285 end
23286 end
23287 end
23288 if done then
23289 setdisc(prevdisc,pre,post,replace)
23290 end
23291 end
23292 end
23293 prevdisc=nil
23294 prevglyph=current
23295 elseif char==false then
23296 prevdisc=nil
23297 prevglyph=current
23298 elseif id==disc_code then
23299 pre,post,replace,pretail,posttail,replacetail=getdisc(current,true)
23300 local done=false
23301 if pre then
23302 for n in nextchar,pre do
23303 local p=rawget(properties,n)
23304 if p then
23305 local i=p.injections or p.preinjections
23306 if i then
23307 local yoffset=i.yoffset
23308 if yoffset and yoffset~=0 then
23309 setoffsets(n,false,yoffset)
23310 end
23311 local leftkern=i.leftkern
23312 if leftkern and leftkern~=0 then
23313 pre=insertnodebefore(pre,n,fontkern(leftkern))
23314 done=true
23315 end
23316 local rightkern=i.rightkern
23317 if rightkern and rightkern~=0 then
23318 insertnodeafter(pre,n,fontkern(rightkern))
23319 done=true
23320 end
23321 end
23322 end
23323 end
23324 end
23325 if post then
23326 for n in nextchar,post do
23327 local p=rawget(properties,n)
23328 if p then
23329 local i=p.injections or p.postinjections
23330 if i then
23331 local yoffset=i.yoffset
23332 if yoffset and yoffset~=0 then
23333 setoffsets(n,false,yoffset)
23334 end
23335 local leftkern=i.leftkern
23336 if leftkern and leftkern~=0 then
23337 post=insertnodebefore(post,n,fontkern(leftkern))
23338 done=true
23339 end
23340 local rightkern=i.rightkern
23341 if rightkern and rightkern~=0 then
23342 insertnodeafter(post,n,fontkern(rightkern))
23343 done=true
23344 end
23345 end
23346 end
23347 end
23348 end
23349 if replace then
23350 for n in nextchar,replace do
23351 local p=rawget(properties,n)
23352 if p then
23353 local i=p.injections or p.replaceinjections
23354 if i then
23355 local yoffset=i.yoffset
23356 if yoffset and yoffset~=0 then
23357 setoffsets(n,false,yoffset)
23358 end
23359 local leftkern=i.leftkern
23360 if leftkern and leftkern~=0 then
23361 replace=insertnodebefore(replace,n,fontkern(leftkern))
23362 done=true
23363 end
23364 local rightkern=i.rightkern
23365 if rightkern and rightkern~=0 then
23366 insertnodeafter(replace,n,fontkern(rightkern))
23367 done=true
23368 end
23369 end
23370 end
23371 end
23372 end
23373 if prevglyph then
23374 if pre then
23375 local p=rawget(properties,prevglyph)
23376 if p then
23377 local i=p.preinjections
23378 if i then
23379 local rightkern=i.rightkern
23380 if rightkern and rightkern~=0 then
23381 pre=insertnodebefore(pre,pre,fontkern(rightkern))
23382 done=true
23383 end
23384 end
23385 end
23386 end
23387 if replace then
23388 local p=rawget(properties,prevglyph)
23389 if p then
23390 local i=p.replaceinjections
23391 if i then
23392 local rightkern=i.rightkern
23393 if rightkern and rightkern~=0 then
23394 replace=insertnodebefore(replace,replace,fontkern(rightkern))
23395 done=true
23396 end
23397 end
23398 end
23399 end
23400 end
23401 if done then
23402 setdisc(current,pre,post,replace)
23403 end
23404 prevglyph=nil
23405 prevdisc=current
23406 else
23407 prevglyph=nil
23408 prevdisc=nil
23409 end
23410 prev=current
23411 current=next
23412 end
23413 if keepregisteredcounts then
23414 keepregisteredcounts=false
23415 else
23416 nofregisteredpositions=0
23417 end
23418 if trace_injections then
23419 show_result(head)
23420 end
23421 return head
23422 end
23423 local function showoffset(n,flag)
23424 local x,y=getoffsets(n)
23425 if x~=0 or y~=0 then
23426 setcolor(n,"darkgray")
23427 end
23428 end
23429 local function inject_everything(head,where)
23430 if trace_injections then
23431 trace(head,"everything")
23432 end
23433 local hascursives=nofregisteredcursives>0
23434 local hasmarks=nofregisteredmarks>0
23435 local current=head
23436 local last=nil
23437 local prev=nil
23438 local next=nil
23439 local prevdisc=nil
23440 local prevglyph=nil
23441 local pre=nil
23442 local post=nil
23443 local replace=nil
23444 local pretail=nil
23445 local posttail=nil
23446 local replacetail=nil
23447 local cursiveanchor=nil
23448 local minc=0
23449 local maxc=0
23450 local glyphs={}
23451 local marks={}
23452 local nofmarks=0
23453 local function processmark(p,n,pn)
23454 local px,py=getoffsets(p)
23455 local nx,ny=getoffsets(n)
23456 local ox=0
23457 local rightkern=nil
23458 local pp=rawget(properties,p)
23459 if pp then
23460 pp=pp.injections
23461 if pp then
23462 rightkern=pp.rightkern
23463 end
23464 end
23465 local markdir=pn.markdir
23466 if rightkern then
23467 ox=px-(pn.markx or 0)-rightkern
23468 if markdir and markdir<0 then
23469 if not pn.markmark then
23470 ox=ox+(pn.leftkern or 0)
23471 end
23472 else
23473 if false then
23474 local leftkern=pp.leftkern
23475 if leftkern then
23476 ox=ox-leftkern
23477 end
23478 end
23479 end
23480 else
23481 ox=px-(pn.markx or 0)
23482 if markdir and markdir<0 then
23483 if not pn.markmark then
23484 local leftkern=pn.leftkern
23485 if leftkern then
23486 ox=ox+leftkern
23487 end
23488 end
23489 end
23490 if pn.checkmark then
23491 local wn=getwidth(n)
23492 if wn and wn~=0 then
23493 wn=wn/2
23494 if trace_injections then
23495 report_injections("correcting non zero width mark %C",getchar(n))
23496 end
23497 insertnodebefore(n,n,fontkern(-wn))
23498 insertnodeafter(n,n,fontkern(-wn))
23499 end
23500 end
23501 end
23502 local oy=ny+py+(pn.marky or 0)
23503 if not pn.markmark then
23504 local yoffset=pn.yoffset
23505 if yoffset then
23506 oy=oy+yoffset
23507 end
23508 end
23509 setoffsets(n,ox,oy)
23510 if trace_marks then
23511 showoffset(n,true)
23512 end
23513 end
23514 while current do
23515 local next=getnext(current)
23516 local char,id=ischar(current)
23517 if char then
23518 local p=rawget(properties,current)
23519 if p then
23520 local i=p.injections
23521 if i then
23522 local pm=i.markbasenode
23523 if pm then
23524 nofmarks=nofmarks+1
23525 marks[nofmarks]=current
23526 else
23527 local yoffset=i.yoffset
23528 if yoffset and yoffset~=0 then
23529 setoffsets(current,false,yoffset)
23530 end
23531 if hascursives then
23532 local cursivex=i.cursivex
23533 if cursivex then
23534 if cursiveanchor then
23535 if cursivex~=0 then
23536 i.leftkern=(i.leftkern or 0)+cursivex
23537 end
23538 if maxc==0 then
23539 minc=1
23540 maxc=1
23541 glyphs[1]=cursiveanchor
23542 else
23543 maxc=maxc+1
23544 glyphs[maxc]=cursiveanchor
23545 end
23546 properties[cursiveanchor].cursivedy=i.cursivey
23547 last=current
23548 else
23549 maxc=0
23550 end
23551 elseif maxc>0 then
23552 local nx,ny=getoffsets(current)
23553 for i=maxc,minc,-1 do
23554 local ti=glyphs[i]
23555 ny=ny+properties[ti].cursivedy
23556 setoffsets(ti,false,ny)
23557 if trace_cursive then
23558 showoffset(ti)
23559 end
23560 end
23561 maxc=0
23562 cursiveanchor=nil
23563 end
23564 if i.cursiveanchor then
23565 cursiveanchor=current
23566 else
23567 if maxc>0 then
23568 local nx,ny=getoffsets(current)
23569 for i=maxc,minc,-1 do
23570 local ti=glyphs[i]
23571 ny=ny+properties[ti].cursivedy
23572 setoffsets(ti,false,ny)
23573 if trace_cursive then
23574 showoffset(ti)
23575 end
23576 end
23577 maxc=0
23578 end
23579 cursiveanchor=nil
23580 end
23581 end
23582 local leftkern=i.leftkern
23583 local rightkern=i.rightkern
23584 if leftkern and leftkern~=0 then
23585 if rightkern and leftkern==-rightkern then
23586 setoffsets(current,leftkern,false)
23587 rightkern=0
23588 elseif prev and getid(prev)==glue_code then
23589 if useitalickerns then
23590 head=insertnodebefore(head,current,italickern(leftkern))
23591 else
23592 setwidth(prev,getwidth(prev)+leftkern)
23593 end
23594 else
23595 head=insertnodebefore(head,current,fontkern(leftkern))
23596 end
23597 end
23598 if rightkern and rightkern~=0 then
23599 if next and getid(next)==glue_code then
23600 if useitalickerns then
23601 insertnodeafter(head,current,italickern(rightkern))
23602 else
23603 setwidth(next,getwidth(next)+rightkern)
23604 end
23605 else
23606 insertnodeafter(head,current,fontkern(rightkern))
23607 end
23608 end
23609 end
23610 elseif next then
23611 local i=p.emptyinjections
23612 if i then
23613 local rightkern=i.rightkern
23614 if rightkern and rightkern~=0 and getid(next)==disc_code then
23615 local replace=getreplace(next)
23616 if replace then
23617 else
23618 setreplace(next,fontkern(rightkern))
23619 end
23620 end
23621 end
23622 end
23623 if prevdisc then
23624 if p then
23625 local done=false
23626 if post then
23627 local i=p.postinjections
23628 if i then
23629 local leftkern=i.leftkern
23630 if leftkern and leftkern~=0 then
23631 setlink(posttail,fontkern(leftkern))
23632 done=true
23633 end
23634 end
23635 end
23636 if replace then
23637 local i=p.replaceinjections
23638 if i then
23639 local leftkern=i.leftkern
23640 if leftkern and leftkern~=0 then
23641 setlink(replacetail,fontkern(leftkern))
23642 done=true
23643 end
23644 end
23645 else
23646 local i=p.emptyinjections
23647 if i then
23648 local leftkern=i.leftkern
23649 if leftkern and leftkern~=0 then
23650 replace=fontkern(leftkern)
23651 done=true
23652 end
23653 end
23654 end
23655 if done then
23656 setdisc(prevdisc,pre,post,replace)
23657 end
23658 end
23659 end
23660 else
23661 if hascursives and maxc>0 then
23662 local nx,ny=getoffsets(current)
23663 for i=maxc,minc,-1 do
23664 local ti=glyphs[i]
23665 ny=ny+properties[ti].cursivedy
23666 local xi,yi=getoffsets(ti)
23667 setoffsets(ti,xi,yi+ny)
23668 end
23669 maxc=0
23670 cursiveanchor=nil
23671 end
23672 end
23673 prevdisc=nil
23674 prevglyph=current
23675 elseif char==false then
23676 prevdisc=nil
23677 prevglyph=current
23678 elseif id==disc_code then
23679 pre,post,replace,pretail,posttail,replacetail=getdisc(current,true)
23680 local done=false
23681 if pre then
23682 for n in nextchar,pre do
23683 local p=rawget(properties,n)
23684 if p then
23685 local i=p.injections or p.preinjections
23686 if i then
23687 local yoffset=i.yoffset
23688 if yoffset and yoffset~=0 then
23689 setoffsets(n,false,yoffset)
23690 end
23691 local leftkern=i.leftkern
23692 if leftkern and leftkern~=0 then
23693 pre=insertnodebefore(pre,n,fontkern(leftkern))
23694 done=true
23695 end
23696 local rightkern=i.rightkern
23697 if rightkern and rightkern~=0 then
23698 insertnodeafter(pre,n,fontkern(rightkern))
23699 done=true
23700 end
23701 if hasmarks then
23702 local pm=i.markbasenode
23703 if pm then
23704 processmark(pm,n,i)
23705 end
23706 end
23707 end
23708 end
23709 end
23710 end
23711 if post then
23712 for n in nextchar,post do
23713 local p=rawget(properties,n)
23714 if p then
23715 local i=p.injections or p.postinjections
23716 if i then
23717 local yoffset=i.yoffset
23718 if yoffset and yoffset~=0 then
23719 setoffsets(n,false,yoffset)
23720 end
23721 local leftkern=i.leftkern
23722 if leftkern and leftkern~=0 then
23723 post=insertnodebefore(post,n,fontkern(leftkern))
23724 done=true
23725 end
23726 local rightkern=i.rightkern
23727 if rightkern and rightkern~=0 then
23728 insertnodeafter(post,n,fontkern(rightkern))
23729 done=true
23730 end
23731 if hasmarks then
23732 local pm=i.markbasenode
23733 if pm then
23734 processmark(pm,n,i)
23735 end
23736 end
23737 end
23738 end
23739 end
23740 end
23741 if replace then
23742 for n in nextchar,replace do
23743 local p=rawget(properties,n)
23744 if p then
23745 local i=p.injections or p.replaceinjections
23746 if i then
23747 local yoffset=i.yoffset
23748 if yoffset and yoffset~=0 then
23749 setoffsets(n,false,yoffset)
23750 end
23751 local leftkern=i.leftkern
23752 if leftkern and leftkern~=0 then
23753 replace=insertnodebefore(replace,n,fontkern(leftkern))
23754 done=true
23755 end
23756 local rightkern=i.rightkern
23757 if rightkern and rightkern~=0 then
23758 insertnodeafter(replace,n,fontkern(rightkern))
23759 done=true
23760 end
23761 if hasmarks then
23762 local pm=i.markbasenode
23763 if pm then
23764 processmark(pm,n,i)
23765 end
23766 end
23767 end
23768 end
23769 end
23770 end
23771 if prevglyph then
23772 if pre then
23773 local p=rawget(properties,prevglyph)
23774 if p then
23775 local i=p.preinjections
23776 if i then
23777 local rightkern=i.rightkern
23778 if rightkern and rightkern~=0 then
23779 pre=insertnodebefore(pre,pre,fontkern(rightkern))
23780 done=true
23781 end
23782 end
23783 end
23784 end
23785 if replace then
23786 local p=rawget(properties,prevglyph)
23787 if p then
23788 local i=p.replaceinjections
23789 if i then
23790 local rightkern=i.rightkern
23791 if rightkern and rightkern~=0 then
23792 replace=insertnodebefore(replace,replace,fontkern(rightkern))
23793 done=true
23794 end
23795 end
23796 end
23797 end
23798 end
23799 if done then
23800 setdisc(current,pre,post,replace)
23801 end
23802 prevglyph=nil
23803 prevdisc=current
23804 else
23805 prevglyph=nil
23806 prevdisc=nil
23807 end
23808 prev=current
23809 current=next
23810 end
23811 if hascursives and maxc>0 then
23812 local nx,ny=getoffsets(last)
23813 for i=maxc,minc,-1 do
23814 local ti=glyphs[i]
23815 ny=ny+properties[ti].cursivedy
23816 setoffsets(ti,false,ny)
23817 if trace_cursive then
23818 showoffset(ti)
23819 end
23820 end
23821 end
23822 if nofmarks>0 then
23823 for i=1,nofmarks do
23824 local m=marks[i]
23825 local p=rawget(properties,m)
23826 local i=p.injections
23827 local b=i.markbasenode
23828 processmark(b,m,i)
23829 end
23830 elseif hasmarks then
23831 end
23832 if keepregisteredcounts then
23833 keepregisteredcounts=false
23834 else
23835 nofregisteredkerns=0
23836 nofregisteredpositions=0
23837 nofregisteredmarks=0
23838 nofregisteredcursives=0
23839 end
23840 if trace_injections then
23841 show_result(head)
23842 end
23843 return head
23844 end
23845 local triggers=false
23846 function nodes.injections.setspacekerns(font,sequence)
23847 if triggers then
23848 triggers[font]=sequence
23849 else
23850 triggers={ [font]=sequence }
23851 end
23852 end
23853 local getthreshold
23854 if context then
23855
23856 --removed
23857
23858 else
23859 injections.threshold=0
23860 getthreshold=function(font)
23861 local p=fontdata[font].parameters
23862 local f=p.factor
23863 local s=p.spacing
23864 local t=injections.threshold*(s and s.width or p.space or 0)-2
23865 return t>0 and t or 0,f
23866 end
23867 end
23868 injections.getthreshold=getthreshold
23869 function injections.isspace(n,threshold,id)
23870 if (id or getid(n))==glue_code then
23871 local w=getwidth(n)
23872 if threshold and w>threshold then
23873 return 32
23874 end
23875 end
23876 end
23877 local getspaceboth=getboth
23878 function injections.installgetspaceboth(gb)
23879 getspaceboth=gb or getboth
23880 end
23881 local function injectspaces(head)
23882 if not triggers then
23883 return head
23884 end
23885 local lastfont=nil
23886 local spacekerns=nil
23887 local leftkerns=nil
23888 local rightkerns=nil
23889 local factor=0
23890 local threshold=0
23891 local leftkern=false
23892 local rightkern=false
23893 local function updatefont(font,trig)
23894 leftkerns=trig.left
23895 rightkerns=trig.right
23896 lastfont=font
23897 threshold,
23898 factor=getthreshold(font)
23899 end
23900 for n in nextglue,head do
23901 local prev,next=getspaceboth(n)
23902 local prevchar=prev and ischar(prev)
23903 local nextchar=next and ischar(next)
23904 if nextchar then
23905 local font=getfont(next)
23906 local trig=triggers[font]
23907 if trig then
23908 if lastfont~=font then
23909 updatefont(font,trig)
23910 end
23911 if rightkerns then
23912 rightkern=rightkerns[nextchar]
23913 end
23914 end
23915 end
23916 if prevchar then
23917 local font=getfont(prev)
23918 local trig=triggers[font]
23919 if trig then
23920 if lastfont~=font then
23921 updatefont(font,trig)
23922 end
23923 if leftkerns then
23924 leftkern=leftkerns[prevchar]
23925 end
23926 end
23927 end
23928 if leftkern then
23929 local old=getwidth(n)
23930 if old>threshold then
23931 if rightkern then
23932 if useitalickerns then
23933 local lnew=leftkern*factor
23934 local rnew=rightkern*factor
23935 if trace_spaces then
23936 report_spaces("%C [%p + %p + %p] %C",prevchar,lnew,old,rnew,nextchar)
23937 end
23938 head=insertnodebefore(head,n,italickern(lnew))
23939 insertnodeafter(head,n,italickern(rnew))
23940 else
23941 local new=old+(leftkern+rightkern)*factor
23942 if trace_spaces then
23943 report_spaces("%C [%p -> %p] %C",prevchar,old,new,nextchar)
23944 end
23945 setwidth(n,new)
23946 end
23947 rightkern=false
23948 else
23949 if useitalickerns then
23950 local new=leftkern*factor
23951 if trace_spaces then
23952 report_spaces("%C [%p + %p]",prevchar,old,new)
23953 end
23954 insertnodeafter(head,n,italickern(new))
23955 else
23956 local new=old+leftkern*factor
23957 if trace_spaces then
23958 report_spaces("%C [%p -> %p]",prevchar,old,new)
23959 end
23960 setwidth(n,new)
23961 end
23962 end
23963 end
23964 leftkern=false
23965 elseif rightkern then
23966 local old=getwidth(n)
23967 if old>threshold then
23968 if useitalickerns then
23969 local new=rightkern*factor
23970 if trace_spaces then
23971 report_spaces("[%p + %p] %C",old,new,nextchar)
23972 end
23973 insertnodeafter(head,n,italickern(new))
23974 else
23975 local new=old+rightkern*factor
23976 if trace_spaces then
23977 report_spaces("[%p -> %p] %C",old,new,nextchar)
23978 end
23979 setwidth(n,new)
23980 end
23981 else
23982 end
23983 rightkern=false
23984 end
23985 end
23986 triggers=false
23987 return head
23988 end
23989 function injections.handler(head,where)
23990 if triggers then
23991 head=injectspaces(head)
23992 end
23993 if nofregisteredmarks>0 or nofregisteredcursives>0 then
23994 if trace_injections then
23995 report_injections("injection variant %a","everything")
23996 end
23997 return inject_everything(head,where)
23998 elseif nofregisteredpositions>0 then
23999 if trace_injections then
24000 report_injections("injection variant %a","positions")
24001 end
24002 return inject_positions_only(head,where)
24003 elseif nofregisteredkerns>0 then
24004 if trace_injections then
24005 report_injections("injection variant %a","kerns")
24006 end
24007 return inject_kerns_only(head,where)
24008 else
24009 return head
24010 end
24011 end
24012
24013 end -- closure
24014
24015 do -- begin closure to overcome local limits and interference
24016
24017 if not modules then modules={} end modules ['font-oup']={
24018 version=1.001,
24019 comment="companion to font-ini.mkiv",
24020 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
24021 copyright="PRAGMA ADE / ConTeXt Development Team",
24022 license="see context related readme files"
24023 }
24024 local next,type=next,type
24025 local P,R,S=lpeg.P,lpeg.R,lpeg.S
24026 local lpegmatch=lpeg.match
24027 local insert,remove,copy,unpack=table.insert,table.remove,table.copy,table.unpack
24028 local find=string.find
24029 local formatters=string.formatters
24030 local sortedkeys=table.sortedkeys
24031 local sortedhash=table.sortedhash
24032 local tohash=table.tohash
24033 local setmetatableindex=table.setmetatableindex
24034 local report_error=logs.reporter("otf reader","error")
24035 local report_markwidth=logs.reporter("otf reader","markwidth")
24036 local report_cleanup=logs.reporter("otf reader","cleanup")
24037 local report_optimizations=logs.reporter("otf reader","merges")
24038 local report_unicodes=logs.reporter("otf reader","unicodes")
24039 local trace_markwidth=false trackers.register("otf.markwidth",function(v) trace_markwidth=v end)
24040 local trace_cleanup=false trackers.register("otf.cleanups",function(v) trace_cleanups=v end)
24041 local trace_optimizations=false trackers.register("otf.optimizations",function(v) trace_optimizations=v end)
24042 local trace_unicodes=false trackers.register("otf.unicodes",function(v) trace_unicodes=v end)
24043 local readers=fonts.handlers.otf.readers
24044 local privateoffset=fonts.constructors and fonts.constructors.privateoffset or 0xF0000
24045 local f_private=formatters["P%05X"]
24046 local f_unicode=formatters["U%05X"]
24047 local f_index=formatters["I%05X"]
24048 local f_character_y=formatters["%C"]
24049 local f_character_n=formatters["[ %C ]"]
24050 local check_duplicates=true
24051 local check_soft_hyphen=context
24052 directives.register("otf.checksofthyphen",function(v)
24053 check_soft_hyphen=v
24054 end)
24055 local function replaced(list,index,replacement)
24056 if type(list)=="number" then
24057 return replacement
24058 elseif type(replacement)=="table" then
24059 local t={}
24060 local n=index-1
24061 for i=1,n do
24062 t[i]=list[i]
24063 end
24064 for i=1,#replacement do
24065 n=n+1
24066 t[n]=replacement[i]
24067 end
24068 for i=index+1,#list do
24069 n=n+1
24070 t[n]=list[i]
24071 end
24072 else
24073 list[index]=replacement
24074 return list
24075 end
24076 end
24077 local function unifyresources(fontdata,indices)
24078 local descriptions=fontdata.descriptions
24079 local resources=fontdata.resources
24080 if not descriptions or not resources then
24081 return
24082 end
24083 local nofindices=#indices
24084 local variants=fontdata.resources.variants
24085 if variants then
24086 for selector,unicodes in next,variants do
24087 for unicode,index in next,unicodes do
24088 unicodes[unicode]=indices[index]
24089 end
24090 end
24091 end
24092 local function remark(marks)
24093 if marks then
24094 local newmarks={}
24095 for k,v in next,marks do
24096 local u=indices[k]
24097 if u then
24098 newmarks[u]=v
24099 elseif trace_optimizations then
24100 report_optimizations("discarding mark %i",k)
24101 end
24102 end
24103 return newmarks
24104 end
24105 end
24106 local marks=resources.marks
24107 if marks then
24108 resources.marks=remark(marks)
24109 end
24110 local markclasses=resources.markclasses
24111 if markclasses then
24112 for class,marks in next,markclasses do
24113 markclasses[class]=remark(marks)
24114 end
24115 end
24116 local marksets=resources.marksets
24117 if marksets then
24118 for class,marks in next,marksets do
24119 marksets[class]=remark(marks)
24120 end
24121 end
24122 local done={}
24123 local duplicates=check_duplicates and resources.duplicates
24124 if duplicates and not next(duplicates) then
24125 duplicates=false
24126 end
24127 local function recover(cover)
24128 for i=1,#cover do
24129 local c=cover[i]
24130 if not done[c] then
24131 local t={}
24132 for k,v in next,c do
24133 local ug=indices[k]
24134 if ug then
24135 t[ug]=v
24136 else
24137 report_error("case %i, bad index in unifying %s: %s of %s",1,"coverage",k,nofindices)
24138 end
24139 end
24140 cover[i]=t
24141 done[c]=d
24142 end
24143 end
24144 end
24145 local function recursed(c,kind)
24146 local t={}
24147 for g,d in next,c do
24148 if type(d)=="table" then
24149 local ug=indices[g]
24150 if ug then
24151 t[ug]=recursed(d,kind)
24152 else
24153 report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g,nofindices)
24154 end
24155 else
24156 t[g]=indices[d]
24157 end
24158 end
24159 return t
24160 end
24161 local function unifythem(sequences)
24162 if not sequences then
24163 return
24164 end
24165 for i=1,#sequences do
24166 local sequence=sequences[i]
24167 local kind=sequence.type
24168 local steps=sequence.steps
24169 local features=sequence.features
24170 if steps then
24171 for i=1,#steps do
24172 local step=steps[i]
24173 if kind=="gsub_single" then
24174 local c=step.coverage
24175 if c then
24176 local t1=done[c]
24177 if not t1 then
24178 t1={}
24179 if duplicates then
24180 for g1,d1 in next,c do
24181 local ug1=indices[g1]
24182 if ug1 then
24183 local ud1=indices[d1]
24184 if ud1 then
24185 t1[ug1]=ud1
24186 local dg1=duplicates[ug1]
24187 if dg1 then
24188 for u in next,dg1 do
24189 t1[u]=ud1
24190 end
24191 end
24192 else
24193 report_error("case %i, bad index in unifying %s: %s of %s",3,kind,d1,nofindices)
24194 end
24195 else
24196 report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g1,nofindices)
24197 end
24198 end
24199 else
24200 for g1,d1 in next,c do
24201 local ug1=indices[g1]
24202 if ug1 then
24203 t1[ug1]=indices[d1]
24204 else
24205 report_error("fuzzy case %i in unifying %s: %i",2,kind,g1)
24206 end
24207 end
24208 end
24209 done[c]=t1
24210 end
24211 step.coverage=t1
24212 end
24213 elseif kind=="gpos_pair" then
24214 local c=step.coverage
24215 if c then
24216 local t1=done[c]
24217 if not t1 then
24218 t1={}
24219 for g1,d1 in next,c do
24220 local ug1=indices[g1]
24221 if ug1 then
24222 local t2=done[d1]
24223 if not t2 then
24224 t2={}
24225 for g2,d2 in next,d1 do
24226 local ug2=indices[g2]
24227 if ug2 then
24228 t2[ug2]=d2
24229 else
24230 report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g2,nofindices,nofindices)
24231 end
24232 end
24233 done[d1]=t2
24234 end
24235 t1[ug1]=t2
24236 else
24237 report_error("case %i, bad index in unifying %s: %s of %s",2,kind,g1,nofindices)
24238 end
24239 end
24240 done[c]=t1
24241 end
24242 step.coverage=t1
24243 end
24244 elseif kind=="gsub_ligature" then
24245 local c=step.coverage
24246 if c then
24247 step.coverage=recursed(c,kind)
24248 end
24249 elseif kind=="gsub_alternate" or kind=="gsub_multiple" then
24250 local c=step.coverage
24251 if c then
24252 local t1=done[c]
24253 if not t1 then
24254 t1={}
24255 if duplicates then
24256 for g1,d1 in next,c do
24257 for i=1,#d1 do
24258 local d1i=d1[i]
24259 local d1u=indices[d1i]
24260 if d1u then
24261 d1[i]=d1u
24262 else
24263 report_error("case %i, bad index in unifying %s: %s of %s",1,kind,i,d1i,nofindices)
24264 end
24265 end
24266 local ug1=indices[g1]
24267 if ug1 then
24268 t1[ug1]=d1
24269 local dg1=duplicates[ug1]
24270 if dg1 then
24271 for u in next,dg1 do
24272 t1[u]=copy(d1)
24273 end
24274 end
24275 else
24276 report_error("case %i, bad index in unifying %s: %s of %s",2,kind,g1,nofindices)
24277 end
24278 end
24279 else
24280 for g1,d1 in next,c do
24281 for i=1,#d1 do
24282 local d1i=d1[i]
24283 local d1u=indices[d1i]
24284 if d1u then
24285 d1[i]=d1u
24286 else
24287 report_error("case %i, bad index in unifying %s: %s of %s",2,kind,d1i,nofindices)
24288 end
24289 end
24290 t1[indices[g1]]=d1
24291 end
24292 end
24293 done[c]=t1
24294 end
24295 step.coverage=t1
24296 end
24297 elseif kind=="gpos_single" then
24298 local c=step.coverage
24299 if c then
24300 local t1=done[c]
24301 if not t1 then
24302 t1={}
24303 if duplicates then
24304 for g1,d1 in next,c do
24305 local ug1=indices[g1]
24306 if ug1 then
24307 t1[ug1]=d1
24308 local dg1=duplicates[ug1]
24309 if dg1 then
24310 for u in next,dg1 do
24311 t1[u]=d1
24312 end
24313 end
24314 else
24315 report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g1,nofindices)
24316 end
24317 end
24318 else
24319 for g1,d1 in next,c do
24320 local ug1=indices[g1]
24321 if ug1 then
24322 t1[ug1]=d1
24323 else
24324 report_error("case %i, bad index in unifying %s: %s of %s",2,kind,g1,nofindices)
24325 end
24326 end
24327 end
24328 done[c]=t1
24329 end
24330 step.coverage=t1
24331 end
24332 elseif kind=="gpos_mark2base" or kind=="gpos_mark2mark" or kind=="gpos_mark2ligature" then
24333 local c=step.coverage
24334 if c then
24335 local t1=done[c]
24336 if not t1 then
24337 t1={}
24338 for g1,d1 in next,c do
24339 local ug1=indices[g1]
24340 if ug1 then
24341 t1[ug1]=d1
24342 else
24343 report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g1,nofindices)
24344 end
24345 end
24346 done[c]=t1
24347 end
24348 step.coverage=t1
24349 end
24350 local c=step.baseclasses
24351 if c then
24352 local t1=done[c]
24353 if not t1 then
24354 for g1,d1 in next,c do
24355 local t2=done[d1]
24356 if not t2 then
24357 t2={}
24358 for g2,d2 in next,d1 do
24359 local ug2=indices[g2]
24360 if ug2 then
24361 t2[ug2]=d2
24362 else
24363 report_error("case %i, bad index in unifying %s: %s of %s",2,kind,g2,nofindices)
24364 end
24365 end
24366 done[d1]=t2
24367 end
24368 c[g1]=t2
24369 end
24370 done[c]=c
24371 end
24372 end
24373 elseif kind=="gpos_cursive" then
24374 local c=step.coverage
24375 if c then
24376 local t1=done[c]
24377 if not t1 then
24378 t1={}
24379 if duplicates then
24380 for g1,d1 in next,c do
24381 local ug1=indices[g1]
24382 if ug1 then
24383 t1[ug1]=d1
24384 local dg1=duplicates[ug1]
24385 if dg1 then
24386 for u in next,dg1 do
24387 t1[u]=copy(d1)
24388 end
24389 end
24390 else
24391 report_error("case %i, bad index in unifying %s: %s of %s",1,kind,g1,nofindices)
24392 end
24393 end
24394 else
24395 for g1,d1 in next,c do
24396 local ug1=indices[g1]
24397 if ug1 then
24398 t1[ug1]=d1
24399 else
24400 report_error("case %i, bad index in unifying %s: %s of %s",2,kind,g1,nofindices)
24401 end
24402 end
24403 end
24404 done[c]=t1
24405 end
24406 step.coverage=t1
24407 end
24408 end
24409 local rules=step.rules
24410 if rules then
24411 for i=1,#rules do
24412 local rule=rules[i]
24413 local before=rule.before if before then recover(before) end
24414 local after=rule.after if after then recover(after) end
24415 local current=rule.current if current then recover(current) end
24416 local replacements=rule.replacements
24417 if replacements then
24418 if not done[replacements] then
24419 local r={}
24420 for k,v in next,replacements do
24421 r[indices[k]]=indices[v]
24422 end
24423 rule.replacements=r
24424 done[replacements]=r
24425 end
24426 end
24427 end
24428 end
24429 end
24430 end
24431 end
24432 end
24433 unifythem(resources.sequences)
24434 unifythem(resources.sublookups)
24435 end
24436 local function copyduplicates(fontdata)
24437 if check_duplicates then
24438 local descriptions=fontdata.descriptions
24439 local resources=fontdata.resources
24440 local duplicates=resources.duplicates
24441 if check_soft_hyphen then
24442 local dh=descriptions[0x2D]
24443 if dh then
24444 local ds=descriptions[0xAD]
24445 if not ds or ds.width~=dh.width then
24446 descriptions[0xAD]=nil
24447 if ds then
24448 if trace_unicodes then
24449 report_unicodes("patching soft hyphen")
24450 end
24451 else
24452 if trace_unicodes then
24453 report_unicodes("adding soft hyphen")
24454 end
24455 end
24456 if not duplicates then
24457 duplicates={}
24458 resources.duplicates=duplicates
24459 end
24460 local d=duplicates[0x2D]
24461 if d then
24462 d[0xAD]=true
24463 else
24464 duplicates[0x2D]={ [0xAD]=true }
24465 end
24466 end
24467 end
24468 end
24469 if duplicates then
24470 for u,d in next,duplicates do
24471 local du=descriptions[u]
24472 if du then
24473 local t={ f_character_y(u),"@",f_index(du.index),"->" }
24474 local n=0
24475 local m=25
24476 for u in next,d do
24477 if descriptions[u] then
24478 if n<m then
24479 t[n+4]=f_character_n(u)
24480 end
24481 else
24482 local c=copy(du)
24483 c.unicode=u
24484 descriptions[u]=c
24485 if n<m then
24486 t[n+4]=f_character_y(u)
24487 end
24488 end
24489 n=n+1
24490 end
24491 if trace_unicodes then
24492 if n<=m then
24493 report_unicodes("%i : % t",n,t)
24494 else
24495 report_unicodes("%i : % t ...",n,t)
24496 end
24497 end
24498 else
24499 end
24500 end
24501 end
24502 end
24503 end
24504 local ignore={
24505 ["notdef"]=true,
24506 [".notdef"]=true,
24507 ["null"]=true,
24508 [".null"]=true,
24509 ["nonmarkingreturn"]=true,
24510 }
24511 local function checklookups(fontdata,missing,nofmissing)
24512 local descriptions=fontdata.descriptions
24513 local resources=fontdata.resources
24514 if missing and nofmissing and nofmissing<=0 then
24515 return
24516 end
24517 local singles={}
24518 local alternates={}
24519 local ligatures={}
24520 if not missing then
24521 missing={}
24522 nofmissing=0
24523 for u,d in next,descriptions do
24524 if not d.unicode then
24525 nofmissing=nofmissing+1
24526 missing[u]=true
24527 end
24528 end
24529 end
24530 local function collectthem(sequences)
24531 if not sequences then
24532 return
24533 end
24534 for i=1,#sequences do
24535 local sequence=sequences[i]
24536 local kind=sequence.type
24537 local steps=sequence.steps
24538 if steps then
24539 for i=1,#steps do
24540 local step=steps[i]
24541 if kind=="gsub_single" then
24542 local c=step.coverage
24543 if c then
24544 singles[#singles+1]=c
24545 end
24546 elseif kind=="gsub_alternate" then
24547 local c=step.coverage
24548 if c then
24549 alternates[#alternates+1]=c
24550 end
24551 elseif kind=="gsub_ligature" then
24552 local c=step.coverage
24553 if c then
24554 ligatures[#ligatures+1]=c
24555 end
24556 end
24557 end
24558 end
24559 end
24560 end
24561 collectthem(resources.sequences)
24562 collectthem(resources.sublookups)
24563 local loops=0
24564 while true do
24565 loops=loops+1
24566 local old=nofmissing
24567 for i=1,#singles do
24568 local c=singles[i]
24569 for g1,g2 in next,c do
24570 if missing[g1] then
24571 local u2=descriptions[g2].unicode
24572 if u2 then
24573 missing[g1]=false
24574 descriptions[g1].unicode=u2
24575 nofmissing=nofmissing-1
24576 end
24577 end
24578 if missing[g2] then
24579 local u1=descriptions[g1].unicode
24580 if u1 then
24581 missing[g2]=false
24582 descriptions[g2].unicode=u1
24583 nofmissing=nofmissing-1
24584 end
24585 end
24586 end
24587 end
24588 for i=1,#alternates do
24589 local c=alternates[i]
24590 for g1,d1 in next,c do
24591 if missing[g1] then
24592 for i=1,#d1 do
24593 local g2=d1[i]
24594 local u2=descriptions[g2].unicode
24595 if u2 then
24596 missing[g1]=false
24597 descriptions[g1].unicode=u2
24598 nofmissing=nofmissing-1
24599 end
24600 end
24601 end
24602 if not missing[g1] then
24603 for i=1,#d1 do
24604 local g2=d1[i]
24605 if missing[g2] then
24606 local u1=descriptions[g1].unicode
24607 if u1 then
24608 missing[g2]=false
24609 descriptions[g2].unicode=u1
24610 nofmissing=nofmissing-1
24611 end
24612 end
24613 end
24614 end
24615 end
24616 end
24617 if nofmissing<=0 then
24618 if trace_unicodes then
24619 report_unicodes("all missings done in %s loops",loops)
24620 end
24621 return
24622 elseif old==nofmissing then
24623 break
24624 end
24625 end
24626 local t,n
24627 local function recursed(c)
24628 for g,d in next,c do
24629 if g~="ligature" then
24630 local u=descriptions[g].unicode
24631 if u then
24632 n=n+1
24633 t[n]=u
24634 recursed(d)
24635 n=n-1
24636 end
24637 elseif missing[d] then
24638 local l={}
24639 local m=0
24640 for i=1,n do
24641 local u=t[i]
24642 if type(u)=="table" then
24643 for i=1,#u do
24644 m=m+1
24645 l[m]=u[i]
24646 end
24647 else
24648 m=m+1
24649 l[m]=u
24650 end
24651 end
24652 missing[d]=false
24653 descriptions[d].unicode=l
24654 nofmissing=nofmissing-1
24655 end
24656 end
24657 end
24658 if nofmissing>0 then
24659 t={}
24660 n=0
24661 local loops=0
24662 while true do
24663 loops=loops+1
24664 local old=nofmissing
24665 for i=1,#ligatures do
24666 recursed(ligatures[i])
24667 end
24668 if nofmissing<=0 then
24669 if trace_unicodes then
24670 report_unicodes("all missings done in %s loops",loops)
24671 end
24672 return
24673 elseif old==nofmissing then
24674 break
24675 end
24676 end
24677 t=nil
24678 n=0
24679 end
24680 if trace_unicodes and nofmissing>0 then
24681 local done={}
24682 for i,r in next,missing do
24683 if r then
24684 local data=descriptions[i]
24685 local name=data and data.name or f_index(i)
24686 if not ignore[name] then
24687 done[name]=true
24688 end
24689 end
24690 end
24691 if next(done) then
24692 report_unicodes("not unicoded: % t",sortedkeys(done))
24693 end
24694 end
24695 end
24696 local firstprivate=fonts.privateoffsets and fonts.privateoffsets.textbase or 0xF0000
24697 local puafirst=0xE000
24698 local pualast=0xF8FF
24699 local function unifymissing(fontdata)
24700 if not fonts.mappings then
24701 require("font-map")
24702 require("font-agl")
24703 end
24704 local unicodes={}
24705 local resources=fontdata.resources
24706 resources.unicodes=unicodes
24707 for unicode,d in next,fontdata.descriptions do
24708 if unicode<privateoffset then
24709 if unicode>=puafirst and unicode<=pualast then
24710 else
24711 local name=d.name
24712 if name then
24713 unicodes[name]=unicode
24714 end
24715 end
24716 else
24717 end
24718 end
24719 fonts.mappings.addtounicode(fontdata,fontdata.filename,checklookups)
24720 resources.unicodes=nil
24721 end
24722 local function unifyglyphs(fontdata,usenames)
24723 local private=fontdata.private or privateoffset
24724 local glyphs=fontdata.glyphs
24725 local indices={}
24726 local descriptions={}
24727 local names=usenames and {}
24728 local resources=fontdata.resources
24729 local zero=glyphs[0]
24730 local zerocode=zero.unicode
24731 local nofglyphs=#glyphs
24732 if not zerocode then
24733 zerocode=private
24734 zero.unicode=zerocode
24735 private=private+1
24736 end
24737 descriptions[zerocode]=zero
24738 if names then
24739 local name=glyphs[0].name or f_private(zerocode)
24740 indices[0]=name
24741 names[name]=zerocode
24742 else
24743 indices[0]=zerocode
24744 end
24745 if names then
24746 for index=1,nofglyphs do
24747 local glyph=glyphs[index]
24748 local unicode=glyph.unicode
24749 if not unicode then
24750 unicode=private
24751 local name=glyph.name or f_private(unicode)
24752 indices[index]=name
24753 names[name]=unicode
24754 private=private+1
24755 elseif unicode>=firstprivate then
24756 unicode=private
24757 local name=glyph.name or f_private(unicode)
24758 indices[index]=name
24759 names[name]=unicode
24760 private=private+1
24761 elseif unicode>=puafirst and unicode<=pualast then
24762 local name=glyph.name or f_private(unicode)
24763 indices[index]=name
24764 names[name]=unicode
24765 elseif descriptions[unicode] then
24766 unicode=private
24767 local name=glyph.name or f_private(unicode)
24768 indices[index]=name
24769 names[name]=unicode
24770 private=private+1
24771 else
24772 local name=glyph.name or f_unicode(unicode)
24773 indices[index]=name
24774 names[name]=unicode
24775 end
24776 descriptions[unicode]=glyph
24777 end
24778 elseif trace_unicodes then
24779 for index=1,nofglyphs do
24780 local glyph=glyphs[index]
24781 local unicode=glyph.unicode
24782 if not unicode then
24783 unicode=private
24784 indices[index]=unicode
24785 private=private+1
24786 elseif unicode>=firstprivate then
24787 local name=glyph.name
24788 if name then
24789 report_unicodes("moving glyph %a indexed %05X from private %U to %U ",name,index,unicode,private)
24790 else
24791 report_unicodes("moving glyph indexed %05X from private %U to %U ",index,unicode,private)
24792 end
24793 unicode=private
24794 indices[index]=unicode
24795 private=private+1
24796 elseif unicode>=puafirst and unicode<=pualast then
24797 local name=glyph.name
24798 if name then
24799 report_unicodes("keeping private unicode %U for glyph %a indexed %05X",unicode,name,index)
24800 else
24801 report_unicodes("keeping private unicode %U for glyph indexed %05X",unicode,index)
24802 end
24803 indices[index]=unicode
24804 elseif descriptions[unicode] then
24805 local name=glyph.name
24806 if name then
24807 report_unicodes("assigning duplicate unicode %U to %U for glyph %a indexed %05X ",unicode,private,name,index)
24808 else
24809 report_unicodes("assigning duplicate unicode %U to %U for glyph indexed %05X ",unicode,private,index)
24810 end
24811 unicode=private
24812 indices[index]=unicode
24813 private=private+1
24814 else
24815 indices[index]=unicode
24816 end
24817 descriptions[unicode]=glyph
24818 end
24819 else
24820 for index=1,nofglyphs do
24821 local glyph=glyphs[index]
24822 local unicode=glyph.unicode
24823 if not unicode then
24824 unicode=private
24825 indices[index]=unicode
24826 private=private+1
24827 elseif unicode>=firstprivate then
24828 local name=glyph.name
24829 unicode=private
24830 indices[index]=unicode
24831 private=private+1
24832 elseif unicode>=puafirst and unicode<=pualast then
24833 local name=glyph.name
24834 indices[index]=unicode
24835 elseif descriptions[unicode] then
24836 local name=glyph.name
24837 unicode=private
24838 indices[index]=unicode
24839 private=private+1
24840 else
24841 indices[index]=unicode
24842 end
24843 descriptions[unicode]=glyph
24844 end
24845 end
24846 if LUATEXENGINE=="luametatex" then
24847 for index=1,nofglyphs do
24848 local math=glyphs[index].math
24849 if math then
24850 local list=math.parts
24851 if list then
24852 for i=1,#list do local l=list[i] l.glyph=indices[l.glyph] end
24853 end
24854 local list=math.variants
24855 if list then
24856 for i=1,#list do list[i]=indices[list[i]] end
24857 end
24858 end
24859 end
24860 else
24861 for index=1,nofglyphs do
24862 local math=glyphs[index].math
24863 if math then
24864 local list=math.vparts
24865 if list then
24866 for i=1,#list do local l=list[i] l.glyph=indices[l.glyph] end
24867 end
24868 local list=math.hparts
24869 if list then
24870 for i=1,#list do local l=list[i] l.glyph=indices[l.glyph] end
24871 end
24872 local list=math.vvariants
24873 if list then
24874 for i=1,#list do list[i]=indices[list[i]] end
24875 end
24876 local list=math.hvariants
24877 if list then
24878 for i=1,#list do list[i]=indices[list[i]] end
24879 end
24880 end
24881 end
24882 end
24883 local colorpalettes=resources.colorpalettes
24884 if colorpalettes then
24885 for index=1,nofglyphs do
24886 local colors=glyphs[index].colors
24887 if colors then
24888 for i=1,#colors do
24889 local c=colors[i]
24890 if c then
24891 c.slot=indices[c.slot]
24892 end
24893 end
24894 end
24895 end
24896 end
24897 fontdata.private=private
24898 fontdata.glyphs=nil
24899 fontdata.names=names
24900 fontdata.descriptions=descriptions
24901 fontdata.hashmethod=hashmethod
24902 fontdata.nofglyphs=nofglyphs
24903 return indices,names
24904 end
24905 local stripredundant do
24906 local p_hex=R("af","AF","09")
24907 local p_digit=R("09")
24908 local p_done=S("._-")^0+P(-1)
24909 local p_style=P(".")
24910 local p_alpha=R("az","AZ")
24911 local p_ALPHA=R("AZ")
24912 local p_crappyname=(
24913 lpeg.utfchartabletopattern({ "uni","u" },true)*S("Xx_")^0*p_hex^1
24914 +lpeg.utfchartabletopattern({ "identity","glyph","jamo" },true)*p_hex^1
24915 +lpeg.utfchartabletopattern({ "index","afii" },true)*p_digit^1
24916 +p_digit*p_hex^3+p_alpha*p_digit^1
24917 +P("aj")*p_digit^1+P("eh_")*(p_digit^1+p_ALPHA*p_digit^1)+(1-P("_"))^1*P("_uni")*p_hex^1+P("_")*P(1)^1
24918 )*p_done
24919 if context then
24920 local forcekeep=false
24921 directives.register("otf.keepnames",function(v)
24922 report_cleanup("keeping weird glyph names, expect larger files and more memory usage")
24923 forcekeep=v
24924 end)
24925 local function stripvariants(descriptions,list)
24926 local n=list and #list or 0
24927 if n>0 then
24928 for i=1,n do
24929 local g=list[i]
24930 if g then
24931 local d=descriptions[g]
24932 if d and d.name then
24933 d.name=nil
24934 n=n+1
24935 end
24936 end
24937 end
24938 end
24939 return n
24940 end
24941 local function stripparts(descriptions,list)
24942 local n=list and #list or 0
24943 if n>0 then
24944 for i=1,n do
24945 local g=list[i].glyph
24946 if g then
24947 local d=descriptions[g]
24948 if d and d.name then
24949 d.name=nil
24950 n=n+1
24951 end
24952 end
24953 end
24954 end
24955 return n
24956 end
24957 local function collectsimple(fontdata)
24958 return nil
24959 end
24960 stripredundant=function(fontdata)
24961 local descriptions=fontdata.descriptions
24962 if descriptions then
24963 local n=0
24964 local c=0
24965 for unicode,d in next,descriptions do
24966 local m=d.math
24967 if m then
24968 n=n+stripvariants(descriptions,m.vvariants)
24969 n=n+stripvariants(descriptions,m.hvariants)
24970 n=n+stripparts (descriptions,m.vparts)
24971 n=n+stripparts (descriptions,m.hparts)
24972 end
24973 end
24974 if forcekeep then
24975 for unicode,d in next,descriptions do
24976 if d.class=="base" then
24977 d.class=nil
24978 c=c+1
24979 end
24980 end
24981 else
24982 local keeplist=collectsimple(fontdata)
24983 for unicode,d in next,descriptions do
24984 local name=d.name
24985 if name then
24986 if keeplist and keeplist[name] then
24987 elseif lpegmatch(p_crappyname,name) then
24988 d.name=nil
24989 n=n+1
24990 end
24991 end
24992 if d.class=="base" then
24993 d.class=nil
24994 c=c+1
24995 end
24996 end
24997 end
24998 if trace_cleanup then
24999 if n>0 then
25000 report_cleanup("%s bogus names removed (verbose unicode)",n)
25001 end
25002 if c>0 then
25003 report_cleanup("%s base class tags removed (default is base)",c)
25004 end
25005 end
25006 end
25007 end
25008 else
25009 stripredundant=function(fontdata)
25010 local descriptions=fontdata.descriptions
25011 if descriptions then
25012 if fonts.privateoffsets.keepnames then
25013 for unicode,d in next,descriptions do
25014 if d.class=="base" then
25015 d.class=nil
25016 end
25017 end
25018 else
25019 for unicode,d in next,descriptions do
25020 local name=d.name
25021 if name then
25022 if lpegmatch(p_crappyname,name) then
25023 d.name=nil
25024 end
25025 end
25026 if d.class=="base" then
25027 d.class=nil
25028 end
25029 end
25030 end
25031 end
25032 end
25033 end
25034 readers.stripredundant=stripredundant
25035 end
25036 function readers.getcomponents(fontdata)
25037 local resources=fontdata.resources
25038 if resources then
25039 local sequences=resources.sequences
25040 if sequences then
25041 local collected={}
25042 for i=1,#sequences do
25043 local sequence=sequences[i]
25044 if sequence.type=="gsub_ligature" then
25045 local steps=sequence.steps
25046 if steps then
25047 local l={}
25048 local function traverse(p,k,v)
25049 if k=="ligature" then
25050 collected[v]={ unpack(l) }
25051 elseif tonumber(v) then
25052 insert(l,k)
25053 collected[v]={ unpack(l) }
25054 remove(l)
25055 else
25056 insert(l,k)
25057 for k,vv in next,v do
25058 traverse(p,k,vv)
25059 end
25060 remove(l)
25061 end
25062 end
25063 for i=1,#steps do
25064 local c=steps[i].coverage
25065 if c then
25066 for k,v in next,c do
25067 traverse(k,k,v)
25068 end
25069 end
25070 end
25071 end
25072 end
25073 end
25074 if next(collected) then
25075 while true do
25076 local done=false
25077 for k,v in next,collected do
25078 for i=1,#v do
25079 local vi=v[i]
25080 if vi==k then
25081 collected[k]=nil
25082 break
25083 else
25084 local c=collected[vi]
25085 if c then
25086 done=true
25087 local t={}
25088 local n=i-1
25089 for j=1,n do
25090 t[j]=v[j]
25091 end
25092 for j=1,#c do
25093 n=n+1
25094 t[n]=c[j]
25095 end
25096 for j=i+1,#v do
25097 n=n+1
25098 t[n]=v[j]
25099 end
25100 collected[k]=t
25101 break
25102 end
25103 end
25104 end
25105 end
25106 if not done then
25107 break
25108 end
25109 end
25110 return collected
25111 end
25112 end
25113 end
25114 end
25115 readers.unifymissing=unifymissing
25116 function readers.rehash(fontdata,hashmethod)
25117 if not (fontdata and fontdata.glyphs) then
25118 return
25119 elseif hashmethod=="indices" then
25120 fontdata.hashmethod="indices"
25121 elseif hashmethod=="names" then
25122 fontdata.hashmethod="names"
25123 local indices=unifyglyphs(fontdata,true)
25124 unifyresources(fontdata,indices)
25125 copyduplicates(fontdata)
25126 unifymissing(fontdata)
25127 else
25128 fontdata.hashmethod="unicodes"
25129 local indices=unifyglyphs(fontdata)
25130 unifyresources(fontdata,indices)
25131 copyduplicates(fontdata)
25132 unifymissing(fontdata)
25133 stripredundant(fontdata)
25134 end
25135 end
25136 function readers.checkhash(fontdata)
25137 local hashmethod=fontdata.hashmethod
25138 if hashmethod=="unicodes" then
25139 fontdata.names=nil
25140 elseif hashmethod=="names" and fontdata.names then
25141 unifyresources(fontdata,fontdata.names)
25142 copyduplicates(fontdata)
25143 fontdata.hashmethod="unicodes"
25144 fontdata.names=nil
25145 else
25146 readers.rehash(fontdata,"unicodes")
25147 end
25148 end
25149 function readers.addunicodetable(fontdata)
25150 local resources=fontdata.resources
25151 local unicodes=resources.unicodes
25152 if not unicodes then
25153 local descriptions=fontdata.descriptions
25154 if descriptions then
25155 unicodes={}
25156 resources.unicodes=unicodes
25157 for u,d in next,descriptions do
25158 local n=d.name
25159 if n then
25160 unicodes[n]=u
25161 end
25162 end
25163 end
25164 end
25165 end
25166 local concat,sort=table.concat,table.sort
25167 local next,type,tostring=next,type,tostring
25168 local criterium=1
25169 local threshold=0
25170 local trace_packing=false trackers.register("otf.packing",function(v) trace_packing=v end)
25171 local trace_loading=false trackers.register("otf.loading",function(v) trace_loading=v end)
25172 local report_otf=logs.reporter("fonts","otf loading")
25173 local function tabstr_normal(t)
25174 local s={}
25175 local n=0
25176 for k,v in next,t do
25177 n=n+1
25178 if type(v)=="table" then
25179 s[n]=k..">"..tabstr_normal(v)
25180 elseif v==true then
25181 s[n]=k.."+"
25182 elseif v then
25183 s[n]=k.."="..v
25184 else
25185 s[n]=k.."-"
25186 end
25187 end
25188 if n==0 then
25189 return ""
25190 elseif n==1 then
25191 return s[1]
25192 else
25193 sort(s)
25194 return concat(s,",")
25195 end
25196 end
25197 local function tabstr_flat(t)
25198 local s={}
25199 local n=0
25200 for k,v in next,t do
25201 n=n+1
25202 s[n]=k.."="..v
25203 end
25204 if n==0 then
25205 return ""
25206 elseif n==1 then
25207 return s[1]
25208 else
25209 sort(s)
25210 return concat(s,",")
25211 end
25212 end
25213 local function tabstr_mixed(t)
25214 local n=#t
25215 if n==0 then
25216 return ""
25217 elseif n==1 then
25218 local k=t[1]
25219 if k==true then
25220 return "++"
25221 elseif k==false then
25222 return "--"
25223 else
25224 return tostring(k)
25225 end
25226 else
25227 local s={}
25228 for i=1,n do
25229 local k=t[i]
25230 if k==true then
25231 s[i]="++"
25232 elseif k==false then
25233 s[i]="--"
25234 else
25235 s[i]=k
25236 end
25237 end
25238 return concat(s,",")
25239 end
25240 end
25241 local function tabstr_boolean(t)
25242 local s={}
25243 local n=0
25244 for k,v in next,t do
25245 n=n+1
25246 if v then
25247 s[n]=k.."+"
25248 else
25249 s[n]=k.."-"
25250 end
25251 end
25252 if n==0 then
25253 return ""
25254 elseif n==1 then
25255 return s[1]
25256 else
25257 sort(s)
25258 return concat(s,",")
25259 end
25260 end
25261 function readers.pack(data)
25262 if data then
25263 local h,t,c={},{},{}
25264 local hh,tt,cc={},{},{}
25265 local nt,ntt=0,0
25266 local function pack_normal(v)
25267 local tag=tabstr_normal(v)
25268 local ht=h[tag]
25269 if ht then
25270 c[ht]=c[ht]+1
25271 return ht
25272 else
25273 nt=nt+1
25274 t[nt]=v
25275 h[tag]=nt
25276 c[nt]=1
25277 return nt
25278 end
25279 end
25280 local function pack_normal_cc(v)
25281 local tag=tabstr_normal(v)
25282 local ht=h[tag]
25283 if ht then
25284 c[ht]=c[ht]+1
25285 return ht
25286 else
25287 v[1]=0
25288 nt=nt+1
25289 t[nt]=v
25290 h[tag]=nt
25291 c[nt]=1
25292 return nt
25293 end
25294 end
25295 local function pack_flat(v)
25296 local tag=tabstr_flat(v)
25297 local ht=h[tag]
25298 if ht then
25299 c[ht]=c[ht]+1
25300 return ht
25301 else
25302 nt=nt+1
25303 t[nt]=v
25304 h[tag]=nt
25305 c[nt]=1
25306 return nt
25307 end
25308 end
25309 local function pack_indexed(v)
25310 local tag=concat(v," ")
25311 local ht=h[tag]
25312 if ht then
25313 c[ht]=c[ht]+1
25314 return ht
25315 else
25316 nt=nt+1
25317 t[nt]=v
25318 h[tag]=nt
25319 c[nt]=1
25320 return nt
25321 end
25322 end
25323 local function pack_mixed(v)
25324 local tag=tabstr_mixed(v)
25325 local ht=h[tag]
25326 if ht then
25327 c[ht]=c[ht]+1
25328 return ht
25329 else
25330 nt=nt+1
25331 t[nt]=v
25332 h[tag]=nt
25333 c[nt]=1
25334 return nt
25335 end
25336 end
25337 local function pack_boolean(v)
25338 local tag=tabstr_boolean(v)
25339 local ht=h[tag]
25340 if ht then
25341 c[ht]=c[ht]+1
25342 return ht
25343 else
25344 nt=nt+1
25345 t[nt]=v
25346 h[tag]=nt
25347 c[nt]=1
25348 return nt
25349 end
25350 end
25351 local function pack_final(v)
25352 if c[v]<=criterium then
25353 return t[v]
25354 else
25355 local hv=hh[v]
25356 if hv then
25357 return hv
25358 else
25359 ntt=ntt+1
25360 tt[ntt]=t[v]
25361 hh[v]=ntt
25362 cc[ntt]=c[v]
25363 return ntt
25364 end
25365 end
25366 end
25367 local function pack_final_cc(v)
25368 if c[v]<=criterium then
25369 return t[v]
25370 else
25371 local hv=hh[v]
25372 if hv then
25373 return hv
25374 else
25375 ntt=ntt+1
25376 tt[ntt]=t[v]
25377 hh[v]=ntt
25378 cc[ntt]=c[v]
25379 return ntt
25380 end
25381 end
25382 end
25383 local function success(stage,pass)
25384 if nt==0 then
25385 if trace_loading or trace_packing then
25386 report_otf("pack quality: nothing to pack")
25387 end
25388 return false
25389 elseif nt>=threshold then
25390 local one=0
25391 local two=0
25392 local rest=0
25393 if pass==1 then
25394 for k,v in next,c do
25395 if v==1 then
25396 one=one+1
25397 elseif v==2 then
25398 two=two+1
25399 else
25400 rest=rest+1
25401 end
25402 end
25403 else
25404 for k,v in next,cc do
25405 if v>20 then
25406 rest=rest+1
25407 elseif v>10 then
25408 two=two+1
25409 else
25410 one=one+1
25411 end
25412 end
25413 data.tables=tt
25414 end
25415 if trace_loading or trace_packing then
25416 report_otf("pack quality: stage %s, pass %s, %s packed, 1-10:%s, 11-20:%s, rest:%s (criterium: %s)",
25417 stage,pass,one+two+rest,one,two,rest,criterium)
25418 end
25419 return true
25420 else
25421 if trace_loading or trace_packing then
25422 report_otf("pack quality: stage %s, pass %s, %s packed, aborting pack (threshold: %s)",
25423 stage,pass,nt,threshold)
25424 end
25425 return false
25426 end
25427 end
25428 local function packers(pass)
25429 if pass==1 then
25430 return pack_normal,pack_indexed,pack_flat,pack_boolean,pack_mixed,pack_normal_cc
25431 else
25432 return pack_final,pack_final,pack_final,pack_final,pack_final,pack_final_cc
25433 end
25434 end
25435 local resources=data.resources
25436 local sequences=resources.sequences
25437 local sublookups=resources.sublookups
25438 local features=resources.features
25439 local palettes=resources.colorpalettes
25440 local variable=resources.variabledata
25441 local chardata=characters and characters.data
25442 local descriptions=data.descriptions or data.glyphs
25443 if not descriptions then
25444 return
25445 end
25446 for pass=1,2 do
25447 if trace_packing then
25448 report_otf("start packing: stage 1, pass %s",pass)
25449 end
25450 local pack_normal,pack_indexed,pack_flat,pack_boolean,pack_mixed,pack_normal_cc=packers(pass)
25451 for unicode,description in next,descriptions do
25452 local boundingbox=description.boundingbox
25453 if boundingbox then
25454 description.boundingbox=pack_indexed(boundingbox)
25455 end
25456 local math=description.math
25457 if math then
25458 local kerns=math.kerns
25459 if kerns then
25460 for tag,kern in next,kerns do
25461 kerns[tag]=pack_normal(kern)
25462 end
25463 end
25464 end
25465 end
25466 local function packthem(sequences)
25467 for i=1,#sequences do
25468 local sequence=sequences[i]
25469 local kind=sequence.type
25470 local steps=sequence.steps
25471 local order=sequence.order
25472 local features=sequence.features
25473 local flags=sequence.flags
25474 if steps then
25475 for i=1,#steps do
25476 local step=steps[i]
25477 if kind=="gpos_pair" then
25478 local c=step.coverage
25479 if c then
25480 if step.format~="pair" then
25481 for g1,d1 in next,c do
25482 c[g1]=pack_normal(d1)
25483 end
25484 elseif step.shared then
25485 local shared={}
25486 for g1,d1 in next,c do
25487 for g2,d2 in next,d1 do
25488 if not shared[d2] then
25489 local f=d2[1] if f and f~=true then d2[1]=pack_indexed(f) end
25490 local s=d2[2] if s and s~=true then d2[2]=pack_indexed(s) end
25491 shared[d2]=true
25492 end
25493 end
25494 end
25495 if pass==2 then
25496 step.shared=nil
25497 end
25498 else
25499 for g1,d1 in next,c do
25500 for g2,d2 in next,d1 do
25501 local f=d2[1] if f and f~=true then d2[1]=pack_indexed(f) end
25502 local s=d2[2] if s and s~=true then d2[2]=pack_indexed(s) end
25503 end
25504 end
25505 end
25506 end
25507 elseif kind=="gpos_single" then
25508 local c=step.coverage
25509 if c then
25510 if step.format=="single" then
25511 for g1,d1 in next,c do
25512 if d1 and d1~=true then
25513 c[g1]=pack_indexed(d1)
25514 end
25515 end
25516 else
25517 step.coverage=pack_normal(c)
25518 end
25519 end
25520 elseif kind=="gpos_cursive" then
25521 local c=step.coverage
25522 if c then
25523 for g1,d1 in next,c do
25524 local f=d1[2] if f then d1[2]=pack_indexed(f) end
25525 local s=d1[3] if s then d1[3]=pack_indexed(s) end
25526 end
25527 end
25528 elseif kind=="gpos_mark2base" or kind=="gpos_mark2mark" then
25529 local c=step.baseclasses
25530 if c then
25531 for g1,d1 in next,c do
25532 for g2,d2 in next,d1 do
25533 d1[g2]=pack_indexed(d2)
25534 end
25535 end
25536 end
25537 local c=step.coverage
25538 if c then
25539 for g1,d1 in next,c do
25540 d1[2]=pack_indexed(d1[2])
25541 end
25542 end
25543 elseif kind=="gpos_mark2ligature" then
25544 local c=step.baseclasses
25545 if c then
25546 for g1,d1 in next,c do
25547 for g2,d2 in next,d1 do
25548 for g3,d3 in next,d2 do
25549 d2[g3]=pack_indexed(d3)
25550 end
25551 end
25552 end
25553 end
25554 local c=step.coverage
25555 if c then
25556 for g1,d1 in next,c do
25557 d1[2]=pack_indexed(d1[2])
25558 end
25559 end
25560 end
25561 local rules=step.rules
25562 if rules then
25563 for i=1,#rules do
25564 local rule=rules[i]
25565 local r=rule.before if r then for i=1,#r do r[i]=pack_boolean(r[i]) end end
25566 local r=rule.after if r then for i=1,#r do r[i]=pack_boolean(r[i]) end end
25567 local r=rule.current if r then for i=1,#r do r[i]=pack_boolean(r[i]) end end
25568 local r=rule.replacements if r then rule.replacements=pack_flat (r) end
25569 end
25570 end
25571 end
25572 end
25573 if order then
25574 sequence.order=pack_indexed(order)
25575 end
25576 if features then
25577 for script,feature in next,features do
25578 features[script]=pack_normal(feature)
25579 end
25580 end
25581 if flags then
25582 sequence.flags=pack_normal(flags)
25583 end
25584 end
25585 end
25586 if sequences then
25587 packthem(sequences)
25588 end
25589 if sublookups then
25590 packthem(sublookups)
25591 end
25592 if features then
25593 for k,list in next,features do
25594 for feature,spec in next,list do
25595 list[feature]=pack_normal(spec)
25596 end
25597 end
25598 end
25599 if palettes then
25600 for i=1,#palettes do
25601 local p=palettes[i]
25602 for j=1,#p do
25603 p[j]=pack_indexed(p[j])
25604 end
25605 end
25606 end
25607 if variable then
25608 local instances=variable.instances
25609 if instances then
25610 for i=1,#instances do
25611 local v=instances[i].values
25612 for j=1,#v do
25613 v[j]=pack_normal(v[j])
25614 end
25615 end
25616 end
25617 local function packdeltas(main)
25618 if main then
25619 local deltas=main.deltas
25620 if deltas then
25621 for i=1,#deltas do
25622 local di=deltas[i]
25623 local d=di.deltas
25624 for j=1,#d do
25625 d[j]=pack_indexed(d[j])
25626 end
25627 di.regions=pack_indexed(di.regions)
25628 end
25629 end
25630 local regions=main.regions
25631 if regions then
25632 for i=1,#regions do
25633 local r=regions[i]
25634 for j=1,#r do
25635 r[j]=pack_normal(r[j])
25636 end
25637 end
25638 end
25639 end
25640 end
25641 packdeltas(variable.global)
25642 packdeltas(variable.horizontal)
25643 packdeltas(variable.vertical)
25644 packdeltas(variable.metrics)
25645 end
25646 if not success(1,pass) then
25647 return
25648 end
25649 end
25650 if nt>0 then
25651 for pass=1,2 do
25652 if trace_packing then
25653 report_otf("start packing: stage 2, pass %s",pass)
25654 end
25655 local pack_normal,pack_indexed,pack_flat,pack_boolean,pack_mixed,pack_normal_cc=packers(pass)
25656 for unicode,description in next,descriptions do
25657 local math=description.math
25658 if math then
25659 local kerns=math.kerns
25660 if kerns then
25661 math.kerns=pack_normal(kerns)
25662 end
25663 end
25664 end
25665 local function packthem(sequences)
25666 for i=1,#sequences do
25667 local sequence=sequences[i]
25668 local kind=sequence.type
25669 local steps=sequence.steps
25670 local features=sequence.features
25671 if steps then
25672 for i=1,#steps do
25673 local step=steps[i]
25674 if kind=="gpos_pair" then
25675 local c=step.coverage
25676 if c then
25677 if step.format=="pair" then
25678 for g1,d1 in next,c do
25679 for g2,d2 in next,d1 do
25680 d1[g2]=pack_normal(d2)
25681 end
25682 end
25683 end
25684 end
25685 elseif kind=="gpos_mark2ligature" then
25686 local c=step.baseclasses
25687 if c then
25688 for g1,d1 in next,c do
25689 for g2,d2 in next,d1 do
25690 d1[g2]=pack_normal(d2)
25691 end
25692 end
25693 end
25694 end
25695 local rules=step.rules
25696 if rules then
25697 for i=1,#rules do
25698 local rule=rules[i]
25699 local r=rule.before if r then rule.before=pack_normal(r) end
25700 local r=rule.after if r then rule.after=pack_normal(r) end
25701 local r=rule.current if r then rule.current=pack_normal(r) end
25702 end
25703 end
25704 end
25705 end
25706 if features then
25707 sequence.features=pack_normal(features)
25708 end
25709 end
25710 end
25711 if sequences then
25712 packthem(sequences)
25713 end
25714 if sublookups then
25715 packthem(sublookups)
25716 end
25717 if variable then
25718 local function unpackdeltas(main)
25719 if main then
25720 local regions=main.regions
25721 if regions then
25722 main.regions=pack_normal(regions)
25723 end
25724 end
25725 end
25726 unpackdeltas(variable.global)
25727 unpackdeltas(variable.horizontal)
25728 unpackdeltas(variable.vertical)
25729 unpackdeltas(variable.metrics)
25730 end
25731 end
25732 for pass=1,2 do
25733 if trace_packing then
25734 report_otf("start packing: stage 3, pass %s",pass)
25735 end
25736 local pack_normal,pack_indexed,pack_flat,pack_boolean,pack_mixed,pack_normal_cc=packers(pass)
25737 local function packthem(sequences)
25738 for i=1,#sequences do
25739 local sequence=sequences[i]
25740 local kind=sequence.type
25741 local steps=sequence.steps
25742 local features=sequence.features
25743 if steps then
25744 for i=1,#steps do
25745 local step=steps[i]
25746 if kind=="gpos_pair" then
25747 local c=step.coverage
25748 if c then
25749 if step.format=="pair" then
25750 for g1,d1 in next,c do
25751 c[g1]=pack_normal(d1)
25752 end
25753 end
25754 end
25755 elseif kind=="gpos_cursive" then
25756 local c=step.coverage
25757 if c then
25758 for g1,d1 in next,c do
25759 c[g1]=pack_normal_cc(d1)
25760 end
25761 end
25762 end
25763 end
25764 end
25765 end
25766 end
25767 if sequences then
25768 packthem(sequences)
25769 end
25770 if sublookups then
25771 packthem(sublookups)
25772 end
25773 end
25774 end
25775 end
25776 end
25777 local unpacked_mt={
25778 __index=function(t,k)
25779 t[k]=false
25780 return k
25781 end
25782 }
25783 function readers.unpack(data)
25784 if data then
25785 local tables=data.tables
25786 if tables then
25787 local resources=data.resources
25788 local descriptions=data.descriptions or data.glyphs
25789 local sequences=resources.sequences
25790 local sublookups=resources.sublookups
25791 local features=resources.features
25792 local palettes=resources.colorpalettes
25793 local variable=resources.variabledata
25794 local unpacked={}
25795 setmetatable(unpacked,unpacked_mt)
25796 for unicode,description in next,descriptions do
25797 local tv=tables[description.boundingbox]
25798 if tv then
25799 description.boundingbox=tv
25800 end
25801 local math=description.math
25802 if math then
25803 local kerns=math.kerns
25804 if kerns then
25805 local tm=tables[kerns]
25806 if tm then
25807 math.kerns=tm
25808 kerns=unpacked[tm]
25809 end
25810 if kerns then
25811 for k,kern in next,kerns do
25812 local tv=tables[kern]
25813 if tv then
25814 kerns[k]=tv
25815 end
25816 end
25817 end
25818 end
25819 end
25820 end
25821 local function unpackthem(sequences)
25822 for i=1,#sequences do
25823 local sequence=sequences[i]
25824 local kind=sequence.type
25825 local steps=sequence.steps
25826 local order=sequence.order
25827 local features=sequence.features
25828 local flags=sequence.flags
25829 local markclass=sequence.markclass
25830 if features then
25831 local tv=tables[features]
25832 if tv then
25833 sequence.features=tv
25834 features=tv
25835 end
25836 for script,feature in next,features do
25837 local tv=tables[feature]
25838 if tv then
25839 features[script]=tv
25840 end
25841 end
25842 end
25843 if steps then
25844 for i=1,#steps do
25845 local step=steps[i]
25846 if kind=="gpos_pair" then
25847 local c=step.coverage
25848 if c then
25849 if step.format=="pair" then
25850 for g1,d1 in next,c do
25851 local tv=tables[d1]
25852 if tv then
25853 c[g1]=tv
25854 d1=tv
25855 end
25856 for g2,d2 in next,d1 do
25857 local tv=tables[d2]
25858 if tv then
25859 d1[g2]=tv
25860 d2=tv
25861 end
25862 local f=tables[d2[1]] if f then d2[1]=f end
25863 local s=tables[d2[2]] if s then d2[2]=s end
25864 end
25865 end
25866 else
25867 for g1,d1 in next,c do
25868 local tv=tables[d1]
25869 if tv then
25870 c[g1]=tv
25871 end
25872 end
25873 end
25874 end
25875 elseif kind=="gpos_single" then
25876 local c=step.coverage
25877 if c then
25878 if step.format=="single" then
25879 for g1,d1 in next,c do
25880 local tv=tables[d1]
25881 if tv then
25882 c[g1]=tv
25883 end
25884 end
25885 else
25886 local tv=tables[c]
25887 if tv then
25888 step.coverage=tv
25889 end
25890 end
25891 end
25892 elseif kind=="gpos_cursive" then
25893 local c=step.coverage
25894 if c then
25895 for g1,d1 in next,c do
25896 local tv=tables[d1]
25897 if tv then
25898 d1=tv
25899 c[g1]=d1
25900 end
25901 local f=tables[d1[2]] if f then d1[2]=f end
25902 local s=tables[d1[3]] if s then d1[3]=s end
25903 end
25904 end
25905 elseif kind=="gpos_mark2base" or kind=="gpos_mark2mark" then
25906 local c=step.baseclasses
25907 if c then
25908 for g1,d1 in next,c do
25909 for g2,d2 in next,d1 do
25910 local tv=tables[d2]
25911 if tv then
25912 d1[g2]=tv
25913 end
25914 end
25915 end
25916 end
25917 local c=step.coverage
25918 if c then
25919 for g1,d1 in next,c do
25920 local tv=tables[d1[2]]
25921 if tv then
25922 d1[2]=tv
25923 end
25924 end
25925 end
25926 elseif kind=="gpos_mark2ligature" then
25927 local c=step.baseclasses
25928 if c then
25929 for g1,d1 in next,c do
25930 for g2,d2 in next,d1 do
25931 local tv=tables[d2]
25932 if tv then
25933 d2=tv
25934 d1[g2]=d2
25935 end
25936 for g3,d3 in next,d2 do
25937 local tv=tables[d2[g3]]
25938 if tv then
25939 d2[g3]=tv
25940 end
25941 end
25942 end
25943 end
25944 end
25945 local c=step.coverage
25946 if c then
25947 for g1,d1 in next,c do
25948 local tv=tables[d1[2]]
25949 if tv then
25950 d1[2]=tv
25951 end
25952 end
25953 end
25954 end
25955 local rules=step.rules
25956 if rules then
25957 for i=1,#rules do
25958 local rule=rules[i]
25959 local before=rule.before
25960 if before then
25961 local tv=tables[before]
25962 if tv then
25963 rule.before=tv
25964 before=tv
25965 end
25966 for i=1,#before do
25967 local tv=tables[before[i]]
25968 if tv then
25969 before[i]=tv
25970 end
25971 end
25972 end
25973 local after=rule.after
25974 if after then
25975 local tv=tables[after]
25976 if tv then
25977 rule.after=tv
25978 after=tv
25979 end
25980 for i=1,#after do
25981 local tv=tables[after[i]]
25982 if tv then
25983 after[i]=tv
25984 end
25985 end
25986 end
25987 local current=rule.current
25988 if current then
25989 local tv=tables[current]
25990 if tv then
25991 rule.current=tv
25992 current=tv
25993 end
25994 for i=1,#current do
25995 local tv=tables[current[i]]
25996 if tv then
25997 current[i]=tv
25998 end
25999 end
26000 end
26001 local replacements=rule.replacements
26002 if replacements then
26003 local tv=tables[replacements]
26004 if tv then
26005 rule.replacements=tv
26006 end
26007 end
26008 end
26009 end
26010 end
26011 end
26012 if order then
26013 local tv=tables[order]
26014 if tv then
26015 sequence.order=tv
26016 end
26017 end
26018 if flags then
26019 local tv=tables[flags]
26020 if tv then
26021 sequence.flags=tv
26022 end
26023 end
26024 end
26025 end
26026 if sequences then
26027 unpackthem(sequences)
26028 end
26029 if sublookups then
26030 unpackthem(sublookups)
26031 end
26032 if features then
26033 for k,list in next,features do
26034 for feature,spec in next,list do
26035 local tv=tables[spec]
26036 if tv then
26037 list[feature]=tv
26038 end
26039 end
26040 end
26041 end
26042 if palettes then
26043 for i=1,#palettes do
26044 local p=palettes[i]
26045 for j=1,#p do
26046 local tv=tables[p[j]]
26047 if tv then
26048 p[j]=tv
26049 end
26050 end
26051 end
26052 end
26053 if variable then
26054 local instances=variable.instances
26055 if instances then
26056 for i=1,#instances do
26057 local v=instances[i].values
26058 for j=1,#v do
26059 local tv=tables[v[j]]
26060 if tv then
26061 v[j]=tv
26062 end
26063 end
26064 end
26065 end
26066 local function unpackdeltas(main)
26067 if main then
26068 local deltas=main.deltas
26069 if deltas then
26070 for i=1,#deltas do
26071 local di=deltas[i]
26072 local d=di.deltas
26073 local r=di.regions
26074 for j=1,#d do
26075 local tv=tables[d[j]]
26076 if tv then
26077 d[j]=tv
26078 end
26079 end
26080 local tv=di.regions
26081 if tv then
26082 di.regions=tv
26083 end
26084 end
26085 end
26086 local regions=main.regions
26087 if regions then
26088 local tv=tables[regions]
26089 if tv then
26090 main.regions=tv
26091 regions=tv
26092 end
26093 for i=1,#regions do
26094 local r=regions[i]
26095 for j=1,#r do
26096 local tv=tables[r[j]]
26097 if tv then
26098 r[j]=tv
26099 end
26100 end
26101 end
26102 end
26103 end
26104 end
26105 unpackdeltas(variable.global)
26106 unpackdeltas(variable.horizontal)
26107 unpackdeltas(variable.vertical)
26108 unpackdeltas(variable.metrics)
26109 end
26110 data.tables=nil
26111 end
26112 end
26113 end
26114 local mt={
26115 __index=function(t,k)
26116 if k=="height" then
26117 local ht=t.boundingbox[4]
26118 return ht<0 and 0 or ht
26119 elseif k=="depth" then
26120 local dp=-t.boundingbox[2]
26121 return dp<0 and 0 or dp
26122 elseif k=="width" then
26123 return 0
26124 elseif k=="name" then
26125 return forcenotdef and ".notdef"
26126 end
26127 end
26128 }
26129 local function sameformat(sequence,steps,first,nofsteps,kind)
26130 return true
26131 end
26132 local function mergesteps_1(lookup,strict)
26133 local steps=lookup.steps
26134 local nofsteps=lookup.nofsteps
26135 local first=steps[1]
26136 if strict then
26137 local f=first.format
26138 for i=2,nofsteps do
26139 if steps[i].format~=f then
26140 if trace_optimizations then
26141 report_optimizations("not merging %a steps of %a lookup %a, different formats",nofsteps,lookup.type,lookup.name)
26142 end
26143 return 0
26144 end
26145 end
26146 end
26147 if trace_optimizations then
26148 report_optimizations("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name)
26149 end
26150 local target=first.coverage
26151 for i=2,nofsteps do
26152 local c=steps[i].coverage
26153 if c then
26154 for k,v in next,c do
26155 if not target[k] then
26156 target[k]=v
26157 end
26158 end
26159 end
26160 end
26161 lookup.nofsteps=1
26162 lookup.merged=true
26163 lookup.steps={ first }
26164 return nofsteps-1
26165 end
26166 local function mergesteps_2(lookup)
26167 local steps=lookup.steps
26168 local nofsteps=lookup.nofsteps
26169 local first=steps[1]
26170 if strict then
26171 local f=first.format
26172 for i=2,nofsteps do
26173 if steps[i].format~=f then
26174 if trace_optimizations then
26175 report_optimizations("not merging %a steps of %a lookup %a, different formats",nofsteps,lookup.type,lookup.name)
26176 end
26177 return 0
26178 end
26179 end
26180 end
26181 if trace_optimizations then
26182 report_optimizations("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name)
26183 end
26184 local target=first.coverage
26185 for i=2,nofsteps do
26186 local c=steps[i].coverage
26187 if c then
26188 for k,v in next,c do
26189 local tk=target[k]
26190 if tk then
26191 for kk,vv in next,v do
26192 if tk[kk]==nil then
26193 tk[kk]=vv
26194 end
26195 end
26196 else
26197 target[k]=v
26198 end
26199 end
26200 end
26201 end
26202 lookup.nofsteps=1
26203 lookup.merged=true
26204 lookup.steps={ first }
26205 return nofsteps-1
26206 end
26207 local function mergesteps_3(lookup,strict)
26208 local steps=lookup.steps
26209 local nofsteps=lookup.nofsteps
26210 if trace_optimizations then
26211 report_optimizations("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name)
26212 end
26213 local coverage={}
26214 for i=1,nofsteps do
26215 local c=steps[i].coverage
26216 if c then
26217 for k,v in next,c do
26218 local tk=coverage[k]
26219 if tk then
26220 if trace_optimizations then
26221 report_optimizations("quitting merge due to multiple checks")
26222 end
26223 return nofsteps
26224 else
26225 coverage[k]=v
26226 end
26227 end
26228 end
26229 end
26230 local first=steps[1]
26231 local baseclasses={}
26232 for i=1,nofsteps do
26233 local offset=i*10
26234 local step=steps[i]
26235 for k,v in sortedhash(step.baseclasses) do
26236 baseclasses[offset+k]=v
26237 end
26238 for k,v in next,step.coverage do
26239 v[1]=offset+v[1]
26240 end
26241 end
26242 first.baseclasses=baseclasses
26243 first.coverage=coverage
26244 lookup.nofsteps=1
26245 lookup.merged=true
26246 lookup.steps={ first }
26247 return nofsteps-1
26248 end
26249 local function nested(old,new)
26250 for k,v in next,old do
26251 if k=="ligature" then
26252 if not new.ligature then
26253 new.ligature=v
26254 end
26255 else
26256 local n=new[k]
26257 if n then
26258 nested(v,n)
26259 else
26260 new[k]=v
26261 end
26262 end
26263 end
26264 end
26265 local function mergesteps_4(lookup)
26266 local steps=lookup.steps
26267 local nofsteps=lookup.nofsteps
26268 local first=steps[1]
26269 if trace_optimizations then
26270 report_optimizations("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name)
26271 end
26272 local target=first.coverage
26273 for i=2,nofsteps do
26274 local c=steps[i].coverage
26275 if c then
26276 for k,v in next,c do
26277 local tk=target[k]
26278 if tk then
26279 nested(v,tk)
26280 else
26281 target[k]=v
26282 end
26283 end
26284 end
26285 end
26286 lookup.nofsteps=1
26287 lookup.steps={ first }
26288 return nofsteps-1
26289 end
26290 local function mergesteps_5(lookup)
26291 local steps=lookup.steps
26292 local nofsteps=lookup.nofsteps
26293 local first=steps[1]
26294 if trace_optimizations then
26295 report_optimizations("merging %a steps of %a lookup %a",nofsteps,lookup.type,lookup.name)
26296 end
26297 local target=first.coverage
26298 local hash=nil
26299 for k,v in next,target do
26300 hash=v[1]
26301 break
26302 end
26303 for i=2,nofsteps do
26304 local c=steps[i].coverage
26305 if c then
26306 for k,v in next,c do
26307 local tk=target[k]
26308 if tk then
26309 if not tk[2] then
26310 tk[2]=v[2]
26311 end
26312 if not tk[3] then
26313 tk[3]=v[3]
26314 end
26315 else
26316 target[k]=v
26317 v[1]=hash
26318 end
26319 end
26320 end
26321 end
26322 lookup.nofsteps=1
26323 lookup.merged=true
26324 lookup.steps={ first }
26325 return nofsteps-1
26326 end
26327 local function checkkerns(lookup)
26328 local steps=lookup.steps
26329 local nofsteps=lookup.nofsteps
26330 local kerned=0
26331 for i=1,nofsteps do
26332 local step=steps[i]
26333 if step.format=="pair" then
26334 local coverage=step.coverage
26335 local kerns=true
26336 for g1,d1 in next,coverage do
26337 if d1==true then
26338 elseif not d1 then
26339 elseif d1[1]~=0 or d1[2]~=0 or d1[4]~=0 then
26340 kerns=false
26341 break
26342 end
26343 end
26344 if kerns then
26345 if trace_optimizations then
26346 report_optimizations("turning pairs of step %a of %a lookup %a into kerns",i,lookup.type,lookup.name)
26347 end
26348 local c={}
26349 for g1,d1 in next,coverage do
26350 if d1 and d1~=true then
26351 c[g1]=d1[3]
26352 end
26353 end
26354 step.coverage=c
26355 step.format="move"
26356 kerned=kerned+1
26357 end
26358 end
26359 end
26360 return kerned
26361 end
26362 local strip_pairs=true
26363 local compact_pairs=true
26364 local compact_singles=true
26365 local merge_pairs=true
26366 local merge_singles=true
26367 local merge_substitutions=true
26368 local merge_alternates=true
26369 local merge_multiples=true
26370 local merge_ligatures=true
26371 local merge_cursives=true
26372 local merge_marks=true
26373 directives.register("otf.strip.pairs",function(v) strip_pairs=v end)
26374 directives.register("otf.compact.pairs",function(v) compact_pairs=v end)
26375 directives.register("otf.compact.singles",function(v) compact_singles=v end)
26376 directives.register("otf.merge.pairs",function(v) merge_pairs=v end)
26377 directives.register("otf.merge.singles",function(v) merge_singles=v end)
26378 directives.register("otf.merge.substitutions",function(v) merge_substitutions=v end)
26379 directives.register("otf.merge.alternates",function(v) merge_alternates=v end)
26380 directives.register("otf.merge.multiples",function(v) merge_multiples=v end)
26381 directives.register("otf.merge.ligatures",function(v) merge_ligatures=v end)
26382 directives.register("otf.merge.cursives",function(v) merge_cursives=v end)
26383 directives.register("otf.merge.marks",function(v) merge_marks=v end)
26384 local function checkpairs(lookup)
26385 local steps=lookup.steps
26386 local nofsteps=lookup.nofsteps
26387 local kerned=0
26388 local function onlykerns(step)
26389 local coverage=step.coverage
26390 for g1,d1 in next,coverage do
26391 for g2,d2 in next,d1 do
26392 if d2[2] then
26393 return false
26394 else
26395 local v=d2[1]
26396 if v==true then
26397 elseif v and (v[1]~=0 or v[2]~=0 or v[4]~=0) then
26398 return false
26399 end
26400 end
26401 end
26402 end
26403 return coverage
26404 end
26405 for i=1,nofsteps do
26406 local step=steps[i]
26407 if step.format=="pair" then
26408 local coverage=onlykerns(step)
26409 if coverage then
26410 if trace_optimizations then
26411 report_optimizations("turning pairs of step %a of %a lookup %a into kerns",i,lookup.type,lookup.name)
26412 end
26413 for g1,d1 in next,coverage do
26414 local d={}
26415 for g2,d2 in next,d1 do
26416 local v=d2[1]
26417 if v==true then
26418 elseif v then
26419 d[g2]=v[3]
26420 end
26421 end
26422 coverage[g1]=d
26423 end
26424 step.format="move"
26425 kerned=kerned+1
26426 end
26427 end
26428 end
26429 return kerned
26430 end
26431 local function strippairs(lookup)
26432 local steps=lookup.steps
26433 local nofsteps=lookup.nofsteps
26434 local stripped=0
26435 for i=1,nofsteps do
26436 local step=steps[i]
26437 if step.format=="pair" then
26438 local coverage=step.coverage
26439 for g1,d1 in next,coverage do
26440 for g2,d2 in next,d1 do
26441 if d2[2] then
26442 elseif d2[1]==true then
26443 d1[g2]=nil
26444 stripped=stripped+1
26445 end
26446 end
26447 end
26448 end
26449 end
26450 return stripped
26451 end
26452 function readers.compact(data)
26453 if not data or data.compacted then
26454 return
26455 else
26456 data.compacted=true
26457 end
26458 local resources=data.resources
26459 local stripped=0
26460 local merged=0
26461 local kerned=0
26462 local allsteps=0
26463 local function compact(what)
26464 local lookups=resources[what]
26465 if lookups then
26466 for i=1,#lookups do
26467 local lookup=lookups[i]
26468 local nofsteps=lookup.nofsteps
26469 local kind=lookup.type
26470 allsteps=allsteps+nofsteps
26471 if nofsteps>1 then
26472 local merg=merged
26473 if kind=="gsub_single" then
26474 if merge_substitutions then
26475 merged=merged+mergesteps_1(lookup)
26476 end
26477 elseif kind=="gsub_alternate" then
26478 if merge_alternates then
26479 merged=merged+mergesteps_1(lookup)
26480 end
26481 elseif kind=="gsub_multiple" then
26482 if merge_multiples then
26483 merged=merged+mergesteps_1(lookup)
26484 end
26485 elseif kind=="gsub_ligature" then
26486 if merge_ligatures then
26487 merged=merged+mergesteps_4(lookup)
26488 end
26489 elseif kind=="gpos_single" then
26490 if merge_singles then
26491 merged=merged+mergesteps_1(lookup,true)
26492 end
26493 if compact_singles then
26494 kerned=kerned+checkkerns(lookup)
26495 end
26496 elseif kind=="gpos_pair" then
26497 if strip_pairs then
26498 stripped=stripped+strippairs(lookup)
26499 end
26500 if merge_pairs then
26501 merged=merged+mergesteps_2(lookup)
26502 end
26503 if compact_pairs then
26504 kerned=kerned+checkpairs(lookup)
26505 end
26506 elseif kind=="gpos_cursive" then
26507 if merge_cursives then
26508 merged=merged+mergesteps_5(lookup)
26509 end
26510 elseif kind=="gpos_mark2mark" or kind=="gpos_mark2base" or kind=="gpos_mark2ligature" then
26511 if merge_marks then
26512 merged=merged+mergesteps_3(lookup)
26513 end
26514 end
26515 if merg~=merged then
26516 lookup.merged=true
26517 end
26518 elseif nofsteps==1 then
26519 local kern=kerned
26520 if kind=="gpos_single" then
26521 if compact_singles then
26522 kerned=kerned+checkkerns(lookup)
26523 end
26524 elseif kind=="gpos_pair" then
26525 if compact_pairs then
26526 kerned=kerned+checkpairs(lookup)
26527 end
26528 end
26529 if kern~=kerned then
26530 end
26531 end
26532 end
26533 elseif trace_optimizations then
26534 report_optimizations("no lookups in %a",what)
26535 end
26536 end
26537 compact("sequences")
26538 compact("sublookups")
26539 if trace_optimizations then
26540 if stripped>0 then
26541 report_optimizations("%i zero positions stripped before merging",stripped)
26542 end
26543 if merged>0 then
26544 report_optimizations("%i steps of %i removed due to merging",merged,allsteps)
26545 end
26546 if kerned>0 then
26547 report_optimizations("%i steps of %i steps turned from pairs into kerns",kerned,allsteps)
26548 end
26549 end
26550 end
26551 if CONTEXTLMTXMODE and CONTEXTLMTXMODE>0 then
26552 local done=0
26553 local function condense_1(k,v,t)
26554 if type(v)=="table" then
26555 local u=false
26556 local l=false
26557 for k,v in next,v do
26558 if k=="ligature" then
26559 l=v
26560 if u then
26561 break
26562 end
26563 elseif u then
26564 break
26565 else
26566 u=true
26567 end
26568 end
26569 if l and not u then
26570 t[k]=l
26571 done=done+1
26572 end
26573 if u then
26574 for k,vv in next,v do
26575 if k~="ligature" then
26576 condense_1(k,vv,v)
26577 end
26578 end
26579 end
26580 end
26581 end
26582 local function condensesteps_1(lookup)
26583 done=0
26584 if lookup.type=="gsub_ligature" then
26585 local steps=lookup.steps
26586 if steps then
26587 for i=1,#steps do
26588 local step=steps[i]
26589 local coverage=step.coverage
26590 if coverage then
26591 for k,v in next,coverage do
26592 if condense_1(k,v,coverage) then
26593 coverage[k]=v.ligature
26594 done=done+1
26595 end
26596 end
26597 end
26598 end
26599 end
26600 end
26601 return done
26602 end
26603 function readers.condense(data)
26604 if not data or data.condensed then
26605 return
26606 else
26607 data.condensed=true
26608 end
26609 local resources=data.resources
26610 local condensed=0
26611 local function condense(what)
26612 local lookups=resources[what]
26613 if lookups then
26614 for i=1,#lookups do
26615 condensed=condensed+condensesteps_1(lookups[i])
26616 end
26617 elseif trace_optimizations then
26618 report_optimizations("no lookups in %a",what)
26619 end
26620 end
26621 condense("sequences")
26622 condense("sublookups")
26623 if trace_optimizations then
26624 if condensed>0 then
26625 report_optimizations("%i ligatures condensed",condensed)
26626 end
26627 end
26628 end
26629 end
26630 local function mergesteps(t,k)
26631 if k=="merged" then
26632 local merged={}
26633 for i=1,#t do
26634 local step=t[i]
26635 local coverage=step.coverage
26636 for k in next,coverage do
26637 local m=merged[k]
26638 if m then
26639 m[2]=i
26640 else
26641 merged[k]={ i,i }
26642 end
26643 end
26644 end
26645 t.merged=merged
26646 return merged
26647 end
26648 end
26649 local function checkmerge(sequence)
26650 local steps=sequence.steps
26651 if steps then
26652 setmetatableindex(steps,mergesteps)
26653 end
26654 end
26655 local function checkflags(sequence,resources)
26656 if not sequence.skiphash then
26657 local flags=sequence.flags
26658 if flags then
26659 local skipmark=flags[1]
26660 local skipligature=flags[2]
26661 local skipbase=flags[3]
26662 local markclass=sequence.markclass
26663 local skipsome=skipmark or skipligature or skipbase or markclass or false
26664 if skipsome then
26665 sequence.skiphash=setmetatableindex(function(t,k)
26666 local c=resources.classes[k]
26667 local v=c==skipmark
26668 or (markclass and c=="mark" and not markclass[k])
26669 or c==skipligature
26670 or c==skipbase
26671 or false
26672 t[k]=v
26673 return v
26674 end)
26675 else
26676 sequence.skiphash=false
26677 end
26678 else
26679 sequence.skiphash=false
26680 end
26681 end
26682 end
26683 local function checksteps(sequence)
26684 local steps=sequence.steps
26685 if steps then
26686 for i=1,#steps do
26687 steps[i].index=i
26688 end
26689 end
26690 end
26691 if fonts.helpers then
26692 fonts.helpers.checkmerge=checkmerge
26693 fonts.helpers.checkflags=checkflags
26694 fonts.helpers.checksteps=checksteps
26695 end
26696 function readers.expand(data)
26697 if not data or data.expanded then
26698 return
26699 else
26700 data.expanded=true
26701 end
26702 local resources=data.resources
26703 local sublookups=resources.sublookups
26704 local sequences=resources.sequences
26705 local markclasses=resources.markclasses
26706 local descriptions=data.descriptions
26707 if descriptions then
26708 local defaultwidth=resources.defaultwidth or 0
26709 local defaultheight=resources.defaultheight or 0
26710 local defaultdepth=resources.defaultdepth or 0
26711 local basename=trace_markwidth and file.basename(resources.filename)
26712 for u,d in next,descriptions do
26713 local bb=d.boundingbox
26714 local wd=d.width
26715 if not wd then
26716 d.width=defaultwidth
26717 elseif trace_markwidth and wd~=0 and d.class=="mark" then
26718 report_markwidth("mark %a with width %b found in %a",d.name or "<noname>",wd,basename)
26719 end
26720 if bb then
26721 local ht=bb[4]
26722 local dp=-bb[2]
26723 if ht==0 or ht<0 then
26724 else
26725 d.height=ht
26726 end
26727 if dp==0 or dp<0 then
26728 else
26729 d.depth=dp
26730 end
26731 end
26732 end
26733 end
26734 local function expandlookups(sequences,whatever)
26735 if sequences then
26736 for i=1,#sequences do
26737 local sequence=sequences[i]
26738 local steps=sequence.steps
26739 if steps then
26740 local nofsteps=sequence.nofsteps
26741 local kind=sequence.type
26742 local markclass=sequence.markclass
26743 if markclass then
26744 if not markclasses then
26745 report_warning("missing markclasses")
26746 sequence.markclass=false
26747 else
26748 sequence.markclass=markclasses[markclass]
26749 end
26750 end
26751 for i=1,nofsteps do
26752 local step=steps[i]
26753 local baseclasses=step.baseclasses
26754 if baseclasses then
26755 local coverage=step.coverage
26756 for k,v in next,coverage do
26757 v[1]=baseclasses[v[1]]
26758 end
26759 elseif kind=="gpos_cursive" then
26760 local coverage=step.coverage
26761 for k,v in next,coverage do
26762 v[1]=coverage
26763 end
26764 end
26765 local rules=step.rules
26766 if rules then
26767 local rulehash={ n=0 }
26768 local rulesize=0
26769 local coverage={}
26770 local lookuptype=sequence.type
26771 local nofrules=#rules
26772 step.coverage=coverage
26773 for currentrule=1,nofrules do
26774 local rule=rules[currentrule]
26775 local current=rule.current
26776 local before=rule.before
26777 local after=rule.after
26778 local replacements=rule.replacements or false
26779 local sequence={}
26780 local nofsequences=0
26781 if before then
26782 for n=1,#before do
26783 nofsequences=nofsequences+1
26784 sequence[nofsequences]=before[n]
26785 end
26786 end
26787 local start=nofsequences+1
26788 for n=1,#current do
26789 nofsequences=nofsequences+1
26790 sequence[nofsequences]=current[n]
26791 end
26792 local stop=nofsequences
26793 if after then
26794 for n=1,#after do
26795 nofsequences=nofsequences+1
26796 sequence[nofsequences]=after[n]
26797 end
26798 end
26799 local lookups=rule.lookups or false
26800 local subtype=nil
26801 if lookups then
26802 for i=1,#lookups do
26803 local lookups=lookups[i]
26804 if lookups then
26805 for k,v in next,lookups do
26806 local lookup=sublookups[v]
26807 if not lookup and whatever then
26808 lookup=whatever[v]
26809 end
26810 if lookup then
26811 lookups[k]=lookup
26812 if not subtype then
26813 subtype=lookup.type
26814 end
26815 else
26816 end
26817 end
26818 end
26819 end
26820 end
26821 if sequence[1] then
26822 sequence.n=#sequence
26823 local ruledata={
26824 currentrule,
26825 lookuptype,
26826 sequence,
26827 start,
26828 stop,
26829 lookups,
26830 replacements,
26831 subtype,
26832 }
26833 rulesize=rulesize+1
26834 rulehash[rulesize]=ruledata
26835 rulehash.n=rulesize
26836 if true then
26837 for unic in next,sequence[start] do
26838 local cu=coverage[unic]
26839 if cu then
26840 local n=#cu+1
26841 cu[n]=ruledata
26842 cu.n=n
26843 else
26844 coverage[unic]={ ruledata,n=1 }
26845 end
26846 end
26847 else
26848 for unic in next,sequence[start] do
26849 local cu=coverage[unic]
26850 if cu then
26851 else
26852 coverage[unic]=rulehash
26853 end
26854 end
26855 end
26856 end
26857 end
26858 end
26859 end
26860 checkmerge(sequence)
26861 checkflags(sequence,resources)
26862 checksteps(sequence)
26863 end
26864 end
26865 end
26866 end
26867 expandlookups(sequences)
26868 expandlookups(sublookups,sequences)
26869 end
26870
26871 end -- closure
26872
26873 do -- begin closure to overcome local limits and interference
26874
26875 if not modules then modules={} end modules ['font-ota']={
26876 version=1.001,
26877 comment="companion to font-ini.mkiv",
26878 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
26879 copyright="PRAGMA ADE / ConTeXt Development Team",
26880 license="see context related readme files"
26881 }
26882 local type=type
26883 local setmetatableindex=table.setmetatableindex
26884 if not trackers then trackers={ register=function() end } end
26885 local fonts,nodes,node=fonts,nodes,node
26886 local allocate=utilities.storage.allocate
26887 local otf=fonts.handlers.otf
26888 local analyzers=fonts.analyzers
26889 local initializers=allocate()
26890 local methods=allocate()
26891 analyzers.initializers=initializers
26892 analyzers.methods=methods
26893 local nuts=nodes.nuts
26894 local tonut=nuts.tonut
26895 local getnext=nuts.getnext
26896 local getprev=nuts.getprev
26897 local getprev=nuts.getprev
26898 local getprop=nuts.getprop
26899 local setprop=nuts.setprop
26900 local getsubtype=nuts.getsubtype
26901 local getchar=nuts.getchar
26902 local ischar=nuts.ischar
26903 local endofmath=nuts.endofmath
26904 local nodecodes=nodes.nodecodes
26905 local disc_code=nodecodes.disc
26906 local math_code=nodecodes.math
26907 local fontdata=fonts.hashes.identifiers
26908 local categories=characters and characters.categories or {}
26909 local chardata=characters and characters.data
26910 local otffeatures=fonts.constructors.features.otf
26911 local registerotffeature=otffeatures.register
26912 local setstate=nuts.setstate
26913 local getstate=nuts.getstate
26914 if not setstate or not getstate then
26915 setstate=function(n,v)
26916 setprop(n,"state",v)
26917 end
26918 getstate=function(n,v)
26919 local s=getprop(n,"state")
26920 if v then
26921 return s==v
26922 else
26923 return s
26924 end
26925 end
26926 nuts.setstate=setstate
26927 nuts.getstate=getstate
26928 end
26929 local s_init=1 local s_rphf=7
26930 local s_medi=2 local s_half=8
26931 local s_fina=3 local s_pref=9
26932 local s_isol=4 local s_blwf=10
26933 local s_mark=5 local s_pstf=11
26934 local s_rest=6
26935 local states=allocate {
26936 init=s_init,
26937 medi=s_medi,
26938 med2=s_medi,
26939 fina=s_fina,
26940 fin2=s_fina,
26941 fin3=s_fina,
26942 isol=s_isol,
26943 mark=s_mark,
26944 rest=s_rest,
26945 rphf=s_rphf,
26946 half=s_half,
26947 pref=s_pref,
26948 blwf=s_blwf,
26949 pstf=s_pstf,
26950 }
26951 local features=allocate {
26952 init=s_init,
26953 medi=s_medi,
26954 med2=s_medi,
26955 fina=s_fina,
26956 fin2=s_fina,
26957 fin3=s_fina,
26958 isol=s_isol,
26959 rphf=s_rphf,
26960 half=s_half,
26961 pref=s_pref,
26962 blwf=s_blwf,
26963 pstf=s_pstf,
26964 }
26965 analyzers.states=states
26966 analyzers.features=features
26967 analyzers.useunicodemarks=false
26968 function analyzers.setstate(head,font)
26969 local useunicodemarks=analyzers.useunicodemarks
26970 local tfmdata=fontdata[font]
26971 local descriptions=tfmdata.descriptions
26972 local first,last,current,n,done=nil,nil,head,0,false
26973 current=tonut(current)
26974 while current do
26975 local char,id=ischar(current,font)
26976 if char and not getstate(current) then
26977 done=true
26978 local d=descriptions[char]
26979 if d then
26980 if d.class=="mark" then
26981 done=true
26982 setstate(current,s_mark)
26983 elseif useunicodemarks and categories[char]=="mn" then
26984 done=true
26985 setstate(current,s_mark)
26986 elseif n==0 then
26987 first,last,n=current,current,1
26988 setstate(current,s_init)
26989 else
26990 last,n=current,n+1
26991 setstate(current,s_medi)
26992 end
26993 else
26994 if first and first==last then
26995 setstate(last,s_isol)
26996 elseif last then
26997 setstate(last,s_fina)
26998 end
26999 first,last,n=nil,nil,0
27000 end
27001 elseif char==false then
27002 if first and first==last then
27003 setstate(last,s_isol)
27004 elseif last then
27005 setstate(last,s_fina)
27006 end
27007 first,last,n=nil,nil,0
27008 if id==math_code then
27009 current=endofmath(current)
27010 end
27011 elseif id==disc_code then
27012 setstate(current,s_medi)
27013 last=current
27014 else
27015 if first and first==last then
27016 setstate(last,s_isol)
27017 elseif last then
27018 setstate(last,s_fina)
27019 end
27020 first,last,n=nil,nil,0
27021 if id==math_code then
27022 current=endofmath(current)
27023 end
27024 end
27025 current=getnext(current)
27026 end
27027 if first and first==last then
27028 setstate(last,s_isol)
27029 elseif last then
27030 setstate(last,s_fina)
27031 end
27032 return head,done
27033 end
27034 local function analyzeinitializer(tfmdata,value)
27035 local script,language=otf.scriptandlanguage(tfmdata)
27036 local action=initializers[script]
27037 if not action then
27038 elseif type(action)=="function" then
27039 return action(tfmdata,value)
27040 else
27041 local action=action[language]
27042 if action then
27043 return action(tfmdata,value)
27044 end
27045 end
27046 end
27047 local function analyzeprocessor(head,font,attr)
27048 local tfmdata=fontdata[font]
27049 local script,language=otf.scriptandlanguage(tfmdata,attr)
27050 local action=methods[script]
27051 if not action then
27052 elseif type(action)=="function" then
27053 return action(head,font,attr)
27054 else
27055 action=action[language]
27056 if action then
27057 return action(head,font,attr)
27058 end
27059 end
27060 return head,false
27061 end
27062 registerotffeature {
27063 name="analyze",
27064 description="analysis of character classes",
27065 default=true,
27066 initializers={
27067 node=analyzeinitializer,
27068 },
27069 processors={
27070 position=1,
27071 node=analyzeprocessor,
27072 }
27073 }
27074 methods.latn=analyzers.setstate
27075 local arab_warned={}
27076 local function warning(current,what)
27077 local char=getchar(current)
27078 if not arab_warned[char] then
27079 log.report("analyze","arab: character %C has no %a class",char,what)
27080 arab_warned[char]=true
27081 end
27082 end
27083 local mappers=allocate {
27084 l=s_init,
27085 d=s_medi,
27086 c=s_medi,
27087 r=s_fina,
27088 u=s_isol,
27089 }
27090 local classifiers=characters.classifiers
27091 if not classifiers then
27092 local f_arabic,l_arabic=characters.blockrange("arabic")
27093 local f_syriac,l_syriac=characters.blockrange("syriac")
27094 local f_mandiac,l_mandiac=characters.blockrange("mandiac")
27095 local f_nko,l_nko=characters.blockrange("nko")
27096 local f_ext_a,l_ext_a=characters.blockrange("arabicextendeda")
27097 classifiers=setmetatableindex(function(t,k)
27098 if type(k)=="number" then
27099 local c=chardata[k]
27100 local v=false
27101 if c then
27102 local arabic=c.arabic
27103 if arabic then
27104 v=mappers[arabic]
27105 if not v then
27106 log.report("analyze","error in mapping arabic %C",k)
27107 v=false
27108 end
27109 elseif (k>=f_arabic and k<=l_arabic) or
27110 (k>=f_syriac and k<=l_syriac) or
27111 (k>=f_mandiac and k<=l_mandiac) or
27112 (k>=f_nko and k<=l_nko) or
27113 (k>=f_ext_a and k<=l_ext_a) then
27114 if categories[k]=="mn" then
27115 v=s_mark
27116 else
27117 v=s_rest
27118 end
27119 end
27120 end
27121 t[k]=v
27122 return v
27123 end
27124 end)
27125 characters.classifiers=classifiers
27126 end
27127 function methods.arab(head,font,attr)
27128 local first,last,c_first,c_last
27129 local current=head
27130 local done=false
27131 current=tonut(current)
27132 while current do
27133 local char,id=ischar(current,font)
27134 if char and not getstate(current) then
27135 done=true
27136 local classifier=classifiers[char]
27137 if not classifier then
27138 if last then
27139 if c_last==s_medi or c_last==s_fina then
27140 setstate(last,s_fina)
27141 else
27142 warning(last,"fina")
27143 setstate(last,s_error)
27144 end
27145 first,last=nil,nil
27146 elseif first then
27147 if c_first==s_medi or c_first==s_fina then
27148 setstate(first,s_isol)
27149 else
27150 warning(first,"isol")
27151 setstate(first,s_error)
27152 end
27153 first=nil
27154 end
27155 elseif classifier==s_mark then
27156 setstate(current,s_mark)
27157 elseif classifier==s_isol then
27158 if last then
27159 if c_last==s_medi or c_last==s_fina then
27160 setstate(last,s_fina)
27161 else
27162 warning(last,"fina")
27163 setstate(last,s_error)
27164 end
27165 first,last=nil,nil
27166 elseif first then
27167 if c_first==s_medi or c_first==s_fina then
27168 setstate(first,s_isol)
27169 else
27170 warning(first,"isol")
27171 setstate(first,s_error)
27172 end
27173 first=nil
27174 end
27175 setstate(current,s_isol)
27176 elseif classifier==s_medi then
27177 if first then
27178 last=current
27179 c_last=classifier
27180 setstate(current,s_medi)
27181 else
27182 setstate(current,s_init)
27183 first=current
27184 c_first=classifier
27185 end
27186 elseif classifier==s_fina then
27187 if last then
27188 if getstate(last)~=s_init then
27189 setstate(last,s_medi)
27190 end
27191 setstate(current,s_fina)
27192 first,last=nil,nil
27193 elseif first then
27194 setstate(current,s_fina)
27195 first=nil
27196 else
27197 setstate(current,s_isol)
27198 end
27199 else
27200 setstate(current,s_rest)
27201 if last then
27202 if c_last==s_medi or c_last==s_fina then
27203 setstate(last,s_fina)
27204 else
27205 warning(last,"fina")
27206 setstate(last,s_error)
27207 end
27208 first,last=nil,nil
27209 elseif first then
27210 if c_first==s_medi or c_first==s_fina then
27211 setstate(first,s_isol)
27212 else
27213 warning(first,"isol")
27214 setstate(first,s_error)
27215 end
27216 first=nil
27217 end
27218 end
27219 else
27220 if last then
27221 if c_last==s_medi or c_last==s_fina then
27222 setstate(last,s_fina)
27223 else
27224 warning(last,"fina")
27225 setstate(last,s_error)
27226 end
27227 first,last=nil,nil
27228 elseif first then
27229 if c_first==s_medi or c_first==s_fina then
27230 setstate(first,s_isol)
27231 else
27232 warning(first,"isol")
27233 setstate(first,s_error)
27234 end
27235 first=nil
27236 end
27237 if id==math_code then
27238 current=endofmath(current)
27239 end
27240 end
27241 current=getnext(current)
27242 end
27243 if last then
27244 if c_last==s_medi or c_last==s_fina then
27245 setstate(last,s_fina)
27246 else
27247 warning(last,"fina")
27248 setstate(last,s_error)
27249 end
27250 elseif first then
27251 if c_first==s_medi or c_first==s_fina then
27252 setstate(first,s_isol)
27253 else
27254 warning(first,"isol")
27255 setstate(first,s_error)
27256 end
27257 end
27258 return head,done
27259 end
27260 methods.syrc=methods.arab
27261 methods.mand=methods.arab
27262 methods.nko=methods.arab
27263 do
27264 local joining=setmetatableindex(function(t,k)
27265 if type(k)=="number" then
27266 local c=chardata[k]
27267 local v=false
27268 if c then
27269 local mongolian=c.mongolian
27270 v=mongolian
27271 end
27272 t[k]=v
27273 return v
27274 end
27275 end)
27276 function methods.mong(head,font,attr)
27277 local first,last
27278 local current=head
27279 local done=false
27280 local prevjoin=nil
27281 local prestate=nil
27282 current=tonut(current)
27283 local function wrapup()
27284 if last then
27285 if last~=first then
27286 local s=getstate(last)
27287 if s==s_medi then
27288 setstate(last,s_fina)
27289 elseif s==s_init then
27290 setstate(last,s_isol)
27291 end
27292 end
27293 last=nil
27294 first=nil
27295 prevjoin=nil
27296 prestate=nil
27297 end
27298 end
27299 while current do
27300 local char,id=ischar(current,font)
27301 if char and not getstate(current) then
27302 local currjoin=joining[char]
27303 done=true
27304 if not last then
27305 setstate(current,s_isol)
27306 prevjoin=currjoin
27307 first=current
27308 last=current
27309 prevstate=s_isol
27310 elseif currjoin=="t" then
27311 last=current
27312 elseif prevjoin=="d" or prevjoin=="jc" or prevjoin=="l" then
27313 if currjoin=="d" or prevjoin=="jc" or prevjoin=="r" then
27314 local s=getstate(last)
27315 if s==s_isol then
27316 setstate(last,s_init)
27317 elseif s==s_fina then
27318 setstate(last,s_medi)
27319 end
27320 setstate(current,s_fina)
27321 prevstate=s_fina
27322 elseif prevjoin=="nj" or prevjoin=="l" then
27323 local s=getstate(last)
27324 if s==s_medi then
27325 setstate(last,s_fina)
27326 elseif s==s_init then
27327 setstate(last,s_isol)
27328 end
27329 setstate(current,s_isol)
27330 prevstate=s_isol
27331 end
27332 prevjoin=currjoin
27333 last=current
27334 elseif prevjoin=="nj" or prevjoin=="r" then
27335 if s==s_medi then
27336 setstate(last,s_fina)
27337 elseif s==s_init then
27338 setstate(last,s_isol)
27339 end
27340 setstate(current,s_isol)
27341 prevjoin=currjoin
27342 prevstate=s_isol
27343 last=current
27344 elseif last then
27345 wrapup()
27346 end
27347 else
27348 if last then
27349 wrapup()
27350 end
27351 if id==math_code then
27352 current=endofmath(current)
27353 end
27354 end
27355 current=getnext(current)
27356 end
27357 if last then
27358 wrapup()
27359 end
27360 return head,done
27361 end
27362 end
27363 directives.register("otf.analyze.useunicodemarks",function(v)
27364 analyzers.useunicodemarks=v
27365 end)
27366
27367 end -- closure
27368
27369 do -- begin closure to overcome local limits and interference
27370
27371 if not modules then modules={} end modules ['font-ots']={
27372 version=1.001,
27373 optimize=true,
27374 comment="companion to font-ini.mkiv",
27375 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
27376 copyright="PRAGMA ADE / ConTeXt Development Team",
27377 license="see context related readme files",
27378 }
27379 local type,next,tonumber=type,next,tonumber
27380 local random=math.random
27381 local formatters=string.formatters
27382 local insert=table.insert
27383 local registertracker=trackers.register
27384 local logs=logs
27385 local trackers=trackers
27386 local nodes=nodes
27387 local attributes=attributes
27388 local fonts=fonts
27389 local otf=fonts.handlers.otf
27390 local tracers=nodes.tracers
27391 local trace_singles=false registertracker("otf.singles",function(v) trace_singles=v end)
27392 local trace_multiples=false registertracker("otf.multiples",function(v) trace_multiples=v end)
27393 local trace_alternatives=false registertracker("otf.alternatives",function(v) trace_alternatives=v end)
27394 local trace_ligatures=false registertracker("otf.ligatures",function(v) trace_ligatures=v end)
27395 local trace_contexts=false registertracker("otf.contexts",function(v) trace_contexts=v end)
27396 local trace_marks=false registertracker("otf.marks",function(v) trace_marks=v end)
27397 local trace_kerns=false registertracker("otf.kerns",function(v) trace_kerns=v end)
27398 local trace_cursive=false registertracker("otf.cursive",function(v) trace_cursive=v end)
27399 local trace_preparing=false registertracker("otf.preparing",function(v) trace_preparing=v end)
27400 local trace_bugs=false registertracker("otf.bugs",function(v) trace_bugs=v end)
27401 local trace_details=false registertracker("otf.details",function(v) trace_details=v end)
27402 local trace_steps=false registertracker("otf.steps",function(v) trace_steps=v end)
27403 local trace_skips=false registertracker("otf.skips",function(v) trace_skips=v end)
27404 local trace_plugins=false registertracker("otf.plugins",function(v) trace_plugins=v end)
27405 local trace_chains=false registertracker("otf.chains",function(v) trace_chains=v end)
27406 local trace_kernruns=false registertracker("otf.kernruns",function(v) trace_kernruns=v end)
27407 local trace_compruns=false registertracker("otf.compruns",function(v) trace_compruns=v end)
27408 local trace_testruns=false registertracker("otf.testruns",function(v) trace_testruns=v end)
27409 local forcediscretionaries=false
27410 local forcepairadvance=false
27411 local repeatablemultiples=context or false
27412 directives.register("otf.forcediscretionaries",function(v) forcediscretionaries=v end)
27413 directives.register("otf.forcepairadvance",function(v) forcepairadvance=v end)
27414 local report_direct=logs.reporter("fonts","otf direct")
27415 local report_subchain=logs.reporter("fonts","otf subchain")
27416 local report_chain=logs.reporter("fonts","otf chain")
27417 local report_process=logs.reporter("fonts","otf process")
27418 local report_warning=logs.reporter("fonts","otf warning")
27419 local report_run=logs.reporter("fonts","otf run")
27420 registertracker("otf.substitutions","otf.singles","otf.multiples","otf.alternatives","otf.ligatures")
27421 registertracker("otf.positions","otf.marks","otf.kerns","otf.cursive")
27422 registertracker("otf.actions","otf.substitutions","otf.positions")
27423 registertracker("otf.sample","otf.steps","otf.substitutions","otf.positions","otf.analyzing")
27424 registertracker("otf.sample.silent","otf.steps=silent","otf.substitutions","otf.positions","otf.analyzing")
27425 local nuts=nodes.nuts
27426 local getnext=nuts.getnext
27427 local setnext=nuts.setnext
27428 local getprev=nuts.getprev
27429 local setprev=nuts.setprev
27430 local getboth=nuts.getboth
27431 local setboth=nuts.setboth
27432 local getid=nuts.getid
27433 local getstate=nuts.getstate
27434 local getsubtype=nuts.getsubtype
27435 local getchar=nuts.getchar
27436 local setchar=nuts.setchar
27437 local getdisc=nuts.getdisc
27438 local setdisc=nuts.setdisc
27439 local getreplace=nuts.getreplace
27440 local setlink=nuts.setlink
27441 local getwidth=nuts.getwidth
27442 local getattr=nuts.getattr
27443 local getglyphdata=nuts.getglyphdata
27444 local components=nuts.components
27445 local copynocomponents=components.copynocomponents
27446 local copyonlyglyphs=components.copyonlyglyphs
27447 local countcomponents=components.count
27448 local setcomponents=components.set
27449 local getcomponents=components.get
27450 local flushcomponents=components.flush
27451 local ischar=nuts.ischar
27452 local usesfont=nuts.usesfont
27453 local insertnodeafter=nuts.insertafter
27454 local copynode=nuts.copy
27455 local copynodelist=nuts.copylist
27456 local removenode=nuts.remove
27457 local findnodetail=nuts.tail
27458 local flushnodelist=nuts.flushlist
27459 local flushnode=nuts.flushnode
27460 local endofmath=nuts.endofmath
27461 local startofpar=nuts.startofpar
27462 local setmetatable=setmetatable
27463 local setmetatableindex=table.setmetatableindex
27464 local nextnode=nuts.traversers.node
27465 local nodecodes=nodes.nodecodes
27466 local glyphcodes=nodes.glyphcodes
27467 local glyph_code=nodecodes.glyph
27468 local glue_code=nodecodes.glue
27469 local disc_code=nodecodes.disc
27470 local math_code=nodecodes.math
27471 local dir_code=nodecodes.dir
27472 local par_code=nodecodes.par
27473 local lefttoright_code=nodes.dirvalues.lefttoright
27474 local righttoleft_code=nodes.dirvalues.righttoleft
27475 local discretionarydisc_code=nodes.disccodes.discretionary
27476 local a_noligature=attributes.private("noligature")
27477 local injections=nodes.injections
27478 local setmark=injections.setmark
27479 local setcursive=injections.setcursive
27480 local setkern=injections.setkern
27481 local setmove=injections.setmove
27482 local setposition=injections.setposition
27483 local resetinjection=injections.reset
27484 local copyinjection=injections.copy
27485 local setligaindex=injections.setligaindex
27486 local getligaindex=injections.getligaindex
27487 local fontdata=fonts.hashes.identifiers
27488 local fontfeatures=fonts.hashes.features
27489 local otffeatures=fonts.constructors.features.otf
27490 local registerotffeature=otffeatures.register
27491 local onetimemessage=fonts.loggers.onetimemessage or function() end
27492 local getrandom=utilities and utilities.randomizer and utilities.randomizer.get
27493 otf.defaultnodealternate="none"
27494 local tfmdata=false
27495 local characters=false
27496 local descriptions=false
27497 local marks=false
27498 local classes=false
27499 local currentfont=false
27500 local factor=0
27501 local threshold=0
27502 local checkmarks=false
27503 local discs=false
27504 local spaces=false
27505 local sweepnode=nil
27506 local sweephead={}
27507 local notmatchpre={}
27508 local notmatchpost={}
27509 local notmatchreplace={}
27510 local handlers={}
27511 local isspace=injections.isspace
27512 local getthreshold=injections.getthreshold
27513 local checkstep=(tracers and tracers.steppers.check) or function() end
27514 local registerstep=(tracers and tracers.steppers.register) or function() end
27515 local registermessage=(tracers and tracers.steppers.message) or function() end
27516 local function logprocess(...)
27517 if trace_steps then
27518 registermessage(...)
27519 if trace_steps=="silent" then
27520 return
27521 end
27522 end
27523 report_direct(...)
27524 end
27525 local function logwarning(...)
27526 report_direct(...)
27527 end
27528 local gref do
27529 local f_unicode=formatters["U+%X"]
27530 local f_uniname=formatters["U+%X (%s)"]
27531 local f_unilist=formatters["% t"]
27532 gref=function(n)
27533 if type(n)=="number" then
27534 local description=descriptions[n]
27535 local name=description and description.name
27536 if name then
27537 return f_uniname(n,name)
27538 else
27539 return f_unicode(n)
27540 end
27541 elseif n then
27542 local t={}
27543 for i=1,#n do
27544 local ni=n[i]
27545 if tonumber(ni) then
27546 local di=descriptions[ni]
27547 local nn=di and di.name
27548 if nn then
27549 t[#t+1]=f_uniname(ni,nn)
27550 else
27551 t[#t+1]=f_unicode(ni)
27552 end
27553 end
27554 end
27555 return f_unilist(t)
27556 else
27557 return "<error in node mode tracing>"
27558 end
27559 end
27560 end
27561 local function cref(dataset,sequence,index)
27562 if not dataset then
27563 return "no valid dataset"
27564 end
27565 local merged=sequence.merged and "merged " or ""
27566 if index and index>1 then
27567 return formatters["feature %a, type %a, %schain lookup %a, index %a"](
27568 dataset[4],sequence.type,merged,sequence.name,index)
27569 else
27570 return formatters["feature %a, type %a, %schain lookup %a"](
27571 dataset[4],sequence.type,merged,sequence.name)
27572 end
27573 end
27574 local function pref(dataset,sequence)
27575 return formatters["feature %a, type %a, %slookup %a"](
27576 dataset[4],sequence.type,sequence.merged and "merged " or "",sequence.name)
27577 end
27578 local function mref(rlmode)
27579 if not rlmode or rlmode>=0 then
27580 return "l2r"
27581 else
27582 return "r2l"
27583 end
27584 end
27585 local function flattendisk(head,disc)
27586 local pre,post,replace,pretail,posttail,replacetail=getdisc(disc,true)
27587 local prev,next=getboth(disc)
27588 local ishead=head==disc
27589 setdisc(disc)
27590 flushnode(disc)
27591 if pre then
27592 flushnodelist(pre)
27593 end
27594 if post then
27595 flushnodelist(post)
27596 end
27597 if ishead then
27598 if replace then
27599 if next then
27600 setlink(replacetail,next)
27601 end
27602 return replace,replace
27603 elseif next then
27604 return next,next
27605 else
27606 end
27607 else
27608 if replace then
27609 if next then
27610 setlink(replacetail,next)
27611 end
27612 setlink(prev,replace)
27613 return head,replace
27614 else
27615 setlink(prev,next)
27616 return head,next
27617 end
27618 end
27619 end
27620 local function appenddisc(disc,list)
27621 local pre,post,replace,pretail,posttail,replacetail=getdisc(disc,true)
27622 local posthead=list
27623 local replacehead=copynodelist(list)
27624 if post then
27625 setlink(posttail,posthead)
27626 else
27627 post=posthead
27628 end
27629 if replace then
27630 setlink(replacetail,replacehead)
27631 else
27632 replace=replacehead
27633 end
27634 setdisc(disc,pre,post,replace)
27635 end
27636 local function markstoligature(head,start,stop,char)
27637 if start==stop and getchar(start)==char then
27638 return head,start
27639 else
27640 local prev=getprev(start)
27641 local next=getnext(stop)
27642 setprev(start)
27643 setnext(stop)
27644 local base=copynocomponents(start,copyinjection)
27645 if head==start then
27646 head=base
27647 end
27648 resetinjection(base)
27649 setchar(base,char)
27650 setcomponents(base,start)
27651 setlink(prev,base,next)
27652 flushcomponents(start)
27653 return head,base
27654 end
27655 end
27656 local no_left_ligature_code=1
27657 local no_right_ligature_code=2
27658 local no_left_kern_code=4
27659 local no_right_kern_code=8
27660 local hasglyphoption=function(n,c)
27661 if c==no_left_ligature_code or c==no_right_ligature_code then
27662 return getattr(n,a_noligature)==1
27663 else
27664 return false
27665 end
27666 end
27667 local function toligature(head,start,stop,char,dataset,sequence,skiphash,discfound,hasmarks)
27668 if hasglyphoption(start,no_right_ligature_code) then
27669 return head,start
27670 end
27671 if start==stop and getchar(start)==char then
27672 resetinjection(start)
27673 setchar(start,char)
27674 return head,start
27675 end
27676 local prev=getprev(start)
27677 local next=getnext(stop)
27678 local comp=start
27679 setprev(start)
27680 setnext(stop)
27681 local base=copynocomponents(start,copyinjection)
27682 if start==head then
27683 head=base
27684 end
27685 resetinjection(base)
27686 setchar(base,char)
27687 setcomponents(base,comp)
27688 setlink(prev,base,next)
27689 if not discfound then
27690 local deletemarks=not skiphash or hasmarks
27691 local components=start
27692 local baseindex=0
27693 local componentindex=0
27694 local head=base
27695 local current=base
27696 while start do
27697 local char=getchar(start)
27698 if not marks[char] then
27699 baseindex=baseindex+componentindex
27700 componentindex=countcomponents(start,marks)
27701 elseif not deletemarks then
27702 setligaindex(start,baseindex+getligaindex(start,componentindex))
27703 if trace_marks then
27704 logwarning("%s: keep ligature mark %s, gets index %s",pref(dataset,sequence),gref(char),getligaindex(start))
27705 end
27706 local n=copynode(start)
27707 copyinjection(n,start)
27708 head,current=insertnodeafter(head,current,n)
27709 elseif trace_marks then
27710 logwarning("%s: delete ligature mark %s",pref(dataset,sequence),gref(char))
27711 end
27712 start=getnext(start)
27713 end
27714 local start=getnext(current)
27715 while start do
27716 local char=ischar(start)
27717 if char then
27718 if marks[char] then
27719 setligaindex(start,baseindex+getligaindex(start,componentindex))
27720 if trace_marks then
27721 logwarning("%s: set ligature mark %s, gets index %s",pref(dataset,sequence),gref(char),getligaindex(start))
27722 end
27723 start=getnext(start)
27724 else
27725 break
27726 end
27727 else
27728 break
27729 end
27730 end
27731 flushcomponents(components)
27732 else
27733 local discprev,discnext=getboth(discfound)
27734 if discprev and discnext then
27735 local pre,post,replace,pretail,posttail,replacetail=getdisc(discfound,true)
27736 if not replace then
27737 local prev=getprev(base)
27738 local copied=copyonlyglyphs(comp)
27739 if pre then
27740 setlink(discprev,pre)
27741 else
27742 setnext(discprev)
27743 end
27744 pre=comp
27745 if post then
27746 setlink(posttail,discnext)
27747 setprev(post)
27748 else
27749 post=discnext
27750 setprev(discnext)
27751 end
27752 setlink(prev,discfound,next)
27753 setboth(base)
27754 setcomponents(base,copied)
27755 replace=base
27756 if forcediscretionaries then
27757 setdisc(discfound,pre,post,replace,discretionarydisc_code)
27758 else
27759 setdisc(discfound,pre,post,replace)
27760 end
27761 base=prev
27762 end
27763 end
27764 end
27765 return head,base
27766 end
27767 local function multiple_glyphs(head,start,multiple,skiphash,what,stop)
27768 local nofmultiples=#multiple
27769 if nofmultiples>0 then
27770 local first=start
27771 resetinjection(start)
27772 setchar(start,multiple[1])
27773 if nofmultiples>1 then
27774 for i=2,nofmultiples do
27775 local n=copynode(start)
27776 resetinjection(n)
27777 setchar(n,multiple[i])
27778 insertnodeafter(head,start,n)
27779 start=n
27780 end
27781 end
27782 if what~=true and repeatablemultiples then
27783 local kind=type(what)
27784 local m,f,l
27785 if kind=="string" then
27786 local what,n=string.match(what,"^repeat(.-)[:=](%d+)$")
27787 if what=="middle" then
27788 m=tonumber(n)
27789 elseif what=="first" then
27790 f=tonumber(n)
27791 elseif what=="last" then
27792 l=tonumber(n)
27793 end
27794 elseif kind=="table" then
27795 m=what.middle
27796 f=what.first
27797 l=what.last
27798 end
27799 if f or m or l then
27800 if m and m>1 and nofmultiples==3 then
27801 local middle=getnext(first)
27802 for i=2,m do
27803 local n=copynode(middle)
27804 resetinjection(n)
27805 insertnodeafter(head,first,n)
27806 end
27807 end
27808 if f and f>1 then
27809 for i=2,f do
27810 local n=copynode(first)
27811 resetinjection(n)
27812 insertnodeafter(head,first,n)
27813 end
27814 end
27815 if l and l>1 then
27816 for i=2,l do
27817 local n=copynode(start)
27818 resetinjection(n)
27819 insertnodeafter(head,start,n)
27820 start=n
27821 end
27822 end
27823 end
27824 end
27825 return head,start,true
27826 else
27827 if trace_multiples then
27828 logprocess("no multiple for %s",gref(getchar(start)))
27829 end
27830 return head,start,false
27831 end
27832 end
27833 local function get_alternative_glyph(start,alternatives,value)
27834 local n=#alternatives
27835 if n==1 then
27836 return alternatives[1],trace_alternatives and "1 (only one present)"
27837 elseif value=="random" then
27838 local r=getrandom and getrandom("glyph",1,n) or random(1,n)
27839 return alternatives[r],trace_alternatives and formatters["value %a, taking %a"](value,r)
27840 elseif value=="first" then
27841 return alternatives[1],trace_alternatives and formatters["value %a, taking %a"](value,1)
27842 elseif value=="last" then
27843 return alternatives[n],trace_alternatives and formatters["value %a, taking %a"](value,n)
27844 end
27845 value=value==true and 1 or tonumber(value)
27846 if type(value)~="number" then
27847 return alternatives[1],trace_alternatives and formatters["invalid value %s, taking %a"](value,1)
27848 end
27849 if value>n then
27850 local defaultalt=otf.defaultnodealternate
27851 if defaultalt=="first" then
27852 return alternatives[n],trace_alternatives and formatters["invalid value %s, taking %a"](value,1)
27853 elseif defaultalt=="last" then
27854 return alternatives[1],trace_alternatives and formatters["invalid value %s, taking %a"](value,n)
27855 else
27856 return false,trace_alternatives and formatters["invalid value %a, %s"](value,"out of range")
27857 end
27858 elseif value==0 then
27859 return getchar(start),trace_alternatives and formatters["invalid value %a, %s"](value,"no change")
27860 elseif value<1 then
27861 return alternatives[1],trace_alternatives and formatters["invalid value %a, taking %a"](value,1)
27862 else
27863 return alternatives[value],trace_alternatives and formatters["value %a, taking %a"](value,value)
27864 end
27865 end
27866 function handlers.gsub_single(head,start,dataset,sequence,replacement)
27867 if trace_singles then
27868 logprocess("%s: replacing %s by single %s",pref(dataset,sequence),gref(getchar(start)),gref(replacement))
27869 end
27870 resetinjection(start)
27871 setchar(start,replacement)
27872 return head,start,true
27873 end
27874 function handlers.gsub_alternate(head,start,dataset,sequence,alternative)
27875 local kind=dataset[4]
27876 local what=dataset[1]
27877 local value=what==true and tfmdata.shared.features[kind] or what
27878 local choice,comment=get_alternative_glyph(start,alternative,value)
27879 if choice then
27880 if trace_alternatives then
27881 logprocess("%s: replacing %s by alternative %a to %s, %s",pref(dataset,sequence),gref(getchar(start)),gref(choice),comment)
27882 end
27883 resetinjection(start)
27884 setchar(start,choice)
27885 else
27886 if trace_alternatives then
27887 logwarning("%s: no variant %a for %s, %s",pref(dataset,sequence),value,gref(getchar(start)),comment)
27888 end
27889 end
27890 return head,start,true
27891 end
27892 function handlers.gsub_multiple(head,start,dataset,sequence,multiple,rlmode,skiphash)
27893 if trace_multiples then
27894 logprocess("%s: replacing %s by multiple %s",pref(dataset,sequence),gref(getchar(start)),gref(multiple))
27895 end
27896 return multiple_glyphs(head,start,multiple,skiphash,dataset[1])
27897 end
27898 function handlers.gsub_ligature(head,start,dataset,sequence,ligature,rlmode,skiphash)
27899 local current=getnext(start)
27900 if not current then
27901 return head,start,false,nil
27902 end
27903 local stop=nil
27904 local startchar=getchar(start)
27905 if skiphash and skiphash[startchar] then
27906 while current do
27907 local char=ischar(current,currentfont)
27908 if char then
27909 local lg=not tonumber(ligature) and ligature[char]
27910 if lg then
27911 stop=current
27912 ligature=lg
27913 current=getnext(current)
27914 else
27915 break
27916 end
27917 else
27918 break
27919 end
27920 end
27921 if stop then
27922 local ligature=tonumber(ligature) or ligature.ligature
27923 if ligature then
27924 if trace_ligatures then
27925 local stopchar=getchar(stop)
27926 head,start=markstoligature(head,start,stop,ligature)
27927 logprocess("%s: replacing %s upto %s by ligature %s case 1",pref(dataset,sequence),gref(startchar),gref(stopchar),gref(getchar(start)))
27928 else
27929 head,start=markstoligature(head,start,stop,ligature)
27930 end
27931 return head,start,true,false
27932 else
27933 end
27934 end
27935 else
27936 local discfound=false
27937 local hasmarks=marks[startchar]
27938 while current do
27939 local char,id=ischar(current,currentfont)
27940 if char then
27941 if skiphash and skiphash[char] then
27942 current=getnext(current)
27943 else
27944 local lg=not tonumber(ligature) and ligature[char]
27945 if lg then
27946 if marks[char] then
27947 hasmarks=true
27948 end
27949 stop=current
27950 ligature=lg
27951 current=getnext(current)
27952 else
27953 break
27954 end
27955 end
27956 elseif char==false then
27957 break
27958 elseif id==disc_code then
27959 discfound=current
27960 break
27961 else
27962 break
27963 end
27964 end
27965 if discfound then
27966 local pre,post,replace=getdisc(discfound)
27967 local match
27968 if replace then
27969 local char=ischar(replace,currentfont)
27970 if char and (not tonumber(ligature) and ligature[char]) then
27971 match=true
27972 end
27973 end
27974 if not match and pre then
27975 local char=ischar(pre,currentfont)
27976 if char and (not tonumber(ligature) and ligature[char]) then
27977 match=true
27978 end
27979 end
27980 if not match and not pre or not replace then
27981 local n=getnext(discfound)
27982 local char=ischar(n,currentfont)
27983 if char and (not tonumber(ligature) and ligature[char]) then
27984 match=true
27985 end
27986 end
27987 if match then
27988 local ishead=head==start
27989 local prev=getprev(start)
27990 if stop then
27991 setnext(stop)
27992 local copy=copynodelist(start)
27993 local tail=stop
27994 local liat=findnodetail(copy)
27995 if pre then
27996 setlink(liat,pre)
27997 end
27998 if replace then
27999 setlink(tail,replace)
28000 end
28001 pre=copy
28002 replace=start
28003 else
28004 setnext(start)
28005 local copy=copynode(start)
28006 if pre then
28007 setlink(copy,pre)
28008 end
28009 if replace then
28010 setlink(start,replace)
28011 end
28012 pre=copy
28013 replace=start
28014 end
28015 setdisc(discfound,pre,post,replace)
28016 if prev then
28017 setlink(prev,discfound)
28018 else
28019 setprev(discfound)
28020 head=discfound
28021 end
28022 start=discfound
28023 return head,start,true,true
28024 end
28025 end
28026 local ligature=tonumber(ligature) or ligature.ligature
28027 if ligature then
28028 if stop then
28029 if trace_ligatures then
28030 local stopchar=getchar(stop)
28031 head,start=toligature(head,start,stop,ligature,dataset,sequence,skiphash,false,hasmarks)
28032 logprocess("%s: replacing %s upto %s by ligature %s case 2",pref(dataset,sequence),gref(startchar),gref(stopchar),gref(ligature))
28033 else
28034 head,start=toligature(head,start,stop,ligature,dataset,sequence,skiphash,false,hasmarks)
28035 end
28036 else
28037 resetinjection(start)
28038 setchar(start,ligature)
28039 if trace_ligatures then
28040 logprocess("%s: replacing %s by (no real) ligature %s case 3",pref(dataset,sequence),gref(startchar),gref(ligature))
28041 end
28042 end
28043 return head,start,true,false
28044 else
28045 end
28046 end
28047 return head,start,false,false
28048 end
28049 function handlers.gpos_single(head,start,dataset,sequence,kerns,rlmode,skiphash,step,injection)
28050 if hasglyphoption(start,no_right_kern_code) then
28051 return head,start,false
28052 else
28053 local startchar=getchar(start)
28054 local format=step.format
28055 if format=="single" or type(kerns)=="table" then
28056 local dx,dy,w,h=setposition(0,start,factor,rlmode,kerns,injection)
28057 if trace_kerns then
28058 logprocess("%s: shifting single %s by %s xy (%p,%p) and wh (%p,%p)",pref(dataset,sequence),gref(startchar),format,dx,dy,w,h)
28059 end
28060 else
28061 local k=(format=="move" and setmove or setkern)(start,factor,rlmode,kerns,injection)
28062 if trace_kerns then
28063 logprocess("%s: shifting single %s by %s %p",pref(dataset,sequence),gref(startchar),format,k)
28064 end
28065 end
28066 return head,start,true
28067 end
28068 end
28069 function handlers.gpos_pair(head,start,dataset,sequence,kerns,rlmode,skiphash,step,injection)
28070 if hasglyphoption(start,no_right_kern_code) then
28071 return head,start,false
28072 else
28073 local snext=getnext(start)
28074 if not snext then
28075 return head,start,false
28076 else
28077 local prev=start
28078 while snext do
28079 local nextchar=ischar(snext,currentfont)
28080 if nextchar then
28081 if skiphash and skiphash[nextchar] then
28082 prev=snext
28083 snext=getnext(snext)
28084 else
28085 local krn=kerns[nextchar]
28086 if not krn then
28087 break
28088 end
28089 local format=step.format
28090 if format=="pair" then
28091 local a=krn[1]
28092 local b=krn[2]
28093 if a==true then
28094 elseif a then
28095 local x,y,w,h=setposition(1,start,factor,rlmode,a,injection)
28096 if trace_kerns then
28097 local startchar=getchar(start)
28098 logprocess("%s: shifting first of pair %s and %s by xy (%p,%p) and wh (%p,%p) as %s",pref(dataset,sequence),gref(startchar),gref(nextchar),x,y,w,h,injection or "injections")
28099 end
28100 end
28101 if b==true then
28102 start=snext
28103 elseif b then
28104 local x,y,w,h=setposition(2,snext,factor,rlmode,b,injection)
28105 if trace_kerns then
28106 local startchar=getchar(start)
28107 logprocess("%s: shifting second of pair %s and %s by xy (%p,%p) and wh (%p,%p) as %s",pref(dataset,sequence),gref(startchar),gref(nextchar),x,y,w,h,injection or "injections")
28108 end
28109 start=snext
28110 elseif forcepairadvance then
28111 start=snext
28112 end
28113 return head,start,true
28114 elseif krn~=0 then
28115 local k=(format=="move" and setmove or setkern)(snext,factor,rlmode,krn,injection)
28116 if trace_kerns then
28117 logprocess("%s: inserting %s %p between %s and %s as %s",pref(dataset,sequence),format,k,gref(getchar(prev)),gref(nextchar),injection or "injections")
28118 end
28119 return head,start,true
28120 else
28121 break
28122 end
28123 end
28124 else
28125 break
28126 end
28127 end
28128 return head,start,false
28129 end
28130 end
28131 end
28132 function handlers.gpos_mark2base(head,start,dataset,sequence,markanchors,rlmode,skiphash)
28133 local markchar=getchar(start)
28134 if marks[markchar] then
28135 local base=getprev(start)
28136 if base then
28137 local basechar=ischar(base,currentfont)
28138 if basechar then
28139 if marks[basechar] then
28140 while base do
28141 base=getprev(base)
28142 if base then
28143 basechar=ischar(base,currentfont)
28144 if basechar then
28145 if not marks[basechar] then
28146 break
28147 end
28148 else
28149 if trace_bugs then
28150 logwarning("%s: no base for mark %s, case %i",pref(dataset,sequence),gref(markchar),1)
28151 end
28152 return head,start,false
28153 end
28154 else
28155 if trace_bugs then
28156 logwarning("%s: no base for mark %s, case %i",pref(dataset,sequence),gref(markchar),2)
28157 end
28158 return head,start,false
28159 end
28160 end
28161 end
28162 local ba=markanchors[1][basechar]
28163 if ba then
28164 local ma=markanchors[2]
28165 local dx,dy,bound=setmark(start,base,factor,rlmode,ba,ma,characters[basechar],false,checkmarks)
28166 if trace_marks then
28167 logprocess("%s, bound %s, anchoring mark %s to basechar %s => (%p,%p)",
28168 pref(dataset,sequence),bound,gref(markchar),gref(basechar),dx,dy)
28169 end
28170 return head,start,true
28171 elseif trace_bugs then
28172 logwarning("%s: mark %s is not anchored to %s",pref(dataset,sequence),gref(markchar),gref(basechar))
28173 end
28174 elseif trace_bugs then
28175 logwarning("%s: nothing preceding, case %i",pref(dataset,sequence),1)
28176 end
28177 elseif trace_bugs then
28178 logwarning("%s: nothing preceding, case %i",pref(dataset,sequence),2)
28179 end
28180 elseif trace_bugs then
28181 logwarning("%s: mark %s is no mark",pref(dataset,sequence),gref(markchar))
28182 end
28183 return head,start,false
28184 end
28185 function handlers.gpos_mark2ligature(head,start,dataset,sequence,markanchors,rlmode,skiphash)
28186 local markchar=getchar(start)
28187 if marks[markchar] then
28188 local base=getprev(start)
28189 if base then
28190 local basechar=ischar(base,currentfont)
28191 if basechar then
28192 if marks[basechar] then
28193 while base do
28194 base=getprev(base)
28195 if base then
28196 basechar=ischar(base,currentfont)
28197 if basechar then
28198 if not marks[basechar] then
28199 break
28200 end
28201 else
28202 if trace_bugs then
28203 logwarning("%s: no base for mark %s, case %i",pref(dataset,sequence),gref(markchar),1)
28204 end
28205 return head,start,false
28206 end
28207 else
28208 if trace_bugs then
28209 logwarning("%s: no base for mark %s, case %i",pref(dataset,sequence),gref(markchar),2)
28210 end
28211 return head,start,false
28212 end
28213 end
28214 end
28215 local ba=markanchors[1][basechar]
28216 if ba then
28217 local ma=markanchors[2]
28218 if ma then
28219 local index=getligaindex(start)
28220 ba=ba[index]
28221 if ba then
28222 local dx,dy,bound=setmark(start,base,factor,rlmode,ba,ma,characters[basechar],false,checkmarks)
28223 if trace_marks then
28224 logprocess("%s, index %s, bound %s, anchoring mark %s to baselig %s at index %s => (%p,%p)",
28225 pref(dataset,sequence),index,bound,gref(markchar),gref(basechar),index,dx,dy)
28226 end
28227 return head,start,true
28228 else
28229 if trace_bugs then
28230 logwarning("%s: no matching anchors for mark %s and baselig %s with index %a",pref(dataset,sequence),gref(markchar),gref(basechar),index)
28231 end
28232 end
28233 end
28234 elseif trace_bugs then
28235 onetimemessage(currentfont,basechar,"no base anchors")
28236 end
28237 elseif trace_bugs then
28238 logwarning("%s: prev node is no char, case %i",pref(dataset,sequence),1)
28239 end
28240 elseif trace_bugs then
28241 logwarning("%s: prev node is no char, case %i",pref(dataset,sequence),2)
28242 end
28243 elseif trace_bugs then
28244 logwarning("%s: mark %s is no mark",pref(dataset,sequence),gref(markchar))
28245 end
28246 return head,start,false
28247 end
28248 function handlers.gpos_mark2mark(head,start,dataset,sequence,markanchors,rlmode,skiphash)
28249 local markchar=getchar(start)
28250 if marks[markchar] then
28251 local base=getprev(start)
28252 local slc=getligaindex(start)
28253 if slc then
28254 while base do
28255 local blc=getligaindex(base)
28256 if blc and blc~=slc then
28257 base=getprev(base)
28258 else
28259 break
28260 end
28261 end
28262 end
28263 if base then
28264 local basechar=ischar(base,currentfont)
28265 if basechar then
28266 local ba=markanchors[1][basechar]
28267 if ba then
28268 local ma=markanchors[2]
28269 local dx,dy,bound=setmark(start,base,factor,rlmode,ba,ma,characters[basechar],true,checkmarks)
28270 if trace_marks then
28271 logprocess("%s, bound %s, anchoring mark %s to basemark %s => (%p,%p)",
28272 pref(dataset,sequence),bound,gref(markchar),gref(basechar),dx,dy)
28273 end
28274 return head,start,true
28275 end
28276 end
28277 end
28278 elseif trace_bugs then
28279 logwarning("%s: mark %s is no mark",pref(dataset,sequence),gref(markchar))
28280 end
28281 return head,start,false
28282 end
28283 function handlers.gpos_cursive(head,start,dataset,sequence,exitanchors,rlmode,skiphash,step)
28284 local startchar=getchar(start)
28285 if marks[startchar] then
28286 if trace_cursive then
28287 logprocess("%s: ignoring cursive for mark %s",pref(dataset,sequence),gref(startchar))
28288 end
28289 else
28290 local nxt=getnext(start)
28291 while nxt do
28292 local nextchar=ischar(nxt,currentfont)
28293 if not nextchar then
28294 break
28295 elseif marks[nextchar] then
28296 nxt=getnext(nxt)
28297 else
28298 local exit=exitanchors[3]
28299 if exit then
28300 local entry=exitanchors[1][nextchar]
28301 if entry then
28302 entry=entry[2]
28303 if entry then
28304 local r2lflag=sequence.flags[4]
28305 local dx,dy,bound=setcursive(start,nxt,factor,rlmode,exit,entry,characters[startchar],characters[nextchar],r2lflag)
28306 if trace_cursive then
28307 logprocess("%s: moving %s to %s cursive (%p,%p) using bound %s in %s mode",pref(dataset,sequence),gref(startchar),gref(nextchar),dx,dy,bound,mref(rlmode))
28308 end
28309 return head,start,true
28310 end
28311 end
28312 end
28313 break
28314 end
28315 end
28316 end
28317 return head,start,false
28318 end
28319 local chainprocs={}
28320 local function logprocess(...)
28321 if trace_steps then
28322 registermessage(...)
28323 if trace_steps=="silent" then
28324 return
28325 end
28326 end
28327 report_subchain(...)
28328 end
28329 local logwarning=report_subchain
28330 local function logprocess(...)
28331 if trace_steps then
28332 registermessage(...)
28333 if trace_steps=="silent" then
28334 return
28335 end
28336 end
28337 report_chain(...)
28338 end
28339 local logwarning=report_chain
28340 local function reversesub(head,start,stop,dataset,sequence,replacements,rlmode,skiphash)
28341 local char=getchar(start)
28342 local replacement=replacements[char]
28343 if replacement then
28344 if trace_singles then
28345 logprocess("%s: single reverse replacement of %s by %s",cref(dataset,sequence),gref(char),gref(replacement))
28346 end
28347 resetinjection(start)
28348 setchar(start,replacement)
28349 return head,start,true
28350 else
28351 return head,start,false
28352 end
28353 end
28354 chainprocs.reversesub=reversesub
28355 local function reportzerosteps(dataset,sequence)
28356 logwarning("%s: no steps",cref(dataset,sequence))
28357 end
28358 local function reportmoresteps(dataset,sequence)
28359 logwarning("%s: more than 1 step",cref(dataset,sequence))
28360 end
28361 local function getmapping(dataset,sequence,currentlookup)
28362 local steps=currentlookup.steps
28363 local nofsteps=currentlookup.nofsteps
28364 if nofsteps==0 then
28365 reportzerosteps(dataset,sequence)
28366 currentlookup.mapping=false
28367 return false
28368 else
28369 if nofsteps>1 then
28370 reportmoresteps(dataset,sequence)
28371 end
28372 local mapping=steps[1].coverage
28373 currentlookup.mapping=mapping
28374 currentlookup.format=steps[1].format
28375 return mapping
28376 end
28377 end
28378 function chainprocs.gsub_remove(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash,chainindex)
28379 if trace_chains then
28380 logprocess("%s: removing character %s",cref(dataset,sequence,chainindex),gref(getchar(start)))
28381 end
28382 head,start=removenode(head,start,true)
28383 return head,getprev(start),true
28384 end
28385 function chainprocs.gsub_single(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash,chainindex)
28386 local mapping=currentlookup.mapping
28387 if mapping==nil then
28388 mapping=getmapping(dataset,sequence,currentlookup)
28389 end
28390 if mapping then
28391 local current=start
28392 while current do
28393 local currentchar=ischar(current)
28394 if currentchar then
28395 local replacement=mapping[currentchar]
28396 if not replacement or replacement=="" then
28397 if trace_bugs then
28398 logwarning("%s: no single for %s",cref(dataset,sequence,chainindex),gref(currentchar))
28399 end
28400 else
28401 if trace_singles then
28402 logprocess("%s: replacing single %s by %s",cref(dataset,sequence,chainindex),gref(currentchar),gref(replacement))
28403 end
28404 resetinjection(current)
28405 setchar(current,replacement)
28406 end
28407 return head,start,true
28408 elseif currentchar==false then
28409 break
28410 elseif current==stop then
28411 break
28412 else
28413 current=getnext(current)
28414 end
28415 end
28416 end
28417 return head,start,false
28418 end
28419 function chainprocs.gsub_alternate(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash,chainindex)
28420 local mapping=currentlookup.mapping
28421 if mapping==nil then
28422 mapping=getmapping(dataset,sequence,currentlookup)
28423 end
28424 if mapping then
28425 local kind=dataset[4]
28426 local what=dataset[1]
28427 local value=what==true and tfmdata.shared.features[kind] or what
28428 local current=start
28429 while current do
28430 local currentchar=ischar(current)
28431 if currentchar then
28432 local alternatives=mapping[currentchar]
28433 if alternatives then
28434 local choice,comment=get_alternative_glyph(current,alternatives,value)
28435 if choice then
28436 if trace_alternatives then
28437 logprocess("%s: replacing %s by alternative %a to %s, %s",cref(dataset,sequence),gref(currentchar),choice,gref(choice),comment)
28438 end
28439 resetinjection(start)
28440 setchar(start,choice)
28441 else
28442 if trace_alternatives then
28443 logwarning("%s: no variant %a for %s, %s",cref(dataset,sequence),value,gref(currentchar),comment)
28444 end
28445 end
28446 end
28447 return head,start,true
28448 elseif currentchar==false then
28449 break
28450 elseif current==stop then
28451 break
28452 else
28453 current=getnext(current)
28454 end
28455 end
28456 end
28457 return head,start,false
28458 end
28459 function chainprocs.gsub_multiple(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash,chainindex)
28460 local mapping=currentlookup.mapping
28461 if mapping==nil then
28462 mapping=getmapping(dataset,sequence,currentlookup)
28463 end
28464 if mapping then
28465 local startchar=getchar(start)
28466 local replacement=mapping[startchar]
28467 if not replacement or replacement=="" then
28468 if trace_bugs then
28469 logwarning("%s: no multiple for %s",cref(dataset,sequence),gref(startchar))
28470 end
28471 else
28472 if trace_multiples then
28473 logprocess("%s: replacing %s by multiple characters %s",cref(dataset,sequence),gref(startchar),gref(replacement))
28474 end
28475 return multiple_glyphs(head,start,replacement,skiphash,dataset[1],stop)
28476 end
28477 end
28478 return head,start,false
28479 end
28480 function chainprocs.gsub_ligature(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash,chainindex)
28481 local mapping=currentlookup.mapping
28482 if mapping==nil then
28483 mapping=getmapping(dataset,sequence,currentlookup)
28484 end
28485 if mapping then
28486 local startchar=getchar(start)
28487 local ligatures=mapping[startchar]
28488 if not ligatures then
28489 if trace_bugs then
28490 logwarning("%s: no ligatures starting with %s",cref(dataset,sequence,chainindex),gref(startchar))
28491 end
28492 else
28493 local hasmarks=marks[startchar]
28494 local current=getnext(start)
28495 local discfound=false
28496 local last=stop
28497 local nofreplacements=1
28498 while current do
28499 local id=getid(current)
28500 if id==disc_code then
28501 if not discfound then
28502 discfound=current
28503 end
28504 if current==stop then
28505 break
28506 else
28507 current=getnext(current)
28508 end
28509 else
28510 local schar=getchar(current)
28511 if skiphash and skiphash[schar] then
28512 current=getnext(current)
28513 else
28514 local lg=not tonumber(ligatures) and ligatures[schar]
28515 if lg then
28516 ligatures=lg
28517 last=current
28518 nofreplacements=nofreplacements+1
28519 if marks[char] then
28520 hasmarks=true
28521 end
28522 if current==stop then
28523 break
28524 else
28525 current=getnext(current)
28526 end
28527 else
28528 break
28529 end
28530 end
28531 end
28532 end
28533 local ligature=tonumber(ligatures) or ligatures.ligature
28534 if ligature then
28535 if chainindex then
28536 stop=last
28537 end
28538 if trace_ligatures then
28539 if start==stop then
28540 logprocess("%s: replacing character %s by ligature %s case 3",cref(dataset,sequence,chainindex),gref(startchar),gref(ligature))
28541 else
28542 logprocess("%s: replacing character %s upto %s by ligature %s case 4",cref(dataset,sequence,chainindex),gref(startchar),gref(getchar(stop)),gref(ligature))
28543 end
28544 end
28545 head,start=toligature(head,start,stop,ligature,dataset,sequence,skiphash,discfound,hasmarks)
28546 return head,start,true,nofreplacements,discfound
28547 elseif trace_bugs then
28548 if start==stop then
28549 logwarning("%s: replacing character %s by ligature fails",cref(dataset,sequence,chainindex),gref(startchar))
28550 else
28551 logwarning("%s: replacing character %s upto %s by ligature fails",cref(dataset,sequence,chainindex),gref(startchar),gref(getchar(stop)))
28552 end
28553 end
28554 end
28555 end
28556 return head,start,false,0,false
28557 end
28558 function chainprocs.gpos_single(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash,chainindex)
28559 if not hasglyphoption(start,no_right_kern_code) then
28560 local mapping=currentlookup.mapping
28561 if mapping==nil then
28562 mapping=getmapping(dataset,sequence,currentlookup)
28563 end
28564 if mapping then
28565 local startchar=getchar(start)
28566 local kerns=mapping[startchar]
28567 if kerns then
28568 local format=currentlookup.format
28569 if format=="single" then
28570 local dx,dy,w,h=setposition(0,start,factor,rlmode,kerns)
28571 if trace_kerns then
28572 logprocess("%s: shifting single %s by %s (%p,%p) and correction (%p,%p)",cref(dataset,sequence),gref(startchar),format,dx,dy,w,h)
28573 end
28574 else
28575 local k=(format=="move" and setmove or setkern)(start,factor,rlmode,kerns,injection)
28576 if trace_kerns then
28577 logprocess("%s: shifting single %s by %s %p",cref(dataset,sequence),gref(startchar),format,k)
28578 end
28579 end
28580 return head,start,true
28581 end
28582 end
28583 end
28584 return head,start,false
28585 end
28586 function chainprocs.gpos_pair(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash,chainindex)
28587 if not hasglyphoption(start,no_right_kern_code) then
28588 local mapping=currentlookup.mapping
28589 if mapping==nil then
28590 mapping=getmapping(dataset,sequence,currentlookup)
28591 end
28592 if mapping then
28593 local snext=getnext(start)
28594 if snext then
28595 local startchar=getchar(start)
28596 local kerns=mapping[startchar]
28597 if kerns then
28598 local prev=start
28599 while snext do
28600 local nextchar=ischar(snext,currentfont)
28601 if not nextchar then
28602 break
28603 end
28604 if skiphash and skiphash[nextchar] then
28605 prev=snext
28606 snext=getnext(snext)
28607 else
28608 local krn=kerns[nextchar]
28609 if not krn then
28610 break
28611 end
28612 local format=currentlookup.format
28613 if format=="pair" then
28614 local a=krn[1]
28615 local b=krn[2]
28616 if a==true then
28617 elseif a then
28618 local x,y,w,h=setposition(1,start,factor,rlmode,a,"injections")
28619 if trace_kerns then
28620 local startchar=getchar(start)
28621 logprocess("%s: shifting first of pair %s and %s by (%p,%p) and correction (%p,%p)",cref(dataset,sequence),gref(startchar),gref(nextchar),x,y,w,h)
28622 end
28623 end
28624 if b==true then
28625 start=snext
28626 elseif b then
28627 local x,y,w,h=setposition(2,snext,factor,rlmode,b,"injections")
28628 if trace_kerns then
28629 local startchar=getchar(start)
28630 logprocess("%s: shifting second of pair %s and %s by (%p,%p) and correction (%p,%p)",cref(dataset,sequence),gref(startchar),gref(nextchar),x,y,w,h)
28631 end
28632 start=snext
28633 elseif forcepairadvance then
28634 start=snext
28635 end
28636 return head,start,true
28637 elseif krn~=0 then
28638 local k=(format=="move" and setmove or setkern)(snext,factor,rlmode,krn)
28639 if trace_kerns then
28640 logprocess("%s: inserting %s %p between %s and %s",cref(dataset,sequence),format,k,gref(getchar(prev)),gref(nextchar))
28641 end
28642 return head,start,true
28643 else
28644 break
28645 end
28646 end
28647 end
28648 end
28649 end
28650 end
28651 end
28652 return head,start,false
28653 end
28654 function chainprocs.gpos_mark2base(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash,chainindex)
28655 local mapping=currentlookup.mapping
28656 if mapping==nil then
28657 mapping=getmapping(dataset,sequence,currentlookup)
28658 end
28659 if mapping then
28660 local markchar=getchar(start)
28661 if marks[markchar] then
28662 local markanchors=mapping[markchar]
28663 if markanchors then
28664 local base=getprev(start)
28665 if base then
28666 local basechar=ischar(base,currentfont)
28667 if basechar then
28668 if marks[basechar] then
28669 while base do
28670 base=getprev(base)
28671 if base then
28672 local basechar=ischar(base,currentfont)
28673 if basechar then
28674 if not marks[basechar] then
28675 break
28676 end
28677 else
28678 if trace_bugs then
28679 logwarning("%s: no base for mark %s, case %i",pref(dataset,sequence),gref(markchar),1)
28680 end
28681 return head,start,false
28682 end
28683 else
28684 if trace_bugs then
28685 logwarning("%s: no base for mark %s, case %i",pref(dataset,sequence),gref(markchar),2)
28686 end
28687 return head,start,false
28688 end
28689 end
28690 end
28691 local ba=markanchors[1][basechar]
28692 if ba then
28693 local ma=markanchors[2]
28694 if ma then
28695 local dx,dy,bound=setmark(start,base,factor,rlmode,ba,ma,characters[basechar],false,checkmarks)
28696 if trace_marks then
28697 logprocess("%s, bound %s, anchoring mark %s to basechar %s => (%p,%p)",
28698 cref(dataset,sequence),bound,gref(markchar),gref(basechar),dx,dy)
28699 end
28700 return head,start,true
28701 end
28702 end
28703 elseif trace_bugs then
28704 logwarning("%s: prev node is no char, case %i",cref(dataset,sequence),1)
28705 end
28706 elseif trace_bugs then
28707 logwarning("%s: prev node is no char, case %i",cref(dataset,sequence),2)
28708 end
28709 elseif trace_bugs then
28710 logwarning("%s: mark %s has no anchors",cref(dataset,sequence),gref(markchar))
28711 end
28712 elseif trace_bugs then
28713 logwarning("%s: mark %s is no mark",cref(dataset,sequence),gref(markchar))
28714 end
28715 end
28716 return head,start,false
28717 end
28718 function chainprocs.gpos_mark2ligature(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash,chainindex)
28719 local mapping=currentlookup.mapping
28720 if mapping==nil then
28721 mapping=getmapping(dataset,sequence,currentlookup)
28722 end
28723 if mapping then
28724 local markchar=getchar(start)
28725 if marks[markchar] then
28726 local markanchors=mapping[markchar]
28727 if markanchors then
28728 local base=getprev(start)
28729 if base then
28730 local basechar=ischar(base,currentfont)
28731 if basechar then
28732 if marks[basechar] then
28733 while base do
28734 base=getprev(base)
28735 if base then
28736 local basechar=ischar(base,currentfont)
28737 if basechar then
28738 if not marks[basechar] then
28739 break
28740 end
28741 else
28742 if trace_bugs then
28743 logwarning("%s: no base for mark %s, case %i",cref(dataset,sequence),markchar,1)
28744 end
28745 return head,start,false
28746 end
28747 else
28748 if trace_bugs then
28749 logwarning("%s: no base for mark %s, case %i",cref(dataset,sequence),markchar,2)
28750 end
28751 return head,start,false
28752 end
28753 end
28754 end
28755 local ba=markanchors[1][basechar]
28756 if ba then
28757 local ma=markanchors[2]
28758 if ma then
28759 local index=getligaindex(start)
28760 ba=ba[index]
28761 if ba then
28762 local dx,dy,bound=setmark(start,base,factor,rlmode,ba,ma,characters[basechar],false,checkmarks)
28763 if trace_marks then
28764 logprocess("%s, bound %s, anchoring mark %s to baselig %s at index %s => (%p,%p)",
28765 cref(dataset,sequence),a or bound,gref(markchar),gref(basechar),index,dx,dy)
28766 end
28767 return head,start,true
28768 end
28769 end
28770 end
28771 elseif trace_bugs then
28772 logwarning("%s, prev node is no char, case %i",cref(dataset,sequence),1)
28773 end
28774 elseif trace_bugs then
28775 logwarning("%s, prev node is no char, case %i",cref(dataset,sequence),2)
28776 end
28777 elseif trace_bugs then
28778 logwarning("%s, mark %s has no anchors",cref(dataset,sequence),gref(markchar))
28779 end
28780 elseif trace_bugs then
28781 logwarning("%s, mark %s is no mark",cref(dataset,sequence),gref(markchar))
28782 end
28783 end
28784 return head,start,false
28785 end
28786 function chainprocs.gpos_mark2mark(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash,chainindex)
28787 local mapping=currentlookup.mapping
28788 if mapping==nil then
28789 mapping=getmapping(dataset,sequence,currentlookup)
28790 end
28791 if mapping then
28792 local markchar=getchar(start)
28793 if marks[markchar] then
28794 local markanchors=mapping[markchar]
28795 if markanchors then
28796 local base=getprev(start)
28797 local slc=getligaindex(start)
28798 if slc then
28799 while base do
28800 local blc=getligaindex(base)
28801 if blc and blc~=slc then
28802 base=getprev(base)
28803 else
28804 break
28805 end
28806 end
28807 end
28808 if base then
28809 local basechar=ischar(base,currentfont)
28810 if basechar then
28811 local ba=markanchors[1][basechar]
28812 if ba then
28813 local ma=markanchors[2]
28814 if ma then
28815 local dx,dy,bound=setmark(start,base,factor,rlmode,ba,ma,characters[basechar],true,checkmarks)
28816 if trace_marks then
28817 logprocess("%s, bound %s, anchoring mark %s to basemark %s => (%p,%p)",
28818 cref(dataset,sequence),bound,gref(markchar),gref(basechar),dx,dy)
28819 end
28820 return head,start,true
28821 end
28822 end
28823 elseif trace_bugs then
28824 logwarning("%s: prev node is no mark, case %i",cref(dataset,sequence),1)
28825 end
28826 elseif trace_bugs then
28827 logwarning("%s: prev node is no mark, case %i",cref(dataset,sequence),2)
28828 end
28829 elseif trace_bugs then
28830 logwarning("%s: mark %s has no anchors",cref(dataset,sequence),gref(markchar))
28831 end
28832 elseif trace_bugs then
28833 logwarning("%s: mark %s is no mark",cref(dataset,sequence),gref(markchar))
28834 end
28835 end
28836 return head,start,false
28837 end
28838 function chainprocs.gpos_cursive(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash,chainindex)
28839 local mapping=currentlookup.mapping
28840 if mapping==nil then
28841 mapping=getmapping(dataset,sequence,currentlookup)
28842 end
28843 if mapping then
28844 local startchar=getchar(start)
28845 local exitanchors=mapping[startchar]
28846 if exitanchors then
28847 if marks[startchar] then
28848 if trace_cursive then
28849 logprocess("%s: ignoring cursive for mark %s",pref(dataset,sequence),gref(startchar))
28850 end
28851 else
28852 local nxt=getnext(start)
28853 while nxt do
28854 local nextchar=ischar(nxt,currentfont)
28855 if not nextchar then
28856 break
28857 elseif marks[nextchar] then
28858 nxt=getnext(nxt)
28859 else
28860 local exit=exitanchors[3]
28861 if exit then
28862 local entry=exitanchors[1][nextchar]
28863 if entry then
28864 entry=entry[2]
28865 if entry then
28866 local r2lflag=sequence.flags[4]
28867 local dx,dy,bound=setcursive(start,nxt,factor,rlmode,exit,entry,characters[startchar],characters[nextchar],r2lflag)
28868 if trace_cursive then
28869 logprocess("%s: moving %s to %s cursive (%p,%p) using bound %s in %s mode",pref(dataset,sequence),gref(startchar),gref(nextchar),dx,dy,bound,mref(rlmode))
28870 end
28871 return head,start,true
28872 end
28873 end
28874 elseif trace_bugs then
28875 onetimemessage(currentfont,startchar,"no entry anchors")
28876 end
28877 break
28878 end
28879 end
28880 end
28881 elseif trace_cursive and trace_details then
28882 logprocess("%s, cursive %s is already done",pref(dataset,sequence),gref(getchar(start)),alreadydone)
28883 end
28884 end
28885 return head,start,false
28886 end
28887 local function show_skip(dataset,sequence,char,ck,class)
28888 logwarning("%s: skipping char %s, class %a, rule %a, lookuptype %a",cref(dataset,sequence),gref(char),class,ck[1],ck[8] or ck[2])
28889 end
28890 local userkern=nuts.pool and nuts.pool.newkern
28891 do if not userkern then
28892 local thekern=nuts.new("kern",1)
28893 local setkern=nuts.setkern
28894 userkern=function(k)
28895 local n=copynode(thekern)
28896 setkern(n,k)
28897 return n
28898 end
28899 end end
28900 local function checked(head)
28901 local current=head
28902 while current do
28903 if getid(current)==glue_code then
28904 local kern=userkern(getwidth(current))
28905 if head==current then
28906 local next=getnext(current)
28907 if next then
28908 setlink(kern,next)
28909 end
28910 flushnode(current)
28911 head=kern
28912 current=next
28913 else
28914 local prev,next=getboth(current)
28915 setlink(prev,kern,next)
28916 flushnode(current)
28917 current=next
28918 end
28919 else
28920 current=getnext(current)
28921 end
28922 end
28923 return head
28924 end
28925 local function setdiscchecked(d,pre,post,replace)
28926 if pre then pre=checked(pre) end
28927 if post then post=checked(post) end
28928 if replace then replace=checked(replace) end
28929 setdisc(d,pre,post,replace)
28930 end
28931 local noflags={ false,false,false,false }
28932 local function chainrun(head,start,last,dataset,sequence,rlmode,skiphash,ck,where)
28933 local size=ck[5]-ck[4]+1
28934 local chainlookups=ck[6]
28935 local done=false
28936 if chainlookups then
28937 if size==1 then
28938 local chainlookup=chainlookups[1]
28939 if chainlookup then
28940 for j=1,#chainlookup do
28941 local chainstep=chainlookup[j]
28942 if chainstep then
28943 local chainkind=chainstep.type
28944 local chainproc=chainprocs[chainkind]
28945 if chainproc then
28946 local ok
28947 head,start,ok=chainproc(head,start,last,dataset,sequence,chainstep,rlmode,skiphash,1)
28948 if ok then
28949 done=true
28950 end
28951 else
28952 logprocess("%s: %s is not yet supported (1)",cref(dataset,sequence),chainkind)
28953 end
28954 else
28955 logprocess("%s: has an issue (1)",cref(dataset,sequence))
28956 end
28957 end
28958 else
28959 end
28960 else
28961 local i=1
28962 local laststart=start
28963 local nofchainlookups=#chainlookups
28964 while start do
28965 if skiphash then
28966 while start do
28967 local char=ischar(start,currentfont)
28968 if char then
28969 if skiphash and skiphash[char] then
28970 start=getnext(start)
28971 else
28972 break
28973 end
28974 else
28975 break
28976 end
28977 end
28978 end
28979 local chainlookup=chainlookups[i]
28980 if chainlookup then
28981 for j=1,#chainlookup do
28982 local chainstep=chainlookup[j]
28983 if chainstep then
28984 local chainkind=chainstep.type
28985 local chainproc=chainprocs[chainkind]
28986 if chainproc then
28987 local ok,n
28988 head,start,ok,n=chainproc(head,start,last,dataset,sequence,chainstep,rlmode,skiphash,i)
28989 if ok then
28990 done=true
28991 if n and n>1 and i+n>nofchainlookups then
28992 i=size
28993 break
28994 end
28995 end
28996 else
28997 logprocess("%s: %s is not yet supported (2)",cref(dataset,sequence),chainkind)
28998 end
28999 else
29000 logprocess("%s: has an issue (2)",cref(dataset,sequence))
29001 end
29002 end
29003 else
29004 end
29005 i=i+1
29006 if i>size or not start then
29007 break
29008 elseif start then
29009 laststart=start
29010 start=getnext(start)
29011 end
29012 end
29013 if not start then
29014 start=laststart
29015 end
29016 end
29017 else
29018 local replacements=ck[7]
29019 if replacements then
29020 head,start,done=reversesub(head,start,last,dataset,sequence,replacements,rlmode,skiphash)
29021 else
29022 done=true
29023 if trace_contexts then
29024 logprocess("%s: skipping match @ %i",cref(dataset,sequence),where)
29025 end
29026 end
29027 end
29028 return head,start,done
29029 end
29030 local function chaindisk(head,start,dataset,sequence,rlmode,skiphash,ck)
29031 if not start then
29032 return head,start,false
29033 end
29034 local startishead=start==head
29035 local seq=ck[3]
29036 local f=ck[4]
29037 local l=ck[5]
29038 local s=#seq
29039 local done=false
29040 local sweepnode=sweepnode
29041 local sweeptype=sweeptype
29042 local sweepoverflow=false
29043 local checkdisc=getprev(head)
29044 local keepdisc=not sweepnode
29045 local lookaheaddisc=nil
29046 local backtrackdisc=nil
29047 local current=start
29048 local last=start
29049 local prev=getprev(start)
29050 local hasglue=false
29051 local useddisc=nil
29052 local usedstart=start
29053 local i=f
29054 while i<=l do
29055 local id=getid(current)
29056 if id==glyph_code then
29057 i=i+1
29058 last=current
29059 current=getnext(current)
29060 elseif id==glue_code then
29061 i=i+1
29062 last=current
29063 current=getnext(current)
29064 hasglue=true
29065 elseif id==disc_code then
29066 if keepdisc then
29067 keepdisc=false
29068 lookaheaddisc=current
29069 local replace=getreplace(current)
29070 if not replace then
29071 sweepoverflow=true
29072 sweepnode=current
29073 current=getnext(current)
29074 else
29075 while replace and i<=l do
29076 if getid(replace)==glyph_code then
29077 i=i+1
29078 end
29079 replace=getnext(replace)
29080 end
29081 current=getnext(replace)
29082 end
29083 last=current
29084 else
29085 head,current=flattendisk(head,current)
29086 end
29087 else
29088 last=current
29089 current=getnext(current)
29090 end
29091 if current then
29092 elseif sweepoverflow then
29093 break
29094 elseif sweeptype=="post" or sweeptype=="replace" then
29095 current=getnext(sweepnode)
29096 if current then
29097 sweeptype=nil
29098 sweepoverflow=true
29099 else
29100 break
29101 end
29102 else
29103 break
29104 end
29105 end
29106 if sweepoverflow then
29107 local prev=current and getprev(current)
29108 if not current or prev~=sweepnode then
29109 local head=getnext(sweepnode)
29110 local tail=nil
29111 if prev then
29112 tail=prev
29113 setprev(current,sweepnode)
29114 else
29115 tail=findnodetail(head)
29116 end
29117 setnext(sweepnode,current)
29118 setprev(head)
29119 setnext(tail)
29120 appenddisc(sweepnode,head)
29121 end
29122 end
29123 if l<s then
29124 local i=l
29125 local t=sweeptype=="post" or sweeptype=="replace"
29126 while current and i<s do
29127 local id=getid(current)
29128 if id==glyph_code then
29129 i=i+1
29130 current=getnext(current)
29131 elseif id==glue_code then
29132 i=i+1
29133 current=getnext(current)
29134 hasglue=true
29135 elseif id==disc_code then
29136 if keepdisc then
29137 keepdisc=false
29138 if notmatchpre[current]~=notmatchreplace[current] then
29139 lookaheaddisc=current
29140 end
29141 local replace=getreplace(current)
29142 while replace and i<s do
29143 if getid(replace)==glyph_code then
29144 i=i+1
29145 end
29146 replace=getnext(replace)
29147 end
29148 current=getnext(current)
29149 elseif notmatchpre[current]~=notmatchreplace[current] then
29150 head,current=flattendisk(head,current)
29151 else
29152 current=getnext(current)
29153 end
29154 else
29155 current=getnext(current)
29156 end
29157 if not current and t then
29158 current=getnext(sweepnode)
29159 if current then
29160 sweeptype=nil
29161 end
29162 end
29163 end
29164 end
29165 if f>1 then
29166 local current=prev
29167 local i=f
29168 local t=sweeptype=="pre" or sweeptype=="replace"
29169 if not current and t and current==checkdisc then
29170 current=getprev(sweepnode)
29171 end
29172 while current and i>1 do
29173 local id=getid(current)
29174 if id==glyph_code then
29175 i=i-1
29176 elseif id==glue_code then
29177 i=i-1
29178 hasglue=true
29179 elseif id==disc_code then
29180 if keepdisc then
29181 keepdisc=false
29182 if notmatchpost[current]~=notmatchreplace[current] then
29183 backtrackdisc=current
29184 end
29185 local replace=getreplace(current)
29186 while replace and i>1 do
29187 if getid(replace)==glyph_code then
29188 i=i-1
29189 end
29190 replace=getnext(replace)
29191 end
29192 elseif notmatchpost[current]~=notmatchreplace[current] then
29193 head,current=flattendisk(head,current)
29194 end
29195 end
29196 current=getprev(current)
29197 if t and current==checkdisc then
29198 current=getprev(sweepnode)
29199 end
29200 end
29201 end
29202 local done=false
29203 if lookaheaddisc then
29204 local cf=start
29205 local cl=getprev(lookaheaddisc)
29206 local cprev=getprev(start)
29207 local insertedmarks=0
29208 while cprev do
29209 local char=ischar(cf,currentfont)
29210 if char and marks[char] then
29211 insertedmarks=insertedmarks+1
29212 cf=cprev
29213 startishead=cf==head
29214 cprev=getprev(cprev)
29215 else
29216 break
29217 end
29218 end
29219 setlink(cprev,lookaheaddisc)
29220 setprev(cf)
29221 setnext(cl)
29222 if startishead then
29223 head=lookaheaddisc
29224 end
29225 local pre,post,replace=getdisc(lookaheaddisc)
29226 local new=copynodelist(cf)
29227 local cnew=new
29228 if pre then
29229 setlink(findnodetail(cf),pre)
29230 end
29231 if replace then
29232 local tail=findnodetail(new)
29233 setlink(tail,replace)
29234 end
29235 for i=1,insertedmarks do
29236 cnew=getnext(cnew)
29237 end
29238 cl=start
29239 local clast=cnew
29240 for i=f,l do
29241 cl=getnext(cl)
29242 clast=getnext(clast)
29243 end
29244 if not notmatchpre[lookaheaddisc] then
29245 local ok=false
29246 cf,start,ok=chainrun(cf,start,cl,dataset,sequence,rlmode,skiphash,ck,1)
29247 if ok then
29248 done=true
29249 end
29250 end
29251 if not notmatchreplace[lookaheaddisc] then
29252 local ok=false
29253 new,cnew,ok=chainrun(new,cnew,clast,dataset,sequence,rlmode,skiphash,ck,2)
29254 if ok then
29255 done=true
29256 end
29257 end
29258 if hasglue then
29259 setdiscchecked(lookaheaddisc,cf,post,new)
29260 else
29261 setdisc(lookaheaddisc,cf,post,new)
29262 end
29263 start=getprev(lookaheaddisc)
29264 useddisc=lookaheaddisc
29265 sweephead[cf]=getnext(clast) or false
29266 sweephead[new]=getnext(cl) or false
29267 elseif backtrackdisc then
29268 local cf=getnext(backtrackdisc)
29269 local cl=start
29270 local cnext=getnext(start)
29271 local insertedmarks=0
29272 while cnext do
29273 local char=ischar(cnext,currentfont)
29274 if char and marks[char] then
29275 insertedmarks=insertedmarks+1
29276 cl=cnext
29277 cnext=getnext(cnext)
29278 else
29279 break
29280 end
29281 end
29282 setlink(backtrackdisc,cnext)
29283 setprev(cf)
29284 setnext(cl)
29285 local pre,post,replace,pretail,posttail,replacetail=getdisc(backtrackdisc,true)
29286 local new=copynodelist(cf)
29287 local cnew=findnodetail(new)
29288 for i=1,insertedmarks do
29289 cnew=getprev(cnew)
29290 end
29291 local clast=cnew
29292 for i=f,l do
29293 clast=getnext(clast)
29294 end
29295 if not notmatchpost[backtrackdisc] then
29296 local ok=false
29297 cf,start,ok=chainrun(cf,start,last,dataset,sequence,rlmode,skiphash,ck,3)
29298 if ok then
29299 done=true
29300 end
29301 end
29302 if not notmatchreplace[backtrackdisc] then
29303 local ok=false
29304 new,cnew,ok=chainrun(new,cnew,clast,dataset,sequence,rlmode,skiphash,ck,4)
29305 if ok then
29306 done=true
29307 end
29308 end
29309 if post then
29310 setlink(posttail,cf)
29311 else
29312 post=cf
29313 end
29314 if replace then
29315 setlink(replacetail,new)
29316 else
29317 replace=new
29318 end
29319 if hasglue then
29320 setdiscchecked(backtrackdisc,pre,post,replace)
29321 else
29322 setdisc(backtrackdisc,pre,post,replace)
29323 end
29324 start=getprev(backtrackdisc)
29325 useddisc=backtrackdisc
29326 sweephead[post]=getnext(clast) or false
29327 sweephead[replace]=getnext(last) or false
29328 else
29329 local ok=false
29330 head,start,ok=chainrun(head,start,last,dataset,sequence,rlmode,skiphash,ck,5)
29331 if ok then
29332 done=true
29333 end
29334 end
29335 if useddisc and start~=usedstart then
29336 start=getnext(start)
29337 end
29338 return head,start,done,useddisc
29339 end
29340 local chaintrac do
29341 local level=0
29342 local last={}
29343 chaintrac=function(head,start,dataset,sequence,rlmode,skiphash,ck,match,discseen,sweepnode)
29344 if dataset then
29345 level=level+1
29346 last[level]=start
29347 local rule=ck[1]
29348 local lookuptype=ck[8] or ck[2]
29349 local nofseq=#ck[3]
29350 local first=ck[4]
29351 local last=ck[5]
29352 local char=getchar(start)
29353 logwarning("+ %i : %s: rule %s %s at char %s for (%s,%s,%s) chars, lookuptype %a, %sdisc seen, %ssweeping",
29354 level,cref(dataset,sequence),rule,match and "matches" or "nomatch",
29355 gref(char),first-1,last-first+1,nofseq-last,lookuptype,
29356 discseen and "" or "no ",sweepnode and "" or "not ")
29357 else
29358 local what=start and "done" or "continue"
29359 local where=head==last[level] and "same" or "different"
29360 local char=getchar(head)
29361 if char then
29362 logwarning("- %i : %s at char %s, %s node",level,what,gref(char),where)
29363 else
29364 logwarning("- %i : %s, %s node",level,what,where)
29365 end
29366 level=level-1
29367 end
29368 end
29369 end
29370 local function handle_contextchain(head,start,dataset,sequence,contexts,rlmode,skiphash)
29371 if not contexts then
29372 return head,start,false
29373 end
29374 local sweepnode=sweepnode
29375 local sweeptype=sweeptype
29376 local postreplace
29377 local prereplace
29378 local checkdisc
29379 local discseen
29380 if sweeptype then
29381 if sweeptype=="replace" then
29382 postreplace=true
29383 prereplace=true
29384 else
29385 postreplace=sweeptype=="post"
29386 prereplace=sweeptype=="pre"
29387 end
29388 checkdisc=getprev(head)
29389 end
29390 local currentfont=currentfont
29391 local skipped
29392 local startprev,
29393 startnext=getboth(start)
29394 local done
29395 local nofcontexts=contexts.n
29396 local startchar=nofcontext==1 or ischar(start,currentfont)
29397 for k=1,nofcontexts do
29398 local ck=contexts[k]
29399 local seq=ck[3]
29400 local f=ck[4]
29401 local last=start
29402 if not startchar or not seq[f][startchar] then
29403 goto next
29404 end
29405 local s=seq.n
29406 if s==1 then
29407 else
29408 local l=ck[5]
29409 local current=start
29410 if l>f then
29411 local discfound
29412 local n=f+1
29413 last=startnext
29414 while n<=l do
29415 if postreplace and not last then
29416 last=getnext(sweepnode)
29417 sweeptype=nil
29418 end
29419 if last then
29420 local char,id=ischar(last,currentfont)
29421 if char then
29422 if seq[n][char] then
29423 if n<l then
29424 last=getnext(last)
29425 end
29426 n=n+1
29427 elseif skiphash and skiphash[char] then
29428 skipped=true
29429 if trace_skips then
29430 show_skip(dataset,sequence,char,ck,classes[char])
29431 end
29432 last=getnext(last)
29433 elseif discfound then
29434 notmatchreplace[discfound]=true
29435 if notmatchpre[discfound] then
29436 goto next
29437 else
29438 break
29439 end
29440 else
29441 goto next
29442 end
29443 elseif char==false then
29444 if discfound then
29445 notmatchreplace[discfound]=true
29446 if notmatchpre[discfound] then
29447 goto next
29448 else
29449 break
29450 end
29451 else
29452 goto next
29453 end
29454 elseif id==disc_code then
29455 discseen=true
29456 discfound=last
29457 notmatchpre[last]=nil
29458 notmatchpost[last]=true
29459 notmatchreplace[last]=nil
29460 local pre,post,replace=getdisc(last)
29461 if pre then
29462 local n=n
29463 while pre do
29464 if seq[n][getchar(pre)] then
29465 n=n+1
29466 if n>l then
29467 break
29468 end
29469 pre=getnext(pre)
29470 else
29471 notmatchpre[last]=true
29472 break
29473 end
29474 end
29475 if n<=l then
29476 notmatchpre[last]=true
29477 end
29478 else
29479 notmatchpre[last]=true
29480 end
29481 if replace then
29482 while replace do
29483 if seq[n][getchar(replace)] then
29484 n=n+1
29485 if n>l then
29486 break
29487 end
29488 replace=getnext(replace)
29489 else
29490 notmatchreplace[last]=true
29491 if notmatchpre[last] then
29492 goto next
29493 else
29494 break
29495 end
29496 end
29497 end
29498 if notmatchpre[last] then
29499 goto next
29500 end
29501 end
29502 last=getnext(last)
29503 else
29504 goto next
29505 end
29506 else
29507 goto next
29508 end
29509 end
29510 end
29511 if f>1 then
29512 local prev=startprev
29513 if prereplace and prev==checkdisc then
29514 prev=getprev(sweepnode)
29515 end
29516 if prev then
29517 local discfound
29518 local n=f-1
29519 while n>=1 do
29520 if prev then
29521 local char,id=ischar(prev,currentfont)
29522 if char then
29523 if seq[n][char] then
29524 if n>1 then
29525 prev=getprev(prev)
29526 end
29527 n=n-1
29528 elseif skiphash and skiphash[char] then
29529 skipped=true
29530 if trace_skips then
29531 show_skip(dataset,sequence,char,ck,classes[char])
29532 end
29533 prev=getprev(prev)
29534 elseif discfound then
29535 notmatchreplace[discfound]=true
29536 if notmatchpost[discfound] then
29537 goto next
29538 else
29539 break
29540 end
29541 else
29542 goto next
29543 end
29544 elseif char==false then
29545 if discfound then
29546 notmatchreplace[discfound]=true
29547 if notmatchpost[discfound] then
29548 goto next
29549 end
29550 else
29551 goto next
29552 end
29553 break
29554 elseif id==disc_code then
29555 discseen=true
29556 discfound=prev
29557 notmatchpre[prev]=true
29558 notmatchpost[prev]=nil
29559 notmatchreplace[prev]=nil
29560 local pre,post,replace,pretail,posttail,replacetail=getdisc(prev,true)
29561 if pre~=start and post~=start and replace~=start then
29562 if post then
29563 local n=n
29564 while posttail do
29565 if seq[n][getchar(posttail)] then
29566 n=n-1
29567 if posttail==post or n<1 then
29568 break
29569 else
29570 posttail=getprev(posttail)
29571 end
29572 else
29573 notmatchpost[prev]=true
29574 break
29575 end
29576 end
29577 if n>=1 then
29578 notmatchpost[prev]=true
29579 end
29580 else
29581 notmatchpost[prev]=true
29582 end
29583 if replace then
29584 while replacetail do
29585 if seq[n][getchar(replacetail)] then
29586 n=n-1
29587 if replacetail==replace or n<1 then
29588 break
29589 else
29590 replacetail=getprev(replacetail)
29591 end
29592 else
29593 notmatchreplace[prev]=true
29594 if notmatchpost[prev] then
29595 goto next
29596 else
29597 break
29598 end
29599 end
29600 end
29601 else
29602 end
29603 end
29604 prev=getprev(prev)
29605 elseif id==glue_code then
29606 local sn=seq[n]
29607 if (sn[32] and spaces[prev]) or sn[0xFFFC] then
29608 n=n-1
29609 prev=getprev(prev)
29610 else
29611 goto next
29612 end
29613 elseif seq[n][0xFFFC] then
29614 n=n-1
29615 prev=getprev(prev)
29616 else
29617 goto next
29618 end
29619 else
29620 goto next
29621 end
29622 end
29623 else
29624 goto next
29625 end
29626 end
29627 if s>l then
29628 local current=last and getnext(last)
29629 if not current and postreplace then
29630 current=getnext(sweepnode)
29631 end
29632 if current then
29633 local discfound
29634 local n=l+1
29635 while n<=s do
29636 if current then
29637 local char,id=ischar(current,currentfont)
29638 if char then
29639 if seq[n][char] then
29640 if n<s then
29641 current=getnext(current)
29642 end
29643 n=n+1
29644 elseif skiphash and skiphash[char] then
29645 skipped=true
29646 if trace_skips then
29647 show_skip(dataset,sequence,char,ck,classes[char])
29648 end
29649 current=getnext(current)
29650 elseif discfound then
29651 notmatchreplace[discfound]=true
29652 if notmatchpre[discfound] then
29653 goto next
29654 else
29655 break
29656 end
29657 else
29658 goto next
29659 end
29660 elseif char==false then
29661 if discfound then
29662 notmatchreplace[discfound]=true
29663 if notmatchpre[discfound] then
29664 goto next
29665 else
29666 break
29667 end
29668 else
29669 goto next
29670 end
29671 elseif id==disc_code then
29672 discseen=true
29673 discfound=current
29674 notmatchpre[current]=nil
29675 notmatchpost[current]=true
29676 notmatchreplace[current]=nil
29677 local pre,post,replace=getdisc(current)
29678 if pre then
29679 local n=n
29680 while pre do
29681 if seq[n][getchar(pre)] then
29682 n=n+1
29683 if n>s then
29684 break
29685 else
29686 pre=getnext(pre)
29687 end
29688 else
29689 notmatchpre[current]=true
29690 break
29691 end
29692 end
29693 if n<=s then
29694 notmatchpre[current]=true
29695 end
29696 else
29697 notmatchpre[current]=true
29698 end
29699 if replace then
29700 while replace do
29701 if seq[n][getchar(replace)] then
29702 n=n+1
29703 if n>s then
29704 break
29705 else
29706 replace=getnext(replace)
29707 end
29708 else
29709 notmatchreplace[current]=true
29710 if notmatchpre[current] then
29711 goto next
29712 else
29713 break
29714 end
29715 end
29716 end
29717 else
29718 end
29719 current=getnext(current)
29720 elseif id==glue_code then
29721 local sn=seq[n]
29722 if (sn[32] and spaces[current]) or sn[0xFFFC] then
29723 n=n+1
29724 current=getnext(current)
29725 else
29726 goto next
29727 end
29728 elseif seq[n][0xFFFC] then
29729 n=n+1
29730 current=getnext(current)
29731 else
29732 goto next
29733 end
29734 else
29735 goto next
29736 end
29737 end
29738 else
29739 goto next
29740 end
29741 end
29742 end
29743 if trace_contexts then
29744 chaintrac(head,start,dataset,sequence,rlmode,skipped and skiphash,ck,true,discseen,sweepnode)
29745 end
29746 if discseen or sweepnode then
29747 head,start,done=chaindisk(head,start,dataset,sequence,rlmode,skipped and skiphash,ck)
29748 else
29749 head,start,done=chainrun(head,start,last,dataset,sequence,rlmode,skipped and skiphash,ck,6)
29750 end
29751 if trace_contexts then
29752 chaintrac(start,done)
29753 end
29754 if done then
29755 break
29756 end
29757 ::next::
29758 end
29759 if discseen then
29760 notmatchpre={}
29761 notmatchpost={}
29762 notmatchreplace={}
29763 end
29764 return head,start,done
29765 end
29766 handlers.gsub_context=handle_contextchain
29767 handlers.gsub_contextchain=handle_contextchain
29768 handlers.gsub_reversecontextchain=handle_contextchain
29769 handlers.gpos_contextchain=handle_contextchain
29770 handlers.gpos_context=handle_contextchain
29771 local function chained_contextchain(head,start,stop,dataset,sequence,currentlookup,rlmode,skiphash)
29772 local steps=currentlookup.steps
29773 local nofsteps=currentlookup.nofsteps
29774 local char=getchar(start)
29775 if nofsteps==1 then
29776 local s=steps[1]
29777 local l=s.coverage[char]
29778 if l then
29779 return handle_contextchain(head,start,dataset,sequence,l,rlmode,skiphash)
29780 end
29781 else
29782 for i=1,nofsteps do
29783 local s=steps[i]
29784 local l=s.coverage[char]
29785 if l then
29786 local h,s,d=handle_contextchain(head,start,dataset,sequence,l,rlmode,skiphash)
29787 if d then
29788 return h,s,d
29789 end
29790 end
29791 end
29792 end
29793 return head,start,false
29794 end
29795 chainprocs.gsub_context=chained_contextchain
29796 chainprocs.gsub_contextchain=chained_contextchain
29797 chainprocs.gsub_reversecontextchain=chained_contextchain
29798 chainprocs.gpos_contextchain=chained_contextchain
29799 chainprocs.gpos_context=chained_contextchain
29800 local missing=setmetatableindex("table")
29801 local logwarning=report_process
29802 local resolved={}
29803 local function logprocess(...)
29804 if trace_steps then
29805 registermessage(...)
29806 if trace_steps=="silent" then
29807 return
29808 end
29809 end
29810 report_process(...)
29811 end
29812 local sequencelists=setmetatableindex(function(t,font)
29813 local sequences=fontdata[font].resources.sequences
29814 if not sequences or not next(sequences) then
29815 sequences=false
29816 end
29817 t[font]=sequences
29818 return sequences
29819 end)
29820 do
29821 local autofeatures=fonts.analyzers.features
29822 local featuretypes=otf.tables.featuretypes
29823 local defaultscript=otf.features.checkeddefaultscript
29824 local defaultlanguage=otf.features.checkeddefaultlanguage
29825 local wildcard="*"
29826 local default="dflt"
29827 local function initialize(sequence,script,language,enabled,autoscript,autolanguage)
29828 local features=sequence.features
29829 if features then
29830 local order=sequence.order
29831 if order then
29832 local featuretype=featuretypes[sequence.type or "unknown"]
29833 for i=1,#order do
29834 local kind=order[i]
29835 local valid=enabled[kind]
29836 if valid then
29837 local scripts=features[kind]
29838 local languages=scripts and (
29839 scripts[script] or
29840 scripts[wildcard] or
29841 (autoscript and defaultscript(featuretype,autoscript,scripts))
29842 )
29843 local enabled=languages and (
29844 languages[language] or
29845 languages[wildcard] or
29846 (autolanguage and defaultlanguage(featuretype,autolanguage,languages))
29847 )
29848 if enabled then
29849 return { valid,autofeatures[kind] or false,sequence,kind }
29850 end
29851 end
29852 end
29853 else
29854 end
29855 end
29856 return false
29857 end
29858 function otf.dataset(tfmdata,font)
29859 local shared=tfmdata.shared
29860 local properties=tfmdata.properties
29861 local language=properties.language or "dflt"
29862 local script=properties.script or "dflt"
29863 local enabled=shared.features
29864 local autoscript=enabled and enabled.autoscript
29865 local autolanguage=enabled and enabled.autolanguage
29866 local res=resolved[font]
29867 if not res then
29868 res={}
29869 resolved[font]=res
29870 end
29871 local rs=res[script]
29872 if not rs then
29873 rs={}
29874 res[script]=rs
29875 end
29876 local rl=rs[language]
29877 if not rl then
29878 rl={
29879 }
29880 rs[language]=rl
29881 local sequences=tfmdata.resources.sequences
29882 if sequences then
29883 for s=1,#sequences do
29884 local v=enabled and initialize(sequences[s],script,language,enabled,autoscript,autolanguage)
29885 if v then
29886 rl[#rl+1]=v
29887 end
29888 end
29889 end
29890 end
29891 return rl
29892 end
29893 end
29894 local function report_disc(what,n)
29895 report_run("%s: %s > %s",what,n,languages.serializediscretionary(n))
29896 end
29897 local function kernrun(disc,k_run,font,attr,...)
29898 if trace_kernruns then
29899 report_disc("kern",disc)
29900 end
29901 local prev,next=getboth(disc)
29902 local nextstart=next
29903 local done=false
29904 local pre,post,replace,pretail,posttail,replacetail=getdisc(disc,true)
29905 local prevmarks=prev
29906 while prevmarks do
29907 local char=ischar(prevmarks,font)
29908 if char and marks[char] then
29909 prevmarks=getprev(prevmarks)
29910 else
29911 break
29912 end
29913 end
29914 if prev and not ischar(prev,font) then
29915 prev=false
29916 end
29917 if next and not ischar(next,font) then
29918 next=false
29919 end
29920 if pre then
29921 if k_run(pre,"injections",nil,font,attr,...) then
29922 done=true
29923 end
29924 if prev then
29925 setlink(prev,pre)
29926 if k_run(prevmarks,"preinjections",pre,font,attr,...) then
29927 done=true
29928 end
29929 setprev(pre)
29930 setlink(prev,disc)
29931 end
29932 end
29933 if post then
29934 if k_run(post,"injections",nil,font,attr,...) then
29935 done=true
29936 end
29937 if next then
29938 setlink(posttail,next)
29939 if k_run(posttail,"postinjections",next,font,attr,...) then
29940 done=true
29941 end
29942 setnext(posttail)
29943 setlink(disc,next)
29944 end
29945 end
29946 if replace then
29947 if k_run(replace,"injections",nil,font,attr,...) then
29948 done=true
29949 end
29950 if prev then
29951 setlink(prev,replace)
29952 if k_run(prevmarks,"replaceinjections",replace,font,attr,...) then
29953 done=true
29954 end
29955 setprev(replace)
29956 setlink(prev,disc)
29957 end
29958 if next then
29959 setlink(replacetail,next)
29960 if k_run(replacetail,"replaceinjections",next,font,attr,...) then
29961 done=true
29962 end
29963 setnext(replacetail)
29964 setlink(disc,next)
29965 end
29966 elseif prev and next then
29967 setlink(prev,next)
29968 if k_run(prevmarks,"emptyinjections",next,font,attr,...) then
29969 done=true
29970 end
29971 setlink(prev,disc,next)
29972 end
29973 if done and trace_testruns then
29974 report_disc("done",disc)
29975 end
29976 return nextstart
29977 end
29978 local function comprun(disc,c_run,...)
29979 if trace_compruns then
29980 report_disc("comp",disc)
29981 end
29982 local pre,post,replace=getdisc(disc)
29983 local renewed=false
29984 if pre then
29985 sweepnode=disc
29986 sweeptype="pre"
29987 local new,done=c_run(pre,...)
29988 if done then
29989 pre=new
29990 renewed=true
29991 end
29992 end
29993 if post then
29994 sweepnode=disc
29995 sweeptype="post"
29996 local new,done=c_run(post,...)
29997 if done then
29998 post=new
29999 renewed=true
30000 end
30001 end
30002 if replace then
30003 sweepnode=disc
30004 sweeptype="replace"
30005 local new,done=c_run(replace,...)
30006 if done then
30007 replace=new
30008 renewed=true
30009 end
30010 end
30011 sweepnode=nil
30012 sweeptype=nil
30013 if renewed then
30014 if trace_testruns then
30015 report_disc("done",disc)
30016 end
30017 setdisc(disc,pre,post,replace)
30018 end
30019 return getnext(disc)
30020 end
30021 local test_flatten_start=2
30022 directives.register("otf.testrun.forceflatten",function(v)
30023 test_flatten_start=v and 1 or 2
30024 end)
30025 local function testrun(disc,t_run,c_run,...)
30026 if trace_testruns then
30027 report_disc("test",disc)
30028 end
30029 local prev,next=getboth(disc)
30030 if not next then
30031 return
30032 end
30033 local pre,post,replace,pretail,posttail,replacetail=getdisc(disc,true)
30034 local renewed=false
30035 if post or replace then
30036 if post then
30037 setlink(posttail,next)
30038 else
30039 post=next
30040 end
30041 if replace then
30042 setlink(replacetail,next)
30043 else
30044 replace=next
30045 end
30046 local d_post=t_run(post,next,...)
30047 local d_replace=t_run(replace,next,...)
30048 if d_post>0 or d_replace>0 then
30049 local d=d_replace>d_post and d_replace or d_post
30050 local head=getnext(disc)
30051 local tail=head
30052 for i=test_flatten_start,d do
30053 local nx=getnext(tail)
30054 local id=getid(nx)
30055 if id==disc_code then
30056 head,tail=flattendisk(head,nx)
30057 elseif id==glyph_code then
30058 tail=nx
30059 else
30060 break
30061 end
30062 end
30063 next=getnext(tail)
30064 setnext(tail)
30065 setprev(head)
30066 local new=copynodelist(head)
30067 if posttail then
30068 setlink(posttail,head)
30069 else
30070 post=head
30071 end
30072 if replacetail then
30073 setlink(replacetail,new)
30074 else
30075 replace=new
30076 end
30077 else
30078 if posttail then
30079 setnext(posttail)
30080 else
30081 post=nil
30082 end
30083 if replacetail then
30084 setnext(replacetail)
30085 else
30086 replace=nil
30087 end
30088 end
30089 setlink(disc,next)
30090 end
30091 if trace_testruns then
30092 report_disc("more",disc)
30093 end
30094 if pre then
30095 sweepnode=disc
30096 sweeptype="pre"
30097 local new,ok=c_run(pre,...)
30098 if ok then
30099 pre=new
30100 renewed=true
30101 end
30102 end
30103 if post then
30104 sweepnode=disc
30105 sweeptype="post"
30106 local new,ok=c_run(post,...)
30107 if ok then
30108 post=new
30109 renewed=true
30110 end
30111 end
30112 if replace then
30113 sweepnode=disc
30114 sweeptype="replace"
30115 local new,ok=c_run(replace,...)
30116 if ok then
30117 replace=new
30118 renewed=true
30119 end
30120 end
30121 sweepnode=nil
30122 sweeptype=nil
30123 if renewed then
30124 setdisc(disc,pre,post,replace)
30125 if trace_testruns then
30126 report_disc("done",disc)
30127 end
30128 end
30129 return getnext(disc)
30130 end
30131 local nesting=0
30132 local function c_run_single(head,font,attr,lookupcache,step,dataset,sequence,rlmode,skiphash,handler)
30133 local done=false
30134 local sweep=sweephead[head]
30135 local start
30136 if sweep then
30137 start=sweep
30138 sweephead[head]=false
30139 else
30140 start=head
30141 end
30142 while start do
30143 local char,id=ischar(start,font)
30144 if char then
30145 local a
30146 if attr then
30147 a=getglyphdata(start)
30148 end
30149 if not a or (a==attr) then
30150 local lookupmatch=lookupcache[char]
30151 if lookupmatch then
30152 local ok
30153 head,start,ok=handler(head,start,dataset,sequence,lookupmatch,rlmode,skiphash,step)
30154 if ok then
30155 done=true
30156 end
30157 end
30158 if start then
30159 start=getnext(start)
30160 end
30161 else
30162 start=getnext(start)
30163 end
30164 elseif char==false then
30165 return head,done
30166 elseif sweep then
30167 return head,done
30168 else
30169 start=getnext(start)
30170 end
30171 end
30172 return head,done
30173 end
30174 local function t_run_single(start,stop,font,attr,lookupcache)
30175 local lastd=nil
30176 while start~=stop do
30177 local char=ischar(start,font)
30178 if char then
30179 local a
30180 if attr then
30181 a=getglyphdata(start)
30182 end
30183 local startnext=getnext(start)
30184 if not a or (a==attr) then
30185 local lookupmatch=lookupcache[char]
30186 if lookupmatch then
30187 local s=startnext
30188 local ss=nil
30189 local sstop=s==stop
30190 if not s then
30191 s=ss
30192 ss=nil
30193 end
30194 while getid(s)==disc_code do
30195 ss=getnext(s)
30196 s=getreplace(s)
30197 if not s then
30198 s=ss
30199 ss=nil
30200 end
30201 end
30202 local l=nil
30203 local d=0
30204 while s do
30205 local char=ischar(s,font)
30206 if char then
30207 local lg=not tonumber(lookupmatch) and lookupmatch[char]
30208 if lg then
30209 if sstop then
30210 d=1
30211 elseif d>0 then
30212 d=d+1
30213 end
30214 l=lg
30215 s=getnext(s)
30216 sstop=s==stop
30217 if not s then
30218 s=ss
30219 ss=nil
30220 end
30221 while getid(s)==disc_code do
30222 ss=getnext(s)
30223 s=getreplace(s)
30224 if not s then
30225 s=ss
30226 ss=nil
30227 end
30228 end
30229 lookupmatch=lg
30230 else
30231 break
30232 end
30233 else
30234 break
30235 end
30236 end
30237 if l and (tonumber(l) or l.ligature) then
30238 lastd=d
30239 end
30240 else
30241 end
30242 else
30243 end
30244 if lastd then
30245 return lastd
30246 end
30247 start=startnext
30248 else
30249 break
30250 end
30251 end
30252 return 0
30253 end
30254 local function k_run_single(sub,injection,last,font,attr,lookupcache,step,dataset,sequence,rlmode,skiphash,handler)
30255 local a
30256 if attr then
30257 a=getglyphdata(sub)
30258 end
30259 if not a or (a==attr) then
30260 for n in nextnode,sub do
30261 if n==last then
30262 break
30263 end
30264 local char=ischar(n,font)
30265 if char then
30266 local lookupmatch=lookupcache[char]
30267 if lookupmatch then
30268 local h,d,ok=handler(sub,n,dataset,sequence,lookupmatch,rlmode,skiphash,step,injection)
30269 if ok then
30270 return true
30271 end
30272 end
30273 end
30274 end
30275 end
30276 end
30277 local function c_run_multiple(head,font,attr,steps,nofsteps,dataset,sequence,rlmode,skiphash,handler)
30278 local done=false
30279 local sweep=sweephead[head]
30280 local start
30281 if sweep then
30282 start=sweep
30283 sweephead[head]=false
30284 else
30285 start=head
30286 end
30287 while start do
30288 local char=ischar(start,font)
30289 if char then
30290 local a
30291 if attr then
30292 a=getglyphdata(start)
30293 end
30294 if not a or (a==attr) then
30295 for i=1,nofsteps do
30296 local step=steps[i]
30297 local lookupcache=step.coverage
30298 local lookupmatch=lookupcache[char]
30299 if lookupmatch then
30300 local ok
30301 head,start,ok=handler(head,start,dataset,sequence,lookupmatch,rlmode,skiphash,step)
30302 if ok then
30303 done=true
30304 break
30305 elseif not start then
30306 break
30307 end
30308 end
30309 end
30310 if start then
30311 start=getnext(start)
30312 end
30313 else
30314 start=getnext(start)
30315 end
30316 elseif char==false then
30317 return head,done
30318 elseif sweep then
30319 return head,done
30320 else
30321 start=getnext(start)
30322 end
30323 end
30324 return head,done
30325 end
30326 local function t_run_multiple(start,stop,font,attr,steps,nofsteps)
30327 local lastd=nil
30328 while start~=stop do
30329 local char=ischar(start,font)
30330 if char then
30331 local a
30332 if attr then
30333 a=getglyphdata(start)
30334 end
30335 local startnext=getnext(start)
30336 if not a or (a==attr) then
30337 for i=1,nofsteps do
30338 local step=steps[i]
30339 local lookupcache=step.coverage
30340 local lookupmatch=lookupcache[char]
30341 if lookupmatch then
30342 local s=startnext
30343 local ss=nil
30344 local sstop=s==stop
30345 if not s then
30346 s=ss
30347 ss=nil
30348 end
30349 while getid(s)==disc_code do
30350 ss=getnext(s)
30351 s=getreplace(s)
30352 if not s then
30353 s=ss
30354 ss=nil
30355 end
30356 end
30357 local l=nil
30358 local d=0
30359 while s do
30360 local char=ischar(s)
30361 if char then
30362 local lg=not tonumber(lookupmatch) and lookupmatch[char]
30363 if lg then
30364 if sstop then
30365 d=1
30366 elseif d>0 then
30367 d=d+1
30368 end
30369 l=lg
30370 s=getnext(s)
30371 sstop=s==stop
30372 if not s then
30373 s=ss
30374 ss=nil
30375 end
30376 while getid(s)==disc_code do
30377 ss=getnext(s)
30378 s=getreplace(s)
30379 if not s then
30380 s=ss
30381 ss=nil
30382 end
30383 end
30384 lookupmatch=lg
30385 else
30386 break
30387 end
30388 else
30389 break
30390 end
30391 end
30392 if l and (tonumber(l) or l.ligature) then
30393 lastd=d
30394 end
30395 end
30396 end
30397 else
30398 end
30399 if lastd then
30400 return lastd
30401 end
30402 start=startnext
30403 else
30404 break
30405 end
30406 end
30407 return 0
30408 end
30409 local function k_run_multiple(sub,injection,last,font,attr,steps,nofsteps,dataset,sequence,rlmode,skiphash,handler)
30410 local a
30411 if attr then
30412 a=getglyphdata(sub)
30413 end
30414 if not a or (a==attr) then
30415 for n in nextnode,sub do
30416 if n==last then
30417 break
30418 end
30419 local char=ischar(n)
30420 if char then
30421 for i=1,nofsteps do
30422 local step=steps[i]
30423 local lookupcache=step.coverage
30424 local lookupmatch=lookupcache[char]
30425 if lookupmatch then
30426 local h,d,ok=handler(sub,n,dataset,sequence,lookupmatch,rlmode,skiphash,step,injection)
30427 if ok then
30428 return true
30429 end
30430 end
30431 end
30432 end
30433 end
30434 end
30435 end
30436 local txtdirstate,pardirstate do
30437 local getdirection=nuts.getdirection
30438 txtdirstate=function(start,stack,top,rlparmode)
30439 local dir,pop=getdirection(start)
30440 if pop then
30441 if top==1 then
30442 return 0,rlparmode
30443 else
30444 top=top-1
30445 if stack[top]==righttoleft_code then
30446 return top,-1
30447 else
30448 return top,1
30449 end
30450 end
30451 elseif dir==lefttoright_code then
30452 top=top+1
30453 stack[top]=lefttoright_code
30454 return top,1
30455 elseif dir==righttoleft_code then
30456 top=top+1
30457 stack[top]=righttoleft_code
30458 return top,-1
30459 else
30460 return top,rlparmode
30461 end
30462 end
30463 pardirstate=function(start)
30464 local dir=getdirection(start)
30465 if dir==lefttoright_code then
30466 return 1,1
30467 elseif dir==righttoleft_code then
30468 return -1,-1
30469 else
30470 return 0,0
30471 end
30472 end
30473 end
30474 otf.helpers=otf.helpers or {}
30475 otf.helpers.txtdirstate=txtdirstate
30476 otf.helpers.pardirstate=pardirstate
30477 do
30478 local fastdisc=true
30479 local testdics=false
30480 directives.register("otf.fastdisc",function(v) fastdisc=v end)
30481 local otfdataset=nil
30482 local getfastdisc={ __index=function(t,k)
30483 local v=usesfont(k,currentfont)
30484 t[k]=v
30485 return v
30486 end }
30487 local getfastspace={ __index=function(t,k)
30488 local v=isspace(k,threshold) or false
30489 t[k]=v
30490 return v
30491 end }
30492 function otf.featuresprocessor(head,font,attr,direction,n)
30493 local sequences=sequencelists[font]
30494 nesting=nesting+1
30495 if nesting==1 then
30496 currentfont=font
30497 tfmdata=fontdata[font]
30498 descriptions=tfmdata.descriptions
30499 characters=tfmdata.characters
30500 local resources=tfmdata.resources
30501 marks=resources.marks
30502 classes=resources.classes
30503 threshold,
30504 factor=getthreshold(font)
30505 checkmarks=tfmdata.properties.checkmarks
30506 if not otfdataset then
30507 otfdataset=otf.dataset
30508 end
30509 discs=fastdisc and n and n>1 and setmetatable({},getfastdisc)
30510 spaces=setmetatable({},getfastspace)
30511 elseif currentfont~=font then
30512 report_warning("nested call with a different font, level %s, quitting",nesting)
30513 nesting=nesting-1
30514 return head,false
30515 end
30516 if trace_steps then
30517 checkstep(head)
30518 end
30519 local initialrl=0
30520 if getid(head)==par_code and startofpar(head) then
30521 initialrl=pardirstate(head)
30522 elseif direction==righttoleft_code then
30523 initialrl=-1
30524 end
30525 local datasets=otfdataset(tfmdata,font,attr)
30526 local dirstack={ nil }
30527 sweephead={}
30528 for s=1,#datasets do
30529 local dataset=datasets[s]
30530 local attribute=dataset[2]
30531 local sequence=dataset[3]
30532 local rlparmode=initialrl
30533 local topstack=0
30534 local typ=sequence.type
30535 local gpossing=typ=="gpos_single" or typ=="gpos_pair"
30536 local forcetestrun=typ=="gsub_ligature"
30537 local handler=handlers[typ]
30538 local steps=sequence.steps
30539 local nofsteps=sequence.nofsteps
30540 local skiphash=sequence.skiphash
30541 if not steps then
30542 local h,ok=handler(head,dataset,sequence,initialrl,font,attr)
30543 if h and h~=head then
30544 head=h
30545 end
30546 elseif typ=="gsub_reversecontextchain" then
30547 local start=findnodetail(head)
30548 local rlmode=0
30549 local merged=steps.merged
30550 while start do
30551 local char=ischar(start,font)
30552 if char then
30553 local m=merged[char]
30554 if m then
30555 local a
30556 if attr then
30557 a=getglyphdata(start)
30558 end
30559 if not a or (a==attr) then
30560 for i=m[1],m[2] do
30561 local step=steps[i]
30562 local lookupcache=step.coverage
30563 local lookupmatch=lookupcache[char]
30564 if lookupmatch then
30565 local ok
30566 head,start,ok=handler(head,start,dataset,sequence,lookupmatch,rlmode,skiphash,step)
30567 if ok then
30568 break
30569 end
30570 end
30571 end
30572 if start then
30573 start=getprev(start)
30574 end
30575 else
30576 start=getprev(start)
30577 end
30578 else
30579 start=getprev(start)
30580 end
30581 else
30582 start=getprev(start)
30583 end
30584 end
30585 else
30586 local start=head
30587 local rlmode=initialrl
30588 if nofsteps==1 then
30589 local step=steps[1]
30590 local lookupcache=step.coverage
30591 while start do
30592 local char,id=ischar(start,font)
30593 if char then
30594 local lookupmatch=lookupcache[char]
30595 if lookupmatch then
30596 local a
30597 if attr then
30598 if getglyphdata(start)==attr and (not attribute or getstate(start,attribute)) then
30599 a=true
30600 end
30601 elseif not attribute or getstate(start,attribute) then
30602 a=true
30603 end
30604 if a then
30605 local ok,df
30606 head,start,ok,df=handler(head,start,dataset,sequence,lookupmatch,rlmode,skiphash,step)
30607 if df then
30608 elseif start then
30609 start=getnext(start)
30610 end
30611 else
30612 start=getnext(start)
30613 end
30614 else
30615 start=getnext(start)
30616 end
30617 elseif char==false or id==glue_code then
30618 start=getnext(start)
30619 elseif id==disc_code then
30620 if not discs or discs[start]==true then
30621 if gpossing then
30622 start=kernrun(start,k_run_single,font,attr,lookupcache,step,dataset,sequence,rlmode,skiphash,handler)
30623 elseif forcetestrun then
30624 start=testrun(start,t_run_single,c_run_single,font,attr,lookupcache,step,dataset,sequence,rlmode,skiphash,handler)
30625 else
30626 start=comprun(start,c_run_single,font,attr,lookupcache,step,dataset,sequence,rlmode,skiphash,handler)
30627 end
30628 else
30629 start=getnext(start)
30630 end
30631 elseif id==math_code then
30632 start=getnext(endofmath(start))
30633 elseif id==dir_code then
30634 topstack,rlmode=txtdirstate(start,dirstack,topstack,rlparmode)
30635 start=getnext(start)
30636 else
30637 start=getnext(start)
30638 end
30639 end
30640 else
30641 local merged=steps.merged
30642 while start do
30643 local char,id=ischar(start,font)
30644 if char then
30645 local m=merged[char]
30646 if m then
30647 local a
30648 if attr then
30649 if getglyphdata(start)==attr and (not attribute or getstate(start,attribute)) then
30650 a=true
30651 end
30652 elseif not attribute or getstate(start,attribute) then
30653 a=true
30654 end
30655 if a then
30656 local ok,df
30657 for i=m[1],m[2] do
30658 local step=steps[i]
30659 local lookupcache=step.coverage
30660 local lookupmatch=lookupcache[char]
30661 if lookupmatch then
30662 head,start,ok,df=handler(head,start,dataset,sequence,lookupmatch,rlmode,skiphash,step)
30663 if df then
30664 break
30665 elseif ok then
30666 break
30667 elseif not start then
30668 break
30669 end
30670 end
30671 end
30672 if df then
30673 elseif start then
30674 start=getnext(start)
30675 end
30676 else
30677 start=getnext(start)
30678 end
30679 else
30680 start=getnext(start)
30681 end
30682 elseif char==false or id==glue_code then
30683 start=getnext(start)
30684 elseif id==disc_code then
30685 if not discs or discs[start]==true then
30686 if gpossing then
30687 start=kernrun(start,k_run_multiple,font,attr,steps,nofsteps,dataset,sequence,rlmode,skiphash,handler)
30688 elseif forcetestrun then
30689 start=testrun(start,t_run_multiple,c_run_multiple,font,attr,steps,nofsteps,dataset,sequence,rlmode,skiphash,handler)
30690 else
30691 start=comprun(start,c_run_multiple,font,attr,steps,nofsteps,dataset,sequence,rlmode,skiphash,handler)
30692 end
30693 else
30694 start=getnext(start)
30695 end
30696 elseif id==math_code then
30697 start=getnext(endofmath(start))
30698 elseif id==dir_code then
30699 topstack,rlmode=txtdirstate(start,dirstack,topstack,rlparmode)
30700 start=getnext(start)
30701 else
30702 start=getnext(start)
30703 end
30704 end
30705 end
30706 end
30707 if trace_steps then
30708 registerstep(head)
30709 end
30710 end
30711 nesting=nesting-1
30712 return head
30713 end
30714 function otf.datasetpositionprocessor(head,font,direction,dataset)
30715 currentfont=font
30716 tfmdata=fontdata[font]
30717 descriptions=tfmdata.descriptions
30718 characters=tfmdata.characters
30719 local resources=tfmdata.resources
30720 marks=resources.marks
30721 classes=resources.classes
30722 threshold,
30723 factor=getthreshold(font)
30724 checkmarks=tfmdata.properties.checkmarks
30725 if type(dataset)=="number" then
30726 dataset=otfdataset(tfmdata,font,0)[dataset]
30727 end
30728 local sequence=dataset[3]
30729 local typ=sequence.type
30730 local handler=handlers[typ]
30731 local steps=sequence.steps
30732 local nofsteps=sequence.nofsteps
30733 local done=false
30734 local dirstack={ nil }
30735 local start=head
30736 local initialrl=(direction==righttoleft_code) and -1 or 0
30737 local rlmode=initialrl
30738 local rlparmode=initialrl
30739 local topstack=0
30740 local merged=steps.merged
30741 local position=0
30742 while start do
30743 local char,id=ischar(start,font)
30744 if char then
30745 position=position+1
30746 local m=merged[char]
30747 if m then
30748 for i=m[1],m[2] do
30749 local step=steps[i]
30750 local lookupcache=step.coverage
30751 local lookupmatch=lookupcache[char]
30752 if lookupmatch then
30753 local ok
30754 head,start,ok=handler(head,start,dataset,sequence,lookupmatch,rlmode,skiphash,step)
30755 if ok then
30756 break
30757 elseif not start then
30758 break
30759 end
30760 end
30761 end
30762 if start then
30763 start=getnext(start)
30764 end
30765 else
30766 start=getnext(start)
30767 end
30768 elseif char==false or id==glue_code then
30769 start=getnext(start)
30770 elseif id==math_code then
30771 start=getnext(endofmath(start))
30772 elseif id==dir_code then
30773 topstack,rlmode=txtdirstate(start,dirstack,topstack,rlparmode)
30774 start=getnext(start)
30775 else
30776 start=getnext(start)
30777 end
30778 end
30779 return head
30780 end
30781 end
30782 do
30783 local plugins={}
30784 otf.plugins=plugins
30785 local report=logs.reporter("fonts")
30786 local warned=false
30787 local okay={ text=true }
30788 function otf.registerplugin(name,f)
30789 if type(name)=="string" and type(f)=="function" then
30790 plugins[name]={ name,f }
30791 if okay[name] then
30792 else
30793 report("plugin %a has been loaded, please be aware of possible side effects",name)
30794 if not warned then
30795 if logs.pushtarget then
30796 logs.pushtarget("log")
30797 end
30798 report("Plugins are not officially supported unless stated otherwise. This is because")
30799 report("they bypass the regular font handling and therefore some features in ConTeXt")
30800 report("(especially those related to fonts) might not work as expected or might not work")
30801 report("at all. Some plugins are for testing and development only and might change")
30802 report("whenever we feel the need for it.")
30803 report()
30804 if logs.poptarget then
30805 logs.poptarget()
30806 end
30807 warned=true
30808 end
30809 end
30810 end
30811 end
30812 function otf.plugininitializer(tfmdata,value)
30813 if type(value)=="string" then
30814 tfmdata.shared.plugin=plugins[value]
30815 end
30816 end
30817 function otf.pluginprocessor(head,font,dynamic,direction)
30818 local s=fontdata[font].shared
30819 local p=s and s.plugin
30820 if p then
30821 if trace_plugins then
30822 report_process("applying plugin %a",p[1])
30823 end
30824 return p[2](head,font,dynamic,direction)
30825 else
30826 return head,false
30827 end
30828 end
30829 end
30830 function otf.featuresinitializer(tfmdata,value)
30831 end
30832 registerotffeature {
30833 name="features",
30834 description="features",
30835 default=true,
30836 initializers={
30837 position=1,
30838 node=otf.featuresinitializer,
30839 plug=otf.plugininitializer,
30840 },
30841 processors={
30842 node=otf.featuresprocessor,
30843 plug=otf.pluginprocessor,
30844 }
30845 }
30846 local function markinitializer(tfmdata,value)
30847 local properties=tfmdata.properties
30848 properties.checkmarks=value
30849 end
30850 registerotffeature {
30851 name="checkmarks",
30852 description="check mark widths",
30853 default=true,
30854 initializers={
30855 node=markinitializer,
30856 },
30857 }
30858 otf.handlers=handlers
30859 if context then
30860
30861 --removed
30862
30863 else
30864 end
30865 local setspacekerns=nodes.injections.setspacekerns if not setspacekerns then os.exit() end
30866 local tag="kern"
30867 function handlers.trigger_space_kerns(head,dataset,sequence,initialrl,font,attr)
30868 local shared=fontdata[font].shared
30869 local features=shared and shared.features
30870 local enabled=features and features.spacekern and features[tag]
30871 if enabled then
30872 setspacekerns(font,sequence)
30873 end
30874 return head,enabled
30875 end
30876 local function hasspacekerns(data)
30877 local resources=data.resources
30878 local sequences=resources.sequences
30879 local validgpos=resources.features.gpos
30880 if validgpos and sequences then
30881 for i=1,#sequences do
30882 local sequence=sequences[i]
30883 local steps=sequence.steps
30884 if steps and sequence.features[tag] then
30885 local kind=sequence.type
30886 if kind=="gpos_pair" or kind=="gpos_single" then
30887 for i=1,#steps do
30888 local step=steps[i]
30889 local coverage=step.coverage
30890 local rules=step.rules
30891 if rules then
30892 elseif not coverage then
30893 elseif kind=="gpos_single" then
30894 elseif kind=="gpos_pair" then
30895 local format=step.format
30896 if format=="move" or format=="kern" then
30897 local kerns=coverage[32]
30898 if kerns then
30899 return true
30900 end
30901 for k,v in next,coverage do
30902 if v[32] then
30903 return true
30904 end
30905 end
30906 elseif format=="pair" then
30907 local kerns=coverage[32]
30908 if kerns then
30909 for k,v in next,kerns do
30910 local one=v[1]
30911 if one and one~=true then
30912 return true
30913 end
30914 end
30915 end
30916 for k,v in next,coverage do
30917 local kern=v[32]
30918 if kern then
30919 local one=kern[1]
30920 if one and one~=true then
30921 return true
30922 end
30923 end
30924 end
30925 end
30926 end
30927 end
30928 end
30929 end
30930 end
30931 end
30932 return false
30933 end
30934 otf.readers.registerextender {
30935 name="spacekerns",
30936 action=function(data)
30937 data.properties.hasspacekerns=hasspacekerns(data)
30938 end
30939 }
30940 local function spaceinitializer(tfmdata,value)
30941 local resources=tfmdata.resources
30942 local spacekerns=resources and resources.spacekerns
30943 if value and spacekerns==nil then
30944 local rawdata=tfmdata.shared and tfmdata.shared.rawdata
30945 local properties=rawdata.properties
30946 if properties and properties.hasspacekerns then
30947 local sequences=resources.sequences
30948 local validgpos=resources.features.gpos
30949 if validgpos and sequences then
30950 local left={}
30951 local right={}
30952 local last=0
30953 local feat=nil
30954 for i=1,#sequences do
30955 local sequence=sequences[i]
30956 local steps=sequence.steps
30957 if steps then
30958 local kern=sequence.features[tag]
30959 if kern then
30960 local kind=sequence.type
30961 if kind=="gpos_pair" or kind=="gpos_single" then
30962 if feat then
30963 for script,languages in next,kern do
30964 local f=feat[script]
30965 if f then
30966 for l in next,languages do
30967 f[l]=true
30968 end
30969 else
30970 feat[script]=languages
30971 end
30972 end
30973 else
30974 feat=kern
30975 end
30976 for i=1,#steps do
30977 local step=steps[i]
30978 local coverage=step.coverage
30979 local rules=step.rules
30980 if rules then
30981 elseif not coverage then
30982 elseif kind=="gpos_single" then
30983 elseif kind=="gpos_pair" then
30984 local format=step.format
30985 if format=="move" or format=="kern" then
30986 local kerns=coverage[32]
30987 if kerns then
30988 for k,v in next,kerns do
30989 right[k]=v
30990 end
30991 end
30992 for k,v in next,coverage do
30993 local kern=v[32]
30994 if kern then
30995 left[k]=kern
30996 end
30997 end
30998 elseif format=="pair" then
30999 local kerns=coverage[32]
31000 if kerns then
31001 for k,v in next,kerns do
31002 local one=v[1]
31003 if one and one~=true then
31004 right[k]=one[3]
31005 end
31006 end
31007 end
31008 for k,v in next,coverage do
31009 local kern=v[32]
31010 if kern then
31011 local one=kern[1]
31012 if one and one~=true then
31013 left[k]=one[3]
31014 end
31015 end
31016 end
31017 end
31018 end
31019 end
31020 last=i
31021 end
31022 else
31023 end
31024 end
31025 end
31026 left=next(left) and left or false
31027 right=next(right) and right or false
31028 if left or right then
31029 spacekerns={
31030 left=left,
31031 right=right,
31032 }
31033 if last>0 then
31034 local triggersequence={
31035 features={ [tag]=feat or { dflt={ dflt=true,} } },
31036 flags=noflags,
31037 name="trigger_space_kerns",
31038 order={ tag },
31039 type="trigger_space_kerns",
31040 left=left,
31041 right=right,
31042 }
31043 insert(sequences,last,triggersequence)
31044 end
31045 end
31046 end
31047 end
31048 resources.spacekerns=spacekerns
31049 end
31050 return spacekerns
31051 end
31052 registerotffeature {
31053 name="spacekern",
31054 description="space kern injection",
31055 default=true,
31056 initializers={
31057 node=spaceinitializer,
31058 },
31059 }
31060
31061 end -- closure
31062
31063 do -- begin closure to overcome local limits and interference
31064
31065 if not modules then modules={} end modules ['font-otc']={
31066 version=1.001,
31067 comment="companion to font-ini.mkiv",
31068 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
31069 copyright="PRAGMA ADE / ConTeXt Development Team",
31070 license="see context related readme files"
31071 }
31072 local insert,sortedkeys,sortedhash,tohash=table.insert,table.sortedkeys,table.sortedhash,table.tohash
31073 local type,next,tonumber=type,next,tonumber
31074 local lpegmatch=lpeg.match
31075 local utfbyte,utflen=utf.byte,utf.len
31076 local sortedhash=table.sortedhash
31077 local trace_loading=false trackers.register("otf.loading",function(v) trace_loading=v end)
31078 local report_otf=logs.reporter("fonts","otf loading")
31079 local fonts=fonts
31080 local otf=fonts.handlers.otf
31081 local registerotffeature=otf.features.register
31082 local setmetatableindex=table.setmetatableindex
31083 local fonthelpers=fonts.helpers
31084 local checkmerge=fonthelpers.checkmerge
31085 local checkflags=fonthelpers.checkflags
31086 local checksteps=fonthelpers.checksteps
31087 local normalized={
31088 substitution="substitution",
31089 single="substitution",
31090 ligature="ligature",
31091 alternate="alternate",
31092 multiple="multiple",
31093 kern="kern",
31094 pair="pair",
31095 single="single",
31096 chainsubstitution="chainsubstitution",
31097 chainposition="chainposition",
31098 }
31099 local types={
31100 substitution="gsub_single",
31101 ligature="gsub_ligature",
31102 alternate="gsub_alternate",
31103 multiple="gsub_multiple",
31104 kern="gpos_pair",
31105 pair="gpos_pair",
31106 single="gpos_single",
31107 chainsubstitution="gsub_contextchain",
31108 chainposition="gpos_contextchain",
31109 }
31110 local names={
31111 gsub_single="gsub",
31112 gsub_multiple="gsub",
31113 gsub_alternate="gsub",
31114 gsub_ligature="gsub",
31115 gsub_context="gsub",
31116 gsub_contextchain="gsub",
31117 gsub_reversecontextchain="gsub",
31118 gpos_single="gpos",
31119 gpos_pair="gpos",
31120 gpos_cursive="gpos",
31121 gpos_mark2base="gpos",
31122 gpos_mark2ligature="gpos",
31123 gpos_mark2mark="gpos",
31124 gpos_context="gpos",
31125 gpos_contextchain="gpos",
31126 }
31127 setmetatableindex(types,function(t,k) t[k]=k return k end)
31128 local everywhere={ ["*"]={ ["*"]=true } }
31129 local noflags={ false,false,false,false }
31130 local function getrange(sequences,category)
31131 local count=#sequences
31132 local first=nil
31133 local last=nil
31134 for i=1,count do
31135 local t=sequences[i].type
31136 if t and names[t]==category then
31137 if not first then
31138 first=i
31139 end
31140 last=i
31141 end
31142 end
31143 return first or 1,last or count
31144 end
31145 local function validspecification(specification,name)
31146 local dataset=specification.dataset
31147 if dataset then
31148 elseif specification[1] then
31149 dataset=specification
31150 specification={ dataset=dataset }
31151 else
31152 dataset={ { data=specification.data } }
31153 specification.data=nil
31154 specification.coverage=dataset
31155 specification.dataset=dataset
31156 end
31157 local first=dataset[1]
31158 if first then
31159 first=first.data
31160 end
31161 if not first then
31162 report_otf("invalid feature specification, no dataset")
31163 return
31164 end
31165 if type(name)~="string" then
31166 name=specification.name or first.name
31167 end
31168 if type(name)~="string" then
31169 report_otf("invalid feature specification, no name")
31170 return
31171 end
31172 local n=#dataset
31173 if n>0 then
31174 for i=1,n do
31175 setmetatableindex(dataset[i],specification)
31176 end
31177 return specification,name
31178 end
31179 end
31180 local function addfeature(data,feature,specifications,prepareonly)
31181 if not specifications then
31182 report_otf("missing specification")
31183 return
31184 end
31185 local descriptions=data.descriptions
31186 local resources=data.resources
31187 if not descriptions or not resources then
31188 report_otf("missing specification")
31189 return
31190 end
31191 local features=resources.features
31192 local sequences=resources.sequences
31193 if not features or not sequences then
31194 report_otf("missing specification")
31195 return
31196 end
31197 local alreadydone=resources.alreadydone
31198 if not alreadydone then
31199 alreadydone={}
31200 resources.alreadydone=alreadydone
31201 end
31202 if alreadydone[specifications] then
31203 return
31204 else
31205 alreadydone[specifications]=true
31206 end
31207 local fontfeatures=resources.features or everywhere
31208 local unicodes=resources.unicodes
31209 local splitter=lpeg.splitter(" ",unicodes)
31210 local done=0
31211 local skip=0
31212 local aglunicodes=false
31213 local privateslot=fonthelpers.privateslot
31214 local specifications=validspecification(specifications,feature)
31215 if not specifications then
31216 return
31217 end
31218 local p=lpeg.P("P")*(lpeg.patterns.hexdigit^1/function(s) return tonumber(s,16) end)*lpeg.P(-1)
31219 local function tounicode(code)
31220 if not code then
31221 return
31222 end
31223 if type(code)=="number" then
31224 return code
31225 end
31226 local u=unicodes[code]
31227 if u then
31228 return u
31229 end
31230 if utflen(code)==1 then
31231 u=utfbyte(code)
31232 if u then
31233 return u
31234 end
31235 end
31236 if privateslot then
31237 u=privateslot(code)
31238 if u then
31239 return u
31240 end
31241 end
31242 local u=lpegmatch(p,code)
31243 if u then
31244 return u
31245 end
31246 if not aglunicodes then
31247 aglunicodes=fonts.encodings.agl.unicodes
31248 end
31249 local u=aglunicodes[code]
31250 if u then
31251 return u
31252 end
31253 end
31254 local coverup=otf.coverup
31255 local coveractions=coverup.actions
31256 local stepkey=coverup.stepkey
31257 local register=coverup.register
31258 local function prepare_substitution(list,featuretype,nocheck)
31259 local coverage={}
31260 local cover=coveractions[featuretype]
31261 for code,replacement in next,list do
31262 local unicode=tounicode(code)
31263 local description=descriptions[unicode]
31264 if not nocheck and not description then
31265 skip=skip+1
31266 else
31267 if type(replacement)=="table" then
31268 replacement=replacement[1]
31269 end
31270 replacement=tounicode(replacement)
31271 if replacement and (nocheck or descriptions[replacement]) then
31272 cover(coverage,unicode,replacement)
31273 done=done+1
31274 else
31275 skip=skip+1
31276 end
31277 end
31278 end
31279 return coverage
31280 end
31281 local function prepare_alternate(list,featuretype,nocheck)
31282 local coverage={}
31283 local cover=coveractions[featuretype]
31284 for code,replacement in next,list do
31285 local unicode=tounicode(code)
31286 local description=descriptions[unicode]
31287 if not nocheck and not description then
31288 skip=skip+1
31289 elseif type(replacement)=="table" then
31290 local r={}
31291 for i=1,#replacement do
31292 local u=tounicode(replacement[i])
31293 r[i]=(nocheck or descriptions[u]) and u or unicode
31294 end
31295 cover(coverage,unicode,r)
31296 done=done+1
31297 else
31298 local u=tounicode(replacement)
31299 if u then
31300 cover(coverage,unicode,{ u })
31301 done=done+1
31302 else
31303 skip=skip+1
31304 end
31305 end
31306 end
31307 return coverage
31308 end
31309 local function prepare_multiple(list,featuretype,nocheck)
31310 local coverage={}
31311 local cover=coveractions[featuretype]
31312 for code,replacement in next,list do
31313 local unicode=tounicode(code)
31314 local description=descriptions[unicode]
31315 if not nocheck and not description then
31316 skip=skip+1
31317 elseif type(replacement)=="table" then
31318 local r={}
31319 local n=0
31320 for i=1,#replacement do
31321 local u=tounicode(replacement[i])
31322 if nocheck or descriptions[u] then
31323 n=n+1
31324 r[n]=u
31325 end
31326 end
31327 if n>0 then
31328 cover(coverage,unicode,r)
31329 done=done+1
31330 else
31331 skip=skip+1
31332 end
31333 else
31334 local u=tounicode(replacement)
31335 if u then
31336 cover(coverage,unicode,{ u })
31337 done=done+1
31338 else
31339 skip=skip+1
31340 end
31341 end
31342 end
31343 return coverage
31344 end
31345 local function prepare_ligature(list,featuretype,nocheck)
31346 local coverage={}
31347 local cover=coveractions[featuretype]
31348 for code,ligature in next,list do
31349 local unicode=tounicode(code)
31350 local description=descriptions[unicode]
31351 if not nocheck and not description then
31352 skip=skip+1
31353 else
31354 if type(ligature)=="string" then
31355 ligature={ lpegmatch(splitter,ligature) }
31356 end
31357 local present=true
31358 for i=1,#ligature do
31359 local l=ligature[i]
31360 local u=tounicode(l)
31361 if nocheck or descriptions[u] then
31362 ligature[i]=u
31363 else
31364 present=false
31365 break
31366 end
31367 end
31368 if present then
31369 cover(coverage,unicode,ligature)
31370 done=done+1
31371 else
31372 skip=skip+1
31373 end
31374 end
31375 end
31376 return coverage
31377 end
31378 local function resetspacekerns()
31379 data.properties.hasspacekerns=true
31380 data.resources .spacekerns=nil
31381 end
31382 local function prepare_kern(list,featuretype)
31383 local coverage={}
31384 local cover=coveractions[featuretype]
31385 local isspace=false
31386 for code,replacement in next,list do
31387 local unicode=tounicode(code)
31388 local description=descriptions[unicode]
31389 if description and type(replacement)=="table" then
31390 local r={}
31391 for k,v in next,replacement do
31392 local u=tounicode(k)
31393 if u then
31394 r[u]=v
31395 if u==32 then
31396 isspace=true
31397 end
31398 end
31399 end
31400 if next(r) then
31401 cover(coverage,unicode,r)
31402 done=done+1
31403 if unicode==32 then
31404 isspace=true
31405 end
31406 else
31407 skip=skip+1
31408 end
31409 else
31410 skip=skip+1
31411 end
31412 end
31413 if isspace then
31414 resetspacekerns()
31415 end
31416 return coverage
31417 end
31418 local function prepare_pair(list,featuretype)
31419 local coverage={}
31420 local cover=coveractions[featuretype]
31421 if cover then
31422 for code,replacement in next,list do
31423 local unicode=tounicode(code)
31424 local description=descriptions[unicode]
31425 if description and type(replacement)=="table" then
31426 local r={}
31427 for k,v in next,replacement do
31428 local u=tounicode(k)
31429 if u then
31430 r[u]=v
31431 if u==32 then
31432 isspace=true
31433 end
31434 end
31435 end
31436 if next(r) then
31437 cover(coverage,unicode,r)
31438 done=done+1
31439 if unicode==32 then
31440 isspace=true
31441 end
31442 else
31443 skip=skip+1
31444 end
31445 else
31446 skip=skip+1
31447 end
31448 end
31449 if isspace then
31450 resetspacekerns()
31451 end
31452 else
31453 report_otf("unknown cover type %a",featuretype)
31454 end
31455 return coverage
31456 end
31457 local prepare_single=prepare_pair
31458 local function hassteps(lookups)
31459 if lookups then
31460 for i=1,#lookups do
31461 local l=lookups[i]
31462 if l then
31463 for j=1,#l do
31464 local l=l[j]
31465 if l then
31466 local n=l.nofsteps
31467 if not n then
31468 return true
31469 elseif n>0 then
31470 return true
31471 end
31472 end
31473 end
31474 end
31475 end
31476 end
31477 return false
31478 end
31479 local function prepare_chain(list,featuretype,sublookups,nocheck)
31480 local rules=list.rules
31481 local coverage={}
31482 if rules then
31483 local lookuptype=types[featuretype]
31484 for nofrules=1,#rules do
31485 local rule=rules[nofrules]
31486 local current=rule.current
31487 local before=rule.before
31488 local after=rule.after
31489 local replacements=rule.replacements or false
31490 local sequence={}
31491 local nofsequences=0
31492 if before then
31493 for n=1,#before do
31494 nofsequences=nofsequences+1
31495 sequence[nofsequences]=before[n]
31496 end
31497 end
31498 local start=nofsequences+1
31499 for n=1,#current do
31500 nofsequences=nofsequences+1
31501 sequence[nofsequences]=current[n]
31502 end
31503 local stop=nofsequences
31504 if after then
31505 for n=1,#after do
31506 nofsequences=nofsequences+1
31507 sequence[nofsequences]=after[n]
31508 end
31509 end
31510 local lookups=rule.lookups or false
31511 local subtype=nil
31512 if lookups and sublookups then
31513 if #lookups>0 then
31514 local ns=stop-start+1
31515 for i=1,ns do
31516 if lookups[i]==nil then
31517 lookups[i]=0
31518 end
31519 end
31520 end
31521 local l={}
31522 for k,v in sortedhash(lookups) do
31523 local t=type(v)
31524 if t=="table" then
31525 for i=1,#v do
31526 local vi=v[i]
31527 if type(vi)~="table" then
31528 v[i]={ vi }
31529 end
31530 end
31531 l[k]=v
31532 elseif t=="number" then
31533 local lookup=sublookups[v]
31534 if lookup then
31535 l[k]={ lookup }
31536 if not subtype then
31537 subtype=lookup.type
31538 end
31539 elseif v==0 then
31540 l[k]={ { type="gsub_remove",nosteps=true } }
31541 else
31542 l[k]=false
31543 end
31544 else
31545 l[k]=false
31546 end
31547 end
31548 if nocheck then
31549 rule.lookups=l
31550 end
31551 lookups=l
31552 end
31553 if nofsequences>0 then
31554 if hassteps(lookups) then
31555 local hashed={}
31556 for i=1,nofsequences do
31557 local t={}
31558 local s=sequence[i]
31559 for i=1,#s do
31560 local u=tounicode(s[i])
31561 if u then
31562 t[u]=true
31563 end
31564 end
31565 hashed[i]=t
31566 end
31567 sequence=hashed
31568 local ruleset={
31569 nofrules,
31570 lookuptype,
31571 sequence,
31572 start,
31573 stop,
31574 lookups,
31575 replacements,
31576 subtype,
31577 }
31578 for unic in sortedhash(sequence[start]) do
31579 local cu=coverage[unic]
31580 if cu then
31581 local n=cu.n+1
31582 cu[n]=ruleset
31583 cu.n=n
31584 else
31585 coverage[unic]={
31586 ruleset,
31587 n=1,
31588 }
31589 end
31590 end
31591 sequence.n=nofsequences
31592 else
31593 end
31594 end
31595 end
31596 end
31597 return coverage
31598 end
31599 local dataset=specifications.dataset
31600 local function report(name,category,position,first,last,sequences)
31601 report_otf("injecting name %a of category %a at position %i in [%i,%i] of [%i,%i]",
31602 name,category,position,first,last,1,#sequences)
31603 end
31604 local function inject(specification,sequences,sequence,first,last,category,name)
31605 local position=specification.position or false
31606 if not position then
31607 position=specification.prepend
31608 if position==true then
31609 if trace_loading then
31610 report(name,category,first,first,last,sequences)
31611 end
31612 insert(sequences,first,sequence)
31613 return
31614 end
31615 end
31616 if not position then
31617 position=specification.append
31618 if position==true then
31619 if trace_loading then
31620 report(name,category,last+1,first,last,sequences)
31621 end
31622 insert(sequences,last+1,sequence)
31623 return
31624 end
31625 end
31626 local kind=type(position)
31627 if kind=="string" then
31628 local index=false
31629 for i=first,last do
31630 local s=sequences[i]
31631 local f=s.features
31632 if f then
31633 for k in sortedhash(f) do
31634 if k==position then
31635 index=i
31636 break
31637 end
31638 end
31639 if index then
31640 break
31641 end
31642 end
31643 end
31644 if index then
31645 position=index
31646 else
31647 position=last+1
31648 end
31649 elseif kind=="number" then
31650 if position<0 then
31651 position=last-position+1
31652 end
31653 if position>last then
31654 position=last+1
31655 elseif position<first then
31656 position=first
31657 end
31658 else
31659 position=last+1
31660 end
31661 if trace_loading then
31662 report(name,category,position,first,last,sequences)
31663 end
31664 insert(sequences,position,sequence)
31665 end
31666 for s=1,#dataset do
31667 local specification=dataset[s]
31668 local valid=specification.valid
31669 local feature=specification.name or feature
31670 if not feature or feature=="" then
31671 report_otf("no valid name given for extra feature")
31672 elseif not valid or valid(data,specification,feature) then
31673 local initialize=specification.initialize
31674 if initialize then
31675 specification.initialize=initialize(specification,data) and initialize or nil
31676 end
31677 local askedfeatures=specification.features or everywhere
31678 local askedsteps=specification.steps or specification.subtables or { specification.data } or {}
31679 local featuretype=specification.type or "substitution"
31680 local featureaction=false
31681 local featureflags=specification.flags or noflags
31682 local nocheck=specification.nocheck
31683 local mapping=specification.mapping
31684 local featureorder=specification.order or { feature }
31685 local featurechain=(featuretype=="chainsubstitution" or featuretype=="chainposition") and 1 or 0
31686 local nofsteps=0
31687 local steps={}
31688 local sublookups=specification.lookups
31689 local category=nil
31690 local steptype=nil
31691 local sequence=nil
31692 if fonts.handlers.otf.handlers[featuretype] then
31693 featureaction=true
31694 else
31695 featuretype=normalized[specification.type or "substitution"] or "substitution"
31696 end
31697 checkflags(specification,resources)
31698 for k,v in next,askedfeatures do
31699 if v[1] then
31700 askedfeatures[k]=tohash(v)
31701 end
31702 end
31703 if featureflags[1] then featureflags[1]="mark" end
31704 if featureflags[2] then featureflags[2]="ligature" end
31705 if featureflags[3] then featureflags[3]="base" end
31706 if featureaction then
31707 category="gsub"
31708 sequence={
31709 features={ [feature]=askedfeatures },
31710 flags=featureflags,
31711 name=feature,
31712 order=featureorder,
31713 type=featuretype,
31714 nofsteps=0,
31715 }
31716 else
31717 if sublookups then
31718 local s={}
31719 for i=1,#sublookups do
31720 local specification=sublookups[i]
31721 local askedsteps=specification.steps or specification.subtables or { specification.data } or {}
31722 local featuretype=normalized[specification.type or "substitution"] or "substitution"
31723 local featureflags=specification.flags or noflags
31724 local nofsteps=0
31725 local steps={}
31726 for i=1,#askedsteps do
31727 local list=askedsteps[i]
31728 local coverage=nil
31729 local format=nil
31730 if featuretype=="substitution" then
31731 coverage=prepare_substitution(list,featuretype,nocheck)
31732 elseif featuretype=="ligature" then
31733 coverage=prepare_ligature(list,featuretype,nocheck)
31734 elseif featuretype=="alternate" then
31735 coverage=prepare_alternate(list,featuretype,nocheck)
31736 elseif featuretype=="multiple" then
31737 coverage=prepare_multiple(list,featuretype,nocheck)
31738 elseif featuretype=="kern" or featuretype=="move" then
31739 format=featuretype
31740 coverage=prepare_kern(list,featuretype)
31741 elseif featuretype=="pair" then
31742 format="pair"
31743 coverage=prepare_pair(list,featuretype)
31744 elseif featuretype=="single" then
31745 format="single"
31746 coverage=prepare_single(list,featuretype)
31747 end
31748 if coverage and next(coverage) then
31749 nofsteps=nofsteps+1
31750 steps[nofsteps]=register(coverage,featuretype,format,feature,nofsteps,descriptions,resources)
31751 end
31752 end
31753 checkmerge(specification)
31754 checksteps(specification)
31755 s[i]={
31756 [stepkey]=steps,
31757 nofsteps=nofsteps,
31758 flags=featureflags,
31759 type=types[featuretype],
31760 }
31761 end
31762 sublookups=s
31763 end
31764 for i=1,#askedsteps do
31765 local list=askedsteps[i]
31766 local coverage=nil
31767 local format=nil
31768 if type(list)=="function" then
31769 list=list(data,specification,list,i)
31770 end
31771 if not list then
31772 elseif featuretype=="substitution" then
31773 category="gsub"
31774 coverage=(mapping and list) or prepare_substitution(list,featuretype,nocheck)
31775 elseif featuretype=="ligature" then
31776 category="gsub"
31777 coverage=prepare_ligature(list,featuretype,nocheck)
31778 elseif featuretype=="alternate" then
31779 category="gsub"
31780 coverage=prepare_alternate(list,featuretype,nocheck)
31781 elseif featuretype=="multiple" then
31782 category="gsub"
31783 coverage=prepare_multiple(list,featuretype,nocheck)
31784 elseif featuretype=="kern" or featuretype=="move" then
31785 category="gpos"
31786 format=featuretype
31787 coverage=prepare_kern(list,featuretype)
31788 elseif featuretype=="pair" then
31789 category="gpos"
31790 format="pair"
31791 coverage=prepare_pair(list,featuretype)
31792 elseif featuretype=="single" then
31793 category="gpos"
31794 format="single"
31795 coverage=prepare_single(list,featuretype)
31796 elseif featuretype=="chainsubstitution" then
31797 category="gsub"
31798 coverage=prepare_chain(list,featuretype,sublookups,nocheck)
31799 elseif featuretype=="chainposition" then
31800 category="gpos"
31801 coverage=prepare_chain(list,featuretype,sublookups,nocheck)
31802 else
31803 report_otf("not registering feature %a, unknown category",feature)
31804 return
31805 end
31806 if coverage and next(coverage) then
31807 nofsteps=nofsteps+1
31808 steps[nofsteps]=register(coverage,featuretype,format,feature,nofsteps,descriptions,resources)
31809 end
31810 end
31811 if nofsteps>0 then
31812 sequence={
31813 chain=featurechain,
31814 features={ [feature]=askedfeatures },
31815 flags=featureflags,
31816 name=feature,
31817 order=featureorder,
31818 [stepkey]=steps,
31819 nofsteps=nofsteps,
31820 type=specification.handler or types[featuretype],
31821 }
31822 if prepareonly then
31823 return sequence
31824 end
31825 end
31826 end
31827 if sequence then
31828 checkflags(sequence,resources)
31829 checkmerge(sequence)
31830 checksteps(sequence)
31831 local first,last=getrange(sequences,category)
31832 inject(specification,sequences,sequence,first,last,category,feature)
31833 local features=fontfeatures[category]
31834 if not features then
31835 features={}
31836 fontfeatures[category]=features
31837 end
31838 local k=features[feature]
31839 if not k then
31840 k={}
31841 features[feature]=k
31842 end
31843 for script,languages in next,askedfeatures do
31844 local kk=k[script]
31845 if not kk then
31846 kk={}
31847 k[script]=kk
31848 end
31849 for language,value in next,languages do
31850 kk[language]=value
31851 end
31852 end
31853 end
31854 end
31855 end
31856 if trace_loading then
31857 report_otf("registering feature %a, affected glyphs %a, skipped glyphs %a",feature,done,skip)
31858 end
31859 end
31860 otf.enhancers.addfeature=addfeature
31861 local extrafeatures={}
31862 local knownfeatures={}
31863 function otf.addfeature(name,specification)
31864 if type(name)=="table" then
31865 specification=name
31866 end
31867 if type(specification)~="table" then
31868 report_otf("invalid feature specification, no valid table")
31869 return
31870 end
31871 specification,name=validspecification(specification,name)
31872 if name and specification then
31873 local slot=knownfeatures[name]
31874 if not slot then
31875 slot=#extrafeatures+1
31876 knownfeatures[name]=slot
31877 elseif specification.overload==false then
31878 slot=#extrafeatures+1
31879 knownfeatures[name]=slot
31880 else
31881 end
31882 specification.name=name
31883 extrafeatures[slot]=specification
31884 end
31885 end
31886 local function enhance(data,filename,raw)
31887 for slot=1,#extrafeatures do
31888 local specification=extrafeatures[slot]
31889 addfeature(data,specification.name,specification)
31890 end
31891 end
31892 otf.enhancers.enhance=enhance
31893 otf.enhancers.register("check extra features",enhance)
31894
31895 end -- closure
31896
31897 do -- begin closure to overcome local limits and interference
31898
31899 if not modules then modules={} end modules ['font-osd']={
31900 version=1.001,
31901 comment="companion to font-ini.mkiv",
31902 author="Kai Eigner, TAT Zetwerk / Hans Hagen, PRAGMA ADE",
31903 copyright="TAT Zetwerk / PRAGMA ADE / ConTeXt Development Team",
31904 license="see context related readme files"
31905 }
31906 local insert,remove,imerge,copy,tohash=table.insert,table.remove,table.imerge,table.copy,table.tohash
31907 local next,type,rawget=next,type,rawget
31908 local formatters=string.formatters
31909 local settings_to_hash=utilities.parsers.settings_to_hash
31910 local report=logs.reporter("otf","devanagari")
31911 fonts=fonts or {}
31912 fonts.analyzers=fonts.analyzers or {}
31913 fonts.analyzers.methods=fonts.analyzers.methods or { node={ otf={} } }
31914 local otf=fonts.handlers.otf
31915 local handlers=otf.handlers
31916 local methods=fonts.analyzers.methods
31917 local otffeatures=fonts.constructors.features.otf
31918 local registerotffeature=otffeatures.register
31919 local trace_steps=false
31920 local nuts=nodes.nuts
31921 local getnext=nuts.getnext
31922 local getprev=nuts.getprev
31923 local getboth=nuts.getboth
31924 local getid=nuts.getid
31925 local getchar=nuts.getchar
31926 local getfont=nuts.getfont
31927 local getsubtype=nuts.getsubtype
31928 local setlink=nuts.setlink
31929 local setnext=nuts.setnext
31930 local setprev=nuts.setprev
31931 local setchar=nuts.setchar
31932 local getprop=nuts.getprop
31933 local setprop=nuts.setprop
31934 local getstate=nuts.getstate
31935 local setstate=nuts.setstate
31936 local ischar=nuts.ischar
31937 local insertnodeafter=nuts.insertafter
31938 local copy_node=nuts.copy
31939 local remove_node=nuts.remove
31940 local flushlist=nuts.flushlist
31941 local flushnode=nuts.flushnode
31942 local copyinjection=nodes.injections.copy
31943 local unsetvalue=attributes.unsetvalue
31944 local fontdata=fonts.hashes.identifiers
31945 local a_syllabe="syllable"
31946 local a_reordered="reordered"
31947 local dotted_circle=0x25CC
31948 local c_nbsp=0x00A0
31949 local c_zwnj=0x200C
31950 local c_zwj=0x200D
31951 local states=fonts.analyzers.states
31952 local s_rphf=states.rphf
31953 local s_half=states.half
31954 local s_pref=states.pref
31955 local s_blwf=states.blwf
31956 local s_pstf=states.pstf
31957 local s_init=states.init
31958 local replace_all_nbsp=nil
31959 replace_all_nbsp=function(head)
31960 replace_all_nbsp=typesetters and typesetters.characters and typesetters.characters.replacenbspaces or function(head)
31961 return head
31962 end
31963 return replace_all_nbsp(head)
31964 end
31965 local processcharacters=nil
31966 local logprocess=nil
31967 if context then
31968
31969 --removed
31970
31971 else
31972 function processcharacters(head,font)
31973 local processors=fontdata[font].shared.processes
31974 for i=1,#processors do
31975 head=processors[i](head,font,0)
31976 end
31977 return head
31978 end
31979 logprocess=function(str)
31980 end
31981 end
31982 local indicgroups=characters and characters.indicgroups
31983 if not indicgroups and characters then
31984 local indic={
31985 c={},
31986 i={},
31987 d={},
31988 m={},
31989 s={},
31990 o={},
31991 }
31992 local indicmarks={
31993 l={},
31994 t={},
31995 b={},
31996 r={},
31997 s={},
31998 }
31999 local indicclasses={
32000 nukta={},
32001 halant={},
32002 ra={},
32003 anudatta={},
32004 }
32005 local indicorders={
32006 bp={},
32007 ap={},
32008 bs={},
32009 as={},
32010 bh={},
32011 ah={},
32012 bm={},
32013 am={},
32014 }
32015 for k,v in next,characters.data do
32016 local i=v.indic
32017 if i then
32018 indic[i][k]=true
32019 i=v.indicmark
32020 if i then
32021 if i=="s" then
32022 local s=v.specials
32023 indicmarks[i][k]={ s[2],s[3] }
32024 else
32025 indicmarks[i][k]=true
32026 end
32027 end
32028 i=v.indicclass
32029 if i then
32030 indicclasses[i][k]=true
32031 end
32032 i=v.indicorder
32033 if i then
32034 indicorders[i][k]=true
32035 end
32036 end
32037 end
32038 indicgroups={
32039 consonant=indic.c,
32040 independent_vowel=indic.i,
32041 dependent_vowel=indic.d,
32042 vowel_modifier=indic.m,
32043 stress_tone_mark=indic.s,
32044 pre_mark=indicmarks.l,
32045 above_mark=indicmarks.t,
32046 below_mark=indicmarks.b,
32047 post_mark=indicmarks.r,
32048 twopart_mark=indicmarks.s,
32049 nukta=indicclasses.nukta,
32050 halant=indicclasses.halant,
32051 ra=indicclasses.ra,
32052 anudatta=indicclasses.anudatta,
32053 before_postscript=indicorders.bp,
32054 after_postscript=indicorders.ap,
32055 before_half=indicorders.bh,
32056 after_half=indicorders.ah,
32057 before_subscript=indicorders.bs,
32058 after_subscript=indicorders.as,
32059 before_main=indicorders.bm,
32060 after_main=indicorders.am,
32061 }
32062 indic=nil
32063 indicmarks=nil
32064 indicclasses=nil
32065 indicorders=nil
32066 characters.indicgroups=indicgroups
32067 end
32068 local consonant=indicgroups.consonant
32069 local independent_vowel=indicgroups.independent_vowel
32070 local dependent_vowel=indicgroups.dependent_vowel
32071 local vowel_modifier=indicgroups.vowel_modifier
32072 local stress_tone_mark=indicgroups.stress_tone_mark
32073 local pre_mark=indicgroups.pre_mark
32074 local above_mark=indicgroups.above_mark
32075 local below_mark=indicgroups.below_mark
32076 local post_mark=indicgroups.post_mark
32077 local twopart_mark=indicgroups.twopart_mark
32078 local nukta=indicgroups.nukta
32079 local halant=indicgroups.halant
32080 local ra=indicgroups.ra
32081 local anudatta=indicgroups.anudatta
32082 local before_postscript=indicgroups.before_postscript
32083 local after_postscript=indicgroups.after_postscript
32084 local before_half=indicgroups.before_half
32085 local after_half=indicgroups.after_half
32086 local before_subscript=indicgroups.before_subscript
32087 local after_subscript=indicgroups.after_subscript
32088 local before_main=indicgroups.before_main
32089 local after_main=indicgroups.after_main
32090 local mark_pre_above_below_post=table.merged (
32091 pre_mark,
32092 above_mark,
32093 below_mark,
32094 post_mark
32095 )
32096 local mark_above_below_post=table.merged (
32097 above_mark,
32098 below_mark,
32099 post_mark
32100 )
32101 local devanagarihash=table.setmetatableindex(function(t,k)
32102 local v=fontdata[k].resources.devanagari or false
32103 t[k]=v
32104 return v
32105 end)
32106 local zw_char={
32107 [c_zwnj]=true,
32108 [c_zwj ]=true,
32109 }
32110 local dflt_true={
32111 dflt=true,
32112 }
32113 local two_defaults={}
32114 local one_defaults={}
32115 local false_flags={ false,false,false,false }
32116 local sequence_reorder_matras={
32117 features={ dv01=two_defaults },
32118 flags=false_flags,
32119 name="dv01_reorder_matras",
32120 order={ "dv01" },
32121 type="devanagari_reorder_matras",
32122 nofsteps=1,
32123 steps={
32124 {
32125 coverage=pre_mark,
32126 }
32127 }
32128 }
32129 local sequence_reorder_reph={
32130 features={ dv02=two_defaults },
32131 flags=false_flags,
32132 name="dv02_reorder_reph",
32133 order={ "dv02" },
32134 type="devanagari_reorder_reph",
32135 nofsteps=1,
32136 steps={
32137 {
32138 coverage={},
32139 }
32140 }
32141 }
32142 local sequence_reorder_pre_base_reordering_consonants={
32143 features={ dv03=one_defaults },
32144 flags=false_flags,
32145 name="dv03_reorder_pre_base_reordering_consonants",
32146 order={ "dv03" },
32147 type="devanagari_reorder_pre_base_reordering_consonants",
32148 nofsteps=1,
32149 steps={
32150 {
32151 coverage={},
32152 }
32153 }
32154 }
32155 local sequence_remove_joiners={
32156 features={ dv04=one_defaults },
32157 flags=false_flags,
32158 name="dv04_remove_joiners",
32159 order={ "dv04" },
32160 type="devanagari_remove_joiners",
32161 nofsteps=1,
32162 steps={
32163 {
32164 coverage=zw_char,
32165 },
32166 }
32167 }
32168 local basic_shaping_forms={
32169 akhn=true,
32170 blwf=true,
32171 cjct=true,
32172 half=true,
32173 nukt=true,
32174 pref=true,
32175 pstf=true,
32176 rkrf=true,
32177 rphf=true,
32178 vatu=true,
32179 locl=true,
32180 }
32181 local valid={
32182 abvs=true,
32183 akhn=true,
32184 blwf=true,
32185 calt=true,
32186 cjct=true,
32187 half=true,
32188 haln=true,
32189 nukt=true,
32190 pref=true,
32191 pres=true,
32192 pstf=true,
32193 psts=true,
32194 rkrf=true,
32195 rphf=true,
32196 vatu=true,
32197 pres=true,
32198 abvs=true,
32199 blws=true,
32200 psts=true,
32201 haln=true,
32202 calt=true,
32203 locl=true,
32204 }
32205 local scripts={}
32206 local scripts_one={ "deva","mlym","beng","gujr","guru","knda","orya","taml","telu" }
32207 local scripts_two={ "dev2","mlm2","bng2","gjr2","gur2","knd2","ory2","tml2","tel2" }
32208 local nofscripts=#scripts_one
32209 for i=1,nofscripts do
32210 local one=scripts_one[i]
32211 local two=scripts_two[i]
32212 scripts[one]=true
32213 scripts[two]=true
32214 two_defaults[two]=dflt_true
32215 one_defaults[one]=dflt_true
32216 one_defaults[two]=dflt_true
32217 end
32218 local function valid_one(s) for i=1,nofscripts do if s[scripts_one[i]] then return true end end end
32219 local function valid_two(s) for i=1,nofscripts do if s[scripts_two[i]] then return true end end end
32220 local function initializedevanagi(tfmdata)
32221 local script,language=otf.scriptandlanguage(tfmdata,attr)
32222 if scripts[script] then
32223 local resources=tfmdata.resources
32224 local devanagari=resources.devanagari
32225 if not devanagari then
32226 report("adding features to font")
32227 local gsubfeatures=resources.features.gsub
32228 local sequences=resources.sequences
32229 local sharedfeatures=tfmdata.shared.features
32230 gsubfeatures["dv01"]=two_defaults
32231 gsubfeatures["dv02"]=two_defaults
32232 gsubfeatures["dv03"]=one_defaults
32233 gsubfeatures["dv04"]=one_defaults
32234 local reorder_pre_base_reordering_consonants=copy(sequence_reorder_pre_base_reordering_consonants)
32235 local reorder_reph=copy(sequence_reorder_reph)
32236 local reorder_matras=copy(sequence_reorder_matras)
32237 local remove_joiners=copy(sequence_remove_joiners)
32238 local lastmatch=0
32239 for s=1,#sequences do
32240 local features=sequences[s].features
32241 if features then
32242 for k,v in next,features do
32243 if k=="locl" then
32244 local steps=sequences[s].steps
32245 local nofsteps=sequences[s].nofsteps
32246 for i=1,nofsteps do
32247 local step=steps[i]
32248 local coverage=step.coverage
32249 if coverage then
32250 for k,v in next,pre_mark do
32251 local locl=coverage[k]
32252 if locl then
32253 if #locl>0 then
32254 for j=1,#locl do
32255 local ck=locl[j]
32256 local f=ck[4]
32257 local chainlookups=ck[6]
32258 if chainlookups then
32259 local chainlookup=chainlookups[f]
32260 for j=1,#chainlookup do
32261 local chainstep=chainlookup[j]
32262 local steps=chainstep.steps
32263 local nofsteps=chainstep.nofsteps
32264 for i=1,nofsteps do
32265 local step=steps[i]
32266 local coverage=step.coverage
32267 if coverage then
32268 locl=coverage[k]
32269 end
32270 end
32271 end
32272 end
32273 end
32274 else
32275 end
32276 if locl then
32277 reorder_matras.steps[1].coverage[locl]=true
32278 end
32279 end
32280 end
32281 end
32282 end
32283 end
32284 if basic_shaping_forms[k] then
32285 lastmatch=lastmatch+1
32286 if s~=lastmatch then
32287 insert(sequences,lastmatch,remove(sequences,s))
32288 end
32289 end
32290 end
32291 end
32292 end
32293 local insertindex=lastmatch+1
32294 if tfmdata.properties.language then
32295 dflt_true[tfmdata.properties.language]=true
32296 end
32297 insert(sequences,insertindex,reorder_pre_base_reordering_consonants)
32298 insert(sequences,insertindex,reorder_reph)
32299 insert(sequences,insertindex,reorder_matras)
32300 insert(sequences,insertindex,remove_joiners)
32301 local blwfcache={}
32302 local vatucache={}
32303 local pstfcache={}
32304 local seqsubset={}
32305 local rephstep={ coverage={} }
32306 local devanagari={
32307 reph=false,
32308 vattu=false,
32309 blwfcache=blwfcache,
32310 vatucache=vatucache,
32311 pstfcache=pstfcache,
32312 seqsubset=seqsubset,
32313 reorderreph=rephstep,
32314 }
32315 reorder_reph.steps={ rephstep }
32316 local pre_base_reordering_consonants={}
32317 reorder_pre_base_reordering_consonants.steps[1].coverage=pre_base_reordering_consonants
32318 resources.devanagari=devanagari
32319 for s=1,#sequences do
32320 local sequence=sequences[s]
32321 local steps=sequence.steps
32322 local nofsteps=sequence.nofsteps
32323 local features=sequence.features
32324 local has_rphf=features.rphf
32325 local has_blwf=features.blwf
32326 local has_vatu=features.vatu
32327 local has_pstf=features.pstf
32328 if has_rphf and has_rphf[script] then
32329 devanagari.reph=true
32330 elseif (has_blwf and has_blwf[script]) or (has_vatu and has_vatu[script]) then
32331 devanagari.vattu=true
32332 for i=1,nofsteps do
32333 local step=steps[i]
32334 local coverage=step.coverage
32335 if coverage then
32336 for k,v in next,coverage do
32337 for h,w in next,halant do
32338 if v[h] and not blwfcache[k] then
32339 blwfcache[k]=v
32340 end
32341 if has_vatu and has_vatu[script] and not vatucache[k] then
32342 vatucache[k]=v
32343 end
32344 end
32345 end
32346 end
32347 end
32348 elseif has_pstf and has_pstf[script] then
32349 for i=1,nofsteps do
32350 local step=steps[i]
32351 local coverage=step.coverage
32352 if coverage then
32353 for k,v in next,coverage do
32354 if not pstfcache[k] then
32355 pstfcache[k]=v
32356 end
32357 end
32358 for k,v in next,ra do
32359 local r=coverage[k]
32360 if r then
32361 local found=false
32362 if #r>0 then
32363 for j=1,#r do
32364 local ck=r[j]
32365 local f=ck[4]
32366 local chainlookups=ck[6]
32367 if chainlookups then
32368 local chainlookup=chainlookups[f]
32369 if chainlookup then
32370 for j=1,#chainlookup do
32371 local chainstep=chainlookup[j]
32372 local steps=chainstep.steps
32373 local nofsteps=chainstep.nofsteps
32374 for i=1,nofsteps do
32375 local step=steps[i]
32376 local coverage=step.coverage
32377 if coverage then
32378 local h=coverage[k]
32379 if h then
32380 for k,v in next,h do
32381 if v then
32382 found=tonumber(v) or v.ligature
32383 if found then
32384 pre_base_reordering_consonants[found]=true
32385 break
32386 end
32387 end
32388 end
32389 if found then
32390 break
32391 end
32392 end
32393 end
32394 end
32395 end
32396 end
32397 end
32398 end
32399 else
32400 for k,v in next,r do
32401 if v then
32402 found=tonumber(v) or v.ligature
32403 if found then
32404 pre_base_reordering_consonants[found]=true
32405 break
32406 end
32407 end
32408 end
32409 end
32410 if found then
32411 break
32412 end
32413 end
32414 end
32415 end
32416 end
32417 end
32418 for kind,spec in next,features do
32419 if valid[kind] and valid_two(spec)then
32420 for i=1,nofsteps do
32421 local step=steps[i]
32422 local coverage=step.coverage
32423 if coverage then
32424 local reph=false
32425 local base=false
32426 if kind=="rphf" then
32427 for k,v in next,ra do
32428 local r=coverage[k]
32429 if r then
32430 base=k
32431 local h=false
32432 if #r>0 then
32433 for j=1,#r do
32434 local ck=r[j]
32435 local f=ck[4]
32436 local chainlookups=ck[6]
32437 if chainlookups then
32438 local chainlookup=chainlookups[f]
32439 for j=1,#chainlookup do
32440 local chainstep=chainlookup[j]
32441 local steps=chainstep.steps
32442 local nofsteps=chainstep.nofsteps
32443 for i=1,nofsteps do
32444 local step=steps[i]
32445 local coverage=step.coverage
32446 if coverage then
32447 local r=coverage[k]
32448 if r then
32449 for k,v in next,halant do
32450 local h=r[k]
32451 if h then
32452 reph=tonumber(h) or h.ligature or false
32453 break
32454 end
32455 end
32456 if h then
32457 break
32458 end
32459 end
32460 end
32461 end
32462 end
32463 end
32464 end
32465 else
32466 for k,v in next,halant do
32467 local h=r[k]
32468 if h then
32469 reph=tonumber(h) or h.ligature or false
32470 break
32471 end
32472 end
32473 end
32474 if reph then
32475 break
32476 end
32477 end
32478 end
32479 end
32480 seqsubset[#seqsubset+1]={ kind,coverage,reph,base }
32481 end
32482 end
32483 end
32484 if kind=="pref" then
32485 local steps=sequence.steps
32486 local nofsteps=sequence.nofsteps
32487 for i=1,nofsteps do
32488 local step=steps[i]
32489 local coverage=step.coverage
32490 if coverage then
32491 for k,v in next,halant do
32492 local h=coverage[k]
32493 if h then
32494 local found=false
32495 if #h>0 then
32496 for j=1,#h do
32497 local ck=h[j]
32498 local f=ck[4]
32499 local chainlookups=ck[6]
32500 if chainlookups then
32501 local chainlookup=chainlookups[f]
32502 for j=1,#chainlookup do
32503 local chainstep=chainlookup[j]
32504 local steps=chainstep.steps
32505 local nofsteps=chainstep.nofsteps
32506 for i=1,nofsteps do
32507 local step=steps[i]
32508 local coverage=step.coverage
32509 if coverage then
32510 local h=coverage[k]
32511 if h then
32512 for k,v in next,h do
32513 if v then
32514 found=tonumber(v) or v.ligature
32515 if found then
32516 pre_base_reordering_consonants[found]=true
32517 break
32518 end
32519 end
32520 end
32521 if found then
32522 break
32523 end
32524 end
32525 end
32526 end
32527 end
32528 end
32529 end
32530 else
32531 for k,v in next,h do
32532 found=v and (tonumber(v) or v.ligature)
32533 if found then
32534 pre_base_reordering_consonants[found]=true
32535 break
32536 end
32537 end
32538 end
32539 if found then
32540 break
32541 end
32542 end
32543 end
32544 end
32545 end
32546 end
32547 end
32548 end
32549 if two_defaults[script] then
32550 sharedfeatures["dv01"]=true
32551 sharedfeatures["dv02"]=true
32552 sharedfeatures["dv03"]=true
32553 sharedfeatures["dv04"]=true
32554 elseif one_defaults[script] then
32555 sharedfeatures["dv03"]=true
32556 sharedfeatures["dv04"]=true
32557 end
32558 end
32559 end
32560 end
32561 registerotffeature {
32562 name="devanagari",
32563 description="inject additional features",
32564 default=true,
32565 initializers={
32566 node=initializedevanagi,
32567 },
32568 }
32569 local function initializeconjuncts(tfmdata,value)
32570 if value then
32571 local resources=tfmdata.resources
32572 local devanagari=resources.devanagari
32573 if devanagari then
32574 local conjuncts="auto"
32575 local movematra="auto"
32576 if type(value)=="string" and value~="auto" then
32577 value=settings_to_hash(value)
32578 conjuncts=rawget(value,"conjuncts") or conjuncts
32579 movematra=rawget(value,"movematra") or movematra
32580 end
32581 if conjuncts=="auto" then
32582 conjuncts="mixed"
32583 end
32584 if movematra=="auto" and
32585 script=="mlym" or
32586 script=="taml" then
32587 movematra="leftbeforebase"
32588 else
32589 movematra="default"
32590 end
32591 devanagari.conjuncts=conjuncts
32592 devanagari.movematra=movematra
32593 if trace_steps then
32594 report("conjuncts %a, movematra %a",conjuncts,movematra)
32595 end
32596 end
32597 end
32598 end
32599 registerotffeature {
32600 name="indic",
32601 description="control indic",
32602 default="auto",
32603 initializers={
32604 node=initializeconjuncts,
32605 },
32606 }
32607 local show_syntax_errors=false
32608 local function inject_syntax_error(head,current,char)
32609 local signal=copy_node(current)
32610 copyinjection(signal,current)
32611 if pre_mark[char] then
32612 setchar(signal,dotted_circle)
32613 else
32614 setchar(current,dotted_circle)
32615 end
32616 return insertnodeafter(head,current,signal)
32617 end
32618 local function initialize_one(font,attr)
32619 local tfmdata=fontdata[font]
32620 local datasets=otf.dataset(tfmdata,font,attr)
32621 local devanagaridata=datasets.devanagari
32622 if not devanagaridata then
32623 devanagaridata={
32624 reph=false,
32625 vattu=false,
32626 blwfcache={},
32627 vatucache={},
32628 pstfcache={},
32629 }
32630 datasets.devanagari=devanagaridata
32631 local resources=tfmdata.resources
32632 local devanagari=resources.devanagari
32633 for s=1,#datasets do
32634 local dataset=datasets[s]
32635 if dataset and dataset[1] then
32636 local kind=dataset[4]
32637 if kind=="rphf" then
32638 devanagaridata.reph=true
32639 elseif kind=="blwf" or kind=="vatu" then
32640 devanagaridata.vattu=true
32641 devanagaridata.blwfcache=devanagari.blwfcache
32642 devanagaridata.vatucache=devanagari.vatucache
32643 devanagaridata.pstfcache=devanagari.pstfcache
32644 end
32645 end
32646 end
32647 end
32648 return devanagaridata.reph,devanagaridata.vattu,devanagaridata.blwfcache,devanagaridata.vatucache,devanagaridata.pstfcache
32649 end
32650 local function contextchain(contexts,n)
32651 local char=getchar(n)
32652 if not contexts.n then
32653 return contexts[char]
32654 else
32655 for k=1,#contexts do
32656 local ck=contexts[k]
32657 local seq=ck[3]
32658 local f=ck[4]
32659 local l=ck[5]
32660 if (l-f)==1 and seq[f+1][char] then
32661 local ok=true
32662 local c=n
32663 for i=l+1,#seq do
32664 c=getnext(c)
32665 if not c or not seq[i][ischar(c)] then
32666 ok=false
32667 break
32668 end
32669 end
32670 if ok then
32671 c=getprev(n)
32672 for i=1,f-1 do
32673 c=getprev(c)
32674 if not c or not seq[f-i][ischar(c)] then
32675 ok=false
32676 end
32677 end
32678 end
32679 if ok then
32680 return true
32681 end
32682 end
32683 end
32684 return false
32685 end
32686 end
32687 local function order_matras(c)
32688 local cn=getnext(c)
32689 local char=getchar(cn)
32690 while dependent_vowel[char] do
32691 local next=getnext(cn)
32692 local cc=c
32693 local cchar=getchar(cc)
32694 while cc~=cn do
32695 if (above_mark[char] and (below_mark[cchar] or post_mark[cchar])) or (below_mark[char] and (post_mark[cchar])) then
32696 local prev,next=getboth(cn)
32697 if next then
32698 setprev(next,prev)
32699 end
32700 setnext(prev,next)
32701 setnext(getprev(cc),cn)
32702 setprev(cn,getprev(cc))
32703 setnext(cn,cc)
32704 setprev(cc,cn)
32705 break
32706 end
32707 cc=getnext(cc)
32708 cchar=getchar(cc)
32709 end
32710 cn=next
32711 char=getchar(cn)
32712 end
32713 end
32714 local swapped=table.swapped(states)
32715 local function reorder_one(head,start,stop,font,attr,nbspaces)
32716 local reph,vattu,blwfcache,vatucache,pstfcache=initialize_one(font,attr)
32717 local current=start
32718 local n=getnext(start)
32719 local base=nil
32720 local firstcons=nil
32721 local lastcons=nil
32722 local basefound=false
32723 if reph and ra[getchar(start)] and halant[getchar(n)] then
32724 if n==stop then
32725 return head,stop,nbspaces
32726 end
32727 if getchar(getnext(n))==c_zwj then
32728 current=start
32729 else
32730 current=getnext(n)
32731 setstate(start,s_rphf)
32732 end
32733 end
32734 if getchar(current)==c_nbsp then
32735 if current==stop then
32736 stop=getprev(stop)
32737 head=remove_node(head,current)
32738 flushnode(current)
32739 if trace_steps then
32740 logprocess("reorder one, remove nbsp")
32741 end
32742 return head,stop,nbspaces
32743 else
32744 nbspaces=nbspaces+1
32745 base=current
32746 firstcons=current
32747 lastcons=current
32748 current=getnext(current)
32749 if current~=stop then
32750 local char=getchar(current)
32751 if nukta[char] then
32752 current=getnext(current)
32753 char=getchar(current)
32754 end
32755 if char==c_zwj and current~=stop then
32756 local next=getnext(current)
32757 if next~=stop and halant[getchar(next)] then
32758 current=next
32759 next=getnext(current)
32760 local tmp=next and getnext(next) or nil
32761 local changestop=next==stop
32762 local tempcurrent=copy_node(next)
32763 copyinjection(tempcurrent,next)
32764 local nextcurrent=copy_node(current)
32765 copyinjection(nextcurrent,current)
32766 setlink(tempcurrent,nextcurrent)
32767 setstate(tempcurrent,s_blwf)
32768 tempcurrent=processcharacters(tempcurrent,font)
32769 setstate(tempcurrent,unsetvalue)
32770 if getchar(next)==getchar(tempcurrent) then
32771 flushlist(tempcurrent)
32772 if show_syntax_errors then
32773 head,current=inject_syntax_error(head,current,char)
32774 end
32775 else
32776 setchar(current,getchar(tempcurrent))
32777 local freenode=getnext(current)
32778 setlink(current,tmp)
32779 flushnode(freenode)
32780 flushlist(tempcurrent)
32781 if changestop then
32782 stop=current
32783 end
32784 end
32785 if trace_steps then
32786 logprocess("reorder one, handle nbsp")
32787 end
32788 end
32789 end
32790 end
32791 end
32792 end
32793 while not basefound do
32794 local char=getchar(current)
32795 if consonant[char] then
32796 setstate(current,s_half)
32797 if not firstcons then
32798 firstcons=current
32799 end
32800 lastcons=current
32801 if not base then
32802 base=current
32803 elseif blwfcache[char] then
32804 setstate(current,s_blwf)
32805 elseif pstfcache[char] then
32806 setstate(current,s_pstf)
32807 else
32808 base=current
32809 end
32810 end
32811 basefound=current==stop
32812 current=getnext(current)
32813 end
32814 if base~=lastcons then
32815 local np=base
32816 local n=getnext(base)
32817 local ch=getchar(n)
32818 if nukta[ch] then
32819 np=n
32820 n=getnext(n)
32821 ch=getchar(n)
32822 end
32823 if halant[ch] then
32824 if lastcons~=stop then
32825 local ln=getnext(lastcons)
32826 if nukta[getchar(ln)] then
32827 lastcons=ln
32828 end
32829 end
32830 local nn=getnext(n)
32831 local ln=getnext(lastcons)
32832 setlink(np,nn)
32833 setnext(lastcons,n)
32834 if ln then
32835 setprev(ln,n)
32836 end
32837 setnext(n,ln)
32838 setprev(n,lastcons)
32839 if lastcons==stop then
32840 stop=n
32841 end
32842 if trace_steps then
32843 logprocess("reorder one, handle halant")
32844 end
32845 end
32846 end
32847 n=getnext(start)
32848 if n~=stop and ra[getchar(start)] and halant[getchar(n)] and not zw_char[getchar(getnext(n))] then
32849 local matra=base
32850 if base~=stop then
32851 local next=getnext(base)
32852 if dependent_vowel[getchar(next)] then
32853 matra=next
32854 end
32855 end
32856 local sp=getprev(start)
32857 local nn=getnext(n)
32858 local mn=getnext(matra)
32859 setlink(sp,nn)
32860 setlink(matra,start)
32861 setlink(n,mn)
32862 if head==start then
32863 head=nn
32864 end
32865 start=nn
32866 if matra==stop then
32867 stop=n
32868 end
32869 if trace_steps then
32870 logprocess("reorder one, handle matra")
32871 end
32872 end
32873 local current=start
32874 while current~=stop do
32875 local next=getnext(current)
32876 if next~=stop and halant[getchar(next)] and getchar(getnext(next))==c_zwnj then
32877 setstate(current,unsetvalue)
32878 end
32879 current=next
32880 end
32881 if base~=stop and getstate(base) then
32882 local next=getnext(base)
32883 if halant[getchar(next)] and not (next~=stop and getchar(getnext(next))==c_zwj) then
32884 setstate(base,unsetvalue)
32885 end
32886 end
32887 local current,allreordered,moved=start,false,{ [base]=true }
32888 local a,b,p,bn=base,base,base,getnext(base)
32889 if base~=stop and nukta[getchar(bn)] then
32890 a,b,p=bn,bn,bn
32891 end
32892 while not allreordered do
32893 local c=current
32894 local n=getnext(current)
32895 local l=nil
32896 if c~=stop then
32897 local ch=getchar(n)
32898 if nukta[ch] then
32899 c=n
32900 n=getnext(n)
32901 ch=getchar(n)
32902 end
32903 if c~=stop then
32904 if halant[ch] then
32905 c=n
32906 n=getnext(n)
32907 ch=getchar(n)
32908 end
32909 local tpm=twopart_mark[ch]
32910 if tpm then
32911 while tpm do
32912 local extra=copy_node(n)
32913 copyinjection(extra,n)
32914 ch=tpm[1]
32915 setchar(n,ch)
32916 setchar(extra,tpm[2])
32917 head=insertnodeafter(head,current,extra)
32918 tpm=twopart_mark[ch]
32919 end
32920 if trace_steps then
32921 logprocess("reorder one, handle mark")
32922 end
32923 end
32924 while c~=stop and dependent_vowel[ch] do
32925 c=n
32926 n=getnext(n)
32927 ch=getchar(n)
32928 end
32929 if c~=stop then
32930 if vowel_modifier[ch] then
32931 c=n
32932 n=getnext(n)
32933 ch=getchar(n)
32934 end
32935 if c~=stop and stress_tone_mark[ch] then
32936 c=n
32937 n=getnext(n)
32938 end
32939 end
32940 end
32941 end
32942 local bp=getprev(firstcons)
32943 local cn=getnext(current)
32944 local last=getnext(c)
32945 local done=false
32946 while cn~=last do
32947 if pre_mark[getchar(cn)] then
32948 if devanagarihash[font].movematra=="leftbeforebase" then
32949 local prev,next=getboth(cn)
32950 setlink(prev,next)
32951 if cn==stop then
32952 stop=getprev(cn)
32953 end
32954 if base==start then
32955 if head==start then
32956 head=cn
32957 end
32958 start=cn
32959 end
32960 setlink(getprev(base),cn)
32961 setlink(cn,base)
32962 cn=next
32963 else
32964 if bp then
32965 setnext(bp,cn)
32966 end
32967 local prev,next=getboth(cn)
32968 if next then
32969 setprev(next,prev)
32970 end
32971 setnext(prev,next)
32972 if cn==stop then
32973 stop=prev
32974 end
32975 setprev(cn,bp)
32976 setlink(cn,firstcons)
32977 if firstcons==start then
32978 if head==start then
32979 head=cn
32980 end
32981 start=cn
32982 end
32983 cn=next
32984 end
32985 done=true
32986 elseif current~=base and dependent_vowel[getchar(cn)] then
32987 local prev,next=getboth(cn)
32988 if next then
32989 setprev(next,prev)
32990 end
32991 setnext(prev,next)
32992 if cn==stop then
32993 stop=prev
32994 end
32995 setlink(b,cn,getnext(b))
32996 order_matras(cn)
32997 cn=next
32998 done=true
32999 elseif current==base and dependent_vowel[getchar(cn)] then
33000 local cnn=getnext(cn)
33001 order_matras(cn)
33002 cn=cnn
33003 while cn~=last and dependent_vowel[getchar(cn)] do
33004 cn=getnext(cn)
33005 end
33006 else
33007 cn=getnext(cn)
33008 end
33009 end
33010 allreordered=c==stop
33011 current=getnext(c)
33012 if done and trace_steps then
33013 logprocess("reorder one, matra")
33014 end
33015 end
33016 if reph or vattu then
33017 local current=start
33018 local cns=nil
33019 local done=false
33020 while current~=stop do
33021 local c=current
33022 local n=getnext(current)
33023 if ra[getchar(current)] and halant[getchar(n)] then
33024 c=n
33025 n=getnext(n)
33026 local b,bn=base,base
33027 while bn~=stop do
33028 local next=getnext(bn)
33029 if dependent_vowel[getchar(next)] then
33030 b=next
33031 end
33032 bn=next
33033 end
33034 if getstate(current,s_rphf) then
33035 if b~=current then
33036 if current==start then
33037 if head==start then
33038 head=n
33039 end
33040 start=n
33041 end
33042 if b==stop then
33043 stop=c
33044 end
33045 local prev=getprev(current)
33046 setlink(prev,n)
33047 local next=getnext(b)
33048 setlink(c,next)
33049 setlink(b,current)
33050 done=true
33051 end
33052 elseif cns and getnext(cns)~=current then
33053 local cp=getprev(current)
33054 local cnsn=getnext(cns)
33055 setlink(cp,n)
33056 setlink(cns,current)
33057 setlink(c,cnsn)
33058 done=true
33059 if c==stop then
33060 stop=cp
33061 break
33062 end
33063 current=getprev(n)
33064 end
33065 else
33066 local char=getchar(current)
33067 if consonant[char] then
33068 cns=current
33069 local next=getnext(cns)
33070 if halant[getchar(next)] then
33071 cns=next
33072 end
33073 if not vatucache[char] then
33074 next=getnext(cns)
33075 while dependent_vowel[getchar(next)] do
33076 cns=next
33077 next=getnext(cns)
33078 end
33079 end
33080 elseif char==c_nbsp then
33081 nbspaces=nbspaces+1
33082 cns=current
33083 local next=getnext(cns)
33084 if halant[getchar(next)] then
33085 cns=next
33086 end
33087 if not vatucache[char] then
33088 next=getnext(cns)
33089 while dependent_vowel[getchar(next)] do
33090 cns=next
33091 next=getnext(cns)
33092 end
33093 end
33094 end
33095 end
33096 current=getnext(current)
33097 end
33098 if done and trace_steps then
33099 logprocess("reorder one, handle reph and vata")
33100 end
33101 end
33102 if getchar(base)==c_nbsp then
33103 nbspaces=nbspaces-1
33104 if base==stop then
33105 stop=getprev(stop)
33106 end
33107 head=remove_node(head,base)
33108 flushnode(base)
33109 end
33110 return head,stop,nbspaces
33111 end
33112 function handlers.devanagari_reorder_matras(head,start)
33113 local current=start
33114 local startfont=getfont(start)
33115 local startattr=getprop(start,a_syllabe)
33116 while current do
33117 local char=ischar(current,startfont)
33118 local next=getnext(current)
33119 if char and getprop(current,a_syllabe)==startattr then
33120 if halant[char] then
33121 if next then
33122 local char=ischar(next,startfont)
33123 if char and zw_char[char] and getprop(next,a_syllabe)==startattr then
33124 current=next
33125 next=getnext(current)
33126 end
33127 end
33128 local startnext=getnext(start)
33129 head=remove_node(head,start)
33130 setlink(start,next)
33131 setlink(current,start)
33132 start=startnext
33133 if trace_steps then
33134 logprocess("reorder matra")
33135 end
33136 break
33137 end
33138 else
33139 break
33140 end
33141 current=next
33142 end
33143 return head,start,true
33144 end
33145 local rephbase={}
33146 function handlers.devanagari_reorder_reph(head,start)
33147 local current=getnext(start)
33148 local startnext=nil
33149 local startprev=nil
33150 local startfont=getfont(start)
33151 local startattr=getprop(start,a_syllabe)
33152 ::step_1::
33153 local char=ischar(start,startfont)
33154 local rephbase=rephbase[startfont][char]
33155 if char and after_subscript[rephbase] then
33156 goto step_5
33157 end
33158 ::step_2::
33159 if char and not after_postscript[rephbase] then
33160 while current do
33161 local char=ischar(current,startfont)
33162 if char and getprop(current,a_syllabe)==startattr then
33163 if halant[char] then
33164 if trace_steps then
33165 logprocess("reorder reph, handling halant")
33166 end
33167 local next=getnext(current)
33168 if next then
33169 local nextchar=ischar(next,startfont)
33170 if nextchar and zw_char[nextchar] and getprop(next,a_syllabe)==startattr then
33171 current=next
33172 next=getnext(current)
33173 end
33174 end
33175 startnext=getnext(start)
33176 head=remove_node(head,start)
33177 setlink(start,next)
33178 setlink(current,start)
33179 start=startnext
33180 startattr=getprop(start,a_syllabe)
33181 break
33182 end
33183 current=getnext(current)
33184 else
33185 break
33186 end
33187 end
33188 end
33189 ::step_3::
33190 if not startnext then
33191 if char and after_main[rephbase] then
33192 current=getnext(start)
33193 while current do
33194 local char=ischar(current,startfont)
33195 if char and getprop(current,a_syllabe)==startattr then
33196 if consonant[char] and not getstate(current,s_pref) then
33197 if trace_steps then
33198 logprocess("reorder reph, handling consonant")
33199 end
33200 startnext=getnext(start)
33201 head=remove_node(head,start)
33202 setlink(current,start)
33203 setlink(start,getnext(current))
33204 start=startnext
33205 startattr=getprop(start,a_syllabe)
33206 break
33207 end
33208 current=getnext(current)
33209 else
33210 break
33211 end
33212 end
33213 end
33214 end
33215 ::step_4::
33216 if not startnext then
33217 if char and before_postscript[rephbase] then
33218 current=getnext(start)
33219 local c=nil
33220 while current do
33221 local char=ischar(current,startfont)
33222 if char and getprop(current,a_syllabe)==startattr then
33223 if getstate(current,s_pstf) then
33224 if trace_steps then
33225 logprocess("reorder reph, before postscript, post base")
33226 end
33227 startnext=getnext(start)
33228 head=remove_node(head,start)
33229 setlink(getprev(current),start)
33230 setlink(start,current)
33231 start=startnext
33232 startattr=getprop(start,a_syllabe)
33233 break
33234 elseif not c and (vowel_modifier[char] or stress_tone_mark[char]) then
33235 c=current
33236 end
33237 current=getnext(current)
33238 else
33239 if c then
33240 if trace_steps then
33241 logprocess("reorder reph, before postscript")
33242 end
33243 startnext=getnext(start)
33244 head=remove_node(head,start)
33245 setlink(getprev(c),start)
33246 setlink(start,c)
33247 start=startnext
33248 startattr=getprop(start,a_syllabe)
33249 end
33250 break
33251 end
33252 end
33253 end
33254 end
33255 ::step_5::
33256 if not startnext then
33257 current=getnext(start)
33258 local c=nil
33259 while current do
33260 local char=ischar(current,startfont)
33261 if char and getprop(current,a_syllabe)==startattr then
33262 local state=getstate(current)
33263 if before_subscript[rephbase] and (state==s_blwf or state==s_pstf) then
33264 c=current
33265 if trace_steps then
33266 logprocess("reorder reph, before subscript")
33267 end
33268 elseif after_subscript[rephbase] and (state==s_pstf) then
33269 if trace_steps then
33270 logprocess("reorder reph, after subscript")
33271 end
33272 c=current
33273 end
33274 current=getnext(current)
33275 else
33276 break
33277 end
33278 end
33279 if c then
33280 startnext=getnext(start)
33281 head=remove_node(head,start)
33282 setlink(getprev(c),start)
33283 setlink(start,c)
33284 start=startnext
33285 startattr=getprop(start,a_syllabe)
33286 end
33287 end
33288 ::step_6::
33289 if not startnext then
33290 current=start
33291 local next=getnext(current)
33292 while next do
33293 local nextchar=ischar(next,startfont)
33294 if nextchar and getprop(next,a_syllabe)==startattr then
33295 current=next
33296 next=getnext(current)
33297 else
33298 break
33299 end
33300 end
33301 if start~=current then
33302 if trace_steps then
33303 logprocess("reorder reph, to end")
33304 end
33305 startnext=getnext(start)
33306 head=remove_node(head,start)
33307 setlink(start,getnext(current))
33308 setlink(current,start)
33309 start=startnext
33310 end
33311 end
33312 return head,start,true
33313 end
33314 function handlers.devanagari_reorder_pre_base_reordering_consonants(head,start)
33315 if getprop(start,a_reordered) then
33316 return head,start,true
33317 end
33318 local current=start
33319 local startfont=getfont(start)
33320 local startattr=getprop(start,a_syllabe)
33321 while current do
33322 local char=ischar(current,startfont)
33323 local next=getnext(current)
33324 if char and getprop(current,a_syllabe)==startattr then
33325 if halant[char] then
33326 if trace_steps then
33327 logprocess("reorder pre base consonants, handle halant")
33328 end
33329 if next then
33330 local char=ischar(next,startfont)
33331 if char and zw_char[char] and getprop(next,a_syllabe)==startattr then
33332 current=next
33333 next=getnext(current)
33334 end
33335 end
33336 local startnext=getnext(start)
33337 head=remove_node(head,start)
33338 setlink(start,next)
33339 setlink(current,start)
33340 setprop(start,"reordered",true)
33341 start=startnext
33342 return head,start,true
33343 end
33344 else
33345 break
33346 end
33347 current=next
33348 end
33349 local startattr=getprop(start,a_syllabe)
33350 local current=getprev(start)
33351 while current and getprop(current,a_syllabe)==startattr do
33352 local char=ischar(current)
33353 if (not dependent_vowel[char] and (not getstate(current) or getstate(current,s_init))) then
33354 if trace_steps then
33355 logprocess("reorder pre base consonants, handle vowel or initial")
33356 end
33357 startnext=getnext(start)
33358 head=remove_node(head,start)
33359 if current==head then
33360 setlink(start,current)
33361 head=start
33362 else
33363 setlink(getprev(current),start)
33364 setlink(start,current)
33365 end
33366 setprop(start,"reordered",true)
33367 start=startnext
33368 break
33369 end
33370 current=getprev(current)
33371 end
33372 return head,start,true
33373 end
33374 function handlers.devanagari_remove_joiners(head,start,kind,lookupname,replacement)
33375 local stop=getnext(start)
33376 local font=getfont(start)
33377 local last=start
33378 while stop do
33379 local char=ischar(stop,font)
33380 if char and (char==c_zwnj or char==c_zwj) then
33381 last=stop
33382 stop=getnext(stop)
33383 else
33384 break
33385 end
33386 end
33387 local prev=getprev(start)
33388 if stop then
33389 setnext(last)
33390 setlink(prev,stop)
33391 elseif prev then
33392 setnext(prev)
33393 end
33394 if head==start then
33395 head=stop
33396 end
33397 flushlist(start)
33398 if trace_steps then
33399 logprocess("remove joiners")
33400 end
33401 return head,stop,true
33402 end
33403 local function initialize_two(font,attr)
33404 local devanagari=fontdata[font].resources.devanagari
33405 if devanagari then
33406 return devanagari.seqsubset or {},devanagari.reorderreph or {}
33407 else
33408 return {},{}
33409 end
33410 end
33411 local function reorder_two(head,start,stop,font,attr,nbspaces)
33412 local seqsubset,reorderreph=initialize_two(font,attr)
33413 local halfpos=nil
33414 local basepos=nil
33415 local subpos=nil
33416 local postpos=nil
33417 reorderreph.coverage={}
33418 rephbase[font]={}
33419 for i=1,#seqsubset do
33420 local subset=seqsubset[i]
33421 local kind=subset[1]
33422 local lookupcache=subset[2]
33423 if kind=="rphf" then
33424 local reph=subset[3]
33425 local base=subset[4]
33426 reorderreph.coverage[reph]=true
33427 rephbase[font][reph]=base
33428 local current=start
33429 local last=getnext(stop)
33430 while current~=last do
33431 if current~=stop then
33432 local c=getchar(current)
33433 local found=lookupcache[c]
33434 if found then
33435 local next=getnext(current)
33436 if contextchain(found,next) then
33437 local afternext=next~=stop and getnext(next)
33438 if afternext and zw_char[getchar(afternext)] then
33439 current=afternext
33440 elseif current==start then
33441 setstate(current,s_rphf)
33442 current=next
33443 else
33444 current=next
33445 end
33446 end
33447 end
33448 end
33449 current=getnext(current)
33450 end
33451 elseif kind=="pref" then
33452 local current=start
33453 local last=getnext(stop)
33454 while current~=last do
33455 if current~=stop then
33456 local c=getchar(current)
33457 local found=lookupcache[c]
33458 if found then
33459 local next=getnext(current)
33460 if contextchain(found,next) then
33461 if not getstate(current) and not getstate(next) then
33462 setstate(current,s_pref)
33463 setstate(next,s_pref)
33464 current=next
33465 end
33466 end
33467 end
33468 end
33469 current=getnext(current)
33470 end
33471 elseif kind=="half" then
33472 local current=start
33473 local last=getnext(stop)
33474 while current~=last do
33475 if current~=stop then
33476 local c=getchar(current)
33477 local found=lookupcache[c]
33478 if found then
33479 local next=getnext(current)
33480 if contextchain(found,next) then
33481 if next~=stop and getchar(getnext(next))==c_zwnj then
33482 current=next
33483 elseif not getstate(current) then
33484 setstate(current,s_half)
33485 if not halfpos then
33486 halfpos=current
33487 end
33488 end
33489 current=getnext(current)
33490 end
33491 end
33492 end
33493 current=getnext(current)
33494 end
33495 elseif kind=="blwf" or kind=="vatu" then
33496 local current=start
33497 local last=getnext(stop)
33498 while current~=last do
33499 if current~=stop then
33500 local c=getchar(current)
33501 local found=lookupcache[c]
33502 if found then
33503 local next=getnext(current)
33504 if contextchain(found,next) then
33505 if not getstate(current) and not getstate(next) then
33506 setstate(current,s_blwf)
33507 setstate(next,s_blwf)
33508 current=next
33509 subpos=current
33510 end
33511 end
33512 end
33513 end
33514 current=getnext(current)
33515 end
33516 elseif kind=="pstf" then
33517 local current=start
33518 local last=getnext(stop)
33519 while current~=last do
33520 if current~=stop then
33521 local c=getchar(current)
33522 local found=lookupcache[c]
33523 if found then
33524 local next=getnext(current)
33525 if contextchain(found,next) then
33526 if not getstate(current) and not getstate(next) then
33527 setstate(current,s_pstf)
33528 setstate(next,s_pstf)
33529 current=next
33530 postpos=current
33531 end
33532 end
33533 end
33534 end
33535 current=getnext(current)
33536 end
33537 end
33538 end
33539 local current,base,firstcons,subnotafterbase,postnotafterbase=start,nil,nil,nil,nil
33540 if getstate(start,s_rphf) then
33541 current=getnext(getnext(start))
33542 end
33543 if current~=getnext(stop) and getchar(current)==c_nbsp then
33544 if current==stop then
33545 stop=getprev(stop)
33546 head=remove_node(head,current)
33547 flushnode(current)
33548 if trace_steps then
33549 logprocess("reorder two, remove nbsp")
33550 end
33551 return head,stop,nbspaces
33552 else
33553 nbspaces=nbspaces+1
33554 base=current
33555 current=getnext(current)
33556 if current~=stop then
33557 local char=getchar(current)
33558 if nukta[char] then
33559 current=getnext(current)
33560 char=getchar(current)
33561 end
33562 if char==c_zwj then
33563 local next=getnext(current)
33564 if current~=stop and next~=stop and halant[getchar(next)] then
33565 current=next
33566 next=getnext(current)
33567 local tmp=getnext(next)
33568 local changestop=next==stop
33569 setnext(next)
33570 setstate(current,s_pref)
33571 current=processcharacters(current,font)
33572 setstate(current,s_blwf)
33573 current=processcharacters(current,font)
33574 setstate(current,s_pstf)
33575 current=processcharacters(current,font)
33576 setstate(current,unsetvalue)
33577 if halant[getchar(current)] then
33578 setnext(getnext(current),tmp)
33579 if show_syntax_errors then
33580 head,current=inject_syntax_error(head,current,char)
33581 end
33582 else
33583 setnext(current,tmp)
33584 if changestop then
33585 stop=current
33586 end
33587 end
33588 end
33589 end
33590 end
33591 if trace_steps then
33592 logprocess("reorder two, handle nbsp")
33593 end
33594 end
33595 else
33596 local last=getnext(stop)
33597 while current~=last do
33598 local next=getnext(current)
33599 if current==subpos then
33600 subnotafterbase=current
33601 end
33602 if current==postpos then
33603 postnotafterbase=current
33604 end
33605 if consonant[getchar(current)] then
33606 if not (current~=stop and next~=stop and halant[getchar(next)] and getchar(getnext(next))==c_zwj) then
33607 if not firstcons then
33608 firstcons=current
33609 end
33610 local a=getstate(current)
33611 if not (a==s_blwf or a==s_pstf or (a~=s_rphf and a~=s_blwf and ra[getchar(current)])) then
33612 base=current
33613 if subnotafterbase then
33614 subpos=base
33615 end
33616 if postnotafterbase then
33617 postpos=base
33618 end
33619 end
33620 end
33621 end
33622 current=next
33623 end
33624 if not base then
33625 base=firstcons
33626 end
33627 end
33628 if not base then
33629 if getstate(start,s_rphf) then
33630 setstate(start,unsetvalue)
33631 end
33632 return head,stop,nbspaces
33633 else
33634 if getstate(base) then
33635 setstate(base,unsetvalue)
33636 end
33637 basepos=base
33638 end
33639 if not halfpos then
33640 halfpos=base
33641 end
33642 if not subpos then
33643 subpos=base
33644 end
33645 if not postpos then
33646 postpos=subpos or base
33647 end
33648 local moved={}
33649 local current=start
33650 local last=getnext(stop)
33651 while current~=last do
33652 local char=getchar(current)
33653 local target=nil
33654 local cn=getnext(current)
33655 local tpm=twopart_mark[char]
33656 if tpm then
33657 while tpm do
33658 local extra=copy_node(current)
33659 copyinjection(extra,current)
33660 char=tpm[1]
33661 setchar(current,char)
33662 setchar(extra,tpm[2])
33663 head=insertnodeafter(head,current,extra)
33664 tpm=twopart_mark[char]
33665 end
33666 if tpm and trace_steps then
33667 logprocess("reorder two, handle matra")
33668 end
33669 end
33670 if not moved[current] and dependent_vowel[char] then
33671 if pre_mark[char] then
33672 moved[current]=true
33673 local prev,next=getboth(current)
33674 setlink(prev,next)
33675 if current==stop then
33676 stop=getprev(current)
33677 end
33678 local pos
33679 if before_main[char] then
33680 pos=basepos
33681 else
33682 pos=halfpos
33683 end
33684 local ppos=getprev(pos)
33685 while ppos and getprop(ppos,a_syllabe)==getprop(pos,a_syllabe) do
33686 if getstate(ppos,s_pref) then
33687 pos=ppos
33688 end
33689 ppos=getprev(ppos)
33690 end
33691 local ppos=getprev(pos)
33692 while ppos and getprop(ppos,a_syllabe)==getprop(pos,a_syllabe) and halant[ischar(ppos)] do
33693 ppos=getprev(ppos)
33694 if ppos and getprop(ppos,a_syllabe)==getprop(pos,a_syllabe) and consonant[ischar(ppos)] then
33695 pos=ppos
33696 ppos=getprev(ppos)
33697 else
33698 break
33699 end
33700 end
33701 if pos==start then
33702 if head==start then
33703 head=current
33704 end
33705 start=current
33706 end
33707 setlink(getprev(pos),current)
33708 setlink(current,pos)
33709 if trace_steps then
33710 logprocess("reorder two, handle pre mark")
33711 end
33712 elseif above_mark[char] then
33713 target=subpos
33714 if postpos==subpos then
33715 postpos=current
33716 end
33717 subpos=current
33718 elseif below_mark[char] then
33719 target=subpos
33720 if postpos==subpos then
33721 postpos=current
33722 end
33723 subpos=current
33724 elseif post_mark[char] then
33725 local n=getnext(postpos)
33726 while n do
33727 local v=ischar(n,font)
33728 if nukta[v] or stress_tone_mark[v] or vowel_modifier[v] then
33729 postpos=n
33730 else
33731 break
33732 end
33733 n=getnext(n)
33734 end
33735 target=postpos
33736 postpos=current
33737 end
33738 if mark_above_below_post[char] then
33739 local prev=getprev(current)
33740 if prev~=target then
33741 local next=getnext(current)
33742 setlink(prev,next)
33743 if current==stop then
33744 stop=prev
33745 end
33746 setlink(current,getnext(target))
33747 setlink(target,current)
33748 if trace_steps then
33749 logprocess("reorder two, handle mark")
33750 end
33751 end
33752 end
33753 end
33754 current=cn
33755 end
33756 local current=getnext(start)
33757 local last=getnext(stop)
33758 while current~=last do
33759 local char=getchar(current)
33760 local cn=getnext(current)
33761 if halant[char] and ra[ischar(cn)] and (not getstate(cn,s_rphf)) and (not getstate(cn,s_blwf)) then
33762 if after_main[ischar(cn)] then
33763 local prev=getprev(current)
33764 local next=getnext(cn)
33765 local bpn=getnext(basepos)
33766 while bpn and dependent_vowel[ischar(bpn)] do
33767 basepos=bpn
33768 bpn=getnext(bpn)
33769 end
33770 if basepos~=prev then
33771 setlink(prev,next)
33772 setlink(cn,getnext(basepos))
33773 setlink(basepos,current)
33774 if cn==stop then
33775 stop=prev
33776 end
33777 cn=next
33778 if trace_steps then
33779 logprocess("reorder two, handle halant and ra")
33780 end
33781 end
33782 end
33783 end
33784 current=cn
33785 end
33786 local current=start
33787 local c=nil
33788 while current~=stop do
33789 local char=getchar(current)
33790 if halant[char] or stress_tone_mark[char] then
33791 if not c then
33792 c=current
33793 end
33794 else
33795 c=nil
33796 end
33797 local next=getnext(current)
33798 if c and nukta[getchar(next)] then
33799 if head==c then
33800 head=next
33801 end
33802 if stop==next then
33803 stop=current
33804 end
33805 setlink(getprev(c),next)
33806 local nextnext=getnext(next)
33807 setnext(current,nextnext)
33808 local nextnextnext=getnext(nextnext)
33809 if nextnextnext then
33810 setprev(nextnextnext,current)
33811 end
33812 setlink(nextnext,c)
33813 if trace_steps then
33814 logprocess("reorder two, handle nukta")
33815 end
33816 end
33817 if stop==current then break end
33818 current=getnext(current)
33819 end
33820 if getchar(base)==c_nbsp then
33821 if base==stop then
33822 stop=getprev(stop)
33823 end
33824 nbspaces=nbspaces-1
33825 head=remove_node(head,base)
33826 flushnode(base)
33827 if trace_steps then
33828 logprocess("reorder two, handle nbsp")
33829 end
33830 end
33831 return head,stop,nbspaces
33832 end
33833 local separator={}
33834 imerge(separator,consonant)
33835 imerge(separator,independent_vowel)
33836 imerge(separator,dependent_vowel)
33837 imerge(separator,vowel_modifier)
33838 imerge(separator,stress_tone_mark)
33839 for k,v in next,nukta do separator[k]=true end
33840 for k,v in next,halant do separator[k]=true end
33841 local function analyze_next_chars_one(c,font,variant)
33842 local n=getnext(c)
33843 if not n then
33844 return c
33845 end
33846 local v=ischar(n,font)
33847 if variant==1 then
33848 if v and nukta[v] then
33849 n=getnext(n)
33850 if n then
33851 v=ischar(n,font)
33852 end
33853 end
33854 if n and v then
33855 local nn=getnext(n)
33856 if nn then
33857 local vv=ischar(nn,font)
33858 if vv then
33859 local nnn=getnext(nn)
33860 if nnn then
33861 local vvv=ischar(nnn,font)
33862 if vvv then
33863 if vv==c_zwj and consonant[vvv] then
33864 c=nnn
33865 elseif (vv==c_zwnj or vv==c_zwj) and halant[vvv] then
33866 local nnnn=getnext(nnn)
33867 if nnnn then
33868 local vvvv=ischar(nnnn,font)
33869 if vvvv and consonant[vvvv] then
33870 c=nnnn
33871 end
33872 end
33873 end
33874 end
33875 end
33876 end
33877 end
33878 end
33879 elseif variant==2 then
33880 if v and nukta[v] then
33881 c=n
33882 end
33883 n=getnext(c)
33884 if n then
33885 v=ischar(n,font)
33886 if v then
33887 local nn=getnext(n)
33888 if nn then
33889 local vv=ischar(nn,font)
33890 if vv and zw_char[v] then
33891 n=nn
33892 v=vv
33893 nn=getnext(nn)
33894 vv=nn and ischar(nn,font)
33895 end
33896 if vv and halant[v] and consonant[vv] then
33897 c=nn
33898 end
33899 end
33900 end
33901 end
33902 end
33903 n=getnext(c)
33904 if not n then
33905 return c
33906 end
33907 v=ischar(n,font)
33908 if not v then
33909 return c
33910 end
33911 local already_pre_mark
33912 local already_above_mark
33913 local already_below_mark
33914 local already_post_mark
33915 while dependent_vowel[v] do
33916 local vowels=twopart_mark[v]
33917 if vowels then
33918 for k=1,#vowels do
33919 local v=vowels[k]
33920 if pre_mark[v] and not already_pre_mark then
33921 already_pre_mark=true
33922 elseif above_mark[v] and not already_above_mark then
33923 already_above_mark=true
33924 elseif below_mark[v] and not already_below_mark then
33925 already_below_mark=true
33926 elseif post_mark[v] and not already_post_mark then
33927 already_post_mark=true
33928 elseif devanagarihash[font].conjuncts=="continue" then
33929 else
33930 return c
33931 end
33932 end
33933 else
33934 if pre_mark[v] and not already_pre_mark then
33935 already_pre_mark=true
33936 elseif post_mark[v] and not already_post_mark then
33937 already_post_mark=true
33938 elseif below_mark[v] and not already_below_mark then
33939 already_below_mark=true
33940 elseif above_mark[v] and not already_above_mark then
33941 already_above_mark=true
33942 elseif devanagarihash[font].conjuncts=="continue" then
33943 else
33944 return c
33945 end
33946 end
33947 c=n
33948 n=getnext(c)
33949 if not n then
33950 return c
33951 end
33952 v=ischar(n,font)
33953 if not v then
33954 return c
33955 end
33956 end
33957 if nukta[v] then
33958 c=n
33959 n=getnext(c)
33960 if not n then
33961 return c
33962 end
33963 v=ischar(n,font)
33964 if not v then
33965 return c
33966 end
33967 end
33968 if halant[v] then
33969 c=n
33970 n=getnext(c)
33971 if not n then
33972 return c
33973 end
33974 v=ischar(n,font)
33975 if not v then
33976 return c
33977 end
33978 end
33979 if vowel_modifier[v] then
33980 c=n
33981 n=getnext(c)
33982 if not n then
33983 return c
33984 end
33985 v=ischar(n,font)
33986 if not v then
33987 return c
33988 end
33989 end
33990 if stress_tone_mark[v] then
33991 c=n
33992 n=getnext(c)
33993 if not n then
33994 return c
33995 end
33996 v=ischar(n,font)
33997 if not v then
33998 return c
33999 end
34000 end
34001 if stress_tone_mark[v] then
34002 return n
34003 else
34004 return c
34005 end
34006 end
34007 local function analyze_next_chars_two(c,font)
34008 local n=getnext(c)
34009 if not n then
34010 return c
34011 end
34012 local v=ischar(n,font)
34013 if v and nukta[v] then
34014 c=n
34015 end
34016 n=c
34017 while true do
34018 local nn=getnext(n)
34019 if nn then
34020 local vv=ischar(nn,font)
34021 if vv then
34022 if halant[vv] then
34023 n=nn
34024 local nnn=getnext(nn)
34025 if nnn then
34026 local vvv=ischar(nnn,font)
34027 if vvv and zw_char[vvv] then
34028 n=nnn
34029 end
34030 end
34031 elseif vv==c_zwnj or vv==c_zwj then
34032 local nnn=getnext(nn)
34033 if nnn then
34034 local vvv=ischar(nnn,font)
34035 if vvv and halant[vvv] then
34036 n=nnn
34037 end
34038 end
34039 else
34040 break
34041 end
34042 local nn=getnext(n)
34043 if nn then
34044 local vv=ischar(nn,font)
34045 if vv and consonant[vv] then
34046 n=nn
34047 local nnn=getnext(nn)
34048 if nnn then
34049 local vvv=ischar(nnn,font)
34050 if vvv and nukta[vvv] then
34051 n=nnn
34052 end
34053 end
34054 c=n
34055 else
34056 break
34057 end
34058 else
34059 break
34060 end
34061 else
34062 break
34063 end
34064 else
34065 break
34066 end
34067 end
34068 if not c then
34069 return
34070 end
34071 n=getnext(c)
34072 if not n then
34073 return c
34074 end
34075 v=ischar(n,font)
34076 if not v then
34077 return c
34078 end
34079 if anudatta[v] then
34080 c=n
34081 n=getnext(c)
34082 if not n then
34083 return c
34084 end
34085 v=ischar(n,font)
34086 if not v then
34087 return c
34088 end
34089 end
34090 if halant[v] then
34091 c=n
34092 n=getnext(c)
34093 if not n then
34094 return c
34095 end
34096 v=ischar(n,font)
34097 if not v then
34098 return c
34099 end
34100 if v==c_zwnj or v==c_zwj then
34101 c=n
34102 n=getnext(c)
34103 if not n then
34104 return c
34105 end
34106 v=ischar(n,font)
34107 if not v then
34108 return c
34109 end
34110 end
34111 else
34112 local already_pre_mark
34113 local already_above_mark
34114 local already_below_mark
34115 local already_post_mark
34116 while dependent_vowel[v] do
34117 local vowels=twopart_mark[v]
34118 if vowels then
34119 for k=1,#vowels do
34120 local v=vowels[k]
34121 if pre_mark[v] and not already_pre_mark then
34122 already_pre_mark=true
34123 elseif above_mark[v] and not already_above_mark then
34124 already_above_mark=true
34125 elseif below_mark[v] and not already_below_mark then
34126 already_below_mark=true
34127 elseif post_mark[v] and not already_post_mark then
34128 already_post_mark=true
34129 elseif devanagarihash[font].conjuncts=="continue" then
34130 else
34131 return c
34132 end
34133 end
34134 else
34135 if pre_mark[v] and not already_pre_mark then
34136 already_pre_mark=true
34137 elseif post_mark[v] and not already_post_mark then
34138 already_post_mark=true
34139 elseif below_mark[v] and not already_below_mark then
34140 already_below_mark=true
34141 elseif above_mark[v] and not already_above_mark then
34142 already_above_mark=true
34143 elseif devanagarihash[font].conjuncts=="continue" then
34144 else
34145 return c
34146 end
34147 end
34148 c=n
34149 n=getnext(c)
34150 if not n then
34151 return c
34152 end
34153 v=ischar(n,font)
34154 if not v then
34155 return c
34156 end
34157 end
34158 if nukta[v] then
34159 c=n
34160 n=getnext(c)
34161 if not n then
34162 return c
34163 end
34164 v=ischar(n,font)
34165 if not v then
34166 return c
34167 end
34168 end
34169 if halant[v] then
34170 c=n
34171 n=getnext(c)
34172 if not n then
34173 return c
34174 end
34175 v=ischar(n,font)
34176 if not v then
34177 return c
34178 end
34179 end
34180 end
34181 if vowel_modifier[v] then
34182 c=n
34183 n=getnext(c)
34184 if not n then
34185 return c
34186 end
34187 v=ischar(n,font)
34188 if not v then
34189 return c
34190 end
34191 end
34192 if stress_tone_mark[v] then
34193 c=n
34194 n=getnext(c)
34195 if not n then
34196 return c
34197 end
34198 v=ischar(n,font)
34199 if not v then
34200 return c
34201 end
34202 end
34203 if stress_tone_mark[v] then
34204 return n
34205 else
34206 return c
34207 end
34208 end
34209 local function method_one(head,font,attr)
34210 local current=head
34211 local start=true
34212 local done=false
34213 local nbspaces=0
34214 local syllabe=0
34215 while current do
34216 local char=ischar(current,font)
34217 if char then
34218 done=true
34219 local syllablestart=current
34220 local syllableend=nil
34221 local c=current
34222 local n=getnext(c)
34223 local first=char
34224 if n and ra[first] then
34225 local second=ischar(n,font)
34226 if second and halant[second] then
34227 local n=getnext(n)
34228 if n then
34229 local third=ischar(n,font)
34230 if third then
34231 c=n
34232 first=third
34233 end
34234 end
34235 end
34236 end
34237 local standalone=first==c_nbsp
34238 if standalone then
34239 local prev=getprev(current)
34240 if prev then
34241 local prevchar=ischar(prev,font)
34242 if not prevchar then
34243 elseif not separator[prevchar] then
34244 else
34245 standalone=false
34246 end
34247 else
34248 end
34249 end
34250 if standalone then
34251 local syllableend=analyze_next_chars_one(c,font,2)
34252 current=getnext(syllableend)
34253 if syllablestart~=syllableend then
34254 head,current,nbspaces=reorder_one(head,syllablestart,syllableend,font,attr,nbspaces)
34255 current=getnext(current)
34256 end
34257 else
34258 if consonant[char] then
34259 local prevc=true
34260 while prevc do
34261 prevc=false
34262 local n=getnext(current)
34263 if not n then
34264 break
34265 end
34266 local v=ischar(n,font)
34267 if not v then
34268 break
34269 end
34270 if nukta[v] then
34271 n=getnext(n)
34272 if not n then
34273 break
34274 end
34275 v=ischar(n,font)
34276 if not v then
34277 break
34278 end
34279 end
34280 if halant[v] then
34281 n=getnext(n)
34282 if not n then
34283 break
34284 end
34285 v=ischar(n,font)
34286 if not v then
34287 break
34288 end
34289 if v==c_zwnj or v==c_zwj then
34290 n=getnext(n)
34291 if not n then
34292 break
34293 end
34294 v=ischar(n,font)
34295 if not v then
34296 break
34297 end
34298 end
34299 if consonant[v] then
34300 prevc=true
34301 current=n
34302 end
34303 end
34304 end
34305 local n=getnext(current)
34306 if n then
34307 local v=ischar(n,font)
34308 if v and nukta[v] then
34309 current=n
34310 n=getnext(current)
34311 end
34312 end
34313 syllableend=current
34314 current=n
34315 if current then
34316 local v=ischar(current,font)
34317 if not v then
34318 elseif halant[v] then
34319 local n=getnext(current)
34320 if n then
34321 local v=ischar(n,font)
34322 if v and zw_char[v] then
34323 syllableend=n
34324 current=getnext(n)
34325 else
34326 syllableend=current
34327 current=n
34328 end
34329 else
34330 syllableend=current
34331 current=n
34332 end
34333 else
34334 if dependent_vowel[v] then
34335 syllableend=current
34336 current=getnext(current)
34337 v=ischar(current,font)
34338 end
34339 if v and vowel_modifier[v] then
34340 syllableend=current
34341 current=getnext(current)
34342 v=ischar(current,font)
34343 end
34344 if v and stress_tone_mark[v] then
34345 syllableend=current
34346 current=getnext(current)
34347 end
34348 end
34349 end
34350 if syllablestart~=syllableend then
34351 if syllableend then
34352 syllabe=syllabe+1
34353 local c=syllablestart
34354 local n=getnext(syllableend)
34355 while c~=n do
34356 setprop(c,a_syllabe,syllabe)
34357 c=getnext(c)
34358 end
34359 end
34360 head,current,nbspaces=reorder_one(head,syllablestart,syllableend,font,attr,nbspaces)
34361 current=getnext(current)
34362 end
34363 elseif independent_vowel[char] then
34364 syllableend=current
34365 current=getnext(current)
34366 if current then
34367 local v=ischar(current,font)
34368 if v then
34369 if vowel_modifier[v] then
34370 syllableend=current
34371 current=getnext(current)
34372 v=ischar(current,font)
34373 end
34374 if v and stress_tone_mark[v] then
34375 syllableend=current
34376 current=getnext(current)
34377 end
34378 end
34379 end
34380 else
34381 if show_syntax_errors then
34382 local mark=mark_pre_above_below_post[char]
34383 if mark then
34384 head,current=inject_syntax_error(head,current,char)
34385 end
34386 end
34387 current=getnext(current)
34388 end
34389 end
34390 else
34391 current=getnext(current)
34392 end
34393 start=false
34394 end
34395 if nbspaces>0 then
34396 head=replace_all_nbsp(head)
34397 end
34398 current=head
34399 local n=0
34400 while current do
34401 local char=ischar(current,font)
34402 if char then
34403 if n==0 and not getstate(current) then
34404 setstate(current,s_init)
34405 end
34406 n=n+1
34407 else
34408 n=0
34409 end
34410 current=getnext(current)
34411 end
34412 return head,done
34413 end
34414 local function method_two(head,font,attr)
34415 local current=head
34416 local start=true
34417 local done=false
34418 local syllabe=0
34419 local nbspaces=0
34420 while current do
34421 local syllablestart=nil
34422 local syllableend=nil
34423 local char=ischar(current,font)
34424 if char then
34425 done=true
34426 syllablestart=current
34427 local c=current
34428 local n=getnext(current)
34429 if n and ra[char] then
34430 local nextchar=ischar(n,font)
34431 if nextchar and halant[nextchar] then
34432 local n=getnext(n)
34433 if n then
34434 local nextnextchar=ischar(n,font)
34435 if nextnextchar then
34436 c=n
34437 char=nextnextchar
34438 end
34439 end
34440 end
34441 end
34442 if independent_vowel[char] then
34443 current=analyze_next_chars_one(c,font,1)
34444 syllableend=current
34445 else
34446 local standalone=char==c_nbsp
34447 if standalone then
34448 nbspaces=nbspaces+1
34449 local p=getprev(current)
34450 if not p then
34451 elseif ischar(p,font) then
34452 elseif not separator[getchar(p)] then
34453 else
34454 standalone=false
34455 end
34456 end
34457 if standalone then
34458 current=analyze_next_chars_one(c,font,2)
34459 syllableend=current
34460 elseif consonant[getchar(current)] then
34461 current=analyze_next_chars_two(current,font)
34462 syllableend=current
34463 end
34464 end
34465 end
34466 if syllableend then
34467 syllabe=syllabe+1
34468 local c=syllablestart
34469 local n=getnext(syllableend)
34470 while c~=n do
34471 setprop(c,a_syllabe,syllabe)
34472 c=getnext(c)
34473 end
34474 end
34475 if syllableend and syllablestart~=syllableend then
34476 head,current,nbspaces=reorder_two(head,syllablestart,syllableend,font,attr,nbspaces)
34477 end
34478 if not syllableend and show_syntax_errors then
34479 local char=ischar(current,font)
34480 if char and not getstate(current) then
34481 local mark=mark_pre_above_below_post[char]
34482 if mark then
34483 head,current=inject_syntax_error(head,current,char)
34484 end
34485 end
34486 end
34487 start=false
34488 current=getnext(current)
34489 end
34490 if nbspaces>0 then
34491 head=replace_all_nbsp(head)
34492 end
34493 current=head
34494 local n=0
34495 while current do
34496 local char=ischar(current,font)
34497 if char then
34498 if n==0 and not getstate(current) then
34499 setstate(current,s_init)
34500 end
34501 n=n+1
34502 else
34503 n=0
34504 end
34505 current=getnext(current)
34506 end
34507 return head,done
34508 end
34509 for i=1,nofscripts do
34510 methods[scripts_one[i]]=method_one
34511 methods[scripts_two[i]]=method_two
34512 end
34513
34514 end -- closure
34515
34516 do -- begin closure to overcome local limits and interference
34517
34518 if not modules then modules={} end modules ['font-ocl']={
34519 version=1.001,
34520 comment="companion to font-ini.mkiv",
34521 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
34522 copyright="PRAGMA ADE / ConTeXt Development Team",
34523 license="see context related readme files"
34524 }
34525 local tostring,tonumber,next=tostring,tonumber,next
34526 local round,max=math.round,math.round
34527 local gsub,find=string.gsub,string.find
34528 local sortedkeys,sortedhash,concat=table.sortedkeys,table.sortedhash,table.concat
34529 local setmetatableindex=table.setmetatableindex
34530 local formatters=string.formatters
34531 local tounicode=fonts.mappings.tounicode
34532 local helpers=fonts.helpers
34533 local charcommand=helpers.commands.char
34534 local rightcommand=helpers.commands.right
34535 local leftcommand=helpers.commands.left
34536 local downcommand=helpers.commands.down
34537 local otf=fonts.handlers.otf
34538 local otfregister=otf.features.register
34539 local f_color=formatters["%.3f %.3f %.3f rg"]
34540 local f_gray=formatters["%.3f g"]
34541 if context then
34542
34543 --removed
34544
34545 else
34546 local tounicode=fonts.mappings.tounicode16
34547 function otf.getactualtext(s)
34548 return
34549 "/Span << /ActualText <feff"..s.."> >> BDC",
34550 "EMC"
34551 end
34552 end
34553 local sharedpalettes={}
34554 local hash=setmetatableindex(function(t,k)
34555 local v={ "pdf","direct",k }
34556 t[k]=v
34557 return v
34558 end)
34559 if context then
34560
34561 --removed
34562
34563 else
34564 function otf.registerpalette(name,values)
34565 sharedpalettes[name]=values
34566 for i=1,#values do
34567 local v=values[i]
34568 if v then
34569 values[i]=hash[f_color(
34570 max(round((v.r or 0)*255),255)/255,
34571 max(round((v.g or 0)*255),255)/255,
34572 max(round((v.b or 0)*255),255)/255
34573 )]
34574 end
34575 end
34576 end
34577 end
34578 local function convert(t,k)
34579 local v={}
34580 for i=1,#k do
34581 local p=k[i]
34582 local r,g,b=p[1],p[2],p[3]
34583 if r==g and g==b then
34584 v[i]=hash[f_gray(r/255)]
34585 else
34586 v[i]=hash[f_color(r/255,g/255,b/255)]
34587 end
34588 end
34589 t[k]=v
34590 return v
34591 end
34592 local mode={ "pdf","mode","font" }
34593 local push={ "pdf","page","q" }
34594 local pop={ "pdf","page","Q" }
34595 local function initializeoverlay(tfmdata,kind,value)
34596 if value then
34597 local resources=tfmdata.resources
34598 local palettes=resources.colorpalettes
34599 if palettes then
34600 local converted=resources.converted
34601 if not converted then
34602 converted=setmetatableindex(convert)
34603 resources.converted=converted
34604 end
34605 local colorvalues=sharedpalettes[value]
34606 local default=false
34607 if colorvalues then
34608 default=colorvalues[#colorvalues]
34609 else
34610 colorvalues=converted[palettes[tonumber(value) or 1] or palettes[1]] or {}
34611 end
34612 local classes=#colorvalues
34613 if classes==0 then
34614 return
34615 end
34616 local characters=tfmdata.characters
34617 local descriptions=tfmdata.descriptions
34618 local properties=tfmdata.properties
34619 properties.virtualized=true
34620 tfmdata.fonts={
34621 { id=0 }
34622 }
34623 local getactualtext=otf.getactualtext
34624 local b,e=getactualtext(tounicode(0xFFFD))
34625 local actualb={ "pdf","page",b }
34626 local actuale={ "pdf","page",e }
34627 for unicode,character in next,characters do
34628 local description=descriptions[unicode]
34629 if description then
34630 local colorlist=description.colors
34631 if colorlist then
34632 local u=description.unicode or characters[unicode].unicode
34633 local w=character.width or 0
34634 local s=#colorlist
34635 local goback=w~=0 and leftcommand[w] or nil
34636 local t={
34637 mode,
34638 not u and actualb or { "pdf","page",(getactualtext(tounicode(u))) },
34639 push,
34640 }
34641 local n=3
34642 local l=nil
34643 for i=1,s do
34644 local entry=colorlist[i]
34645 local v=colorvalues[entry.class] or default
34646 if v and l~=v then
34647 n=n+1 t[n]=v
34648 l=v
34649 end
34650 n=n+1 t[n]=charcommand[entry.slot]
34651 if s>1 and i<s and goback then
34652 n=n+1 t[n]=goback
34653 end
34654 end
34655 n=n+1 t[n]=pop
34656 n=n+1 t[n]=actuale
34657 character.commands=t
34658 end
34659 end
34660 end
34661 return true
34662 end
34663 end
34664 end
34665 otfregister {
34666 name="colr",
34667 description="color glyphs",
34668 manipulators={
34669 base=initializeoverlay,
34670 node=initializeoverlay,
34671 }
34672 }
34673 do
34674 local nofstreams=0
34675 local f_name=formatters[ [[pdf-glyph-%05i]] ]
34676 local f_used=context and formatters[ [[original:///%s]] ] or formatters[ [[%s]] ]
34677 local hashed={}
34678 local cache={}
34679 local openpdf=pdfe.new
34680 function otf.storepdfdata(pdf)
34681 local done=hashed[pdf]
34682 if not done then
34683 nofstreams=nofstreams+1
34684 local f=f_name(nofstreams)
34685 local n=openpdf(pdf,#pdf,f)
34686 done=f_used(n)
34687 hashed[pdf]=done
34688 end
34689 return done
34690 end
34691 end
34692 local function pdftovirtual(tfmdata,pdfshapes,kind)
34693 if not tfmdata or not pdfshapes or not kind then
34694 return
34695 end
34696 local characters=tfmdata.characters
34697 local properties=tfmdata.properties
34698 local parameters=tfmdata.parameters
34699 local hfactor=parameters.hfactor
34700 properties.virtualized=true
34701 tfmdata.fonts={
34702 { id=0 }
34703 }
34704 local getactualtext=otf.getactualtext
34705 local storepdfdata=otf.storepdfdata
34706 local b,e=getactualtext(tounicode(0xFFFD))
34707 local actualb={ "pdf","page",b }
34708 local actuale={ "pdf","page",e }
34709 local vfimage=lpdf and lpdf.vfimage or function(wd,ht,dp,data,name)
34710 local name=storepdfdata(data)
34711 return { "image",{ filename=name,width=wd,height=ht,depth=dp } }
34712 end
34713 for unicode,character in sortedhash(characters) do
34714 local index=character.index
34715 if index then
34716 local pdf=pdfshapes[index]
34717 local typ=type(pdf)
34718 local data=nil
34719 local dx=nil
34720 local dy=nil
34721 local scale=1
34722 if typ=="table" then
34723 data=pdf.data
34724 dx=pdf.x or pdf.dx or 0
34725 dy=pdf.y or pdf.dy or 0
34726 scale=pdf.scale or 1
34727 elseif typ=="string" then
34728 data=pdf
34729 dx=0
34730 dy=0
34731 elseif typ=="number" then
34732 data=pdf
34733 dx=0
34734 dy=0
34735 end
34736 if data then
34737 local bt=unicode and getactualtext(unicode)
34738 local wd=character.width or 0
34739 local ht=character.height or 0
34740 local dp=character.depth or 0
34741 character.commands={
34742 not unicode and actualb or { "pdf","page",(getactualtext(unicode)) },
34743 downcommand [dp+dy*hfactor],
34744 rightcommand[ dx*hfactor],
34745 vfimage(scale*wd,ht,dp,data,pdfshapes.filename or ""),
34746 actuale,
34747 }
34748 character[kind]=true
34749 end
34750 end
34751 end
34752 end
34753 local otfsvg=otf.svg or {}
34754 otf.svg=otfsvg
34755 otf.svgenabled=true
34756 do
34757 local report_svg=logs.reporter("fonts","svg conversion")
34758 local loaddata=io.loaddata
34759 local savedata=io.savedata
34760 local remove=os.remove
34761 if context then
34762
34763 --removed
34764
34765 else
34766 function otfsvg.filterglyph(entry,index)
34767 return entry.data
34768 end
34769 end
34770 local runner=sandbox and sandbox.registerrunner {
34771 name="otfsvg",
34772 program="inkscape",
34773 method="pipeto",
34774 template="--export-area-drawing --shell > temp-otf-svg-shape.log",
34775 reporter=report_svg,
34776 }
34777 if not runner then
34778 runner=function()
34779 return io.popen("inkscape --export-area-drawing --shell > temp-otf-svg-shape.log","w")
34780 end
34781 end
34782 local new=nil
34783 local function inkscapeformat(suffix)
34784 if new==nil then
34785 new=os.resultof("inkscape --version") or ""
34786 new=new=="" or not find(new,"Inkscape%s*0")
34787 end
34788 return new and "filename" or suffix
34789 end
34790 function otfsvg.topdf(svgshapes,tfmdata)
34791 local pdfshapes={}
34792 local inkscape=runner()
34793 if inkscape then
34794 local descriptions=tfmdata.descriptions
34795 local nofshapes=#svgshapes
34796 local s_format=inkscapeformat("pdf")
34797 local f_svgfile=formatters["temp-otf-svg-shape-%i.svg"]
34798 local f_pdffile=formatters["temp-otf-svg-shape-%i.pdf"]
34799 local f_convert=formatters[new and "file-open:%s; export-%s:%s; export-do\n" or "%s --export-%s=%s\n"]
34800 local filterglyph=otfsvg.filterglyph
34801 local nofdone=0
34802 local processed={}
34803 report_svg("processing %i svg containers",nofshapes)
34804 statistics.starttiming()
34805 for i=1,nofshapes do
34806 local entry=svgshapes[i]
34807 for index=entry.first,entry.last do
34808 local data=filterglyph(entry,index)
34809 if data and data~="" then
34810 local svgfile=f_svgfile(index)
34811 local pdffile=f_pdffile(index)
34812 savedata(svgfile,data)
34813 inkscape:write(f_convert(svgfile,s_format,pdffile))
34814 processed[index]=true
34815 nofdone=nofdone+1
34816 if nofdone%25==0 then
34817 report_svg("%i shapes submitted",nofdone)
34818 end
34819 end
34820 end
34821 end
34822 if nofdone%25~=0 then
34823 report_svg("%i shapes submitted",nofdone)
34824 end
34825 report_svg("processing can be going on for a while")
34826 inkscape:write("quit\n")
34827 inkscape:close()
34828 report_svg("processing %i pdf results",nofshapes)
34829 for index in next,processed do
34830 local svgfile=f_svgfile(index)
34831 local pdffile=f_pdffile(index)
34832 local pdfdata=loaddata(pdffile)
34833 if pdfdata and pdfdata~="" then
34834 pdfshapes[index]={
34835 data=pdfdata,
34836 }
34837 end
34838 remove(svgfile)
34839 remove(pdffile)
34840 end
34841 local characters=tfmdata.characters
34842 for k,v in next,characters do
34843 local d=descriptions[k]
34844 local i=d.index
34845 if i then
34846 local p=pdfshapes[i]
34847 if p then
34848 local w=d.width
34849 local l=d.boundingbox[1]
34850 local r=d.boundingbox[3]
34851 p.scale=(r-l)/w
34852 p.x=l
34853 end
34854 end
34855 end
34856 if not next(pdfshapes) then
34857 report_svg("there are no converted shapes, fix your setup")
34858 end
34859 statistics.stoptiming()
34860 if statistics.elapsedseconds then
34861 report_svg("svg conversion time %s",statistics.elapsedseconds() or "-")
34862 end
34863 end
34864 return pdfshapes
34865 end
34866 end
34867 local function initializesvg(tfmdata,kind,value)
34868 if value and otf.svgenabled then
34869 local svg=tfmdata.properties.svg
34870 local hash=svg and svg.hash
34871 local timestamp=svg and svg.timestamp
34872 if not hash then
34873 return
34874 end
34875 local pdffile=containers.read(otf.pdfcache,hash)
34876 local pdfshapes=pdffile and pdffile.pdfshapes
34877 if not pdfshapes or pdffile.timestamp~=timestamp or not next(pdfshapes) then
34878 local svgfile=containers.read(otf.svgcache,hash)
34879 local svgshapes=svgfile and svgfile.svgshapes
34880 pdfshapes=svgshapes and otfsvg.topdf(svgshapes,tfmdata,otf.pdfcache.writable,hash) or {}
34881 containers.write(otf.pdfcache,hash,{
34882 pdfshapes=pdfshapes,
34883 timestamp=timestamp,
34884 })
34885 end
34886 pdftovirtual(tfmdata,pdfshapes,"svg")
34887 return true
34888 end
34889 end
34890 otfregister {
34891 name="svg",
34892 description="svg glyphs",
34893 manipulators={
34894 base=initializesvg,
34895 node=initializesvg,
34896 }
34897 }
34898 local otfpng=otf.png or {}
34899 otf.png=otfpng
34900 otf.pngenabled=true
34901 do
34902 local report_png=logs.reporter("fonts","png conversion")
34903 local loaddata=io.loaddata
34904 local savedata=io.savedata
34905 local remove=os.remove
34906 local runner=sandbox and sandbox.registerrunner {
34907 name="otfpng",
34908 program="gm",
34909 template="convert -quality 100 temp-otf-png-shape.png temp-otf-png-shape.pdf > temp-otf-svg-shape.log",
34910 }
34911 if not runner then
34912 runner=function()
34913 return os.execute("gm convert -quality 100 temp-otf-png-shape.png temp-otf-png-shape.pdf > temp-otf-svg-shape.log")
34914 end
34915 end
34916 function otfpng.topdf(pngshapes)
34917 local pdfshapes={}
34918 local pngfile="temp-otf-png-shape.png"
34919 local pdffile="temp-otf-png-shape.pdf"
34920 local nofdone=0
34921 local indices=sortedkeys(pngshapes)
34922 local nofindices=#indices
34923 report_png("processing %i png containers",nofindices)
34924 statistics.starttiming()
34925 for i=1,nofindices do
34926 local index=indices[i]
34927 local entry=pngshapes[index]
34928 local data=entry.data
34929 local x=entry.x
34930 local y=entry.y
34931 savedata(pngfile,data)
34932 runner()
34933 pdfshapes[index]={
34934 x=x~=0 and x or nil,
34935 y=y~=0 and y or nil,
34936 data=loaddata(pdffile),
34937 }
34938 nofdone=nofdone+1
34939 if nofdone%100==0 then
34940 report_png("%i shapes processed",nofdone)
34941 end
34942 end
34943 report_png("processing %i pdf results",nofindices)
34944 remove(pngfile)
34945 remove(pdffile)
34946 statistics.stoptiming()
34947 if statistics.elapsedseconds then
34948 report_png("png conversion time %s",statistics.elapsedseconds() or "-")
34949 end
34950 return pdfshapes
34951 end
34952 end
34953 local function initializepng(tfmdata,kind,value)
34954 if value and otf.pngenabled then
34955 local png=tfmdata.properties.png
34956 local hash=png and png.hash
34957 local timestamp=png and png.timestamp
34958 if not hash then
34959 return
34960 end
34961 local pdffile=containers.read(otf.pdfcache,hash)
34962 local pdfshapes=pdffile and pdffile.pdfshapes
34963 if not pdfshapes or pdffile.timestamp~=timestamp then
34964 local pngfile=containers.read(otf.pngcache,hash)
34965 local pngshapes=pngfile and pngfile.pngshapes
34966 pdfshapes=pngshapes and otfpng.topdf(pngshapes) or {}
34967 containers.write(otf.pdfcache,hash,{
34968 pdfshapes=pdfshapes,
34969 timestamp=timestamp,
34970 })
34971 end
34972 pdftovirtual(tfmdata,pdfshapes,"png")
34973 return true
34974 end
34975 end
34976 otfregister {
34977 name="sbix",
34978 description="sbix glyphs",
34979 manipulators={
34980 base=initializepng,
34981 node=initializepng,
34982 }
34983 }
34984 otfregister {
34985 name="cblc",
34986 description="cblc glyphs",
34987 manipulators={
34988 base=initializepng,
34989 node=initializepng,
34990 }
34991 }
34992 if context then
34993
34994 --removed
34995
34996 end
34997
34998 end -- closure
34999
35000 do -- begin closure to overcome local limits and interference
35001
35002 if not modules then modules={} end modules ['font-onr']={
35003 version=1.001,
35004 optimize=true,
35005 comment="companion to font-ini.mkiv",
35006 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
35007 copyright="PRAGMA ADE / ConTeXt Development Team",
35008 license="see context related readme files"
35009 }
35010 local fonts,logs,trackers,resolvers=fonts,logs,trackers,resolvers
35011 local next,type,tonumber,rawset=next,type,tonumber,rawset
35012 local match,lower,gsub,strip,find=string.match,string.lower,string.gsub,string.strip,string.find
35013 local char,byte,sub=string.char,string.byte,string.sub
35014 local abs=math.abs
35015 local bxor,rshift=bit32.bxor,bit32.rshift
35016 local P,S,R,V,Cmt,C,Ct,Cs,Carg,Cf,Cg,Cc=lpeg.P,lpeg.S,lpeg.R,lpeg.V,lpeg.Cmt,lpeg.C,lpeg.Ct,lpeg.Cs,lpeg.Carg,lpeg.Cf,lpeg.Cg,lpeg.Cc
35017 local lpegmatch,patterns=lpeg.match,lpeg.patterns
35018 local trace_indexing=false trackers.register("afm.indexing",function(v) trace_indexing=v end)
35019 local trace_loading=false trackers.register("afm.loading",function(v) trace_loading=v end)
35020 local report_afm=logs.reporter("fonts","afm loading")
35021 local report_pfb=logs.reporter("fonts","pfb loading")
35022 local handlers=fonts.handlers
35023 local afm=handlers.afm or {}
35024 handlers.afm=afm
35025 local readers=afm.readers or {}
35026 afm.readers=readers
35027 afm.version=1.513
35028 local get_indexes,get_shapes
35029 do
35030 local decrypt
35031 do
35032 local r,c1,c2,n=0,0,0,0
35033 local function step(c)
35034 local cipher=byte(c)
35035 local plain=bxor(cipher,rshift(r,8))
35036 r=((cipher+r)*c1+c2)%65536
35037 return char(plain)
35038 end
35039 decrypt=function(binary,initial,seed)
35040 r,c1,c2,n=initial,52845,22719,seed
35041 binary=gsub(binary,".",step)
35042 return sub(binary,n+1)
35043 end
35044 end
35045 local charstrings=P("/CharStrings")
35046 local subroutines=P("/Subrs")
35047 local encoding=P("/Encoding")
35048 local dup=P("dup")
35049 local put=P("put")
35050 local array=P("array")
35051 local name=P("/")*C((R("az","AZ","09")+S("-_."))^1)
35052 local digits=R("09")^1
35053 local cardinal=digits/tonumber
35054 local spaces=P(" ")^1
35055 local spacing=patterns.whitespace^0
35056 local routines,vector,chars,n,m
35057 local initialize=function(str,position,size)
35058 n=0
35059 m=size
35060 return position+1
35061 end
35062 local setroutine=function(str,position,index,size,filename)
35063 if routines[index] then
35064 return false
35065 end
35066 local forward=position+size
35067 local stream=decrypt(sub(str,position+1,forward),4330,4)
35068 routines[index]={ byte(stream,1,#stream) }
35069 n=n+1
35070 if n>=m then
35071 return #str
35072 end
35073 return forward+1
35074 end
35075 local setvector=function(str,position,name,size,filename)
35076 local forward=position+tonumber(size)
35077 if n>=m then
35078 return #str
35079 elseif forward<#str then
35080 if n==0 and name~=".notdef" then
35081 report_pfb("reserving .notdef at index 0 in %a",filename)
35082 n=n+1
35083 end
35084 vector[n]=name
35085 n=n+1
35086 return forward
35087 else
35088 return #str
35089 end
35090 end
35091 local setshapes=function(str,position,name,size,filename)
35092 local forward=position+tonumber(size)
35093 local stream=sub(str,position+1,forward)
35094 if n>m then
35095 return #str
35096 elseif forward<#str then
35097 if n==0 and name~=".notdef" then
35098 report_pfb("reserving .notdef at index 0 in %a",filename)
35099 n=n+1
35100 end
35101 vector[n]=name
35102 n=n+1
35103 chars [n]=decrypt(stream,4330,4)
35104 return forward
35105 else
35106 return #str
35107 end
35108 end
35109 local p_rd=spacing*(P("RD")+P("-|"))
35110 local p_np=spacing*(P("NP")+P("|"))
35111 local p_nd=spacing*(P("ND")+P("|"))
35112 local p_filterroutines=
35113 (1-subroutines)^0*subroutines*spaces*Cmt(cardinal,initialize)*(Cmt(cardinal*spaces*cardinal*p_rd*Carg(1),setroutine)*p_np+(1-p_nd))^1
35114 local p_filtershapes=
35115 (1-charstrings)^0*charstrings*spaces*Cmt(cardinal,initialize)*(Cmt(name*spaces*cardinal*p_rd*Carg(1),setshapes)*p_nd+P(1))^1
35116 local p_filternames=Ct (
35117 (1-charstrings)^0*charstrings*spaces*Cmt(cardinal,initialize)*(Cmt(name*spaces*cardinal*Carg(1),setvector)+P(1))^1
35118 )
35119 local p_filterencoding=(1-encoding)^0*encoding*spaces*digits*spaces*array*(1-dup)^0*Cf(
35120 Ct("")*Cg(spacing*dup*spaces*cardinal*spaces*name*spaces*put)^1
35121 ,rawset)
35122 local key=spacing*P("/")*R("az","AZ")
35123 local str=spacing*Cs { (P("(")/"")*((1-P("\\(")-P("\\)")-S("()"))+V(1))^0*(P(")")/"") }
35124 local num=spacing*(R("09")+S("+-."))^1/tonumber
35125 local arr=spacing*Ct (S("[{")*(num)^0*spacing*S("]}"))
35126 local boo=spacing*(P("true")*Cc(true)+P("false")*Cc(false))
35127 local nam=spacing*P("/")*Cs(R("az","AZ")^1)
35128 local p_filtermetadata=(
35129 P("/")*Carg(1)*((
35130 C("version")*str+C("Copyright")*str+C("Notice")*str+C("FullName")*str+C("FamilyName")*str+C("Weight")*str+C("ItalicAngle")*num+C("isFixedPitch")*boo+C("UnderlinePosition")*num+C("UnderlineThickness")*num+C("FontName")*nam+C("FontMatrix")*arr+C("FontBBox")*arr
35131 ) )/function(t,k,v) t[lower(k)]=v end+P(1)
35132 )^0*Carg(1)
35133 local function loadpfbvector(filename,shapestoo,streams)
35134 local data=io.loaddata(resolvers.findfile(filename))
35135 if not data then
35136 report_pfb("no data in %a",filename)
35137 return
35138 end
35139 if not (find(data,"!PS-AdobeFont-",1,true) or find(data,"%!FontType1",1,true)) then
35140 report_pfb("no font in %a",filename)
35141 return
35142 end
35143 local ascii,binary=match(data,"(.*)eexec%s+......(.*)")
35144 if not binary then
35145 report_pfb("no binary data in %a",filename)
35146 return
35147 end
35148 binary=decrypt(binary,55665,4)
35149 local names={}
35150 local encoding=lpegmatch(p_filterencoding,ascii)
35151 local metadata=lpegmatch(p_filtermetadata,ascii,1,{})
35152 local glyphs={}
35153 routines,vector,chars={},{},{}
35154 if shapestoo or streams then
35155 lpegmatch(p_filterroutines,binary,1,filename)
35156 lpegmatch(p_filtershapes,binary,1,filename)
35157 local data={
35158 dictionaries={
35159 {
35160 charstrings=chars,
35161 charset=vector,
35162 subroutines=routines,
35163 }
35164 },
35165 }
35166 fonts.handlers.otf.readers.parsecharstrings(false,data,glyphs,true,"cff",streams,true)
35167 else
35168 lpegmatch(p_filternames,binary,1,filename)
35169 end
35170 names=vector
35171 routines,vector,chars=nil,nil,nil
35172 return names,encoding,glyphs,metadata
35173 end
35174 local pfb=handlers.pfb or {}
35175 handlers.pfb=pfb
35176 pfb.loadvector=loadpfbvector
35177 get_indexes=function(data,pfbname)
35178 local vector=loadpfbvector(pfbname)
35179 if vector then
35180 local characters=data.characters
35181 if trace_loading then
35182 report_afm("getting index data from %a",pfbname)
35183 end
35184 for index=0,#vector do
35185 local name=vector[index]
35186 local char=characters[name]
35187 if char then
35188 if trace_indexing then
35189 report_afm("glyph %a has index %a",name,index)
35190 end
35191 char.index=index
35192 else
35193 if trace_indexing then
35194 report_afm("glyph %a has index %a but no data",name,index)
35195 end
35196 end
35197 end
35198 end
35199 end
35200 get_shapes=function(pfbname)
35201 local vector,encoding,glyphs=loadpfbvector(pfbname,true)
35202 return glyphs
35203 end
35204 end
35205 local spacer=patterns.spacer
35206 local whitespace=patterns.whitespace
35207 local lineend=patterns.newline
35208 local spacing=spacer^0
35209 local number=spacing*S("+-")^-1*(R("09")+S("."))^1/tonumber
35210 local name=spacing*C((1-whitespace)^1)
35211 local words=spacing*((1-lineend)^1/strip)
35212 local rest=(1-lineend)^0
35213 local fontdata=Carg(1)
35214 local semicolon=spacing*P(";")
35215 local plus=spacing*P("plus")*number
35216 local minus=spacing*P("minus")*number
35217 local function addkernpair(data,one,two,value)
35218 local chr=data.characters[one]
35219 if chr then
35220 local kerns=chr.kerns
35221 if kerns then
35222 kerns[two]=tonumber(value)
35223 else
35224 chr.kerns={ [two]=tonumber(value) }
35225 end
35226 end
35227 end
35228 local p_kernpair=(fontdata*P("KPX")*name*name*number)/addkernpair
35229 local chr=false
35230 local ind=0
35231 local function start(data,version)
35232 data.metadata.afmversion=version
35233 ind=0
35234 chr={}
35235 end
35236 local function stop()
35237 ind=0
35238 chr=false
35239 end
35240 local function setindex(i)
35241 if i<0 then
35242 ind=ind+1
35243 else
35244 ind=i
35245 end
35246 chr={
35247 index=ind
35248 }
35249 end
35250 local function setwidth(width)
35251 chr.width=width
35252 end
35253 local function setname(data,name)
35254 data.characters[name]=chr
35255 end
35256 local function setboundingbox(boundingbox)
35257 chr.boundingbox=boundingbox
35258 end
35259 local function setligature(plus,becomes)
35260 local ligatures=chr.ligatures
35261 if ligatures then
35262 ligatures[plus]=becomes
35263 else
35264 chr.ligatures={ [plus]=becomes }
35265 end
35266 end
35267 local p_charmetric=((
35268 P("C")*number/setindex+P("WX")*number/setwidth+P("N")*fontdata*name/setname+P("B")*Ct((number)^4)/setboundingbox+P("L")*(name)^2/setligature
35269 )*semicolon )^1
35270 local p_charmetrics=P("StartCharMetrics")*number*(p_charmetric+(1-P("EndCharMetrics")))^0*P("EndCharMetrics")
35271 local p_kernpairs=P("StartKernPairs")*number*(p_kernpair+(1-P("EndKernPairs" )))^0*P("EndKernPairs" )
35272 local function set_1(data,key,a) data.metadata[lower(key)]=a end
35273 local function set_2(data,key,a,b) data.metadata[lower(key)]={ a,b } end
35274 local function set_3(data,key,a,b,c) data.metadata[lower(key)]={ a,b,c } end
35275 local p_parameters=P(false)+fontdata*((P("FontName")+P("FullName")+P("FamilyName"))/lower)*words/function(data,key,value)
35276 data.metadata[key]=value
35277 end+fontdata*((P("Weight")+P("Version"))/lower)*name/function(data,key,value)
35278 data.metadata[key]=value
35279 end+fontdata*P("IsFixedPitch")*name/function(data,pitch)
35280 data.metadata.monospaced=toboolean(pitch,true)
35281 end+fontdata*P("FontBBox")*Ct(number^4)/function(data,boundingbox)
35282 data.metadata.boundingbox=boundingbox
35283 end+fontdata*((P("CharWidth")+P("CapHeight")+P("XHeight")+P("Descender")+P("Ascender")+P("ItalicAngle"))/lower)*number/function(data,key,value)
35284 data.metadata[key]=value
35285 end+P("Comment")*spacing*(P(false)+(fontdata*C("DESIGNSIZE")*number*rest)/set_1
35286 +(fontdata*C("TFM designsize")*number*rest)/set_1+(fontdata*C("DesignSize")*number*rest)/set_1+(fontdata*C("CODINGSCHEME")*words*rest)/set_1
35287 +(fontdata*C("CHECKSUM")*number*words*rest)/set_1
35288 +(fontdata*C("SPACE")*number*plus*minus*rest)/set_3
35289 +(fontdata*C("QUAD")*number*rest)/set_1
35290 +(fontdata*C("EXTRASPACE")*number*rest)/set_1
35291 +(fontdata*C("NUM")*number*number*number*rest)/set_3
35292 +(fontdata*C("DENOM")*number*number*rest)/set_2
35293 +(fontdata*C("SUP")*number*number*number*rest)/set_3
35294 +(fontdata*C("SUB")*number*number*rest)/set_2
35295 +(fontdata*C("SUPDROP")*number*rest)/set_1
35296 +(fontdata*C("SUBDROP")*number*rest)/set_1
35297 +(fontdata*C("DELIM")*number*number*rest)/set_2
35298 +(fontdata*C("AXISHEIGHT")*number*rest)/set_1
35299 )
35300 local fullparser=(P("StartFontMetrics")*fontdata*name/start )*(p_charmetrics+p_kernpairs+p_parameters+(1-P("EndFontMetrics")) )^0*(P("EndFontMetrics")/stop )
35301 local infoparser=(P("StartFontMetrics")*fontdata*name/start )*(p_parameters+(1-P("EndFontMetrics")) )^0*(P("EndFontMetrics")/stop )
35302 local function read(filename,parser)
35303 local afmblob=io.loaddata(filename)
35304 if afmblob then
35305 local data={
35306 resources={
35307 filename=resolvers.unresolve(filename),
35308 version=afm.version,
35309 creator="context mkiv",
35310 },
35311 properties={
35312 hasitalics=false,
35313 },
35314 goodies={},
35315 metadata={
35316 filename=file.removesuffix(file.basename(filename))
35317 },
35318 characters={
35319 },
35320 descriptions={
35321 },
35322 }
35323 if trace_loading then
35324 report_afm("parsing afm file %a",filename)
35325 end
35326 lpegmatch(parser,afmblob,1,data)
35327 return data
35328 else
35329 if trace_loading then
35330 report_afm("no valid afm file %a",filename)
35331 end
35332 return nil
35333 end
35334 end
35335 function readers.loadfont(afmname,pfbname)
35336 local data=read(resolvers.findfile(afmname),fullparser)
35337 if data then
35338 if not pfbname or pfbname=="" then
35339 pfbname=resolvers.findfile(file.replacesuffix(file.nameonly(afmname),"pfb"))
35340 end
35341 if pfbname and pfbname~="" then
35342 data.resources.filename=resolvers.unresolve(pfbname)
35343 get_indexes(data,pfbname)
35344 return data
35345 else
35346 report_afm("no pfb file for %a",afmname)
35347 end
35348 end
35349 end
35350 function readers.loadshapes(filename)
35351 local fullname=resolvers.findfile(filename) or ""
35352 if fullname=="" then
35353 return {
35354 filename="not found: "..filename,
35355 glyphs={}
35356 }
35357 else
35358 return {
35359 filename=fullname,
35360 format="opentype",
35361 glyphs=get_shapes(fullname) or {},
35362 units=1000,
35363 }
35364 end
35365 end
35366 function readers.getinfo(filename)
35367 local data=read(resolvers.findfile(filename),infoparser)
35368 if data then
35369 return data.metadata
35370 end
35371 end
35372
35373 end -- closure
35374
35375 do -- begin closure to overcome local limits and interference
35376
35377 if not modules then modules={} end modules ['font-one']={
35378 version=1.001,
35379 optimize=true,
35380 comment="companion to font-ini.mkiv",
35381 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
35382 copyright="PRAGMA ADE / ConTeXt Development Team",
35383 license="see context related readme files"
35384 }
35385 local fonts,logs,trackers,containers,resolvers=fonts,logs,trackers,containers,resolvers
35386 local next,type,tonumber,rawget=next,type,tonumber,rawget
35387 local match,gsub=string.match,string.gsub
35388 local abs=math.abs
35389 local P,S,R,Cmt,C,Ct,Cs,Carg=lpeg.P,lpeg.S,lpeg.R,lpeg.Cmt,lpeg.C,lpeg.Ct,lpeg.Cs,lpeg.Carg
35390 local lpegmatch,patterns=lpeg.match,lpeg.patterns
35391 local sortedhash=table.sortedhash
35392 local trace_features=false trackers.register("afm.features",function(v) trace_features=v end)
35393 local trace_indexing=false trackers.register("afm.indexing",function(v) trace_indexing=v end)
35394 local trace_loading=false trackers.register("afm.loading",function(v) trace_loading=v end)
35395 local trace_defining=false trackers.register("fonts.defining",function(v) trace_defining=v end)
35396 local report_afm=logs.reporter("fonts","afm loading")
35397 local setmetatableindex=table.setmetatableindex
35398 local derivetable=table.derive
35399 local findbinfile=resolvers.findbinfile
35400 local privateoffset=fonts.constructors and fonts.constructors.privateoffset or 0xF0000
35401 local definers=fonts.definers
35402 local readers=fonts.readers
35403 local constructors=fonts.constructors
35404 local afm=constructors.handlers.afm
35405 local pfb=constructors.handlers.pfb
35406 local otf=fonts.handlers.otf
35407 local otfreaders=otf.readers
35408 local otfenhancers=otf.enhancers
35409 local afmfeatures=constructors.features.afm
35410 local registerafmfeature=afmfeatures.register
35411 local afmenhancers=constructors.enhancers.afm
35412 local registerafmenhancer=afmenhancers.register
35413 afm.version=1.513
35414 afm.cache=containers.define("fonts","one",afm.version,true)
35415 afm.autoprefixed=true
35416 afm.helpdata={}
35417 afm.syncspace=true
35418 local overloads=fonts.mappings.overloads
35419 local applyruntimefixes=fonts.treatments and fonts.treatments.applyfixes
35420 function afm.load(filename)
35421 filename=resolvers.findfile(filename,'afm') or ""
35422 if filename~="" and not fonts.names.ignoredfile(filename) then
35423 local name=file.removesuffix(file.basename(filename))
35424 local data=containers.read(afm.cache,name)
35425 local attr=lfs.attributes(filename)
35426 local size=attr and attr.size or 0
35427 local time=attr and attr.modification or 0
35428 local pfbfile=file.replacesuffix(name,"pfb")
35429 local pfbname=resolvers.findfile(pfbfile,"pfb") or ""
35430 if pfbname=="" then
35431 pfbname=resolvers.findfile(file.basename(pfbfile),"pfb") or ""
35432 end
35433 local pfbsize=0
35434 local pfbtime=0
35435 if pfbname~="" then
35436 local attr=lfs.attributes(pfbname)
35437 pfbsize=attr.size or 0
35438 pfbtime=attr.modification or 0
35439 end
35440 if not data or data.size~=size or data.time~=time or data.pfbsize~=pfbsize or data.pfbtime~=pfbtime then
35441 report_afm("reading %a",filename)
35442 data=afm.readers.loadfont(filename,pfbname)
35443 if data then
35444 afmenhancers.apply(data,filename)
35445 fonts.mappings.addtounicode(data,filename)
35446 otfreaders.stripredundant(data)
35447 otfreaders.pack(data)
35448 data.size=size
35449 data.time=time
35450 data.pfbsize=pfbsize
35451 data.pfbtime=pfbtime
35452 report_afm("saving %a in cache",name)
35453 data=containers.write(afm.cache,name,data)
35454 data=containers.read(afm.cache,name)
35455 end
35456 end
35457 if data then
35458 otfreaders.unpack(data)
35459 otfreaders.expand(data)
35460 otfreaders.addunicodetable(data)
35461 otfenhancers.apply(data,filename,data)
35462 if applyruntimefixes then
35463 applyruntimefixes(filename,data)
35464 end
35465 end
35466 return data
35467 end
35468 end
35469 local uparser=fonts.mappings.makenameparser()
35470 local function enhance_unify_names(data,filename)
35471 local unicodevector=fonts.encodings.agl.unicodes
35472 local unicodes={}
35473 local names={}
35474 local private=data.private or privateoffset
35475 local descriptions=data.descriptions
35476 for name,blob in sortedhash(data.characters) do
35477 local code=unicodevector[name]
35478 if not code then
35479 code=lpegmatch(uparser,name)
35480 if type(code)~="number" then
35481 code=private
35482 private=private+1
35483 report_afm("assigning private slot %U for unknown glyph name %a",code,name)
35484 end
35485 end
35486 local index=blob.index
35487 unicodes[name]=code
35488 names[name]=index
35489 blob.name=name
35490 descriptions[code]={
35491 boundingbox=blob.boundingbox,
35492 width=blob.width,
35493 kerns=blob.kerns,
35494 index=index,
35495 name=name,
35496 }
35497 end
35498 for unicode,description in next,descriptions do
35499 local kerns=description.kerns
35500 if kerns then
35501 local krn={}
35502 for name,kern in next,kerns do
35503 local unicode=unicodes[name]
35504 if unicode then
35505 krn[unicode]=kern
35506 else
35507 end
35508 end
35509 description.kerns=krn
35510 end
35511 end
35512 data.characters=nil
35513 data.private=private
35514 local resources=data.resources
35515 local filename=resources.filename or file.removesuffix(file.basename(filename))
35516 resources.filename=resolvers.unresolve(filename)
35517 resources.unicodes=unicodes
35518 resources.marks={}
35519 end
35520 local everywhere={ ["*"]={ ["*"]=true } }
35521 local noflags={ false,false,false,false }
35522 local function enhance_normalize_features(data)
35523 local ligatures=setmetatableindex("table")
35524 local kerns=setmetatableindex("table")
35525 local extrakerns=setmetatableindex("table")
35526 for u,c in next,data.descriptions do
35527 local l=c.ligatures
35528 local k=c.kerns
35529 local e=c.extrakerns
35530 if l then
35531 ligatures[u]=l
35532 for u,v in next,l do
35533 l[u]={ ligature=v }
35534 end
35535 c.ligatures=nil
35536 end
35537 if k then
35538 kerns[u]=k
35539 for u,v in next,k do
35540 k[u]=v
35541 end
35542 c.kerns=nil
35543 end
35544 if e then
35545 extrakerns[u]=e
35546 for u,v in next,e do
35547 e[u]=v
35548 end
35549 c.extrakerns=nil
35550 end
35551 end
35552 local features={
35553 gpos={},
35554 gsub={},
35555 }
35556 local sequences={
35557 }
35558 if next(ligatures) then
35559 features.gsub.liga=everywhere
35560 data.properties.hasligatures=true
35561 sequences[#sequences+1]={
35562 features={
35563 liga=everywhere,
35564 },
35565 flags=noflags,
35566 name="s_s_0",
35567 nofsteps=1,
35568 order={ "liga" },
35569 type="gsub_ligature",
35570 steps={
35571 {
35572 coverage=ligatures,
35573 },
35574 },
35575 }
35576 end
35577 if next(kerns) then
35578 features.gpos.kern=everywhere
35579 data.properties.haskerns=true
35580 sequences[#sequences+1]={
35581 features={
35582 kern=everywhere,
35583 },
35584 flags=noflags,
35585 name="p_s_0",
35586 nofsteps=1,
35587 order={ "kern" },
35588 type="gpos_pair",
35589 steps={
35590 {
35591 format="kern",
35592 coverage=kerns,
35593 },
35594 },
35595 }
35596 end
35597 if next(extrakerns) then
35598 features.gpos.extrakerns=everywhere
35599 data.properties.haskerns=true
35600 sequences[#sequences+1]={
35601 features={
35602 extrakerns=everywhere,
35603 },
35604 flags=noflags,
35605 name="p_s_1",
35606 nofsteps=1,
35607 order={ "extrakerns" },
35608 type="gpos_pair",
35609 steps={
35610 {
35611 format="kern",
35612 coverage=extrakerns,
35613 },
35614 },
35615 }
35616 end
35617 data.resources.features=features
35618 data.resources.sequences=sequences
35619 end
35620 local function enhance_fix_names(data)
35621 for k,v in next,data.descriptions do
35622 local n=v.name
35623 local r=overloads[n]
35624 if r then
35625 local name=r.name
35626 if trace_indexing then
35627 report_afm("renaming characters %a to %a",n,name)
35628 end
35629 v.name=name
35630 v.unicode=r.unicode
35631 end
35632 end
35633 end
35634 local addthem=function(rawdata,ligatures)
35635 if ligatures then
35636 local descriptions=rawdata.descriptions
35637 local resources=rawdata.resources
35638 local unicodes=resources.unicodes
35639 for ligname,ligdata in next,ligatures do
35640 local one=descriptions[unicodes[ligname]]
35641 if one then
35642 for _,pair in next,ligdata do
35643 local two=unicodes[pair[1]]
35644 local three=unicodes[pair[2]]
35645 if two and three then
35646 local ol=one.ligatures
35647 if ol then
35648 if not ol[two] then
35649 ol[two]=three
35650 end
35651 else
35652 one.ligatures={ [two]=three }
35653 end
35654 end
35655 end
35656 end
35657 end
35658 end
35659 end
35660 local function enhance_add_ligatures(rawdata)
35661 addthem(rawdata,afm.helpdata.ligatures)
35662 end
35663 local function enhance_add_extra_kerns(rawdata)
35664 local descriptions=rawdata.descriptions
35665 local resources=rawdata.resources
35666 local unicodes=resources.unicodes
35667 local function do_it_left(what)
35668 if what then
35669 for unicode,description in next,descriptions do
35670 local kerns=description.kerns
35671 if kerns then
35672 local extrakerns
35673 for complex,simple in next,what do
35674 complex=unicodes[complex]
35675 simple=unicodes[simple]
35676 if complex and simple then
35677 local ks=kerns[simple]
35678 if ks and not kerns[complex] then
35679 if extrakerns then
35680 extrakerns[complex]=ks
35681 else
35682 extrakerns={ [complex]=ks }
35683 end
35684 end
35685 end
35686 end
35687 if extrakerns then
35688 description.extrakerns=extrakerns
35689 end
35690 end
35691 end
35692 end
35693 end
35694 local function do_it_copy(what)
35695 if what then
35696 for complex,simple in next,what do
35697 complex=unicodes[complex]
35698 simple=unicodes[simple]
35699 if complex and simple then
35700 local complexdescription=descriptions[complex]
35701 if complexdescription then
35702 local simpledescription=descriptions[complex]
35703 if simpledescription then
35704 local extrakerns
35705 local kerns=simpledescription.kerns
35706 if kerns then
35707 for unicode,kern in next,kerns do
35708 if extrakerns then
35709 extrakerns[unicode]=kern
35710 else
35711 extrakerns={ [unicode]=kern }
35712 end
35713 end
35714 end
35715 local extrakerns=simpledescription.extrakerns
35716 if extrakerns then
35717 for unicode,kern in next,extrakerns do
35718 if extrakerns then
35719 extrakerns[unicode]=kern
35720 else
35721 extrakerns={ [unicode]=kern }
35722 end
35723 end
35724 end
35725 if extrakerns then
35726 complexdescription.extrakerns=extrakerns
35727 end
35728 end
35729 end
35730 end
35731 end
35732 end
35733 end
35734 do_it_left(afm.helpdata.leftkerned)
35735 do_it_left(afm.helpdata.bothkerned)
35736 do_it_copy(afm.helpdata.bothkerned)
35737 do_it_copy(afm.helpdata.rightkerned)
35738 end
35739 local function adddimensions(data)
35740 if data then
35741 for unicode,description in next,data.descriptions do
35742 local bb=description.boundingbox
35743 if bb then
35744 local ht=bb[4]
35745 local dp=-bb[2]
35746 if ht==0 or ht<0 then
35747 else
35748 description.height=ht
35749 end
35750 if dp==0 or dp<0 then
35751 else
35752 description.depth=dp
35753 end
35754 end
35755 end
35756 end
35757 end
35758 local function copytotfm(data)
35759 if data and data.descriptions then
35760 local metadata=data.metadata
35761 local resources=data.resources
35762 local properties=derivetable(data.properties)
35763 local descriptions=derivetable(data.descriptions)
35764 local goodies=derivetable(data.goodies)
35765 local characters={}
35766 local parameters={}
35767 local unicodes=resources.unicodes
35768 for unicode,description in next,data.descriptions do
35769 characters[unicode]={}
35770 end
35771 local filename=constructors.checkedfilename(resources)
35772 local fontname=metadata.fontname or metadata.fullname
35773 local fullname=metadata.fullname or metadata.fontname
35774 local endash=0x2013
35775 local emdash=0x2014
35776 local space=0x0020
35777 local spacer="space"
35778 local spaceunits=500
35779 local monospaced=metadata.monospaced
35780 local charwidth=metadata.charwidth
35781 local italicangle=metadata.italicangle
35782 local charxheight=metadata.xheight and metadata.xheight>0 and metadata.xheight
35783 properties.monospaced=monospaced
35784 parameters.italicangle=italicangle
35785 parameters.charwidth=charwidth
35786 parameters.charxheight=charxheight
35787 local d_endash=descriptions[endash]
35788 local d_emdash=descriptions[emdash]
35789 local d_space=descriptions[space]
35790 if not d_space or d_space==0 then
35791 d_space=d_endash
35792 end
35793 if d_space then
35794 spaceunits,spacer=d_space.width or 0,"space"
35795 end
35796 if properties.monospaced then
35797 if spaceunits==0 and d_emdash then
35798 spaceunits,spacer=d_emdash.width or 0,"emdash"
35799 end
35800 else
35801 if spaceunits==0 and d_endash then
35802 spaceunits,spacer=d_emdash.width or 0,"endash"
35803 end
35804 end
35805 if spaceunits==0 and charwidth then
35806 spaceunits,spacer=charwidth or 0,"charwidth"
35807 end
35808 if spaceunits==0 then
35809 spaceunits=tonumber(spaceunits) or 500
35810 end
35811 if spaceunits==0 then
35812 spaceunits=500
35813 end
35814 parameters.slant=0
35815 parameters.space=spaceunits
35816 parameters.space_stretch=500
35817 parameters.space_shrink=333
35818 parameters.x_height=400
35819 parameters.quad=1000
35820 if italicangle and italicangle~=0 then
35821 parameters.italicangle=italicangle
35822 parameters.italicfactor=math.cos(math.rad(90+italicangle))
35823 parameters.slant=- math.tan(italicangle*math.pi/180)
35824 end
35825 if monospaced then
35826 parameters.space_stretch=0
35827 parameters.space_shrink=0
35828 elseif afm.syncspace then
35829 parameters.space_stretch=spaceunits/2
35830 parameters.space_shrink=spaceunits/3
35831 end
35832 parameters.extra_space=parameters.space_shrink
35833 if charxheight then
35834 parameters.x_height=charxheight
35835 else
35836 local x=0x0078
35837 if x then
35838 local x=descriptions[x]
35839 if x then
35840 parameters.x_height=x.height
35841 end
35842 end
35843 end
35844 if metadata.sup then
35845 local dummy={ 0,0,0 }
35846 parameters[ 1]=metadata.designsize or 0
35847 parameters[ 2]=metadata.checksum or 0
35848 parameters[ 3],
35849 parameters[ 4],
35850 parameters[ 5]=unpack(metadata.space or dummy)
35851 parameters[ 6]=metadata.quad or 0
35852 parameters[ 7]=metadata.extraspace or 0
35853 parameters[ 8],
35854 parameters[ 9],
35855 parameters[10]=unpack(metadata.num or dummy)
35856 parameters[11],
35857 parameters[12]=unpack(metadata.denom or dummy)
35858 parameters[13],
35859 parameters[14],
35860 parameters[15]=unpack(metadata.sup or dummy)
35861 parameters[16],
35862 parameters[17]=unpack(metadata.sub or dummy)
35863 parameters[18]=metadata.supdrop or 0
35864 parameters[19]=metadata.subdrop or 0
35865 parameters[20],
35866 parameters[21]=unpack(metadata.delim or dummy)
35867 parameters[22]=metadata.axisheight or 0
35868 end
35869 parameters.designsize=(metadata.designsize or 10)*65536
35870 parameters.ascender=abs(metadata.ascender or 0)
35871 parameters.descender=abs(metadata.descender or 0)
35872 parameters.units=1000
35873 properties.spacer=spacer
35874 properties.format=fonts.formats[filename] or "type1"
35875 properties.filename=filename
35876 properties.fontname=fontname
35877 properties.fullname=fullname
35878 properties.psname=fullname
35879 properties.name=filename or fullname or fontname
35880 properties.private=properties.private or data.private or privateoffset
35881 if not CONTEXTLMTXMODE or CONTEXTLMTXMODE==0 then
35882 properties.encodingbytes=2
35883 end
35884 if next(characters) then
35885 return {
35886 characters=characters,
35887 descriptions=descriptions,
35888 parameters=parameters,
35889 resources=resources,
35890 properties=properties,
35891 goodies=goodies,
35892 }
35893 end
35894 end
35895 return nil
35896 end
35897 function afm.setfeatures(tfmdata,features)
35898 local okay=constructors.initializefeatures("afm",tfmdata,features,trace_features,report_afm)
35899 if okay then
35900 return constructors.collectprocessors("afm",tfmdata,features,trace_features,report_afm)
35901 else
35902 return {}
35903 end
35904 end
35905 local function addtables(data)
35906 local resources=data.resources
35907 local lookuptags=resources.lookuptags
35908 local unicodes=resources.unicodes
35909 if not lookuptags then
35910 lookuptags={}
35911 resources.lookuptags=lookuptags
35912 end
35913 setmetatableindex(lookuptags,function(t,k)
35914 local v=type(k)=="number" and ("lookup "..k) or k
35915 t[k]=v
35916 return v
35917 end)
35918 if not unicodes then
35919 unicodes={}
35920 resources.unicodes=unicodes
35921 setmetatableindex(unicodes,function(t,k)
35922 setmetatableindex(unicodes,nil)
35923 for u,d in next,data.descriptions do
35924 local n=d.name
35925 if n then
35926 t[n]=u
35927 end
35928 end
35929 return rawget(t,k)
35930 end)
35931 end
35932 constructors.addcoreunicodes(unicodes)
35933 end
35934 local function afmtotfm(specification)
35935 local afmname=specification.filename or specification.name
35936 if specification.forced=="afm" or specification.format=="afm" then
35937 if trace_loading then
35938 report_afm("forcing afm format for %a",afmname)
35939 end
35940 else
35941 local tfmname=findbinfile(afmname,"ofm") or ""
35942 if tfmname~="" then
35943 if trace_loading then
35944 report_afm("fallback from afm to tfm for %a",afmname)
35945 end
35946 return
35947 end
35948 end
35949 if afmname~="" then
35950 local features=constructors.checkedfeatures("afm",specification.features.normal)
35951 specification.features.normal=features
35952 constructors.hashinstance(specification,true)
35953 specification=definers.resolve(specification)
35954 local cache_id=specification.hash
35955 local tfmdata=containers.read(constructors.cache,cache_id)
35956 if not tfmdata then
35957 local rawdata=afm.load(afmname)
35958 if rawdata and next(rawdata) then
35959 addtables(rawdata)
35960 adddimensions(rawdata)
35961 tfmdata=copytotfm(rawdata)
35962 if tfmdata and next(tfmdata) then
35963 local shared=tfmdata.shared
35964 if not shared then
35965 shared={}
35966 tfmdata.shared=shared
35967 end
35968 shared.rawdata=rawdata
35969 shared.dynamics={}
35970 tfmdata.changed={}
35971 shared.features=features
35972 shared.processes=afm.setfeatures(tfmdata,features)
35973 end
35974 elseif trace_loading then
35975 report_afm("no (valid) afm file found with name %a",afmname)
35976 end
35977 tfmdata=containers.write(constructors.cache,cache_id,tfmdata)
35978 end
35979 return tfmdata
35980 end
35981 end
35982 local function read_from_afm(specification)
35983 local tfmdata=afmtotfm(specification)
35984 if tfmdata then
35985 tfmdata.properties.name=specification.name
35986 tfmdata.properties.id=specification.id
35987 tfmdata=constructors.scale(tfmdata,specification)
35988 local allfeatures=tfmdata.shared.features or specification.features.normal
35989 constructors.applymanipulators("afm",tfmdata,allfeatures,trace_features,report_afm)
35990 fonts.loggers.register(tfmdata,'afm',specification)
35991 end
35992 return tfmdata
35993 end
35994 registerafmfeature {
35995 name="mode",
35996 description="mode",
35997 initializers={
35998 base=otf.modeinitializer,
35999 node=otf.modeinitializer,
36000 }
36001 }
36002 registerafmfeature {
36003 name="features",
36004 description="features",
36005 default=true,
36006 initializers={
36007 node=otf.nodemodeinitializer,
36008 base=otf.basemodeinitializer,
36009 },
36010 processors={
36011 node=otf.featuresprocessor,
36012 }
36013 }
36014 fonts.formats.afm="type1"
36015 fonts.formats.pfb="type1"
36016 local function check_afm(specification,fullname)
36017 local foundname=findbinfile(fullname,'afm') or ""
36018 if foundname=="" then
36019 foundname=fonts.names.getfilename(fullname,"afm") or ""
36020 end
36021 if fullname and foundname=="" and afm.autoprefixed then
36022 local encoding,shortname=match(fullname,"^(.-)%-(.*)$")
36023 if encoding and shortname and fonts.encodings.known[encoding] then
36024 shortname=findbinfile(shortname,'afm') or ""
36025 if shortname~="" then
36026 foundname=shortname
36027 if trace_defining then
36028 report_afm("stripping encoding prefix from filename %a",afmname)
36029 end
36030 end
36031 end
36032 end
36033 if foundname~="" then
36034 specification.filename=foundname
36035 specification.format="afm"
36036 return read_from_afm(specification)
36037 end
36038 end
36039 function readers.afm(specification,method)
36040 local fullname=specification.filename or ""
36041 local tfmdata=nil
36042 if fullname=="" then
36043 local forced=specification.forced or ""
36044 if forced~="" then
36045 tfmdata=check_afm(specification,specification.name.."."..forced)
36046 end
36047 if not tfmdata then
36048 local check_tfm=readers.check_tfm
36049 method=(check_tfm and (method or definers.method or "afm or tfm")) or "afm"
36050 if method=="tfm" then
36051 tfmdata=check_tfm(specification,specification.name)
36052 elseif method=="afm" then
36053 tfmdata=check_afm(specification,specification.name)
36054 elseif method=="tfm or afm" then
36055 tfmdata=check_tfm(specification,specification.name) or check_afm(specification,specification.name)
36056 else
36057 tfmdata=check_afm(specification,specification.name) or check_tfm(specification,specification.name)
36058 end
36059 end
36060 else
36061 tfmdata=check_afm(specification,fullname)
36062 end
36063 return tfmdata
36064 end
36065 function readers.pfb(specification,method)
36066 local original=specification.specification
36067 if trace_defining then
36068 report_afm("using afm reader for %a",original)
36069 end
36070 specification.forced="afm"
36071 local function swap(name)
36072 local value=specification[swap]
36073 if value then
36074 specification[swap]=gsub("%.pfb",".afm",1)
36075 end
36076 end
36077 swap("filename")
36078 swap("fullname")
36079 swap("forcedname")
36080 swap("specification")
36081 return readers.afm(specification,method)
36082 end
36083 registerafmenhancer("unify names",enhance_unify_names)
36084 registerafmenhancer("add ligatures",enhance_add_ligatures)
36085 registerafmenhancer("add extra kerns",enhance_add_extra_kerns)
36086 registerafmenhancer("normalize features",enhance_normalize_features)
36087 registerafmenhancer("check extra features",otfenhancers.enhance)
36088 registerafmenhancer("fix names",enhance_fix_names)
36089
36090 end -- closure
36091
36092 do -- begin closure to overcome local limits and interference
36093
36094 if not modules then modules={} end modules ['font-afk']={
36095 version=1.001,
36096 comment="companion to font-lib.mkiv",
36097 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
36098 copyright="PRAGMA ADE / ConTeXt Development Team",
36099 license="see context related readme files",
36100 dataonly=true,
36101 }
36102 local allocate=utilities.storage.allocate
36103 fonts.handlers.afm.helpdata={
36104 ligatures=allocate {
36105 ['f']={
36106 { 'f','ff' },
36107 { 'i','fi' },
36108 { 'l','fl' },
36109 },
36110 ['ff']={
36111 { 'i','ffi' }
36112 },
36113 ['fi']={
36114 { 'i','fii' }
36115 },
36116 ['fl']={
36117 { 'i','fli' }
36118 },
36119 ['s']={
36120 { 't','st' }
36121 },
36122 ['i']={
36123 { 'j','ij' }
36124 },
36125 },
36126 texligatures=allocate {
36127 ['quoteleft']={
36128 { 'quoteleft','quotedblleft' }
36129 },
36130 ['quoteright']={
36131 { 'quoteright','quotedblright' }
36132 },
36133 ['hyphen']={
36134 { 'hyphen','endash' }
36135 },
36136 ['endash']={
36137 { 'hyphen','emdash' }
36138 }
36139 },
36140 leftkerned=allocate {
36141 AEligature="A",aeligature="a",
36142 OEligature="O",oeligature="o",
36143 IJligature="I",ijligature="i",
36144 AE="A",ae="a",
36145 OE="O",oe="o",
36146 IJ="I",ij="i",
36147 Ssharp="S",ssharp="s",
36148 },
36149 rightkerned=allocate {
36150 AEligature="E",aeligature="e",
36151 OEligature="E",oeligature="e",
36152 IJligature="J",ijligature="j",
36153 AE="E",ae="e",
36154 OE="E",oe="e",
36155 IJ="J",ij="j",
36156 Ssharp="S",ssharp="s",
36157 },
36158 bothkerned=allocate {
36159 Acircumflex="A",acircumflex="a",
36160 Ccircumflex="C",ccircumflex="c",
36161 Ecircumflex="E",ecircumflex="e",
36162 Gcircumflex="G",gcircumflex="g",
36163 Hcircumflex="H",hcircumflex="h",
36164 Icircumflex="I",icircumflex="i",
36165 Jcircumflex="J",jcircumflex="j",
36166 Ocircumflex="O",ocircumflex="o",
36167 Scircumflex="S",scircumflex="s",
36168 Ucircumflex="U",ucircumflex="u",
36169 Wcircumflex="W",wcircumflex="w",
36170 Ycircumflex="Y",ycircumflex="y",
36171 Agrave="A",agrave="a",
36172 Egrave="E",egrave="e",
36173 Igrave="I",igrave="i",
36174 Ograve="O",ograve="o",
36175 Ugrave="U",ugrave="u",
36176 Ygrave="Y",ygrave="y",
36177 Atilde="A",atilde="a",
36178 Itilde="I",itilde="i",
36179 Otilde="O",otilde="o",
36180 Utilde="U",utilde="u",
36181 Ntilde="N",ntilde="n",
36182 Adiaeresis="A",adiaeresis="a",Adieresis="A",adieresis="a",
36183 Ediaeresis="E",ediaeresis="e",Edieresis="E",edieresis="e",
36184 Idiaeresis="I",idiaeresis="i",Idieresis="I",idieresis="i",
36185 Odiaeresis="O",odiaeresis="o",Odieresis="O",odieresis="o",
36186 Udiaeresis="U",udiaeresis="u",Udieresis="U",udieresis="u",
36187 Ydiaeresis="Y",ydiaeresis="y",Ydieresis="Y",ydieresis="y",
36188 Aacute="A",aacute="a",
36189 Cacute="C",cacute="c",
36190 Eacute="E",eacute="e",
36191 Iacute="I",iacute="i",
36192 Lacute="L",lacute="l",
36193 Nacute="N",nacute="n",
36194 Oacute="O",oacute="o",
36195 Racute="R",racute="r",
36196 Sacute="S",sacute="s",
36197 Uacute="U",uacute="u",
36198 Yacute="Y",yacute="y",
36199 Zacute="Z",zacute="z",
36200 Dstroke="D",dstroke="d",
36201 Hstroke="H",hstroke="h",
36202 Tstroke="T",tstroke="t",
36203 Cdotaccent="C",cdotaccent="c",
36204 Edotaccent="E",edotaccent="e",
36205 Gdotaccent="G",gdotaccent="g",
36206 Idotaccent="I",idotaccent="i",
36207 Zdotaccent="Z",zdotaccent="z",
36208 Amacron="A",amacron="a",
36209 Emacron="E",emacron="e",
36210 Imacron="I",imacron="i",
36211 Omacron="O",omacron="o",
36212 Umacron="U",umacron="u",
36213 Ccedilla="C",ccedilla="c",
36214 Kcedilla="K",kcedilla="k",
36215 Lcedilla="L",lcedilla="l",
36216 Ncedilla="N",ncedilla="n",
36217 Rcedilla="R",rcedilla="r",
36218 Scedilla="S",scedilla="s",
36219 Tcedilla="T",tcedilla="t",
36220 Ohungarumlaut="O",ohungarumlaut="o",
36221 Uhungarumlaut="U",uhungarumlaut="u",
36222 Aogonek="A",aogonek="a",
36223 Eogonek="E",eogonek="e",
36224 Iogonek="I",iogonek="i",
36225 Uogonek="U",uogonek="u",
36226 Aring="A",aring="a",
36227 Uring="U",uring="u",
36228 Abreve="A",abreve="a",
36229 Ebreve="E",ebreve="e",
36230 Gbreve="G",gbreve="g",
36231 Ibreve="I",ibreve="i",
36232 Obreve="O",obreve="o",
36233 Ubreve="U",ubreve="u",
36234 Ccaron="C",ccaron="c",
36235 Dcaron="D",dcaron="d",
36236 Ecaron="E",ecaron="e",
36237 Lcaron="L",lcaron="l",
36238 Ncaron="N",ncaron="n",
36239 Rcaron="R",rcaron="r",
36240 Scaron="S",scaron="s",
36241 Tcaron="T",tcaron="t",
36242 Zcaron="Z",zcaron="z",
36243 dotlessI="I",dotlessi="i",
36244 dotlessJ="J",dotlessj="j",
36245 AEligature="AE",aeligature="ae",AE="AE",ae="ae",
36246 OEligature="OE",oeligature="oe",OE="OE",oe="oe",
36247 IJligature="IJ",ijligature="ij",IJ="IJ",ij="ij",
36248 Lstroke="L",lstroke="l",Lslash="L",lslash="l",
36249 Ostroke="O",ostroke="o",Oslash="O",oslash="o",
36250 Ssharp="SS",ssharp="ss",
36251 Aumlaut="A",aumlaut="a",
36252 Eumlaut="E",eumlaut="e",
36253 Iumlaut="I",iumlaut="i",
36254 Oumlaut="O",oumlaut="o",
36255 Uumlaut="U",uumlaut="u",
36256 }
36257 }
36258
36259 end -- closure
36260
36261 do -- begin closure to overcome local limits and interference
36262
36263 if not modules then modules={} end modules ['luatex-fonts-tfm']={
36264 version=1.001,
36265 comment="companion to font-ini.mkiv",
36266 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
36267 copyright="PRAGMA ADE / ConTeXt Development Team",
36268 license="see context related readme files"
36269 }
36270 local next,type=next,type
36271 local match,format=string.match,string.format
36272 local concat,sortedhash=table.concat,table.sortedhash
36273 local idiv=number.idiv
36274 local trace_defining=false trackers.register("fonts.defining",function(v) trace_defining=v end)
36275 local trace_features=false trackers.register("tfm.features",function(v) trace_features=v end)
36276 local report_defining=logs.reporter("fonts","defining")
36277 local report_tfm=logs.reporter("fonts","tfm loading")
36278 local findbinfile=resolvers.findbinfile
36279 local setmetatableindex=table.setmetatableindex
36280 local fonts=fonts
36281 local handlers=fonts.handlers
36282 local helpers=fonts.helpers
36283 local readers=fonts.readers
36284 local constructors=fonts.constructors
36285 local encodings=fonts.encodings
36286 local tfm=constructors.handlers.tfm
36287 tfm.version=1.000
36288 tfm.maxnestingdepth=5
36289 tfm.maxnestingsize=65536*1024
36290 local otf=fonts.handlers.otf
36291 local otfenhancers=otf.enhancers
36292 local tfmfeatures=constructors.features.tfm
36293 local registertfmfeature=tfmfeatures.register
36294 local tfmenhancers=constructors.enhancers.tfm
36295 local registertfmenhancer=tfmenhancers.register
36296 local charcommand=helpers.commands.char
36297 constructors.resolvevirtualtoo=false
36298 fonts.formats.tfm="type1"
36299 fonts.formats.ofm="type1"
36300 function tfm.setfeatures(tfmdata,features)
36301 local okay=constructors.initializefeatures("tfm",tfmdata,features,trace_features,report_tfm)
36302 if okay then
36303 return constructors.collectprocessors("tfm",tfmdata,features,trace_features,report_tfm)
36304 else
36305 return {}
36306 end
36307 end
36308 local depth={}
36309 local loadtfm=font.read_tfm
36310 local loadvf=font.read_vf
36311 local function read_from_tfm(specification)
36312 local filename=specification.filename
36313 local size=specification.size
36314 depth[filename]=(depth[filename] or 0)+1
36315 if trace_defining then
36316 report_defining("loading tfm file %a at size %s",filename,size)
36317 end
36318 local tfmdata=loadtfm(filename,size)
36319 if tfmdata then
36320 local features=specification.features and specification.features.normal or {}
36321 local features=constructors.checkedfeatures("tfm",features)
36322 specification.features.normal=features
36323 local newtfmdata=(depth[filename]==1) and tfm.reencode(tfmdata,specification)
36324 if newtfmdata then
36325 tfmdata=newtfmdata
36326 end
36327 local resources=tfmdata.resources or {}
36328 local properties=tfmdata.properties or {}
36329 local parameters=tfmdata.parameters or {}
36330 local shared=tfmdata.shared or {}
36331 shared.features=features
36332 shared.resources=resources
36333 properties.name=tfmdata.name
36334 properties.fontname=tfmdata.fontname
36335 properties.psname=tfmdata.psname
36336 properties.fullname=tfmdata.fullname
36337 properties.filename=specification.filename
36338 properties.format=tfmdata.format or fonts.formats.tfm
36339 properties.usedbitmap=tfmdata.usedbitmap
36340 tfmdata.properties=properties
36341 tfmdata.resources=resources
36342 tfmdata.parameters=parameters
36343 tfmdata.shared=shared
36344 shared.rawdata={ resources=resources }
36345 shared.features=features
36346 if newtfmdata then
36347 if not resources.marks then
36348 resources.marks={}
36349 end
36350 if not resources.sequences then
36351 resources.sequences={}
36352 end
36353 if not resources.features then
36354 resources.features={
36355 gsub={},
36356 gpos={},
36357 }
36358 end
36359 if not tfmdata.changed then
36360 tfmdata.changed={}
36361 end
36362 if not tfmdata.descriptions then
36363 tfmdata.descriptions=tfmdata.characters
36364 end
36365 otf.readers.addunicodetable(tfmdata)
36366 tfmenhancers.apply(tfmdata,filename)
36367 constructors.applymanipulators("tfm",tfmdata,features,trace_features,report_tfm)
36368 otf.readers.unifymissing(tfmdata)
36369 fonts.mappings.addtounicode(tfmdata,filename)
36370 tfmdata.tounicode=1
36371 local tounicode=fonts.mappings.tounicode
36372 for unicode,v in next,tfmdata.characters do
36373 local u=v.unicode
36374 if u then
36375 v.tounicode=tounicode(u)
36376 end
36377 end
36378 if tfmdata.usedbitmap then
36379 tfm.addtounicode(tfmdata)
36380 end
36381 end
36382 shared.processes=next(features) and tfm.setfeatures(tfmdata,features) or nil
36383 if size<0 then
36384 size=idiv(65536*-size,100)
36385 end
36386 parameters.factor=1
36387 parameters.units=1000
36388 parameters.size=size
36389 parameters.slant=parameters.slant or parameters[1] or 0
36390 parameters.space=parameters.space or parameters[2] or 0
36391 parameters.space_stretch=parameters.space_stretch or parameters[3] or 0
36392 parameters.space_shrink=parameters.space_shrink or parameters[4] or 0
36393 parameters.x_height=parameters.x_height or parameters[5] or 0
36394 parameters.quad=parameters.quad or parameters[6] or 0
36395 parameters.extra_space=parameters.extra_space or parameters[7] or 0
36396 constructors.enhanceparameters(parameters)
36397 properties.private=properties.private or tfmdata.private or privateoffset
36398 if newtfmdata then
36399 elseif constructors.resolvevirtualtoo then
36400 fonts.loggers.register(tfmdata,file.suffix(filename),specification)
36401 local vfname=findbinfile(specification.name,'ovf')
36402 if vfname and vfname~="" then
36403 local vfdata=loadvf(vfname,size)
36404 if vfdata then
36405 local chars=tfmdata.characters
36406 for k,v in next,vfdata.characters do
36407 chars[k].commands=v.commands
36408 end
36409 properties.virtualized=true
36410 tfmdata.fonts=vfdata.fonts
36411 tfmdata.type="virtual"
36412 local fontlist=vfdata.fonts
36413 local name=file.nameonly(filename)
36414 for i=1,#fontlist do
36415 local n=fontlist[i].name
36416 local s=fontlist[i].size
36417 local d=depth[filename]
36418 s=constructors.scaled(s,vfdata.designsize)
36419 if d>tfm.maxnestingdepth then
36420 report_defining("too deeply nested virtual font %a with size %a, max nesting depth %s",n,s,tfm.maxnestingdepth)
36421 fontlist[i]={ id=0 }
36422 elseif (d>1) and (s>tfm.maxnestingsize) then
36423 report_defining("virtual font %a exceeds size %s",n,s)
36424 fontlist[i]={ id=0 }
36425 else
36426 local t,id=constructors.readanddefine(n,s)
36427 fontlist[i]={ id=id }
36428 end
36429 end
36430 end
36431 end
36432 end
36433 properties.haskerns=true
36434 properties.hasligatures=true
36435 properties.hasitalics=true
36436 resources.unicodes={}
36437 resources.lookuptags={}
36438 depth[filename]=depth[filename]-1
36439 return tfmdata
36440 else
36441 depth[filename]=depth[filename]-1
36442 end
36443 end
36444 local function check_tfm(specification,fullname)
36445 local foundname=findbinfile(fullname,'tfm') or ""
36446 if foundname=="" then
36447 foundname=findbinfile(fullname,'ofm') or ""
36448 end
36449 if foundname=="" then
36450 foundname=fonts.names.getfilename(fullname,"tfm") or ""
36451 end
36452 if foundname~="" then
36453 specification.filename=foundname
36454 specification.format="ofm"
36455 return read_from_tfm(specification)
36456 elseif trace_defining then
36457 report_defining("loading tfm with name %a fails",specification.name)
36458 end
36459 end
36460 readers.check_tfm=check_tfm
36461 function readers.tfm(specification)
36462 local fullname=specification.filename or ""
36463 if fullname=="" then
36464 local forced=specification.forced or ""
36465 if forced~="" then
36466 fullname=specification.name.."."..forced
36467 else
36468 fullname=specification.name
36469 end
36470 end
36471 return check_tfm(specification,fullname)
36472 end
36473 readers.ofm=readers.tfm
36474 do
36475 local outfiles={}
36476 local tfmcache=table.setmetatableindex(function(t,tfmdata)
36477 local id=font.define(tfmdata)
36478 t[tfmdata]=id
36479 return id
36480 end)
36481 local encdone=table.setmetatableindex("table")
36482 function tfm.reencode(tfmdata,specification)
36483 local features=specification.features
36484 if not features then
36485 return
36486 end
36487 local features=features.normal
36488 if not features then
36489 return
36490 end
36491 local tfmfile=file.basename(tfmdata.name)
36492 local encfile=features.reencode
36493 local pfbfile=features.pfbfile
36494 local bitmap=features.bitmap
36495 if not encfile then
36496 return
36497 end
36498 local pfbfile=outfiles[tfmfile]
36499 if pfbfile==nil then
36500 if bitmap then
36501 pfbfile=false
36502 elseif type(pfbfile)~="string" then
36503 pfbfile=tfmfile
36504 end
36505 if type(pfbfile)=="string" then
36506 pfbfile=file.addsuffix(pfbfile,"pfb")
36507 report_tfm("using type1 shapes from %a for %a",pfbfile,tfmfile)
36508 else
36509 report_tfm("using bitmap shapes for %a",tfmfile)
36510 pfbfile=false
36511 end
36512 outfiles[tfmfile]=pfbfile
36513 end
36514 local encoding=false
36515 local vector=false
36516 if type(pfbfile)=="string" then
36517 local pfb=constructors.handlers.pfb
36518 if pfb and pfb.loadvector then
36519 local v,e=pfb.loadvector(pfbfile)
36520 if v then
36521 vector=v
36522 end
36523 if e then
36524 encoding=e
36525 end
36526 end
36527 end
36528 if type(encfile)=="string" and encfile~="auto" then
36529 encoding=fonts.encodings.load(file.addsuffix(encfile,"enc"))
36530 if encoding then
36531 encoding=encoding.vector
36532 end
36533 end
36534 if not encoding then
36535 report_tfm("bad encoding for %a, quitting",tfmfile)
36536 return
36537 end
36538 local unicoding=fonts.encodings.agl and fonts.encodings.agl.unicodes
36539 local virtualid=tfmcache[tfmdata]
36540 local tfmdata=table.copy(tfmdata)
36541 local characters={}
36542 local originals=tfmdata.characters
36543 local indices={}
36544 local parentfont={ "font",1 }
36545 local private=tfmdata.privateoffset or constructors.privateoffset
36546 local reported=encdone[tfmfile][encfile]
36547 local backmap=vector and table.swapped(vector)
36548 local done={}
36549 for index,name in sortedhash(encoding) do
36550 local unicode=unicoding[name]
36551 local original=originals[index]
36552 if original then
36553 if unicode then
36554 original.unicode=unicode
36555 else
36556 unicode=private
36557 private=private+1
36558 if not reported then
36559 report_tfm("glyph %a in font %a with encoding %a gets unicode %U",name,tfmfile,encfile,unicode)
36560 end
36561 end
36562 characters[unicode]=original
36563 indices[index]=unicode
36564 original.name=name
36565 if backmap then
36566 original.index=backmap[name]
36567 else
36568 original.commands={ parentfont,charcommand[index] }
36569 original.oindex=index
36570 end
36571 done[name]=true
36572 elseif not done[name] then
36573 report_tfm("bad index %a in font %a with name %a",index,tfmfile,name)
36574 end
36575 end
36576 encdone[tfmfile][encfile]=true
36577 for k,v in next,characters do
36578 local kerns=v.kerns
36579 if kerns then
36580 local t={}
36581 for k,v in next,kerns do
36582 local i=indices[k]
36583 if i then
36584 t[i]=v
36585 end
36586 end
36587 v.kerns=next(t) and t or nil
36588 end
36589 local ligatures=v.ligatures
36590 if ligatures then
36591 local t={}
36592 for k,v in next,ligatures do
36593 local i=indices[k]
36594 if i then
36595 t[i]=v
36596 v.char=indices[v.char]
36597 end
36598 end
36599 v.ligatures=next(t) and t or nil
36600 end
36601 end
36602 tfmdata.fonts={ { id=virtualid } }
36603 tfmdata.characters=characters
36604 tfmdata.fullname=tfmdata.fullname or tfmdata.name
36605 tfmdata.psname=file.nameonly(pfbfile or tfmdata.name)
36606 tfmdata.filename=pfbfile
36607 tfmdata.encodingbytes=2
36608 tfmdata.format="type1"
36609 tfmdata.tounicode=1
36610 tfmdata.embedding="subset"
36611 tfmdata.usedbitmap=bitmap and virtualid
36612 tfmdata.private=private
36613 return tfmdata
36614 end
36615 end
36616 do
36617 local template=[[
36618 /CIDInit /ProcSet findresource begin
36619 12 dict begin
36620 begincmap
36621 /CIDSystemInfo << /Registry (TeX) /Ordering (bitmap-%s) /Supplement 0 >> def
36622 /CMapName /TeX-bitmap-%s def
36623 /CMapType 2 def
36624 1 begincodespacerange
36625 <00> <FF>
36626 endcodespacerange
36627 %s beginbfchar
36628 %s
36629 endbfchar
36630 endcmap
36631 CMapName currentdict /CMap defineresource pop end
36632 end
36633 end
36634 ]]
36635 local flushstreamobject=lpdf and lpdf.flushstreamobject
36636 local setfontattributes=lpdf and lpdf.setfontattributes
36637 if not flushstreamobject then
36638 flushstreamobject=function(data)
36639 return pdf.obj { immediate=true,type="stream",string=data }
36640 end
36641 end
36642 if not setfontattributes then
36643 setfontattributes=function(id,data)
36644 return pdf.setfontattributes(id,data)
36645 end
36646 end
36647 function tfm.addtounicode(tfmdata)
36648 local id=tfmdata.usedbitmap
36649 local map={}
36650 local char={}
36651 for k,v in next,tfmdata.characters do
36652 local index=v.oindex
36653 local tounicode=v.tounicode
36654 if index and tounicode then
36655 map[index]=tounicode
36656 end
36657 end
36658 for k,v in sortedhash(map) do
36659 char[#char+1]=format("<%02X> <%s>",k,v)
36660 end
36661 char=concat(char,"\n")
36662 local stream=format(template,id,id,#char,char)
36663 local reference=flushstreamobject(stream,nil,true)
36664 setfontattributes(id,format("/ToUnicode %i 0 R",reference))
36665 end
36666 end
36667 do
36668 local everywhere={ ["*"]={ ["*"]=true } }
36669 local noflags={ false,false,false,false }
36670 local function enhance_normalize_features(data)
36671 local ligatures=setmetatableindex("table")
36672 local kerns=setmetatableindex("table")
36673 local characters=data.characters
36674 for u,c in next,characters do
36675 local l=c.ligatures
36676 local k=c.kerns
36677 if l then
36678 ligatures[u]=l
36679 for u,v in next,l do
36680 l[u]={ ligature=v.char }
36681 end
36682 c.ligatures=nil
36683 end
36684 if k then
36685 kerns[u]=k
36686 for u,v in next,k do
36687 k[u]=v
36688 end
36689 c.kerns=nil
36690 end
36691 end
36692 for u,l in next,ligatures do
36693 for k,v in next,l do
36694 local vl=v.ligature
36695 local dl=ligatures[vl]
36696 if dl then
36697 for kk,vv in next,dl do
36698 v[kk]=vv
36699 end
36700 end
36701 end
36702 end
36703 local features={
36704 gpos={},
36705 gsub={},
36706 }
36707 local sequences={
36708 }
36709 if next(ligatures) then
36710 features.gsub.liga=everywhere
36711 data.properties.hasligatures=true
36712 sequences[#sequences+1]={
36713 features={
36714 liga=everywhere,
36715 },
36716 flags=noflags,
36717 name="s_s_0",
36718 nofsteps=1,
36719 order={ "liga" },
36720 type="gsub_ligature",
36721 steps={
36722 {
36723 coverage=ligatures,
36724 },
36725 },
36726 }
36727 end
36728 if next(kerns) then
36729 features.gpos.kern=everywhere
36730 data.properties.haskerns=true
36731 sequences[#sequences+1]={
36732 features={
36733 kern=everywhere,
36734 },
36735 flags=noflags,
36736 name="p_s_0",
36737 nofsteps=1,
36738 order={ "kern" },
36739 type="gpos_pair",
36740 steps={
36741 {
36742 format="kern",
36743 coverage=kerns,
36744 },
36745 },
36746 }
36747 end
36748 data.resources.features=features
36749 data.resources.sequences=sequences
36750 data.shared.resources=data.shared.resources or resources
36751 end
36752 registertfmenhancer("normalize features",enhance_normalize_features)
36753 registertfmenhancer("check extra features",otfenhancers.enhance)
36754 end
36755 registertfmfeature {
36756 name="mode",
36757 description="mode",
36758 initializers={
36759 base=otf.modeinitializer,
36760 node=otf.modeinitializer,
36761 }
36762 }
36763 registertfmfeature {
36764 name="features",
36765 description="features",
36766 default=true,
36767 initializers={
36768 base=otf.basemodeinitializer,
36769 node=otf.nodemodeinitializer,
36770 },
36771 processors={
36772 node=otf.featuresprocessor,
36773 }
36774 }
36775
36776 end -- closure
36777
36778 do -- begin closure to overcome local limits and interference
36779
36780 if not modules then modules={} end modules ['font-lua']={
36781 version=1.001,
36782 comment="companion to font-ini.mkiv",
36783 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
36784 copyright="PRAGMA ADE / ConTeXt Development Team",
36785 license="see context related readme files"
36786 }
36787 local trace_defining=false trackers.register("fonts.defining",function(v) trace_defining=v end)
36788 local report_lua=logs.reporter("fonts","lua loading")
36789 local fonts=fonts
36790 local readers=fonts.readers
36791 fonts.formats.lua="lua"
36792 local function check_lua(specification,fullname)
36793 local fullname=resolvers.findfile(fullname) or ""
36794 if fullname~="" then
36795 local loader=loadfile(fullname)
36796 loader=loader and loader()
36797 return loader and loader(specification)
36798 end
36799 end
36800 readers.check_lua=check_lua
36801 function readers.lua(specification)
36802 local original=specification.specification
36803 if trace_defining then
36804 report_lua("using lua reader for %a",original)
36805 end
36806 local fullname=specification.filename or ""
36807 if fullname=="" then
36808 local forced=specification.forced or ""
36809 if forced~="" then
36810 fullname=specification.name.."."..forced
36811 else
36812 fullname=specification.name
36813 end
36814 end
36815 return check_lua(specification,fullname)
36816 end
36817
36818 end -- closure
36819
36820 do -- begin closure to overcome local limits and interference
36821
36822 if not modules then modules={} end modules ['font-def']={
36823 version=1.001,
36824 comment="companion to font-ini.mkiv",
36825 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
36826 copyright="PRAGMA ADE / ConTeXt Development Team",
36827 license="see context related readme files"
36828 }
36829 local lower,gsub=string.lower,string.gsub
36830 local tostring,next=tostring,next
36831 local lpegmatch=lpeg.match
36832 local suffixonly,removesuffix,basename=file.suffix,file.removesuffix,file.basename
36833 local formatters=string.formatters
36834 local sortedhash,sortedkeys=table.sortedhash,table.sortedkeys
36835 local allocate=utilities.storage.allocate
36836 local trace_defining=false trackers .register("fonts.defining",function(v) trace_defining=v end)
36837 local directive_embedall=false directives.register("fonts.embedall",function(v) directive_embedall=v end)
36838 trackers.register("fonts.loading","fonts.defining","otf.loading","afm.loading","tfm.loading")
36839 local report_defining=logs.reporter("fonts","defining")
36840 local fonts=fonts
36841 local fontdata=fonts.hashes.identifiers
36842 local readers=fonts.readers
36843 local definers=fonts.definers
36844 local specifiers=fonts.specifiers
36845 local constructors=fonts.constructors
36846 local fontgoodies=fonts.goodies
36847 readers.sequence=allocate { 'otf','ttf','afm','tfm','lua' }
36848 local variants=allocate()
36849 specifiers.variants=variants
36850 definers.methods=definers.methods or {}
36851 local internalized=allocate()
36852 local loadedfonts=constructors.loadedfonts
36853 local designsizes=constructors.designsizes
36854 local resolvefile=fontgoodies and fontgoodies.filenames and fontgoodies.filenames.resolve or function(s) return s end
36855 local function makespecification(specification,lookup,name,sub,method,detail,size)
36856 size=size or 655360
36857 if not lookup or lookup=="" then
36858 lookup=definers.defaultlookup
36859 end
36860 if trace_defining then
36861 report_defining("specification %a, lookup %a, name %a, sub %a, method %a, detail %a",
36862 specification,lookup,name,sub,method,detail)
36863 end
36864 local t={
36865 lookup=lookup,
36866 specification=specification,
36867 size=size,
36868 name=name,
36869 sub=sub,
36870 method=method,
36871 detail=detail,
36872 resolved="",
36873 forced="",
36874 features={},
36875 }
36876 return t
36877 end
36878 definers.makespecification=makespecification
36879 if context then
36880
36881 --removed
36882
36883 end
36884 definers.resolvers=definers.resolvers or {}
36885 local resolvers=definers.resolvers
36886 function resolvers.file(specification)
36887 local name=resolvefile(specification.name)
36888 local suffix=lower(suffixonly(name))
36889 if fonts.formats[suffix] then
36890 specification.forced=suffix
36891 specification.forcedname=name
36892 specification.name=removesuffix(name)
36893 else
36894 specification.name=name
36895 end
36896 end
36897 function resolvers.name(specification)
36898 local resolve=fonts.names.resolve
36899 if resolve then
36900 local resolved,sub,subindex,instance=resolve(specification.name,specification.sub,specification)
36901 if resolved then
36902 specification.resolved=resolved
36903 specification.sub=sub
36904 specification.subindex=subindex
36905 if instance then
36906 specification.instance=instance
36907 local features=specification.features
36908 if not features then
36909 features={}
36910 specification.features=features
36911 end
36912 local normal=features.normal
36913 if not normal then
36914 normal={}
36915 features.normal=normal
36916 end
36917 normal.instance=instance
36918 end
36919 local suffix=lower(suffixonly(resolved))
36920 if fonts.formats[suffix] then
36921 specification.forced=suffix
36922 specification.forcedname=resolved
36923 specification.name=removesuffix(resolved)
36924 else
36925 specification.name=resolved
36926 end
36927 end
36928 else
36929 resolvers.file(specification)
36930 end
36931 end
36932 function resolvers.spec(specification)
36933 local resolvespec=fonts.names.resolvespec
36934 if resolvespec then
36935 local resolved,sub,subindex=resolvespec(specification.name,specification.sub,specification)
36936 if resolved then
36937 specification.resolved=resolved
36938 specification.sub=sub
36939 specification.subindex=subindex
36940 specification.forced=lower(suffixonly(resolved))
36941 specification.forcedname=resolved
36942 specification.name=removesuffix(resolved)
36943 end
36944 else
36945 resolvers.name(specification)
36946 end
36947 end
36948 function definers.resolve(specification)
36949 if not specification.resolved or specification.resolved=="" then
36950 local r=resolvers[specification.lookup]
36951 if r then
36952 r(specification)
36953 end
36954 end
36955 if specification.forced=="" then
36956 specification.forced=nil
36957 specification.forcedname=nil
36958 end
36959 specification.hash=lower(specification.name..' @ '..constructors.hashfeatures(specification))
36960 if specification.sub and specification.sub~="" then
36961 specification.hash=specification.sub..' @ '..specification.hash
36962 end
36963 return specification
36964 end
36965 function definers.applypostprocessors(tfmdata)
36966 local postprocessors=tfmdata.postprocessors
36967 if postprocessors then
36968 local properties=tfmdata.properties
36969 for i=1,#postprocessors do
36970 local extrahash=postprocessors[i](tfmdata)
36971 if type(extrahash)=="string" and extrahash~="" then
36972 extrahash=gsub(lower(extrahash),"[^a-z]","-")
36973 properties.fullname=formatters["%s-%s"](properties.fullname,extrahash)
36974 end
36975 end
36976 end
36977 return tfmdata
36978 end
36979 local function checkembedding(tfmdata)
36980 local properties=tfmdata.properties
36981 local embedding
36982 if directive_embedall then
36983 embedding="full"
36984 elseif properties and properties.filename and constructors.dontembed[properties.filename] then
36985 embedding="no"
36986 else
36987 embedding="subset"
36988 end
36989 if properties then
36990 properties.embedding=embedding
36991 else
36992 tfmdata.properties={ embedding=embedding }
36993 end
36994 tfmdata.embedding=embedding
36995 end
36996 local function checkfeatures(tfmdata)
36997 local resources=tfmdata.resources
36998 local shared=tfmdata.shared
36999 if resources and shared then
37000 local features=resources.features
37001 local usedfeatures=shared.features
37002 if features and usedfeatures then
37003 local usedlanguage=usedfeatures.language or "dflt"
37004 local usedscript=usedfeatures.script or "dflt"
37005 local function check(what)
37006 if what then
37007 local foundlanguages={}
37008 for feature,scripts in next,what do
37009 if usedscript=="auto" or scripts["*"] then
37010 elseif not scripts[usedscript] then
37011 else
37012 for script,languages in next,scripts do
37013 if languages["*"] then
37014 elseif context and not languages[usedlanguage] then
37015 report_defining("font %!font:name!, feature %a, script %a, no language %a",
37016 tfmdata,feature,script,usedlanguage)
37017 end
37018 end
37019 end
37020 for script,languages in next,scripts do
37021 for language in next,languages do
37022 foundlanguages[language]=true
37023 end
37024 end
37025 end
37026 if false then
37027 foundlanguages["*"]=nil
37028 foundlanguages=sortedkeys(foundlanguages)
37029 for feature,scripts in sortedhash(what) do
37030 for script,languages in next,scripts do
37031 if not languages["*"] then
37032 for i=1,#foundlanguages do
37033 local language=foundlanguages[i]
37034 if context and not languages[language] then
37035 report_defining("font %!font:name!, feature %a, script %a, no language %a",
37036 tfmdata,feature,script,language)
37037 end
37038 end
37039 end
37040 end
37041 end
37042 end
37043 end
37044 end
37045 check(features.gsub)
37046 check(features.gpos)
37047 end
37048 end
37049 end
37050 function definers.loadfont(specification)
37051 local hash=constructors.hashinstance(specification)
37052 local tfmdata=loadedfonts[hash]
37053 if not tfmdata then
37054 local forced=specification.forced or ""
37055 if forced~="" then
37056 local reader=readers[lower(forced)]
37057 tfmdata=reader and reader(specification)
37058 if not tfmdata then
37059 report_defining("forced type %a of %a not found",forced,specification.name)
37060 end
37061 else
37062 local sequence=readers.sequence
37063 for s=1,#sequence do
37064 local reader=sequence[s]
37065 if readers[reader] then
37066 if trace_defining then
37067 report_defining("trying (reader sequence driven) type %a for %a with file %a",reader,specification.name,specification.filename)
37068 end
37069 tfmdata=readers[reader](specification)
37070 if tfmdata then
37071 break
37072 else
37073 specification.filename=nil
37074 end
37075 end
37076 end
37077 end
37078 if tfmdata then
37079 tfmdata=definers.applypostprocessors(tfmdata)
37080 checkembedding(tfmdata)
37081 loadedfonts[hash]=tfmdata
37082 designsizes[specification.hash]=tfmdata.parameters.designsize
37083 checkfeatures(tfmdata)
37084 end
37085 end
37086 if not tfmdata then
37087 report_defining("font with asked name %a is not found using lookup %a",specification.name,specification.lookup)
37088 end
37089 return tfmdata
37090 end
37091 function constructors.readanddefine(name,size)
37092 local specification=definers.analyze(name,size)
37093 local method=specification.method
37094 if method and variants[method] then
37095 specification=variants[method](specification)
37096 end
37097 specification=definers.resolve(specification)
37098 local hash=constructors.hashinstance(specification)
37099 local id=definers.registered(hash)
37100 if not id then
37101 local tfmdata=definers.loadfont(specification)
37102 if tfmdata then
37103 tfmdata.properties.hash=hash
37104 id=font.define(tfmdata)
37105 definers.register(tfmdata,id)
37106 else
37107 id=0
37108 end
37109 end
37110 return fontdata[id],id
37111 end
37112 function definers.registered(hash)
37113 local id=internalized[hash]
37114 return id,id and fontdata[id]
37115 end
37116 function definers.register(tfmdata,id)
37117 if tfmdata and id then
37118 local hash=tfmdata.properties.hash
37119 if not hash then
37120 report_defining("registering font, id %a, name %a, invalid hash",id,tfmdata.properties.filename or "?")
37121 elseif not internalized[hash] then
37122 internalized[hash]=id
37123 if trace_defining then
37124 report_defining("registering font, id %s, hash %a",id,hash)
37125 end
37126 fontdata[id]=tfmdata
37127 end
37128 end
37129 end
37130 function definers.read(specification,size,id)
37131 statistics.starttiming(fonts)
37132 if type(specification)=="string" then
37133 specification=definers.analyze(specification,size)
37134 end
37135 local method=specification.method
37136 if method and variants[method] then
37137 specification=variants[method](specification)
37138 end
37139 specification=definers.resolve(specification)
37140 local hash=constructors.hashinstance(specification)
37141 local tfmdata=definers.registered(hash)
37142 if tfmdata then
37143 if trace_defining then
37144 report_defining("already hashed: %s",hash)
37145 end
37146 else
37147 tfmdata=definers.loadfont(specification)
37148 if tfmdata then
37149 tfmdata.original=specification.specification
37150 if trace_defining then
37151 report_defining("loaded and hashed: %s",hash)
37152 end
37153 tfmdata.properties.hash=hash
37154 if id then
37155 definers.register(tfmdata,id)
37156 end
37157 else
37158 if trace_defining then
37159 report_defining("not loaded and hashed: %s",hash)
37160 end
37161 end
37162 end
37163 if not tfmdata then
37164 report_defining("unknown font %a, loading aborted",specification.name)
37165 elseif trace_defining and type(tfmdata)=="table" then
37166 local properties=tfmdata.properties or {}
37167 local parameters=tfmdata.parameters or {}
37168 report_defining("using %a font with id %a, name %a, size %a, bytes %a, encoding %a, fullname %a, filename %a",
37169 properties.format or "unknown",id or "-",properties.name,parameters.size,properties.encodingbytes,
37170 properties.encodingname,properties.fullname,basename(properties.filename))
37171 end
37172 statistics.stoptiming(fonts)
37173 return tfmdata
37174 end
37175 function font.getfont(id)
37176 return fontdata[id]
37177 end
37178 if not context then
37179 callbacks.register('define_font',definers.read,"definition of fonts (tfmdata preparation)")
37180 end
37181
37182 end -- closure
37183
37184 do -- begin closure to overcome local limits and interference
37185
37186 if not modules then modules={} end modules ['font-shp']={
37187 version=1.001,
37188 comment="companion to font-ini.mkiv",
37189 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
37190 copyright="PRAGMA ADE / ConTeXt Development Team",
37191 license="see context related readme files"
37192 }
37193 local tonumber,next=tonumber,next
37194 local concat=table.concat
37195 local formatters,lower=string.formatters,string.lower
37196 local otf=fonts.handlers.otf
37197 local afm=fonts.handlers.afm
37198 local pfb=fonts.handlers.pfb
37199 local hashes=fonts.hashes
37200 local identifiers=hashes.identifiers
37201 local version=otf.version or 0.015
37202 local shapescache=containers.define("fonts","shapes",version,true)
37203 local streamscache=containers.define("fonts","streams",version,true)
37204 local compact_streams=false
37205 directives.register("fonts.streams.compact",function(v) compact_streams=v end)
37206 local function packoutlines(data,makesequence)
37207 local subfonts=data.subfonts
37208 if subfonts then
37209 for i=1,#subfonts do
37210 packoutlines(subfonts[i],makesequence)
37211 end
37212 return
37213 end
37214 local common=data.segments
37215 if common then
37216 return
37217 end
37218 local glyphs=data.glyphs
37219 if not glyphs then
37220 return
37221 end
37222 if makesequence then
37223 for index=0,#glyphs do
37224 local glyph=glyphs[index]
37225 if glyph then
37226 local segments=glyph.segments
37227 if segments then
37228 local sequence={}
37229 local nofsequence=0
37230 for i=1,#segments do
37231 local segment=segments[i]
37232 local nofsegment=#segment
37233 nofsequence=nofsequence+1
37234 sequence[nofsequence]=segment[nofsegment]
37235 for i=1,nofsegment-1 do
37236 nofsequence=nofsequence+1
37237 sequence[nofsequence]=segment[i]
37238 end
37239 end
37240 glyph.sequence=sequence
37241 glyph.segments=nil
37242 end
37243 end
37244 end
37245 else
37246 local hash={}
37247 local common={}
37248 local reverse={}
37249 local last=0
37250 for index=0,#glyphs do
37251 local glyph=glyphs[index]
37252 if glyph then
37253 local segments=glyph.segments
37254 if segments then
37255 for i=1,#segments do
37256 local h=concat(segments[i]," ")
37257 hash[h]=(hash[h] or 0)+1
37258 end
37259 end
37260 end
37261 end
37262 for index=0,#glyphs do
37263 local glyph=glyphs[index]
37264 if glyph then
37265 local segments=glyph.segments
37266 if segments then
37267 for i=1,#segments do
37268 local segment=segments[i]
37269 local h=concat(segment," ")
37270 if hash[h]>1 then
37271 local idx=reverse[h]
37272 if not idx then
37273 last=last+1
37274 reverse[h]=last
37275 common[last]=segment
37276 idx=last
37277 end
37278 segments[i]=idx
37279 end
37280 end
37281 end
37282 end
37283 end
37284 if last>0 then
37285 data.segments=common
37286 end
37287 end
37288 end
37289 local function unpackoutlines(data)
37290 local subfonts=data.subfonts
37291 if subfonts then
37292 for i=1,#subfonts do
37293 unpackoutlines(subfonts[i])
37294 end
37295 return
37296 end
37297 local common=data.segments
37298 if not common then
37299 return
37300 end
37301 local glyphs=data.glyphs
37302 if not glyphs then
37303 return
37304 end
37305 for index=0,#glyphs do
37306 local glyph=glyphs[index]
37307 if glyph then
37308 local segments=glyph.segments
37309 if segments then
37310 for i=1,#segments do
37311 local c=common[segments[i]]
37312 if c then
37313 segments[i]=c
37314 end
37315 end
37316 end
37317 end
37318 end
37319 data.segments=nil
37320 end
37321 local readers=otf.readers
37322 local cleanname=otf.readers.helpers.cleanname
37323 local function makehash(filename,sub,instance)
37324 local name=cleanname(file.basename(filename))
37325 if instance then
37326 return formatters["%s-%s-%s"](name,sub or 0,cleanname(instance))
37327 else
37328 return formatters["%s-%s"] (name,sub or 0)
37329 end
37330 end
37331 local function loadoutlines(cache,filename,sub,instance)
37332 local base=file.basename(filename)
37333 local name=file.removesuffix(base)
37334 local kind=file.suffix(filename)
37335 local attr=lfs.attributes(filename)
37336 local size=attr and attr.size or 0
37337 local time=attr and attr.modification or 0
37338 local sub=tonumber(sub)
37339 if size>0 and (kind=="otf" or kind=="ttf" or kind=="tcc") then
37340 local hash=makehash(filename,sub,instance)
37341 data=containers.read(cache,hash)
37342 if not data or data.time~=time or data.size~=size then
37343 data=otf.readers.loadshapes(filename,sub,instance)
37344 if data then
37345 data.size=size
37346 data.format=data.format or (kind=="otf" and "opentype") or "truetype"
37347 data.time=time
37348 packoutlines(data)
37349 containers.write(cache,hash,data)
37350 data=containers.read(cache,hash)
37351 end
37352 end
37353 unpackoutlines(data)
37354 elseif size>0 and (kind=="pfb") then
37355 local hash=containers.cleanname(base)
37356 data=containers.read(cache,hash)
37357 if not data or data.time~=time or data.size~=size then
37358 data=afm.readers.loadshapes(filename)
37359 if data then
37360 data.size=size
37361 data.format="type1"
37362 data.time=time
37363 packoutlines(data)
37364 containers.write(cache,hash,data)
37365 data=containers.read(cache,hash)
37366 end
37367 end
37368 unpackoutlines(data)
37369 else
37370 data={
37371 filename=filename,
37372 size=0,
37373 time=time,
37374 format="unknown",
37375 units=1000,
37376 glyphs={}
37377 }
37378 end
37379 return data
37380 end
37381 local function cachethem(cache,hash,data)
37382 containers.write(cache,hash,data,compact_streams)
37383 return containers.read(cache,hash)
37384 end
37385 local function loadstreams(cache,filename,sub,instance)
37386 local base=file.basename(filename)
37387 local name=file.removesuffix(base)
37388 local kind=lower(file.suffix(filename))
37389 local attr=lfs.attributes(filename)
37390 local size=attr and attr.size or 0
37391 local time=attr and attr.modification or 0
37392 local sub=tonumber(sub)
37393 if size>0 and (kind=="otf" or kind=="ttf" or kind=="ttc") then
37394 local hash=makehash(filename,sub,instance)
37395 data=containers.read(cache,hash)
37396 if not data or data.time~=time or data.size~=size then
37397 data=otf.readers.loadshapes(filename,sub,instance,true)
37398 if data then
37399 local glyphs=data.glyphs
37400 local streams={}
37401 if glyphs then
37402 for i=0,#glyphs do
37403 local glyph=glyphs[i]
37404 if glyph then
37405 streams[i]=glyph.stream or ""
37406 else
37407 streams[i]=""
37408 end
37409 end
37410 end
37411 data.streams=streams
37412 data.glyphs=nil
37413 data.size=size
37414 data.format=data.format or (kind=="otf" and "opentype") or "truetype"
37415 data.time=time
37416 data=cachethem(cache,hash,data)
37417 end
37418 end
37419 elseif size>0 and (kind=="pfb") then
37420 local hash=makehash(filename,sub,instance)
37421 data=containers.read(cache,hash)
37422 if not data or data.time~=time or data.size~=size then
37423 local names,encoding,streams,metadata=pfb.loadvector(filename,false,true)
37424 if streams then
37425 local fontbbox=metadata.fontbbox or { 0,0,0,0 }
37426 for i=0,#streams do
37427 local s=streams[i]
37428 streams[i]=s.stream or "\14"
37429 end
37430 data={
37431 filename=filename,
37432 size=size,
37433 time=time,
37434 format="type1",
37435 streams=streams,
37436 fontheader={
37437 fontversion=metadata.version,
37438 units=1000,
37439 xmin=fontbbox[1],
37440 ymin=fontbbox[2],
37441 xmax=fontbbox[3],
37442 ymax=fontbbox[4],
37443 },
37444 horizontalheader={
37445 ascender=0,
37446 descender=0,
37447 },
37448 maximumprofile={
37449 nofglyphs=#streams+1,
37450 },
37451 names={
37452 copyright=metadata.copyright,
37453 family=metadata.familyname,
37454 fullname=metadata.fullname,
37455 fontname=metadata.fontname,
37456 subfamily=metadata.subfamilyname,
37457 trademark=metadata.trademark,
37458 notice=metadata.notice,
37459 version=metadata.version,
37460 },
37461 cffinfo={
37462 familyname=metadata.familyname,
37463 fullname=metadata.fullname,
37464 italicangle=metadata.italicangle,
37465 monospaced=metadata.isfixedpitch and true or false,
37466 underlineposition=metadata.underlineposition,
37467 underlinethickness=metadata.underlinethickness,
37468 weight=metadata.weight,
37469 },
37470 }
37471 data=cachethem(cache,hash,data)
37472 end
37473 end
37474 else
37475 data={
37476 filename=filename,
37477 size=0,
37478 time=time,
37479 format="unknown",
37480 streams={}
37481 }
37482 end
37483 return data
37484 end
37485 local loadedshapes={}
37486 local loadedstreams={}
37487 local function loadoutlinedata(fontdata,streams)
37488 local properties=fontdata.properties
37489 local filename=properties.filename
37490 local subindex=fontdata.subindex
37491 local instance=properties.instance
37492 local hash=makehash(filename,subindex,instance)
37493 local loaded=loadedshapes[hash]
37494 if not loaded then
37495 loaded=loadoutlines(shapescache,filename,subindex,instance)
37496 loadedshapes[hash]=loaded
37497 end
37498 return loaded
37499 end
37500 hashes.shapes=table.setmetatableindex(function(t,k)
37501 local f=identifiers[k]
37502 if f then
37503 return loadoutlinedata(f)
37504 end
37505 end)
37506 local function getstreamhash(fontid)
37507 local fontdata=identifiers[fontid]
37508 if fontdata then
37509 local properties=fontdata.properties
37510 local fonthash=makehash(properties.filename,properties.subfont,properties.instance)
37511 return fonthash,fontdata
37512 end
37513 end
37514 local function loadstreamdata(fontdata)
37515 local properties=fontdata.properties
37516 local shared=fontdata.shared
37517 local rawdata=shared and shared.rawdata
37518 local metadata=rawdata and rawdata.metadata
37519 local filename=properties.filename
37520 local subindex=metadata and metadata.subfontindex
37521 local instance=properties.instance
37522 local hash=makehash(filename,subindex,instance)
37523 local loaded=loadedstreams[hash]
37524 if not loaded then
37525 loaded=loadstreams(streamscache,filename,subindex,instance)
37526 loadedstreams[hash]=loaded
37527 end
37528 return loaded
37529 end
37530 hashes.streams=table.setmetatableindex(function(t,k)
37531 local f=identifiers[k]
37532 if f then
37533 return loadstreamdata(f)
37534 end
37535 end)
37536 otf.loadoutlinedata=loadoutlinedata
37537 otf.loadstreamdata=loadstreamdata
37538 otf.loadshapes=loadshapes
37539 otf.getstreamhash=getstreamhash
37540 local streams=fonts.hashes.streams
37541 callback.register("glyph_stream_provider",function(id,index,mode)
37542 if id>0 then
37543 local streams=streams[id].streams
37544 if streams then
37545 return streams[index] or ""
37546 end
37547 end
37548 return ""
37549 end)
37550
37551 end -- closure
37552
37553 do -- begin closure to overcome local limits and interference
37554
37555 if not modules then modules={} end modules ['luatex-fonts-def']={
37556 version=1.001,
37557 comment="companion to luatex-*.tex",
37558 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
37559 copyright="PRAGMA ADE / ConTeXt Development Team",
37560 license="see context related readme files"
37561 }
37562 if context then
37563 --removed
37564
37565 end
37566 local fonts=fonts
37567 fonts.constructors.namemode="specification"
37568 function fonts.definers.getspecification(str)
37569 return "",str,"",":",str
37570 end
37571 local list={}
37572 local function issome () list.lookup='name' end
37573 local function isfile () list.lookup='file' end
37574 local function isname () list.lookup='name' end
37575 local function thename(s) list.name=s end
37576 local function issub (v) list.sub=v end
37577 local function iscrap (s) list.crap=string.lower(s) end
37578 local function iskey (k,v) list[k]=v end
37579 local function istrue (s) list[s]=true end
37580 local function isfalse(s) list[s]=false end
37581 local P,S,R,C,Cs=lpeg.P,lpeg.S,lpeg.R,lpeg.C,lpeg.Cs
37582 local spaces=P(" ")^0
37583 local namespec=Cs((P("{")/"")*(1-S("}"))^0*(P("}")/"")+(1-S("/:("))^0)
37584 local crapspec=spaces*P("/")*(((1-P(":"))^0)/iscrap)*spaces
37585 local filename_1=P("file:")/isfile*(namespec/thename)
37586 local filename_2=P("[")*P(true)/isfile*(((1-P("]"))^0)/thename)*P("]")
37587 local fontname_1=P("name:")/isname*(namespec/thename)
37588 local fontname_2=P(true)/issome*(namespec/thename)
37589 local sometext=R("az","AZ","09")^1
37590 local somekey=R("az","AZ","09")^1
37591 local somevalue=(P("{")/"")*(1-P("}"))^0*(P("}")/"")+(1-S(";"))^1
37592 local truevalue=P("+")*spaces*(sometext/istrue)
37593 local falsevalue=P("-")*spaces*(sometext/isfalse)
37594 local keyvalue=(C(somekey)*spaces*P("=")*spaces*C(somevalue))/iskey
37595 local somevalue=sometext/istrue
37596 local subvalue=P("(")*(C(P(1-S("()"))^1)/issub)*P(")")
37597 local option=spaces*(keyvalue+falsevalue+truevalue+somevalue)*spaces
37598 local options=P(":")*spaces*(P(";")^0*option)^0
37599 local pattern=(filename_1+filename_2+fontname_1+fontname_2)*subvalue^0*crapspec^0*options^0
37600 function fonts.definers.analyze(str,size)
37601 local specification=fonts.definers.makespecification(str,nil,nil,nil,":",nil,size)
37602 list={}
37603 lpeg.match(pattern,str)
37604 list.crap=nil
37605 if list.name then
37606 specification.name=list.name
37607 list.name=nil
37608 end
37609 if list.lookup then
37610 specification.lookup=list.lookup
37611 list.lookup=nil
37612 end
37613 if list.sub then
37614 specification.sub=list.sub
37615 list.sub=nil
37616 end
37617 specification.features.normal=fonts.handlers.otf.features.normalize(list)
37618 list=nil
37619 return specification
37620 end
37621 function fonts.definers.applypostprocessors(tfmdata)
37622 local postprocessors=tfmdata.postprocessors
37623 if postprocessors then
37624 for i=1,#postprocessors do
37625 local extrahash=postprocessors[i](tfmdata)
37626 if type(extrahash)=="string" and extrahash~="" then
37627 extrahash=string.gsub(lower(extrahash),"[^a-z]","-")
37628 tfmdata.properties.fullname=format("%s-%s",tfmdata.properties.fullname,extrahash)
37629 end
37630 end
37631 end
37632 return tfmdata
37633 end
37634
37635 end -- closure
37636
37637 do -- begin closure to overcome local limits and interference
37638
37639 if not modules then modules={} end modules ['luatex-fonts-ext']={
37640 version=1.001,
37641 comment="companion to luatex-*.tex",
37642 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
37643 copyright="PRAGMA ADE / ConTeXt Development Team",
37644 license="see context related readme files"
37645 }
37646 if context then
37647 --removed
37648
37649 end
37650 local byte=string.byte
37651 local fonts=fonts
37652 local handlers=fonts.handlers
37653 local otf=handlers.otf
37654 local afm=handlers.afm
37655 local registerotffeature=otf.features.register
37656 local registerafmfeature=afm.features.register
37657 function fonts.loggers.onetimemessage() end
37658 fonts.protrusions=fonts.protrusions or {}
37659 fonts.protrusions.setups=fonts.protrusions.setups or {}
37660 local setups=fonts.protrusions.setups
37661 setups['default']={
37662 factor=1,
37663 left=1,
37664 right=1,
37665 [0x002C]={ 0,1 },
37666 [0x002E]={ 0,1 },
37667 [0x003A]={ 0,1 },
37668 [0x003B]={ 0,1 },
37669 [0x002D]={ 0,1 },
37670 [0x2013]={ 0,0.50 },
37671 [0x2014]={ 0,0.33 },
37672 [0x3001]={ 0,1 },
37673 [0x3002]={ 0,1 },
37674 [0x060C]={ 0,1 },
37675 [0x061B]={ 0,1 },
37676 [0x06D4]={ 0,1 },
37677 }
37678 local function initializeprotrusion(tfmdata,value)
37679 if value then
37680 local setup=setups[value]
37681 if setup then
37682 local factor,left,right=setup.factor or 1,setup.left or 1,setup.right or 1
37683 local emwidth=tfmdata.parameters.quad
37684 tfmdata.parameters.protrusion={
37685 auto=true,
37686 }
37687 for i,chr in next,tfmdata.characters do
37688 local v,pl,pr=setup[i],nil,nil
37689 if v then
37690 pl,pr=v[1],v[2]
37691 end
37692 if pl and pl~=0 then chr.left_protruding=left*pl*factor end
37693 if pr and pr~=0 then chr.right_protruding=right*pr*factor end
37694 end
37695 end
37696 end
37697 end
37698 local specification={
37699 name="protrusion",
37700 description="shift characters into the left and or right margin",
37701 initializers={
37702 base=initializeprotrusion,
37703 node=initializeprotrusion,
37704 }
37705 }
37706 registerotffeature(specification)
37707 registerafmfeature(specification)
37708 fonts.expansions=fonts.expansions or {}
37709 fonts.expansions.setups=fonts.expansions.setups or {}
37710 local setups=fonts.expansions.setups
37711 setups['default']={
37712 stretch=2,
37713 shrink=2,
37714 step=.5,
37715 factor=1,
37716 [byte('A')]=0.5,[byte('B')]=0.7,[byte('C')]=0.7,[byte('D')]=0.5,[byte('E')]=0.7,
37717 [byte('F')]=0.7,[byte('G')]=0.5,[byte('H')]=0.7,[byte('K')]=0.7,[byte('M')]=0.7,
37718 [byte('N')]=0.7,[byte('O')]=0.5,[byte('P')]=0.7,[byte('Q')]=0.5,[byte('R')]=0.7,
37719 [byte('S')]=0.7,[byte('U')]=0.7,[byte('W')]=0.7,[byte('Z')]=0.7,
37720 [byte('a')]=0.7,[byte('b')]=0.7,[byte('c')]=0.7,[byte('d')]=0.7,[byte('e')]=0.7,
37721 [byte('g')]=0.7,[byte('h')]=0.7,[byte('k')]=0.7,[byte('m')]=0.7,[byte('n')]=0.7,
37722 [byte('o')]=0.7,[byte('p')]=0.7,[byte('q')]=0.7,[byte('s')]=0.7,[byte('u')]=0.7,
37723 [byte('w')]=0.7,[byte('z')]=0.7,
37724 [byte('2')]=0.7,[byte('3')]=0.7,[byte('6')]=0.7,[byte('8')]=0.7,[byte('9')]=0.7,
37725 }
37726 local function initializeexpansion(tfmdata,value)
37727 if value then
37728 local setup=setups[value]
37729 if setup then
37730 local factor=setup.factor or 1
37731 tfmdata.parameters.expansion={
37732 stretch=10*(setup.stretch or 0),
37733 shrink=10*(setup.shrink or 0),
37734 step=10*(setup.step or 0),
37735 auto=true,
37736 }
37737 for i,chr in next,tfmdata.characters do
37738 local v=setup[i]
37739 if v and v~=0 then
37740 chr.expansion_factor=v*factor
37741 else
37742 chr.expansion_factor=factor
37743 end
37744 end
37745 end
37746 end
37747 end
37748 local specification={
37749 name="expansion",
37750 description="apply hz optimization",
37751 initializers={
37752 base=initializeexpansion,
37753 node=initializeexpansion,
37754 }
37755 }
37756 registerotffeature(specification)
37757 registerafmfeature(specification)
37758 if not otf.features.normalize then
37759 otf.features.normalize=function(t)
37760 if t.rand then
37761 t.rand="random"
37762 end
37763 return t
37764 end
37765 end
37766 function fonts.helpers.nametoslot(name)
37767 local t=type(name)
37768 if t=="string" then
37769 local tfmdata=fonts.hashes.identifiers[currentfont()]
37770 local shared=tfmdata and tfmdata.shared
37771 local fntdata=shared and shared.rawdata
37772 return fntdata and fntdata.resources.unicodes[name]
37773 elseif t=="number" then
37774 return n
37775 end
37776 end
37777 fonts.encodings=fonts.encodings or {}
37778 local reencodings={}
37779 fonts.encodings.reencodings=reencodings
37780 local function specialreencode(tfmdata,value)
37781 local encoding=value and reencodings[value]
37782 if encoding then
37783 local temp={}
37784 local char=tfmdata.characters
37785 for k,v in next,encoding do
37786 temp[k]=char[v]
37787 end
37788 for k,v in next,temp do
37789 char[k]=temp[k]
37790 end
37791 return string.format("reencoded:%s",value)
37792 end
37793 end
37794 local function initialize(tfmdata,value)
37795 tfmdata.postprocessors=tfmdata.postprocessors or {}
37796 table.insert(tfmdata.postprocessors,
37797 function(tfmdata)
37798 return specialreencode(tfmdata,value)
37799 end
37800 )
37801 end
37802 registerotffeature {
37803 name="reencode",
37804 description="reencode characters",
37805 manipulators={
37806 base=initialize,
37807 node=initialize,
37808 }
37809 }
37810 local function initialize(tfmdata,key,value)
37811 if value then
37812 tfmdata.mathparameters=nil
37813 end
37814 end
37815 registerotffeature {
37816 name="ignoremathconstants",
37817 description="ignore math constants table",
37818 initializers={
37819 base=initialize,
37820 node=initialize,
37821 }
37822 }
37823
37824 end -- closure
37825
37826 do -- begin closure to overcome local limits and interference
37827
37828 if not modules then modules={} end modules ['font-imp-tex']={
37829 version=1.001,
37830 comment="companion to font-ini.mkiv",
37831 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
37832 copyright="PRAGMA ADE / ConTeXt Development Team",
37833 license="see context related readme files"
37834 }
37835 local next=next
37836 local fonts=fonts
37837 local otf=fonts.handlers.otf
37838 local registerotffeature=otf.features.register
37839 local addotffeature=otf.addfeature
37840 local tlig={
37841 type="ligature",
37842 order={ "tlig" },
37843 prepend=true,
37844 data={
37845 [0x2013]={ 0x002D,0x002D },
37846 [0x2014]={ 0x002D,0x002D,0x002D },
37847 },
37848 }
37849 local tquo={
37850 type="ligature",
37851 order={ "tquo" },
37852 prepend=true,
37853 data={
37854 [0x201C]={ 0x0060,0x0060 },
37855 [0x201D]={ 0x0027,0x0027 },
37856 [0x201E]={ 0x002C,0x002C },
37857 },
37858 }
37859 local trep={
37860 type="substitution",
37861 order={ "trep" },
37862 prepend=true,
37863 data={
37864 [0x0027]=0x2019,
37865 },
37866 }
37867 addotffeature("trep",trep)
37868 addotffeature("tlig",tlig)
37869 addotffeature("tquo",tquo)
37870 registerotffeature { name="tlig",description="tex ligatures" }
37871 registerotffeature { name="tquo",description="tex quotes" }
37872 registerotffeature { name="trep",description="tex replacements" }
37873 local anum_arabic={
37874 [0x0030]=0x0660,
37875 [0x0031]=0x0661,
37876 [0x0032]=0x0662,
37877 [0x0033]=0x0663,
37878 [0x0034]=0x0664,
37879 [0x0035]=0x0665,
37880 [0x0036]=0x0666,
37881 [0x0037]=0x0667,
37882 [0x0038]=0x0668,
37883 [0x0039]=0x0669,
37884 }
37885 local anum_persian={
37886 [0x0030]=0x06F0,
37887 [0x0031]=0x06F1,
37888 [0x0032]=0x06F2,
37889 [0x0033]=0x06F3,
37890 [0x0034]=0x06F4,
37891 [0x0035]=0x06F5,
37892 [0x0036]=0x06F6,
37893 [0x0037]=0x06F7,
37894 [0x0038]=0x06F8,
37895 [0x0039]=0x06F9,
37896 }
37897 local function valid(data)
37898 local features=data.resources.features
37899 if features then
37900 for k,v in next,features do
37901 for k,v in next,v do
37902 if v.arab then
37903 return true
37904 end
37905 end
37906 end
37907 end
37908 end
37909 local specification={
37910 {
37911 type="substitution",
37912 features={ arab={ urd=true,dflt=true } },
37913 order={ "anum" },
37914 data=anum_arabic,
37915 valid=valid,
37916 },
37917 {
37918 type="substitution",
37919 features={ arab={ urd=true } },
37920 order={ "anum" },
37921 data=anum_persian,
37922 valid=valid,
37923 },
37924 }
37925 addotffeature("anum",specification)
37926 registerotffeature {
37927 name="anum",
37928 description="arabic digits",
37929 }
37930
37931 end -- closure
37932
37933 do -- begin closure to overcome local limits and interference
37934
37935 if not modules then modules={} end modules ['font-imp-ligatures']={
37936 version=1.001,
37937 comment="companion to font-ini.mkiv",
37938 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
37939 copyright="PRAGMA ADE / ConTeXt Development Team",
37940 license="see context related readme files"
37941 }
37942 local lpegmatch=lpeg.match
37943 local utfsplit=utf.split
37944 local settings_to_array=utilities.parsers.settings_to_array
37945 local fonts=fonts
37946 local otf=fonts.handlers.otf
37947 local registerotffeature=otf.features.register
37948 local addotffeature=otf.addfeature
37949 local lookups={}
37950 local protect={}
37951 local revert={}
37952 local zwjchar=0x200C
37953 local zwj={ zwjchar }
37954 addotffeature {
37955 name="blockligatures",
37956 type="chainsubstitution",
37957 nocheck=true,
37958 prepend=true,
37959 future=true,
37960 lookups={
37961 {
37962 type="multiple",
37963 data=lookups,
37964 },
37965 },
37966 data={
37967 rules=protect,
37968 }
37969 }
37970 addotffeature {
37971 name="blockligatures",
37972 type="chainsubstitution",
37973 nocheck=true,
37974 append=true,
37975 overload=false,
37976 lookups={
37977 {
37978 type="ligature",
37979 data=lookups,
37980 },
37981 },
37982 data={
37983 rules=revert,
37984 }
37985 }
37986 registerotffeature {
37987 name='blockligatures',
37988 description='block certain ligatures',
37989 }
37990 local splitter=lpeg.splitat(":")
37991 local function blockligatures(str)
37992 local t=settings_to_array(str)
37993 for i=1,#t do
37994 local ti=t[i]
37995 local before,current,after=lpegmatch(splitter,ti)
37996 if current and after then
37997 if before then
37998 before=utfsplit(before)
37999 for i=1,#before do
38000 before[i]={ before[i] }
38001 end
38002 end
38003 if current then
38004 current=utfsplit(current)
38005 end
38006 if after then
38007 after=utfsplit(after)
38008 for i=1,#after do
38009 after[i]={ after[i] }
38010 end
38011 end
38012 else
38013 before=nil
38014 current=utfsplit(ti)
38015 after=nil
38016 end
38017 if #current>1 then
38018 local one=current[1]
38019 local two=current[2]
38020 lookups[one]={ one,zwjchar }
38021 local one={ one }
38022 local two={ two }
38023 local new=#protect+1
38024 protect[new]={
38025 before=before,
38026 current={ one,two },
38027 after=after,
38028 lookups={ 1,false },
38029 }
38030 revert[new]={
38031 current={ one,zwj },
38032 after={ two },
38033 lookups={ 1,false },
38034 }
38035 end
38036 end
38037 end
38038 otf.helpers.blockligatures=blockligatures
38039 if context then
38040
38041 --removed
38042
38043 end
38044
38045 end -- closure
38046
38047 do -- begin closure to overcome local limits and interference
38048
38049 if not modules then modules={} end modules ['font-imp-italics']={
38050 version=1.001,
38051 comment="companion to font-ini.mkiv and hand-ini.mkiv",
38052 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
38053 copyright="PRAGMA ADE / ConTeXt Development Team",
38054 license="see context related readme files"
38055 }
38056 local next,tonumber=next,tonumber
38057 local fonts=fonts
38058 local handlers=fonts.handlers
38059 local registerotffeature=handlers.otf.features.register
38060 local registerafmfeature=handlers.afm.features.register
38061 local function initialize(tfmdata,value)
38062 if value then
38063 local parameters=tfmdata.parameters
38064 local italicangle=parameters.italicangle
38065 if italicangle and italicangle~=0 then
38066 local properties=tfmdata.properties
38067 local factor=tonumber(value) or 1
38068 properties.hasitalics=true
38069 properties.autoitalicamount=factor*(parameters.uwidth or 40)/2
38070 end
38071 end
38072 end
38073 local specification={
38074 name="itlc",
38075 description="italic correction",
38076 initializers={
38077 base=initialize,
38078 node=initialize,
38079 }
38080 }
38081 registerotffeature(specification)
38082 registerafmfeature(specification)
38083 if context then
38084
38085 --removed
38086
38087 end
38088
38089 end -- closure
38090
38091 do -- begin closure to overcome local limits and interference
38092
38093 if not modules then modules={} end modules ['font-imp-effects']={
38094 version=1.001,
38095 comment="companion to font-ini.mkiv",
38096 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
38097 copyright="PRAGMA ADE / ConTeXt Development Team",
38098 license="see context related readme files"
38099 }
38100 local next,type,tonumber=next,type,tonumber
38101 local is_boolean=string.is_boolean
38102 local fonts=fonts
38103 local handlers=fonts.handlers
38104 local registerotffeature=handlers.otf.features.register
38105 local registerafmfeature=handlers.afm.features.register
38106 local settings_to_hash=utilities.parsers.settings_to_hash_colon_too
38107 local helpers=fonts.helpers
38108 local prependcommands=helpers.prependcommands
38109 local charcommand=helpers.commands.char
38110 local leftcommand=helpers.commands.left
38111 local rightcommand=helpers.commands.right
38112 local upcommand=helpers.commands.up
38113 local downcommand=helpers.commands.down
38114 local dummycommand=helpers.commands.dummy
38115 local report_effect=logs.reporter("fonts","effect")
38116 local report_slant=logs.reporter("fonts","slant")
38117 local report_extend=logs.reporter("fonts","extend")
38118 local report_squeeze=logs.reporter("fonts","squeeze")
38119 local trace=false
38120 trackers.register("fonts.effect",function(v) trace=v end)
38121 trackers.register("fonts.slant",function(v) trace=v end)
38122 trackers.register("fonts.extend",function(v) trace=v end)
38123 trackers.register("fonts.squeeze",function(v) trace=v end)
38124 local function initializeslant(tfmdata,value)
38125 value=tonumber(value)
38126 if not value then
38127 value=0
38128 elseif value>1 then
38129 value=1
38130 elseif value<-1 then
38131 value=-1
38132 end
38133 if trace then
38134 report_slant("applying %0.3f",value)
38135 end
38136 tfmdata.parameters.slantfactor=value
38137 end
38138 local specification={
38139 name="slant",
38140 description="slant glyphs",
38141 initializers={
38142 base=initializeslant,
38143 node=initializeslant,
38144 }
38145 }
38146 registerotffeature(specification)
38147 registerafmfeature(specification)
38148 local function initializeextend(tfmdata,value)
38149 value=tonumber(value)
38150 if not value then
38151 value=0
38152 elseif value>10 then
38153 value=10
38154 elseif value<-10 then
38155 value=-10
38156 end
38157 if trace then
38158 report_extend("applying %0.3f",value)
38159 end
38160 tfmdata.parameters.extendfactor=value
38161 end
38162 local specification={
38163 name="extend",
38164 description="scale glyphs horizontally",
38165 initializers={
38166 base=initializeextend,
38167 node=initializeextend,
38168 }
38169 }
38170 registerotffeature(specification)
38171 registerafmfeature(specification)
38172 local function initializesqueeze(tfmdata,value)
38173 value=tonumber(value)
38174 if not value then
38175 value=0
38176 elseif value>10 then
38177 value=10
38178 elseif value<-10 then
38179 value=-10
38180 end
38181 if trace then
38182 report_squeeze("applying %0.3f",value)
38183 end
38184 tfmdata.parameters.squeezefactor=value
38185 end
38186 local specification={
38187 name="squeeze",
38188 description="scale glyphs vertically",
38189 initializers={
38190 base=initializesqueeze,
38191 node=initializesqueeze,
38192 }
38193 }
38194 registerotffeature(specification)
38195 registerafmfeature(specification)
38196 local effects={
38197 inner=0,
38198 normal=0,
38199 outer=1,
38200 outline=1,
38201 both=2,
38202 hidden=3,
38203 }
38204 local function initializeeffect(tfmdata,value)
38205 local spec
38206 if type(value)=="number" then
38207 spec={ width=value }
38208 else
38209 spec=settings_to_hash(value)
38210 end
38211 local effect=spec.effect or "both"
38212 local width=tonumber(spec.width) or 0
38213 local mode=effects[effect]
38214 if not mode then
38215 report_effect("invalid effect %a",effect)
38216 elseif width==0 and mode==0 then
38217 report_effect("invalid width %a for effect %a",width,effect)
38218 else
38219 local parameters=tfmdata.parameters
38220 local properties=tfmdata.properties
38221 parameters.mode=mode
38222 parameters.width=width*1000
38223 if is_boolean(spec.auto)==true then
38224 local squeeze=1-width/20
38225 local average=(1-squeeze)*width*100
38226 spec.squeeze=squeeze
38227 spec.extend=1+width/2
38228 spec.wdelta=average
38229 spec.hdelta=average/2
38230 spec.ddelta=average/2
38231 spec.vshift=average/2
38232 end
38233 local factor=tonumber(spec.factor) or 0
38234 local hfactor=tonumber(spec.hfactor) or factor
38235 local vfactor=tonumber(spec.vfactor) or factor
38236 local delta=tonumber(spec.delta) or 1
38237 local wdelta=tonumber(spec.wdelta) or delta
38238 local hdelta=tonumber(spec.hdelta) or delta
38239 local ddelta=tonumber(spec.ddelta) or hdelta
38240 local vshift=tonumber(spec.vshift) or 0
38241 local slant=spec.slant
38242 local extend=spec.extend
38243 local squeeze=spec.squeeze
38244 if slant then
38245 initializeslant(tfmdata,slant)
38246 end
38247 if extend then
38248 initializeextend(tfmdata,extend)
38249 end
38250 if squeeze then
38251 initializesqueeze(tfmdata,squeeze)
38252 end
38253 properties.effect={
38254 effect=effect,
38255 width=width,
38256 factor=factor,
38257 hfactor=hfactor,
38258 vfactor=vfactor,
38259 wdelta=wdelta,
38260 hdelta=hdelta,
38261 ddelta=ddelta,
38262 vshift=vshift,
38263 slant=tfmdata.parameters.slantfactor,
38264 extend=tfmdata.parameters.extendfactor,
38265 squeeze=tfmdata.parameters.squeezefactor,
38266 }
38267 end
38268 end
38269 local rules={
38270 "RadicalRuleThickness",
38271 "OverbarRuleThickness",
38272 "FractionRuleThickness",
38273 "UnderbarRuleThickness",
38274 }
38275 local function setmathparameters(tfmdata,characters,mathparameters,dx,dy,squeeze,multiplier)
38276 if dy~=0 then
38277 for i=1,#rules do
38278 local name=rules[i]
38279 local value=mathparameters[name]
38280 if value then
38281 mathparameters[name]=(squeeze or 1)*(value+dy)
38282 end
38283 end
38284 end
38285 end
38286 local function setmathcharacters(tfmdata,characters,mathparameters,dx,dy,squeeze,wdelta,hdelta,ddelta)
38287 local function wdpatch(char)
38288 if wsnap~=0 then
38289 char.width=char.width+wdelta/2
38290 end
38291 end
38292 local function htpatch(char)
38293 if hsnap~=0 then
38294 local height=char.height
38295 if height then
38296 char.height=char.height+2*dy
38297 end
38298 end
38299 end
38300 local character=characters[0x221A]
38301 if character and character.next then
38302 local char=character
38303 local next=character.next
38304 wdpatch(char)
38305 htpatch(char)
38306 while next do
38307 char=characters[next]
38308 wdpatch(char)
38309 htpatch(char)
38310 next=char.next
38311 end
38312 if char then
38313 local v=char.vert_variants
38314 if v then
38315 local top=v[#v]
38316 if top then
38317 local char=characters[top.glyph]
38318 htpatch(char)
38319 end
38320 end
38321 end
38322 end
38323 end
38324 local function manipulateeffect(tfmdata)
38325 local effect=tfmdata.properties.effect
38326 if effect then
38327 local characters=tfmdata.characters
38328 local parameters=tfmdata.parameters
38329 local mathparameters=tfmdata.mathparameters
38330 local multiplier=effect.width*100
38331 local factor=parameters.factor
38332 local hfactor=parameters.hfactor
38333 local vfactor=parameters.vfactor
38334 local wdelta=effect.wdelta*hfactor*multiplier
38335 local hdelta=effect.hdelta*vfactor*multiplier
38336 local ddelta=effect.ddelta*vfactor*multiplier
38337 local vshift=effect.vshift*vfactor*multiplier
38338 local squeeze=effect.squeeze
38339 local hshift=wdelta/2
38340 local dx=multiplier*vfactor
38341 local dy=vshift
38342 local factor=(1+effect.factor)*factor
38343 local hfactor=(1+effect.hfactor)*hfactor
38344 local vfactor=(1+effect.vfactor)*vfactor
38345 vshift=vshift~=0 and upcommand[vshift] or false
38346 hshift=rightcommand[hshift]
38347 for unicode,character in next,characters do
38348 local oldwidth=character.width
38349 local oldheight=character.height
38350 local olddepth=character.depth
38351 if oldwidth and oldwidth>0 then
38352 character.width=oldwidth+wdelta
38353 local commands=character.commands
38354 if vshift then
38355 if commands then
38356 prependcommands (commands,
38357 hshift,
38358 vshift
38359 )
38360 else
38361 character.commands={
38362 hshift,
38363 vshift,
38364 charcommand[unicode]
38365 }
38366 end
38367 else
38368 if commands then
38369 prependcommands (commands,
38370 hshift
38371 )
38372 else
38373 character.commands={
38374 hshift,
38375 charcommand[unicode]
38376 }
38377 end
38378 end
38379 end
38380 if oldheight and oldheight>0 then
38381 character.height=oldheight+hdelta
38382 end
38383 if olddepth and olddepth>0 then
38384 character.depth=olddepth+ddelta
38385 end
38386 end
38387 if mathparameters then
38388 setmathparameters(tfmdata,characters,mathparameters,dx,dy,squeeze,multiplier)
38389 setmathcharacters(tfmdata,characters,mathparameters,dx,dy,squeeze,wdelta,hdelta,ddelta)
38390 end
38391 parameters.factor=factor
38392 parameters.hfactor=hfactor
38393 parameters.vfactor=vfactor
38394 if trace then
38395 report_effect("applying")
38396 report_effect(" effect : %s",effect.effect)
38397 report_effect(" width : %s => %s",effect.width,multiplier)
38398 report_effect(" factor : %s => %s",effect.factor,factor )
38399 report_effect(" hfactor : %s => %s",effect.hfactor,hfactor)
38400 report_effect(" vfactor : %s => %s",effect.vfactor,vfactor)
38401 report_effect(" wdelta : %s => %s",effect.wdelta,wdelta)
38402 report_effect(" hdelta : %s => %s",effect.hdelta,hdelta)
38403 report_effect(" ddelta : %s => %s",effect.ddelta,ddelta)
38404 end
38405 end
38406 end
38407 local specification={
38408 name="effect",
38409 description="apply effects to glyphs",
38410 initializers={
38411 base=initializeeffect,
38412 node=initializeeffect,
38413 },
38414 manipulators={
38415 base=manipulateeffect,
38416 node=manipulateeffect,
38417 },
38418 }
38419 registerotffeature(specification)
38420 registerafmfeature(specification)
38421 local function initializeoutline(tfmdata,value)
38422 value=tonumber(value)
38423 if not value then
38424 value=0
38425 else
38426 value=tonumber(value) or 0
38427 end
38428 local parameters=tfmdata.parameters
38429 local properties=tfmdata.properties
38430 parameters.mode=effects.outline
38431 parameters.width=value*1000
38432 properties.effect={
38433 effect=effect,
38434 width=width,
38435 }
38436 end
38437 local specification={
38438 name="outline",
38439 description="outline glyphs",
38440 initializers={
38441 base=initializeoutline,
38442 node=initializeoutline,
38443 }
38444 }
38445 registerotffeature(specification)
38446 registerafmfeature(specification)
38447
38448 end -- closure
38449
38450 do -- begin closure to overcome local limits and interference
38451
38452
38453 fonts.handlers.otf.addfeature {
38454 ["dataset"]={
38455 {
38456 ["data"]={
38457 ["À"]={ "A","̀" },
38458 ["Á"]={ "A","́" },
38459 ["Â"]={ "A","̂" },
38460 ["Ã"]={ "A","̃" },
38461 ["Ä"]={ "A","̈" },
38462 ["Å"]={ "A","̊" },
38463 ["Ç"]={ "C","̧" },
38464 ["È"]={ "E","̀" },
38465 ["É"]={ "E","́" },
38466 ["Ê"]={ "E","̂" },
38467 ["Ë"]={ "E","̈" },
38468 ["Ì"]={ "I","̀" },
38469 ["Í"]={ "I","́" },
38470 ["Î"]={ "I","̂" },
38471 ["Ï"]={ "I","̈" },
38472 ["Ñ"]={ "N","̃" },
38473 ["Ò"]={ "O","̀" },
38474 ["Ó"]={ "O","́" },
38475 ["Ô"]={ "O","̂" },
38476 ["Õ"]={ "O","̃" },
38477 ["Ö"]={ "O","̈" },
38478 ["Ù"]={ "U","̀" },
38479 ["Ú"]={ "U","́" },
38480 ["Û"]={ "U","̂" },
38481 ["Ü"]={ "U","̈" },
38482 ["Ý"]={ "Y","́" },
38483 ["à"]={ "a","̀" },
38484 ["á"]={ "a","́" },
38485 ["â"]={ "a","̂" },
38486 ["ã"]={ "a","̃" },
38487 ["ä"]={ "a","̈" },
38488 ["å"]={ "a","̊" },
38489 ["ç"]={ "c","̧" },
38490 ["è"]={ "e","̀" },
38491 ["é"]={ "e","́" },
38492 ["ê"]={ "e","̂" },
38493 ["ë"]={ "e","̈" },
38494 ["ì"]={ "i","̀" },
38495 ["í"]={ "i","́" },
38496 ["î"]={ "i","̂" },
38497 ["ï"]={ "i","̈" },
38498 ["ñ"]={ "n","̃" },
38499 ["ò"]={ "o","̀" },
38500 ["ó"]={ "o","́" },
38501 ["ô"]={ "o","̂" },
38502 ["õ"]={ "o","̃" },
38503 ["ö"]={ "o","̈" },
38504 ["ù"]={ "u","̀" },
38505 ["ú"]={ "u","́" },
38506 ["û"]={ "u","̂" },
38507 ["ü"]={ "u","̈" },
38508 ["ý"]={ "y","́" },
38509 ["ÿ"]={ "y","̈" },
38510 ["Ā"]={ "A","̄" },
38511 ["ā"]={ "a","̄" },
38512 ["Ă"]={ "A","̆" },
38513 ["ă"]={ "a","̆" },
38514 ["Ą"]={ "A","̨" },
38515 ["ą"]={ "a","̨" },
38516 ["Ć"]={ "C","́" },
38517 ["ć"]={ "c","́" },
38518 ["Ĉ"]={ "C","̂" },
38519 ["ĉ"]={ "c","̂" },
38520 ["Ċ"]={ "C","̇" },
38521 ["ċ"]={ "c","̇" },
38522 ["Č"]={ "C","̌" },
38523 ["č"]={ "c","̌" },
38524 ["Ď"]={ "D","̌" },
38525 ["ď"]={ "d","̌" },
38526 ["Ē"]={ "E","̄" },
38527 ["ē"]={ "e","̄" },
38528 ["Ĕ"]={ "E","̆" },
38529 ["ĕ"]={ "e","̆" },
38530 ["Ė"]={ "E","̇" },
38531 ["ė"]={ "e","̇" },
38532 ["Ę"]={ "E","̨" },
38533 ["ę"]={ "e","̨" },
38534 ["Ě"]={ "E","̌" },
38535 ["ě"]={ "e","̌" },
38536 ["Ĝ"]={ "G","̂" },
38537 ["ĝ"]={ "g","̂" },
38538 ["Ğ"]={ "G","̆" },
38539 ["ğ"]={ "g","̆" },
38540 ["Ġ"]={ "G","̇" },
38541 ["ġ"]={ "g","̇" },
38542 ["Ģ"]={ "G","̧" },
38543 ["ģ"]={ "g","̧" },
38544 ["Ĥ"]={ "H","̂" },
38545 ["ĥ"]={ "h","̂" },
38546 ["Ĩ"]={ "I","̃" },
38547 ["ĩ"]={ "i","̃" },
38548 ["Ī"]={ "I","̄" },
38549 ["ī"]={ "i","̄" },
38550 ["Ĭ"]={ "I","̆" },
38551 ["ĭ"]={ "i","̆" },
38552 ["Į"]={ "I","̨" },
38553 ["į"]={ "i","̨" },
38554 ["İ"]={ "I","̇" },
38555 ["Ĵ"]={ "J","̂" },
38556 ["ĵ"]={ "j","̂" },
38557 ["Ķ"]={ "K","̧" },
38558 ["ķ"]={ "k","̧" },
38559 ["Ĺ"]={ "L","́" },
38560 ["ĺ"]={ "l","́" },
38561 ["Ļ"]={ "L","̧" },
38562 ["ļ"]={ "l","̧" },
38563 ["Ľ"]={ "L","̌" },
38564 ["ľ"]={ "l","̌" },
38565 ["Ń"]={ "N","́" },
38566 ["ń"]={ "n","́" },
38567 ["Ņ"]={ "N","̧" },
38568 ["ņ"]={ "n","̧" },
38569 ["Ň"]={ "N","̌" },
38570 ["ň"]={ "n","̌" },
38571 ["Ō"]={ "O","̄" },
38572 ["ō"]={ "o","̄" },
38573 ["Ŏ"]={ "O","̆" },
38574 ["ŏ"]={ "o","̆" },
38575 ["Ő"]={ "O","̋" },
38576 ["ő"]={ "o","̋" },
38577 ["Ŕ"]={ "R","́" },
38578 ["ŕ"]={ "r","́" },
38579 ["Ŗ"]={ "R","̧" },
38580 ["ŗ"]={ "r","̧" },
38581 ["Ř"]={ "R","̌" },
38582 ["ř"]={ "r","̌" },
38583 ["Ś"]={ "S","́" },
38584 ["ś"]={ "s","́" },
38585 ["Ŝ"]={ "S","̂" },
38586 ["ŝ"]={ "s","̂" },
38587 ["Ş"]={ "S","̧" },
38588 ["ş"]={ "s","̧" },
38589 ["Š"]={ "S","̌" },
38590 ["š"]={ "s","̌" },
38591 ["Ţ"]={ "T","̧" },
38592 ["ţ"]={ "t","̧" },
38593 ["Ť"]={ "T","̌" },
38594 ["ť"]={ "t","̌" },
38595 ["Ũ"]={ "U","̃" },
38596 ["ũ"]={ "u","̃" },
38597 ["Ū"]={ "U","̄" },
38598 ["ū"]={ "u","̄" },
38599 ["Ŭ"]={ "U","̆" },
38600 ["ŭ"]={ "u","̆" },
38601 ["Ů"]={ "U","̊" },
38602 ["ů"]={ "u","̊" },
38603 ["Ű"]={ "U","̋" },
38604 ["ű"]={ "u","̋" },
38605 ["Ų"]={ "U","̨" },
38606 ["ų"]={ "u","̨" },
38607 ["Ŵ"]={ "W","̂" },
38608 ["ŵ"]={ "w","̂" },
38609 ["Ŷ"]={ "Y","̂" },
38610 ["ŷ"]={ "y","̂" },
38611 ["Ÿ"]={ "Y","̈" },
38612 ["Ź"]={ "Z","́" },
38613 ["ź"]={ "z","́" },
38614 ["Ż"]={ "Z","̇" },
38615 ["ż"]={ "z","̇" },
38616 ["Ž"]={ "Z","̌" },
38617 ["ž"]={ "z","̌" },
38618 ["Ơ"]={ "O","̛" },
38619 ["ơ"]={ "o","̛" },
38620 ["Ư"]={ "U","̛" },
38621 ["ư"]={ "u","̛" },
38622 ["Ǎ"]={ "A","̌" },
38623 ["ǎ"]={ "a","̌" },
38624 ["Ǐ"]={ "I","̌" },
38625 ["ǐ"]={ "i","̌" },
38626 ["Ǒ"]={ "O","̌" },
38627 ["ǒ"]={ "o","̌" },
38628 ["Ǔ"]={ "U","̌" },
38629 ["ǔ"]={ "u","̌" },
38630 ["Ǖ"]={ "Ü","̄" },
38631 ["ǖ"]={ "ü","̄" },
38632 ["Ǘ"]={ "Ü","́" },
38633 ["ǘ"]={ "ü","́" },
38634 ["Ǚ"]={ "Ü","̌" },
38635 ["ǚ"]={ "ü","̌" },
38636 ["Ǜ"]={ "Ü","̀" },
38637 ["ǜ"]={ "ü","̀" },
38638 ["Ǟ"]={ "Ä","̄" },
38639 ["ǟ"]={ "ä","̄" },
38640 ["Ǡ"]={ "Ȧ","̄" },
38641 ["ǡ"]={ "ȧ","̄" },
38642 ["Ǣ"]={ "Æ","̄" },
38643 ["ǣ"]={ "æ","̄" },
38644 ["Ǧ"]={ "G","̌" },
38645 ["ǧ"]={ "g","̌" },
38646 ["Ǩ"]={ "K","̌" },
38647 ["ǩ"]={ "k","̌" },
38648 ["Ǫ"]={ "O","̨" },
38649 ["ǫ"]={ "o","̨" },
38650 ["Ǭ"]={ "Ǫ","̄" },
38651 ["ǭ"]={ "ǫ","̄" },
38652 ["Ǯ"]={ "Ʒ","̌" },
38653 ["ǯ"]={ "ʒ","̌" },
38654 ["ǰ"]={ "j","̌" },
38655 ["Ǵ"]={ "G","́" },
38656 ["ǵ"]={ "g","́" },
38657 ["Ǹ"]={ "N","̀" },
38658 ["ǹ"]={ "n","̀" },
38659 ["Ǻ"]={ "Å","́" },
38660 ["ǻ"]={ "å","́" },
38661 ["Ǽ"]={ "Æ","́" },
38662 ["ǽ"]={ "æ","́" },
38663 ["Ǿ"]={ "Ø","́" },
38664 ["ǿ"]={ "ø","́" },
38665 ["Ȁ"]={ "A","̏" },
38666 ["ȁ"]={ "a","̏" },
38667 ["Ȃ"]={ "A","̑" },
38668 ["ȃ"]={ "a","̑" },
38669 ["Ȅ"]={ "E","̏" },
38670 ["ȅ"]={ "e","̏" },
38671 ["Ȇ"]={ "E","̑" },
38672 ["ȇ"]={ "e","̑" },
38673 ["Ȉ"]={ "I","̏" },
38674 ["ȉ"]={ "i","̏" },
38675 ["Ȋ"]={ "I","̑" },
38676 ["ȋ"]={ "i","̑" },
38677 ["Ȍ"]={ "O","̏" },
38678 ["ȍ"]={ "o","̏" },
38679 ["Ȏ"]={ "O","̑" },
38680 ["ȏ"]={ "o","̑" },
38681 ["Ȑ"]={ "R","̏" },
38682 ["ȑ"]={ "r","̏" },
38683 ["Ȓ"]={ "R","̑" },
38684 ["ȓ"]={ "r","̑" },
38685 ["Ȕ"]={ "U","̏" },
38686 ["ȕ"]={ "u","̏" },
38687 ["Ȗ"]={ "U","̑" },
38688 ["ȗ"]={ "u","̑" },
38689 ["Ș"]={ "S","̦" },
38690 ["ș"]={ "s","̦" },
38691 ["Ț"]={ "T","̦" },
38692 ["ț"]={ "t","̦" },
38693 ["Ȟ"]={ "H","̌" },
38694 ["ȟ"]={ "h","̌" },
38695 ["Ȧ"]={ "A","̇" },
38696 ["ȧ"]={ "a","̇" },
38697 ["Ȩ"]={ "E","̧" },
38698 ["ȩ"]={ "e","̧" },
38699 ["Ȫ"]={ "Ö","̄" },
38700 ["ȫ"]={ "ö","̄" },
38701 ["Ȭ"]={ "Õ","̄" },
38702 ["ȭ"]={ "õ","̄" },
38703 ["Ȯ"]={ "O","̇" },
38704 ["ȯ"]={ "o","̇" },
38705 ["Ȱ"]={ "Ȯ","̄" },
38706 ["ȱ"]={ "ȯ","̄" },
38707 ["Ȳ"]={ "Y","̄" },
38708 ["ȳ"]={ "y","̄" },
38709 ["̈́"]={ "̈","́" },
38710 ["΅"]={ "¨","́" },
38711 ["Ά"]={ "Α","́" },
38712 ["Έ"]={ "Ε","́" },
38713 ["Ή"]={ "Η","́" },
38714 ["Ί"]={ "Ι","́" },
38715 ["Ό"]={ "Ο","́" },
38716 ["Ύ"]={ "Υ","́" },
38717 ["Ώ"]={ "Ω","́" },
38718 ["ΐ"]={ "ϊ","́" },
38719 ["Ϊ"]={ "Ι","̈" },
38720 ["Ϋ"]={ "Υ","̈" },
38721 ["ά"]={ "α","́" },
38722 ["έ"]={ "ε","́" },
38723 ["ή"]={ "η","́" },
38724 ["ί"]={ "ι","́" },
38725 ["ΰ"]={ "ϋ","́" },
38726 ["ϊ"]={ "ι","̈" },
38727 ["ϋ"]={ "υ","̈" },
38728 ["ό"]={ "ο","́" },
38729 ["ύ"]={ "υ","́" },
38730 ["ώ"]={ "ω","́" },
38731 ["ϓ"]={ "ϒ","́" },
38732 ["ϔ"]={ "ϒ","̈" },
38733 ["Ѐ"]={ "Е","̀" },
38734 ["Ё"]={ "Е","̈" },
38735 ["Ѓ"]={ "Г","́" },
38736 ["Ї"]={ "І","̈" },
38737 ["Ќ"]={ "К","́" },
38738 ["Ѝ"]={ "И","̀" },
38739 ["Ў"]={ "У","̆" },
38740 ["Й"]={ "И","̆" },
38741 ["й"]={ "и","̆" },
38742 ["ѐ"]={ "е","̀" },
38743 ["ё"]={ "е","̈" },
38744 ["ѓ"]={ "г","́" },
38745 ["ї"]={ "і","̈" },
38746 ["ќ"]={ "к","́" },
38747 ["ѝ"]={ "и","̀" },
38748 ["ў"]={ "у","̆" },
38749 ["Ѷ"]={ "Ѵ","̏" },
38750 ["ѷ"]={ "ѵ","̏" },
38751 ["Ӂ"]={ "Ж","̆" },
38752 ["ӂ"]={ "ж","̆" },
38753 ["Ӑ"]={ "А","̆" },
38754 ["ӑ"]={ "а","̆" },
38755 ["Ӓ"]={ "А","̈" },
38756 ["ӓ"]={ "а","̈" },
38757 ["Ӗ"]={ "Е","̆" },
38758 ["ӗ"]={ "е","̆" },
38759 ["Ӛ"]={ "Ә","̈" },
38760 ["ӛ"]={ "ә","̈" },
38761 ["Ӝ"]={ "Ж","̈" },
38762 ["ӝ"]={ "ж","̈" },
38763 ["Ӟ"]={ "З","̈" },
38764 ["ӟ"]={ "з","̈" },
38765 ["Ӣ"]={ "И","̄" },
38766 ["ӣ"]={ "и","̄" },
38767 ["Ӥ"]={ "И","̈" },
38768 ["ӥ"]={ "и","̈" },
38769 ["Ӧ"]={ "О","̈" },
38770 ["ӧ"]={ "о","̈" },
38771 ["Ӫ"]={ "Ө","̈" },
38772 ["ӫ"]={ "ө","̈" },
38773 ["Ӭ"]={ "Э","̈" },
38774 ["ӭ"]={ "э","̈" },
38775 ["Ӯ"]={ "У","̄" },
38776 ["ӯ"]={ "у","̄" },
38777 ["Ӱ"]={ "У","̈" },
38778 ["ӱ"]={ "у","̈" },
38779 ["Ӳ"]={ "У","̋" },
38780 ["ӳ"]={ "у","̋" },
38781 ["Ӵ"]={ "Ч","̈" },
38782 ["ӵ"]={ "ч","̈" },
38783 ["Ӹ"]={ "Ы","̈" },
38784 ["ӹ"]={ "ы","̈" },
38785 ["آ"]={ "ا","ٓ" },
38786 ["أ"]={ "ا","ٔ" },
38787 ["ؤ"]={ "و","ٔ" },
38788 ["إ"]={ "ا","ٕ" },
38789 ["ئ"]={ "ي","ٔ" },
38790 ["ۀ"]={ "ە","ٔ" },
38791 ["ۂ"]={ "ہ","ٔ" },
38792 ["ۓ"]={ "ے","ٔ" },
38793 ["ऩ"]={ "न","़" },
38794 ["ऱ"]={ "र","़" },
38795 ["ऴ"]={ "ळ","़" },
38796 ["क़"]={ "क","़" },
38797 ["ख़"]={ "ख","़" },
38798 ["ग़"]={ "ग","़" },
38799 ["ज़"]={ "ज","़" },
38800 ["ड़"]={ "ड","़" },
38801 ["ढ़"]={ "ढ","़" },
38802 ["फ़"]={ "फ","़" },
38803 ["य़"]={ "य","़" },
38804 ["ো"]={ "ে","া" },
38805 ["ৌ"]={ "ে","ৗ" },
38806 ["ড়"]={ "ড","়" },
38807 ["ঢ়"]={ "ঢ","়" },
38808 ["য়"]={ "য","়" },
38809 ["ਲ਼"]={ "ਲ","਼" },
38810 ["ਸ਼"]={ "ਸ","਼" },
38811 ["ਖ਼"]={ "ਖ","਼" },
38812 ["ਗ਼"]={ "ਗ","਼" },
38813 ["ਜ਼"]={ "ਜ","਼" },
38814 ["ਫ਼"]={ "ਫ","਼" },
38815 ["ୈ"]={ "େ","ୖ" },
38816 ["ୋ"]={ "େ","ା" },
38817 ["ୌ"]={ "େ","ୗ" },
38818 ["ଡ଼"]={ "ଡ","଼" },
38819 ["ଢ଼"]={ "ଢ","଼" },
38820 ["ஔ"]={ "ஒ","ௗ" },
38821 ["ொ"]={ "ெ","ா" },
38822 ["ோ"]={ "ே","ா" },
38823 ["ௌ"]={ "ெ","ௗ" },
38824 ["ై"]={ "ె","ౖ" },
38825 ["ೀ"]={ "ಿ","ೕ" },
38826 ["ೇ"]={ "ೆ","ೕ" },
38827 ["ೈ"]={ "ೆ","ೖ" },
38828 ["ೊ"]={ "ೆ","ೂ" },
38829 ["ೋ"]={ "ೊ","ೕ" },
38830 ["ൊ"]={ "െ","ാ" },
38831 ["ോ"]={ "േ","ാ" },
38832 ["ൌ"]={ "െ","ൗ" },
38833 ["ේ"]={ "ෙ","්" },
38834 ["ො"]={ "ෙ","ා" },
38835 ["ෝ"]={ "ො","්" },
38836 ["ෞ"]={ "ෙ","ෟ" },
38837 ["གྷ"]={ "ག","ྷ" },
38838 ["ཌྷ"]={ "ཌ","ྷ" },
38839 ["དྷ"]={ "ད","ྷ" },
38840 ["བྷ"]={ "བ","ྷ" },
38841 ["ཛྷ"]={ "ཛ","ྷ" },
38842 ["ཀྵ"]={ "ཀ","ྵ" },
38843 ["ཱི"]={ "ཱ","ི" },
38844 ["ཱུ"]={ "ཱ","ུ" },
38845 ["ྲྀ"]={ "ྲ","ྀ" },
38846 ["ླྀ"]={ "ླ","ྀ" },
38847 ["ཱྀ"]={ "ཱ","ྀ" },
38848 ["ྒྷ"]={ "ྒ","ྷ" },
38849 ["ྜྷ"]={ "ྜ","ྷ" },
38850 ["ྡྷ"]={ "ྡ","ྷ" },
38851 ["ྦྷ"]={ "ྦ","ྷ" },
38852 ["ྫྷ"]={ "ྫ","ྷ" },
38853 ["ྐྵ"]={ "ྐ","ྵ" },
38854 ["ဦ"]={ "ဥ","ီ" },
38855 ["ᬆ"]={ "ᬅ","ᬵ" },
38856 ["ᬈ"]={ "ᬇ","ᬵ" },
38857 ["ᬊ"]={ "ᬉ","ᬵ" },
38858 ["ᬌ"]={ "ᬋ","ᬵ" },
38859 ["ᬎ"]={ "ᬍ","ᬵ" },
38860 ["ᬒ"]={ "ᬑ","ᬵ" },
38861 ["ᬻ"]={ "ᬺ","ᬵ" },
38862 ["ᬽ"]={ "ᬼ","ᬵ" },
38863 ["ᭀ"]={ "ᬾ","ᬵ" },
38864 ["ᭁ"]={ "ᬿ","ᬵ" },
38865 ["ᭃ"]={ "ᭂ","ᬵ" },
38866 ["Ḁ"]={ "A","̥" },
38867 ["ḁ"]={ "a","̥" },
38868 ["Ḃ"]={ "B","̇" },
38869 ["ḃ"]={ "b","̇" },
38870 ["Ḅ"]={ "B","̣" },
38871 ["ḅ"]={ "b","̣" },
38872 ["Ḇ"]={ "B","̱" },
38873 ["ḇ"]={ "b","̱" },
38874 ["Ḉ"]={ "Ç","́" },
38875 ["ḉ"]={ "ç","́" },
38876 ["Ḋ"]={ "D","̇" },
38877 ["ḋ"]={ "d","̇" },
38878 ["Ḍ"]={ "D","̣" },
38879 ["ḍ"]={ "d","̣" },
38880 ["Ḏ"]={ "D","̱" },
38881 ["ḏ"]={ "d","̱" },
38882 ["Ḑ"]={ "D","̧" },
38883 ["ḑ"]={ "d","̧" },
38884 ["Ḓ"]={ "D","̭" },
38885 ["ḓ"]={ "d","̭" },
38886 ["Ḕ"]={ "Ē","̀" },
38887 ["ḕ"]={ "ē","̀" },
38888 ["Ḗ"]={ "Ē","́" },
38889 ["ḗ"]={ "ē","́" },
38890 ["Ḙ"]={ "E","̭" },
38891 ["ḙ"]={ "e","̭" },
38892 ["Ḛ"]={ "E","̰" },
38893 ["ḛ"]={ "e","̰" },
38894 ["Ḝ"]={ "Ȩ","̆" },
38895 ["ḝ"]={ "ȩ","̆" },
38896 ["Ḟ"]={ "F","̇" },
38897 ["ḟ"]={ "f","̇" },
38898 ["Ḡ"]={ "G","̄" },
38899 ["ḡ"]={ "g","̄" },
38900 ["Ḣ"]={ "H","̇" },
38901 ["ḣ"]={ "h","̇" },
38902 ["Ḥ"]={ "H","̣" },
38903 ["ḥ"]={ "h","̣" },
38904 ["Ḧ"]={ "H","̈" },
38905 ["ḧ"]={ "h","̈" },
38906 ["Ḩ"]={ "H","̧" },
38907 ["ḩ"]={ "h","̧" },
38908 ["Ḫ"]={ "H","̮" },
38909 ["ḫ"]={ "h","̮" },
38910 ["Ḭ"]={ "I","̰" },
38911 ["ḭ"]={ "i","̰" },
38912 ["Ḯ"]={ "Ï","́" },
38913 ["ḯ"]={ "ï","́" },
38914 ["Ḱ"]={ "K","́" },
38915 ["ḱ"]={ "k","́" },
38916 ["Ḳ"]={ "K","̣" },
38917 ["ḳ"]={ "k","̣" },
38918 ["Ḵ"]={ "K","̱" },
38919 ["ḵ"]={ "k","̱" },
38920 ["Ḷ"]={ "L","̣" },
38921 ["ḷ"]={ "l","̣" },
38922 ["Ḹ"]={ "Ḷ","̄" },
38923 ["ḹ"]={ "ḷ","̄" },
38924 ["Ḻ"]={ "L","̱" },
38925 ["ḻ"]={ "l","̱" },
38926 ["Ḽ"]={ "L","̭" },
38927 ["ḽ"]={ "l","̭" },
38928 ["Ḿ"]={ "M","́" },
38929 ["ḿ"]={ "m","́" },
38930 ["Ṁ"]={ "M","̇" },
38931 ["ṁ"]={ "m","̇" },
38932 ["Ṃ"]={ "M","̣" },
38933 ["ṃ"]={ "m","̣" },
38934 ["Ṅ"]={ "N","̇" },
38935 ["ṅ"]={ "n","̇" },
38936 ["Ṇ"]={ "N","̣" },
38937 ["ṇ"]={ "n","̣" },
38938 ["Ṉ"]={ "N","̱" },
38939 ["ṉ"]={ "n","̱" },
38940 ["Ṋ"]={ "N","̭" },
38941 ["ṋ"]={ "n","̭" },
38942 ["Ṍ"]={ "Õ","́" },
38943 ["ṍ"]={ "õ","́" },
38944 ["Ṏ"]={ "Õ","̈" },
38945 ["ṏ"]={ "õ","̈" },
38946 ["Ṑ"]={ "Ō","̀" },
38947 ["ṑ"]={ "ō","̀" },
38948 ["Ṓ"]={ "Ō","́" },
38949 ["ṓ"]={ "ō","́" },
38950 ["Ṕ"]={ "P","́" },
38951 ["ṕ"]={ "p","́" },
38952 ["Ṗ"]={ "P","̇" },
38953 ["ṗ"]={ "p","̇" },
38954 ["Ṙ"]={ "R","̇" },
38955 ["ṙ"]={ "r","̇" },
38956 ["Ṛ"]={ "R","̣" },
38957 ["ṛ"]={ "r","̣" },
38958 ["Ṝ"]={ "Ṛ","̄" },
38959 ["ṝ"]={ "ṛ","̄" },
38960 ["Ṟ"]={ "R","̱" },
38961 ["ṟ"]={ "r","̱" },
38962 ["Ṡ"]={ "S","̇" },
38963 ["ṡ"]={ "s","̇" },
38964 ["Ṣ"]={ "S","̣" },
38965 ["ṣ"]={ "s","̣" },
38966 ["Ṥ"]={ "Ś","̇" },
38967 ["ṥ"]={ "ś","̇" },
38968 ["Ṧ"]={ "Š","̇" },
38969 ["ṧ"]={ "š","̇" },
38970 ["Ṩ"]={ "Ṣ","̇" },
38971 ["ṩ"]={ "ṣ","̇" },
38972 ["Ṫ"]={ "T","̇" },
38973 ["ṫ"]={ "t","̇" },
38974 ["Ṭ"]={ "T","̣" },
38975 ["ṭ"]={ "t","̣" },
38976 ["Ṯ"]={ "T","̱" },
38977 ["ṯ"]={ "t","̱" },
38978 ["Ṱ"]={ "T","̭" },
38979 ["ṱ"]={ "t","̭" },
38980 ["Ṳ"]={ "U","̤" },
38981 ["ṳ"]={ "u","̤" },
38982 ["Ṵ"]={ "U","̰" },
38983 ["ṵ"]={ "u","̰" },
38984 ["Ṷ"]={ "U","̭" },
38985 ["ṷ"]={ "u","̭" },
38986 ["Ṹ"]={ "Ũ","́" },
38987 ["ṹ"]={ "ũ","́" },
38988 ["Ṻ"]={ "Ū","̈" },
38989 ["ṻ"]={ "ū","̈" },
38990 ["Ṽ"]={ "V","̃" },
38991 ["ṽ"]={ "v","̃" },
38992 ["Ṿ"]={ "V","̣" },
38993 ["ṿ"]={ "v","̣" },
38994 ["Ẁ"]={ "W","̀" },
38995 ["ẁ"]={ "w","̀" },
38996 ["Ẃ"]={ "W","́" },
38997 ["ẃ"]={ "w","́" },
38998 ["Ẅ"]={ "W","̈" },
38999 ["ẅ"]={ "w","̈" },
39000 ["Ẇ"]={ "W","̇" },
39001 ["ẇ"]={ "w","̇" },
39002 ["Ẉ"]={ "W","̣" },
39003 ["ẉ"]={ "w","̣" },
39004 ["Ẋ"]={ "X","̇" },
39005 ["ẋ"]={ "x","̇" },
39006 ["Ẍ"]={ "X","̈" },
39007 ["ẍ"]={ "x","̈" },
39008 ["Ẏ"]={ "Y","̇" },
39009 ["ẏ"]={ "y","̇" },
39010 ["Ẑ"]={ "Z","̂" },
39011 ["ẑ"]={ "z","̂" },
39012 ["Ẓ"]={ "Z","̣" },
39013 ["ẓ"]={ "z","̣" },
39014 ["Ẕ"]={ "Z","̱" },
39015 ["ẕ"]={ "z","̱" },
39016 ["ẖ"]={ "h","̱" },
39017 ["ẗ"]={ "t","̈" },
39018 ["ẘ"]={ "w","̊" },
39019 ["ẙ"]={ "y","̊" },
39020 ["ẛ"]={ "ſ","̇" },
39021 ["Ạ"]={ "A","̣" },
39022 ["ạ"]={ "a","̣" },
39023 ["Ả"]={ "A","̉" },
39024 ["ả"]={ "a","̉" },
39025 ["Ấ"]={ "Â","́" },
39026 ["ấ"]={ "â","́" },
39027 ["Ầ"]={ "Â","̀" },
39028 ["ầ"]={ "â","̀" },
39029 ["Ẩ"]={ "Â","̉" },
39030 ["ẩ"]={ "â","̉" },
39031 ["Ẫ"]={ "Â","̃" },
39032 ["ẫ"]={ "â","̃" },
39033 ["Ậ"]={ "Ạ","̂" },
39034 ["ậ"]={ "ạ","̂" },
39035 ["Ắ"]={ "Ă","́" },
39036 ["ắ"]={ "ă","́" },
39037 ["Ằ"]={ "Ă","̀" },
39038 ["ằ"]={ "ă","̀" },
39039 ["Ẳ"]={ "Ă","̉" },
39040 ["ẳ"]={ "ă","̉" },
39041 ["Ẵ"]={ "Ă","̃" },
39042 ["ẵ"]={ "ă","̃" },
39043 ["Ặ"]={ "Ạ","̆" },
39044 ["ặ"]={ "ạ","̆" },
39045 ["Ẹ"]={ "E","̣" },
39046 ["ẹ"]={ "e","̣" },
39047 ["Ẻ"]={ "E","̉" },
39048 ["ẻ"]={ "e","̉" },
39049 ["Ẽ"]={ "E","̃" },
39050 ["ẽ"]={ "e","̃" },
39051 ["Ế"]={ "Ê","́" },
39052 ["ế"]={ "ê","́" },
39053 ["Ề"]={ "Ê","̀" },
39054 ["ề"]={ "ê","̀" },
39055 ["Ể"]={ "Ê","̉" },
39056 ["ể"]={ "ê","̉" },
39057 ["Ễ"]={ "Ê","̃" },
39058 ["ễ"]={ "ê","̃" },
39059 ["Ệ"]={ "Ẹ","̂" },
39060 ["ệ"]={ "ẹ","̂" },
39061 ["Ỉ"]={ "I","̉" },
39062 ["ỉ"]={ "i","̉" },
39063 ["Ị"]={ "I","̣" },
39064 ["ị"]={ "i","̣" },
39065 ["Ọ"]={ "O","̣" },
39066 ["ọ"]={ "o","̣" },
39067 ["Ỏ"]={ "O","̉" },
39068 ["ỏ"]={ "o","̉" },
39069 ["Ố"]={ "Ô","́" },
39070 ["ố"]={ "ô","́" },
39071 ["Ồ"]={ "Ô","̀" },
39072 ["ồ"]={ "ô","̀" },
39073 ["Ổ"]={ "Ô","̉" },
39074 ["ổ"]={ "ô","̉" },
39075 ["Ỗ"]={ "Ô","̃" },
39076 ["ỗ"]={ "ô","̃" },
39077 ["Ộ"]={ "Ọ","̂" },
39078 ["ộ"]={ "ọ","̂" },
39079 ["Ớ"]={ "Ơ","́" },
39080 ["ớ"]={ "ơ","́" },
39081 ["Ờ"]={ "Ơ","̀" },
39082 ["ờ"]={ "ơ","̀" },
39083 ["Ở"]={ "Ơ","̉" },
39084 ["ở"]={ "ơ","̉" },
39085 ["Ỡ"]={ "Ơ","̃" },
39086 ["ỡ"]={ "ơ","̃" },
39087 ["Ợ"]={ "Ơ","̣" },
39088 ["ợ"]={ "ơ","̣" },
39089 ["Ụ"]={ "U","̣" },
39090 ["ụ"]={ "u","̣" },
39091 ["Ủ"]={ "U","̉" },
39092 ["ủ"]={ "u","̉" },
39093 ["Ứ"]={ "Ư","́" },
39094 ["ứ"]={ "ư","́" },
39095 ["Ừ"]={ "Ư","̀" },
39096 ["ừ"]={ "ư","̀" },
39097 ["Ử"]={ "Ư","̉" },
39098 ["ử"]={ "ư","̉" },
39099 ["Ữ"]={ "Ư","̃" },
39100 ["ữ"]={ "ư","̃" },
39101 ["Ự"]={ "Ư","̣" },
39102 ["ự"]={ "ư","̣" },
39103 ["Ỳ"]={ "Y","̀" },
39104 ["ỳ"]={ "y","̀" },
39105 ["Ỵ"]={ "Y","̣" },
39106 ["ỵ"]={ "y","̣" },
39107 ["Ỷ"]={ "Y","̉" },
39108 ["ỷ"]={ "y","̉" },
39109 ["Ỹ"]={ "Y","̃" },
39110 ["ỹ"]={ "y","̃" },
39111 ["ἀ"]={ "α","̓" },
39112 ["ἁ"]={ "α","̔" },
39113 ["ἂ"]={ "ἀ","̀" },
39114 ["ἃ"]={ "ἁ","̀" },
39115 ["ἄ"]={ "ἀ","́" },
39116 ["ἅ"]={ "ἁ","́" },
39117 ["ἆ"]={ "ἀ","͂" },
39118 ["ἇ"]={ "ἁ","͂" },
39119 ["Ἀ"]={ "Α","̓" },
39120 ["Ἁ"]={ "Α","̔" },
39121 ["Ἂ"]={ "Ἀ","̀" },
39122 ["Ἃ"]={ "Ἁ","̀" },
39123 ["Ἄ"]={ "Ἀ","́" },
39124 ["Ἅ"]={ "Ἁ","́" },
39125 ["Ἆ"]={ "Ἀ","͂" },
39126 ["Ἇ"]={ "Ἁ","͂" },
39127 ["ἐ"]={ "ε","̓" },
39128 ["ἑ"]={ "ε","̔" },
39129 ["ἒ"]={ "ἐ","̀" },
39130 ["ἓ"]={ "ἑ","̀" },
39131 ["ἔ"]={ "ἐ","́" },
39132 ["ἕ"]={ "ἑ","́" },
39133 ["Ἐ"]={ "Ε","̓" },
39134 ["Ἑ"]={ "Ε","̔" },
39135 ["Ἒ"]={ "Ἐ","̀" },
39136 ["Ἓ"]={ "Ἑ","̀" },
39137 ["Ἔ"]={ "Ἐ","́" },
39138 ["Ἕ"]={ "Ἑ","́" },
39139 ["ἠ"]={ "η","̓" },
39140 ["ἡ"]={ "η","̔" },
39141 ["ἢ"]={ "ἠ","̀" },
39142 ["ἣ"]={ "ἡ","̀" },
39143 ["ἤ"]={ "ἠ","́" },
39144 ["ἥ"]={ "ἡ","́" },
39145 ["ἦ"]={ "ἠ","͂" },
39146 ["ἧ"]={ "ἡ","͂" },
39147 ["Ἠ"]={ "Η","̓" },
39148 ["Ἡ"]={ "Η","̔" },
39149 ["Ἢ"]={ "Ἠ","̀" },
39150 ["Ἣ"]={ "Ἡ","̀" },
39151 ["Ἤ"]={ "Ἠ","́" },
39152 ["Ἥ"]={ "Ἡ","́" },
39153 ["Ἦ"]={ "Ἠ","͂" },
39154 ["Ἧ"]={ "Ἡ","͂" },
39155 ["ἰ"]={ "ι","̓" },
39156 ["ἱ"]={ "ι","̔" },
39157 ["ἲ"]={ "ἰ","̀" },
39158 ["ἳ"]={ "ἱ","̀" },
39159 ["ἴ"]={ "ἰ","́" },
39160 ["ἵ"]={ "ἱ","́" },
39161 ["ἶ"]={ "ἰ","͂" },
39162 ["ἷ"]={ "ἱ","͂" },
39163 ["Ἰ"]={ "Ι","̓" },
39164 ["Ἱ"]={ "Ι","̔" },
39165 ["Ἲ"]={ "Ἰ","̀" },
39166 ["Ἳ"]={ "Ἱ","̀" },
39167 ["Ἴ"]={ "Ἰ","́" },
39168 ["Ἵ"]={ "Ἱ","́" },
39169 ["Ἶ"]={ "Ἰ","͂" },
39170 ["Ἷ"]={ "Ἱ","͂" },
39171 ["ὀ"]={ "ο","̓" },
39172 ["ὁ"]={ "ο","̔" },
39173 ["ὂ"]={ "ὀ","̀" },
39174 ["ὃ"]={ "ὁ","̀" },
39175 ["ὄ"]={ "ὀ","́" },
39176 ["ὅ"]={ "ὁ","́" },
39177 ["Ὀ"]={ "Ο","̓" },
39178 ["Ὁ"]={ "Ο","̔" },
39179 ["Ὂ"]={ "Ὀ","̀" },
39180 ["Ὃ"]={ "Ὁ","̀" },
39181 ["Ὄ"]={ "Ὀ","́" },
39182 ["Ὅ"]={ "Ὁ","́" },
39183 ["ὐ"]={ "υ","̓" },
39184 ["ὑ"]={ "υ","̔" },
39185 ["ὒ"]={ "ὐ","̀" },
39186 ["ὓ"]={ "ὑ","̀" },
39187 ["ὔ"]={ "ὐ","́" },
39188 ["ὕ"]={ "ὑ","́" },
39189 ["ὖ"]={ "ὐ","͂" },
39190 ["ὗ"]={ "ὑ","͂" },
39191 ["Ὑ"]={ "Υ","̔" },
39192 ["Ὓ"]={ "Ὑ","̀" },
39193 ["Ὕ"]={ "Ὑ","́" },
39194 ["Ὗ"]={ "Ὑ","͂" },
39195 ["ὠ"]={ "ω","̓" },
39196 ["ὡ"]={ "ω","̔" },
39197 ["ὢ"]={ "ὠ","̀" },
39198 ["ὣ"]={ "ὡ","̀" },
39199 ["ὤ"]={ "ὠ","́" },
39200 ["ὥ"]={ "ὡ","́" },
39201 ["ὦ"]={ "ὠ","͂" },
39202 ["ὧ"]={ "ὡ","͂" },
39203 ["Ὠ"]={ "Ω","̓" },
39204 ["Ὡ"]={ "Ω","̔" },
39205 ["Ὢ"]={ "Ὠ","̀" },
39206 ["Ὣ"]={ "Ὡ","̀" },
39207 ["Ὤ"]={ "Ὠ","́" },
39208 ["Ὥ"]={ "Ὡ","́" },
39209 ["Ὦ"]={ "Ὠ","͂" },
39210 ["Ὧ"]={ "Ὡ","͂" },
39211 ["ὰ"]={ "α","̀" },
39212 ["ὲ"]={ "ε","̀" },
39213 ["ὴ"]={ "η","̀" },
39214 ["ὶ"]={ "ι","̀" },
39215 ["ὸ"]={ "ο","̀" },
39216 ["ὺ"]={ "υ","̀" },
39217 ["ὼ"]={ "ω","̀" },
39218 ["ᾀ"]={ "ἀ","ͅ" },
39219 ["ᾁ"]={ "ἁ","ͅ" },
39220 ["ᾂ"]={ "ἂ","ͅ" },
39221 ["ᾃ"]={ "ἃ","ͅ" },
39222 ["ᾄ"]={ "ἄ","ͅ" },
39223 ["ᾅ"]={ "ἅ","ͅ" },
39224 ["ᾆ"]={ "ἆ","ͅ" },
39225 ["ᾇ"]={ "ἇ","ͅ" },
39226 ["ᾈ"]={ "Ἀ","ͅ" },
39227 ["ᾉ"]={ "Ἁ","ͅ" },
39228 ["ᾊ"]={ "Ἂ","ͅ" },
39229 ["ᾋ"]={ "Ἃ","ͅ" },
39230 ["ᾌ"]={ "Ἄ","ͅ" },
39231 ["ᾍ"]={ "Ἅ","ͅ" },
39232 ["ᾎ"]={ "Ἆ","ͅ" },
39233 ["ᾏ"]={ "Ἇ","ͅ" },
39234 ["ᾐ"]={ "ἠ","ͅ" },
39235 ["ᾑ"]={ "ἡ","ͅ" },
39236 ["ᾒ"]={ "ἢ","ͅ" },
39237 ["ᾓ"]={ "ἣ","ͅ" },
39238 ["ᾔ"]={ "ἤ","ͅ" },
39239 ["ᾕ"]={ "ἥ","ͅ" },
39240 ["ᾖ"]={ "ἦ","ͅ" },
39241 ["ᾗ"]={ "ἧ","ͅ" },
39242 ["ᾘ"]={ "Ἠ","ͅ" },
39243 ["ᾙ"]={ "Ἡ","ͅ" },
39244 ["ᾚ"]={ "Ἢ","ͅ" },
39245 ["ᾛ"]={ "Ἣ","ͅ" },
39246 ["ᾜ"]={ "Ἤ","ͅ" },
39247 ["ᾝ"]={ "Ἥ","ͅ" },
39248 ["ᾞ"]={ "Ἦ","ͅ" },
39249 ["ᾟ"]={ "Ἧ","ͅ" },
39250 ["ᾠ"]={ "ὠ","ͅ" },
39251 ["ᾡ"]={ "ὡ","ͅ" },
39252 ["ᾢ"]={ "ὢ","ͅ" },
39253 ["ᾣ"]={ "ὣ","ͅ" },
39254 ["ᾤ"]={ "ὤ","ͅ" },
39255 ["ᾥ"]={ "ὥ","ͅ" },
39256 ["ᾦ"]={ "ὦ","ͅ" },
39257 ["ᾧ"]={ "ὧ","ͅ" },
39258 ["ᾨ"]={ "Ὠ","ͅ" },
39259 ["ᾩ"]={ "Ὡ","ͅ" },
39260 ["ᾪ"]={ "Ὢ","ͅ" },
39261 ["ᾫ"]={ "Ὣ","ͅ" },
39262 ["ᾬ"]={ "Ὤ","ͅ" },
39263 ["ᾭ"]={ "Ὥ","ͅ" },
39264 ["ᾮ"]={ "Ὦ","ͅ" },
39265 ["ᾯ"]={ "Ὧ","ͅ" },
39266 ["ᾰ"]={ "α","̆" },
39267 ["ᾱ"]={ "α","̄" },
39268 ["ᾲ"]={ "ὰ","ͅ" },
39269 ["ᾳ"]={ "α","ͅ" },
39270 ["ᾴ"]={ "ά","ͅ" },
39271 ["ᾶ"]={ "α","͂" },
39272 ["ᾷ"]={ "ᾶ","ͅ" },
39273 ["Ᾰ"]={ "Α","̆" },
39274 ["Ᾱ"]={ "Α","̄" },
39275 ["Ὰ"]={ "Α","̀" },
39276 ["ᾼ"]={ "Α","ͅ" },
39277 ["῁"]={ "¨","͂" },
39278 ["ῂ"]={ "ὴ","ͅ" },
39279 ["ῃ"]={ "η","ͅ" },
39280 ["ῄ"]={ "ή","ͅ" },
39281 ["ῆ"]={ "η","͂" },
39282 ["ῇ"]={ "ῆ","ͅ" },
39283 ["Ὲ"]={ "Ε","̀" },
39284 ["Ὴ"]={ "Η","̀" },
39285 ["ῌ"]={ "Η","ͅ" },
39286 ["῍"]={ "᾿","̀" },
39287 ["῎"]={ "᾿","́" },
39288 ["῏"]={ "᾿","͂" },
39289 ["ῐ"]={ "ι","̆" },
39290 ["ῑ"]={ "ι","̄" },
39291 ["ῒ"]={ "ϊ","̀" },
39292 ["ῖ"]={ "ι","͂" },
39293 ["ῗ"]={ "ϊ","͂" },
39294 ["Ῐ"]={ "Ι","̆" },
39295 ["Ῑ"]={ "Ι","̄" },
39296 ["Ὶ"]={ "Ι","̀" },
39297 ["῝"]={ "῾","̀" },
39298 ["῞"]={ "῾","́" },
39299 ["῟"]={ "῾","͂" },
39300 ["ῠ"]={ "υ","̆" },
39301 ["ῡ"]={ "υ","̄" },
39302 ["ῢ"]={ "ϋ","̀" },
39303 ["ῤ"]={ "ρ","̓" },
39304 ["ῥ"]={ "ρ","̔" },
39305 ["ῦ"]={ "υ","͂" },
39306 ["ῧ"]={ "ϋ","͂" },
39307 ["Ῠ"]={ "Υ","̆" },
39308 ["Ῡ"]={ "Υ","̄" },
39309 ["Ὺ"]={ "Υ","̀" },
39310 ["Ῥ"]={ "Ρ","̔" },
39311 ["῭"]={ "¨","̀" },
39312 ["ῲ"]={ "ὼ","ͅ" },
39313 ["ῳ"]={ "ω","ͅ" },
39314 ["ῴ"]={ "ώ","ͅ" },
39315 ["ῶ"]={ "ω","͂" },
39316 ["ῷ"]={ "ῶ","ͅ" },
39317 ["Ὸ"]={ "Ο","̀" },
39318 ["Ὼ"]={ "Ω","̀" },
39319 ["ῼ"]={ "Ω","ͅ" },
39320 ["↚"]={ "←","̸" },
39321 ["↛"]={ "→","̸" },
39322 ["↮"]={ "↔","̸" },
39323 ["⇍"]={ "⇐","̸" },
39324 ["⇎"]={ "⇔","̸" },
39325 ["⇏"]={ "⇒","̸" },
39326 ["∄"]={ "∃","̸" },
39327 ["∉"]={ "∈","̸" },
39328 ["∌"]={ "∋","̸" },
39329 ["∤"]={ "∣","̸" },
39330 ["∦"]={ "∥","̸" },
39331 ["≁"]={ "∼","̸" },
39332 ["≄"]={ "≃","̸" },
39333 ["≇"]={ "≅","̸" },
39334 ["≉"]={ "≈","̸" },
39335 ["≠"]={ "=","̸" },
39336 ["≢"]={ "≡","̸" },
39337 ["≭"]={ "≍","̸" },
39338 ["≮"]={ "<","̸" },
39339 ["≯"]={ ">","̸" },
39340 ["≰"]={ "≤","̸" },
39341 ["≱"]={ "≥","̸" },
39342 ["≴"]={ "≲","̸" },
39343 ["≵"]={ "≳","̸" },
39344 ["≸"]={ "≶","̸" },
39345 ["≹"]={ "≷","̸" },
39346 ["⊀"]={ "≺","̸" },
39347 ["⊁"]={ "≻","̸" },
39348 ["⊄"]={ "⊂","̸" },
39349 ["⊅"]={ "⊃","̸" },
39350 ["⊈"]={ "⊆","̸" },
39351 ["⊉"]={ "⊇","̸" },
39352 ["⊬"]={ "⊢","̸" },
39353 ["⊭"]={ "⊨","̸" },
39354 ["⊮"]={ "⊩","̸" },
39355 ["⊯"]={ "⊫","̸" },
39356 ["⋠"]={ "≼","̸" },
39357 ["⋡"]={ "≽","̸" },
39358 ["⋢"]={ "⊑","̸" },
39359 ["⋣"]={ "⊒","̸" },
39360 ["⋪"]={ "⊲","̸" },
39361 ["⋫"]={ "⊳","̸" },
39362 ["⋬"]={ "⊴","̸" },
39363 ["⋭"]={ "⊵","̸" },
39364 ["⫝̸"]={ "⫝","̸" },
39365 ["が"]={ "か","゙" },
39366 ["ぎ"]={ "き","゙" },
39367 ["ぐ"]={ "く","゙" },
39368 ["げ"]={ "け","゙" },
39369 ["ご"]={ "こ","゙" },
39370 ["ざ"]={ "さ","゙" },
39371 ["じ"]={ "し","゙" },
39372 ["ず"]={ "す","゙" },
39373 ["ぜ"]={ "せ","゙" },
39374 ["ぞ"]={ "そ","゙" },
39375 ["だ"]={ "た","゙" },
39376 ["ぢ"]={ "ち","゙" },
39377 ["づ"]={ "つ","゙" },
39378 ["で"]={ "て","゙" },
39379 ["ど"]={ "と","゙" },
39380 ["ば"]={ "は","゙" },
39381 ["ぱ"]={ "は","゚" },
39382 ["び"]={ "ひ","゙" },
39383 ["ぴ"]={ "ひ","゚" },
39384 ["ぶ"]={ "ふ","゙" },
39385 ["ぷ"]={ "ふ","゚" },
39386 ["べ"]={ "へ","゙" },
39387 ["ぺ"]={ "へ","゚" },
39388 ["ぼ"]={ "ほ","゙" },
39389 ["ぽ"]={ "ほ","゚" },
39390 ["ゔ"]={ "う","゙" },
39391 ["ゞ"]={ "ゝ","゙" },
39392 ["ガ"]={ "カ","゙" },
39393 ["ギ"]={ "キ","゙" },
39394 ["グ"]={ "ク","゙" },
39395 ["ゲ"]={ "ケ","゙" },
39396 ["ゴ"]={ "コ","゙" },
39397 ["ザ"]={ "サ","゙" },
39398 ["ジ"]={ "シ","゙" },
39399 ["ズ"]={ "ス","゙" },
39400 ["ゼ"]={ "セ","゙" },
39401 ["ゾ"]={ "ソ","゙" },
39402 ["ダ"]={ "タ","゙" },
39403 ["ヂ"]={ "チ","゙" },
39404 ["ヅ"]={ "ツ","゙" },
39405 ["デ"]={ "テ","゙" },
39406 ["ド"]={ "ト","゙" },
39407 ["バ"]={ "ハ","゙" },
39408 ["パ"]={ "ハ","゚" },
39409 ["ビ"]={ "ヒ","゙" },
39410 ["ピ"]={ "ヒ","゚" },
39411 ["ブ"]={ "フ","゙" },
39412 ["プ"]={ "フ","゚" },
39413 ["ベ"]={ "ヘ","゙" },
39414 ["ペ"]={ "ヘ","゚" },
39415 ["ボ"]={ "ホ","゙" },
39416 ["ポ"]={ "ホ","゚" },
39417 ["ヴ"]={ "ウ","゙" },
39418 ["ヷ"]={ "ワ","゙" },
39419 ["ヸ"]={ "ヰ","゙" },
39420 ["ヹ"]={ "ヱ","゙" },
39421 ["ヺ"]={ "ヲ","゙" },
39422 ["ヾ"]={ "ヽ","゙" },
39423 ["יִ"]={ "י","ִ" },
39424 ["ײַ"]={ "ײ","ַ" },
39425 ["שׁ"]={ "ש","ׁ" },
39426 ["שׂ"]={ "ש","ׂ" },
39427 ["שּׁ"]={ "שּ","ׁ" },
39428 ["שּׂ"]={ "שּ","ׂ" },
39429 ["אַ"]={ "א","ַ" },
39430 ["אָ"]={ "א","ָ" },
39431 ["אּ"]={ "א","ּ" },
39432 ["בּ"]={ "ב","ּ" },
39433 ["גּ"]={ "ג","ּ" },
39434 ["דּ"]={ "ד","ּ" },
39435 ["הּ"]={ "ה","ּ" },
39436 ["וּ"]={ "ו","ּ" },
39437 ["זּ"]={ "ז","ּ" },
39438 ["טּ"]={ "ט","ּ" },
39439 ["יּ"]={ "י","ּ" },
39440 ["ךּ"]={ "ך","ּ" },
39441 ["כּ"]={ "כ","ּ" },
39442 ["לּ"]={ "ל","ּ" },
39443 ["מּ"]={ "מ","ּ" },
39444 ["נּ"]={ "נ","ּ" },
39445 ["סּ"]={ "ס","ּ" },
39446 ["ףּ"]={ "ף","ּ" },
39447 ["פּ"]={ "פ","ּ" },
39448 ["צּ"]={ "צ","ּ" },
39449 ["קּ"]={ "ק","ּ" },
39450 ["רּ"]={ "ר","ּ" },
39451 ["שּ"]={ "ש","ּ" },
39452 ["תּ"]={ "ת","ּ" },
39453 ["וֹ"]={ "ו","ֹ" },
39454 ["בֿ"]={ "ב","ֿ" },
39455 ["כֿ"]={ "כ","ֿ" },
39456 ["פֿ"]={ "פ","ֿ" },
39457 ["𑂚"]={ "𑂙","𑂺" },
39458 ["𑂜"]={ "𑂛","𑂺" },
39459 ["𑂫"]={ "𑂥","𑂺" },
39460 ["𑄮"]={ "𑄱","𑄧" },
39461 ["𑄯"]={ "𑄲","𑄧" },
39462 ["𑍋"]={ "𑍇","𑌾" },
39463 ["𑍌"]={ "𑍇","𑍗" },
39464 ["𑒻"]={ "𑒹","𑒺" },
39465 ["𑒼"]={ "𑒹","𑒰" },
39466 ["𑒾"]={ "𑒹","𑒽" },
39467 ["𑖺"]={ "𑖸","𑖯" },
39468 ["𑖻"]={ "𑖹","𑖯" },
39469 ["𝅗𝅥"]={ "𝅗","𝅥" },
39470 ["𝅘𝅥"]={ "𝅘","𝅥" },
39471 ["𝅘𝅥𝅮"]={ "𝅘𝅥","𝅮" },
39472 ["𝅘𝅥𝅯"]={ "𝅘𝅥","𝅯" },
39473 ["𝅘𝅥𝅰"]={ "𝅘𝅥","𝅰" },
39474 ["𝅘𝅥𝅱"]={ "𝅘𝅥","𝅱" },
39475 ["𝅘𝅥𝅲"]={ "𝅘𝅥","𝅲" },
39476 ["𝆹𝅥"]={ "𝆹","𝅥" },
39477 ["𝆺𝅥"]={ "𝆺","𝅥" },
39478 ["𝆹𝅥𝅮"]={ "𝆹𝅥","𝅮" },
39479 ["𝆺𝅥𝅮"]={ "𝆺𝅥","𝅮" },
39480 ["𝆹𝅥𝅯"]={ "𝆹𝅥","𝅯" },
39481 ["𝆺𝅥𝅯"]={ "𝆺𝅥","𝅯" },
39482 },
39483 },
39484 {
39485 ["data"]={
39486 ["À"]={ "A","̀" },
39487 ["Á"]={ "A","́" },
39488 ["Â"]={ "A","̂" },
39489 ["Ã"]={ "A","̃" },
39490 ["Ä"]={ "A","̈" },
39491 ["Å"]={ "A","̊" },
39492 ["Ç"]={ "C","̧" },
39493 ["È"]={ "E","̀" },
39494 ["É"]={ "E","́" },
39495 ["Ê"]={ "E","̂" },
39496 ["Ë"]={ "E","̈" },
39497 ["Ì"]={ "I","̀" },
39498 ["Í"]={ "I","́" },
39499 ["Î"]={ "I","̂" },
39500 ["Ï"]={ "I","̈" },
39501 ["Ñ"]={ "N","̃" },
39502 ["Ò"]={ "O","̀" },
39503 ["Ó"]={ "O","́" },
39504 ["Ô"]={ "O","̂" },
39505 ["Õ"]={ "O","̃" },
39506 ["Ö"]={ "O","̈" },
39507 ["Ù"]={ "U","̀" },
39508 ["Ú"]={ "U","́" },
39509 ["Û"]={ "U","̂" },
39510 ["Ü"]={ "U","̈" },
39511 ["Ý"]={ "Y","́" },
39512 ["à"]={ "a","̀" },
39513 ["á"]={ "a","́" },
39514 ["â"]={ "a","̂" },
39515 ["ã"]={ "a","̃" },
39516 ["ä"]={ "a","̈" },
39517 ["å"]={ "a","̊" },
39518 ["ç"]={ "c","̧" },
39519 ["è"]={ "e","̀" },
39520 ["é"]={ "e","́" },
39521 ["ê"]={ "e","̂" },
39522 ["ë"]={ "e","̈" },
39523 ["ì"]={ "i","̀" },
39524 ["í"]={ "i","́" },
39525 ["î"]={ "i","̂" },
39526 ["ï"]={ "i","̈" },
39527 ["ñ"]={ "n","̃" },
39528 ["ò"]={ "o","̀" },
39529 ["ó"]={ "o","́" },
39530 ["ô"]={ "o","̂" },
39531 ["õ"]={ "o","̃" },
39532 ["ö"]={ "o","̈" },
39533 ["ù"]={ "u","̀" },
39534 ["ú"]={ "u","́" },
39535 ["û"]={ "u","̂" },
39536 ["ü"]={ "u","̈" },
39537 ["ý"]={ "y","́" },
39538 ["ÿ"]={ "y","̈" },
39539 ["Ā"]={ "A","̄" },
39540 ["ā"]={ "a","̄" },
39541 ["Ă"]={ "A","̆" },
39542 ["ă"]={ "a","̆" },
39543 ["Ą"]={ "A","̨" },
39544 ["ą"]={ "a","̨" },
39545 ["Ć"]={ "C","́" },
39546 ["ć"]={ "c","́" },
39547 ["Ĉ"]={ "C","̂" },
39548 ["ĉ"]={ "c","̂" },
39549 ["Ċ"]={ "C","̇" },
39550 ["ċ"]={ "c","̇" },
39551 ["Č"]={ "C","̌" },
39552 ["č"]={ "c","̌" },
39553 ["Ď"]={ "D","̌" },
39554 ["ď"]={ "d","̌" },
39555 ["Ē"]={ "E","̄" },
39556 ["ē"]={ "e","̄" },
39557 ["Ĕ"]={ "E","̆" },
39558 ["ĕ"]={ "e","̆" },
39559 ["Ė"]={ "E","̇" },
39560 ["ė"]={ "e","̇" },
39561 ["Ę"]={ "E","̨" },
39562 ["ę"]={ "e","̨" },
39563 ["Ě"]={ "E","̌" },
39564 ["ě"]={ "e","̌" },
39565 ["Ĝ"]={ "G","̂" },
39566 ["ĝ"]={ "g","̂" },
39567 ["Ğ"]={ "G","̆" },
39568 ["ğ"]={ "g","̆" },
39569 ["Ġ"]={ "G","̇" },
39570 ["ġ"]={ "g","̇" },
39571 ["Ģ"]={ "G","̧" },
39572 ["ģ"]={ "g","̧" },
39573 ["Ĥ"]={ "H","̂" },
39574 ["ĥ"]={ "h","̂" },
39575 ["Ĩ"]={ "I","̃" },
39576 ["ĩ"]={ "i","̃" },
39577 ["Ī"]={ "I","̄" },
39578 ["ī"]={ "i","̄" },
39579 ["Ĭ"]={ "I","̆" },
39580 ["ĭ"]={ "i","̆" },
39581 ["Į"]={ "I","̨" },
39582 ["į"]={ "i","̨" },
39583 ["İ"]={ "I","̇" },
39584 ["Ĵ"]={ "J","̂" },
39585 ["ĵ"]={ "j","̂" },
39586 ["Ķ"]={ "K","̧" },
39587 ["ķ"]={ "k","̧" },
39588 ["Ĺ"]={ "L","́" },
39589 ["ĺ"]={ "l","́" },
39590 ["Ļ"]={ "L","̧" },
39591 ["ļ"]={ "l","̧" },
39592 ["Ľ"]={ "L","̌" },
39593 ["ľ"]={ "l","̌" },
39594 ["Ń"]={ "N","́" },
39595 ["ń"]={ "n","́" },
39596 ["Ņ"]={ "N","̧" },
39597 ["ņ"]={ "n","̧" },
39598 ["Ň"]={ "N","̌" },
39599 ["ň"]={ "n","̌" },
39600 ["Ō"]={ "O","̄" },
39601 ["ō"]={ "o","̄" },
39602 ["Ŏ"]={ "O","̆" },
39603 ["ŏ"]={ "o","̆" },
39604 ["Ő"]={ "O","̋" },
39605 ["ő"]={ "o","̋" },
39606 ["Ŕ"]={ "R","́" },
39607 ["ŕ"]={ "r","́" },
39608 ["Ŗ"]={ "R","̧" },
39609 ["ŗ"]={ "r","̧" },
39610 ["Ř"]={ "R","̌" },
39611 ["ř"]={ "r","̌" },
39612 ["Ś"]={ "S","́" },
39613 ["ś"]={ "s","́" },
39614 ["Ŝ"]={ "S","̂" },
39615 ["ŝ"]={ "s","̂" },
39616 ["Ş"]={ "S","̧" },
39617 ["ş"]={ "s","̧" },
39618 ["Š"]={ "S","̌" },
39619 ["š"]={ "s","̌" },
39620 ["Ţ"]={ "T","̧" },
39621 ["ţ"]={ "t","̧" },
39622 ["Ť"]={ "T","̌" },
39623 ["ť"]={ "t","̌" },
39624 ["Ũ"]={ "U","̃" },
39625 ["ũ"]={ "u","̃" },
39626 ["Ū"]={ "U","̄" },
39627 ["ū"]={ "u","̄" },
39628 ["Ŭ"]={ "U","̆" },
39629 ["ŭ"]={ "u","̆" },
39630 ["Ů"]={ "U","̊" },
39631 ["ů"]={ "u","̊" },
39632 ["Ű"]={ "U","̋" },
39633 ["ű"]={ "u","̋" },
39634 ["Ų"]={ "U","̨" },
39635 ["ų"]={ "u","̨" },
39636 ["Ŵ"]={ "W","̂" },
39637 ["ŵ"]={ "w","̂" },
39638 ["Ŷ"]={ "Y","̂" },
39639 ["ŷ"]={ "y","̂" },
39640 ["Ÿ"]={ "Y","̈" },
39641 ["Ź"]={ "Z","́" },
39642 ["ź"]={ "z","́" },
39643 ["Ż"]={ "Z","̇" },
39644 ["ż"]={ "z","̇" },
39645 ["Ž"]={ "Z","̌" },
39646 ["ž"]={ "z","̌" },
39647 ["Ơ"]={ "O","̛" },
39648 ["ơ"]={ "o","̛" },
39649 ["Ư"]={ "U","̛" },
39650 ["ư"]={ "u","̛" },
39651 ["Ǎ"]={ "A","̌" },
39652 ["ǎ"]={ "a","̌" },
39653 ["Ǐ"]={ "I","̌" },
39654 ["ǐ"]={ "i","̌" },
39655 ["Ǒ"]={ "O","̌" },
39656 ["ǒ"]={ "o","̌" },
39657 ["Ǔ"]={ "U","̌" },
39658 ["ǔ"]={ "u","̌" },
39659 ["Ǖ"]={ "Ü","̄" },
39660 ["ǖ"]={ "ü","̄" },
39661 ["Ǘ"]={ "Ü","́" },
39662 ["ǘ"]={ "ü","́" },
39663 ["Ǚ"]={ "Ü","̌" },
39664 ["ǚ"]={ "ü","̌" },
39665 ["Ǜ"]={ "Ü","̀" },
39666 ["ǜ"]={ "ü","̀" },
39667 ["Ǟ"]={ "Ä","̄" },
39668 ["ǟ"]={ "ä","̄" },
39669 ["Ǡ"]={ "Ȧ","̄" },
39670 ["ǡ"]={ "ȧ","̄" },
39671 ["Ǣ"]={ "Æ","̄" },
39672 ["ǣ"]={ "æ","̄" },
39673 ["Ǧ"]={ "G","̌" },
39674 ["ǧ"]={ "g","̌" },
39675 ["Ǩ"]={ "K","̌" },
39676 ["ǩ"]={ "k","̌" },
39677 ["Ǫ"]={ "O","̨" },
39678 ["ǫ"]={ "o","̨" },
39679 ["Ǭ"]={ "Ǫ","̄" },
39680 ["ǭ"]={ "ǫ","̄" },
39681 ["Ǯ"]={ "Ʒ","̌" },
39682 ["ǯ"]={ "ʒ","̌" },
39683 ["ǰ"]={ "j","̌" },
39684 ["Ǵ"]={ "G","́" },
39685 ["ǵ"]={ "g","́" },
39686 ["Ǹ"]={ "N","̀" },
39687 ["ǹ"]={ "n","̀" },
39688 ["Ǻ"]={ "Å","́" },
39689 ["ǻ"]={ "å","́" },
39690 ["Ǽ"]={ "Æ","́" },
39691 ["ǽ"]={ "æ","́" },
39692 ["Ǿ"]={ "Ø","́" },
39693 ["ǿ"]={ "ø","́" },
39694 ["Ȁ"]={ "A","̏" },
39695 ["ȁ"]={ "a","̏" },
39696 ["Ȃ"]={ "A","̑" },
39697 ["ȃ"]={ "a","̑" },
39698 ["Ȅ"]={ "E","̏" },
39699 ["ȅ"]={ "e","̏" },
39700 ["Ȇ"]={ "E","̑" },
39701 ["ȇ"]={ "e","̑" },
39702 ["Ȉ"]={ "I","̏" },
39703 ["ȉ"]={ "i","̏" },
39704 ["Ȋ"]={ "I","̑" },
39705 ["ȋ"]={ "i","̑" },
39706 ["Ȍ"]={ "O","̏" },
39707 ["ȍ"]={ "o","̏" },
39708 ["Ȏ"]={ "O","̑" },
39709 ["ȏ"]={ "o","̑" },
39710 ["Ȑ"]={ "R","̏" },
39711 ["ȑ"]={ "r","̏" },
39712 ["Ȓ"]={ "R","̑" },
39713 ["ȓ"]={ "r","̑" },
39714 ["Ȕ"]={ "U","̏" },
39715 ["ȕ"]={ "u","̏" },
39716 ["Ȗ"]={ "U","̑" },
39717 ["ȗ"]={ "u","̑" },
39718 ["Ș"]={ "S","̦" },
39719 ["ș"]={ "s","̦" },
39720 ["Ț"]={ "T","̦" },
39721 ["ț"]={ "t","̦" },
39722 ["Ȟ"]={ "H","̌" },
39723 ["ȟ"]={ "h","̌" },
39724 ["Ȧ"]={ "A","̇" },
39725 ["ȧ"]={ "a","̇" },
39726 ["Ȩ"]={ "E","̧" },
39727 ["ȩ"]={ "e","̧" },
39728 ["Ȫ"]={ "Ö","̄" },
39729 ["ȫ"]={ "ö","̄" },
39730 ["Ȭ"]={ "Õ","̄" },
39731 ["ȭ"]={ "õ","̄" },
39732 ["Ȯ"]={ "O","̇" },
39733 ["ȯ"]={ "o","̇" },
39734 ["Ȱ"]={ "Ȯ","̄" },
39735 ["ȱ"]={ "ȯ","̄" },
39736 ["Ȳ"]={ "Y","̄" },
39737 ["ȳ"]={ "y","̄" },
39738 ["̈́"]={ "̈","́" },
39739 ["΅"]={ "¨","́" },
39740 ["Ά"]={ "Α","́" },
39741 ["Έ"]={ "Ε","́" },
39742 ["Ή"]={ "Η","́" },
39743 ["Ί"]={ "Ι","́" },
39744 ["Ό"]={ "Ο","́" },
39745 ["Ύ"]={ "Υ","́" },
39746 ["Ώ"]={ "Ω","́" },
39747 ["ΐ"]={ "ϊ","́" },
39748 ["Ϊ"]={ "Ι","̈" },
39749 ["Ϋ"]={ "Υ","̈" },
39750 ["ά"]={ "α","́" },
39751 ["έ"]={ "ε","́" },
39752 ["ή"]={ "η","́" },
39753 ["ί"]={ "ι","́" },
39754 ["ΰ"]={ "ϋ","́" },
39755 ["ϊ"]={ "ι","̈" },
39756 ["ϋ"]={ "υ","̈" },
39757 ["ό"]={ "ο","́" },
39758 ["ύ"]={ "υ","́" },
39759 ["ώ"]={ "ω","́" },
39760 ["ϓ"]={ "ϒ","́" },
39761 ["ϔ"]={ "ϒ","̈" },
39762 ["Ѐ"]={ "Е","̀" },
39763 ["Ё"]={ "Е","̈" },
39764 ["Ѓ"]={ "Г","́" },
39765 ["Ї"]={ "І","̈" },
39766 ["Ќ"]={ "К","́" },
39767 ["Ѝ"]={ "И","̀" },
39768 ["Ў"]={ "У","̆" },
39769 ["Й"]={ "И","̆" },
39770 ["й"]={ "и","̆" },
39771 ["ѐ"]={ "е","̀" },
39772 ["ё"]={ "е","̈" },
39773 ["ѓ"]={ "г","́" },
39774 ["ї"]={ "і","̈" },
39775 ["ќ"]={ "к","́" },
39776 ["ѝ"]={ "и","̀" },
39777 ["ў"]={ "у","̆" },
39778 ["Ѷ"]={ "Ѵ","̏" },
39779 ["ѷ"]={ "ѵ","̏" },
39780 ["Ӂ"]={ "Ж","̆" },
39781 ["ӂ"]={ "ж","̆" },
39782 ["Ӑ"]={ "А","̆" },
39783 ["ӑ"]={ "а","̆" },
39784 ["Ӓ"]={ "А","̈" },
39785 ["ӓ"]={ "а","̈" },
39786 ["Ӗ"]={ "Е","̆" },
39787 ["ӗ"]={ "е","̆" },
39788 ["Ӛ"]={ "Ә","̈" },
39789 ["ӛ"]={ "ә","̈" },
39790 ["Ӝ"]={ "Ж","̈" },
39791 ["ӝ"]={ "ж","̈" },
39792 ["Ӟ"]={ "З","̈" },
39793 ["ӟ"]={ "з","̈" },
39794 ["Ӣ"]={ "И","̄" },
39795 ["ӣ"]={ "и","̄" },
39796 ["Ӥ"]={ "И","̈" },
39797 ["ӥ"]={ "и","̈" },
39798 ["Ӧ"]={ "О","̈" },
39799 ["ӧ"]={ "о","̈" },
39800 ["Ӫ"]={ "Ө","̈" },
39801 ["ӫ"]={ "ө","̈" },
39802 ["Ӭ"]={ "Э","̈" },
39803 ["ӭ"]={ "э","̈" },
39804 ["Ӯ"]={ "У","̄" },
39805 ["ӯ"]={ "у","̄" },
39806 ["Ӱ"]={ "У","̈" },
39807 ["ӱ"]={ "у","̈" },
39808 ["Ӳ"]={ "У","̋" },
39809 ["ӳ"]={ "у","̋" },
39810 ["Ӵ"]={ "Ч","̈" },
39811 ["ӵ"]={ "ч","̈" },
39812 ["Ӹ"]={ "Ы","̈" },
39813 ["ӹ"]={ "ы","̈" },
39814 ["آ"]={ "ا","ٓ" },
39815 ["أ"]={ "ا","ٔ" },
39816 ["ؤ"]={ "و","ٔ" },
39817 ["إ"]={ "ا","ٕ" },
39818 ["ئ"]={ "ي","ٔ" },
39819 ["ۀ"]={ "ە","ٔ" },
39820 ["ۂ"]={ "ہ","ٔ" },
39821 ["ۓ"]={ "ے","ٔ" },
39822 ["ऩ"]={ "न","़" },
39823 ["ऱ"]={ "र","़" },
39824 ["ऴ"]={ "ळ","़" },
39825 ["क़"]={ "क","़" },
39826 ["ख़"]={ "ख","़" },
39827 ["ग़"]={ "ग","़" },
39828 ["ज़"]={ "ज","़" },
39829 ["ड़"]={ "ड","़" },
39830 ["ढ़"]={ "ढ","़" },
39831 ["फ़"]={ "फ","़" },
39832 ["य़"]={ "य","़" },
39833 ["ো"]={ "ে","া" },
39834 ["ৌ"]={ "ে","ৗ" },
39835 ["ড়"]={ "ড","়" },
39836 ["ঢ়"]={ "ঢ","়" },
39837 ["য়"]={ "য","়" },
39838 ["ਲ਼"]={ "ਲ","਼" },
39839 ["ਸ਼"]={ "ਸ","਼" },
39840 ["ਖ਼"]={ "ਖ","਼" },
39841 ["ਗ਼"]={ "ਗ","਼" },
39842 ["ਜ਼"]={ "ਜ","਼" },
39843 ["ਫ਼"]={ "ਫ","਼" },
39844 ["ୈ"]={ "େ","ୖ" },
39845 ["ୋ"]={ "େ","ା" },
39846 ["ୌ"]={ "େ","ୗ" },
39847 ["ଡ଼"]={ "ଡ","଼" },
39848 ["ଢ଼"]={ "ଢ","଼" },
39849 ["ஔ"]={ "ஒ","ௗ" },
39850 ["ொ"]={ "ெ","ா" },
39851 ["ோ"]={ "ே","ா" },
39852 ["ௌ"]={ "ெ","ௗ" },
39853 ["ై"]={ "ె","ౖ" },
39854 ["ೀ"]={ "ಿ","ೕ" },
39855 ["ೇ"]={ "ೆ","ೕ" },
39856 ["ೈ"]={ "ೆ","ೖ" },
39857 ["ೊ"]={ "ೆ","ೂ" },
39858 ["ೋ"]={ "ೊ","ೕ" },
39859 ["ൊ"]={ "െ","ാ" },
39860 ["ോ"]={ "േ","ാ" },
39861 ["ൌ"]={ "െ","ൗ" },
39862 ["ේ"]={ "ෙ","්" },
39863 ["ො"]={ "ෙ","ා" },
39864 ["ෝ"]={ "ො","්" },
39865 ["ෞ"]={ "ෙ","ෟ" },
39866 ["གྷ"]={ "ག","ྷ" },
39867 ["ཌྷ"]={ "ཌ","ྷ" },
39868 ["དྷ"]={ "ད","ྷ" },
39869 ["བྷ"]={ "བ","ྷ" },
39870 ["ཛྷ"]={ "ཛ","ྷ" },
39871 ["ཀྵ"]={ "ཀ","ྵ" },
39872 ["ཱི"]={ "ཱ","ི" },
39873 ["ཱུ"]={ "ཱ","ུ" },
39874 ["ྲྀ"]={ "ྲ","ྀ" },
39875 ["ླྀ"]={ "ླ","ྀ" },
39876 ["ཱྀ"]={ "ཱ","ྀ" },
39877 ["ྒྷ"]={ "ྒ","ྷ" },
39878 ["ྜྷ"]={ "ྜ","ྷ" },
39879 ["ྡྷ"]={ "ྡ","ྷ" },
39880 ["ྦྷ"]={ "ྦ","ྷ" },
39881 ["ྫྷ"]={ "ྫ","ྷ" },
39882 ["ྐྵ"]={ "ྐ","ྵ" },
39883 ["ဦ"]={ "ဥ","ီ" },
39884 ["ᬆ"]={ "ᬅ","ᬵ" },
39885 ["ᬈ"]={ "ᬇ","ᬵ" },
39886 ["ᬊ"]={ "ᬉ","ᬵ" },
39887 ["ᬌ"]={ "ᬋ","ᬵ" },
39888 ["ᬎ"]={ "ᬍ","ᬵ" },
39889 ["ᬒ"]={ "ᬑ","ᬵ" },
39890 ["ᬻ"]={ "ᬺ","ᬵ" },
39891 ["ᬽ"]={ "ᬼ","ᬵ" },
39892 ["ᭀ"]={ "ᬾ","ᬵ" },
39893 ["ᭁ"]={ "ᬿ","ᬵ" },
39894 ["ᭃ"]={ "ᭂ","ᬵ" },
39895 ["Ḁ"]={ "A","̥" },
39896 ["ḁ"]={ "a","̥" },
39897 ["Ḃ"]={ "B","̇" },
39898 ["ḃ"]={ "b","̇" },
39899 ["Ḅ"]={ "B","̣" },
39900 ["ḅ"]={ "b","̣" },
39901 ["Ḇ"]={ "B","̱" },
39902 ["ḇ"]={ "b","̱" },
39903 ["Ḉ"]={ "Ç","́" },
39904 ["ḉ"]={ "ç","́" },
39905 ["Ḋ"]={ "D","̇" },
39906 ["ḋ"]={ "d","̇" },
39907 ["Ḍ"]={ "D","̣" },
39908 ["ḍ"]={ "d","̣" },
39909 ["Ḏ"]={ "D","̱" },
39910 ["ḏ"]={ "d","̱" },
39911 ["Ḑ"]={ "D","̧" },
39912 ["ḑ"]={ "d","̧" },
39913 ["Ḓ"]={ "D","̭" },
39914 ["ḓ"]={ "d","̭" },
39915 ["Ḕ"]={ "Ē","̀" },
39916 ["ḕ"]={ "ē","̀" },
39917 ["Ḗ"]={ "Ē","́" },
39918 ["ḗ"]={ "ē","́" },
39919 ["Ḙ"]={ "E","̭" },
39920 ["ḙ"]={ "e","̭" },
39921 ["Ḛ"]={ "E","̰" },
39922 ["ḛ"]={ "e","̰" },
39923 ["Ḝ"]={ "Ȩ","̆" },
39924 ["ḝ"]={ "ȩ","̆" },
39925 ["Ḟ"]={ "F","̇" },
39926 ["ḟ"]={ "f","̇" },
39927 ["Ḡ"]={ "G","̄" },
39928 ["ḡ"]={ "g","̄" },
39929 ["Ḣ"]={ "H","̇" },
39930 ["ḣ"]={ "h","̇" },
39931 ["Ḥ"]={ "H","̣" },
39932 ["ḥ"]={ "h","̣" },
39933 ["Ḧ"]={ "H","̈" },
39934 ["ḧ"]={ "h","̈" },
39935 ["Ḩ"]={ "H","̧" },
39936 ["ḩ"]={ "h","̧" },
39937 ["Ḫ"]={ "H","̮" },
39938 ["ḫ"]={ "h","̮" },
39939 ["Ḭ"]={ "I","̰" },
39940 ["ḭ"]={ "i","̰" },
39941 ["Ḯ"]={ "Ï","́" },
39942 ["ḯ"]={ "ï","́" },
39943 ["Ḱ"]={ "K","́" },
39944 ["ḱ"]={ "k","́" },
39945 ["Ḳ"]={ "K","̣" },
39946 ["ḳ"]={ "k","̣" },
39947 ["Ḵ"]={ "K","̱" },
39948 ["ḵ"]={ "k","̱" },
39949 ["Ḷ"]={ "L","̣" },
39950 ["ḷ"]={ "l","̣" },
39951 ["Ḹ"]={ "Ḷ","̄" },
39952 ["ḹ"]={ "ḷ","̄" },
39953 ["Ḻ"]={ "L","̱" },
39954 ["ḻ"]={ "l","̱" },
39955 ["Ḽ"]={ "L","̭" },
39956 ["ḽ"]={ "l","̭" },
39957 ["Ḿ"]={ "M","́" },
39958 ["ḿ"]={ "m","́" },
39959 ["Ṁ"]={ "M","̇" },
39960 ["ṁ"]={ "m","̇" },
39961 ["Ṃ"]={ "M","̣" },
39962 ["ṃ"]={ "m","̣" },
39963 ["Ṅ"]={ "N","̇" },
39964 ["ṅ"]={ "n","̇" },
39965 ["Ṇ"]={ "N","̣" },
39966 ["ṇ"]={ "n","̣" },
39967 ["Ṉ"]={ "N","̱" },
39968 ["ṉ"]={ "n","̱" },
39969 ["Ṋ"]={ "N","̭" },
39970 ["ṋ"]={ "n","̭" },
39971 ["Ṍ"]={ "Õ","́" },
39972 ["ṍ"]={ "õ","́" },
39973 ["Ṏ"]={ "Õ","̈" },
39974 ["ṏ"]={ "õ","̈" },
39975 ["Ṑ"]={ "Ō","̀" },
39976 ["ṑ"]={ "ō","̀" },
39977 ["Ṓ"]={ "Ō","́" },
39978 ["ṓ"]={ "ō","́" },
39979 ["Ṕ"]={ "P","́" },
39980 ["ṕ"]={ "p","́" },
39981 ["Ṗ"]={ "P","̇" },
39982 ["ṗ"]={ "p","̇" },
39983 ["Ṙ"]={ "R","̇" },
39984 ["ṙ"]={ "r","̇" },
39985 ["Ṛ"]={ "R","̣" },
39986 ["ṛ"]={ "r","̣" },
39987 ["Ṝ"]={ "Ṛ","̄" },
39988 ["ṝ"]={ "ṛ","̄" },
39989 ["Ṟ"]={ "R","̱" },
39990 ["ṟ"]={ "r","̱" },
39991 ["Ṡ"]={ "S","̇" },
39992 ["ṡ"]={ "s","̇" },
39993 ["Ṣ"]={ "S","̣" },
39994 ["ṣ"]={ "s","̣" },
39995 ["Ṥ"]={ "Ś","̇" },
39996 ["ṥ"]={ "ś","̇" },
39997 ["Ṧ"]={ "Š","̇" },
39998 ["ṧ"]={ "š","̇" },
39999 ["Ṩ"]={ "Ṣ","̇" },
40000 ["ṩ"]={ "ṣ","̇" },
40001 ["Ṫ"]={ "T","̇" },
40002 ["ṫ"]={ "t","̇" },
40003 ["Ṭ"]={ "T","̣" },
40004 ["ṭ"]={ "t","̣" },
40005 ["Ṯ"]={ "T","̱" },
40006 ["ṯ"]={ "t","̱" },
40007 ["Ṱ"]={ "T","̭" },
40008 ["ṱ"]={ "t","̭" },
40009 ["Ṳ"]={ "U","̤" },
40010 ["ṳ"]={ "u","̤" },
40011 ["Ṵ"]={ "U","̰" },
40012 ["ṵ"]={ "u","̰" },
40013 ["Ṷ"]={ "U","̭" },
40014 ["ṷ"]={ "u","̭" },
40015 ["Ṹ"]={ "Ũ","́" },
40016 ["ṹ"]={ "ũ","́" },
40017 ["Ṻ"]={ "Ū","̈" },
40018 ["ṻ"]={ "ū","̈" },
40019 ["Ṽ"]={ "V","̃" },
40020 ["ṽ"]={ "v","̃" },
40021 ["Ṿ"]={ "V","̣" },
40022 ["ṿ"]={ "v","̣" },
40023 ["Ẁ"]={ "W","̀" },
40024 ["ẁ"]={ "w","̀" },
40025 ["Ẃ"]={ "W","́" },
40026 ["ẃ"]={ "w","́" },
40027 ["Ẅ"]={ "W","̈" },
40028 ["ẅ"]={ "w","̈" },
40029 ["Ẇ"]={ "W","̇" },
40030 ["ẇ"]={ "w","̇" },
40031 ["Ẉ"]={ "W","̣" },
40032 ["ẉ"]={ "w","̣" },
40033 ["Ẋ"]={ "X","̇" },
40034 ["ẋ"]={ "x","̇" },
40035 ["Ẍ"]={ "X","̈" },
40036 ["ẍ"]={ "x","̈" },
40037 ["Ẏ"]={ "Y","̇" },
40038 ["ẏ"]={ "y","̇" },
40039 ["Ẑ"]={ "Z","̂" },
40040 ["ẑ"]={ "z","̂" },
40041 ["Ẓ"]={ "Z","̣" },
40042 ["ẓ"]={ "z","̣" },
40043 ["Ẕ"]={ "Z","̱" },
40044 ["ẕ"]={ "z","̱" },
40045 ["ẖ"]={ "h","̱" },
40046 ["ẗ"]={ "t","̈" },
40047 ["ẘ"]={ "w","̊" },
40048 ["ẙ"]={ "y","̊" },
40049 ["ẛ"]={ "ſ","̇" },
40050 ["Ạ"]={ "A","̣" },
40051 ["ạ"]={ "a","̣" },
40052 ["Ả"]={ "A","̉" },
40053 ["ả"]={ "a","̉" },
40054 ["Ấ"]={ "Â","́" },
40055 ["ấ"]={ "â","́" },
40056 ["Ầ"]={ "Â","̀" },
40057 ["ầ"]={ "â","̀" },
40058 ["Ẩ"]={ "Â","̉" },
40059 ["ẩ"]={ "â","̉" },
40060 ["Ẫ"]={ "Â","̃" },
40061 ["ẫ"]={ "â","̃" },
40062 ["Ậ"]={ "Ạ","̂" },
40063 ["ậ"]={ "ạ","̂" },
40064 ["Ắ"]={ "Ă","́" },
40065 ["ắ"]={ "ă","́" },
40066 ["Ằ"]={ "Ă","̀" },
40067 ["ằ"]={ "ă","̀" },
40068 ["Ẳ"]={ "Ă","̉" },
40069 ["ẳ"]={ "ă","̉" },
40070 ["Ẵ"]={ "Ă","̃" },
40071 ["ẵ"]={ "ă","̃" },
40072 ["Ặ"]={ "Ạ","̆" },
40073 ["ặ"]={ "ạ","̆" },
40074 ["Ẹ"]={ "E","̣" },
40075 ["ẹ"]={ "e","̣" },
40076 ["Ẻ"]={ "E","̉" },
40077 ["ẻ"]={ "e","̉" },
40078 ["Ẽ"]={ "E","̃" },
40079 ["ẽ"]={ "e","̃" },
40080 ["Ế"]={ "Ê","́" },
40081 ["ế"]={ "ê","́" },
40082 ["Ề"]={ "Ê","̀" },
40083 ["ề"]={ "ê","̀" },
40084 ["Ể"]={ "Ê","̉" },
40085 ["ể"]={ "ê","̉" },
40086 ["Ễ"]={ "Ê","̃" },
40087 ["ễ"]={ "ê","̃" },
40088 ["Ệ"]={ "Ẹ","̂" },
40089 ["ệ"]={ "ẹ","̂" },
40090 ["Ỉ"]={ "I","̉" },
40091 ["ỉ"]={ "i","̉" },
40092 ["Ị"]={ "I","̣" },
40093 ["ị"]={ "i","̣" },
40094 ["Ọ"]={ "O","̣" },
40095 ["ọ"]={ "o","̣" },
40096 ["Ỏ"]={ "O","̉" },
40097 ["ỏ"]={ "o","̉" },
40098 ["Ố"]={ "Ô","́" },
40099 ["ố"]={ "ô","́" },
40100 ["Ồ"]={ "Ô","̀" },
40101 ["ồ"]={ "ô","̀" },
40102 ["Ổ"]={ "Ô","̉" },
40103 ["ổ"]={ "ô","̉" },
40104 ["Ỗ"]={ "Ô","̃" },
40105 ["ỗ"]={ "ô","̃" },
40106 ["Ộ"]={ "Ọ","̂" },
40107 ["ộ"]={ "ọ","̂" },
40108 ["Ớ"]={ "Ơ","́" },
40109 ["ớ"]={ "ơ","́" },
40110 ["Ờ"]={ "Ơ","̀" },
40111 ["ờ"]={ "ơ","̀" },
40112 ["Ở"]={ "Ơ","̉" },
40113 ["ở"]={ "ơ","̉" },
40114 ["Ỡ"]={ "Ơ","̃" },
40115 ["ỡ"]={ "ơ","̃" },
40116 ["Ợ"]={ "Ơ","̣" },
40117 ["ợ"]={ "ơ","̣" },
40118 ["Ụ"]={ "U","̣" },
40119 ["ụ"]={ "u","̣" },
40120 ["Ủ"]={ "U","̉" },
40121 ["ủ"]={ "u","̉" },
40122 ["Ứ"]={ "Ư","́" },
40123 ["ứ"]={ "ư","́" },
40124 ["Ừ"]={ "Ư","̀" },
40125 ["ừ"]={ "ư","̀" },
40126 ["Ử"]={ "Ư","̉" },
40127 ["ử"]={ "ư","̉" },
40128 ["Ữ"]={ "Ư","̃" },
40129 ["ữ"]={ "ư","̃" },
40130 ["Ự"]={ "Ư","̣" },
40131 ["ự"]={ "ư","̣" },
40132 ["Ỳ"]={ "Y","̀" },
40133 ["ỳ"]={ "y","̀" },
40134 ["Ỵ"]={ "Y","̣" },
40135 ["ỵ"]={ "y","̣" },
40136 ["Ỷ"]={ "Y","̉" },
40137 ["ỷ"]={ "y","̉" },
40138 ["Ỹ"]={ "Y","̃" },
40139 ["ỹ"]={ "y","̃" },
40140 ["ἀ"]={ "α","̓" },
40141 ["ἁ"]={ "α","̔" },
40142 ["ἂ"]={ "ἀ","̀" },
40143 ["ἃ"]={ "ἁ","̀" },
40144 ["ἄ"]={ "ἀ","́" },
40145 ["ἅ"]={ "ἁ","́" },
40146 ["ἆ"]={ "ἀ","͂" },
40147 ["ἇ"]={ "ἁ","͂" },
40148 ["Ἀ"]={ "Α","̓" },
40149 ["Ἁ"]={ "Α","̔" },
40150 ["Ἂ"]={ "Ἀ","̀" },
40151 ["Ἃ"]={ "Ἁ","̀" },
40152 ["Ἄ"]={ "Ἀ","́" },
40153 ["Ἅ"]={ "Ἁ","́" },
40154 ["Ἆ"]={ "Ἀ","͂" },
40155 ["Ἇ"]={ "Ἁ","͂" },
40156 ["ἐ"]={ "ε","̓" },
40157 ["ἑ"]={ "ε","̔" },
40158 ["ἒ"]={ "ἐ","̀" },
40159 ["ἓ"]={ "ἑ","̀" },
40160 ["ἔ"]={ "ἐ","́" },
40161 ["ἕ"]={ "ἑ","́" },
40162 ["Ἐ"]={ "Ε","̓" },
40163 ["Ἑ"]={ "Ε","̔" },
40164 ["Ἒ"]={ "Ἐ","̀" },
40165 ["Ἓ"]={ "Ἑ","̀" },
40166 ["Ἔ"]={ "Ἐ","́" },
40167 ["Ἕ"]={ "Ἑ","́" },
40168 ["ἠ"]={ "η","̓" },
40169 ["ἡ"]={ "η","̔" },
40170 ["ἢ"]={ "ἠ","̀" },
40171 ["ἣ"]={ "ἡ","̀" },
40172 ["ἤ"]={ "ἠ","́" },
40173 ["ἥ"]={ "ἡ","́" },
40174 ["ἦ"]={ "ἠ","͂" },
40175 ["ἧ"]={ "ἡ","͂" },
40176 ["Ἠ"]={ "Η","̓" },
40177 ["Ἡ"]={ "Η","̔" },
40178 ["Ἢ"]={ "Ἠ","̀" },
40179 ["Ἣ"]={ "Ἡ","̀" },
40180 ["Ἤ"]={ "Ἠ","́" },
40181 ["Ἥ"]={ "Ἡ","́" },
40182 ["Ἦ"]={ "Ἠ","͂" },
40183 ["Ἧ"]={ "Ἡ","͂" },
40184 ["ἰ"]={ "ι","̓" },
40185 ["ἱ"]={ "ι","̔" },
40186 ["ἲ"]={ "ἰ","̀" },
40187 ["ἳ"]={ "ἱ","̀" },
40188 ["ἴ"]={ "ἰ","́" },
40189 ["ἵ"]={ "ἱ","́" },
40190 ["ἶ"]={ "ἰ","͂" },
40191 ["ἷ"]={ "ἱ","͂" },
40192 ["Ἰ"]={ "Ι","̓" },
40193 ["Ἱ"]={ "Ι","̔" },
40194 ["Ἲ"]={ "Ἰ","̀" },
40195 ["Ἳ"]={ "Ἱ","̀" },
40196 ["Ἴ"]={ "Ἰ","́" },
40197 ["Ἵ"]={ "Ἱ","́" },
40198 ["Ἶ"]={ "Ἰ","͂" },
40199 ["Ἷ"]={ "Ἱ","͂" },
40200 ["ὀ"]={ "ο","̓" },
40201 ["ὁ"]={ "ο","̔" },
40202 ["ὂ"]={ "ὀ","̀" },
40203 ["ὃ"]={ "ὁ","̀" },
40204 ["ὄ"]={ "ὀ","́" },
40205 ["ὅ"]={ "ὁ","́" },
40206 ["Ὀ"]={ "Ο","̓" },
40207 ["Ὁ"]={ "Ο","̔" },
40208 ["Ὂ"]={ "Ὀ","̀" },
40209 ["Ὃ"]={ "Ὁ","̀" },
40210 ["Ὄ"]={ "Ὀ","́" },
40211 ["Ὅ"]={ "Ὁ","́" },
40212 ["ὐ"]={ "υ","̓" },
40213 ["ὑ"]={ "υ","̔" },
40214 ["ὒ"]={ "ὐ","̀" },
40215 ["ὓ"]={ "ὑ","̀" },
40216 ["ὔ"]={ "ὐ","́" },
40217 ["ὕ"]={ "ὑ","́" },
40218 ["ὖ"]={ "ὐ","͂" },
40219 ["ὗ"]={ "ὑ","͂" },
40220 ["Ὑ"]={ "Υ","̔" },
40221 ["Ὓ"]={ "Ὑ","̀" },
40222 ["Ὕ"]={ "Ὑ","́" },
40223 ["Ὗ"]={ "Ὑ","͂" },
40224 ["ὠ"]={ "ω","̓" },
40225 ["ὡ"]={ "ω","̔" },
40226 ["ὢ"]={ "ὠ","̀" },
40227 ["ὣ"]={ "ὡ","̀" },
40228 ["ὤ"]={ "ὠ","́" },
40229 ["ὥ"]={ "ὡ","́" },
40230 ["ὦ"]={ "ὠ","͂" },
40231 ["ὧ"]={ "ὡ","͂" },
40232 ["Ὠ"]={ "Ω","̓" },
40233 ["Ὡ"]={ "Ω","̔" },
40234 ["Ὢ"]={ "Ὠ","̀" },
40235 ["Ὣ"]={ "Ὡ","̀" },
40236 ["Ὤ"]={ "Ὠ","́" },
40237 ["Ὥ"]={ "Ὡ","́" },
40238 ["Ὦ"]={ "Ὠ","͂" },
40239 ["Ὧ"]={ "Ὡ","͂" },
40240 ["ὰ"]={ "α","̀" },
40241 ["ὲ"]={ "ε","̀" },
40242 ["ὴ"]={ "η","̀" },
40243 ["ὶ"]={ "ι","̀" },
40244 ["ὸ"]={ "ο","̀" },
40245 ["ὺ"]={ "υ","̀" },
40246 ["ὼ"]={ "ω","̀" },
40247 ["ᾀ"]={ "ἀ","ͅ" },
40248 ["ᾁ"]={ "ἁ","ͅ" },
40249 ["ᾂ"]={ "ἂ","ͅ" },
40250 ["ᾃ"]={ "ἃ","ͅ" },
40251 ["ᾄ"]={ "ἄ","ͅ" },
40252 ["ᾅ"]={ "ἅ","ͅ" },
40253 ["ᾆ"]={ "ἆ","ͅ" },
40254 ["ᾇ"]={ "ἇ","ͅ" },
40255 ["ᾈ"]={ "Ἀ","ͅ" },
40256 ["ᾉ"]={ "Ἁ","ͅ" },
40257 ["ᾊ"]={ "Ἂ","ͅ" },
40258 ["ᾋ"]={ "Ἃ","ͅ" },
40259 ["ᾌ"]={ "Ἄ","ͅ" },
40260 ["ᾍ"]={ "Ἅ","ͅ" },
40261 ["ᾎ"]={ "Ἆ","ͅ" },
40262 ["ᾏ"]={ "Ἇ","ͅ" },
40263 ["ᾐ"]={ "ἠ","ͅ" },
40264 ["ᾑ"]={ "ἡ","ͅ" },
40265 ["ᾒ"]={ "ἢ","ͅ" },
40266 ["ᾓ"]={ "ἣ","ͅ" },
40267 ["ᾔ"]={ "ἤ","ͅ" },
40268 ["ᾕ"]={ "ἥ","ͅ" },
40269 ["ᾖ"]={ "ἦ","ͅ" },
40270 ["ᾗ"]={ "ἧ","ͅ" },
40271 ["ᾘ"]={ "Ἠ","ͅ" },
40272 ["ᾙ"]={ "Ἡ","ͅ" },
40273 ["ᾚ"]={ "Ἢ","ͅ" },
40274 ["ᾛ"]={ "Ἣ","ͅ" },
40275 ["ᾜ"]={ "Ἤ","ͅ" },
40276 ["ᾝ"]={ "Ἥ","ͅ" },
40277 ["ᾞ"]={ "Ἦ","ͅ" },
40278 ["ᾟ"]={ "Ἧ","ͅ" },
40279 ["ᾠ"]={ "ὠ","ͅ" },
40280 ["ᾡ"]={ "ὡ","ͅ" },
40281 ["ᾢ"]={ "ὢ","ͅ" },
40282 ["ᾣ"]={ "ὣ","ͅ" },
40283 ["ᾤ"]={ "ὤ","ͅ" },
40284 ["ᾥ"]={ "ὥ","ͅ" },
40285 ["ᾦ"]={ "ὦ","ͅ" },
40286 ["ᾧ"]={ "ὧ","ͅ" },
40287 ["ᾨ"]={ "Ὠ","ͅ" },
40288 ["ᾩ"]={ "Ὡ","ͅ" },
40289 ["ᾪ"]={ "Ὢ","ͅ" },
40290 ["ᾫ"]={ "Ὣ","ͅ" },
40291 ["ᾬ"]={ "Ὤ","ͅ" },
40292 ["ᾭ"]={ "Ὥ","ͅ" },
40293 ["ᾮ"]={ "Ὦ","ͅ" },
40294 ["ᾯ"]={ "Ὧ","ͅ" },
40295 ["ᾰ"]={ "α","̆" },
40296 ["ᾱ"]={ "α","̄" },
40297 ["ᾲ"]={ "ὰ","ͅ" },
40298 ["ᾳ"]={ "α","ͅ" },
40299 ["ᾴ"]={ "ά","ͅ" },
40300 ["ᾶ"]={ "α","͂" },
40301 ["ᾷ"]={ "ᾶ","ͅ" },
40302 ["Ᾰ"]={ "Α","̆" },
40303 ["Ᾱ"]={ "Α","̄" },
40304 ["Ὰ"]={ "Α","̀" },
40305 ["ᾼ"]={ "Α","ͅ" },
40306 ["῁"]={ "¨","͂" },
40307 ["ῂ"]={ "ὴ","ͅ" },
40308 ["ῃ"]={ "η","ͅ" },
40309 ["ῄ"]={ "ή","ͅ" },
40310 ["ῆ"]={ "η","͂" },
40311 ["ῇ"]={ "ῆ","ͅ" },
40312 ["Ὲ"]={ "Ε","̀" },
40313 ["Ὴ"]={ "Η","̀" },
40314 ["ῌ"]={ "Η","ͅ" },
40315 ["῍"]={ "᾿","̀" },
40316 ["῎"]={ "᾿","́" },
40317 ["῏"]={ "᾿","͂" },
40318 ["ῐ"]={ "ι","̆" },
40319 ["ῑ"]={ "ι","̄" },
40320 ["ῒ"]={ "ϊ","̀" },
40321 ["ῖ"]={ "ι","͂" },
40322 ["ῗ"]={ "ϊ","͂" },
40323 ["Ῐ"]={ "Ι","̆" },
40324 ["Ῑ"]={ "Ι","̄" },
40325 ["Ὶ"]={ "Ι","̀" },
40326 ["῝"]={ "῾","̀" },
40327 ["῞"]={ "῾","́" },
40328 ["῟"]={ "῾","͂" },
40329 ["ῠ"]={ "υ","̆" },
40330 ["ῡ"]={ "υ","̄" },
40331 ["ῢ"]={ "ϋ","̀" },
40332 ["ῤ"]={ "ρ","̓" },
40333 ["ῥ"]={ "ρ","̔" },
40334 ["ῦ"]={ "υ","͂" },
40335 ["ῧ"]={ "ϋ","͂" },
40336 ["Ῠ"]={ "Υ","̆" },
40337 ["Ῡ"]={ "Υ","̄" },
40338 ["Ὺ"]={ "Υ","̀" },
40339 ["Ῥ"]={ "Ρ","̔" },
40340 ["῭"]={ "¨","̀" },
40341 ["ῲ"]={ "ὼ","ͅ" },
40342 ["ῳ"]={ "ω","ͅ" },
40343 ["ῴ"]={ "ώ","ͅ" },
40344 ["ῶ"]={ "ω","͂" },
40345 ["ῷ"]={ "ῶ","ͅ" },
40346 ["Ὸ"]={ "Ο","̀" },
40347 ["Ὼ"]={ "Ω","̀" },
40348 ["ῼ"]={ "Ω","ͅ" },
40349 ["↚"]={ "←","̸" },
40350 ["↛"]={ "→","̸" },
40351 ["↮"]={ "↔","̸" },
40352 ["⇍"]={ "⇐","̸" },
40353 ["⇎"]={ "⇔","̸" },
40354 ["⇏"]={ "⇒","̸" },
40355 ["∄"]={ "∃","̸" },
40356 ["∉"]={ "∈","̸" },
40357 ["∌"]={ "∋","̸" },
40358 ["∤"]={ "∣","̸" },
40359 ["∦"]={ "∥","̸" },
40360 ["≁"]={ "∼","̸" },
40361 ["≄"]={ "≃","̸" },
40362 ["≇"]={ "≅","̸" },
40363 ["≉"]={ "≈","̸" },
40364 ["≠"]={ "=","̸" },
40365 ["≢"]={ "≡","̸" },
40366 ["≭"]={ "≍","̸" },
40367 ["≮"]={ "<","̸" },
40368 ["≯"]={ ">","̸" },
40369 ["≰"]={ "≤","̸" },
40370 ["≱"]={ "≥","̸" },
40371 ["≴"]={ "≲","̸" },
40372 ["≵"]={ "≳","̸" },
40373 ["≸"]={ "≶","̸" },
40374 ["≹"]={ "≷","̸" },
40375 ["⊀"]={ "≺","̸" },
40376 ["⊁"]={ "≻","̸" },
40377 ["⊄"]={ "⊂","̸" },
40378 ["⊅"]={ "⊃","̸" },
40379 ["⊈"]={ "⊆","̸" },
40380 ["⊉"]={ "⊇","̸" },
40381 ["⊬"]={ "⊢","̸" },
40382 ["⊭"]={ "⊨","̸" },
40383 ["⊮"]={ "⊩","̸" },
40384 ["⊯"]={ "⊫","̸" },
40385 ["⋠"]={ "≼","̸" },
40386 ["⋡"]={ "≽","̸" },
40387 ["⋢"]={ "⊑","̸" },
40388 ["⋣"]={ "⊒","̸" },
40389 ["⋪"]={ "⊲","̸" },
40390 ["⋫"]={ "⊳","̸" },
40391 ["⋬"]={ "⊴","̸" },
40392 ["⋭"]={ "⊵","̸" },
40393 ["⫝̸"]={ "⫝","̸" },
40394 ["が"]={ "か","゙" },
40395 ["ぎ"]={ "き","゙" },
40396 ["ぐ"]={ "く","゙" },
40397 ["げ"]={ "け","゙" },
40398 ["ご"]={ "こ","゙" },
40399 ["ざ"]={ "さ","゙" },
40400 ["じ"]={ "し","゙" },
40401 ["ず"]={ "す","゙" },
40402 ["ぜ"]={ "せ","゙" },
40403 ["ぞ"]={ "そ","゙" },
40404 ["だ"]={ "た","゙" },
40405 ["ぢ"]={ "ち","゙" },
40406 ["づ"]={ "つ","゙" },
40407 ["で"]={ "て","゙" },
40408 ["ど"]={ "と","゙" },
40409 ["ば"]={ "は","゙" },
40410 ["ぱ"]={ "は","゚" },
40411 ["び"]={ "ひ","゙" },
40412 ["ぴ"]={ "ひ","゚" },
40413 ["ぶ"]={ "ふ","゙" },
40414 ["ぷ"]={ "ふ","゚" },
40415 ["べ"]={ "へ","゙" },
40416 ["ぺ"]={ "へ","゚" },
40417 ["ぼ"]={ "ほ","゙" },
40418 ["ぽ"]={ "ほ","゚" },
40419 ["ゔ"]={ "う","゙" },
40420 ["ゞ"]={ "ゝ","゙" },
40421 ["ガ"]={ "カ","゙" },
40422 ["ギ"]={ "キ","゙" },
40423 ["グ"]={ "ク","゙" },
40424 ["ゲ"]={ "ケ","゙" },
40425 ["ゴ"]={ "コ","゙" },
40426 ["ザ"]={ "サ","゙" },
40427 ["ジ"]={ "シ","゙" },
40428 ["ズ"]={ "ス","゙" },
40429 ["ゼ"]={ "セ","゙" },
40430 ["ゾ"]={ "ソ","゙" },
40431 ["ダ"]={ "タ","゙" },
40432 ["ヂ"]={ "チ","゙" },
40433 ["ヅ"]={ "ツ","゙" },
40434 ["デ"]={ "テ","゙" },
40435 ["ド"]={ "ト","゙" },
40436 ["バ"]={ "ハ","゙" },
40437 ["パ"]={ "ハ","゚" },
40438 ["ビ"]={ "ヒ","゙" },
40439 ["ピ"]={ "ヒ","゚" },
40440 ["ブ"]={ "フ","゙" },
40441 ["プ"]={ "フ","゚" },
40442 ["ベ"]={ "ヘ","゙" },
40443 ["ペ"]={ "ヘ","゚" },
40444 ["ボ"]={ "ホ","゙" },
40445 ["ポ"]={ "ホ","゚" },
40446 ["ヴ"]={ "ウ","゙" },
40447 ["ヷ"]={ "ワ","゙" },
40448 ["ヸ"]={ "ヰ","゙" },
40449 ["ヹ"]={ "ヱ","゙" },
40450 ["ヺ"]={ "ヲ","゙" },
40451 ["ヾ"]={ "ヽ","゙" },
40452 ["יִ"]={ "י","ִ" },
40453 ["ײַ"]={ "ײ","ַ" },
40454 ["שׁ"]={ "ש","ׁ" },
40455 ["שׂ"]={ "ש","ׂ" },
40456 ["שּׁ"]={ "שּ","ׁ" },
40457 ["שּׂ"]={ "שּ","ׂ" },
40458 ["אַ"]={ "א","ַ" },
40459 ["אָ"]={ "א","ָ" },
40460 ["אּ"]={ "א","ּ" },
40461 ["בּ"]={ "ב","ּ" },
40462 ["גּ"]={ "ג","ּ" },
40463 ["דּ"]={ "ד","ּ" },
40464 ["הּ"]={ "ה","ּ" },
40465 ["וּ"]={ "ו","ּ" },
40466 ["זּ"]={ "ז","ּ" },
40467 ["טּ"]={ "ט","ּ" },
40468 ["יּ"]={ "י","ּ" },
40469 ["ךּ"]={ "ך","ּ" },
40470 ["כּ"]={ "כ","ּ" },
40471 ["לּ"]={ "ל","ּ" },
40472 ["מּ"]={ "מ","ּ" },
40473 ["נּ"]={ "נ","ּ" },
40474 ["סּ"]={ "ס","ּ" },
40475 ["ףּ"]={ "ף","ּ" },
40476 ["פּ"]={ "פ","ּ" },
40477 ["צּ"]={ "צ","ּ" },
40478 ["קּ"]={ "ק","ּ" },
40479 ["רּ"]={ "ר","ּ" },
40480 ["שּ"]={ "ש","ּ" },
40481 ["תּ"]={ "ת","ּ" },
40482 ["וֹ"]={ "ו","ֹ" },
40483 ["בֿ"]={ "ב","ֿ" },
40484 ["כֿ"]={ "כ","ֿ" },
40485 ["פֿ"]={ "פ","ֿ" },
40486 ["𑂚"]={ "𑂙","𑂺" },
40487 ["𑂜"]={ "𑂛","𑂺" },
40488 ["𑂫"]={ "𑂥","𑂺" },
40489 ["𑄮"]={ "𑄱","𑄧" },
40490 ["𑄯"]={ "𑄲","𑄧" },
40491 ["𑍋"]={ "𑍇","𑌾" },
40492 ["𑍌"]={ "𑍇","𑍗" },
40493 ["𑒻"]={ "𑒹","𑒺" },
40494 ["𑒼"]={ "𑒹","𑒰" },
40495 ["𑒾"]={ "𑒹","𑒽" },
40496 ["𑖺"]={ "𑖸","𑖯" },
40497 ["𑖻"]={ "𑖹","𑖯" },
40498 ["𝅗𝅥"]={ "𝅗","𝅥" },
40499 ["𝅘𝅥"]={ "𝅘","𝅥" },
40500 ["𝅘𝅥𝅮"]={ "𝅘𝅥","𝅮" },
40501 ["𝅘𝅥𝅯"]={ "𝅘𝅥","𝅯" },
40502 ["𝅘𝅥𝅰"]={ "𝅘𝅥","𝅰" },
40503 ["𝅘𝅥𝅱"]={ "𝅘𝅥","𝅱" },
40504 ["𝅘𝅥𝅲"]={ "𝅘𝅥","𝅲" },
40505 ["𝆹𝅥"]={ "𝆹","𝅥" },
40506 ["𝆺𝅥"]={ "𝆺","𝅥" },
40507 ["𝆹𝅥𝅮"]={ "𝆹𝅥","𝅮" },
40508 ["𝆺𝅥𝅮"]={ "𝆺𝅥","𝅮" },
40509 ["𝆹𝅥𝅯"]={ "𝆹𝅥","𝅯" },
40510 ["𝆺𝅥𝅯"]={ "𝆺𝅥","𝅯" },
40511 },
40512 },
40513 },
40514 ["name"]="collapse",
40515 ["prepend"]=true,
40516 ["type"]="ligature",
40517 }
40518
40519 end -- closure
40520
40521 do -- begin closure to overcome local limits and interference
40522
40523 if not modules then modules={} end modules ['luatex-fonts-gbn']={
40524 version=1.001,
40525 comment="companion to luatex-*.tex",
40526 author="Hans Hagen, PRAGMA-ADE, Hasselt NL",
40527 copyright="PRAGMA ADE / ConTeXt Development Team",
40528 license="see context related readme files"
40529 }
40530 if context then
40531 --removed
40532
40533 end
40534 local next=next
40535 local fonts=fonts
40536 local nodes=nodes
40537 local nuts=nodes.nuts
40538 local traverseid=nuts.traverseid
40539 local flushnode=nuts.flushnode
40540 local glyph_code=nodes.nodecodes.glyph
40541 local disc_code=nodes.nodecodes.disc
40542 local tonode=nuts.tonode
40543 local tonut=nuts.tonut
40544 local getfont=nuts.getfont
40545 local getchar=nuts.getchar
40546 local getid=nuts.getid
40547 local getboth=nuts.getboth
40548 local getprev=nuts.getprev
40549 local getnext=nuts.getnext
40550 local getdisc=nuts.getdisc
40551 local setchar=nuts.setchar
40552 local setlink=nuts.setlink
40553 local setprev=nuts.setprev
40554 local n_ligaturing=node.ligaturing
40555 local n_kerning=node.kerning
40556 local d_ligaturing=nuts.ligaturing
40557 local d_kerning=nuts.kerning
40558 local basemodepass=true
40559 local function l_warning() logs.report("fonts","don't call 'node.ligaturing' directly") l_warning=nil end
40560 local function k_warning() logs.report("fonts","don't call 'node.kerning' directly") k_warning=nil end
40561 function node.ligaturing(...)
40562 if basemodepass and l_warning then
40563 l_warning()
40564 end
40565 return n_ligaturing(...)
40566 end
40567 function node.kerning(...)
40568 if basemodepass and k_warning then
40569 k_warning()
40570 end
40571 return n_kerning(...)
40572 end
40573 function nuts.ligaturing(...)
40574 if basemodepass and l_warning then
40575 l_warning()
40576 end
40577 return d_ligaturing(...)
40578 end
40579 function nuts.kerning(...)
40580 if basemodepass and k_warning then
40581 k_warning()
40582 end
40583 return d_kerning(...)
40584 end
40585 function nodes.handlers.setbasemodepass(v)
40586 basemodepass=v
40587 end
40588 local function nodepass(head,groupcode,size,packtype,direction)
40589 local fontdata=fonts.hashes.identifiers
40590 if fontdata then
40591 local usedfonts={}
40592 local basefonts={}
40593 local prevfont=nil
40594 local basefont=nil
40595 local variants=nil
40596 local redundant=nil
40597 local nofused=0
40598 for n in traverseid(glyph_code,head) do
40599 local font=getfont(n)
40600 if font~=prevfont then
40601 if basefont then
40602 basefont[2]=getprev(n)
40603 end
40604 prevfont=font
40605 local used=usedfonts[font]
40606 if not used then
40607 local tfmdata=fontdata[font]
40608 if tfmdata then
40609 local shared=tfmdata.shared
40610 if shared then
40611 local processors=shared.processes
40612 if processors and #processors>0 then
40613 usedfonts[font]=processors
40614 nofused=nofused+1
40615 elseif basemodepass then
40616 basefont={ n,nil }
40617 basefonts[#basefonts+1]=basefont
40618 end
40619 end
40620 local resources=tfmdata.resources
40621 variants=resources and resources.variants
40622 variants=variants and next(variants) and variants or false
40623 end
40624 else
40625 local tfmdata=fontdata[prevfont]
40626 if tfmdata then
40627 local resources=tfmdata.resources
40628 variants=resources and resources.variants
40629 variants=variants and next(variants) and variants or false
40630 end
40631 end
40632 end
40633 if variants then
40634 local char=getchar(n)
40635 if (char>=0xFE00 and char<=0xFE0F) or (char>=0xE0100 and char<=0xE01EF) then
40636 local hash=variants[char]
40637 if hash then
40638 local p=getprev(n)
40639 if p and getid(p)==glyph_code then
40640 local variant=hash[getchar(p)]
40641 if variant then
40642 setchar(p,variant)
40643 end
40644 end
40645 end
40646 if not redundant then
40647 redundant={ n }
40648 else
40649 redundant[#redundant+1]=n
40650 end
40651 end
40652 end
40653 end
40654 local nofbasefonts=#basefonts
40655 if redundant then
40656 for i=1,#redundant do
40657 local r=redundant[i]
40658 local p,n=getboth(r)
40659 if r==head then
40660 head=n
40661 setprev(n)
40662 else
40663 setlink(p,n)
40664 end
40665 if nofbasefonts>0 then
40666 for i=1,nofbasefonts do
40667 local bi=basefonts[i]
40668 if r==bi[1] then
40669 bi[1]=n
40670 end
40671 if r==bi[2] then
40672 bi[2]=n
40673 end
40674 end
40675 end
40676 flushnode(r)
40677 end
40678 end
40679 for d in traverseid(disc_code,head) do
40680 local _,_,r=getdisc(d)
40681 if r then
40682 for n in traverseid(glyph_code,r) do
40683 local font=getfont(n)
40684 if font~=prevfont then
40685 prevfont=font
40686 local used=usedfonts[font]
40687 if not used then
40688 local tfmdata=fontdata[font]
40689 if tfmdata then
40690 local shared=tfmdata.shared
40691 if shared then
40692 local processors=shared.processes
40693 if processors and #processors>0 then
40694 usedfonts[font]=processors
40695 nofused=nofused+1
40696 end
40697 end
40698 end
40699 end
40700 end
40701 end
40702 end
40703 end
40704 if next(usedfonts) then
40705 for font,processors in next,usedfonts do
40706 for i=1,#processors do
40707 head=processors[i](head,font,0,direction,nofused) or head
40708 end
40709 end
40710 end
40711 if basemodepass and nofbasefonts>0 then
40712 for i=1,nofbasefonts do
40713 local range=basefonts[i]
40714 local start=range[1]
40715 local stop=range[2]
40716 if start then
40717 local front=head==start
40718 local prev,next
40719 if stop then
40720 next=getnext(stop)
40721 start,stop=d_ligaturing(start,stop)
40722 start,stop=d_kerning(start,stop)
40723 else
40724 prev=getprev(start)
40725 start=d_ligaturing(start)
40726 start=d_kerning(start)
40727 end
40728 if prev then
40729 setlink(prev,start)
40730 end
40731 if next then
40732 setlink(stop,next)
40733 end
40734 if front and head~=start then
40735 head=start
40736 end
40737 end
40738 end
40739 end
40740 end
40741 return head
40742 end
40743 local function basepass(head)
40744 if basemodepass then
40745 head=d_ligaturing(head)
40746 head=d_kerning(head)
40747 end
40748 return head
40749 end
40750 local protectpass=node.direct.protectglyphs or node.direct.protect_glyphs
40751 local injectpass=nodes.injections.handler
40752 function nodes.handlers.nodepass(head,...)
40753 if head then
40754 return tonode(nodepass(tonut(head),...))
40755 end
40756 end
40757 function nodes.handlers.basepass(head)
40758 if head then
40759 return tonode(basepass(tonut(head)))
40760 end
40761 end
40762 function nodes.handlers.injectpass(head)
40763 if head then
40764 return tonode(injectpass(tonut(head)))
40765 end
40766 end
40767 function nodes.handlers.protectpass(head)
40768 if head then
40769 protectpass(tonut(head))
40770 return head
40771 end
40772 end
40773 function nodes.simple_font_handler(head,groupcode,size,packtype,direction)
40774 if head then
40775 head=tonut(head)
40776 head=nodepass(head,groupcode,size,packtype,direction)
40777 head=injectpass(head)
40778 if not basemodepass then
40779 head=basepass(head)
40780 end
40781 protectpass(head)
40782 head=tonode(head)
40783 end
40784 return head
40785 end
40786
40787 end -- closure