summaryrefslogtreecommitdiff
path: root/tex
diff options
context:
space:
mode:
Diffstat (limited to 'tex')
-rw-r--r--tex/context/base/mkii/cont-new.mkii2
-rw-r--r--tex/context/base/mkii/context.mkii2
-rw-r--r--tex/context/base/mkii/mult-cs.mkii2
-rw-r--r--tex/context/base/mkiv/cont-new.mkiv2
-rw-r--r--tex/context/base/mkiv/context.mkiv2
-rw-r--r--tex/context/base/mkiv/l-macro-imp-optimize.lua3
-rw-r--r--tex/context/base/mkiv/l-number.lua52
-rw-r--r--tex/context/base/mkiv/mult-def.lua6
-rw-r--r--tex/context/base/mkiv/status-files.pdfbin23958 -> 23954 bytes
-rw-r--r--tex/context/base/mkiv/status-lua.pdfbin225830 -> 225900 bytes
-rw-r--r--tex/context/base/mkiv/util-sac.lua4
-rw-r--r--tex/context/base/mkxl/anch-pgr.lmt2
-rw-r--r--tex/context/base/mkxl/back-pdf.mkxl8
-rw-r--r--tex/context/base/mkxl/cont-new.mkxl2
-rw-r--r--tex/context/base/mkxl/context.mkxl2
-rw-r--r--tex/context/base/mkxl/core-sys.mkxl19
-rw-r--r--tex/context/base/mkxl/driv-shp.lmt46
-rw-r--r--tex/context/base/mkxl/driv-shp.mkxl2
-rw-r--r--tex/context/base/mkxl/font-otj.lmt30
-rw-r--r--tex/context/base/mkxl/l-number.lmt105
-rw-r--r--tex/context/base/mkxl/l-unicode.lmt808
-rw-r--r--tex/context/base/mkxl/lang-ini.mkxl30
-rw-r--r--tex/context/base/mkxl/lpdf-aux.lmt2
-rw-r--r--tex/context/base/mkxl/lpdf-emb.lmt68
-rw-r--r--tex/context/base/mkxl/lpdf-epa.lmt5
-rw-r--r--tex/context/base/mkxl/lpdf-img.lmt883
-rw-r--r--tex/context/base/mkxl/lpdf-ini.lmt25
-rw-r--r--tex/context/base/mkxl/lpdf-lmt.lmt45
-rw-r--r--tex/context/base/mkxl/lpdf-wid.lmt2
-rw-r--r--tex/context/base/mkxl/luat-bas.mkxl6
-rw-r--r--tex/context/base/mkxl/luat-lib.mkxl4
-rw-r--r--tex/context/base/mkxl/math-ini.mkxl4
-rw-r--r--tex/context/base/mkxl/math-map.lmt809
-rw-r--r--tex/context/base/mkxl/math-noa.lmt9
-rw-r--r--tex/context/base/mkxl/mlib-cnt.lmt4
-rw-r--r--tex/context/base/mkxl/mlib-ctx.mkxl4
-rw-r--r--tex/context/base/mkxl/mlib-svg.lmt4
-rw-r--r--tex/context/base/mkxl/spac-ali.mkxl2
-rw-r--r--tex/context/base/mkxl/syst-aux.mkxl2
-rw-r--r--tex/context/base/mkxl/toks-aux.lmt10
-rw-r--r--tex/context/base/mkxl/trac-vis.lmt63
-rw-r--r--tex/context/base/mkxl/trac-vis.mkxl2
-rw-r--r--tex/context/base/mkxl/typo-cap.mkxl1
-rw-r--r--tex/context/base/mkxl/typo-dir.lmt212
-rw-r--r--tex/context/base/mkxl/typo-dir.mkxl2
-rw-r--r--tex/context/base/mkxl/util-fil.lmt163
-rw-r--r--tex/context/base/mkxl/util-sac.lmt285
-rw-r--r--tex/context/interface/mkii/keys-cs.xml2
-rw-r--r--tex/generic/context/luatex/luatex-fonts-merged.lua2
49 files changed, 3048 insertions, 701 deletions
diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii
index 119202772..133f5ce71 100644
--- a/tex/context/base/mkii/cont-new.mkii
+++ b/tex/context/base/mkii/cont-new.mkii
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\newcontextversion{2021.05.06 23:31}
+\newcontextversion{2021.05.09 17:12}
%D This file is loaded at runtime, thereby providing an
%D excellent place for hacks, patches, extensions and new
diff --git a/tex/context/base/mkii/context.mkii b/tex/context/base/mkii/context.mkii
index fd62edc3b..f5a02b246 100644
--- a/tex/context/base/mkii/context.mkii
+++ b/tex/context/base/mkii/context.mkii
@@ -20,7 +20,7 @@
%D your styles an modules.
\edef\contextformat {\jobname}
-\edef\contextversion{2021.05.06 23:31}
+\edef\contextversion{2021.05.09 17:12}
%D For those who want to use this:
diff --git a/tex/context/base/mkii/mult-cs.mkii b/tex/context/base/mkii/mult-cs.mkii
index 72369ad89..8645dd34b 100644
--- a/tex/context/base/mkii/mult-cs.mkii
+++ b/tex/context/base/mkii/mult-cs.mkii
@@ -141,6 +141,7 @@
\setinterfacevariable{chemistry}{chemistry}
\setinterfacevariable{cite}{cite}
\setinterfacevariable{closed}{closed}
+\setinterfacevariable{collapsed}{collapsed}
\setinterfacevariable{color}{barevne}
\setinterfacevariable{column}{column}
\setinterfacevariable{columns}{sloupce}
@@ -392,6 +393,7 @@
\setinterfacevariable{nostopper}{nostopper}
\setinterfacevariable{not}{ne}
\setinterfacevariable{notation}{notation}
+\setinterfacevariable{notcollapsed}{notcollapsed}
\setinterfacevariable{note}{note}
\setinterfacevariable{nothanging}{nothanging}
\setinterfacevariable{nothyphenated}{nothyphenated}
diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv
index 44bbf2253..9d7c8e584 100644
--- a/tex/context/base/mkiv/cont-new.mkiv
+++ b/tex/context/base/mkiv/cont-new.mkiv
@@ -13,7 +13,7 @@
% \normalend % uncomment this to get the real base runtime
-\newcontextversion{2021.05.06 23:31}
+\newcontextversion{2021.05.09 17:12}
%D This file is loaded at runtime, thereby providing an excellent place for hacks,
%D patches, extensions and new features. There can be local overloads in cont-loc
diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv
index 1e4ecb731..b0a0aae71 100644
--- a/tex/context/base/mkiv/context.mkiv
+++ b/tex/context/base/mkiv/context.mkiv
@@ -45,7 +45,7 @@
%D {YYYY.MM.DD HH:MM} format.
\edef\contextformat {\jobname}
-\edef\contextversion{2021.05.06 23:31}
+\edef\contextversion{2021.05.09 17:12}
%D Kind of special:
diff --git a/tex/context/base/mkiv/l-macro-imp-optimize.lua b/tex/context/base/mkiv/l-macro-imp-optimize.lua
index 1ecaef7d4..c343dfa74 100644
--- a/tex/context/base/mkiv/l-macro-imp-optimize.lua
+++ b/tex/context/base/mkiv/l-macro-imp-optimize.lua
@@ -28,7 +28,7 @@ if LUAVERSION >= 5.3 and lua.macros then
-- This indirect method makes it possible to use both the functions
-- and the inline variant (which often looks better). Also, a mixed
- -- 5,2 and 5.3 source is not possible because the 5.2 doesn't deal
+ -- 5.2 and 5.3 source is not possible because the 5.2 doesn't deal
-- with the newer 5.3 syntax.
-- We need to check for 64 usage: 0xFFFFFFFFFFFFFFFF (-1)
@@ -44,6 +44,7 @@ lua.macros.resolvestring [[
#define extract1(a,b) ((a >> b) & 0x01)
#define extract2(a,b) ((a >> b) & 0x03)
#define extract4(a,b) ((a >> b) & 0x0F)
+#define extract8(a,b) ((a >> b) & 0xFF)
#define lshift(a,b) (((a)<<(b))&0xFFFFFFFF)
#define rshift(a,b) (((a)>>(b))&0xFFFFFFFF)
#define intdiv(a,b) ((a)//(b))
diff --git a/tex/context/base/mkiv/l-number.lua b/tex/context/base/mkiv/l-number.lua
index 9fd2f82f7..0ec60880d 100644
--- a/tex/context/base/mkiv/l-number.lua
+++ b/tex/context/base/mkiv/l-number.lua
@@ -1,16 +1,13 @@
if not modules then modules = { } end modules ['l-number'] = {
version = 1.001,
- comment = "companion to luat-lib.mkiv",
+ comment = "companion to luat-lib.mkxl",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
--- this module will be replaced when we have the bit library .. the number based sets
--- might go away
-
local tostring, tonumber = tostring, tonumber
-local format, floor, match, rep = string.format, math.floor, string.match, string.rep
+local format, match, rep = string.format, string.match, string.rep
local concat, insert = table.concat, table.insert
local lpegmatch = lpeg.match
local floor = math.floor
@@ -18,51 +15,6 @@ local floor = math.floor
number = number or { }
local number = number
--- begin obsolete code --
-
--- if bit32 then
---
--- local btest, bor = bit32.btest, bit32.bor
---
--- function number.bit(p)
--- return 2 ^ (p - 1) -- 1-based indexing
--- end
---
--- number.hasbit = btest
--- number.setbit = bor
---
--- function number.setbit(x,p) -- why not bor?
--- return btest(x,p) and x or x + p
--- end
---
--- function number.clearbit(x,p)
--- return btest(x,p) and x - p or x
--- end
---
--- else
---
--- -- http://ricilake.blogspot.com/2007/10/iterating-bits-in-lua.html
---
--- function number.bit(p)
--- return 2 ^ (p - 1) -- 1-based indexing
--- end
---
--- function number.hasbit(x, p) -- typical call: if hasbit(x, bit(3)) then ...
--- return x % (p + p) >= p
--- end
---
--- function number.setbit(x, p)
--- return (x % (p + p) >= p) and x or x + p
--- end
---
--- function number.clearbit(x, p)
--- return (x % (p + p) >= p) and x - p or x
--- end
---
--- end
-
--- end obsolete code --
-
-- print(number.tobitstring(8))
-- print(number.tobitstring(14))
-- print(number.tobitstring(66))
diff --git a/tex/context/base/mkiv/mult-def.lua b/tex/context/base/mkiv/mult-def.lua
index 6168da413..2bcfdf74c 100644
--- a/tex/context/base/mkiv/mult-def.lua
+++ b/tex/context/base/mkiv/mult-def.lua
@@ -15983,6 +15983,9 @@ return {
["pe"]="افقی",
["ro"]="orizontal",
},
+ ["collapsed"]={
+ ["en"]="collapsed",
+ },
["hyphenated"]={
["cs"]="hyphenated",
["de"]="hyphenate",
@@ -17239,6 +17242,9 @@ return {
["pe"]="بدون‌آویزان‌کردن",
["ro"]="nothanging",
},
+ ["notcollapsed"]={
+ ["en"]="notcollapsed",
+ },
["nothyphenated"]={
["cs"]="nothyphenated",
["de"]="nothyphenated",
diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf
index 7d80be3cf..ae7b876b7 100644
--- a/tex/context/base/mkiv/status-files.pdf
+++ b/tex/context/base/mkiv/status-files.pdf
Binary files differ
diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf
index 4b993fa62..e5e48e356 100644
--- a/tex/context/base/mkiv/status-lua.pdf
+++ b/tex/context/base/mkiv/status-lua.pdf
Binary files differ
diff --git a/tex/context/base/mkiv/util-sac.lua b/tex/context/base/mkiv/util-sac.lua
index a8851f4c8..522b0bc08 100644
--- a/tex/context/base/mkiv/util-sac.lua
+++ b/tex/context/base/mkiv/util-sac.lua
@@ -377,10 +377,10 @@ if sio and sio.readcardinal2 then
f[2] = i + 4
return readfixed4(f[1],i)
end
- function streams.read2dot4(f)
+ function streams.read2dot14(f)
local i = f[2]
f[2] = i + 2
- return read2dot4(f[1],i)
+ return read2dot14(f[1],i)
end
function streams.readbytes(f,n)
local i = f[2]
diff --git a/tex/context/base/mkxl/anch-pgr.lmt b/tex/context/base/mkxl/anch-pgr.lmt
index c30c456d5..e561f8b79 100644
--- a/tex/context/base/mkxl/anch-pgr.lmt
+++ b/tex/context/base/mkxl/anch-pgr.lmt
@@ -251,8 +251,6 @@ interfaces.implement {
-- optimized already but we can assume a cycle i.e. prune the last point and then
-- even less code .. we could merge some loops but his is more robust
--- use idiv here
-
local function topairs(t,n)
local r = { }
for i=1,n do
diff --git a/tex/context/base/mkxl/back-pdf.mkxl b/tex/context/base/mkxl/back-pdf.mkxl
index d59c29bc0..baa90ff22 100644
--- a/tex/context/base/mkxl/back-pdf.mkxl
+++ b/tex/context/base/mkxl/back-pdf.mkxl
@@ -17,8 +17,8 @@
\writestatus{loading}{ConTeXt Backend Macros / PDF}
-\registerctxluafile{lpdf-ini}{autosuffix,optimize}
-\registerctxluafile{lpdf-lmt}{autosuffix,optimize}
+\registerctxluafile{lpdf-ini}{autosuffix}
+\registerctxluafile{lpdf-lmt}{autosuffix}
\registerctxluafile{lpdf-col}{autosuffix}
\registerctxluafile{lpdf-xmp}{autosuffix}
\registerctxluafile{lpdf-ano}{autosuffix}
@@ -34,9 +34,9 @@
\registerctxluafile{lpdf-tag}{autosuffix}
\registerctxluafile{lpdf-fmt}{autosuffix}
\registerctxluafile{lpdf-pde}{autosuffix}
-\registerctxluafile{lpdf-img}{autosuffix,optimize}
+\registerctxluafile{lpdf-img}{autosuffix}
\registerctxluafile{lpdf-epa}{autosuffix}
-\registerctxluafile{lpdf-emb}{autosuffix,optimize}
+\registerctxluafile{lpdf-emb}{autosuffix}
\registerctxluafile{lpdf-fnt}{autosuffix}
\registerctxluafile{lpdf-rul}{autosuffix}
diff --git a/tex/context/base/mkxl/cont-new.mkxl b/tex/context/base/mkxl/cont-new.mkxl
index e9e866256..bcd32fcda 100644
--- a/tex/context/base/mkxl/cont-new.mkxl
+++ b/tex/context/base/mkxl/cont-new.mkxl
@@ -13,7 +13,7 @@
% \normalend % uncomment this to get the real base runtime
-\newcontextversion{2021.05.06 23:31}
+\newcontextversion{2021.05.09 17:12}
%D This file is loaded at runtime, thereby providing an excellent place for hacks,
%D patches, extensions and new features. There can be local overloads in cont-loc
diff --git a/tex/context/base/mkxl/context.mkxl b/tex/context/base/mkxl/context.mkxl
index 25fc6ca26..47f4f3e1a 100644
--- a/tex/context/base/mkxl/context.mkxl
+++ b/tex/context/base/mkxl/context.mkxl
@@ -29,7 +29,7 @@
%D {YYYY.MM.DD HH:MM} format.
\immutable\edef\contextformat {\jobname}
-\immutable\edef\contextversion{2021.05.06 23:31}
+\immutable\edef\contextversion{2021.05.09 17:12}
%overloadmode 1 % check frozen / warning
%overloadmode 2 % check frozen / error
diff --git a/tex/context/base/mkxl/core-sys.mkxl b/tex/context/base/mkxl/core-sys.mkxl
index c5093588e..832098315 100644
--- a/tex/context/base/mkxl/core-sys.mkxl
+++ b/tex/context/base/mkxl/core-sys.mkxl
@@ -233,12 +233,27 @@
%
% \ignorestartstop[bagger]
+%D When looking at an application of \type {\beginsimplegroup} and \type I wondered
+%D about this one but it doesn't make much sense. One hould define highlights that
+%D have style and color, but on the other hand, we might want to combine a font
+%D style and some other treatment. The overhead of commalists (where we can use
+%D {\aftergrouped} for collecting stop tags) is neglectable but it makes no sense.
+%D Maybe we need a \type {command} or better (as commands can take arguments) a
+%D \type {setups} key, but no one ever asked so \unknown.
+
+% \processnextcommalist\typo_highlights_step ...
+%
+% list : 10K single: 0.111 / 0.132 with command / 0.134 with setups
+% single: 10K single: 0.075 / 0.098 with command / 0.099 with setups
+
\installcorenamespace{highlight}
\installcommandhandler \??highlight {highlight} \??highlight % we could do with less
\setuphighlight
[\c!define=\v!yes]
+% \c!command=,
+% \c!setups=]
\appendtoks
\ifcstok{\highlightparameter\c!define}\v!yes
@@ -253,6 +268,8 @@
{\def\currenthighlight{#1}%
\dostarttagged\t!highlight\currenthighlight
\usehighlightstyleandcolor\c!style\c!color
+ % \usehighlightstyleandcolor\c!style\c!color
+ % \highlightparameter\c!command
\dotaghighlight}
{\dostoptagged}}
@@ -264,6 +281,8 @@
\def\currenthighlight{#1}%
\dostarttagged\t!highlight\currenthighlight
\usehighlightstyleandcolor\c!style\c!color
+ % \usehighlightstyleandcolor\c!style\c!color
+ % \highlightparameter\c!command
\dotaghighlight}
\permanent\protected\def\stophighlight
diff --git a/tex/context/base/mkxl/driv-shp.lmt b/tex/context/base/mkxl/driv-shp.lmt
index 2be1fd105..0fe0e5f9f 100644
--- a/tex/context/base/mkxl/driv-shp.lmt
+++ b/tex/context/base/mkxl/driv-shp.lmt
@@ -17,10 +17,8 @@ local sortedhash = table.sortedhash
local splitstring = string.split
local find = string.find
local stripstring = string.strip
-local idiv = number.idiv
local sequenced = table.sequenced
local round = math.round
-local extract = bit32.extract
local nuts = nodes.nuts
local tonut = nodes.tonut
@@ -168,18 +166,6 @@ local flush_character do
local vfinjectors = fonts.helpers.vfinjectors
- local function flushchar(current,font,char,fnt,chr,f,e)
- if fnt then
- local nest = char ~= chr or font ~= fnt
- if fnt == 0 then
- fnt = main
- end
- return flush_character(current,fnt,chr,factor,nest,pos_h,pos_v,pos_r,f,e)
- else
- return 0
- end
- end
-
local function flush_vf_packet(current,pos_h,pos_v,pos_r,font,char,data,factor,vfcommands,sx,sy)
if nesting > 100 then
@@ -214,6 +200,18 @@ local flush_character do
-- we assume resolved fonts: id mandate but maybe also size
+ local function flushchar(fnt,chr,f,e) -- can't be moved out of the function due to binding locals
+ if fnt then -- to the function variables etc etc ... kind of messy
+ local nest = char ~= chr or font ~= fnt
+ if fnt == 0 then
+ fnt = main
+ end
+ return flush_character(current,fnt,chr,factor,nest,pos_h,pos_v,pos_r,f,e)
+ else
+ return 0
+ end
+ end
+
for i=1,#vfcommands do
local packet = vfcommands[i]
local command = packet[1]
@@ -221,24 +219,24 @@ local flush_character do
local chr = packet[2]
local f = packet[3]
local e = packet[4]
- pos_h = pos_h + flushchar(current,font,char,fnt,chr,f,e)
+ pos_h = pos_h + flushchar(fnt,chr,f,e)
elseif command == "slot" then
local index = packet[2]
local chr = packet[3]
local f = packet[4]
local e = packet[5]
if index == 0 then
- pos_h = pos_h + flushchar(current,font,char,font,chr,f,e)
+ pos_h = pos_h + flushchar(font,chr,f,e)
else
local okay = fonts and fonts[index]
if okay then
local fnt = okay.id
if fnt then
- pos_h = pos_h + flushchar(current,font,char,fnt,chr,f,e)
+ pos_h = pos_h + flushchar(fnt,chr,f,e)
end
else
-- safeguard, we assume the font itself (often index 1)
- pos_h = pos_h + flushchar(current,font,char,font,chr,f,e)
+ pos_h = pos_h + flushchar(font,chr,f,e)
end
end
elseif command == "use" then
@@ -309,7 +307,7 @@ local flush_character do
pos_v = pos_v + v * sy
end
if c then
- flushchar(current,font,char,fnt,c)
+ flushchar(fnt,c)
pos_h = ph
pos_v = pv
end
@@ -329,7 +327,7 @@ local flush_character do
pos_v = pos_v + v * sy
end
if c then
- flushchar(current,font,char,fnt,c)
+ flushchar(fnt,c)
pos_h = ph
pos_v = pv
end
@@ -601,10 +599,10 @@ end
local hlist_out, vlist_out do
local function applyanchor(orientation,x,y,width,height,depth,woffset,hoffset,doffset,xoffset,yoffset)
- local ot = extract(orientation, 0,4)
- local ay = extract(orientation, 4,4)
- local ax = extract(orientation, 8,4)
- local of = extract(orientation,12,4)
+ local ot = (orientation>> 0) & x0F
+ local ay = (orientation>> 4) & x0F
+ local ax = (orientation>> 8) & x0F
+ local of = (orientation>>12) & x0F
if ot == 4 then
ot, ay = 0, 1
elseif ot == 5 then
diff --git a/tex/context/base/mkxl/driv-shp.mkxl b/tex/context/base/mkxl/driv-shp.mkxl
index 199215a59..52da9d2b5 100644
--- a/tex/context/base/mkxl/driv-shp.mkxl
+++ b/tex/context/base/mkxl/driv-shp.mkxl
@@ -11,7 +11,7 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\registerctxluafile{driv-shp}{autosuffix,optimize}
+\registerctxluafile{driv-shp}{autosuffix}
\unprotect
diff --git a/tex/context/base/mkxl/font-otj.lmt b/tex/context/base/mkxl/font-otj.lmt
index 8f0f4d33c..adbce23e1 100644
--- a/tex/context/base/mkxl/font-otj.lmt
+++ b/tex/context/base/mkxl/font-otj.lmt
@@ -132,7 +132,6 @@ end
local useitalickerns = false
local useadvance = false
-local usezwjkerns = true -- when useadvance
directives.register("fonts.injections.useitalics", function(v)
if v then
@@ -1016,14 +1015,8 @@ local function inject_kerns_only_margins(head,where)
if i then
local leftkern = i.leftkern
if leftkern and leftkern ~= 0 then
- if usezwjkerns then
- replace = copynode(current)
- setchar(replace,0x200D) -- zwj
- addxymargins(replace,-leftkern)
- else
- replace = somekern(fontkern,xscaled(current,leftkern),current)
- end
- setdisc(prevdisc,pre,post,replace) -- setreplace
+ -- prev disc | current
+ addxymargins(current,-leftkern) -- NEEDS CHECKING
end
end
end
@@ -1711,13 +1704,8 @@ local function inject_positions_only_margins(head,where)
if replace then
-- error, we expect an empty one
else
- if usezwjkerns then
- replace = copynode(current)
- setchar(replace,0x200D) -- zwj
- addxymargins(replace,false,-rightkern)
- else
- replace = somekern(fontkern,xscaled(current,rightkern),current) -- maybe also leftkern
- end
+ -- next disc | current
+ addxymargins(current,-rightkern) -- NEEDS CHECKING
done = true --KE
end
end
@@ -1748,14 +1736,8 @@ local function inject_positions_only_margins(head,where)
-- new .. okay?
local leftkern = i.leftkern
if leftkern and leftkern ~= 0 then
- if usezwjkerns then
- replace = copynode(current)
- setchar(replace,0x200D) -- zwj
- addxymargins(replace,-leftkern)
- else
- replace = somekern(fontkern,xscaled(current,leftkern),current)
- end
- setdisc(prevdisc,pre,post,replace)
+ -- prev disc | current
+ addxymargins(current,-leftkern) -- NEEDS CHECKING
end
end
end
diff --git a/tex/context/base/mkxl/l-number.lmt b/tex/context/base/mkxl/l-number.lmt
new file mode 100644
index 000000000..e13ac8260
--- /dev/null
+++ b/tex/context/base/mkxl/l-number.lmt
@@ -0,0 +1,105 @@
+if not modules then modules = { } end modules ['l-number'] = {
+ version = 1.001,
+ comment = "companion to luat-lib.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- See l-number.lua for the more generic (also 5.2) versions of the
+-- functions below ... that file evolved over time.
+
+local tonumber = tonumber
+local format = string.format
+local concat = table.concat
+local floor = math.floor
+
+number = number or { }
+local number = number
+
+-- print(number.tobitstring(8))
+-- print(number.tobitstring(14))
+-- print(number.tobitstring(66))
+-- print(number.tobitstring(0x00))
+-- print(number.tobitstring(0xFF))
+-- print(number.tobitstring(46260767936,4))
+
+local t = {
+ "0", "0", "0", "0", "0", "0", "0", "0",
+ "0", "0", "0", "0", "0", "0", "0", "0",
+ "0", "0", "0", "0", "0", "0", "0", "0",
+ "0", "0", "0", "0", "0", "0", "0", "0",
+}
+
+function number.tobitstring(b,m,w)
+ if not w then
+ w = 32
+ end
+ local n = w
+ for i=0,w-1 do
+ local v = (b>>i) & 0x1 -- bextract(b,i)
+ local k = w - i
+ if v == 1 then
+ n = k
+ t[k] = "1"
+ else
+ t[k] = "0"
+ end
+ end
+ if w then
+ return concat(t,"",1,w)
+ elseif m then
+ m = 33 - m * 8
+ if m < 1 then
+ m = 1
+ end
+ return concat(t,"",1,m)
+ elseif n < 8 then
+ return concat(t)
+ elseif n < 16 then
+ return concat(t,"",9)
+ elseif n < 24 then
+ return concat(t,"",17)
+ else
+ return concat(t,"",25)
+ end
+end
+
+function number.valid(str,default)
+ return tonumber(str) or default or nil
+end
+
+function number.toevenhex(n)
+ local s = format("%X",n)
+ if #s % 2 == 0 then
+ return s
+ else
+ return "0" .. s
+ end
+end
+
+function number.bytetodecimal(b)
+ local d = floor(b * 100 / 255 + 0.5)
+ if d > 100 then
+ return 100
+ elseif d < -100 then
+ return -100
+ else
+ return d
+ end
+end
+
+function number.decimaltobyte(d)
+ local b = floor(d * 255 / 100 + 0.5)
+ if b > 255 then
+ return 255
+ elseif b < -255 then
+ return -255
+ else
+ return b
+ end
+end
+
+function number.idiv(i,d)
+ return i // d
+end
diff --git a/tex/context/base/mkxl/l-unicode.lmt b/tex/context/base/mkxl/l-unicode.lmt
new file mode 100644
index 000000000..f2c94b1c2
--- /dev/null
+++ b/tex/context/base/mkxl/l-unicode.lmt
@@ -0,0 +1,808 @@
+if not modules then modules = { } end modules ['l-unicode'] = {
+ version = 1.001,
+ optimize = true,
+ comment = "companion to luat-lib.mkxl",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- See l-unicode.lua for the more generic (also 5.2) versions of the
+-- functions below ... that file evolved over time.
+--
+-- In lua 5.3+ we have:
+--
+-- utf8.char(···) : concatinated
+-- utf8.charpatt : "[\0-\x7F\xC2-\xF4][\x80-\xBF]*"
+-- utf8.codes(s) : for p, c in utf8.codes(s) do body end
+-- utf8.codepoint(s [, i [, j]])
+-- utf8.len(s [, i])
+-- utf8.offset(s, n [, i])
+
+utf = utf or { }
+unicode = nil
+
+local type = type
+local char, byte, format, sub, gmatch, rep = string.char, string.byte, string.format, string.sub, string.gmatch, string.rep
+local concat = table.concat
+local P, C, R, Cs, Ct, Cmt, Cc, Carg, Cp = lpeg.P, lpeg.C, lpeg.R, lpeg.Cs, lpeg.Ct, lpeg.Cmt, lpeg.Cc, lpeg.Carg, lpeg.Cp
+
+local lpegmatch = lpeg.match
+local patterns = lpeg.patterns
+local tabletopattern = lpeg.utfchartabletopattern
+
+local finder = lpeg.finder
+local replacer = lpeg.replacer
+
+local p_utftype = patterns.utftype
+local p_utfstricttype = patterns.utfstricttype
+local p_utfoffset = patterns.utfoffset
+local p_utf8character = patterns.utf8character
+local p_utf8char = patterns.utf8char
+local p_utf8byte = patterns.utf8byte
+local p_utfbom = patterns.utfbom
+local p_newline = patterns.newline
+local p_whitespace = patterns.whitespace
+
+local utfchar = string.utfcharacter
+local utfbyte = string.utfvalue
+local utflength = string.utflength
+local utfcharacters = string.utfcharacters
+local utfbytepairs = string.bytepairs
+
+-- string.utfvalues
+-- string.characters
+-- string.characterpairs
+-- string.bytes
+-- string.utflength
+-- string.utfvalues
+
+utf.char = utfchar
+utf.byte = utfbyte
+utf.len = utflength
+utf.length = utflength
+utf.characters = utfcharacters
+utf.bytepairs = utfbytepairs
+
+function utf.filetype(data)
+ return data and lpegmatch(p_utftype,data) or "unknown"
+end
+
+do
+
+ local toentities = Cs (
+ (
+ patterns.utf8one
+ + (
+ patterns.utf8two
+ + patterns.utf8three
+ + patterns.utf8four
+ ) / function(s) local b = utfbyte(s) if b < 127 then return s else return format("&#%X;",b) end end
+ )^0
+ )
+
+ patterns.toentities = toentities
+
+ function utf.toentities(str)
+ return lpegmatch(toentities,str)
+ end
+
+end
+
+do
+
+ local one = P(1)
+ local two = C(1) * C(1)
+ local four = C(R(utfchar(0xD8),utfchar(0xFF))) * C(1) * C(1) * C(1)
+
+ local pattern =
+ P("\254\255") * Cs( (
+ four / function(a,b,c,d)
+ local ab = 0xFF * byte(a) + byte(b)
+ local cd = 0xFF * byte(c) + byte(d)
+ return utfchar((ab-0xD800)*0x400 + (cd-0xDC00) + 0x10000)
+ end
+ + two / function(a,b)
+ return utfchar(byte(a)*256 + byte(b))
+ end
+ + one
+ )^1 )
+ + P("\255\254") * Cs( (
+ four / function(b,a,d,c)
+ local ab = 0xFF * byte(a) + byte(b)
+ local cd = 0xFF * byte(c) + byte(d)
+ return utfchar((ab-0xD800)*0x400 + (cd-0xDC00) + 0x10000)
+ end
+ + two / function(b,a)
+ return utfchar(byte(a)*256 + byte(b))
+ end
+ + one
+ )^1 )
+
+ function string.toutf(s) -- in string namespace
+ return lpegmatch(pattern,s) or s -- todo: utf32
+ end
+
+end
+
+do
+
+ local validatedutf = Cs (
+ (
+ patterns.utf8one
+ + patterns.utf8two
+ + patterns.utf8three
+ + patterns.utf8four
+ + P(1) / "�"
+ )^0
+ )
+
+ patterns.validatedutf = validatedutf
+
+ function utf.is_valid(str)
+ return type(str) == "string" and lpegmatch(validatedutf,str) or false
+ end
+
+end
+
+if not utf.sub then
+
+ -- also negative indices, upto 10 times slower than a c variant
+
+ local b, e, n, first, last = 0, 0, 0, 0, 0
+
+ local function slide_zero(s,p)
+ n = n + 1
+ if n >= last then
+ e = p - 1
+ else
+ return p
+ end
+ end
+
+ local function slide_one(s,p)
+ n = n + 1
+ if n == first then
+ b = p
+ end
+ if n >= last then
+ e = p - 1
+ else
+ return p
+ end
+ end
+
+ local function slide_two(s,p)
+ n = n + 1
+ if n == first then
+ b = p
+ else
+ return true
+ end
+ end
+
+ local pattern_zero = Cmt(p_utf8character,slide_zero)^0
+ local pattern_one = Cmt(p_utf8character,slide_one )^0
+ local pattern_two = Cmt(p_utf8character,slide_two )^0
+
+ local pattern_first = C(p_utf8character)
+
+ function utf.sub(str,start,stop)
+ if not start then
+ return str
+ end
+ if start == 0 then
+ start = 1
+ end
+ if not stop then
+ if start < 0 then
+ local l = utflength(str) -- we can inline this function if needed
+ start = l + start
+ else
+ start = start - 1
+ end
+ b, n, first = 0, 0, start
+ lpegmatch(pattern_two,str)
+ if n >= first then
+ return sub(str,b)
+ else
+ return ""
+ end
+ end
+ if start < 0 or stop < 0 then
+ local l = utf.length(str)
+ if start < 0 then
+ start = l + start
+ if start <= 0 then
+ start = 1
+ else
+ start = start + 1
+ end
+ end
+ if stop < 0 then
+ stop = l + stop
+ if stop == 0 then
+ stop = 1
+ else
+ stop = stop + 1
+ end
+ end
+ end
+ if start == 1 and stop == 1 then
+ return lpegmatch(pattern_first,str) or ""
+ elseif start > stop then
+ return ""
+ elseif start > 1 then
+ b, e, n, first, last = 0, 0, 0, start - 1, stop
+ lpegmatch(pattern_one,str)
+ if n >= first and e == 0 then
+ e = #str
+ end
+ return sub(str,b,e)
+ else
+ b, e, n, last = 1, 0, 0, stop
+ lpegmatch(pattern_zero,str)
+ if e == 0 then
+ e = #str
+ end
+ return sub(str,b,e)
+ end
+ end
+
+ -- local n = 100000
+ -- local str = string.rep("123456àáâãäå",100)
+ --
+ -- for i=-15,15,1 do
+ -- for j=-15,15,1 do
+ -- if utf.xsub(str,i,j) ~= utf.sub(str,i,j) then
+ -- print("error",i,j,"l>"..utf.xsub(str,i,j),"s>"..utf.sub(str,i,j))
+ -- end
+ -- end
+ -- if utf.xsub(str,i) ~= utf.sub(str,i) then
+ -- print("error",i,"l>"..utf.xsub(str,i),"s>"..utf.sub(str,i))
+ -- end
+ -- end
+
+ -- print(" 1, 7",utf.xsub(str, 1, 7),utf.sub(str, 1, 7))
+ -- print(" 0, 7",utf.xsub(str, 0, 7),utf.sub(str, 0, 7))
+ -- print(" 0, 9",utf.xsub(str, 0, 9),utf.sub(str, 0, 9))
+ -- print(" 4 ",utf.xsub(str, 4 ),utf.sub(str, 4 ))
+ -- print(" 0 ",utf.xsub(str, 0 ),utf.sub(str, 0 ))
+ -- print(" 0, 0",utf.xsub(str, 0, 0),utf.sub(str, 0, 0))
+ -- print(" 4, 4",utf.xsub(str, 4, 4),utf.sub(str, 4, 4))
+ -- print(" 4, 0",utf.xsub(str, 4, 0),utf.sub(str, 4, 0))
+ -- print("-3, 0",utf.xsub(str,-3, 0),utf.sub(str,-3, 0))
+ -- print(" 0,-3",utf.xsub(str, 0,-3),utf.sub(str, 0,-3))
+ -- print(" 5,-3",utf.xsub(str,-5,-3),utf.sub(str,-5,-3))
+ -- print("-3 ",utf.xsub(str,-3 ),utf.sub(str,-3 ))
+
+end
+
+function utf.remapper(mapping,option,action) -- static also returns a pattern
+ local variant = type(mapping)
+ if variant == "table" then
+ action = action or mapping
+ if option == "dynamic" then
+ local pattern = false
+ table.setmetatablenewindex(mapping,function(t,k,v) rawset(t,k,v) pattern = false end)
+ return function(str)
+ if not str or str == "" then
+ return ""
+ else
+ if not pattern then
+ pattern = Cs((tabletopattern(mapping)/action + p_utf8character)^0)
+ end
+ return lpegmatch(pattern,str)
+ end
+ end
+ elseif option == "pattern" then
+ return Cs((tabletopattern(mapping)/action + p_utf8character)^0)
+ -- elseif option == "static" then
+ else
+ local pattern = Cs((tabletopattern(mapping)/action + p_utf8character)^0)
+ return function(str)
+ if not str or str == "" then
+ return ""
+ else
+ return lpegmatch(pattern,str)
+ end
+ end, pattern
+ end
+ elseif variant == "function" then
+ if option == "pattern" then
+ return Cs((p_utf8character/mapping + p_utf8character)^0)
+ else
+ local pattern = Cs((p_utf8character/mapping + p_utf8character)^0)
+ return function(str)
+ if not str or str == "" then
+ return ""
+ else
+ return lpegmatch(pattern,str)
+ end
+ end, pattern
+ end
+ else
+ -- is actually an error
+ return function(str)
+ return str or ""
+ end
+ end
+end
+
+-- local remap = utf.remapper { a = 'd', b = "c", c = "b", d = "a" }
+-- print(remap("abcd 1234 abcd"))
+
+function utf.replacer(t) -- no precheck, always string builder
+ local r = replacer(t,false,false,true)
+ return function(str)
+ return lpegmatch(r,str)
+ end
+end
+
+function utf.subtituter(t) -- with precheck and no building if no match
+ local f = finder (t)
+ local r = replacer(t,false,false,true)
+ return function(str)
+ local i = lpegmatch(f,str)
+ if not i then
+ return str
+ elseif i > #str then
+ return str
+ else
+ -- return sub(str,1,i-2) .. lpegmatch(r,str,i-1) -- slower
+ return lpegmatch(r,str)
+ end
+ end
+end
+
+-- inspect(utf.split("a b c d"))
+-- inspect(utf.split("a b c d",true))
+
+local utflinesplitter = p_utfbom^-1 * lpeg.tsplitat(p_newline)
+local utfcharsplitter_ows = p_utfbom^-1 * Ct(C(p_utf8character)^0)
+local utfcharsplitter_iws = p_utfbom^-1 * Ct((p_whitespace^1 + C(p_utf8character))^0)
+local utfcharsplitter_raw = Ct(C(p_utf8character)^0)
+
+patterns.utflinesplitter = utflinesplitter
+
+function utf.splitlines(str)
+ return lpegmatch(utflinesplitter,str or "")
+end
+
+function utf.split(str,ignorewhitespace) -- new
+ if ignorewhitespace then
+ return lpegmatch(utfcharsplitter_iws,str or "")
+ else
+ return lpegmatch(utfcharsplitter_ows,str or "")
+ end
+end
+
+function utf.totable(str) -- keeps bom
+ return lpegmatch(utfcharsplitter_raw,str)
+end
+
+-- 0 EF BB BF UTF-8
+-- 1 FF FE UTF-16-little-endian
+-- 2 FE FF UTF-16-big-endian
+-- 3 FF FE 00 00 UTF-32-little-endian
+-- 4 00 00 FE FF UTF-32-big-endian
+--
+-- \000 fails in <= 5.0 but is valid in >=5.1 where %z is depricated
+
+-- utf.name = {
+-- [0] = 'utf-8',
+-- [1] = 'utf-16-le',
+-- [2] = 'utf-16-be',
+-- [3] = 'utf-32-le',
+-- [4] = 'utf-32-be'
+-- }
+
+function utf.magic(f) -- not used
+ local str = f:read(4) or ""
+ local off = lpegmatch(p_utfoffset,str)
+ if off < 4 then
+ f:seek('set',off)
+ end
+ return lpegmatch(p_utftype,str)
+end
+
+local utf_16_be_getbom = patterns.utfbom_16_be^-1
+local utf_16_le_getbom = patterns.utfbom_16_le^-1
+local utf_32_be_getbom = patterns.utfbom_32_be^-1
+local utf_32_le_getbom = patterns.utfbom_32_le^-1
+
+local utf_16_be_linesplitter = utf_16_be_getbom * lpeg.tsplitat(patterns.utf_16_be_nl)
+local utf_16_le_linesplitter = utf_16_le_getbom * lpeg.tsplitat(patterns.utf_16_le_nl)
+local utf_32_be_linesplitter = utf_32_be_getbom * lpeg.tsplitat(patterns.utf_32_be_nl)
+local utf_32_le_linesplitter = utf_32_le_getbom * lpeg.tsplitat(patterns.utf_32_le_nl)
+
+local more = 0
+
+local p_utf16_to_utf8_be = C(1) * C(1) /function(left,right)
+ local now = 256*byte(left) + byte(right)
+ if more > 0 then
+ now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000
+ more = 0
+ return utfchar(now)
+ elseif now >= 0xD800 and now <= 0xDBFF then
+ more = now
+ return "" -- else the c's end up in the stream
+ else
+ return utfchar(now)
+ end
+end
+
+local p_utf16_to_utf8_le = C(1) * C(1) /function(right,left)
+ local now = 256*byte(left) + byte(right)
+ if more > 0 then
+ now = (more-0xD800)*0x400 + (now-0xDC00) + 0x10000
+ more = 0
+ return utfchar(now)
+ elseif now >= 0xD800 and now <= 0xDBFF then
+ more = now
+ return "" -- else the c's end up in the stream
+ else
+ return utfchar(now)
+ end
+end
+
+local p_utf32_to_utf8_be = C(1) * C(1) * C(1) * C(1) /function(a,b,c,d)
+ return utfchar(256*256*256*byte(a) + 256*256*byte(b) + 256*byte(c) + byte(d))
+end
+
+local p_utf32_to_utf8_le = C(1) * C(1) * C(1) * C(1) /function(a,b,c,d)
+ return utfchar(256*256*256*byte(d) + 256*256*byte(c) + 256*byte(b) + byte(a))
+end
+
+p_utf16_to_utf8_be = P(true) / function() more = 0 end * utf_16_be_getbom * Cs(p_utf16_to_utf8_be^0)
+p_utf16_to_utf8_le = P(true) / function() more = 0 end * utf_16_le_getbom * Cs(p_utf16_to_utf8_le^0)
+p_utf32_to_utf8_be = P(true) / function() more = 0 end * utf_32_be_getbom * Cs(p_utf32_to_utf8_be^0)
+p_utf32_to_utf8_le = P(true) / function() more = 0 end * utf_32_le_getbom * Cs(p_utf32_to_utf8_le^0)
+
+patterns.utf16_to_utf8_be = p_utf16_to_utf8_be
+patterns.utf16_to_utf8_le = p_utf16_to_utf8_le
+patterns.utf32_to_utf8_be = p_utf32_to_utf8_be
+patterns.utf32_to_utf8_le = p_utf32_to_utf8_le
+
+local utf16_to_utf8_be = function(s)
+ if s and s ~= "" then
+ return lpegmatch(p_utf16_to_utf8_be,s)
+ else
+ return s
+ end
+end
+
+local utf16_to_utf8_be_t = function(t)
+ if not t then
+ return nil
+ elseif type(t) == "string" then
+ t = lpegmatch(utf_16_be_linesplitter,t)
+ end
+ for i=1,#t do
+ local s = t[i]
+ if s ~= "" then
+ t[i] = lpegmatch(p_utf16_to_utf8_be,s)
+ end
+ end
+ return t
+end
+
+local utf16_to_utf8_le = function(s)
+ if s and s ~= "" then
+ return lpegmatch(p_utf16_to_utf8_le,s)
+ else
+ return s
+ end
+end
+
+local utf16_to_utf8_le_t = function(t)
+ if not t then
+ return nil
+ elseif type(t) == "string" then
+ t = lpegmatch(utf_16_le_linesplitter,t)
+ end
+ for i=1,#t do
+ local s = t[i]
+ if s ~= "" then
+ t[i] = lpegmatch(p_utf16_to_utf8_le,s)
+ end
+ end
+ return t
+end
+
+local utf32_to_utf8_be = function(s)
+ if s and s ~= "" then
+ return lpegmatch(p_utf32_to_utf8_be,s)
+ else
+ return s
+ end
+end
+
+local utf32_to_utf8_be_t = function(t)
+ if not t then
+ return nil
+ elseif type(t) == "string" then
+ t = lpegmatch(utf_32_be_linesplitter,t)
+ end
+ for i=1,#t do
+ local s = t[i]
+ if s ~= "" then
+ t[i] = lpegmatch(p_utf32_to_utf8_be,s)
+ end
+ end
+ return t
+end
+
+local utf32_to_utf8_le = function(s)
+ if s and s ~= "" then
+ return lpegmatch(p_utf32_to_utf8_le,s)
+ else
+ return s
+ end
+end
+
+local utf32_to_utf8_le_t = function(t)
+ if not t then
+ return nil
+ elseif type(t) == "string" then
+ t = lpegmatch(utf_32_le_linesplitter,t)
+ end
+ for i=1,#t do
+ local s = t[i]
+ if s ~= "" then
+ t[i] = lpegmatch(p_utf32_to_utf8_le,s)
+ end
+ end
+ return t
+end
+
+utf.utf16_to_utf8_le_t = utf16_to_utf8_le_t
+utf.utf16_to_utf8_be_t = utf16_to_utf8_be_t
+utf.utf32_to_utf8_le_t = utf32_to_utf8_le_t
+utf.utf32_to_utf8_be_t = utf32_to_utf8_be_t
+
+utf.utf16_to_utf8_le = utf16_to_utf8_le
+utf.utf16_to_utf8_be = utf16_to_utf8_be
+utf.utf32_to_utf8_le = utf32_to_utf8_le
+utf.utf32_to_utf8_be = utf32_to_utf8_be
+
+function utf.utf8_to_utf8_t(t)
+ return type(t) == "string" and lpegmatch(utflinesplitter,t) or t
+end
+
+function utf.utf16_to_utf8_t(t,endian)
+ return endian and utf16_to_utf8_be_t(t) or utf16_to_utf8_le_t(t) or t
+end
+
+function utf.utf32_to_utf8_t(t,endian)
+ return endian and utf32_to_utf8_be_t(t) or utf32_to_utf8_le_t(t) or t
+end
+
+do
+
+ local function little(b)
+ if b < 0x10000 then
+ return char(b%256,(b>>8))
+ else
+ b = b - 0x10000
+ local b1 = (b>>10) + 0xD800
+ local b2 = b%1024 + 0xDC00
+ return char(b1%256,(b1>>8),b2%256,(b2>>8))
+ end
+ end
+
+ local function big(b)
+ if b < 0x10000 then
+ return char((b>>8),b%256)
+ else
+ b = b - 0x10000
+ local b1 = (b>>10) + 0xD800
+ local b2 = b%1024 + 0xDC00
+ return char((b1>>8),b1%256,(b2>>8),b2%256)
+ end
+ end
+
+ local l_remap = Cs((p_utf8byte/little+P(1)/"")^0)
+ local b_remap = Cs((p_utf8byte/big +P(1)/"")^0)
+
+ local function utf8_to_utf16_be(str,nobom)
+ if nobom then
+ return lpegmatch(b_remap,str)
+ else
+ return char(254,255) .. lpegmatch(b_remap,str)
+ end
+ end
+
+ local function utf8_to_utf16_le(str,nobom)
+ if nobom then
+ return lpegmatch(l_remap,str)
+ else
+ return char(255,254) .. lpegmatch(l_remap,str)
+ end
+ end
+
+ utf.utf8_to_utf16_be = utf8_to_utf16_be
+ utf.utf8_to_utf16_le = utf8_to_utf16_le
+
+ function utf.utf8_to_utf16(str,littleendian,nobom)
+ if littleendian then
+ return utf8_to_utf16_le(str,nobom)
+ else
+ return utf8_to_utf16_be(str,nobom)
+ end
+ end
+
+end
+
+local pattern = Cs (
+ (p_utf8byte / function(unicode ) return format( "0x%04X", unicode) end) *
+ (p_utf8byte * Carg(1) / function(unicode,separator) return format("%s0x%04X",separator,unicode) end)^0
+)
+
+function utf.tocodes(str,separator)
+ return lpegmatch(pattern,str,1,separator or " ")
+end
+
+function utf.ustring(s)
+ return format("U+%05X",type(s) == "number" and s or utfbyte(s))
+end
+
+function utf.xstring(s)
+ return format("0x%05X",type(s) == "number" and s or utfbyte(s))
+end
+
+function utf.toeight(str)
+ if not str or str == "" then
+ return nil
+ end
+ local utftype = lpegmatch(p_utfstricttype,str)
+ if utftype == "utf-8" then
+ return sub(str,4) -- remove the bom
+ elseif utftype == "utf-16-be" then
+ return utf16_to_utf8_be(str) -- bom gets removed
+ elseif utftype == "utf-16-le" then
+ return utf16_to_utf8_le(str) -- bom gets removed
+ else
+ return str
+ end
+end
+
+do
+
+ local p_nany = p_utf8character / ""
+ local cache = { }
+
+ function utf.count(str,what)
+ if type(what) == "string" then
+ local p = cache[what]
+ if not p then
+ p = Cs((P(what)/" " + p_nany)^0)
+ cache[p] = p
+ end
+ return #lpegmatch(p,str)
+ else -- 4 times slower but still faster than / function
+ return #lpegmatch(Cs((P(what)/" " + p_nany)^0),str)
+ end
+ end
+
+end
+
+utf.values = string.utfvalues
+
+function utf.chrlen(u) -- u is number
+ return
+ (u < 0x80 and 1) or
+ (u < 0xE0 and 2) or
+ (u < 0xF0 and 3) or
+ (u < 0xF8 and 4) or
+ (u < 0xFC and 5) or
+ (u < 0xFE and 6) or 0
+end
+
+-- hashing saves a little but not that much in practice
+--
+-- local utf32 = table.setmetatableindex(function(t,k) local v = toutf32(k) t[k] = v return v end)
+
+do
+
+ local extract = bit32.extract
+ local char = string.char
+
+ function utf.toutf32string(n)
+ if n <= 0xFF then
+ return
+ char(n) ..
+ "\000\000\000"
+ elseif n <= 0xFFFF then
+ return
+ char(extract(n, 0,8)) ..
+ char(extract(n, 8,8)) ..
+ "\000\000"
+ elseif n <= 0xFFFFFF then
+ return
+ char(extract(n, 0,8)) ..
+ char(extract(n, 8,8)) ..
+ char(extract(n,16,8)) ..
+ "\000"
+ else
+ return
+ char(extract(n, 0,8)) ..
+ char(extract(n, 8,8)) ..
+ char(extract(n,16,8)) ..
+ char(extract(n,24,8))
+ end
+ end
+
+end
+
+-- goodie:
+
+function string.utfpadd(s,n)
+ if n and n ~= 0 then
+ local l = utflength(s)
+ if n > 0 then
+ local d = n - l
+ if d > 0 then
+ return rep(c or " ",d) .. s
+ end
+ else
+ local d = - n - l
+ if d > 0 then
+ return s .. rep(c or " ",d)
+ end
+ end
+ end
+ return s
+end
+
+-- goodies
+
+do
+
+ lpeg.UP = P
+
+ function lpeg.US(str)
+ local p = P(false)
+ for uc in utfcharacters(str) do
+ p = p + P(uc)
+ end
+ return p
+ end
+
+ local range = p_utf8byte * p_utf8byte + Cc(false) -- utf8byte is already a capture
+
+ function lpeg.UR(str,more)
+ local first, last
+ if type(str) == "number" then
+ first = str
+ last = more or first
+ else
+ first, last = lpegmatch(range,str)
+ if not last then
+ return P(str)
+ end
+ end
+ if first == last then
+ return P(str)
+ end
+ if not utfchar then
+ utfchar = utf.char -- maybe delayed
+ end
+ if utfchar and (last - first < 8) then -- a somewhat arbitrary criterium
+ local p = P(false)
+ for i=first,last do
+ p = p + P(utfchar(i))
+ end
+ return p -- nil when invalid range
+ else
+ local f = function(b)
+ return b >= first and b <= last
+ end
+ -- tricky, these nested captures
+ return p_utf8byte / f -- nil when invalid range
+ end
+ end
+
+ -- print(lpeg.match(lpeg.Cs((C(lpeg.UR("αω"))/{ ["χ"] = "OEPS" })^0),"αωχαω"))
+
+end
diff --git a/tex/context/base/mkxl/lang-ini.mkxl b/tex/context/base/mkxl/lang-ini.mkxl
index d99fa4f79..7e11bc783 100644
--- a/tex/context/base/mkxl/lang-ini.mkxl
+++ b/tex/context/base/mkxl/lang-ini.mkxl
@@ -445,16 +445,38 @@
\relax
\hccode"002D "002D
-\hccode"2010 "2010
-\hccode"2013 "2013
-\hccode"2014 "2014
+
+\permanent\protected\def\keephyphensequences
+ {\hccode"2010 \zerocount
+ \hccode"2013 \zerocount
+ \hccode"2014 \zerocount}
+
+\permanent\protected\def\collapsehyphensequences
+ {\hccode"2010 "2010\relax
+ \hccode"2013 "2013\relax
+ \hccode"2014 "2014\relax}
+
+\collapsehyphensequences
% maybe a (un)setter for handlers
\permanent\protected\def\dohyphens {\hyphenationmode\completehyphenationmodecode}
-%permanent\protected\def\nohyphens {\hyphenationmode\zerocount}
\permanent\protected\def\nohyphens {\hyphenationmode\partialhyphenationmodecode}
+% \permanent\protected\def\dohyphens
+% {\ifbitwiseand\hyphenationmode\collapsehyphenationmodecode
+% \hyphenationmode\completehyphenationmodecode
+% \else
+% \hyphenationmode\numexpr\completehyphenationmodecode-\collapsehyphenationmodecode\relax
+% \fi}
+
+% \permanent\protected\def\nohyphens
+% {\ifbitwiseand\hyphenationmode\collapsehyphenationmodecode
+% \hyphenationmode\partialhyphenationmodecode
+% \else
+% \hyphenationmode\numexpr\partialhyphenationmodecode-\collapsehyphenationmodecode\relax
+% \fi}
+
\permanent\protected\def\dohyphencollapsing{\hyphenationmode\bitwiseflip\hyphenationmode \collapsehyphenationmodecode}
\permanent\protected\def\nohyphencollapsing{\hyphenationmode\bitwiseflip\hyphenationmode-\collapsehyphenationmodecode}
diff --git a/tex/context/base/mkxl/lpdf-aux.lmt b/tex/context/base/mkxl/lpdf-aux.lmt
index 91636ad04..65bc2e6cc 100644
--- a/tex/context/base/mkxl/lpdf-aux.lmt
+++ b/tex/context/base/mkxl/lpdf-aux.lmt
@@ -23,7 +23,7 @@ local cache = table.setmetatableindex(function(t,k) -- can be made weak
v = format("%04x",v)
else
v = v - 0x10000
- v = format("%04x%04x",rshift(v,10)+0xD800,v%1024+0xDC00)
+ v = format("%04x%04x",rshift(v,10)+0xD800,v%1024+0xDC00) -- will become >> when we drop luajittex
end
t[k] = v
return v
diff --git a/tex/context/base/mkxl/lpdf-emb.lmt b/tex/context/base/mkxl/lpdf-emb.lmt
index 3a2b2a0aa..928aea7cf 100644
--- a/tex/context/base/mkxl/lpdf-emb.lmt
+++ b/tex/context/base/mkxl/lpdf-emb.lmt
@@ -38,8 +38,6 @@ local format = string.format
local concat, sortedhash, sort = table.concat, table.sortedhash, table.sort
local utfchar = utf.char
local random, round, max, abs, ceiling = math.random, math.round, math.max, math.abs, math.ceiling
-local extract, lshift, rshift, band, bor = bit32.extract, bit32.lshift, bit32.rshift, bit32.band, bit32.bor
-local idiv = number.idiv
local setmetatableindex = table.setmetatableindex
local pdfnull = lpdf.null
@@ -85,34 +83,42 @@ local getmapentry = fonts.mappings.getentry
local tocardinal1 = char
local function tocardinal2(n)
- return char(extract(n,8,8),extract(n,0,8))
+ -- return char(extract8(n,8),extract8(n,0))
+ return char((n>>8)&0xFF,(n>>0)&0xFF)
end
local function tocardinal3(n)
- return char(extract(n,16,8),extract(n,8,8),extract(n,0,8))
+ -- return char(extract8(n,16),extract8(n,8),extract8(n,0))
+ return char((n>>16)&0xFF,(n>>8)&0xFF,(n>>0)&0xFF)
end
local function tocardinal4(n)
- return char(extract(n,24,8),extract(n,16,8),extract(n,8,8),extract(n,0,8))
+ -- return char(extract8(n,24),extract8(n,16),extract8(n,8),extract8(n,0))
+ return char((n>>24)&0xFF,(n>>16)&0xFF,(n>>8)&0xFF,(n>>0)&0xFF)
end
local function tointeger2(n)
- return char(extract(n,8,8),extract(n,0,8))
+ -- return char(extract8(n,8),extract8(n,0))
+ return char((n>>8)&0xFF,(n>>0)&0xFF)
end
local function tointeger3(n)
- return char(extract(n,16,8),extract(n,8,8),extract(n,0,8))
+ -- return char(extract8(n,16),extract8(n,8),extract8(n,0))
+ return char((n>>16)&0xFF,(n>>8)&0xFF,(n>>0)&0xFF)
end
local function tointeger4(n)
- return char(extract(n,24,8),extract(n,16,8),extract(n,8,8),extract(n,0,8))
+ -- return char(extract8(n,24),extract8(n,16),extract8(n,8),extract8(n,0))
+ return char((n>>24)&0xFF,(n>>16)&0xFF,(n>>8)&0xFF,(n>>0)&0xFF)
end
local function tocardinal8(n)
- local l = idiv(n,0x100000000)
+ local l = n // 0x100000000
local r = n % 0x100000000
- return char(extract(l,24,8),extract(l,16,8),extract(l,8,8),extract(l,0,8),
- extract(r,24,8),extract(r,16,8),extract(r,8,8),extract(r,0,8))
+ -- return char(extract8(l,24) & 0xFF,extract8(l,16) & 0xFF,extract8(l,8) & 0xFF,extract8(l,0) & 0xFF,
+ -- extract8(r,24) & 0xFF,extract8(r,16) & 0xFF,extract8(r,8) & 0xFF,extract8(r,0) & 0xFF)
+ return char((l>>24)&0xFF,(l>>16)&0xFF,(l>>8)&0xFF,(l>>0)&0xFF,
+ (r>>24)&0xFF,(r>>16)&0xFF,(r>>8)&0xFF,(r>>0)&0xFF)
end
-- A couple of shared helpers.
@@ -269,16 +275,16 @@ end
tocidsetdictionary = function(indices,min,max)
if includecidset or forcecidset then
local b = { }
- local m = idiv(max+7,8)
+ local m = (max + 7) // 8
for i=0,max do
b[i] = 0
end
- b[0] = bor(b[0],lshift(1,7)) -- force notdef into the file
+ b[0] = b[0] | (1 << 7) -- force notdef into the file
for i=min,max do
if indices[i] then
- local bi = idiv(i,8)
+ local bi = i // 8
local ni = i % 8
- b[bi] = bor(b[bi],lshift(1,7-ni))
+ b[bi] = b[bi] | (1 << (7-ni))
end
end
b = char(unpack(b,0,#b))
@@ -473,12 +479,12 @@ do
local i = 1
local k = 0
while i <= count do
- i = lshift(i,1)
+ i = i << 1
k = k + 1
end
- local searchrange = lshift(i,3)
+ local searchrange = i << 3
local entryselector = k - 1
- local rangeshift = lshift(count,4) - lshift(i,3)
+ local rangeshift = (count << 4) - (i << 3)
local index = {
tocardinal4(0x00010000), -- tables.version
tocardinal2(count),
@@ -495,7 +501,7 @@ do
if data then
local csum = checksum(data)
local dlength = #data
- local length = idiv(dlength+3,4) * 4
+ local length = ((dlength + 3) // 4) * 4
local padding = length - dlength
nl = nl + 1 ; list[nl] = data
for i=1,padding do
@@ -905,21 +911,21 @@ do
todictinteger = function(n)
if not n then
- return char(band(139,0xFF))
+ return char(139 & 0xFF)
elseif n >= -107 and n <= 107 then
- return char(band(n + 139,0xFF))
+ return char((n + 139) & 0xFF)
elseif n >= 108 and n <= 1131 then
n = 0xF700 + n - 108
- return char(band(rshift(n,8),0xFF),band(n,0xFF))
+ return char((n >> 8) & 0xFF, n & 0xFF)
elseif n >= -1131 and n <= -108 then
n = 0xFB00 - n - 108
- return char(band(rshift(n,8),0xFF),band(n,0xFF))
+ return char((n >> 8) & 0xFF, n & 0xFF)
elseif n >= -32768 and n <= 32767 then
- -- return int2tag .. tointeger2(n)
- return char(28,extract(n,8,8),extract(n,0,8))
+ -- return char(28,extract8(n,8),extract8(n,0))
+ return char(28,(n>>8)&0xFF,(n>>0)&0xFF)
else
- -- return int4tag .. tointeger4(n)
- return char(29,extract(n,24,8),extract(n,16,8),extract(n,8,8),extract(n,0,8))
+ -- return char(29,extract8(n,24&0xFF,extract8(n,16),extract8(n,8),extract8(n,0))
+ return char(29,(n>>24)&0xFF,(n>>16)&0xFF,(n>>8)&0xFF,(n>>0)&0xFF)
end
end
@@ -933,11 +939,11 @@ do
-- elseif n >= -1131 and n <= 1131 then
-- return encoder[n]
-- elseif n >= -32768 and n <= 32767 then
- -- -- return int2tag .. tointeger2(n)
- -- return char(28,extract(n,8,8),extract(n,0,8))
+ -- -- return char(28,extract8(n,8),extract8(n,0))
+ -- return char(28,(n>>8)&0xFF,(n>>0)&0xFF)
-- else
- -- -- return int4tag .. tointeger4(n)
- -- return char(29,extract(n,24,8),extract(n,16,8),extract(n,8,8),extract(n,0,8))
+ -- -- return char(29,extract8(n,24),extract8(n,16),extract8(n,8),extract8(n,0))
+ -- return char(29,(n>>24)&0xFF,(n>>16)&0xFF,(n>>8)&0xFF,(n>>0)&0xFF)
-- end
-- end
diff --git a/tex/context/base/mkxl/lpdf-epa.lmt b/tex/context/base/mkxl/lpdf-epa.lmt
index b37e9c043..98f59e93e 100644
--- a/tex/context/base/mkxl/lpdf-epa.lmt
+++ b/tex/context/base/mkxl/lpdf-epa.lmt
@@ -17,7 +17,6 @@ local concat, merged = table.concat, table.merged
local abs = math.abs
local expandname = file.expandname
local allocate = utilities.storage.allocate
-local bor, band = bit32.bor, bit32.band
local isfile = lfs.isfile
local trace_links = false trackers.register("figures.links", function(v) trace_links = v end)
@@ -548,7 +547,7 @@ local annotationflags = lpdf.flags.annotations
local function copyF(v,lock) -- todo: bxor 24
if lock then
- v = bor(v or 0,annotationflags.ReadOnly + annotationflags.Locked + annotationflags.LockedContents)
+ v = (v or 0) | (annotationflags.ReadOnly + annotationflags.Locked + annotationflags.LockedContents)
end
if v then
return pdfcopyinteger(v)
@@ -715,7 +714,7 @@ local function flagstoset(flag,flags)
local t = { }
if flags then
for k, v in next, flags do
- if band(flag,v) ~= 0 then
+ if (flag & v) ~= 0 then
t[k] = true
end
end
diff --git a/tex/context/base/mkxl/lpdf-img.lmt b/tex/context/base/mkxl/lpdf-img.lmt
index 50034c360..e1b822210 100644
--- a/tex/context/base/mkxl/lpdf-img.lmt
+++ b/tex/context/base/mkxl/lpdf-img.lmt
@@ -11,19 +11,20 @@ if not modules then modules = { } end modules ['lpdf-img'] = {
-- At some point we can also use it for fonts. For small images performance is ok
-- with pure lua but for bigger images we can use some helpers. Normally in a
-- typesetting workflow non-interlaced images are used. One should convert
--- interlaced images to more efficient non-interlaced ones (ok, we can cache
--- them if needed).
+-- interlaced images to more efficient non-interlaced ones (ok, we can cache them if
+-- needed).
--
--- The \LUA\ code is slightly optimized so we could have done with less lines if
--- we wanted but best gain a little. The idea is that we collect striped (in stages)
--- so that we can play with substitutions.
+-- The \LUA\ code is slightly optimized so we could have done with less lines if we
+-- wanted but best gain a little. The idea is that we collect striped (in stages) so
+-- that we can play with substitutions. We keep this variant commented but not
+-- embedding it saves some 14K bytecode in the format.
local type = type
local concat, move = table.concat, table.move
local ceil, min = math.ceil, math.min
local char, byte, find, gmatch = string.char, string.byte, string.find, string.gmatch
-local idiv = number.idiv
-local band, rshift = bit32.band, bit32.rshift
+----- idiv = number.idiv
+----- band, rshift = bit32.band, bit32.rshift
local loaddata = io.loaddata
local setmetatableindex = table.setmetatableindex
@@ -58,8 +59,8 @@ end)
local createimage = images.create
-local zlibcompress = (xzip or zlib).compress
-local zlibdecompress = (xzip or zlib).decompress
+local zlibcompress = xzip.compress
+local zlibdecompress = xzip.decompress
local trace = false
@@ -250,10 +251,10 @@ do
end
elseif filter == 3 then
for j=n+1,n+bpp do
- t[j] = (t[j] + idiv(t[j-len],2)) % 256
+ t[j] = (t[j] + (t[j-len] // 2)) % 256
end
for j=n+bpp+1,n+m do
- t[j] = (t[j] + idiv(t[j-bpp] + t[j-len],2)) % 256
+ t[j] = (t[j] + (t[j-bpp] + t[j-len]) // 2) % 256
end
elseif filter == 4 then
for j=n+1,n+bpp do
@@ -282,95 +283,95 @@ do
return t
end
- local filtermask_l = function (content,xsize,ysize,colordepth,colorspace,hasfilter)
- local mask = { }
- local bytes = colordepth == 16 and 2 or 1
- local bpp = colorspace == "DeviceRGB" and 3 or 1
- local length = #content
- local size = ysize * xsize * ((bpp+1)*bytes + (hasfilter and 1 or 0))
- local n = 1
- local l = 1
- if bytes == 2 then
- if bpp == 1 then
- for i=1,ysize do
- if hasfilter then
- content[n] = "" ; n = n + 1
- end
- for j=1,xsize do
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- end
- end
- elseif bpp == 3 then
- for i=1,ysize do
- if hasfilter then
- content[n] = "" ; n = n + 1
- end
- for j=1,xsize do
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- end
- end
- else
- return "", ""
- end
- else
- if bpp == 1 then
- for i=1,ysize do
- if hasfilter then
- content[n] = "" ; n = n + 1
- end
- for j=1,xsize do
- content[n] = chars[content[n]] ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- end
- end
- elseif bpp == 3 then
- for i=1,ysize do
- if hasfilter then
- content[n] = "" ; n = n + 1
- end
- for j=1,xsize do
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- end
- end
- else
- return "", ""
- end
- end
- return concat(content), concat(mask)
- end
-
- local decodemask_l = function(content,xsize,ysize,colordepth,colorspace)
- local bytes = colordepth == 16 and 2 or 1
- local bpp = colorspace == "DeviceRGB" and 3 or 1
- local slice = bytes*(bpp+1)
- local length = #content
- local size = ysize * xsize * ((bpp+1)*bytes + 1) -- assume filter
- content = openstring(content)
- content = readbytetable(content,length)
- setmetatableindex(content,zero)
- applyfilter(content,xsize,ysize,slice)
- content, mask = filtermask(content,xsize,ysize,colordepth,colorspace,true)
- return content, mask
- end
+ -- local filtermask_l = function (content,xsize,ysize,colordepth,colorspace,hasfilter)
+ -- local mask = { }
+ -- local bytes = colordepth == 16 and 2 or 1
+ -- local bpp = colorspace == "DeviceRGB" and 3 or 1
+ -- local length = #content
+ -- local size = ysize * xsize * ((bpp+1)*bytes + (hasfilter and 1 or 0))
+ -- local n = 1
+ -- local l = 1
+ -- if bytes == 2 then
+ -- if bpp == 1 then
+ -- for i=1,ysize do
+ -- if hasfilter then
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- for j=1,xsize do
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- end
+ -- elseif bpp == 3 then
+ -- for i=1,ysize do
+ -- if hasfilter then
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- for j=1,xsize do
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- end
+ -- else
+ -- return "", ""
+ -- end
+ -- else
+ -- if bpp == 1 then
+ -- for i=1,ysize do
+ -- if hasfilter then
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- for j=1,xsize do
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- end
+ -- elseif bpp == 3 then
+ -- for i=1,ysize do
+ -- if hasfilter then
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- for j=1,xsize do
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- end
+ -- else
+ -- return "", ""
+ -- end
+ -- end
+ -- return concat(content), concat(mask)
+ -- end
+
+ -- local decodemask_l = function(content,xsize,ysize,colordepth,colorspace)
+ -- local bytes = colordepth == 16 and 2 or 1
+ -- local bpp = colorspace == "DeviceRGB" and 3 or 1
+ -- local slice = bytes*(bpp+1)
+ -- local length = #content
+ -- local size = ysize * xsize * ((bpp+1)*bytes + 1) -- assume filter
+ -- content = openstring(content)
+ -- content = readbytetable(content,length)
+ -- setmetatableindex(content,zero)
+ -- applyfilter(content,xsize,ysize,slice)
+ -- content, mask = filtermask(content,xsize,ysize,colordepth,colorspace,true)
+ -- return content, mask
+ -- end
local filtermask_c = function(content,xsize,ysize,colordepth,colorspace)
local bytes = colordepth == 16 and 2 or 1
@@ -388,12 +389,12 @@ do
return pngsplitmask(content,xsize,ysize,bpp,bytes,mask,filter)
end
- local function decodestrip_l(s,nx,ny,slice)
- local input = readbytetable(s,ny*(nx*slice+1))
- setmetatableindex(input,zero)
- applyfilter(input,nx,ny,slice)
- return input, true
- end
+ -- local function decodestrip_l(s,nx,ny,slice)
+ -- local input = readbytetable(s,ny*(nx*slice+1))
+ -- setmetatableindex(input,zero)
+ -- applyfilter(input,nx,ny,slice)
+ -- return input, true
+ -- end
local function decodestrip_c(s,nx,ny,slice)
local input = readstring(s,ny*(nx*slice+1))
@@ -409,204 +410,204 @@ do
local xblock = { 8, 4, 4, 2, 2, 1, 1 }
local yblock = { 8, 8, 4, 4, 2, 2, 1 }
- local function transpose_l(xsize,ysize,slice,pass,input,output,filter)
- local xstart = xstart[pass]
- local xstep = xstep[pass]
- local ystart = ystart[pass]
- local ystep = ystep[pass]
- local nx = idiv(xsize + xstep - xstart - 1,xstep)
- local ny = idiv(ysize + ystep - ystart - 1,ystep)
- local offset = filter and 1 or 0
- local xstep = xstep * slice
- local xstart = xstart * slice
- local xsize = xsize * slice
- local target = ystart * xsize + xstart + 1
- local ystep = ystep * xsize
- local start = 1
- local plus = nx * xstep
- local step = plus - xstep
- if not output then
- output = newoutput(xsize*(parts or slice)*ysize)
- end
- if slice == 1 then
- for j=0,ny-1 do
- start = start + offset
- local target = target + j * ystep
- for target=target,target+step,xstep do
- output[target] = input[start]
- start = start + slice
- end
- end
- elseif slice == 2 then
- for j=0,ny-1 do
- start = start + offset
- local target = target + j * ystep
- for target=target,target+step,xstep do
- output[target] = input[start]
- output[target+1] = input[start+1]
- start = start + slice
- end
- end
- elseif slice == 3 then
- for j=0,ny-1 do
- start = start + offset
- local target = target + j * ystep
- for target=target,target+step,xstep do
- output[target] = input[start]
- output[target+1] = input[start+1]
- output[target+2] = input[start+2]
- start = start + slice
- end
- end
- elseif slice == 4 then
- for j=0,ny-1 do
- start = start + offset
- local target = target + j * ystep
- for target=target,target+step,xstep do
- output[target] = input[start]
- output[target+1] = input[start+1]
- output[target+2] = input[start+2]
- output[target+3] = input[start+3]
- start = start + slice
- end
- end
- else
- local delta = slice - 1
- for j=0,ny-1 do
- start = start + offset
- local target = target + j * ystep
- for target=target,target+step,xstep do
- move(input,start,start+delta,target,output)
- start = start + slice
- end
- end
- end
- return output;
- end
+ -- local function transpose_l(xsize,ysize,slice,pass,input,output,filter)
+ -- local xstart = xstart[pass]
+ -- local xstep = xstep[pass]
+ -- local ystart = ystart[pass]
+ -- local ystep = ystep[pass]
+ -- local nx = idiv(xsize + xstep - xstart - 1,xstep)
+ -- local ny = idiv(ysize + ystep - ystart - 1,ystep)
+ -- local offset = filter and 1 or 0
+ -- local xstep = xstep * slice
+ -- local xstart = xstart * slice
+ -- local xsize = xsize * slice
+ -- local target = ystart * xsize + xstart + 1
+ -- local ystep = ystep * xsize
+ -- local start = 1
+ -- local plus = nx * xstep
+ -- local step = plus - xstep
+ -- if not output then
+ -- output = newoutput(xsize*(parts or slice)*ysize)
+ -- end
+ -- if slice == 1 then
+ -- for j=0,ny-1 do
+ -- start = start + offset
+ -- local target = target + j * ystep
+ -- for target=target,target+step,xstep do
+ -- output[target] = input[start]
+ -- start = start + slice
+ -- end
+ -- end
+ -- elseif slice == 2 then
+ -- for j=0,ny-1 do
+ -- start = start + offset
+ -- local target = target + j * ystep
+ -- for target=target,target+step,xstep do
+ -- output[target] = input[start]
+ -- output[target+1] = input[start+1]
+ -- start = start + slice
+ -- end
+ -- end
+ -- elseif slice == 3 then
+ -- for j=0,ny-1 do
+ -- start = start + offset
+ -- local target = target + j * ystep
+ -- for target=target,target+step,xstep do
+ -- output[target] = input[start]
+ -- output[target+1] = input[start+1]
+ -- output[target+2] = input[start+2]
+ -- start = start + slice
+ -- end
+ -- end
+ -- elseif slice == 4 then
+ -- for j=0,ny-1 do
+ -- start = start + offset
+ -- local target = target + j * ystep
+ -- for target=target,target+step,xstep do
+ -- output[target] = input[start]
+ -- output[target+1] = input[start+1]
+ -- output[target+2] = input[start+2]
+ -- output[target+3] = input[start+3]
+ -- start = start + slice
+ -- end
+ -- end
+ -- else
+ -- local delta = slice - 1
+ -- for j=0,ny-1 do
+ -- start = start + offset
+ -- local target = target + j * ystep
+ -- for target=target,target+step,xstep do
+ -- move(input,start,start+delta,target,output)
+ -- start = start + slice
+ -- end
+ -- end
+ -- end
+ -- return output;
+ -- end
local transpose_c = pnginterlace
-- print(band(rshift(v,4),0x03),extract(v,4,2))
-- print(band(rshift(v,6),0x03),extract(v,6,2))
- local function expand_l(t,xsize,ysize,parts,run,factor,filter)
- local size = ysize * xsize + 1 -- a bit of overshoot, needs testing, probably a few bytes us ok
- local xline = filter and (run+1) or run
- local f = filter and 1 or 0
- local l = xline - 1
- local n = 1
- local o = newoutput(size)
- local k = 0
- if factor then
- if parts == 4 then
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 2
- else
- k = k + 1 ; o[k] = extract4(v,4) * 0x11
- k = k + 1 ; o[k] = extract4(v,0) * 0x11
- end
- end
- k = i * xsize
- n = n + xline
- end
- elseif parts == 2 then
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 4
- else
- k = k + 1 ; o[k] = extract2(v,6) * 0x55
- k = k + 1 ; o[k] = extract2(v,4) * 0x55
- k = k + 1 ; o[k] = extract2(v,2) * 0x55
- k = k + 1 ; o[k] = extract2(v,0) * 0x55
- end
- end
- k = i * xsize
- n = n + xline
- end
- else
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 8
- else
- k = k + 1 ; if band(v,0x80) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,7) * 0xFF
- k = k + 1 ; if band(v,0x40) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,6) * 0xFF
- k = k + 1 ; if band(v,0x20) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,5) * 0xFF
- k = k + 1 ; if band(v,0x10) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,4) * 0xFF
- k = k + 1 ; if band(v,0x08) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,3) * 0xFF
- k = k + 1 ; if band(v,0x04) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,2) * 0xFF
- k = k + 1 ; if band(v,0x02) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,1) * 0xFF
- k = k + 1 ; if band(v,0x01) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,0) * 0xFF
- end
- end
- k = i * xsize
- n = n + xline
- end
- end
- else
- if parts == 4 then
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 2
- else
- k = k + 1 ; o[k] = extract4(v,4)
- k = k + 1 ; o[k] = extract4(v,0)
- end
- end
- k = i * xsize
- n = n + xline
- end
- elseif parts == 2 then
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 4
- else
- k = k + 1 ; o[k] = extract2(v,6)
- k = k + 1 ; o[k] = extract2(v,4)
- k = k + 1 ; o[k] = extract2(v,2)
- k = k + 1 ; o[k] = extract2(v,0)
- end
- end
- k = i * xsize
- n = n + xline
- end
- else
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 8
- else
- k = k + 1 ; if band(v,0x80) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,7)
- k = k + 1 ; if band(v,0x40) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,6)
- k = k + 1 ; if band(v,0x20) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,5)
- k = k + 1 ; if band(v,0x10) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,4)
- k = k + 1 ; if band(v,0x08) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,3)
- k = k + 1 ; if band(v,0x04) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,2)
- k = k + 1 ; if band(v,0x02) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,1)
- k = k + 1 ; if band(v,0x01) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,0)
- end
- end
- k = i * xsize
- n = n + xline
- end
- end
- end
- for i=size,xsize * ysize +1,-1 do
- o[i] = nil
- end
- return o, false
- end
+ -- local function expand_l(t,xsize,ysize,parts,run,factor,filter)
+ -- local size = ysize * xsize + 1 -- a bit of overshoot, needs testing, probably a few bytes us ok
+ -- local xline = filter and (run+1) or run
+ -- local f = filter and 1 or 0
+ -- local l = xline - 1
+ -- local n = 1
+ -- local o = newoutput(size)
+ -- local k = 0
+ -- if factor then
+ -- if parts == 4 then
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 2
+ -- else
+ -- k = k + 1 ; o[k] = extract4(v,4) * 0x11
+ -- k = k + 1 ; o[k] = extract4(v,0) * 0x11
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- elseif parts == 2 then
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 4
+ -- else
+ -- k = k + 1 ; o[k] = extract2(v,6) * 0x55
+ -- k = k + 1 ; o[k] = extract2(v,4) * 0x55
+ -- k = k + 1 ; o[k] = extract2(v,2) * 0x55
+ -- k = k + 1 ; o[k] = extract2(v,0) * 0x55
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- else
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 8
+ -- else
+ -- k = k + 1 ; if band(v,0x80) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,7) * 0xFF
+ -- k = k + 1 ; if band(v,0x40) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,6) * 0xFF
+ -- k = k + 1 ; if band(v,0x20) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,5) * 0xFF
+ -- k = k + 1 ; if band(v,0x10) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,4) * 0xFF
+ -- k = k + 1 ; if band(v,0x08) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,3) * 0xFF
+ -- k = k + 1 ; if band(v,0x04) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,2) * 0xFF
+ -- k = k + 1 ; if band(v,0x02) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,1) * 0xFF
+ -- k = k + 1 ; if band(v,0x01) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,0) * 0xFF
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- end
+ -- else
+ -- if parts == 4 then
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 2
+ -- else
+ -- k = k + 1 ; o[k] = extract4(v,4)
+ -- k = k + 1 ; o[k] = extract4(v,0)
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- elseif parts == 2 then
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 4
+ -- else
+ -- k = k + 1 ; o[k] = extract2(v,6)
+ -- k = k + 1 ; o[k] = extract2(v,4)
+ -- k = k + 1 ; o[k] = extract2(v,2)
+ -- k = k + 1 ; o[k] = extract2(v,0)
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- else
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 8
+ -- else
+ -- k = k + 1 ; if band(v,0x80) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,7)
+ -- k = k + 1 ; if band(v,0x40) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,6)
+ -- k = k + 1 ; if band(v,0x20) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,5)
+ -- k = k + 1 ; if band(v,0x10) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,4)
+ -- k = k + 1 ; if band(v,0x08) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,3)
+ -- k = k + 1 ; if band(v,0x04) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,2)
+ -- k = k + 1 ; if band(v,0x02) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,1)
+ -- k = k + 1 ; if band(v,0x01) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,0)
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- end
+ -- end
+ -- for i=size,xsize * ysize +1,-1 do
+ -- o[i] = nil
+ -- end
+ -- return o, false
+ -- end
local expand_c = pngexpand
@@ -672,8 +673,8 @@ do
local xstep = xstep[pass]
local ystart = ystart[pass]
local ystep = ystep[pass]
- local nx = idiv(xsize + xstep - xstart - 1,xstep)
- local ny = idiv(ysize + ystep - ystart - 1,ystep)
+ local nx = (xsize + xstep - xstart - 1) // xstep
+ local ny = (ysize + ystep - ystart - 1) // ystep
if nx > 0 and ny > 0 then
local input, filter
if parts then
@@ -715,95 +716,95 @@ do
return r
end
- local function createmask_l(content,palette,transparent,xsize,ysize,colordepth,colorspace)
- if palette then
- local r = expandvector(transparent)
- local size = xsize*ysize
- local len = ceil(xsize*colordepth/8) + 1
- local o = newoutput(xsize*ysize)
- local u = setmetatableindex(zero)
- content = zlibdecompress(content)
- content = openstring(content)
- for i=0,ysize-1 do
- local t = readbytetable(content,len)
- local k = i * xsize
- local filter = t[1]
- if filter == 0 then
- elseif filter == 1 then
- for j=3,len do
- t[j] = (t[j] + t[j-1]) % 256
- end
- elseif filter == 2 then
- for j=2,len do
- t[j] = (t[j] + u[j]) % 256
- end
- elseif filter == 3 then
- local j = 2
- t[j] = (t[j] + idiv(u[j],2)) % 256
- for j=3,len do
- t[j] = (t[j] + idiv(t[j-1] + u[j],2)) % 256
- end
- elseif filter == 4 then
- local j = 2
- local p = j - len
- local b = t[p]
- if b < 0 then
- b = - b
- end
- if b > 0 then
- t[j] = (t[j] + b) % 256
- end
- for j=3,len do
- local p = j - len
- local a = t[j-1]
- local b = t[p]
- local c = t[p-1]
- local pa = b - c
- local pb = a - c
- local pc = pa + pb
- if pa < 0 then pa = - pa end
- if pb < 0 then pb = - pb end
- if pc < 0 then pc = - pc end
- t[j] = (t[j] + ((pa <= pb and pa <= pc and a) or (pb <= pc and b) or c)) % 256
- end
- end
- if colordepth == 8 then
- for j=2,len do
- local v = t[j]
- k = k + 1 ; o[k] = r[v]
- end
- elseif colordepth == 4 then
- for j=2,len do
- local v = t[j]
- k = k + 1 ; o[k] = r[extract4(v,4)]
- k = k + 1 ; o[k] = r[extract4(v,0)]
- end
- elseif colordepth == 2 then
- for j=2,len do
- local v = t[j]
- k = k + 1 ; o[k] = r[extract2(v,6)]
- k = k + 1 ; o[k] = r[extract2(v,4)]
- k = k + 1 ; o[k] = r[extract2(v,2)]
- k = k + 1 ; o[k] = r[extract2(v,0)]
- end
- else
- for j=2,len do
- local v = t[j]
- k = k + 1 ; o[k] = r[extract1(v,7)]
- k = k + 1 ; o[k] = r[extract1(v,6)]
- k = k + 1 ; o[k] = r[extract1(v,5)]
- k = k + 1 ; o[k] = r[extract1(v,4)]
- k = k + 1 ; o[k] = r[extract1(v,3)]
- k = k + 1 ; o[k] = r[extract1(v,2)]
- k = k + 1 ; o[k] = r[extract1(v,1)]
- k = k + 1 ; o[k] = r[extract1(v,0)]
- end
- end
- u = t
- end
- return concat(o,"",1,size)
- end
- end
+ -- local function createmask_l(content,palette,transparent,xsize,ysize,colordepth,colorspace)
+ -- if palette then
+ -- local r = expandvector(transparent)
+ -- local size = xsize*ysize
+ -- local len = ceil(xsize*colordepth/8) + 1
+ -- local o = newoutput(xsize*ysize)
+ -- local u = setmetatableindex(zero)
+ -- content = zlibdecompress(content)
+ -- content = openstring(content)
+ -- for i=0,ysize-1 do
+ -- local t = readbytetable(content,len)
+ -- local k = i * xsize
+ -- local filter = t[1]
+ -- if filter == 0 then
+ -- elseif filter == 1 then
+ -- for j=3,len do
+ -- t[j] = (t[j] + t[j-1]) % 256
+ -- end
+ -- elseif filter == 2 then
+ -- for j=2,len do
+ -- t[j] = (t[j] + u[j]) % 256
+ -- end
+ -- elseif filter == 3 then
+ -- local j = 2
+ -- t[j] = (t[j] + idiv(u[j],2)) % 256
+ -- for j=3,len do
+ -- t[j] = (t[j] + idiv(t[j-1] + u[j],2)) % 256
+ -- end
+ -- elseif filter == 4 then
+ -- local j = 2
+ -- local p = j - len
+ -- local b = t[p]
+ -- if b < 0 then
+ -- b = - b
+ -- end
+ -- if b > 0 then
+ -- t[j] = (t[j] + b) % 256
+ -- end
+ -- for j=3,len do
+ -- local p = j - len
+ -- local a = t[j-1]
+ -- local b = t[p]
+ -- local c = t[p-1]
+ -- local pa = b - c
+ -- local pb = a - c
+ -- local pc = pa + pb
+ -- if pa < 0 then pa = - pa end
+ -- if pb < 0 then pb = - pb end
+ -- if pc < 0 then pc = - pc end
+ -- t[j] = (t[j] + ((pa <= pb and pa <= pc and a) or (pb <= pc and b) or c)) % 256
+ -- end
+ -- end
+ -- if colordepth == 8 then
+ -- for j=2,len do
+ -- local v = t[j]
+ -- k = k + 1 ; o[k] = r[v]
+ -- end
+ -- elseif colordepth == 4 then
+ -- for j=2,len do
+ -- local v = t[j]
+ -- k = k + 1 ; o[k] = r[extract4(v,4)]
+ -- k = k + 1 ; o[k] = r[extract4(v,0)]
+ -- end
+ -- elseif colordepth == 2 then
+ -- for j=2,len do
+ -- local v = t[j]
+ -- k = k + 1 ; o[k] = r[extract2(v,6)]
+ -- k = k + 1 ; o[k] = r[extract2(v,4)]
+ -- k = k + 1 ; o[k] = r[extract2(v,2)]
+ -- k = k + 1 ; o[k] = r[extract2(v,0)]
+ -- end
+ -- else
+ -- for j=2,len do
+ -- local v = t[j]
+ -- k = k + 1 ; o[k] = r[extract1(v,7)]
+ -- k = k + 1 ; o[k] = r[extract1(v,6)]
+ -- k = k + 1 ; o[k] = r[extract1(v,5)]
+ -- k = k + 1 ; o[k] = r[extract1(v,4)]
+ -- k = k + 1 ; o[k] = r[extract1(v,3)]
+ -- k = k + 1 ; o[k] = r[extract1(v,2)]
+ -- k = k + 1 ; o[k] = r[extract1(v,1)]
+ -- k = k + 1 ; o[k] = r[extract1(v,0)]
+ -- end
+ -- end
+ -- u = t
+ -- end
+ -- return concat(o,"",1,size)
+ -- end
+ -- end
local function createmask_c(content,palette,transparent,xsize,ysize,colordepth,colorspace)
if palette then
@@ -825,28 +826,28 @@ do
elseif colordepth == 4 then
for j=1,len do
local v = t[j]
- k = k + 1 ; o[k] = r[extract4(v,4)]
- k = k + 1 ; o[k] = r[extract4(v,0)]
+ k = k + 1 ; o[k] = r[(v >> 4) & 0x0F] -- r[extract4(v,4)]
+ k = k + 1 ; o[k] = r[(v >> 0) & 0x0F] -- r[extract4(v,0)]
end
elseif colordepth == 2 then
for j=1,len do
local v = t[j]
- k = k + 1 ; o[k] = r[extract2(v,6)]
- k = k + 1 ; o[k] = r[extract2(v,4)]
- k = k + 1 ; o[k] = r[extract2(v,2)]
- k = k + 1 ; o[k] = r[extract2(v,0)]
+ k = k + 1 ; o[k] = r[(v >> 6) & 0x03] -- r[extract2(v,6)]
+ k = k + 1 ; o[k] = r[(v >> 4) & 0x03] -- r[extract2(v,4)]
+ k = k + 1 ; o[k] = r[(v >> 2) & 0x03] -- r[extract2(v,2)]
+ k = k + 1 ; o[k] = r[(v >> 0) & 0x03] -- r[extract2(v,0)]
end
else
for j=1,len do
local v = t[j]
- k = k + 1 ; o[k] = r[extract1(v,7)]
- k = k + 1 ; o[k] = r[extract1(v,6)]
- k = k + 1 ; o[k] = r[extract1(v,5)]
- k = k + 1 ; o[k] = r[extract1(v,4)]
- k = k + 1 ; o[k] = r[extract1(v,3)]
- k = k + 1 ; o[k] = r[extract1(v,2)]
- k = k + 1 ; o[k] = r[extract1(v,1)]
- k = k + 1 ; o[k] = r[extract1(v,0)]
+ k = k + 1 ; o[k] = r[(v >> 7) & 0x01] -- r[extract1(v,7)]
+ k = k + 1 ; o[k] = r[(v >> 6) & 0x01] -- r[extract1(v,6)]
+ k = k + 1 ; o[k] = r[(v >> 5) & 0x01] -- r[extract1(v,5)]
+ k = k + 1 ; o[k] = r[(v >> 4) & 0x01] -- r[extract1(v,4)]
+ k = k + 1 ; o[k] = r[(v >> 3) & 0x01] -- r[extract1(v,3)]
+ k = k + 1 ; o[k] = r[(v >> 2) & 0x01] -- r[extract1(v,2)]
+ k = k + 1 ; o[k] = r[(v >> 1) & 0x01] -- r[extract1(v,1)]
+ k = k + 1 ; o[k] = r[(v >> 0) & 0x01] -- r[extract1(v,0)]
end
end
end
@@ -854,25 +855,25 @@ do
end
end
- local function tocmyk_l(content,colordepth)
- local l = #content
- local t = { }
- local n = 0
- if colordepth == 8 then
- for i=1,l,3 do
- local r, g, b = byte(content,i,i+2)
- n = n + 1 ; t[n] = char(255-r,255-g,255-b,0) -- a tad faster than chars[...]
- end
- else
- for i=1,l,6 do
- local r1, r2, g1, g2, b1, b2 = byte(content,i,i+5)
- n = n + 1 ; t[n] = char(255-r1,255-r2,255-g1,255-g2,255-b1,255-b2,0,0)
- end
- end
- return concat(t)
- end
-
- local tocmyk_c = pngtocmyk or tocmyk_l
+ -- local function tocmyk_l(content,colordepth)
+ -- local l = #content
+ -- local t = { }
+ -- local n = 0
+ -- if colordepth == 8 then
+ -- for i=1,l,3 do
+ -- local r, g, b = byte(content,i,i+2)
+ -- n = n + 1 ; t[n] = char(255-r,255-g,255-b,0) -- a tad faster than chars[...]
+ -- end
+ -- else
+ -- for i=1,l,6 do
+ -- local r1, r2, g1, g2, b1, b2 = byte(content,i,i+5)
+ -- n = n + 1 ; t[n] = char(255-r1,255-r2,255-g1,255-g2,255-b1,255-b2,0,0)
+ -- end
+ -- end
+ -- return concat(t)
+ -- end
+
+ local tocmyk_c = pngtocmyk
local function converttocmyk(content,colorspace,colordepth)
if colorspace == "DeviceRGB" and colordepth == 8 or colordepth == 16 then
@@ -885,16 +886,16 @@ do
return content, colorspace
end
- local function switch(v)
- if v then
- filtermask = filtermask_l
- decodemask = decodemask_l
- decodestrip = decodestrip_l
- transpose = transpose_l
- expand = expand_l
- createmask = createmask_l
- tocmyk = tocmyk_l
- else
+ -- local function switch(v)
+ -- if v then
+ -- filtermask = filtermask_l
+ -- decodemask = decodemask_l
+ -- decodestrip = decodestrip_l
+ -- transpose = transpose_l
+ -- expand = expand_l
+ -- createmask = createmask_l
+ -- tocmyk = tocmyk_l
+ -- else
filtermask = filtermask_c
decodemask = decodemask_c
decodestrip = decodestrip_c
@@ -902,15 +903,15 @@ do
expand = expand_c
createmask = createmask_c
tocmyk = tocmyk_c
- end
- end
+ -- end
+ -- end
- if pngapplyfilter then
- switch(false)
- directives.register("graphics.png.purelua",switch)
- else
- switch(true)
- end
+ -- if pngapplyfilter then
+ -- switch(false)
+ -- directives.register("graphics.png.purelua",switch)
+ -- else
+ -- switch(true)
+ -- end
local alwaysdecode = false -- trucky with palettes
local compresslevel = 3
@@ -1125,7 +1126,7 @@ do
palette = pdfarray {
pdfconstant("Indexed"),
pdfconstant(colorspace),
- idiv(#palette,nofbytes),
+ #palette // nofbytes,
pdfreference(pdfflushstreamobject(palette)),
}
end
diff --git a/tex/context/base/mkxl/lpdf-ini.lmt b/tex/context/base/mkxl/lpdf-ini.lmt
index bfa180b7e..9b4a2379c 100644
--- a/tex/context/base/mkxl/lpdf-ini.lmt
+++ b/tex/context/base/mkxl/lpdf-ini.lmt
@@ -64,7 +64,6 @@ local P, C, R, S, Cc, Cs, V = lpeg.P, lpeg.C, lpeg.R, lpeg.S, lpeg.Cc, lpeg.Cs,
local lpegmatch, lpegpatterns = lpeg.match, lpeg.patterns
local formatters = string.formatters
local isboolean = string.is_boolean
-local rshift = bit32.rshift
local report_objects = logs.reporter("backend","objects")
local report_finalizing = logs.reporter("backend","finalizing")
@@ -192,27 +191,6 @@ do
end
--- we could use a hash of predefined unicodes
-
--- local function tosixteen(str) -- an lpeg might be faster (no table)
--- if not str or str == "" then
--- return "<feff>" -- not () as we want an indication that it's unicode
--- else
--- local r, n = { "<feff" }, 1
--- for b in utfvalues(str) do
--- n = n + 1
--- if b < 0x10000 then
--- r[n] = format("%04x",b)
--- else
--- r[n] = format("%04x%04x",rshift(b,10),b%1024+0xDC00)
--- end
--- end
--- n = n + 1
--- r[n] = ">"
--- return concat(r)
--- end
--- end
-
local tosixteen, fromsixteen, topdfdoc, frompdfdoc, toeight, fromeight
do
@@ -223,8 +201,7 @@ do
v = format("%04x",v)
else
v = v - 0x10000
- v = format("%04x%04x",rshift(v,10)+0xD800,v%1024+0xDC00)
- -- v = format("%04x%04x",rshift(v-0x10000,10)+0xD800,v%1024+0xDC00)
+ v = format("%04x%04x",(v>>10)+0xD800,v%1024+0xDC00)
end
t[k] = v
return v
diff --git a/tex/context/base/mkxl/lpdf-lmt.lmt b/tex/context/base/mkxl/lpdf-lmt.lmt
index c0f02d75b..6e6d7c4c9 100644
--- a/tex/context/base/mkxl/lpdf-lmt.lmt
+++ b/tex/context/base/mkxl/lpdf-lmt.lmt
@@ -35,7 +35,6 @@ if not modules then modules = { } end modules ['lpdf-lmt'] = {
local type, next, unpack, tonumber, rawget = type, next, unpack, tonumber, rawget
local char, rep, find = string.char, string.rep, string.find
local formatters, splitupstring = string.formatters, string.splitup
-local band, extract = bit32.band, bit32.extract
local concat, sortedhash = table.concat, table.sortedhash
local setmetatableindex = table.setmetatableindex
local loaddata = io.loaddata
@@ -1230,11 +1229,11 @@ local flushimage do
rx, ry = bpfactor, bpfactor
end
- if band(transform,7) > 3 then
+ if (transform & 7) > 3 then
-- mirror
rx, tx = -rx, -tx
end
- local t = band(transform + rotation,3)
+ local t = (transform + rotation) & 3
if t == 0 then
-- nothing
elseif t == 1 then
@@ -1257,11 +1256,11 @@ local flushimage do
local t = transform + rotation
- if band(transform,7) > 3 then
+ if (transform & 7) > 3 then
t = t + 1
end
- t = band(t,3)
+ t = t & 3
if t == 0 then
-- no transform
@@ -2553,8 +2552,8 @@ local openfile, closefile do
if strm then
o = -o
end
- c1 = extract(o,8,8)
- c2 = extract(o,0,8)
+ c1 = (o>>8)&0xFF
+ c2 = (o>>0)&0xFF
if strm then
objects[i] = char(2,c1,c2,streams[o][i])
else
@@ -2566,8 +2565,8 @@ local openfile, closefile do
for i=nofobjects,1,-1 do
local o = objects[i]
if not o then
- local f1 = extract(lastfree,8,8)
- local f2 = extract(lastfree,0,8)
+ local f1 = (lastfree>>8)&0xFF
+ local f2 = (lastfree>>0)&0xFF
objects[i] = char(0,f1,f2,0)
lastfree = i
end
@@ -2584,9 +2583,9 @@ local openfile, closefile do
if strm then
o = -o
end
- c1 = extract(o,16,8)
- c2 = extract(o, 8,8)
- c3 = extract(o, 0,8)
+ c1 = (o>>16)&0xFF
+ c2 = (o>> 8)&0xFF
+ c3 = (o>> 0)&0xFF
if strm then
objects[i] = char(2,c1,c2,c3,streams[o][i])
else
@@ -2598,9 +2597,9 @@ local openfile, closefile do
for i=nofobjects,1,-1 do
local o = objects[i]
if not o then
- local f1 = extract(lastfree,16,8)
- local f2 = extract(lastfree, 8,8)
- local f3 = extract(lastfree, 0,8)
+ local f1 = (lastfree>>16)&0xFF
+ local f2 = (lastfree>> 8)&0xFF
+ local f3 = (lastfree>> 0)&0xFF
objects[i] = char(0,f1,f2,f3,0)
lastfree = i
end
@@ -2617,10 +2616,10 @@ local openfile, closefile do
if strm then
o = -o
end
- c1 = extract(o,24,8)
- c2 = extract(o,16,8)
- c3 = extract(o, 8,8)
- c4 = extract(o, 0,8)
+ c1 = (o>>24)&0xFF
+ c2 = (o>>16)&0xFF
+ c3 = (o>> 8)&0xFF
+ c4 = (o>> 0)&0xFF
if strm then
objects[i] = char(2,c1,c2,c3,c4,streams[o][i])
else
@@ -2632,10 +2631,10 @@ local openfile, closefile do
for i=nofobjects,1,-1 do
local o = objects[i]
if not o then
- local f1 = extract(lastfree,24,8)
- local f2 = extract(lastfree,16,8)
- local f3 = extract(lastfree, 8,8)
- local f4 = extract(lastfree, 0,8)
+ local f1 = (lastfree>>24)&0xFF
+ local f2 = (lastfree>>16)&0xFF
+ local f3 = (lastfree>> 8)&0xFF
+ local f4 = (lastfree>> 0)&0xFF
objects[i] = char(0,f1,f2,f3,f4,0)
lastfree = i
end
diff --git a/tex/context/base/mkxl/lpdf-wid.lmt b/tex/context/base/mkxl/lpdf-wid.lmt
index 268ca119e..53ba32812 100644
--- a/tex/context/base/mkxl/lpdf-wid.lmt
+++ b/tex/context/base/mkxl/lpdf-wid.lmt
@@ -459,7 +459,7 @@ function nodeinjections.attachfile(specification)
AP = appearance,
OC = analyzelayer(specification.layer),
-- F = pdfnull(), -- another rediculous need to satisfy validation
- F = bit32.band(bit32.bor(flags,4),(1023-1-2-32-256)), -- set 3, clear 1,2,6,9; PDF 32000-1, p385
+ F = (flags | 4) & (1023-1-2-32-256), -- set 3, clear 1,2,6,9; PDF 32000-1, p385
}
local width = specification.width or 0
local height = specification.height or 0
diff --git a/tex/context/base/mkxl/luat-bas.mkxl b/tex/context/base/mkxl/luat-bas.mkxl
index 0add4ce69..20d6c88fc 100644
--- a/tex/context/base/mkxl/luat-bas.mkxl
+++ b/tex/context/base/mkxl/luat-bas.mkxl
@@ -23,9 +23,8 @@
\registerctxluafile{l-string} {}
\registerctxluafile{l-table} {}
\registerctxluafile{l-boolean} {}
-\registerctxluafile{l-number} {}
+\registerctxluafile{l-number} {autosuffix}
\registerctxluafile{l-math} {}
-%registerctxluafile{l-aux} {}
\registerctxluafile{l-io} {}
\registerctxluafile{l-os} {}
\registerctxluafile{l-file} {}
@@ -33,8 +32,7 @@
\registerctxluafile{l-md5} {}
\registerctxluafile{l-sha} {}
\registerctxluafile{l-dir} {}
-\registerctxluafile{l-unicode} {optimize}
-%registerctxluafile{l-utils} {}
+\registerctxluafile{l-unicode} {autosuffix}
\registerctxluafile{l-url} {}
\registerctxluafile{l-set} {}
diff --git a/tex/context/base/mkxl/luat-lib.mkxl b/tex/context/base/mkxl/luat-lib.mkxl
index 61f9ccfd0..9bbcf7d17 100644
--- a/tex/context/base/mkxl/luat-lib.mkxl
+++ b/tex/context/base/mkxl/luat-lib.mkxl
@@ -15,8 +15,8 @@
\registerctxluafile{util-str}{}
\registerctxluafile{util-tab}{}
-\registerctxluafile{util-fil}{optimize}
-\registerctxluafile{util-sac}{optimize}
+\registerctxluafile{util-fil}{autosuffix}
+\registerctxluafile{util-sac}{autosuffix}
\registerctxluafile{util-sto}{} % could also be done in trac-deb.mkiv
\registerctxluafile{util-pck}{}
\registerctxluafile{util-prs}{}
diff --git a/tex/context/base/mkxl/math-ini.mkxl b/tex/context/base/mkxl/math-ini.mkxl
index 041246bca..46d1871a2 100644
--- a/tex/context/base/mkxl/math-ini.mkxl
+++ b/tex/context/base/mkxl/math-ini.mkxl
@@ -70,9 +70,9 @@
\registerctxluafile{math-ext}{}
\registerctxluafile{math-vfu}{autosuffix}
\registerctxluafile{math-ttv}{}
-\registerctxluafile{math-map}{optimize}
+\registerctxluafile{math-map}{autosuffix}
\registerctxluafile{math-ren}{}
-\registerctxluafile{math-noa}{autosuffix,optimize}
+\registerctxluafile{math-noa}{autosuffix}
\registerctxluafile{math-tag}{autosuffix}
\registerctxluafile{math-fbk}{}
\registerctxluafile{math-dir}{}
diff --git a/tex/context/base/mkxl/math-map.lmt b/tex/context/base/mkxl/math-map.lmt
new file mode 100644
index 000000000..de738a304
--- /dev/null
+++ b/tex/context/base/mkxl/math-map.lmt
@@ -0,0 +1,809 @@
+if not modules then modules = { } end modules ['math-map'] = {
+ version = 1.001,
+ optimize = true,
+ comment = "companion to math-ini.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- todo: make sparse .. if self
+
+--[[ldx--
+<p>Remapping mathematics alphabets.</p>
+--ldx]]--
+
+-- oldstyle: not really mathematics but happened to be part of
+-- the mathematics fonts in cmr
+--
+-- persian: we will also provide mappers for other
+-- scripts
+
+-- todo: alphabets namespace
+-- maybe: script/scriptscript dynamic,
+
+-- superscripped primes get unscripted !
+
+-- to be looked into once the fonts are ready (will become font
+-- goodie):
+--
+-- (U+2202,U+1D715) : upright
+-- (U+2202,U+1D715) : italic
+-- (U+2202,U+1D715) : upright
+--
+-- plus add them to the regular vectors below so that they honor \it etc
+
+local type, next = type, next
+local merged, sortedhash = table.merged, table.sortedhash
+
+local allocate = utilities.storage.allocate
+
+local otffeatures = fonts.constructors.features.otf
+local registerotffeature = otffeatures.register
+
+local setmetatableindex = table.setmetatableindex
+
+local texgetattribute = tex.getattribute
+local texsetattribute = tex.setattribute
+
+local trace_greek = false trackers.register("math.greek", function(v) trace_greek = v end)
+local report_remapping = logs.reporter("mathematics","remapping")
+
+mathematics = mathematics or { }
+local mathematics = mathematics
+
+local implement = interfaces.implement
+
+-- Unfortunately some alphabets have gaps (thereby troubling all applications that
+-- need to deal with math). Somewhat strange considering all those weird symbols that
+-- were added afterwards. The following trickery (and data) is only to be used for
+-- diagnostics and quick and dirty alphabet tracing (s-mat-10.mkiv) as we deal with
+-- it otherwise.
+
+-- todo: allocate
+
+mathematics.styles = allocate { "regular", "sansserif", "monospaced", "fraktur", "script", "blackboard" }
+mathematics.alternatives = allocate { "normal", "bold", "italic", "bolditalic" }
+mathematics.sets = allocate { "ucletters", "lcletters", "digits", "ucgreek", "lcgreek", "symbols" }
+
+mathematics.charactersets = allocate {
+ ucletters = {
+ 0x00041, 0x00042, 0x00043, 0x00044, 0x00045,
+ 0x00046, 0x00047, 0x00048, 0x00049, 0x0004A,
+ 0x0004B, 0x0004C, 0x0004D, 0x0004E, 0x0004F,
+ 0x00050, 0x00051, 0x00052, 0x00053, 0x00054,
+ 0x00055, 0x00056, 0x00057, 0x00058, 0x00059,
+ 0x0005A,
+ },
+ lcletters = {
+ 0x00061, 0x00062, 0x00063, 0x00064, 0x00065,
+ 0x00066, 0x00067, 0x00068, 0x00069, 0x0006A,
+ 0x0006B, 0x0006C, 0x0006D, 0x0006E, 0x0006F,
+ 0x00070, 0x00071, 0x00072, 0x00073, 0x00074,
+ 0x00075, 0x00076, 0x00077, 0x00078, 0x00079,
+ 0x0007A,
+ },
+ digits = {
+ 0x00030, 0x00031, 0x00032, 0x00033, 0x00034,
+ 0x00035, 0x00036, 0x00037, 0x00038, 0x00039,
+ },
+ ucgreek = {
+ 0x0391, 0x0392, 0x0393, 0x0394, 0x0395,
+ 0x0396, 0x0397, 0x0398, 0x0399, 0x039A,
+ 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
+ 0x03A0, 0x03A1, 0x03A3, 0x03A4, 0x03A5,
+ 0x03A6, 0x03A7, 0x03A8, 0x03A9
+ },
+ lcgreek = {
+ 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5,
+ 0x03B6, 0x03B7, 0x03B8, 0x03B9, 0x03BA,
+ 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
+ 0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4,
+ 0x03C5, 0x03C6, 0x03C7, 0x03C8, 0x03C9,
+ 0x03D1, 0x03D5, 0x03D6, 0x03F0, 0x03F1,
+ 0x03F4, 0x03F5
+ },
+}
+
+mathematics.gaps = allocate {
+ [0x1D455] = 0x0210E, -- ℎ h
+ [0x1D49D] = 0x0212C, -- ℬ script B
+ [0x1D4A0] = 0x02130, -- ℰ script E
+ [0x1D4A1] = 0x02131, -- ℱ script F
+ [0x1D4A3] = 0x0210B, -- ℋ script H
+ [0x1D4A4] = 0x02110, -- ℐ script I
+ [0x1D4A7] = 0x02112, -- ℒ script L
+ [0x1D4A8] = 0x02133, -- ℳ script M
+ [0x1D4AD] = 0x0211B, -- ℛ script R
+ [0x1D4BA] = 0x0212F, -- ℯ script e
+ [0x1D4BC] = 0x0210A, -- ℊ script g
+ -- [0x1D4C1] = 0x02113, -- exception: liter
+ [0x1D4C4] = 0x02134, -- ℴ script o
+ [0x1D506] = 0x0212D, -- ℭ fraktur C
+ [0x1D50B] = 0x0210C, -- ℌ fraktur H
+ [0x1D50C] = 0x02111, -- ℑ fraktur I
+ [0x1D515] = 0x0211C, -- ℜ fraktur R
+ [0x1D51D] = 0x02128, -- ℨ fraktur Z
+ [0x1D53A] = 0x02102, -- ℂ bb C
+ [0x1D53F] = 0x0210D, -- ℍ bb H
+ [0x1D545] = 0x02115, -- ℕ bb N
+ [0x1D547] = 0x02119, -- ℙ bb P
+ [0x1D548] = 0x0211A, -- ℚ bb Q
+ [0x1D549] = 0x0211D, -- ℝ bb R
+ [0x1D551] = 0x02124, -- ℤ bb Z
+}
+
+local function fillinmathgaps(tfmdata,key,value)
+ local mathgaps = mathematics.gaps
+ local characters = tfmdata.characters
+ local descriptions = tfmdata.descriptions
+ for gap, original in next, mathgaps do
+ if characters[original] and not characters[gap] then
+ characters [gap] = characters [original]
+ descriptions[gap] = descriptions[original]
+ end
+ end
+end
+
+registerotffeature {
+ name = "mathgaps",
+ description = "plug gaps in math alphabets",
+ comment = "regular document sources should not depend on this",
+ manipulators = {
+ base = fillinmathgaps,
+ node = fillinmathgaps,
+ }
+}
+
+-- we could use one level less and have tf etc be tables directly but the
+-- following approach permits easier remapping of a-a, A-Z and 0-9 to
+-- fallbacks; symbols is currently mostly greek
+
+local function todigit (n) local t = { } for i=0, 9 do t[0x00030+i] = n+i end return t end
+local function toupper (n) local t = { } for i=0,25 do t[0x00041+i] = n+i end return t end
+local function tolower (n) local t = { } for i=0,25 do t[0x00061+i] = n+i end return t end
+local function tovector(t) return t end
+
+-- how about 0x2A (ast) cq. 0x2217
+-- 0x2D (hyphen) cq. 0x2212
+-- 0x3A (colon) cq. 0x2236
+
+local regular_tf = {
+ digits = todigit(0x00030),
+ ucletters = toupper(0x00041),
+ lcletters = tolower(0x00061),
+ ucgreek = {
+ [0x0391]=0x0391, [0x0392]=0x0392, [0x0393]=0x0393, [0x0394]=0x0394, [0x0395]=0x0395,
+ [0x0396]=0x0396, [0x0397]=0x0397, [0x0398]=0x0398, [0x0399]=0x0399, [0x039A]=0x039A,
+ [0x039B]=0x039B, [0x039C]=0x039C, [0x039D]=0x039D, [0x039E]=0x039E, [0x039F]=0x039F,
+ [0x03A0]=0x03A0, [0x03A1]=0x03A1, [0x03A3]=0x03A3, [0x03A4]=0x03A4, [0x03A5]=0x03A5,
+ [0x03A6]=0x03A6, [0x03A7]=0x03A7, [0x03A8]=0x03A8, [0x03A9]=0x03A9,
+ },
+ lcgreek = {
+ [0x03B1]=0x03B1, [0x03B2]=0x03B2, [0x03B3]=0x03B3, [0x03B4]=0x03B4, [0x03B5]=0x03B5,
+ [0x03B6]=0x03B6, [0x03B7]=0x03B7, [0x03B8]=0x03B8, [0x03B9]=0x03B9, [0x03BA]=0x03BA,
+ [0x03BB]=0x03BB, [0x03BC]=0x03BC, [0x03BD]=0x03BD, [0x03BE]=0x03BE, [0x03BF]=0x03BF,
+ [0x03C0]=0x03C0, [0x03C1]=0x03C1, [0x03C2]=0x03C2, [0x03C3]=0x03C3, [0x03C4]=0x03C4,
+ [0x03C5]=0x03C5, [0x03C6]=0x03C6, [0x03C7]=0x03C7, [0x03C8]=0x03C8, [0x03C9]=0x03C9,
+ [0x03D1]=0x03D1, [0x03D5]=0x03D5, [0x03D6]=0x03D6, [0x03F0]=0x03F0, [0x03F1]=0x03F1,
+ [0x03F4]=0x03F4, [0x03F5]=0x03F5,
+ },
+ symbols = {
+ [0x2202]=0x2202, [0x2207]=0x2207,
+ [0x0027]=0x2032, -- prime
+ },
+}
+
+local regular_it = {
+ digits = tovector(regular_tf.digits),
+ ucletters = toupper(0x1D434),
+ lcletters = { -- H
+ [0x00061]=0x1D44E, [0x00062]=0x1D44F, [0x00063]=0x1D450, [0x00064]=0x1D451, [0x00065]=0x1D452,
+ [0x00066]=0x1D453, [0x00067]=0x1D454, [0x00068]=0x0210E, [0x00069]=0x1D456, [0x0006A]=0x1D457,
+ [0x0006B]=0x1D458, [0x0006C]=0x1D459, [0x0006D]=0x1D45A, [0x0006E]=0x1D45B, [0x0006F]=0x1D45C,
+ [0x00070]=0x1D45D, [0x00071]=0x1D45E, [0x00072]=0x1D45F, [0x00073]=0x1D460, [0x00074]=0x1D461,
+ [0x00075]=0x1D462, [0x00076]=0x1D463, [0x00077]=0x1D464, [0x00078]=0x1D465, [0x00079]=0x1D466,
+ [0x0007A]=0x1D467,
+ -- arabic
+ [0x00627] = 0x1EE00, [0x00628] = 0x1EE21, [0x0062A] = 0x1EE15, [0x0062B] = 0x1EE16,
+ [0x0062C] = 0x1EE22, [0x0062D] = 0x1EE07, [0x0062E] = 0x1EE17, [0x0062F] = 0x1EE03,
+ [0x00630] = 0x1EE18, [0x00631] = 0x1EE13, [0x00632] = 0x1EE06, [0x00633] = 0x1EE0E,
+ [0x00634] = 0x1EE14, [0x00635] = 0x1EE11, [0x00636] = 0x1EE19, [0x00637] = 0x1EE08,
+ [0x00638] = 0x1EE1A, [0x00639] = 0x1EE0F, [0x0063A] = 0x1EE1B, [0x00641] = 0x1EE10,
+ [0x00642] = 0x1EE12, [0x00643] = 0x1EE0A, [0x00644] = 0x1EE0B, [0x00645] = 0x1EE0C,
+ [0x00646] = 0x1EE0D, [0x00647] = 0x1EE24, [0x00648] = 0x1EE05, [0x0064A] = 0x1EE09,
+ [0x0066E] = 0x1EE1C, [0x0066F] = 0x1EE1F, [0x006A1] = 0x1EE1E, [0x006BA] = 0x1EE1D,
+ },
+ ucgreek = {
+ [0x0391]=0x1D6E2, [0x0392]=0x1D6E3, [0x0393]=0x1D6E4, [0x0394]=0x1D6E5, [0x0395]=0x1D6E6,
+ [0x0396]=0x1D6E7, [0x0397]=0x1D6E8, [0x0398]=0x1D6E9, [0x0399]=0x1D6EA, [0x039A]=0x1D6EB,
+ [0x039B]=0x1D6EC, [0x039C]=0x1D6ED, [0x039D]=0x1D6EE, [0x039E]=0x1D6EF, [0x039F]=0x1D6F0,
+ [0x03A0]=0x1D6F1, [0x03A1]=0x1D6F2, [0x03A3]=0x1D6F4, [0x03A4]=0x1D6F5, [0x03A5]=0x1D6F6,
+ [0x03A6]=0x1D6F7, [0x03A7]=0x1D6F8, [0x03A8]=0x1D6F9, [0x03A9]=0x1D6FA,
+ },
+ lcgreek = {
+ [0x03B1]=0x1D6FC, [0x03B2]=0x1D6FD, [0x03B3]=0x1D6FE, [0x03B4]=0x1D6FF, [0x03B5]=0x1D700,
+ [0x03B6]=0x1D701, [0x03B7]=0x1D702, [0x03B8]=0x1D703, [0x03B9]=0x1D704, [0x03BA]=0x1D705,
+ [0x03BB]=0x1D706, [0x03BC]=0x1D707, [0x03BD]=0x1D708, [0x03BE]=0x1D709, [0x03BF]=0x1D70A,
+ [0x03C0]=0x1D70B, [0x03C1]=0x1D70C, [0x03C2]=0x1D70D, [0x03C3]=0x1D70E, [0x03C4]=0x1D70F,
+ [0x03C5]=0x1D710, [0x03C6]=0x1D711, [0x03C7]=0x1D712, [0x03C8]=0x1D713, [0x03C9]=0x1D714,
+ [0x03D1]=0x1D717, [0x03D5]=0x1D719, [0x03D6]=0x1D71B, [0x03F0]=0x1D718, [0x03F1]=0x1D71A,
+ [0x03F4]=0x1D6F3, [0x03F5]=0x1D716,
+ },
+ symbols = {
+ [0x2202]=0x1D715, [0x2207]=0x1D6FB,
+ [0x0027]=0x2032, -- prime
+ },
+}
+
+local regular_bf= {
+ digits = todigit(0x1D7CE),
+ ucletters = toupper(0x1D400),
+ lcletters = tolower(0x1D41A),
+ ucgreek = {
+ [0x0391]=0x1D6A8, [0x0392]=0x1D6A9, [0x0393]=0x1D6AA, [0x0394]=0x1D6AB, [0x0395]=0x1D6AC,
+ [0x0396]=0x1D6AD, [0x0397]=0x1D6AE, [0x0398]=0x1D6AF, [0x0399]=0x1D6B0, [0x039A]=0x1D6B1,
+ [0x039B]=0x1D6B2, [0x039C]=0x1D6B3, [0x039D]=0x1D6B4, [0x039E]=0x1D6B5, [0x039F]=0x1D6B6,
+ [0x03A0]=0x1D6B7, [0x03A1]=0x1D6B8, [0x03A3]=0x1D6BA, [0x03A4]=0x1D6BB, [0x03A5]=0x1D6BC,
+ [0x03A6]=0x1D6BD, [0x03A7]=0x1D6BE, [0x03A8]=0x1D6BF, [0x03A9]=0x1D6C0,
+ },
+ lcgreek = {
+ [0x03B1]=0x1D6C2, [0x03B2]=0x1D6C3, [0x03B3]=0x1D6C4, [0x03B4]=0x1D6C5, [0x03B5]=0x1D6C6,
+ [0x03B6]=0x1D6C7, [0x03B7]=0x1D6C8, [0x03B8]=0x1D6C9, [0x03B9]=0x1D6CA, [0x03BA]=0x1D6CB,
+ [0x03BB]=0x1D6CC, [0x03BC]=0x1D6CD, [0x03BD]=0x1D6CE, [0x03BE]=0x1D6CF, [0x03BF]=0x1D6D0,
+ [0x03C0]=0x1D6D1, [0x03C1]=0x1D6D2, [0x03C2]=0x1D6D3, [0x03C3]=0x1D6D4, [0x03C4]=0x1D6D5,
+ [0x03C5]=0x1D6D6, [0x03C6]=0x1D6D7, [0x03C7]=0x1D6D8, [0x03C8]=0x1D6D9, [0x03C9]=0x1D6DA,
+ [0x03D1]=0x1D6DD, [0x03D5]=0x1D6DF, [0x03D6]=0x1D6E1, [0x03F0]=0x1D6DE, [0x03F1]=0x1D6E0,
+ [0x03F4]=0x1D6B9, [0x03F5]=0x1D6DC,
+ },
+ symbols = {
+ [0x2202]=0x1D6DB, [0x2207]=0x1D6C1,
+ [0x0027]=0x2032, -- prime
+ },
+}
+
+local regular_bi = {
+ digits = tovector(regular_bf.digits),
+ ucletters = toupper(0x1D468),
+ lcletters = tolower(0x1D482),
+ ucgreek = {
+ [0x0391]=0x1D71C, [0x0392]=0x1D71D, [0x0393]=0x1D71E, [0x0394]=0x1D71F, [0x0395]=0x1D720,
+ [0x0396]=0x1D721, [0x0397]=0x1D722, [0x0398]=0x1D723, [0x0399]=0x1D724, [0x039A]=0x1D725,
+ [0x039B]=0x1D726, [0x039C]=0x1D727, [0x039D]=0x1D728, [0x039E]=0x1D729, [0x039F]=0x1D72A,
+ [0x03A0]=0x1D72B, [0x03A1]=0x1D72C, [0x03A3]=0x1D72E, [0x03A4]=0x1D72F, [0x03A5]=0x1D730,
+ [0x03A6]=0x1D731, [0x03A7]=0x1D732, [0x03A8]=0x1D733, [0x03A9]=0x1D734,
+ },
+ lcgreek = {
+ [0x03B1]=0x1D736, [0x03B2]=0x1D737, [0x03B3]=0x1D738, [0x03B4]=0x1D739, [0x03B5]=0x1D73A,
+ [0x03B6]=0x1D73B, [0x03B7]=0x1D73C, [0x03B8]=0x1D73D, [0x03B9]=0x1D73E, [0x03BA]=0x1D73F,
+ [0x03BB]=0x1D740, [0x03BC]=0x1D741, [0x03BD]=0x1D742, [0x03BE]=0x1D743, [0x03BF]=0x1D744,
+ [0x03C0]=0x1D745, [0x03C1]=0x1D746, [0x03C2]=0x1D747, [0x03C3]=0x1D748, [0x03C4]=0x1D749,
+ [0x03C5]=0x1D74A, [0x03C6]=0x1D74B, [0x03C7]=0x1D74C, [0x03C8]=0x1D74D, [0x03C9]=0x1D74E,
+ [0x03D1]=0x1D751, [0x03D5]=0x1D753, [0x03D6]=0x1D755, [0x03F0]=0x1D752, [0x03F1]=0x1D754,
+ [0x03F4]=0x1D72D, [0x03F5]=0x1D750,
+ },
+ symbols = {
+ [0x2202]=0x1D74F, [0x2207]=0x1D735,
+ [0x0027]=0x2032, -- prime
+ },
+}
+
+local regular = {
+ tf = regular_tf,
+ it = regular_it,
+ bf = regular_bf,
+ bi = regular_bi,
+}
+
+local sansserif_tf = {
+ digits = todigit(0x1D7E2),
+ ucletters = toupper(0x1D5A0),
+ lcletters = tolower(0x1D5BA),
+ lcgreek = tovector(regular_tf.lcgreek),
+ ucgreek = tovector(regular_tf.ucgreek),
+ symbols = tovector(regular_tf.symbols),
+}
+
+local sansserif_it = {
+ digits = tovector(regular_tf.digits),
+ ucletters = toupper(0x1D608),
+ lcletters = tolower(0x1D622),
+ lcgreek = tovector(regular_tf.lcgreek),
+ ucgreek = tovector(regular_tf.ucgreek),
+ symbols = tovector(regular_tf.symbols),
+}
+
+local sansserif_bf = {
+ digits = todigit(0x1D7EC),
+ ucletters = toupper(0x1D5D4),
+ lcletters = tolower(0x1D5EE),
+ ucgreek = {
+ [0x0391]=0x1D756, [0x0392]=0x1D757, [0x0393]=0x1D758, [0x0394]=0x1D759, [0x0395]=0x1D75A,
+ [0x0396]=0x1D75B, [0x0397]=0x1D75C, [0x0398]=0x1D75D, [0x0399]=0x1D75E, [0x039A]=0x1D75F,
+ [0x039B]=0x1D760, [0x039C]=0x1D761, [0x039D]=0x1D762, [0x039E]=0x1D763, [0x039F]=0x1D764,
+ [0x03A0]=0x1D765, [0x03A1]=0x1D766, [0x03A3]=0x1D768, [0x03A4]=0x1D769, [0x03A5]=0x1D76A,
+ [0x03A6]=0x1D76B, [0x03A7]=0x1D76C, [0x03A8]=0x1D76D, [0x03A9]=0x1D76E,
+ },
+ lcgreek = {
+ [0x03B1]=0x1D770, [0x03B2]=0x1D771, [0x03B3]=0x1D772, [0x03B4]=0x1D773, [0x03B5]=0x1D774,
+ [0x03B6]=0x1D775, [0x03B7]=0x1D776, [0x03B8]=0x1D777, [0x03B9]=0x1D778, [0x03BA]=0x1D779,
+ [0x03BB]=0x1D77A, [0x03BC]=0x1D77B, [0x03BD]=0x1D77C, [0x03BE]=0x1D77D, [0x03BF]=0x1D77E,
+ [0x03C0]=0x1D77F, [0x03C1]=0x1D780, [0x03C2]=0x1D781, [0x03C3]=0x1D782, [0x03C4]=0x1D783,
+ [0x03C5]=0x1D784, [0x03C6]=0x1D785, [0x03C7]=0x1D786, [0x03C8]=0x1D787, [0x03C9]=0x1D788,
+ [0x03D1]=0x1D78B, [0x03D5]=0x1D78D, [0x03D6]=0x1D78F, [0x03F0]=0x1D78C, [0x03F1]=0x1D78E,
+ [0x03F4]=0x1D767, [0x03F5]=0x1D78A,
+ },
+ symbols = {
+ [0x2202]=0x1D789, [0x2207]=0x1D76F,
+ [0x0027]=0x2032, -- prime
+ },
+}
+
+local sansserif_bi = {
+ digits = tovector(sansserif_bf.digits),
+ ucletters = toupper(0x1D63C),
+ lcletters = tolower(0x1D656),
+ ucgreek = {
+ [0x0391]=0x1D790, [0x0392]=0x1D791, [0x0393]=0x1D792, [0x0394]=0x1D793, [0x0395]=0x1D794,
+ [0x0396]=0x1D795, [0x0397]=0x1D796, [0x0398]=0x1D797, [0x0399]=0x1D798, [0x039A]=0x1D799,
+ [0x039B]=0x1D79A, [0x039C]=0x1D79B, [0x039D]=0x1D79C, [0x039E]=0x1D79D, [0x039F]=0x1D79E,
+ [0x03A0]=0x1D79F, [0x03A1]=0x1D7A0, [0x03A3]=0x1D7A2, [0x03A4]=0x1D7A3, [0x03A5]=0x1D7A4,
+ [0x03A6]=0x1D7A5, [0x03A7]=0x1D7A6, [0x03A8]=0x1D7A7, [0x03A9]=0x1D7A8,
+ },
+ lcgreek = {
+ [0x03B1]=0x1D7AA, [0x03B2]=0x1D7AB, [0x03B3]=0x1D7AC, [0x03B4]=0x1D7AD, [0x03B5]=0x1D7AE,
+ [0x03B6]=0x1D7AF, [0x03B7]=0x1D7B0, [0x03B8]=0x1D7B1, [0x03B9]=0x1D7B2, [0x03BA]=0x1D7B3,
+ [0x03BB]=0x1D7B4, [0x03BC]=0x1D7B5, [0x03BD]=0x1D7B6, [0x03BE]=0x1D7B7, [0x03BF]=0x1D7B8,
+ [0x03C0]=0x1D7B9, [0x03C1]=0x1D7BA, [0x03C2]=0x1D7BB, [0x03C3]=0x1D7BC, [0x03C4]=0x1D7BD,
+ [0x03C5]=0x1D7BE, [0x03C6]=0x1D7BF, [0x03C7]=0x1D7C0, [0x03C8]=0x1D7C1, [0x03C9]=0x1D7C2,
+ [0x03D1]=0x1D7C5, [0x03D5]=0x1D7C7, [0x03D6]=0x1D7C9, [0x03F0]=0x1D7C6, [0x03F1]=0x1D7C8,
+ [0x03F4]=0x1D7A1, [0x03F5]=0x1D7C4,
+ },
+ symbols = {
+ [0x2202]=0x1D7C3, [0x2207]=0x1D7A9,
+ [0x0027]=0x2032, -- prime
+ },
+}
+
+local sansserif = {
+ tf = sansserif_tf,
+ it = sansserif_it,
+ bf = sansserif_bf,
+ bi = sansserif_bi,
+}
+
+local monospaced_tf = {
+ digits = todigit(0x1D7F6),
+ ucletters = toupper(0x1D670),
+ lcletters = tolower(0x1D68A),
+ lcgreek = tovector(sansserif_tf.lcgreek),
+ ucgreek = tovector(sansserif_tf.ucgreek),
+ symbols = tovector(sansserif_tf.symbols),
+}
+
+local monospaced_it = tovector(sansserif_it)
+local monospaced_bf = tovector(sansserif_bf)
+local monospaced_bi = tovector(sansserif_bi)
+
+local monospaced = {
+ tf = monospaced_tf,
+ it = monospaced_tf,
+ bf = monospaced_tf,
+ bi = monospaced_bf,
+}
+
+local blackboard_tf = {
+ digits = todigit(0x1D7D8),
+ ucletters = { -- C H N P Q R Z
+ [0x00041]=0x1D538, [0x00042]=0x1D539, [0x00043]=0x02102, [0x00044]=0x1D53B, [0x00045]=0x1D53C,
+ [0x00046]=0x1D53D, [0x00047]=0x1D53E, [0x00048]=0x0210D, [0x00049]=0x1D540, [0x0004A]=0x1D541,
+ [0x0004B]=0x1D542, [0x0004C]=0x1D543, [0x0004D]=0x1D544, [0x0004E]=0x02115, [0x0004F]=0x1D546,
+ [0x00050]=0x02119, [0x00051]=0x0211A, [0x00052]=0x0211D, [0x00053]=0x1D54A, [0x00054]=0x1D54B,
+ [0x00055]=0x1D54C, [0x00056]=0x1D54D, [0x00057]=0x1D54E, [0x00058]=0x1D54F, [0x00059]=0x1D550,
+ [0x0005A]=0x02124,
+ },
+ lcletters = {
+ -- tolower(0x1D552) :
+ [0x00061] = 0x1D552, [0x00062] = 0x1D553, [0x00063] = 0x1D554, [0x00064] = 0x1D555,
+ [0x00065] = 0x1D556, [0x00066] = 0x1D557, [0x00067] = 0x1D558, [0x00068] = 0x1D559,
+ [0x00069] = 0x1D55A, [0x0006A] = 0x1D55B, [0x0006B] = 0x1D55C, [0x0006C] = 0x1D55D,
+ [0x0006D] = 0x1D55E, [0x0006E] = 0x1D55F, [0x0006F] = 0x1D560, [0x00070] = 0x1D561,
+ [0x00071] = 0x1D562, [0x00072] = 0x1D563, [0x00073] = 0x1D564, [0x00074] = 0x1D565,
+ [0x00075] = 0x1D566, [0x00076] = 0x1D567, [0x00077] = 0x1D568, [0x00078] = 0x1D569,
+ [0x00079] = 0x1D56A, [0x0007A] = 0x1D56B,
+ -- arabic
+ [0x00628] = 0x1EEA1, [0x0062A] = 0x1EEB5, [0x0062B] = 0x1EEB6, [0x0062C] = 0x1EEA2,
+ [0x0062D] = 0x1EEA7, [0x0062E] = 0x1EEB7, [0x0062F] = 0x1EEA3, [0x00630] = 0x1EEB8,
+ [0x00631] = 0x1EEB3, [0x00632] = 0x1EEA6, [0x00633] = 0x1EEAE, [0x00634] = 0x1EEB4,
+ [0x00635] = 0x1EEB1, [0x00636] = 0x1EEB9, [0x00637] = 0x1EEA8, [0x00638] = 0x1EEBA,
+ [0x00639] = 0x1EEAF, [0x0063A] = 0x1EEBB, [0x00641] = 0x1EEB0, [0x00642] = 0x1EEB2,
+ [0x00644] = 0x1EEAB, [0x00645] = 0x1EEAC, [0x00646] = 0x1EEAD, [0x00648] = 0x1EEA5,
+ [0x0064A] = 0x1EEA9,
+ },
+ lcgreek = { -- gamma pi
+ [0x03B3]=0x0213C, [0x03C0]=0x0213D,
+ },
+ ucgreek = { -- Gamma pi
+ [0x0393]=0x0213E, [0x03A0]=0x0213F,
+ },
+ symbols = { -- sum
+ [0x2211]=0x02140,
+ [0x0027]=0x2032, -- prime
+ },
+}
+
+blackboard_tf.lcgreek = merged(regular_tf.lcgreek, blackboard_tf.lcgreek)
+blackboard_tf.ucgreek = merged(regular_tf.ucgreek, blackboard_tf.ucgreek)
+blackboard_tf.symbols = merged(regular_tf.symbols, blackboard_tf.symbols)
+
+local blackboard = {
+ tf = blackboard_tf,
+ it = blackboard_tf,
+ bf = blackboard_tf,
+ bi = blackboard_tf,
+}
+
+local fraktur_tf= {
+ digits = tovector(regular_tf.digits),
+ ucletters = { -- C H I R Z
+ [0x00041]=0x1D504, [0x00042]=0x1D505, [0x00043]=0x0212D, [0x00044]=0x1D507, [0x00045]=0x1D508,
+ [0x00046]=0x1D509, [0x00047]=0x1D50A, [0x00048]=0x0210C, [0x00049]=0x02111, [0x0004A]=0x1D50D,
+ [0x0004B]=0x1D50E, [0x0004C]=0x1D50F, [0x0004D]=0x1D510, [0x0004E]=0x1D511, [0x0004F]=0x1D512,
+ [0x00050]=0x1D513, [0x00051]=0x1D514, [0x00052]=0x0211C, [0x00053]=0x1D516, [0x00054]=0x1D517,
+ [0x00055]=0x1D518, [0x00056]=0x1D519, [0x00057]=0x1D51A, [0x00058]=0x1D51B, [0x00059]=0x1D51C,
+ [0x0005A]=0x02128,
+ },
+ lcletters = tolower(0x1D51E),
+ lcgreek = tovector(regular_tf.lcgreek),
+ ucgreek = tovector(regular_tf.ucgreek),
+ symbols = tovector(regular_tf.symbols),
+}
+
+local fraktur_bf = {
+ digits = tovector(regular_bf.digits),
+ ucletters = toupper(0x1D56C),
+ lcletters = tolower(0x1D586),
+ lcgreek = tovector(regular_bf.lcgreek),
+ ucgreek = tovector(regular_bf.ucgreek),
+ symbols = tovector(regular_bf.symbols),
+}
+
+local fraktur = { -- ok
+ tf = fraktur_tf,
+ bf = fraktur_bf,
+ it = fraktur_tf,
+ bi = fraktur_bf,
+}
+
+local script_tf = {
+ digits = tovector(regular_tf.digits),
+ ucletters = { -- B E F H I L M R -- P 2118
+ [0x00041]=0x1D49C, [0x00042]=0x0212C, [0x00043]=0x1D49E, [0x00044]=0x1D49F, [0x00045]=0x02130,
+ [0x00046]=0x02131, [0x00047]=0x1D4A2, [0x00048]=0x0210B, [0x00049]=0x02110, [0x0004A]=0x1D4A5,
+ [0x0004B]=0x1D4A6, [0x0004C]=0x02112, [0x0004D]=0x02133, [0x0004E]=0x1D4A9, [0x0004F]=0x1D4AA,
+ [0x00050]=0x1D4AB, [0x00051]=0x1D4AC, [0x00052]=0x0211B, [0x00053]=0x1D4AE, [0x00054]=0x1D4AF,
+ [0x00055]=0x1D4B0, [0x00056]=0x1D4B1, [0x00057]=0x1D4B2, [0x00058]=0x1D4B3, [0x00059]=0x1D4B4,
+ [0x0005A]=0x1D4B5,
+ },
+ lcletters = { -- E G O -- L 2113
+ [0x00061]=0x1D4B6, [0x00062]=0x1D4B7, [0x00063]=0x1D4B8, [0x00064]=0x1D4B9, [0x00065]=0x0212F,
+ [0x00066]=0x1D4BB, [0x00067]=0x0210A, [0x00068]=0x1D4BD, [0x00069]=0x1D4BE, [0x0006A]=0x1D4BF,
+ [0x0006B]=0x1D4C0, [0x0006C]=0x1D4C1, [0x0006D]=0x1D4C2, [0x0006E]=0x1D4C3, [0x0006F]=0x02134,
+ [0x00070]=0x1D4C5, [0x00071]=0x1D4C6, [0x00072]=0x1D4C7, [0x00073]=0x1D4C8, [0x00074]=0x1D4C9,
+ [0x00075]=0x1D4CA, [0x00076]=0x1D4CB, [0x00077]=0x1D4CC, [0x00078]=0x1D4CD, [0x00079]=0x1D4CE,
+ [0x0007A]=0x1D4CF,
+ },
+ lcgreek = tovector(regular_tf.lcgreek),
+ ucgreek = tovector(regular_tf.ucgreek),
+ symbols = tovector(regular_tf.symbols),
+}
+
+local script_bf = {
+ digits = tovector(regular_bf.digits),
+ ucletters = toupper(0x1D4D0),
+ lcletters = tolower(0x1D4EA),
+ lcgreek = tovector(regular_bf.lcgreek),
+ ucgreek = tovector(regular_bf.ucgreek),
+ symbols = tovector(regular_bf.symbols),
+}
+
+local script = {
+ tf = script_tf,
+ bf = script_bf,
+ it = script_tf,
+ bi = script_bf,
+}
+
+local alphabets = allocate {
+ regular = regular,
+ sansserif = sansserif,
+ monospaced = monospaced,
+ blackboard = blackboard,
+ fraktur = fraktur,
+ script = script,
+}
+
+alphabets.tt = tovector(monospaced)
+alphabets.ss = tovector(sansserif)
+alphabets.rm = tovector(regular)
+alphabets.bb = tovector(blackboard)
+alphabets.fr = tovector(fraktur)
+alphabets.sr = tovector(script)
+
+monospaced.normal = tovector(monospaced_tf)
+monospaced.italic = tovector(monospaced_it)
+monospaced.bold = tovector(monospaced_bf)
+monospaced.bolditalic = tovector(monospaced_bi)
+
+sansserif.normal = tovector(sansserif_tf)
+sansserif.italic = tovector(sansserif_it)
+sansserif.bold = tovector(sansserif_bf)
+sansserif.bolditalic = tovector(sansserif_bi)
+
+regular.normal = tovector(regular_tf)
+regular.italic = tovector(regular_it)
+regular.bold = tovector(regular_bf)
+regular.bolditalic = tovector(regular_bi)
+
+alphabets.serif = tovector(regular)
+alphabets.type = tovector(monospaced)
+alphabets.teletype = tovector(monospaced)
+
+mathematics.alphabets = alphabets
+
+local mathremap = allocate { }
+mathematics.mapremap = mathremap
+
+local boldmap = allocate { }
+mathematics.boldmap = boldmap
+
+-- all math (a bit of redundancy here) (sorted for tracing)
+
+for alphabet, styles in sortedhash(alphabets) do -- per 9/6/2011 we also have attr for missing
+ for style, data in sortedhash(styles) do
+ -- let's keep the long names (for tracing)
+ local n = #mathremap + 1
+ local d = {
+ attribute = n,
+ alphabet = alphabet,
+ style = style,
+ }
+ styles[style] = d
+ setmetatableindex(d,data) -- we could use a alphadata table
+ mathremap[n] = d
+ end
+end
+
+-- bold math
+
+local function remapbold(tf,bf)
+ local styles = mathematics.styles
+ local sets = mathematics.sets
+ for i=1,#styles do
+ for j=1,#sets do
+ local one = styles[i]
+ local two = sets[j]
+ local a = alphabets[one]
+ local tf = a[tf][two]
+ local bf = a[bf][two]
+ if tf and bf then
+ for k, v in next, tf do
+ boldmap[v] = bf[k]
+ end
+ end
+ end
+ end
+end
+
+remapbold("tf","bf")
+remapbold("it","bi")
+
+-- table.save("e:/tmp/a.lua",alphabets)
+-- table.save("e:/tmp/b.lua",boldmap)
+
+function mathematics.tostyle(attribute)
+ local r = mathremap[attribute]
+ return r and r.style or "tf"
+end
+
+function mathematics.toname(attribute)
+ local r = mathremap[attribute]
+ return r and r.alphabet or "regular"
+end
+
+-- of course we could do some div/mod trickery instead
+
+local mathalphabet = attributes.private("mathalphabet")
+
+function mathematics.getboth(alphabet,style)
+ local data = alphabet and alphabets[alphabet] or regular
+ data = data[style or "tf"] or data.tf
+ return data and data.attribute
+end
+
+function mathematics.getstyle(style)
+ local r = mathremap[texgetattribute(mathalphabet)]
+ local alphabet = r and r.alphabet or "regular"
+ local data = alphabets[alphabet][style]
+ return data and data.attribute
+end
+
+function mathematics.syncboth(alphabet,style)
+ local data = alphabet and alphabets[alphabet] or regular
+ data = style and data[style] or data.tf
+ texsetattribute(mathalphabet,data and data.attribute or texattribute[mathalphabet])
+end
+
+function mathematics.syncstyle(style)
+ local r = mathremap[texgetattribute(mathalphabet)]
+ local alphabet = r and r.alphabet or "regular"
+ local data = alphabets[alphabet][style]
+ texsetattribute(mathalphabet,data and data.attribute or texattribute[mathalphabet])
+end
+
+function mathematics.syncname(alphabet)
+ -- local r = mathremap[mathalphabet]
+ local r = mathremap[texgetattribute(mathalphabet)]
+ local style = r and r.style or "tf"
+ local data = alphabets[alphabet][style]
+ texsetattribute(mathalphabet,data and data.attribute or texattribute[mathalphabet])
+end
+
+implement {
+ name = "setmathattribute",
+ arguments = "2 strings",
+ actions = function(alphabet,style)
+ local data = alphabets[alphabet] or regular
+ data = data[style] or data.tf
+ texsetattribute(mathalphabet,data and data.attribute or texattribute[mathalphabet])
+ end
+}
+
+implement {
+ name = "setmathstyle",
+ arguments = "string",
+ actions = function(style)
+ local r = mathremap[texgetattribute(mathalphabet)]
+ local alphabet = r and r.alphabet or "regular"
+ local data = alphabets[alphabet][style]
+ texsetattribute(mathalphabet,data and data.attribute or texattribute[mathalphabet])
+ end
+}
+
+implement {
+ name = "setmathalphabet",
+ arguments = "string",
+ actions = function(alphabet)
+ -- local r = mathremap[mathalphabet]
+ local r = mathremap[texgetattribute(mathalphabet)]
+ local style = r and r.style or "tf"
+ local data = alphabets[alphabet][style]
+ texsetattribute(mathalphabet,data and data.attribute or texattribute[mathalphabet])
+ end
+}
+
+local islcgreek = regular_tf.lcgreek
+local isucgreek = regular_tf.ucgreek
+local issygreek = regular_tf.symbols
+local isgreek = merged(islcgreek,isucgreek,issygreek)
+
+local greekremapping = {
+ [1] = { what = "unchanged" }, -- upright
+ [2] = { what = "upright", it = "tf", bi = "bf" }, -- upright
+ [3] = { what = "italic", tf = "it", bf = "bi" }, -- italic
+}
+
+local usedremap = { }
+
+local function resolver(map)
+ return function (t,k)
+ local v =
+ map.digits [k] or
+ map.lcletters[k] or map.ucletters[k] or
+ map.lcgreek [k] or map.ucgreek [k] or
+ map.symbols [k] or k
+ t[k] = v
+ return v
+ end
+end
+
+for k, v in next, mathremap do
+ local t = { }
+ setmetatableindex(t,resolver(v))
+ usedremap[k] = t
+end
+
+local function remapgreek(mathalphabet,how,detail,char)
+ local r = mathremap[mathalphabet] -- what if 0
+ local alphabet = r and r.alphabet or "regular"
+ local style = r and r.style or "tf"
+ local remapping = greekremapping[how]
+ if trace_greek then
+ report_remapping("greek %s, %s char %C, alphabet %a %a, method %a","before",detail,char,alphabet,style,remapping.what)
+ end
+ local newstyle = remapping[style]
+ if newstyle then
+ local data = alphabets[alphabet][newstyle] -- always something
+ mathalphabet = data and data.attribute or mathalphabet
+ style = newstyle
+ end
+ if trace_greek then
+ report_remapping("greek %s, %s char %C, alphabet %a %a, method %a","after",detail,char,alphabet,style,remapping.what)
+ end
+ return mathalphabet, style
+end
+
+function mathematics.remapalphabets(char,mathalphabet,mathgreek)
+ if not mathalphabet then
+ return
+ end
+ if mathgreek and mathgreek > 0 then
+ if not isgreek[char] then
+ -- nothing needed
+ elseif islcgreek[char] then
+ local lc = (mathgreek >> 4) & 0x0F
+ if lc > 1 then
+ mathalphabet = remapgreek(mathalphabet,lc,"lowercase",char)
+ end
+ elseif isucgreek[char] then
+ local uc = (mathgreek >> 0) & 0x0F
+ if uc > 1 then
+ mathalphabet = remapgreek(mathalphabet,uc,"uppercase",char)
+ end
+ elseif issygreek[char] then
+ local sy = (mathgreek >> 8) & 0x0F
+ if sy > 1 then
+ mathalphabet = remapgreek(mathalphabet,sy,"symbol",char)
+ end
+ end
+ end
+ if mathalphabet > 0 then
+ local remap = usedremap[mathalphabet] -- redundant check
+ if remap then
+ local newchar = remap[char]
+ return newchar ~= char and newchar
+ end
+ end
+ -- return nil
+end
+
+-- begin of experiment
+
+local fallback = {
+ tf = "bf",
+ it = "bi",
+ bf = "tf",
+ bi = "it",
+}
+
+function mathematics.fallbackstyleattr(attribute)
+ local r = mathremap[attribute]
+ local alphabet = r.alphabet or "regular"
+ local style = r.style or "tf"
+ local fback = fallback[style]
+ if fback then
+ local data = alphabets[alphabet][fback]
+ if data then
+ local attr = data.attribute
+ return attribute ~= attr and attr
+ end
+ end
+end
+
+-- end of experiment
+
+local function checkedcopy(characters,child,parent)
+ for k, v in next, child do
+ if not characters[v] then
+ characters[v] = characters[parent[k]]
+ end
+ end
+end
+
+function mathematics.addfallbacks(main)
+ local characters = main.characters
+ checkedcopy(characters,regular.bf.ucgreek,regular.tf.ucgreek)
+ checkedcopy(characters,regular.bf.lcgreek,regular.tf.lcgreek)
+ checkedcopy(characters,regular.bi.ucgreek,regular.it.ucgreek)
+ checkedcopy(characters,regular.bi.lcgreek,regular.it.lcgreek)
+end
diff --git a/tex/context/base/mkxl/math-noa.lmt b/tex/context/base/mkxl/math-noa.lmt
index a4858363b..fd30db573 100644
--- a/tex/context/base/mkxl/math-noa.lmt
+++ b/tex/context/base/mkxl/math-noa.lmt
@@ -30,7 +30,6 @@ local formatters, gmatch = string.formatters, string.gmatch
local sortedhash = table.sortedhash
local insert, remove = table.insert, table.remove
local div, round = math.div, math.round
-local bor, band = bit32.bor, bit32.band
local fonts = fonts
local nodes = nodes
@@ -1320,7 +1319,7 @@ do
local last = 0
local known = setmetatableindex(function(t,k)
- local v = bor(0,2^last)
+ local v = 0 | 2^last
t[k] = v
last = last + 1
return v
@@ -1435,7 +1434,7 @@ do
else
local a = alternates[s] -- or known[s]
if a then
- attribute = bor(attribute,a)
+ attribute = attribute | a
end
end
end
@@ -1450,7 +1449,7 @@ do
end
end
if attribute > 0 and current and current > 0 then
- return bor(current,attribute)
+ return current | attribute
else
return attribute
end
@@ -1492,7 +1491,7 @@ do
local hashes = mathalternates.hashes
for i=1,#registered do
local r = registered[i]
- if band(a,r) ~= 0 then
+ if (a & r) ~= 0 then
local char = getchar(pointer)
local alt = hashes[i][char]
if alt == nil then
diff --git a/tex/context/base/mkxl/mlib-cnt.lmt b/tex/context/base/mkxl/mlib-cnt.lmt
index bddcb33b8..9d8a483ba 100644
--- a/tex/context/base/mkxl/mlib-cnt.lmt
+++ b/tex/context/base/mkxl/mlib-cnt.lmt
@@ -49,8 +49,6 @@ local next, type, tostring = next, type, tostring
local round, abs, min, max, floor = math.round, math.abs, math.min, math.max, math.floor
local concat, move = table.concat, table.move
-local bor = bit32.bor -- it's really time to ditch support for luajit
-
local starttiming = statistics.starttiming
local stoptiming = statistics.stoptiming
local resettiming = statistics.resettiming
@@ -421,7 +419,7 @@ function mp.lmt_contours_start()
for j=1,ny do
local f = fi[j]
if f >= minr and f <= maxr then
- di[j] = bor(di[j],bit)
+ di[j] = di[j] | bit
end
end
end
diff --git a/tex/context/base/mkxl/mlib-ctx.mkxl b/tex/context/base/mkxl/mlib-ctx.mkxl
index ac9e73c2e..384650a45 100644
--- a/tex/context/base/mkxl/mlib-ctx.mkxl
+++ b/tex/context/base/mkxl/mlib-ctx.mkxl
@@ -27,8 +27,8 @@
\registerctxluafile{mlib-int}{autosuffix}
\registerctxluafile{mlib-lmt}{autosuffix}
\registerctxluafile{mlib-pos}{autosuffix}
-\registerctxluafile{mlib-cnt}{autosuffix,optimize}
-\registerctxluafile{mlib-svg}{autosuffix,optimize}
+\registerctxluafile{mlib-cnt}{autosuffix}
+\registerctxluafile{mlib-svg}{autosuffix}
\unprotect
diff --git a/tex/context/base/mkxl/mlib-svg.lmt b/tex/context/base/mkxl/mlib-svg.lmt
index 1b2114ec9..3e6d68099 100644
--- a/tex/context/base/mkxl/mlib-svg.lmt
+++ b/tex/context/base/mkxl/mlib-svg.lmt
@@ -514,13 +514,11 @@ local colorcomponents, withcolor, thecolor, usedcolors do
local f_svggray = formatters['svggray(%.3N)']
local f_svgname = formatters['"%s"']
- local extract = bit32.extract
-
local triplets = setmetatableindex(function(t,k)
-- we delay building all these strings
local v = svgcolors[k]
if v then
- v = { extract(v,16,8)/255, extract(v,8,8)/255, extract(v,0,8)/255 }
+ v = { ((v>>16)&0xFF)/0xFF, ((v>>8)&0xFF)/0xFF, ((v>>0)&0xFF)/0xFF }
else
v = false
end
diff --git a/tex/context/base/mkxl/spac-ali.mkxl b/tex/context/base/mkxl/spac-ali.mkxl
index 1fdececfd..765dc428d 100644
--- a/tex/context/base/mkxl/spac-ali.mkxl
+++ b/tex/context/base/mkxl/spac-ali.mkxl
@@ -716,6 +716,8 @@
%defcsname\??aligncommand\v!nospacing \endcsname{\toksapp\t_spac_align_collected{\normalspacing\plusone}} % not yet
\defcsname\??aligncommand\v!hyphenated \endcsname{\toksapp\t_spac_align_collected{\dohyphens}}
\defcsname\??aligncommand\v!nothyphenated \endcsname{\toksapp\t_spac_align_collected{\nohyphens}}
+\defcsname\??aligncommand\v!collapsed \endcsname{\toksapp\t_spac_align_collected{\dohyphencollapsing}}
+\defcsname\??aligncommand\v!notcollapsed \endcsname{\toksapp\t_spac_align_collected{\nohyphencollapsing}}
\defcsname\??aligncommand\v!tolerant \endcsname{\toksapp\t_spac_align_collected{\spac_align_set_tolerant}}
\defcsname\??aligncommand\v!verytolerant \endcsname{\toksapp\t_spac_align_collected{\spac_align_set_very_tolerant}}
diff --git a/tex/context/base/mkxl/syst-aux.mkxl b/tex/context/base/mkxl/syst-aux.mkxl
index aa521130d..21b1a66ef 100644
--- a/tex/context/base/mkxl/syst-aux.mkxl
+++ b/tex/context/base/mkxl/syst-aux.mkxl
@@ -1069,7 +1069,7 @@
% \expandafterspaces\syst_helpers_process_comma_item#2#3\ignorearguments\ignorearguments\ignorearguments
% \popmacro\commalistcommand}
-\permanent\protected\def\processnextcommalist#1[#2#3]%
+\permanent\protected\def\processnextcommalist#1[#2#3]% watch out: mkiv has two extra initial arguments
{\pushmacro\commalistcommand
\def\commalistcommand{#1}%
\expandafterspaces\syst_helpers_process_comma_item#2#3\ignorearguments\ignorearguments\ignorearguments
diff --git a/tex/context/base/mkxl/toks-aux.lmt b/tex/context/base/mkxl/toks-aux.lmt
index 4f9ed7eb1..46d42dfdc 100644
--- a/tex/context/base/mkxl/toks-aux.lmt
+++ b/tex/context/base/mkxl/toks-aux.lmt
@@ -135,6 +135,8 @@ local hyphenationcodes = { }
local frozenparcodes = { }
local flagcodes = { }
local normalizecodes = { }
+-- local parcontextcodes = { }
+-- local parbegincodes = { }
for k, v in next, tex.getgroupvalues() do groupcodes[k] = gsub(v,"[_ ]","") end
for k, v in next, tex.gethyphenationvalues() do hyphenationcodes[k] = gsub(v,"[_ ]","") end
@@ -143,6 +145,8 @@ for k, v in next, tex.getdiscoptionvalues() do discoptioncodes[k] = gsub(v,"[_
for k, v in next, tex.getfrozenparvalues() do frozenparcodes[k] = gsub(v,"[_ ]","") end
for k, v in next, tex.getflagvalues() do flagcodes[k] = gsub(v,"[_ ]","") end
for k, v in next, tex.getnormalizevalues() do normalizecodes[k] = gsub(v,"[_ ]","") end
+-- for k, v in next, tex.getparcontextvalues() do parcontextcodes[k] = gsub(v,"[_ ]","") end
+-- for k, v in next, tex.getparbeginvalues() do parbegincodes[k] = gsub(v,"[_ ]","") end
if environment.initex then
@@ -155,6 +159,8 @@ if environment.initex then
for k, v in next, frozenparcodes do texintegerdef("frozen" .. v .. "code", k,"immutable") end
for k, v in next, flagcodes do texintegerdef(v .. "flagcode", k,"immutable") end
for k, v in next, normalizecodes do texintegerdef(v .. "code", k,"immutable") end
+ -- for k, v in next, parcontextcodes do texintegerdef(v .. "parcontextcode", k,"immutable") end
+ -- for k, v in next, parbegincodes do texintegerdef(v .. "parbegincode", k,"immutable") end
end
@@ -165,6 +171,8 @@ hyphenationcodes = utilities.storage.allocate(table.swapped(hyphenationcodes
frozenparcodes = utilities.storage.allocate(table.swapped(frozenparcodes, frozenparcodes))
flagcodes = utilities.storage.allocate(table.swapped(flagcodes, flagcodes))
normalizecodes = utilities.storage.allocate(table.swapped(normalizecodes, normalizecodes))
+-- parcontextcodes = utilities.storage.allocate(table.swapped(parcontextcodes, parcontextcodes))
+-- parbegincodes = utilities.storage.allocate(table.swapped(parbegincodes, parbegincodes))
tex.groupcodes = groupcodes
tex.glyphoptioncodes = glyphoptioncodes
@@ -173,3 +181,5 @@ tex.hyphenationcodes = hyphenationcodes
tex.frozenparcodes = frozenparcodes
tex.flagcodes = flagcodes
tex.normalizecodes = normalizecodes
+-- tex.parcontextcodes = parcontextcodes
+-- tex.parbegincodes = parbegincodes
diff --git a/tex/context/base/mkxl/trac-vis.lmt b/tex/context/base/mkxl/trac-vis.lmt
index 0c3e0168c..72835165d 100644
--- a/tex/context/base/mkxl/trac-vis.lmt
+++ b/tex/context/base/mkxl/trac-vis.lmt
@@ -106,9 +106,6 @@ local stoptiming = statistics.stoptiming
local a_visual = attributes.private("visual")
local a_layer = attributes.private("viewerlayer")
-local band = bit32.band
-local bor = bit32.bor
-
local enableaction = nodes.tasks.enableaction
-- local trace_hbox
@@ -261,13 +258,13 @@ local function setvisual(n,a,what,list) -- this will become more efficient when
if not a or a == 0 or a == unsetvalue then
a = preset_makeup
else
- a = bor(a,preset_makeup)
+ a = a | preset_makeup
end
elseif n == "boxes" then
if not a or a == 0 or a == unsetvalue then
a = preset_boxes
else
- a = bor(a,preset_boxes)
+ a = a | preset_boxes
end
elseif n == "all" then
if what == false then
@@ -275,7 +272,7 @@ local function setvisual(n,a,what,list) -- this will become more efficient when
elseif not a or a == 0 or a == unsetvalue then
a = preset_all
else
- a = bor(a,preset_all)
+ a = a | preset_all
end
else
for s in gmatch(n,"[a-z]+") do
@@ -285,7 +282,7 @@ local function setvisual(n,a,what,list) -- this will become more efficient when
elseif not a or a == 0 or a == unsetvalue then
a = m
else
- a = bor(a,m)
+ a = a | m
end
end
end
@@ -1373,33 +1370,33 @@ do
else
goto list
end
- else -- dead slow:
+ else -- we need them to be booleans
-- cache[a]()
- trace_hbox = band(a,0x0000001) ~= 0
- trace_vbox = band(a,0x0000002) ~= 0
- trace_vtop = band(a,0x0000004) ~= 0
- trace_kern = band(a,0x0000008) ~= 0
- trace_glue = band(a,0x0000010) ~= 0
- trace_penalty = band(a,0x0000020) ~= 0
- trace_fontkern = band(a,0x0000040) ~= 0
- trace_strut = band(a,0x0000080) ~= 0
- trace_whatsit = band(a,0x0000100) ~= 0
- trace_glyph = band(a,0x0000200) ~= 0
- trace_simple = band(a,0x0000400) ~= 0
- trace_user = band(a,0x0000800) ~= 0
- trace_math = band(a,0x0001000) ~= 0
- trace_italic = band(a,0x0002000) ~= 0
- trace_origin = band(a,0x0004000) ~= 0
- trace_discretionary = band(a,0x0008000) ~= 0
- trace_expansion = band(a,0x0010000) ~= 0
- trace_line = band(a,0x0020000) ~= 0
- trace_space = band(a,0x0040000) ~= 0
- trace_depth = band(a,0x0080000) ~= 0
- trace_marginkern = band(a,0x0100000) ~= 0
- trace_mathlistkern = band(a,0x0200000) ~= 0
- trace_dir = band(a,0x0400000) ~= 0
- trace_par = band(a,0x0800000) ~= 0
- trace_math_glue = band(a,0x1000000) ~= 0
+ trace_hbox = a & 0x0000001 ~= 0
+ trace_vbox = a & 0x0000002 ~= 0
+ trace_vtop = a & 0x0000004 ~= 0
+ trace_kern = a & 0x0000008 ~= 0
+ trace_glue = a & 0x0000010 ~= 0
+ trace_penalty = a & 0x0000020 ~= 0
+ trace_fontkern = a & 0x0000040 ~= 0
+ trace_strut = a & 0x0000080 ~= 0
+ trace_whatsit = a & 0x0000100 ~= 0
+ trace_glyph = a & 0x0000200 ~= 0
+ trace_simple = a & 0x0000400 ~= 0
+ trace_user = a & 0x0000800 ~= 0
+ trace_math = a & 0x0001000 ~= 0
+ trace_italic = a & 0x0002000 ~= 0
+ trace_origin = a & 0x0004000 ~= 0
+ trace_discretionary = a & 0x0008000 ~= 0
+ trace_expansion = a & 0x0010000 ~= 0
+ trace_line = a & 0x0020000 ~= 0
+ trace_space = a & 0x0040000 ~= 0
+ trace_depth = a & 0x0080000 ~= 0
+ trace_marginkern = a & 0x0100000 ~= 0
+ trace_mathlistkern = a & 0x0200000 ~= 0
+ trace_dir = a & 0x0400000 ~= 0
+ trace_par = a & 0x0800000 ~= 0
+ trace_math_glue = a & 0x1000000 ~= 0
end
elseif a == unsetvalue then
goto list
diff --git a/tex/context/base/mkxl/trac-vis.mkxl b/tex/context/base/mkxl/trac-vis.mkxl
index dd69e0bb8..38ab7ca3d 100644
--- a/tex/context/base/mkxl/trac-vis.mkxl
+++ b/tex/context/base/mkxl/trac-vis.mkxl
@@ -32,7 +32,7 @@
\writestatus{loading}{ConTeXt Tracing Macros / Visualization}
-\registerctxluafile{trac-vis}{autosuffix,optimize}
+\registerctxluafile{trac-vis}{autosuffix}
\unprotect
diff --git a/tex/context/base/mkxl/typo-cap.mkxl b/tex/context/base/mkxl/typo-cap.mkxl
index bab69e130..53b68dcb8 100644
--- a/tex/context/base/mkxl/typo-cap.mkxl
+++ b/tex/context/base/mkxl/typo-cap.mkxl
@@ -18,7 +18,6 @@
%D Maybe we need a more clever system: either command or style mode etc. so
%D that we can avoid the grouped mess in a simple style switch.
-% \registerctxluafile{typo-cap}{autosuffix,optimize}
\registerctxluafile{typo-cap}{autosuffix}
% \definesystemattribute[case][public] % already predefined
diff --git a/tex/context/base/mkxl/typo-dir.lmt b/tex/context/base/mkxl/typo-dir.lmt
new file mode 100644
index 000000000..7e1d6e29c
--- /dev/null
+++ b/tex/context/base/mkxl/typo-dir.lmt
@@ -0,0 +1,212 @@
+if not modules then modules = { } end modules ['typo-dir'] = {
+ version = 1.001,
+ comment = "companion to typo-dir.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- When we started with this, there were some issues in luatex so we needed to take care of
+-- intereferences. Some has been improved but we stil might end up with each node having a
+-- dir property. Now, the biggest problem is that there is an official bidi algorithm but
+-- some searching on the web shows that there are many confusing aspects and therefore
+-- proposals circulate about (sometimes imcompatible ?) improvements. In the end it all boils
+-- down to the lack of willingness to tag an input source. Of course tagging of each number
+-- and fenced strip is somewhat over the top, but now it has to be captured in logic. Texies
+-- normally have no problem with tagging but we need to handle any input. So, what we have
+-- done here (over the years) is starting from what we expect to see happen, especially with
+-- respect to punctation, numbers and fences. Eventually alternative algorithms will be provides
+-- so that users can choose (the reason why suggestion sfor improvements circulate on the web
+-- is that it is non trivial to predict the expected behaviour so one hopes that the ditor
+-- and the rest of the machinery match somehow. Anyway, the fun of tex is that it has no hard
+-- coded behavior. And ... we also want to have more debugging and extras and ... so we want
+-- a flexible approach. In the end we will have:
+--
+-- = full tagging (mechanism turned off)
+-- = half tagging (the current implementation)
+-- = unicode version x interpretation (several depending on the evolution)
+
+local next, type = next, type
+local format, insert, sub, find, match = string.format, table.insert, string.sub, string.find, string.match
+
+local nodes, node = nodes, node
+
+local trace_textdirections = false trackers.register("typesetters.directions.text", function(v) trace_textdirections = v end)
+local trace_mathdirections = false trackers.register("typesetters.directions.math", function(v) trace_mathdirections = v end)
+local trace_directions = false trackers.register("typesetters.directions", function(v) trace_textdirections = v trace_mathdirections = v end)
+
+local one_too = false directives.register("typesetters.directions.onetoo", function(v) one_too = v end)
+
+local report_textdirections = logs.reporter("typesetting","text directions")
+----- report_mathdirections = logs.reporter("typesetting","math directions")
+
+local texsetattribute = tex.setattribute
+local unsetvalue = attributes.unsetvalue
+
+local nuts = nodes.nuts
+local getnext = nuts.getnext
+local getattr = nuts.getattr
+
+local enableaction = nodes.tasks.enableaction
+local tracers = nodes.tracers
+local setcolor = tracers.colors.set
+local resetcolor = tracers.colors.reset
+
+local implement = interfaces.implement
+
+local directions = typesetters.directions or { }
+typesetters.directions = directions
+
+local a_directions = attributes.private('directions')
+
+local variables = interfaces.variables
+local v_global = variables["global"]
+local v_local = variables["local"]
+local v_on = variables.on
+local v_yes = variables.yes
+
+local m_enabled = 0x00000040 -- 2^6 64
+local m_global = 0x00000080 -- 2^7
+local m_fences = 0x00000100 -- 2^8
+
+local handlers = { }
+local methods = { }
+local lastmethod = 0
+
+local function installhandler(name,handler)
+ local method = methods[name]
+ if not method then
+ lastmethod = lastmethod + 1
+ method = lastmethod
+ methods[name] = method
+ end
+ handlers[method] = handler
+ return method
+end
+
+directions.handlers = handlers
+directions.installhandler = installhandler
+
+local function tomode(specification)
+ local scope = specification.scope
+ local mode
+ if scope == v_global or scope == v_on then
+ mode = m_enabled + m_global
+ elseif scope == v_local then
+ mode = m_enabled
+ else
+ return 0
+ end
+ local method = methods[specification.method]
+ if method then
+ mode = mode + method
+ else
+ return 0
+ end
+ if specification.fences == v_yes then
+ mode = mode + m_fences
+ end
+ return mode
+end
+
+local function getglobal(a)
+ return a and a > 0 and (a & m_global) ~= 0
+end
+
+local function getfences(a)
+ return a and a > 0 and (a & m_fences) ~= 0
+end
+
+local function getmethod(a)
+ return a and a > 0 and a % m_enabled or 0
+end
+
+directions.tomode = tomode
+directions.getglobal = getglobal
+directions.getfences = getfences
+directions.getmethod = getmethod
+directions.installhandler = installhandler
+
+-- beware: in dha we have character properties and in dua|b we have direction properties
+
+function directions.setcolor(current,direction,reversed,mirror)
+ if mirror then
+ setcolor(current,"bidi:mirrored")
+ elseif direction == "l" then
+ setcolor(current,reversed and "bidi:left:reversed" or "bidi:left:original")
+ elseif direction == "r" then
+ setcolor(current,reversed and "bidi:right:reversed" or "bidi:right:original")
+ else
+ resetcolor(current)
+ end
+end
+
+implement {
+ name = "getbidimode",
+ actions = { tomode, context },
+ arguments = {
+ {
+ { "scope" },
+ { "method" },
+ { "fences" },
+ }
+ }
+}
+
+local enabled = false
+
+local starttiming = statistics.starttiming
+local stoptiming = statistics.stoptiming
+
+-- If we have hbox{!} then the hbox determines the direction but we can consider
+-- a fast analysis, not that it matters much because there's nothing to swap in
+-- the list unless one glyphs becomes multiple (can that really happen?).
+--
+-- \enabledirectives[typesetters.directions.onetoo]
+
+function directions.handler(head,where,_,_,direction)
+ local only_one = not getnext(head)
+ if only_one and not one_too then
+ return head
+ end
+ local attr = getattr(head,a_directions)
+ if not attr or attr == 0 then
+ return head
+ end
+ local method = getmethod(attr)
+ local handler = handlers[method]
+ if not handler then
+ return head
+ end
+ starttiming(directions)
+ head = handler(head,direction,only_one,where)
+ stoptiming(directions)
+ return head
+end
+
+statistics.register("text directions", function()
+ if enabled then
+ return statistics.elapsedseconds(directions)
+ end
+end)
+
+function directions.set(n) -- todo: names and numbers
+ if not enabled then
+ if trace_textdirections then
+ report_textdirections("enabling directions handler")
+ end
+ enableaction("processors","typesetters.directions.handler")
+ enabled = true
+ end
+ if not n or n == 0 then
+ n = unsetvalue
+ -- maybe tracing
+ end
+ texsetattribute(a_directions,n)
+end
+
+implement {
+ name = "setdirection",
+ arguments = "integer",
+ actions = directions.set
+}
diff --git a/tex/context/base/mkxl/typo-dir.mkxl b/tex/context/base/mkxl/typo-dir.mkxl
index 8439ed342..328b157ef 100644
--- a/tex/context/base/mkxl/typo-dir.mkxl
+++ b/tex/context/base/mkxl/typo-dir.mkxl
@@ -18,7 +18,7 @@
\unprotect
-\registerctxluafile{typo-dir}{optimize}
+\registerctxluafile{typo-dir}{autosuffix}
\registerctxluafile{typo-dha}{}
%registerctxluafile{typo-dua}{}
%registerctxluafile{typo-dub}{}
diff --git a/tex/context/base/mkxl/util-fil.lmt b/tex/context/base/mkxl/util-fil.lmt
new file mode 100644
index 000000000..a3631d043
--- /dev/null
+++ b/tex/context/base/mkxl/util-fil.lmt
@@ -0,0 +1,163 @@
+if not modules then modules = { } end modules ['util-fil'] = {
+ version = 1.001,
+ optimize = true,
+ comment = "companion to luat-lib.mkxl",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- For the old ones, see util-fil.lua.
+
+local byte = string.byte
+local char = string.char
+
+utilities = utilities or { }
+local files = { }
+utilities.files = files
+
+local zerobased = { }
+
+function files.open(filename,zb)
+ local f = io.open(filename,"rb")
+ if f then
+ zerobased[f] = zb or false
+ end
+ return f
+end
+
+function files.close(f)
+ zerobased[f] = nil
+ f:close()
+end
+
+function files.size(f)
+ local current = f:seek()
+ local size = f:seek("end")
+ f:seek("set",current)
+ return size
+end
+
+files.getsize = files.size
+
+function files.setposition(f,n)
+ if zerobased[f] then
+ f:seek("set",n)
+ else
+ f:seek("set",n - 1)
+ end
+end
+
+function files.getposition(f)
+ if zerobased[f] then
+ return f:seek()
+ else
+ return f:seek() + 1
+ end
+end
+
+function files.look(f,n,chars)
+ local p = f:seek()
+ local s = f:read(n)
+ f:seek("set",p)
+ if chars then
+ return s
+ else
+ return byte(s,1,#s)
+ end
+end
+
+function files.skip(f,n)
+ if n == 1 then
+ f:read(n)
+ else
+ f:seek("set",f:seek()+n)
+ end
+end
+
+-- readers:
+
+files.readcardinal1 = fio.readcardinal1
+files.readcardinal2 = fio.readcardinal2
+files.readcardinal3 = fio.readcardinal3
+files.readcardinal4 = fio.readcardinal4
+
+files.readcardinal1le = fio.readcardinal1le or files.readcardinal1le
+files.readcardinal2le = fio.readcardinal2le or files.readcardinal2le
+files.readcardinal3le = fio.readcardinal3le or files.readcardinal3le
+files.readcardinal4le = fio.readcardinal4le or files.readcardinal4le
+
+files.readinteger1 = fio.readinteger1
+files.readinteger2 = fio.readinteger2
+files.readinteger3 = fio.readinteger3
+files.readinteger4 = fio.readinteger4
+
+files.readinteger1le = fio.readinteger1le or files.readinteger1le
+files.readinteger2le = fio.readinteger2le or files.readinteger2le
+files.readinteger3le = fio.readinteger3le or files.readinteger3le
+files.readinteger4le = fio.readinteger4le or files.readinteger4le
+
+files.readfixed2 = fio.readfixed2
+files.readfixed4 = fio.readfixed4
+files.read2dot14 = fio.read2dot14
+files.setposition = fio.setposition
+files.getposition = fio.getposition
+
+files.readbyte = files.readcardinal1
+files.readsignedbyte = files.readinteger1
+files.readcardinal = files.readcardinal1
+files.readinteger = files.readinteger1
+
+local skipposition = fio.skipposition
+files.skipposition = skipposition
+
+files.readbytes = fio.readbytes
+files.readbytetable = fio.readbytetable
+files.readcardinaltable = fio.readcardinaltable
+files.readintegertable = fio.readintegertable
+
+function files.readchar(f)
+ return f:read(1)
+end
+
+function files.readstring(f,n)
+ return f:read(n or 1)
+end
+
+function files.skipshort(f,n)
+ skipposition(f,2*(n or 1))
+end
+
+function files.skiplong(f,n)
+ skipposition(f,4*(n or 1))
+end
+
+-- writers
+
+function files.writestring(f,s)
+ f:write(char(byte(s,1,#s)))
+end
+
+function files.writebyte(f,b)
+ f:write(char(b))
+end
+
+files.writecardinal1 = fio.writecardinal1
+files.writecardinal2 = fio.writecardinal2
+files.writecardinal3 = fio.writecardinal3
+files.writecardinal4 = fio.writecardinal4
+
+files.writecardinal1le = fio.writecardinal1le
+files.writecardinal2le = fio.writecardinal2le
+files.writecardinal3le = fio.writecardinal3le
+files.writecardinal4le = fio.writecardinal4le
+
+files.writeinteger1 = fio.writeinteger1 or fio.writecardinal1
+files.writeinteger2 = fio.writeinteger2 or fio.writecardinal2
+files.writeinteger3 = fio.writeinteger3 or fio.writecardinal3
+files.writeinteger4 = fio.writeinteger4 or fio.writecardinal4
+
+files.writeinteger1le = files.writeinteger1le or fio.writecardinal1le
+files.writeinteger2le = files.writeinteger2le or fio.writecardinal2le
+files.writeinteger3le = files.writeinteger3le or fio.writecardinal3le
+files.writeinteger4le = files.writeinteger4le or fio.writecardinal4le
diff --git a/tex/context/base/mkxl/util-sac.lmt b/tex/context/base/mkxl/util-sac.lmt
new file mode 100644
index 000000000..60ecb0e33
--- /dev/null
+++ b/tex/context/base/mkxl/util-sac.lmt
@@ -0,0 +1,285 @@
+if not modules then modules = { } end modules ['util-sac'] = {
+ version = 1.001,
+ optimize = true,
+ comment = "companion to luat-lib.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+
+local byte, sub = string.byte, string.sub
+local tonumber = tonumber
+
+utilities = utilities or { }
+local streams = { }
+utilities.streams = streams
+
+function streams.open(filename,zerobased)
+ local f = filename and io.loaddata(filename)
+ if f then
+ return { f, 1, #f, zerobased or false }
+ end
+end
+
+function streams.openstring(f,zerobased)
+ if f then
+ return { f, 1, #f, zerobased or false }
+ end
+end
+
+function streams.getstring(f)
+ if f then
+ return f[1]
+ end
+end
+
+function streams.close()
+ -- dummy
+end
+
+function streams.size(f)
+ return f and f[3] or 0
+end
+
+streams.getsize = streams.size
+
+function streams.setposition(f,i)
+ if f[4] then
+ -- zerobased
+ if i <= 0 then
+ f[2] = 1
+ else
+ f[2] = i + 1
+ end
+ else
+ if i <= 1 then
+ f[2] = 1
+ else
+ f[2] = i
+ end
+ end
+end
+
+function streams.getposition(f)
+ if f[4] then
+ -- zerobased
+ return f[2] - 1
+ else
+ return f[2]
+ end
+end
+
+function streams.look(f,n,chars)
+ local b = f[2]
+ local e = b + n - 1
+ if chars then
+ return sub(f[1],b,e)
+ else
+ return byte(f[1],b,e)
+ end
+end
+
+function streams.skip(f,n)
+ f[2] = f[2] + n
+end
+
+--
+
+function streams.readbyte(f)
+ local i = f[2]
+ f[2] = i + 1
+ return byte(f[1],i)
+end
+
+function streams.readbytes(f,n)
+ local i = f[2]
+ local j = i + n
+ f[2] = j
+ return byte(f[1],i,j-1)
+end
+
+function streams.readbytetable(f,n)
+ local i = f[2]
+ local j = i + n
+ f[2] = j
+ return { byte(f[1],i,j-1) }
+end
+
+function streams.skipbytes(f,n)
+ f[2] = f[2] + n
+end
+
+function streams.readchar(f)
+ local i = f[2]
+ f[2] = i + 1
+ return sub(f[1],i,i)
+end
+
+function streams.readstring(f,n)
+ local i = f[2]
+ local j = i + n
+ f[2] = j
+ return sub(f[1],i,j-1)
+end
+
+function streams.skipshort(f,n) f[2] = f[2] + 2*(n or 1) end
+function streams.skiplong (f,n) f[2] = f[2] + 4*(n or 1) end
+
+local readcardinal1 = sio.readcardinal1
+local readcardinal2 = sio.readcardinal2
+local readcardinal3 = sio.readcardinal3
+local readcardinal4 = sio.readcardinal4
+
+function streams.readcardinal1(f) local i = f[2] f[2] = i + 1 return readcardinal1(f[1],i) end
+function streams.readcardinal2(f) local i = f[2] f[2] = i + 2 return readcardinal2(f[1],i) end
+function streams.readcardinal3(f) local i = f[2] f[2] = i + 3 return readcardinal3(f[1],i) end
+function streams.readcardinal4(f) local i = f[2] f[2] = i + 4 return readcardinal4(f[1],i) end
+
+local readcardinal1le = sio.readcardinal1le
+local readcardinal2le = sio.readcardinal2le
+local readcardinal3le = sio.readcardinal3le
+local readcardinal4le = sio.readcardinal4le
+
+function streams.readcardinal1le(f) local i = f[2] f[2] = i + 1 return readcardinal1le(f[1],i) end
+function streams.readcardinal2le(f) local i = f[2] f[2] = i + 2 return readcardinal2le(f[1],i) end
+function streams.readcardinal3le(f) local i = f[2] f[2] = i + 3 return readcardinal3le(f[1],i) end
+function streams.readcardinal4le(f) local i = f[2] f[2] = i + 4 return readcardinal4le(f[1],i) end
+
+local readinteger1 = sio.readinteger1
+local readinteger2 = sio.readinteger2
+local readinteger3 = sio.readinteger3
+local readinteger4 = sio.readinteger4
+
+function streams.readinteger1(f) local i = f[2] f[2] = i + 1 return readinteger1(f[1],i) end
+function streams.readinteger2(f) local i = f[2] f[2] = i + 2 return readinteger2(f[1],i) end
+function streams.readinteger3(f) local i = f[2] f[2] = i + 3 return readinteger3(f[1],i) end
+function streams.readinteger4(f) local i = f[2] f[2] = i + 4 return readinteger4(f[1],i) end
+
+local readinteger1le = sio.readinteger1le
+local readinteger2le = sio.readinteger2le
+local readinteger3le = sio.readinteger3le
+local readinteger4le = sio.readinteger4le
+
+function streams.readinteger1le(f) local i = f[2] f[2] = i + 1 return readinteger1le(f[1],i) end
+function streams.readinteger2le(f) local i = f[2] f[2] = i + 2 return readinteger2le(f[1],i) end
+function streams.readinteger3le(f) local i = f[2] f[2] = i + 3 return readinteger3le(f[1],i) end
+function streams.readinteger4le(f) local i = f[2] f[2] = i + 4 return readinteger4le(f[1],i) end
+
+local readfixed2 = sio.readfixed2
+local readfixed4 = sio.readfixed4
+local read2dot14 = sio.read2dot14
+
+function streams.readfixed2(f) local i = f[2] f[2] = i + 2 return readfixed2(f[1],i) end
+function streams.readfixed4(f) local i = f[2] f[2] = i + 4 return readfixed4(f[1],i) end
+function streams.read2dot14(f) local i = f[2] f[2] = i + 2 return read2dot14(f[1],i) end
+
+local readbytes = sio.readbytes
+local readbytetable = sio.readbytetable
+
+function streams.readbytes(f,n)
+ local i = f[2]
+ local s = f[3]
+ local p = i + n
+ if p > s then
+ f[2] = s + 1
+ else
+ f[2] = p
+ end
+ return readbytes(f[1],i,n)
+end
+
+function streams.readbytetable(f,n)
+ local i = f[2]
+ local s = f[3]
+ local p = i + n
+ if p > s then
+ f[2] = s + 1
+ else
+ f[2] = p
+ end
+ return readbytetable(f[1],i,n)
+end
+
+streams.readbyte = streams.readcardinal1
+streams.readsignedbyte = streams.readinteger1
+streams.readcardinal = streams.readcardinal1
+streams.readinteger = streams.readinteger1
+
+local readcardinaltable = sio.readcardinaltable
+local readintegertable = sio.readintegertable
+
+function utilities.streams.readcardinaltable(f,n,b)
+ local i = f[2]
+ local s = f[3]
+ local p = i + n * b
+ if p > s then
+ f[2] = s + 1
+ else
+ f[2] = p
+ end
+ return readcardinaltable(f[1],i,n,b)
+end
+
+function utilities.streams.readintegertable(f,n,b)
+ local i = f[2]
+ local s = f[3]
+ local p = i + n * b
+ if p > s then
+ f[2] = s + 1
+ else
+ f[2] = p
+ end
+ return readintegertable(f[1],i,n,b)
+end
+
+-- For practical reasons we put this here. It's less efficient but ok when we don't
+-- have much access.
+
+local files = utilities.files
+
+if files then
+
+ local openfile = files.open
+ local openstream = streams.open
+ local openstring = streams.openstring
+
+ local setmetatable = setmetatable
+
+ function io.newreader(str,method)
+ local f, m
+ if method == "string" then
+ f = openstring(str)
+ m = streams
+ elseif method == "stream" then
+ f = openstream(str)
+ m = streams
+ else
+ f = openfile(str,"rb")
+ m = files
+ end
+ if f then
+ local t = { }
+ setmetatable(t, {
+ __index = function(t,k)
+ local r = m[k]
+ if k == "close" then
+ if f then
+ m.close(f)
+ f = nil
+ end
+ return function() end
+ elseif r then
+ local v = function(_,a,b) return r(f,a,b) end
+ t[k] = v
+ return v
+ else
+ print("unknown key",k)
+ end
+ end
+ } )
+ return t
+ end
+ end
+
+end
diff --git a/tex/context/interface/mkii/keys-cs.xml b/tex/context/interface/mkii/keys-cs.xml
index eee6b834e..f13345e04 100644
--- a/tex/context/interface/mkii/keys-cs.xml
+++ b/tex/context/interface/mkii/keys-cs.xml
@@ -144,6 +144,7 @@
<cd:variable name='chemistry' value='chemistry'/>
<cd:variable name='cite' value='cite'/>
<cd:variable name='closed' value='closed'/>
+ <cd:variable name='collapsed' value='collapsed'/>
<cd:variable name='color' value='barevne'/>
<cd:variable name='column' value='column'/>
<cd:variable name='columns' value='sloupce'/>
@@ -395,6 +396,7 @@
<cd:variable name='nostopper' value='nostopper'/>
<cd:variable name='not' value='ne'/>
<cd:variable name='notation' value='notation'/>
+ <cd:variable name='notcollapsed' value='notcollapsed'/>
<cd:variable name='note' value='note'/>
<cd:variable name='nothanging' value='nothanging'/>
<cd:variable name='nothyphenated' value='nothyphenated'/>
diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua
index 7a2804026..386529b1a 100644
--- a/tex/generic/context/luatex/luatex-fonts-merged.lua
+++ b/tex/generic/context/luatex/luatex-fonts-merged.lua
@@ -1,6 +1,6 @@
-- merged file : c:/data/develop/context/sources/luatex-fonts-merged.lua
-- parent file : c:/data/develop/context/sources/luatex-fonts.lua
--- merge date : 2021-05-06 23:31
+-- merge date : 2021-05-09 17:12
do -- begin closure to overcome local limits and interference