From 7ab18e79ca56e0a86098536f4800fce0a75136d9 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Sat, 13 Mar 2021 11:41:41 +0100 Subject: 2021-03-13 11:21:00 --- tex/context/base/mkii/cont-new.mkii | 2 +- tex/context/base/mkii/context.mkii | 2 +- tex/context/base/mkii/mult-en.mkii | 3 + tex/context/base/mkiv/cont-new.mkiv | 2 +- tex/context/base/mkiv/context.mkiv | 2 +- tex/context/base/mkiv/file-job.lua | 5 +- tex/context/base/mkiv/node-scn.lua | 12 +- tex/context/base/mkiv/status-files.pdf | Bin 25372 -> 25397 bytes tex/context/base/mkiv/status-lua.pdf | Bin 257053 -> 257164 bytes tex/context/base/mkxl/cont-new.mkxl | 2 +- tex/context/base/mkxl/context.mkxl | 2 +- tex/context/base/mkxl/file-job.lmt | 7 +- tex/context/base/mkxl/libs-imp-foreign.lmt | 119 ++++++++++++ tex/context/base/mkxl/libs-imp-foreign.mkxl | 204 +++++++++++++++++++++ tex/context/base/mkxl/lpdf-ini.lmt | 4 +- tex/context/base/mkxl/lpdf-lmt.lmt | 4 +- tex/context/base/mkxl/node-scn.lmt | 12 +- tex/context/interface/mkii/keys-en.xml | 3 + tex/generic/context/luatex/luatex-fonts-merged.lua | 2 +- 19 files changed, 363 insertions(+), 24 deletions(-) create mode 100644 tex/context/base/mkxl/libs-imp-foreign.lmt create mode 100644 tex/context/base/mkxl/libs-imp-foreign.mkxl diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index 0b809b68c..1b3a16837 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.03.09 11:39} +\newcontextversion{2021.03.13 11:18} %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 5e34a6801..a35156dc5 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.03.09 11:39} +\edef\contextversion{2021.03.13 11:18} %D For those who want to use this: diff --git a/tex/context/base/mkii/mult-en.mkii b/tex/context/base/mkii/mult-en.mkii index d3a073db3..df67038c3 100644 --- a/tex/context/base/mkii/mult-en.mkii +++ b/tex/context/base/mkii/mult-en.mkii @@ -774,6 +774,8 @@ \setinterfaceconstant{deepnumbercommand}{deepnumbercommand} \setinterfaceconstant{deeptextcommand}{deeptextcommand} \setinterfaceconstant{default}{default} +\setinterfaceconstant{defaultheight}{defaultheight} +\setinterfaceconstant{defaultwidth}{defaultwidth} \setinterfaceconstant{define}{define} \setinterfaceconstant{delay}{delay} \setinterfaceconstant{depth}{depth} @@ -1118,6 +1120,7 @@ \setinterfaceconstant{print}{print} \setinterfaceconstant{printable}{printable} \setinterfaceconstant{process}{process} +\setinterfaceconstant{processors}{processors} \setinterfaceconstant{profile}{profile} \setinterfaceconstant{properties}{properties} \setinterfaceconstant{pubsep}{pubsep} diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index 8dc4e7f9d..000c25c18 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.03.09 11:39} +\newcontextversion{2021.03.13 11:18} %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 241224d7b..294a062f6 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.03.09 11:39} +\edef\contextversion{2021.03.13 11:18} %D Kind of special: diff --git a/tex/context/base/mkiv/file-job.lua b/tex/context/base/mkiv/file-job.lua index 97e223387..0d26cdfb2 100644 --- a/tex/context/base/mkiv/file-job.lua +++ b/tex/context/base/mkiv/file-job.lua @@ -49,6 +49,8 @@ local cleanpath = resolvers.cleanpath local toppath = resolvers.toppath local resolveprefix = resolvers.resolve +local currentfile = luatex.currentfile + local hasscheme = url.hasscheme local jobresolvers = resolvers.jobs @@ -791,7 +793,8 @@ end local function autoname(name) if name == "*" then - name = nameonly(toppath() or name) + -- name = nameonly(toppath() or name) + name = nameonly(currentfile() or name) end return name end diff --git a/tex/context/base/mkiv/node-scn.lua b/tex/context/base/mkiv/node-scn.lua index 0ec1ba387..3c1dd2d88 100644 --- a/tex/context/base/mkiv/node-scn.lua +++ b/tex/context/base/mkiv/node-scn.lua @@ -122,7 +122,9 @@ local function processwords(attribute,data,flush,head,parent,skip) -- we have hl local continue, leaders, done, strip, level = false, false, false, true, -1 while n do local id = getid(n) - if id == glyph_code or id == rule_code or (id == hlist_code and getattr(n,a_runningtext)) then + if id == glyph_code or id == rule_code or (id == hlist_code and getattr(n,a_runningtext)) +or id == disc_code or id == boundary_code + then local aa = getattr(n,attribute) if aa and aa ~= skip then if aa == a then @@ -164,10 +166,10 @@ local function processwords(attribute,data,flush,head,parent,skip) -- we have hl setlist(n,(processwords(attribute,data,flush,list,n,aa))) -- watch () end end - elseif id == disc_code or id == boundary_code then - if f then - l = n - end +-- elseif id == disc_code or id == boundary_code then +-- if f then +-- l = n +-- end elseif id == kern_code and getsubtype(n) == fontkern_code then if f then l = n diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf index 94c1fd1c6..012ebe91f 100644 Binary files a/tex/context/base/mkiv/status-files.pdf and b/tex/context/base/mkiv/status-files.pdf differ diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf index 40f9782ba..b0387df70 100644 Binary files a/tex/context/base/mkiv/status-lua.pdf and b/tex/context/base/mkiv/status-lua.pdf differ diff --git a/tex/context/base/mkxl/cont-new.mkxl b/tex/context/base/mkxl/cont-new.mkxl index 096e94210..61707dd62 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.03.09 11:39} +\newcontextversion{2021.03.13 11:18} %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 8c2be0abc..78ddcbd97 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.03.09 11:39} +\immutable\edef\contextversion{2021.03.13 11:18} %overloadmode 1 % check frozen / warning %overloadmode 2 % check frozen / error diff --git a/tex/context/base/mkxl/file-job.lmt b/tex/context/base/mkxl/file-job.lmt index 95ad48e82..50064622a 100644 --- a/tex/context/base/mkxl/file-job.lmt +++ b/tex/context/base/mkxl/file-job.lmt @@ -49,6 +49,8 @@ local cleanpath = resolvers.cleanpath local toppath = resolvers.toppath local resolveprefix = resolvers.resolve +local currentfile = luatex.currentfile + local hasscheme = url.hasscheme local jobresolvers = resolvers.jobs @@ -842,14 +844,15 @@ local function gotopreviouslevel(what) poptree() currenttype = remove(typestack) or v_text remove(stacks[what]) -- not currenttype ... weak recovery -context.endinput() -- does not work + context.endinput() -- context.signalendofinput(what) end local function autoname() local name = scan_delimited(91,93) or scan_delimited(0,32) -- [name] or name if name == "*" then - name = nameonly(toppath() or name) + -- name = nameonly(toppath() or name) + name = nameonly(currentfile() or name) end return name end diff --git a/tex/context/base/mkxl/libs-imp-foreign.lmt b/tex/context/base/mkxl/libs-imp-foreign.lmt new file mode 100644 index 000000000..7e4ec9239 --- /dev/null +++ b/tex/context/base/mkxl/libs-imp-foreign.lmt @@ -0,0 +1,119 @@ +if not modules then modules = { } end modules ['libs-imp-foreign'] = { + version = 1.001, + comment = "companion to luat-imp-foreign.mkxl", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +-- See libs-imp-foreign.mkxl for some comments. + +local report = logs.reporter("foreign") + +local libname = "foreign" +----- libfile = "libffi-7" +local libfile = "libffi*" +----- libfile = "d:/inkscape/bin/libffi-7.dll" -- libffi* + +local libforeign = resolvers.libraries.validoptional(libname) + +if package.loaded[libname] then + return package.loaded[libname] +end + +local function okay() + -- Don't worry, when one overloads this flag the engine will abort with an + -- error message anyway, but it's less nice. + if not status.permit_loadlib then + report() + report("opening foreign libraries is not enabled") + report() + os.exit() + elseif libforeign and resolvers.libraries.optionalloaded(libname,libfile) then + okay = function() return true end + else + okay = function() return false end + end + return okay() +end + +local foreignload = libforeign.load + +local foreign = { + types = libforeign.types, + abivalues = libforeign.abivalues, + totable = libforeign.totable, + load = function(name) + if okay() then + local fullname = resolvers.findlib(name) + if fullname and fullname ~= "" then + return foreignload(fullname) + else + -- report an error + end + end + end, +} + +-- In due time I'll add the struct and array methods using Lua 5.4 features. + +package .loaded[libname] = foreign +optional.loaded[libname] = foreign + +return foreign + +-- A simple test: + +-- \setupbodyfont[dejavu,10pt] +-- +-- \starttext +-- +-- \registerctxluafile{libs-imp-foreign}{autosuffix} +-- +-- \startluacode +-- +-- local foreign = optional.loaded.foreign +-- +-- local kplib = (os.platform == "win64" and "kpathsea*w64") +-- or (os.platform == "win32" and "kpathsea*w32") +-- or "libkpathsea" +-- +-- local kpse = foreign.load(kplib) +-- +-- local set_program_name = kpse.kpse_set_program_name +-- local find_file = kpse.kpse_find_file +-- +-- set_program_name:types { "string", "string" } +-- find_file :types { ret = "string", "string", "int", "int" } +-- +-- set_program_name("pdftex","pdftex") +-- +-- local function lookup(filename,filetype,n) +-- local c = os.clock() +-- for i=1,n do +-- if find_file(filename,filetype,0) then +-- -- okay +-- end +-- end +-- c = os.clock() - c +-- +-- local NC, BC, NR = context.NC, context.BC, context.NR +-- +-- context.starttabulate() +-- BC() context("asked") NC() context.type(filename) NC() NR() +-- BC() context("found") NC() context.type(find_file(filename,filetype,0)) NC() NR() +-- if n > 0 then +-- BC() context("times") NC() context(n) NC() NR() +-- BC() context("seconds") NC() context(" %0.3f",c) NC() NR() +-- BC() context("lookup") NC() context(" %0.6f",c/n) NC() NR() +-- end +-- context.stoptabulate() +-- end +-- +-- lookup("oeps.tex", 26,10000) +-- lookup("metafun.mp", 16, 5000) +-- lookup("logo10.afm", 4, 2500) +-- +-- \stopluacode +-- +-- \stoptext diff --git a/tex/context/base/mkxl/libs-imp-foreign.mkxl b/tex/context/base/mkxl/libs-imp-foreign.mkxl new file mode 100644 index 000000000..5c2663586 --- /dev/null +++ b/tex/context/base/mkxl/libs-imp-foreign.mkxl @@ -0,0 +1,204 @@ +% permitloadlib=true + +%D \module +%D [ file=libs-imp-foreign, +%D version=2021.03.10, +%D title=\CONTEXT\ Extra Modules, +%D subtitle=Basic FFI, +%D author=Hans Hagen, +%D date=\currentdate, +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] +%C +%C This module is part of the \CONTEXT\ macro||package and is +%C therefore copyrighted by \PRAGMA. See mreadme.pdf for +%C details. + +%D This module was added as a side track of a user wanting to run a library that is +%D not (has support) built in. In order to identify issues I wondered if we could +%D have an additional feature to the already present optional libraries (of course +%D with the usual loadlib protection. Keep in mind that loading libraries creates a +%D dependency and an api can change. And in a long term program like any \TEX\ +%D program we don't want that (at least I don't want users to be forced to install +%D lots of additional source code and dependencies in order to compile \LUAMETATEX\ +%D successfully. +%D +%D So, I looked around for alternatives to ffi and ran into the (stable since 5 +%D years) alien module (by Fabio Mascarenhas) that uses the rather portable libffi +%D but it does have some dependencies. For callbacks you need to set some parameters +%D normally dealt with when configuring and compiling which does creates a +%D dependency. So, in the end I just took its keyword driven approach but wrapped it +%D in alternative code that more matches other modules and assumes \LUA\ 5.4. +%D +%D Additional features like arrays and structs will be implemented when we need them +%D using modern \LUA\ 5.4 features (string packing, toclose, etc). For now I +%D consider all this an experiment and will pick up the thread when I have an +%D example. +%D +%D So, how far do we go? I think as soon as a library becomes more complex, say with +%D multi|-|dimensional arrays one should just write a proper interface. So we limit +%D ourselves here. One problem with more complex datastructures is that it opens the +%D door to abuse thanks to uncontrolled memory access. + +\registerctxluafile{libs-imp-foreign}{autosuffix} + +\continueifinputfile{libs-imp-foreign.mkxl} + +%D The difference in performance is not that significant because the time spent in +%D the called function is the bottleneck here. + +\usemodule[article-basic] \setupbodyfont[8pt] \noheaderandfooterlines + +\starttext + +\startluacode + + local NC, BC, NR = context.NC, context.BC, context.NR + + function document.identify(kpse,set_program_name,find_file) + context.starttabulate { "|l|lp|" } + BC() context.type("kpse") NC() context.typ(tostring(kpse)) NC() NR() + BC() context.type("set_program_name") NC() context.typ(tostring(set_program_name)) NC() NR() + BC() context.type("find_file") NC() context.typ(tostring(find_file)) NC() NR() + context.stoptabulate() + end + + function document.lookup(find_file,filename,filetype,present,n) + + local c = os.clock() + for i=1,n do + if find_file(filename,filetype,present) then + -- okay + end + end + c = os.clock() - c + + context.starttabulate() + BC() context("asked") NC() context.type(filename) NC() NR() + BC() context("found") NC() context.type(find_file(filename,filetype,present)) NC() NR() + if n > 0 then + BC() context("times") NC() context(n) NC() NR() + BC() context("seconds") NC() context(" %0.3f",c) NC() NR() + BC() context("lookup") NC() context(" %0.6f",c/n) NC() NR() + end + context.stoptabulate() + end +\stopluacode + +\starttitle[title=kpse via foreign] + +\startluacode + + local foreign = optional.loaded.foreign + + local kplib = (os.platform == "win64" and "kpathsea*w64") + or (os.platform == "win32" and "kpathsea*w32") + or "libkpathsea" + + local kpse = foreign.load(kplib) + + local set_program_name = kpse:register { + name = "kpse_set_program_name", + arguments = { "string", "string" } + } + + local find_file = kpse:register { + name = "kpse_find_file", + arguments = { "string", "int", "int" }, + result = "string", + } + local path_expand = kpse:register { + name = "kpse_path_expand", + arguments = { "string" }, + result = "string", + } + local all_path_search = kpse:register { + name = "kpse_all_path_search", + arguments = { "string", "string" }, + result = "pointer", + finalizer = function(p) + return foreign.totable(p,"string") -- unknown n, so NULL terminated + end + } + + -- print(kpse) + -- print(set_program_name) + -- print(kpse:registered("kpse_set_program_name")) + -- print(kpse:available("kpse_set_program_name")) + -- print(kpse:available("set_program_name")) + -- print(kpse:available("kpse_find_file")) + + -- inspect(kpse:registered ()) + -- inspect(foreign.types()) + -- inspect(foreign.abivalues()) + + local set_program_name = kpse:registered("kpse_set_program_name") + local find_file = kpse:registered("kpse_find_file") + + set_program_name("luatex","luatex") + + document.lookup(find_file, "libs-imp-foreign.mkxl", 26, 0, 100000) + document.lookup(find_file, "oeps.tex", 26, 0, 10000) + document.lookup(find_file, "metafun.mp", 16, 0, 5000) + document.lookup(find_file, "logo10.afm", 4, 0, 2500) + + document.identify(kpse, set_program_name, find_file) + + -- set_program_name("pdftex","pdftex") + -- + -- local t = path_expand("$TEXINPUTS") + -- local p = all_path_search(t,"oeps.tex") + -- + -- inspect(t) + -- inspect(p) + +\stopluacode + +\stoptitle + +\registerctxluafile{libs-imp-kpse}{autosuffix} + +\starttitle[title=kpse via optional / string] + +\startluacode + + local kpse = optional.loaded.kpse + + local set_program_name = kpse.set_program_name + local find_file = kpse.find_file + + kpse.set_program_name("luatex") + + document.lookup(find_file, "libs-imp-foreign.mkxl", "tex", false, 100000) + document.lookup(find_file, "oeps.tex", "tex", false, 10000) + document.lookup(find_file, "metafun.mp", "mp", false, 5000) + document.lookup(find_file, "logo10.afm", "afm", false, 2500) + + document.identify(kpse, set_program_name, find_file) + +\stopluacode + +\stoptitle + +\starttitle[title=kpse via optional / number] + +\startluacode + + local kpse = optional.loaded.kpse + + local set_program_name = kpse.set_program_name + local find_file = kpse.find_file + + kpse.set_program_name("luatex") + + document.lookup(find_file, "libs-imp-foreign.mkxl", 26, false, 100000) + document.lookup(find_file, "oeps.tex", 26, false, 10000) + document.lookup(find_file, "metafun.mp", 16, false, 5000) + document.lookup(find_file, "logo10.afm", 4, false, 2500) + + document.identify(kpse, set_program_name, find_file) + +\stopluacode + +\stoptitle + +\stoptext diff --git a/tex/context/base/mkxl/lpdf-ini.lmt b/tex/context/base/mkxl/lpdf-ini.lmt index 27625606a..ee9248bf7 100644 --- a/tex/context/base/mkxl/lpdf-ini.lmt +++ b/tex/context/base/mkxl/lpdf-ini.lmt @@ -1068,8 +1068,8 @@ do local luatexversion = format("%1.2f",LUATEXVERSION) local luatexfunctionality = tostring(LUATEXFUNCTIONALITY) metadata = { - producer = format("LuaTeX-%s",luatexversion), - creator = format("LuaTeX %s %s + ConTeXt LMTX %s",luatexversion,luatexfunctionality,contextversion), + producer = format("LuaMetaTeX-%s",luatexversion), + creator = format("LuaMetaTeX %s %s + ConTeXt LMTX %s",luatexversion,luatexfunctionality,contextversion), luatexversion = luatexversion, contextversion = contextversion, luatexfunctionality = luatexfunctionality, diff --git a/tex/context/base/mkxl/lpdf-lmt.lmt b/tex/context/base/mkxl/lpdf-lmt.lmt index 3c2db0247..14b51b3b1 100644 --- a/tex/context/base/mkxl/lpdf-lmt.lmt +++ b/tex/context/base/mkxl/lpdf-lmt.lmt @@ -2992,11 +2992,11 @@ do luatex.registerstopactions(function() if pdfname then local r = lpdf.lastreferredpage() -- somehow referenced - local t = lpdf.nofpages() -- in tuc file local s = lpdf.getnofpages() -- in page tree, saved in file + local t = lpdf.nofpages() -- in tuc file if r > s then report() - report("referred pages: %i, saved pages %i, pages from tuc file: %i, possible corrupt file",r,e,t) + report("referred pages: %i, saved pages %i, pages from tuc file: %i, possible corrupt file",r,s,t) report() end end diff --git a/tex/context/base/mkxl/node-scn.lmt b/tex/context/base/mkxl/node-scn.lmt index 0ec1ba387..3c1dd2d88 100644 --- a/tex/context/base/mkxl/node-scn.lmt +++ b/tex/context/base/mkxl/node-scn.lmt @@ -122,7 +122,9 @@ local function processwords(attribute,data,flush,head,parent,skip) -- we have hl local continue, leaders, done, strip, level = false, false, false, true, -1 while n do local id = getid(n) - if id == glyph_code or id == rule_code or (id == hlist_code and getattr(n,a_runningtext)) then + if id == glyph_code or id == rule_code or (id == hlist_code and getattr(n,a_runningtext)) +or id == disc_code or id == boundary_code + then local aa = getattr(n,attribute) if aa and aa ~= skip then if aa == a then @@ -164,10 +166,10 @@ local function processwords(attribute,data,flush,head,parent,skip) -- we have hl setlist(n,(processwords(attribute,data,flush,list,n,aa))) -- watch () end end - elseif id == disc_code or id == boundary_code then - if f then - l = n - end +-- elseif id == disc_code or id == boundary_code then +-- if f then +-- l = n +-- end elseif id == kern_code and getsubtype(n) == fontkern_code then if f then l = n diff --git a/tex/context/interface/mkii/keys-en.xml b/tex/context/interface/mkii/keys-en.xml index dc2cc49c3..6f225eef6 100644 --- a/tex/context/interface/mkii/keys-en.xml +++ b/tex/context/interface/mkii/keys-en.xml @@ -780,6 +780,8 @@ + + @@ -1124,6 +1126,7 @@ + diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 1928cabe4..f23926727 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-03-09 11:39 +-- merge date : 2021-03-13 11:18 do -- begin closure to overcome local limits and interference -- cgit v1.2.3