diff options
author | Hans Hagen <pragma@wxs.nl> | 2019-01-17 23:06:17 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2019-01-17 23:06:17 +0100 |
commit | 823bd4a7d8ff32c05807b02e650ecbd60b43e95d (patch) | |
tree | f6ac3760c1d5da04f8570587b76572cd4fb44ecd /tex | |
parent | 17527db3823d6123f4e462d13244430c40b78adb (diff) | |
download | context-823bd4a7d8ff32c05807b02e650ecbd60b43e95d.tar.gz |
2019-01-17 22:18:00
Diffstat (limited to 'tex')
28 files changed, 472 insertions, 995 deletions
diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index 1b9f858fc..30a77ed87 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{2019.01.07 16:10} +\newcontextversion{2019.01.17 22:10} %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 0aaf30a95..df046d115 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{2019.01.07 16:10} +\edef\contextversion{2019.01.17 22:10} %D For those who want to use this: diff --git a/tex/context/base/mkiv/cont-new.mkiv b/tex/context/base/mkiv/cont-new.mkiv index 8c55f9583..d09b56df9 100644 --- a/tex/context/base/mkiv/cont-new.mkiv +++ b/tex/context/base/mkiv/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2019.01.07 16:10} +\newcontextversion{2019.01.17 22:10} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/mkiv/cont-run.lua b/tex/context/base/mkiv/cont-run.lua index aed2178d8..c8030bf39 100644 --- a/tex/context/base/mkiv/cont-run.lua +++ b/tex/context/base/mkiv/cont-run.lua @@ -175,6 +175,8 @@ if sandboxing then traceback = traceback, } + package.loaded.debug = debug + elseif debugging then -- we keep debug @@ -187,15 +189,13 @@ else sethook = sethook, } -end + package.loaded.debug = debug -local function processjob() +end - environment.initializefilenames() -- todo: check if we really need to pre-prep the filename +local preparejob preparejob = function() -- tricky: we need a hook for this local arguments = environment.arguments - local suffix = environment.suffix - local filename = environment.filename -- hm, not inputfilename ! if arguments.lmtx or not status.obj_ptr then report("enabling lmtx mode") @@ -245,6 +245,24 @@ local function processjob() -- directives.enable("logs.errors",arguments.errors) -- end + preparejob = function() end + + job.prepare = preparejob + +end + +job.prepare = preparejob + +local function processjob() + + environment.initializefilenames() -- todo: check if we really need to pre-prep the filename + + local arguments = environment.arguments + local suffix = environment.suffix + local filename = environment.filename -- hm, not inputfilename ! + + preparejob() + if not filename or filename == "" then -- skip elseif suffix == "xml" or arguments.forcexml then @@ -308,7 +326,6 @@ local function processjob() -- \writestatus{system}{processing as tex} -- We have a regular tex file so no \starttext yet as we can -- load fonts. - -- context.enabletrackers { "resolvers.*" } context.input(filename) -- context.disabletrackers { "resolvers.*" } diff --git a/tex/context/base/mkiv/context.mkiv b/tex/context/base/mkiv/context.mkiv index 2ab2151b5..5d3401226 100644 --- a/tex/context/base/mkiv/context.mkiv +++ b/tex/context/base/mkiv/context.mkiv @@ -42,7 +42,7 @@ %D has to match \type {YYYY.MM.DD HH:MM} format. \edef\contextformat {\jobname} -\edef\contextversion{2019.01.07 16:10} +\edef\contextversion{2019.01.17 22:10} \edef\contextkind {beta} %D For those who want to use this: @@ -606,6 +606,14 @@ \ctxlua{statistics.stoptiming(statistics)}% \to \everyjob +% \appendtoks +% \ctxlua{job.prepare()}% +% \to \everyjob + +% \appendtoks +% \enabletrackers[*]% +% \to \everyjob + \appendtoks \ctxlua{statistics.savefmtstatus("\jobname","\contextversion","context.mkiv","\contextkind","\contextbanner")}% can become automatic \to \everydump diff --git a/tex/context/base/mkiv/data-zip.lua b/tex/context/base/mkiv/data-zip.lua index 32666bef2..6f20b4a9d 100644 --- a/tex/context/base/mkiv/data-zip.lua +++ b/tex/context/base/mkiv/data-zip.lua @@ -31,11 +31,11 @@ local resolvers = resolvers zip = zip or { } local zip = zip -zip.archives = zip.archives or { } -local archives = zip.archives +local archives = zip.archives or { } +zip.archives = archives -zip.registeredfiles = zip.registeredfiles or { } -local registeredfiles = zip.registeredfiles +local registeredfiles = zip.registeredfiles or { } +zip.registeredfiles = registeredfiles local function validzip(str) -- todo: use url splitter if not find(str,"^zip://") then @@ -108,7 +108,7 @@ function resolvers.finders.zip(specification) end local dfile = zfile:open(queryname) if dfile then - dfile = zfile:close() + dfile:close() if trace_locating then report_zip("finder: file %a found",queryname) end diff --git a/tex/context/base/mkiv/font-sol.lua b/tex/context/base/mkiv/font-sol.lua index 20472746c..9f892332f 100644 --- a/tex/context/base/mkiv/font-sol.lua +++ b/tex/context/base/mkiv/font-sol.lua @@ -351,7 +351,7 @@ function splitters.split(head) -- best also pass the direction local function flush() -- we can move this local font = getfont(start) local last = getnext(stop) - local list = last and copy_node_list(start,stop) or copy_node_list(start) + local list = last and copy_node_list(start,last) or copy_node_list(start) local n = #cache + 1 if encapsulate then local user_one = new_usernumber(splitter_one,n) diff --git a/tex/context/base/mkiv/lpdf-ini.lua b/tex/context/base/mkiv/lpdf-ini.lua index 09a4678a1..ddbfd6edb 100644 --- a/tex/context/base/mkiv/lpdf-ini.lua +++ b/tex/context/base/mkiv/lpdf-ini.lua @@ -521,6 +521,8 @@ do for k, v in next, t do if k == "__extra__" then e = v + elseif k == "__stream__" then + -- do nothing (yet) else n = n + 1 r[n] = k @@ -533,8 +535,9 @@ do local tv = type(v) -- mostly tables if tv == "table" then - local mv = getmetatable(v) - if mv and mv.__lpdftype then + -- local mv = getmetatable(v) + -- if mv and mv.__lpdftype then + if v.__lpdftype__ then -- if v == t then -- report_objects("ignoring circular reference in dirctionary") -- r[i] = f_key_null(k) @@ -582,9 +585,9 @@ do if tv == "number" then r[k] = f_tonumber(v) elseif tv == "table" then - local mv = getmetatable(v) - local mt = mv and mv.__lpdftype - if mt then + -- local mv = getmetatable(v) + -- if mv and mv.__lpdftype then + if v.__lpdftype__ then -- if v == t then -- report_objects("ignoring circular reference in array") -- r[k] = "null" @@ -707,20 +710,35 @@ end local function add_x(t,k,v) rawset(t,k,tostring(v)) end -local mt_x = { __lpdftype = "stream", __tostring = tostring_x, __call = value_x, __newindex = add_x } -local mt_d = { __lpdftype = "dictionary", __tostring = tostring_d, __call = value_d, __add = add_to_d } -local mt_a = { __lpdftype = "array", __tostring = tostring_a, __call = value_a, __add = add_to_a } -local mt_u = { __lpdftype = "unicode", __tostring = tostring_u, __call = value_u } -local mt_s = { __lpdftype = "string", __tostring = tostring_s, __call = value_s } -local mt_p = { __lpdftype = "docstring", __tostring = tostring_p, __call = value_p } -local mt_n = { __lpdftype = "number", __tostring = tostring_n, __call = value_n } -local mt_c = { __lpdftype = "constant", __tostring = tostring_c, __call = value_c } -local mt_z = { __lpdftype = "null", __tostring = tostring_z, __call = value_z } -local mt_t = { __lpdftype = "true", __tostring = tostring_t, __call = value_t } -local mt_f = { __lpdftype = "false", __tostring = tostring_f, __call = value_f } -local mt_r = { __lpdftype = "reference", __tostring = tostring_r, __call = value_r } -local mt_v = { __lpdftype = "verbose", __tostring = tostring_v, __call = value_v } -local mt_l = { __lpdftype = "literal", __tostring = tostring_l, __call = value_l } +-- local mt_x = { __index = { __lpdftype__ = "stream" }, __lpdftype = "stream", __tostring = tostring_x, __call = value_x, __newindex = add_x } +-- local mt_d = { __index = { __lpdftype__ = "dictionary" }, __lpdftype = "dictionary", __tostring = tostring_d, __call = value_d, __add = add_to_d } +-- local mt_a = { __index = { __lpdftype__ = "array" }, __lpdftype = "array", __tostring = tostring_a, __call = value_a, __add = add_to_a } +-- local mt_u = { __index = { __lpdftype__ = "unicode" }, __lpdftype = "unicode", __tostring = tostring_u, __call = value_u } +-- local mt_s = { __index = { __lpdftype__ = "string" }, __lpdftype = "string", __tostring = tostring_s, __call = value_s } +-- local mt_p = { __index = { __lpdftype__ = "docstring" }, __lpdftype = "docstring", __tostring = tostring_p, __call = value_p } +-- local mt_n = { __index = { __lpdftype__ = "number" }, __lpdftype = "number", __tostring = tostring_n, __call = value_n } +-- local mt_c = { __index = { __lpdftype__ = "constant" }, __lpdftype = "constant", __tostring = tostring_c, __call = value_c } +-- local mt_z = { __index = { __lpdftype__ = "null" }, __lpdftype = "null", __tostring = tostring_z, __call = value_z } +-- local mt_t = { __index = { __lpdftype__ = "true" }, __lpdftype = "true", __tostring = tostring_t, __call = value_t } +-- local mt_f = { __index = { __lpdftype__ = "false" }, __lpdftype = "false", __tostring = tostring_f, __call = value_f } +-- local mt_r = { __index = { __lpdftype__ = "reference" }, __lpdftype = "reference", __tostring = tostring_r, __call = value_r } +-- local mt_v = { __index = { __lpdftype__ = "verbose" }, __lpdftype = "verbose", __tostring = tostring_v, __call = value_v } +-- local mt_l = { __index = { __lpdftype__ = "literal" }, __lpdftype = "literal", __tostring = tostring_l, __call = value_l } + +local mt_x = { __index = { __lpdftype__ = "stream" }, __tostring = tostring_x, __call = value_x, __newindex = add_x } +local mt_d = { __index = { __lpdftype__ = "dictionary" }, __tostring = tostring_d, __call = value_d, __add = add_to_d } +local mt_a = { __index = { __lpdftype__ = "array" }, __tostring = tostring_a, __call = value_a, __add = add_to_a } +local mt_u = { __index = { __lpdftype__ = "unicode" }, __tostring = tostring_u, __call = value_u } +local mt_s = { __index = { __lpdftype__ = "string" }, __tostring = tostring_s, __call = value_s } +local mt_p = { __index = { __lpdftype__ = "docstring" }, __tostring = tostring_p, __call = value_p } +local mt_n = { __index = { __lpdftype__ = "number" }, __tostring = tostring_n, __call = value_n } +local mt_c = { __index = { __lpdftype__ = "constant" }, __tostring = tostring_c, __call = value_c } +local mt_z = { __index = { __lpdftype__ = "null" }, __tostring = tostring_z, __call = value_z } +local mt_t = { __index = { __lpdftype__ = "true" }, __tostring = tostring_t, __call = value_t } +local mt_f = { __index = { __lpdftype__ = "false" }, __tostring = tostring_f, __call = value_f } +local mt_r = { __index = { __lpdftype__ = "reference" }, __tostring = tostring_r, __call = value_r } +local mt_v = { __index = { __lpdftype__ = "verbose" }, __tostring = tostring_v, __call = value_v } +local mt_l = { __index = { __lpdftype__ = "literal" }, __tostring = tostring_l, __call = value_l } local function pdfstream(t) -- we need to add attributes if t then @@ -730,9 +748,9 @@ local function pdfstream(t) -- we need to add attributes t[i] = tostring(t[i]) end elseif tt == "string" then - t= { t } + t = { t } else - t= { tostring(t) } + t = { tostring(t) } end end return setmetatable(t or { },mt_x) diff --git a/tex/context/base/mkiv/lpdf-u3d.lua b/tex/context/base/mkiv/lpdf-u3d.lua index fff89dc0f..f6897e92d 100644 --- a/tex/context/base/mkiv/lpdf-u3d.lua +++ b/tex/context/base/mkiv/lpdf-u3d.lua @@ -27,7 +27,6 @@ local nodeinjections = backends.pdf.nodeinjections local pdfconstant = lpdf.constant local pdfboolean = lpdf.boolean -local pdfnumber = lpdf.number local pdfunicode = lpdf.unicode local pdfdictionary = lpdf.dictionary local pdfarray = lpdf.array @@ -448,13 +447,12 @@ local function insert3d(spec) -- width, height, factor, display, controls, label stored_pr[tag] = ref end if ref then -- see back-pdf ** .. here we have a local /IM ! - local zero, one = pdfnumber(0), pdfnumber(1) -- not really needed local pw = pdfdictionary { Type = pdfconstant("XObject"), Subtype = pdfconstant("Form"), - FormType = one, - BBox = pdfarray { zero, zero, pdfnumber(factor*width), pdfnumber(factor*height) }, - Matrix = pdfarray { one, zero, zero, one, zero, zero }, + FormType = 1, + BBox = pdfarray { 0, 0, pdfnumber(factor*width), pdfnumber(factor*height) }, + Matrix = pdfarray { 1, 0, 0, 1, 0, 0 }, ProcSet = lpdf.procset(), Resources = pdfdictionary { XObject = pdfdictionary { @@ -464,8 +462,8 @@ local function insert3d(spec) -- width, height, factor, display, controls, label ExtGState = pdfdictionary { GS = pdfdictionary { Type = pdfconstant("ExtGState"), - CA = one, - ca = one, + CA = 1, + ca = 1, } }, } diff --git a/tex/context/base/mkiv/lpdf-xmp.lua b/tex/context/base/mkiv/lpdf-xmp.lua index ac7872fc2..508bb1997 100644 --- a/tex/context/base/mkiv/lpdf-xmp.lua +++ b/tex/context/base/mkiv/lpdf-xmp.lua @@ -136,11 +136,11 @@ local function update() -- local t = type(dates) if t == "number" or t == "string" then - t = converters.totime(dates) - if t then + local d = converters.totime(dates) + if d then included.date = true included.id = "fake" - report_info("forced date/time information %a will be used",lpdf.settime(t)) + report_info("forced date/time information %a will be used",lpdf.settime(d)) settrailerid(false) return end diff --git a/tex/context/base/mkiv/luat-cod.lua b/tex/context/base/mkiv/luat-cod.lua index 1a20908bd..9f8bbb544 100644 --- a/tex/context/base/mkiv/luat-cod.lua +++ b/tex/context/base/mkiv/luat-cod.lua @@ -11,6 +11,10 @@ local match, gsub, find, format, gmatch = string.match, string.gsub, string.find local texconfig, lua = texconfig, lua +-- maybe pick up from commandline: +-- +-- texconfig.interaction: 0=batchmode 1=nonstopmode 2=scrollmode 3=errornonstopmode 4=normal + -- some basic housekeeping texconfig.kpse_init = false diff --git a/tex/context/base/mkiv/math-fbk.lua b/tex/context/base/mkiv/math-fbk.lua index bfe2fde57..50c977178 100644 --- a/tex/context/base/mkiv/math-fbk.lua +++ b/tex/context/base/mkiv/math-fbk.lua @@ -318,9 +318,10 @@ local function accent_to_extensible(target,newchr,original,oldchr,height,depth,s height = height or 0 depth = depth or 0 end + local oldheight = olddata.height or 0 local correction = swap and - downcommand[(olddata.height or 0) - height] - or downcommand[olddata.height + (offset or 0)] + downcommand[oldheight - height] + or downcommand[oldheight + (offset or 0)] local newdata = { commands = { correction, charcommand[oldchr] }, width = olddata.width, @@ -654,3 +655,35 @@ virtualcharacters[0x2980] = function(data) return equals(data,0x2980,0x007C,-1/8 -- }, -- } -- end + +-- lucida needs this + +virtualcharacters[0x305] = function(data) + local target = data.target + local height = target.parameters.xheight/8 + local width = target.parameters.emwidth/2 + local depth = height + local used = 0.8 * width + return { + width = width, + height = height, + depth = depth, + commands = { { "rule", height, width } }, + horiz_variants = { + { + advance = width, + ["end"] = used, + glyph = 0x305, + start = 0, + }, + { + advance = width, + ["end"] = 0, + extender = 1, + glyph = 0x305, + start = used, + }, + } + } +end + diff --git a/tex/context/base/mkiv/math-noa.lua b/tex/context/base/mkiv/math-noa.lua index 7da84980e..51fc211dd 100644 --- a/tex/context/base/mkiv/math-noa.lua +++ b/tex/context/base/mkiv/math-noa.lua @@ -1446,7 +1446,7 @@ end -- in opentype the italic correction of a limop is added to the width and luatex does -- some juggling that we want to avoid but we need to do something here (in fact, we could --- better fix the width of the character +-- better fix the width of the character) do diff --git a/tex/context/base/mkiv/meta-blb.lua b/tex/context/base/mkiv/meta-blb.lua index 5fea35f6d..ca3e55e42 100644 --- a/tex/context/base/mkiv/meta-blb.lua +++ b/tex/context/base/mkiv/meta-blb.lua @@ -31,10 +31,6 @@ local report = logs.reporter("metapost","blobs") trackers.register("metapost.blobs", function(v) trace = v end) --- We start with a text that comes from an analyze stage and can end up with --- one or more results. For practical reasons we store the blobs in one array --- and work with ranges. - local allblobs = { } local function newcategory(t,k) @@ -189,10 +185,6 @@ local function reset() blob_raw_reset() end -local function analyze(object,prescript) - -- nothing -end - local function process(object,prescript,before,after) -- if prescript.tb_stage == "inject" then local tb_blob = tonumber(prescript.tb_blob) @@ -205,7 +197,6 @@ end metapost.installplugin { name = "texblob", reset = reset, - analyze = analyze, process = process, } @@ -291,71 +282,33 @@ interfaces.implement { actions = initialize, } -local ft_reset, ft_analyze, ft_process do - - if metapost.use_one_pass then - - local mp_category = 0 - local mp_str = "" - - function mp.mf_inject_blob(category,str) - newblob(category,str) -- only for tracing - mp_category = category - mp_str = str - tex.runtoks("mpblobtext") - end - - interfaces.implement { - name = "mpblobtext", - actions = function() - context.MPLIBfollowtext(mp_category,mp_str) - end - } - - ft_process = function(object,prescript,before,after) - if prescript.ft_category then - object.path = false - object.color = false - object.grouped = true - object.istext = true - end - end - - - else - - ft_reset = function() - -- nothing - end - - ft_analyze = function(object,prescript) - if prescript.ft_stage == "trial" then - local ft_category = tonumber(prescript.ft_category) - if ft_category then - newblob(ft_category,object.postscript) -- only for tracing - context.MPLIBfollowtext(ft_category,object.postscript) - metapost.getjobdata().multipass = true - end - end - end - - ft_process = function(object,prescript,before,after) - if prescript.ft_stage == "final" then - object.path = false - object.color = false - object.grouped = true - object.istext = true - end - end +local mp_category = 0 +local mp_str = "" +function mp.mf_inject_blob(category,str) + newblob(category,str) -- only for tracing + mp_category = category + mp_str = str + tex.runtoks("mpblobtext") +end +interfaces.implement { + name = "mpblobtext", + actions = function() + context.MPLIBfollowtext(mp_category,mp_str) end +} +local process = function(object,prescript,before,after) + if prescript.ft_category then + object.path = false + object.color = false + object.grouped = true + object.istext = true + end end metapost.installplugin { name = "followtext", - reset = ft_reset, - analyze = ft_analyze, - process = ft_process, + process = process, } diff --git a/tex/context/base/mkiv/meta-fnt.lua b/tex/context/base/mkiv/meta-fnt.lua index e1d8d86eb..d2d642902 100644 --- a/tex/context/base/mkiv/meta-fnt.lua +++ b/tex/context/base/mkiv/meta-fnt.lua @@ -110,10 +110,7 @@ local function process(mpxformat,name,instances,scalefactor) descriptions = { } metapost.process { mpx = mpxformat, - -- trialrun = false, flusher = flusher, - -- multipass = false, - -- isextrapass = false, askedfig = "all", -- incontext = false, data = { diff --git a/tex/context/base/mkiv/meta-ini.mkiv b/tex/context/base/mkiv/meta-ini.mkiv index e0aba5fc0..89c7699de 100644 --- a/tex/context/base/mkiv/meta-ini.mkiv +++ b/tex/context/base/mkiv/meta-ini.mkiv @@ -881,19 +881,6 @@ {\meta_prepare_instance_variable{#1}% \edef\overlaystamp{\overlaystamp:\MPvariable{#1}}} -%D \macros -%D {MPdatafile} -%D -%D We redefine a macro from \type {supp-mps.tex}: - -% This will change ... - -\def\MPdataMPYfile{\jobname-mpgraph.mpy} - -\startMPextensions - def data_mpy_file = "\noexpand\MPdataMPYfile" enddef ; -\stopMPextensions - \unexpanded\def\getMPdata {\clf_getMPdata} \let\rawMPdata \clf_getMPdata diff --git a/tex/context/base/mkiv/mlib-ctx.lua b/tex/context/base/mkiv/mlib-ctx.lua index 99ef6c813..89f2fa0ee 100644 --- a/tex/context/base/mkiv/mlib-ctx.lua +++ b/tex/context/base/mkiv/mlib-ctx.lua @@ -323,20 +323,14 @@ implement { statistics.register("metapost", function() local n = metapost.n if n and n > 0 then - local nofconverted = metapost.makempy.nofconverted local elapsedtime = statistics.elapsedtime - local elapsed = statistics.elapsed - local instances, memory = metapost.getstatistics(true) - local str = format("%s seconds, loading: %s, execution: %s, n: %s, average: %s, instances: %i, luacalls: %i, memory: %0.3f M", + local elapsed = statistics.elapsed + local instances, + memory = metapost.getstatistics(true) + return format("%s seconds, loading: %s, execution: %s, n: %s, average: %s, instances: %i, luacalls: %i, memory: %0.3f M", elapsedtime(metapost), elapsedtime(mplib), elapsedtime(metapost.exectime), n, elapsedtime((elapsed(metapost) + elapsed(mplib) + elapsed(metapost.exectime)) / n), instances, metapost.nofscriptruns(),memory/(1024*1024)) - if nofconverted > 0 then - return format("%s, external: %s (%s calls)", - str, elapsedtime(metapost.makempy), nofconverted) - else - return str - end else return nil end diff --git a/tex/context/base/mkiv/mlib-pdf.lua b/tex/context/base/mkiv/mlib-pdf.lua index c3c8c00da..717bb1634 100644 --- a/tex/context/base/mkiv/mlib-pdf.lua +++ b/tex/context/base/mkiv/mlib-pdf.lua @@ -6,8 +6,6 @@ if not modules then modules = { } end modules ['mlib-pdf'] = { license = "see context related readme files", } --- maybe %s is better than %f - local gsub = string.gsub local concat, insert, remove = table.concat, table.insert, table.remove local abs, sqrt, round = math.abs, math.sqrt, math.round @@ -42,11 +40,9 @@ local pdfflusher = { } metapost.flushers.pdf = pdfflusher metapost.n = 0 -metapost.optimize = true -- false local experiment = true -- uses context(node) that already does delayed nodes local savedliterals = nil -- needs checking ------ mpsliteral = nodes.pool.register(node.new("whatsit",nodes.whatsitcodes.pdfliteral)) local mpsliteral = nodes.pool.pdforiginliteral local f_f = formatters["%.6F"] @@ -87,65 +83,27 @@ trackers.register("metapost.forcestroke",function(v) force_stroke = v end) --- local pdfliteral = function(pdfcode) --- local literal = copy_node(mpsliteral) --- literal.data = pdfcode --- return literal --- end - -- Because in MKiV we always have two passes, we save the objects. When an extra -- mp run is done (due to for instance texts identifier in the parse pass), we -- get a new result table and the stored objects are forgotten. Otherwise they -- are reused. local function getobjects(result,figure,index) - if metapost.optimize then - local robjects = result.objects - if not robjects then - robjects = { } - result.objects = robjects - end - local fobjects = robjects[index or 1] - if not fobjects then - fobjects = figure:objects() - robjects[index] = fobjects - end - return fobjects - else - return figure:objects() - end + return figure:objects() end function metapost.convert(specification,result) - local trialrun = specification.trialrun - local flusher = specification.flusher - local multipass = specification.multipass - local askedfig = specification.askedfig - local incontext = specification.incontext - if trialrun then - local multipassindeed = metapost.parse(result,askedfig) - if multipass and not multipassindeed and metapost.optimize then - if save_table then - table.save(save_table,metapost.totable(result,1)) -- direct - end - metapost.flush(specification,result) - else - return false - end - else - if save_table then - table.save(save_table,metapost.totable(result,1)) -- direct - end - metapost.flush(specification,result) + local flusher = specification.flusher + local askedfig = specification.askedfig + if save_table then + table.save(save_table,metapost.totable(result,1)) -- direct end + metapost.flush(specification,result) return true -- done end function metapost.flushliteral(d) if savedliterals then --- local literal = copy_node(mpsliteral) --- literal.data = savedliterals[d] --- write_node(literal) write_node(mpsliteral(savedliterals[d])) else report_metapost("problem flushing literal %a",d) @@ -160,7 +118,6 @@ function pdfflusher.comment(message) if message then message = formatters["%% mps graphic %s: %s"](metapost.n,message) if experiment then - -- context(pdfliteral(message)) context(mpsliteral(message)) elseif savedliterals then local last = #savedliterals + 1 @@ -190,7 +147,6 @@ function pdfflusher.flushfigure(pdfliterals) -- table if #pdfliterals > 0 then pdfliterals = concat(pdfliterals,"\n") if experiment then - -- context(pdfliteral(pdfliterals)) context(mpsliteral(pdfliterals)) else if savedliterals then @@ -342,15 +298,6 @@ local p_boolean = P("false") * Cc(false) + P("true") * Cc(true) local p_set = Ct(number^1) local p_path = Ct(Ct(number * number^-5)^1) --- local variable = --- P("1:") * key * p_number --- + P("2:") * key * p_string --- + P("3:") * key * p_boolean --- + S("4568") * P(":") * key * p_set --- + P("7:") * key * p_path --- --- local pattern_key = Cf ( Carg(1) * (Cg(variable * newline^0)^0), rawset) - local variable = P("1:") * p_number + P("2:") * p_string @@ -504,7 +451,6 @@ function metapost.flush(specification,result) setmetatable(object, { __index = original }) - -- first we analyze local before, after = processplugins(object) local evenodd, collect, both = false, false, false local postscript = object.postscript @@ -689,35 +635,6 @@ function metapost.flush(specification,result) end end -function metapost.parse(result,askedfig) - if result then - local figures = result.fig - if figures then - local multipass = false - local analyzeplugins = metapost.analyzeplugins -- each object - for index=1,#figures do - local figure = figures[index] - local properties = pushproperties(figure) - if askedfig == "direct" or askedfig == "all" or askedfig == properties.number then - local objects = getobjects(result,figure,index) - if objects then - for o=1,#objects do - if analyzeplugins(objects[o]) then - multipass = true - end - end - end - if askedfig ~= "all" then - break - end - end - popproperties() - end - return multipass - end - end -end - -- tracing: do @@ -757,7 +674,6 @@ function metapost.totable(result,askedfig) local figure = result and result.fig and result.fig[1] if figure then local results = { } - -- local objects = figure:objects() local objects = getobjects(result,figure,askedfig) for o=1,#objects do local object = objects[o] diff --git a/tex/context/base/mkiv/mlib-pps.lua b/tex/context/base/mkiv/mlib-pps.lua index f6b142d46..5ee375982 100644 --- a/tex/context/base/mkiv/mlib-pps.lua +++ b/tex/context/base/mkiv/mlib-pps.lua @@ -23,7 +23,6 @@ local context = context local implement = interfaces.implement local setmacro = interfaces.setmacro ------ texgetbox = tex.getbox local texsetbox = tex.setbox local textakebox = tex.takebox -- or: nodes.takebox local copy_list = node.copy_list @@ -58,9 +57,6 @@ local cmyktorgb = colors.cmyktorgb -- or function() return 0,0,0 e local rgbtogray = colors.rgbtogray -- or function() return 0 end local cmyktogray = colors.cmyktogray -- or function() return 0 end -metapost.makempy = metapost.makempy or { nofconverted = 0 } -local makempy = metapost.makempy - local nooutercolor = "0 g 0 G" local nooutertransparency = "/Tr0 gs" -- only when set local outercolormode = 0 @@ -296,49 +292,23 @@ end -- end of new -local settext, gettext - -if metapost.use_one_pass then - - settext = function(box,slot,str) - if top then - -- if trace_textexts then - -- report_textexts("getting text %s from box %s",slot,box) - -- end - top.textexts[slot] = textakebox(box) - end - end - - gettext = function(box,slot) - if top then - texsetbox(box,top.textexts[slot]) - top.textexts[slot] = false - -- if trace_textexts then - -- report_textexts("putting text %s in box %s",slot,box) - -- end - end - end - -else - - settext = function(box,slot,str) - if top then - -- if trace_textexts then - -- report_textexts("getting text %s from box %s",slot,box) - -- end - top.textexts[slot] = textakebox(box) - end +local settext = function(box,slot,str) + if top then + -- if trace_textexts then + -- report_textexts("getting text %s from box %s",slot,box) + -- end + top.textexts[slot] = textakebox(box) end +end - gettext = function(box,slot) - if top then - texsetbox(box,copy_list(top.textexts[slot])) - -- if trace_textexts then - -- report_textexts("putting text %s in box %s",slot,box) - -- end - end +local gettext = function(box,slot) + if top then + texsetbox(box,top.textexts[slot]) + top.textexts[slot] = false + -- if trace_textexts then + -- report_textexts("putting text %s in box %s",slot,box) + -- end end - end metapost.settext = settext @@ -495,76 +465,9 @@ setmetatableindex(models, function(t,k) end) local function colorconverter(cs) - -- return models[colors.currentmodel()](cs) return models[outercolormodel](cs) end -local btex = P("btex") -local etex = P(" etex") -local vtex = P("verbatimtex") -local ttex = P("textext") -local gtex = P("graphictext") -local multipass = P("forcemultipass") -local spacing = S(" \n\r\t\v")^0 -local dquote = P('"') - -local found, forced = false, false - -local function convert(str) - found = true - return "rawtextext(\"" .. str .. "\")" -- centered -end -local function ditto(str) - return "\" & ditto & \"" -end -local function register() - found = true -end -local function force() - forced = true -end - -local texmess = (dquote/ditto + (1 - etex))^0 - -local function ignore(s) - report_metapost("ignoring verbatim tex: %s",s) - return "" -end - --- local parser = P { --- [1] = Cs((V(2)/register + V(4)/ignore + V(3)/convert + V(5)/force + 1)^0), --- [2] = ttex + gtex, --- [3] = btex * spacing * Cs(texmess) * etex, --- [4] = vtex * spacing * Cs(texmess) * etex, --- [5] = multipass, -- experimental, only for testing --- } - --- currently a a one-liner produces less code - --- textext.*(".*") can have "'s but tricky parsing as we can have concatenated strings --- so this is something for a boring plane or train trip and we might assume proper mp --- input anyway - -local parser = Cs(( - (ttex + gtex)/register - + (btex * spacing * Cs(texmess) * etex)/convert - + (vtex * spacing * Cs(texmess) * etex)/ignore - + 1 -)^0) - -local checking_enabled = false directives.register("metapost.checktexts",function(v) checking_enabled = v end) - -local function checktexts(str) - if checking_enabled then - found, forced = false, false - return lpegmatch(parser,str), found, forced - else - return str - end -end - -metapost.checktexts = checktexts - local factor = 65536*(7227/7200) implement { @@ -586,10 +489,6 @@ metapost.sxsy = sxsy -- for stock mp we need to declare the booleans first -local no_first_run = "boolean mfun_first_run ; mfun_first_run := false ;" -local do_first_run = "boolean mfun_first_run ; mfun_first_run := true ;" -local no_trial_run = "boolean mfun_trial_run ; mfun_trial_run := false ;" -local do_trial_run = "boolean mfun_trial_run ; mfun_trial_run := true ;" local do_begin_fig = "; beginfig(1) ; " local do_end_fig = "; endfig ;" local do_safeguard = ";" @@ -611,20 +510,6 @@ function metapost.preparetextextsdata() mp.mf_tt_initialize(collected) end -metapost.intermediate = metapost.intermediate or { } -metapost.intermediate.actions = metapost.intermediate.actions or { } - -metapost.method = 1 -- 1:dumb 2:clever 3:nothing - -if metapost.use_one_pass then - - metapost.method = 3 - checking_enabled = false - -end - --- maybe we can latelua the texts some day - local runmetapost = metapost.run local function checkaskedfig(askedfig) -- return askedfig, wrappit @@ -651,7 +536,6 @@ local function extrapass() metapost.preparetextextsdata() runmetapost { mpx = top.mpx, - isextrapass = true, askedfig = top.askedfig, incontext = true, data = { @@ -684,107 +568,36 @@ function metapost.graphic_base_pass(specification) top.wrappit = wrappit top.nofruns = nofruns metapost.namespace = specification.namespace or "" - -- - local done_1, done_2, done_3, forced_1, forced_2, forced_3 - if checking_enabled then - data, done_1, forced_1 = checktexts(data) - if extensions == "" then - extensions, done_2, forced_2 = "", false, false - else - extensions, done_2, forced_2 = checktexts(extensions) - end - if inclusions == "" then - inclusions, done_3, forced_3 = "", false, false - else - inclusions, done_3, forced_3 = checktexts(inclusions) - end - end - top.intermediate = false - top.multipass = false -- no needed here - top.mpx = mpx - top.data = data - top.initializations = initializations - local method = metapost.method + top.mpx = mpx + top.data = data + top.initializations = initializations if trace_runs then - if method == 1 then - report_metapost("forcing two runs due to library configuration") - elseif method ~= 2 then - report_metapost("ignoring extra run due to library configuration") - elseif not (done_1 or done_2 or done_3) then - report_metapost("forcing one run only due to analysis") - elseif done_1 then - report_metapost("forcing at max two runs due to main code") - elseif done_2 then - report_metapost("forcing at max two runs due to extensions") - else - report_metapost("forcing at max two runs due to inclusions") - end - end - if method == 1 or (method == 2 and (done_1 or done_2 or done_3)) then - if trace_runs then - report_metapost("first run of job %s, asked figure %a",nofruns,askedfig) - end - local flushed = runmetapost { - mpx = mpx, - trialrun = true, - multipass = not (forced_1 or forced_2 or forced_3), - askedfig = askedfig, - incontext = true, - data = { - inclusions, - wrappit and do_begin_fig or "", - do_first_run, - do_trial_run, - initializations, - do_safeguard, - data, - wrappit and do_end_fig or "", - }, - } - if top.intermediate then - for _, action in next, metapost.intermediate.actions do - action() - end - end - if not flushed or not metapost.optimize then - -- This is tricky as we can only ask for objects once and therefore - -- we really need a second run when we're not optimized. - context(extrapass) - end - else - if trace_runs then - report_metapost("running job %s, asked figure %a",nofruns,askedfig) - end - runmetapost { - mpx = mpx, - askedfig = askedfig, - incontext = true, - data = { - inclusions, - wrappit and do_begin_fig or "", - do_first_run, - no_trial_run, - initializations, - do_safeguard, - data, - wrappit and do_end_fig or "", - }, - } + report_metapost("running job %s, asked figure %a",nofruns,askedfig) end + runmetapost { + mpx = mpx, + askedfig = askedfig, + incontext = true, + data = { + inclusions, + wrappit and do_begin_fig or "", + initializations, + do_safeguard, + data, + wrappit and do_end_fig or "", + }, + } context(stopjob) end -local function oldschool(mpx, data, trialrun, flusher, multipass, isextrapass, askedfig, incontext) +local function oldschool(mpx, data, trial_run, flusher, was_multi_pass, is_extra_pass, askedfig, incontext) metapost.process { - mpx = mpx, - trialrun = trialrun, - flusher = flusher, - multipass = multipass, - isextrapass = isextrapass, - askedfig = askedfig, - useplugins = incontext, - incontext = incontext, - data = data, + mpx = mpx, + flusher = flusher, + askedfig = askedfig, + useplugins = incontext, + incontext = incontext, + data = data, } end @@ -798,83 +611,6 @@ function metapost.process(specification,...) end end -local start = [[\starttext]] -local preamble = [[\def\MPLIBgraphictext#1{\startTEXpage[scale=10000]#1\stopTEXpage}]] -local stop = [[\stoptext]] - -local mpyfilename = nil - -function makempy.registerfile(filename) - mpyfilename = filename -end - -implement { - name = "registermpyfile", - actions = makempy.registerfile, - arguments = "string" -} - -local pdftompy = sandbox.registerrunner { - name = "mpy:pstoedit", - program = "pstoedit", - template = "-ssp -dt -f mpost %pdffile% %mpyfile%", - checkers = { - pdffile = "writable", - mpyfile = "readable", - }, - reporter = report_metapost, -} - -local textopdf = sandbox.registerrunner { - name = "mpy:context", - program = "context", - template = "--once %runmode% %texfile%", - checkers = { - runmode = "string", - texfile = "readable", - }, - reporter = report_metapost, -} - -function makempy.processgraphics(graphics) - if #graphics == 0 then - return - end - if mpyfilename and exists(mpyfilename) then - report_metapost("using file: %s",mpyfilename) - return - end - makempy.nofconverted = makempy.nofconverted + 1 - starttiming(makempy) - local mpofile = tex.jobname .. "-mpgraph" - local mpyfile = file.replacesuffix(mpofile,"mpy") - local pdffile = file.replacesuffix(mpofile,"pdf") - local texfile = file.replacesuffix(mpofile,"tex") - savedata(texfile, { start, preamble, metapost.tex.get(), concat(graphics,"\n"), stop }, "\n") - textopdf { - runmode = tex.interactionmode == 0 and "--batchmode" or "", - texfile = texfile, - } - if exists(pdffile) then - pdftompy { - pdffile = pdffile, - mpyfile = mpyfile, - } - if exists(mpyfile) then - local result, r = { }, 0 - local data = io.loaddata(mpyfile) - if data and #data > 0 then - for figure in gmatch(data,"beginfig(.-)endfig") do - r = r + 1 - result[r] = formatters["begingraphictextfig%sendgraphictextfig ;\n"](figure) - end - savedata(mpyfile,concat(result,"")) - end - end - end - stoptiming(makempy) -end - -- -- the new plugin handler -- -- local sequencers = utilities.sequencers @@ -882,11 +618,9 @@ local appendgroup = sequencers.appendgroup local appendaction = sequencers.appendaction local resetteractions = sequencers.new { arguments = "t" } -local analyzeractions = sequencers.new { arguments = "object,prescript" } local processoractions = sequencers.new { arguments = "object,prescript,before,after" } appendgroup(resetteractions, "system") -appendgroup(analyzeractions, "system") appendgroup(processoractions,"system") -- later entries come first @@ -955,17 +689,6 @@ function metapost.resetplugins(t) -- intialize plugins, before figure end end -function metapost.analyzeplugins(object) -- each object (first pass) - if top.plugmode then - local prescript = object.prescript -- specifications - if prescript and #prescript > 0 then - analyzeractions.runner(object,splitprescript(prescript) or {}) - return top.multipass - end - end - return false -end - function metapost.processplugins(object) -- each object (second pass) if top.plugmode then local prescript = object.prescript -- specifications @@ -1014,7 +737,7 @@ end -- text -local tx_reset, tx_analyze, tx_process do +local tx_reset, tx_process do local eol = S("\n\r")^1 local cleaner = Cs((P("@@")/"@" + P("@")/"%%" + P(1))^0) @@ -1055,339 +778,174 @@ local tx_reset, tx_analyze, tx_process do f_cmyk_nop = formatters["c=%.3N,m=%.3N,y=%.3N,k=%.3N"] end) - if metapost.use_one_pass then - - local ctx_MPLIBsetNtext = context.MPLIBsetNtextX - local ctx_MPLIBsetCtext = context.MPLIBsetCtextX - local ctx_MPLIBsettext = context.MPLIBsettextX - - local bp = number.dimenfactors.bp - - local mp_index = 0 - local mp_target = 0 - local mp_c = nil - local mp_a = nil - local mp_t = nil - - local function processtext() - local mp_text = top.texstrings[mp_index] - if not mp_text then - report_textexts("missing text for index %a",mp_index) - elseif not mp_c then - ctx_MPLIBsetNtext(mp_target,mp_text) - elseif #mp_c == 1 then - if mp_a and mp_t then - ctx_MPLIBsetCtext(mp_target,f_gray_yes(mp_c[1],mp_a,mp_t),mp_text) - else - ctx_MPLIBsetCtext(mp_target,f_gray_nop(mp_c[1]),mp_text) - end - elseif #mp_c == 3 then - if mp_a and mp_t then - ctx_MPLIBsetCtext(mp_target,f_rgb_nop(mp_c[1],mp_c[2],mp_c[3],mp_a,mp_t),mp_text) - else - ctx_MPLIBsetCtext(mp_target,f_rgb_nop(mp_c[1],mp_c[2],mp_c[3]),mp_text) - end - elseif #mp_c == 4 then - if mp_a and mp_t then - ctx_MPLIBsetCtext(mp_target,f_cmyk_yes(mp_c[1],mp_c[2],mp_c[3],mp_c[4],mp_a,mp_t),mp_text) - else - ctx_MPLIBsetCtext(mp_target,f_cmyk_nop(mp_c[1],mp_c[2],mp_c[3],mp_c[4]),mp_text) - end + local ctx_MPLIBsetNtext = context.MPLIBsetNtextX + local ctx_MPLIBsetCtext = context.MPLIBsetCtextX + local ctx_MPLIBsettext = context.MPLIBsettextX + + local bp = number.dimenfactors.bp + + local mp_index = 0 + local mp_target = 0 + local mp_c = nil + local mp_a = nil + local mp_t = nil + + local function processtext() + local mp_text = top.texstrings[mp_index] + if not mp_text then + report_textexts("missing text for index %a",mp_index) + elseif not mp_c then + ctx_MPLIBsetNtext(mp_target,mp_text) + elseif #mp_c == 1 then + if mp_a and mp_t then + ctx_MPLIBsetCtext(mp_target,f_gray_yes(mp_c[1],mp_a,mp_t),mp_text) else - -- can't happen - ctx_MPLIBsetNtext(mp_target,mp_text) + ctx_MPLIBsetCtext(mp_target,f_gray_nop(mp_c[1]),mp_text) end - end - - function mp.mf_some_text(index,str) - mp_target = index - mp_index = index - mp_c = nil - mp_a = nil - mp_t = nil - top.texstrings[mp_index] = str - tex.runtoks("mptexttoks") - local box = textakebox("mptextbox") - top.textexts[mp_target] = box - mp.triplet(bp*box.width,bp*box.height,bp*box.depth) - madetext = nil - end - - local madetext = nil - - function mp.mf_made_text(index) - mp.mf_some_text(index,madetext) - end - - function metapost.maketext(s,mode) - if mode and mode == 1 then - if trace_btexetex then - report_metapost("ignoring verbatimtex: [[%s]]",s) - end + elseif #mp_c == 3 then + if mp_a and mp_t then + ctx_MPLIBsetCtext(mp_target,f_rgb_nop(mp_c[1],mp_c[2],mp_c[3],mp_a,mp_t),mp_text) else - if trace_btexetex then - report_metapost("handling btex ... etex: [[%s]]",s) - end - -- madetext = utilities.strings.collapse(s) - madetext = s - return "rawmadetext" + ctx_MPLIBsetCtext(mp_target,f_rgb_nop(mp_c[1],mp_c[2],mp_c[3]),mp_text) end - end - - function mp.mf_formatted_text(index,fmt,...) - local t = { } - for i=1,select("#",...) do - local ti = select(i,...) - if type(ti) ~= "table" then - t[#t+1] = ti - end + elseif #mp_c == 4 then + if mp_a and mp_t then + ctx_MPLIBsetCtext(mp_target,f_cmyk_yes(mp_c[1],mp_c[2],mp_c[3],mp_c[4],mp_a,mp_t),mp_text) + else + ctx_MPLIBsetCtext(mp_target,f_cmyk_nop(mp_c[1],mp_c[2],mp_c[3],mp_c[4]),mp_text) end - local f = lpegmatch(cleaner,fmt) - local s = formatters[f](unpack(t)) or "" - mp.mf_some_text(index,s) + else + -- can't happen + ctx_MPLIBsetNtext(mp_target,mp_text) end + end - interfaces.implement { - name = "mptexttoks", - actions = processtext, - } + function mp.mf_some_text(index,str) + mp_target = index + mp_index = index + mp_c = nil + mp_a = nil + mp_t = nil + top.texstrings[mp_index] = str + tex.runtoks("mptexttoks") + local box = textakebox("mptextbox") + top.textexts[mp_target] = box + mp.triplet(bp*box.width,bp*box.height,bp*box.depth) + madetext = nil + end + + local madetext = nil + + function mp.mf_made_text(index) + mp.mf_some_text(index,madetext) + end - tx_reset = function() - if top then - top.texhash = { } - top.texlast = 0 + function metapost.maketext(s,mode) + if mode and mode == 1 then + if trace_btexetex then + report_metapost("ignoring verbatimtex: [[%s]]",s) end + else + if trace_btexetex then + report_metapost("handling btex ... etex: [[%s]]",s) + end + -- madetext = utilities.strings.collapse(s) + madetext = s + return "rawmadetext" end + end - tx_process = function(object,prescript,before,after) - local data = top.texdata[metapost.properties.number] - local index = tonumber(prescript.tx_index) - if index then - if trace_textexts then - report_textexts("using index %a",index) - end - -- - mp_c = object.color - if #mp_c == 0 then - local txc = prescript.tx_color - if txc then - mp_c = lpegmatch(pat,txc) - end - end - mp_a = tonumber(prescript.tr_alternative) - mp_t = tonumber(prescript.tr_transparency) - -- - mp_index = index - mp_target = top.texlast - 1 - top.texlast = mp_target - -- - local mp_text = top.texstrings[mp_index] - local box - if prescript.tx_cache == "no" then - tex.runtoks("mptexttoks") - box = textakebox("mptextbox") - else - local hash = fmt(mp_text,mp_a or "-",mp_t or "-",mp_c or "-") - box = data.texhash[hash] - if box then - box = copy_list(box) - else - tex.runtoks("mptexttoks") - box = textakebox("mptextbox") - data.texhash[hash] = box - end - end - top.textexts[mp_target] = box - -- - if box then - -- we need to freeze the variables outside the function - local sx, rx, ry, sy, tx, ty = cm(object) - local target = mp_target - before[#before+1] = function() - context.MPLIBgettextscaledcm(target, - f_f(sx), -- bah ... %s no longer checks - f_f(rx), -- bah ... %s no longer checks - f_f(ry), -- bah ... %s no longer checks - f_f(sy), -- bah ... %s no longer checks - f_f(tx), -- bah ... %s no longer checks - f_f(ty), -- bah ... %s no longer checks - sxsy(box.width,box.height,box.depth)) - end - else - before[#before+1] = function() - report_textexts("unknown %s",index) - end - end - if not trace_textexts then - object.path = false -- else: keep it - end - object.color = false - object.grouped = true - object.istext = true + function mp.mf_formatted_text(index,fmt,...) + local t = { } + for i=1,select("#",...) do + local ti = select(i,...) + if type(ti) ~= "table" then + t[#t+1] = ti end end + local f = lpegmatch(cleaner,fmt) + local s = formatters[f](unpack(t)) or "" + mp.mf_some_text(index,s) + end - else - - local ctx_MPLIBsetNtext = context.MPLIBsetNtext - local ctx_MPLIBsetCtext = context.MPLIBsetCtext - local ctx_MPLIBsettext = context.MPLIBsettext + interfaces.implement { + name = "mptexttoks", + actions = processtext, + } - tx_reset = function() - if top then - top.texhash = { } - top.texlast = 0 - end + tx_reset = function() + if top then + top.texhash = { } + top.texlast = 0 end + end - -- we reuse content when possible - -- we always create at least one instance (for dimensions) - -- we make sure we don't do that when we use one (else counter issues with e.g. \definelabel) - - tx_analyze = function(object,prescript) - local data = top.texdata[metapost.properties.number] - local tx_stage = prescript.tx_stage - if tx_stage == "trial" then - local tx_trial = data.textrial + 1 - data.textrial = tx_trial - local tx_number = tonumber(prescript.tx_number) - local s = object.postscript or "" - local c = object.color -- only simple ones, no transparency - if #c == 0 then - local txc = prescript.tx_color - if txc then - c = lpegmatch(pat,txc) - end - end - if prescript.tx_type == "format" then - s = applyformat(s) - end - local a = tonumber(prescript.tr_alternative) - local t = tonumber(prescript.tr_transparency) - local h = fmt(tx_number,a or "-",t or "-",c or "-") - local n = data.texhash[h] -- todo: hashed variant with s (nicer for similar labels) - if n then - data.texslots[tx_trial] = n - if trace_textexts then - report_textexts("stage %a, usage %a, number %a, %s %a, hash %a, text %a",tx_stage,tx_trial,tx_number,"old",n,h,s) - end - elseif prescript.tx_global == "yes" and data.texorder[tx_number] then - -- we already have one flush and don't want it redone .. this needs checking - if trace_textexts then - report_textexts("stage %a, usage %a, number %a, %s %a, hash %a, text %a",tx_stage,tx_trial,tx_number,"ignored",tx_last,h,s) - end - else - local tx_last = top.texlast + 1 - top.texlast = tx_last - -- report_textexts("tex string: %s",s) - if not c then - ctx_MPLIBsetNtext(tx_last,s) - elseif #c == 1 then - if a and t then - ctx_MPLIBsetCtext(tx_last,f_gray_yes(c[1],a,t),s) - else - ctx_MPLIBsetCtext(tx_last,f_gray_nop(c[1]),s) - end - elseif #c == 3 then - if a and t then - ctx_MPLIBsetCtext(tx_last,f_rgb_nop(c[1],c[2],c[3],a,t),s) - else - ctx_MPLIBsetCtext(tx_last,f_rgb_nop(c[1],c[2],c[3]),s) - end - elseif #c == 4 then - if a and t then - ctx_MPLIBsetCtext(tx_last,f_cmyk_yes(c[1],c[2],c[3],c[4],a,t),s) - else - ctx_MPLIBsetCtext(tx_last,f_cmyk_nop(c[1],c[2],c[3],c[4]),s) - end - else - ctx_MPLIBsetNtext(tx_last,s) - end - top.multipass = true - data.texhash [h] = tx_last - -- data.texhash [tx_number] = tx_last - data.texslots[tx_trial] = tx_last - data.texorder[tx_number] = tx_last - if trace_textexts then - report_textexts("stage %a, usage %a, number %a, %s %a, hash %a, text %a",tx_stage,tx_trial,tx_number,"new",tx_last,h,s) - end - end - elseif tx_stage == "extra" then - local tx_trial = data.textrial + 1 - data.textrial = tx_trial - local tx_number = tonumber(prescript.tx_number) - if not data.texorder[tx_number] then - local s = object.postscript or "" - local tx_last = top.texlast + 1 - top.texlast = tx_last - ctx_MPLIBsettext(tx_last,s) - top.multipass = true - data.texslots[tx_trial] = tx_last - data.texorder[tx_number] = tx_last - if trace_textexts then - report_textexts("stage %a, usage %a, number %a, extra %a, text %a",tx_stage,tx_trial,tx_number,tx_last,s) - end + tx_process = function(object,prescript,before,after) + local data = top.texdata[metapost.properties.number] + local index = tonumber(prescript.tx_index) + if index then + if trace_textexts then + report_textexts("using index %a",index) + end + -- + mp_c = object.color + if #mp_c == 0 then + local txc = prescript.tx_color + if txc then + mp_c = lpegmatch(pat,txc) end end - end - - tx_process = function(object,prescript,before,after) - local data = top.texdata[metapost.properties.number] - local tx_number = tonumber(prescript.tx_number) - if tx_number then - local tx_stage = prescript.tx_stage - if tx_stage == "final" then - local tx_final = data.texfinal + 1 - data.texfinal = tx_final - local n = data.texslots[tx_final] - if trace_textexts then - report_textexts("stage %a, usage %a, number %a, use %a",tx_stage,tx_final,tx_number,n) - end - local sx, rx, ry, sy, tx, ty = cm(object) -- needs to be frozen outside the function - local box = top.textexts[n] - if box then - before[#before+1] = function() - -- flush always happens, we can have a special flush function injected before - context.MPLIBgettextscaledcm(n, - f_f(sx), -- bah ... %s no longer checks - f_f(rx), -- bah ... %s no longer checks - f_f(ry), -- bah ... %s no longer checks - f_f(sy), -- bah ... %s no longer checks - f_f(tx), -- bah ... %s no longer checks - f_f(ty), -- bah ... %s no longer checks - sxsy(box.width,box.height,box.depth)) - end - else - before[#before+1] = function() - report_textexts("unknown %s",tx_number) - end - end - if not trace_textexts then - object.path = false -- else: keep it - end - object.color = false - object.grouped = true - object.istext = true + mp_a = tonumber(prescript.tr_alternative) + mp_t = tonumber(prescript.tr_transparency) + -- + mp_index = index + mp_target = top.texlast - 1 + top.texlast = mp_target + -- + local mp_text = top.texstrings[mp_index] + local box + if prescript.tx_cache == "no" then + tex.runtoks("mptexttoks") + box = textakebox("mptextbox") + else + local hash = fmt(mp_text,mp_a or "-",mp_t or "-",mp_c or "-") + box = data.texhash[hash] + if box then + box = copy_list(box) + else + tex.runtoks("mptexttoks") + box = textakebox("mptextbox") + data.texhash[hash] = box end end - end - - local f_textext = formatters[ [[rawtextext("%s")]] ] - - function metapost.maketext(s,mode) - if mode and mode == 1 then - if trace_btexetex then - report_metapost("ignoring verbatimtex: [[%s]]",s) + top.textexts[mp_target] = box + -- + if box then + -- we need to freeze the variables outside the function + local sx, rx, ry, sy, tx, ty = cm(object) + local target = mp_target + before[#before+1] = function() + context.MPLIBgettextscaledcm(target, + f_f(sx), -- bah ... %s no longer checks + f_f(rx), -- bah ... %s no longer checks + f_f(ry), -- bah ... %s no longer checks + f_f(sy), -- bah ... %s no longer checks + f_f(tx), -- bah ... %s no longer checks + f_f(ty), -- bah ... %s no longer checks + sxsy(box.width,box.height,box.depth)) end else - if trace_btexetex then - report_metapost("handling btex ... etex: [[%s]]",s) + before[#before+1] = function() + report_textexts("unknown %s",index) end - s = gsub(s,'"','"&ditto&"') - return f_textext(s) end + if not trace_textexts then + object.path = false -- else: keep it + end + object.color = false + object.grouped = true + object.istext = true end - end end @@ -1426,61 +984,29 @@ end -- graphics (we use the given index because pictures can be reused) -local gt_reset, gt_analyze, gt_process do +local gt_reset, gt_process do local graphics = { } - if metapost.use_one_pass then - local mp_index = 0 - local mp_str = "" + local mp_index = 0 + local mp_str = "" - function metapost.intermediate.actions.makempy() - end - - function mp.mf_graphic_text(index,str) - if not graphics[index] then - mp_index = index - mp_str = str - tex.runtoks("mpgraphictexttoks") - end + function mp.mf_graphic_text(index,str) + if not graphics[index] then + mp_index = index + mp_str = str + tex.runtoks("mpgraphictexttoks") end - - interfaces.implement { - name = "mpgraphictexttoks", - actions = function() - context.MPLIBgraphictext(mp_index,mp_str) - end, - } - - - else - - function metapost.intermediate.actions.makempy() - if #graphics > 0 then - makempy.processgraphics(graphics) - graphics = { } -- ? could be gt_reset - end - end - - local function gt_analyze(object,prescript) - local gt_stage = prescript.gt_stage - local gt_index = tonumber(prescript.gt_index) - if gt_stage == "trial" and not graphics[gt_index] then - graphics[gt_index] = formatters["\\MPLIBgraphictext{%s}"](object.postscript or "") - top.intermediate = true - top.multipass = true - end - end - - -- local function gt_process(object,prescript,before,after) - -- local gt_stage = prescript.gt_stage - -- if gt_stage == "final" then - -- end - -- end - end + interfaces.implement { + name = "mpgraphictexttoks", + actions = function() + context.MPLIBgraphictext(mp_index,mp_str) + end, + } + end -- shades @@ -1868,7 +1394,7 @@ end -- outlines -local ot_reset, ot_analyze, ot_process do +local ot_reset, ot_process do local outlinetexts = { } -- also in top data @@ -1876,43 +1402,26 @@ local ot_reset, ot_analyze, ot_process do outlinetexts = { } end - if metapost.use_one_pass then - - local mp_index = 0 - local mp_kind = "" - local mp_str = "" + local mp_index = 0 + local mp_kind = "" + local mp_str = "" - function mp.mf_outline_text(index,str,kind) - if not outlinetexts[index] then - mp_index = index - mp_kind = kind - mp_str = str - tex.runtoks("mpoutlinetoks") - end + function mp.mf_outline_text(index,str,kind) + if not outlinetexts[index] then + mp_index = index + mp_kind = kind + mp_str = str + tex.runtoks("mpoutlinetoks") end - - interfaces.implement { - name = "mpoutlinetoks", - actions = function() - context.MPLIBoutlinetext(mp_index,mp_kind,mp_str) - end, - } - - else - - ot_analyze = function(object,prescript) - local ot_stage = prescript.ot_stage - local ot_index = tonumber(prescript.ot_index) - if ot_index and ot_stage == "trial" and not outlinetexts[ot_index] then - local ot_kind = prescript.ot_kind or "" - top.intermediate = true - top.multipass = true - context.MPLIBoutlinetext(ot_index,ot_kind,object.postscript) - end - end - end + interfaces.implement { + name = "mpoutlinetoks", + actions = function() + context.MPLIBoutlinetext(mp_index,mp_kind,mp_str) + end, + } + implement { name = "MPLIBconvertoutlinetext", arguments = { "integer", "string", "integer" }, @@ -1944,15 +1453,11 @@ end local function installplugin(specification) local reset = specification.reset - local analyze = specification.analyze local process = specification.process local object = specification.object if reset then appendaction(resetteractions,"system",reset) end - if analyze then - appendaction(analyzeractions,"system",analyze) - end if process then appendaction(processoractions,"system",process) end @@ -1962,15 +1467,15 @@ metapost.installplugin = installplugin -- definitions -installplugin { name = "outline", reset = ot_reset, analyze = ot_analyze, process = ot_process } -installplugin { name = "color", reset = cl_reset, analyze = cl_analyze, process = cl_process } -installplugin { name = "text", reset = tx_reset, analyze = tx_analyze, process = tx_process } -installplugin { name = "group", reset = gr_reset, analyze = gr_analyze, process = gr_process } -installplugin { name = "graphictext", reset = gt_reset, analyze = gt_analyze, process = gt_process } -installplugin { name = "shade", reset = sh_reset, analyze = sh_analyze, process = sh_process } -installplugin { name = "bitmap", reset = bm_reset, analyze = bm_analyze, process = bm_process } -installplugin { name = "box", reset = bx_reset, analyze = bx_analyze, process = bx_process } -installplugin { name = "position", reset = ps_reset, analyze = ps_analyze, process = ps_process } -installplugin { name = "figure", reset = fg_reset, analyze = fg_analyze, process = fg_process } -installplugin { name = "layer", reset = la_reset, analyze = la_analyze, process = la_process } -installplugin { name = "transparency", reset = tr_reset, analyze = tr_analyze, process = tr_process } +installplugin { name = "outline", reset = ot_reset, process = ot_process } +installplugin { name = "color", reset = cl_reset, process = cl_process } +installplugin { name = "text", reset = tx_reset, process = tx_process } +installplugin { name = "group", reset = gr_reset, process = gr_process } +installplugin { name = "graphictext", reset = gt_reset, process = gt_process } +installplugin { name = "shade", reset = sh_reset, process = sh_process } +installplugin { name = "bitmap", reset = bm_reset, process = bm_process } +installplugin { name = "box", reset = bx_reset, process = bx_process } +installplugin { name = "position", reset = ps_reset, process = ps_process } +installplugin { name = "figure", reset = fg_reset, process = fg_process } +installplugin { name = "layer", reset = la_reset, process = la_process } +installplugin { name = "transparency", reset = tr_reset, process = tr_process } diff --git a/tex/context/base/mkiv/mlib-run.lua b/tex/context/base/mkiv/mlib-run.lua index 649d57c61..a3a833c4e 100644 --- a/tex/context/base/mkiv/mlib-run.lua +++ b/tex/context/base/mkiv/mlib-run.lua @@ -71,20 +71,6 @@ end ----- mpbasepath = lpeg.instringchecker(lpeg.append { "/metapost/context/", "/metapost/base/" }) local mpbasepath = lpeg.instringchecker(P("/metapost/") * (P("context") + P("base")) * P("/")) --- local function i_finder(askedname,mode,ftype) -- fake message for mpost.map and metafun.mpvi --- local foundname = file.is_qualified_path(askedname) and askedname or resolvers.findfile(askedname,ftype) --- if not mpbasepath(foundname) then --- -- we could use the via file but we don't have a complete io interface yet --- local data, found, forced = metapost.checktexts(io.loaddata(foundname) or "") --- if found then --- local tempname = luatex.registertempfile(foundname,true) --- io.savedata(tempname,data) --- foundname = tempname --- end --- end --- return foundname --- end - -- mplib has no real io interface so we have a different mechanism than -- tex (as soon as we have more control, we will use the normal code) -- @@ -98,21 +84,6 @@ do local new_instance = mplib.new - local function preprocessed(name) - if not mpbasepath(name) then - -- we could use the via file but we don't have a complete io interface yet - local data, found, forced = metapost.checktexts(io.loaddata(name) or "") - if found then - local temp = luatex.registertempfile(name,true) - io.savedata(temp,data) - return temp - end - end - return name - end - - mplib.preprocessed = preprocessed -- helper - local function validftype(ftype) if ftype == "" then -- whatever @@ -124,14 +95,13 @@ do end finders.file = function(specification,name,mode,ftype) - return preprocessed(resolvers.findfile(name,validftype(ftype))) + return resolvers.findfile(name,validftype(ftype)) end local function i_finder(name,mode,ftype) -- fake message for mpost.map and metafun.mpvi local specification = url.hashed(name) local finder = finders[specification.scheme] or finders.file local found = finder(specification,name,mode,validftype(ftype)) - -- print(found) return found end @@ -308,8 +278,6 @@ local function prepareddata(data,collapse) end end -metapost.use_one_pass = true -- Some day I will prune the code (still testing). - metapost.defaultformat = "metafun" metapost.defaultinstance = "metafun" metapost.defaultmethod = "default" @@ -460,18 +428,13 @@ end -- -- mpx string or mp object -- data string or table of strings --- trialrun boolean -- flusher table with flush methods --- multipass boolean --- isextrapass boolean -- askedfig string ("all" etc) or number -- incontext boolean -- plugmode boolean local function makebeginbanner(specification) - return formatters - ["%% begin graphic: n=%s, trialrun=%l, multipass=%l, isextrapass=%l\n\n"] - (metapost.n, specification.trialrun, specification.multipass, specification.isextrapass) + return formatters["%% begin graphic: n=%s\n\n"](metapost.n) end local function makeendbanner(specification) diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf Binary files differindex 05a5a0e47..d1c0f7bca 100644 --- a/tex/context/base/mkiv/status-files.pdf +++ b/tex/context/base/mkiv/status-files.pdf diff --git a/tex/context/base/mkiv/status-lua.pdf b/tex/context/base/mkiv/status-lua.pdf Binary files differindex e5566d82b..e70941e70 100644 --- a/tex/context/base/mkiv/status-lua.pdf +++ b/tex/context/base/mkiv/status-lua.pdf diff --git a/tex/context/base/mkiv/task-ini.lua b/tex/context/base/mkiv/task-ini.lua index 67bd26de6..cfff3625a 100644 --- a/tex/context/base/mkiv/task-ini.lua +++ b/tex/context/base/mkiv/task-ini.lua @@ -121,7 +121,7 @@ appendaction("math", "builders", "noads.handlers.align", appendaction("finalizers", "lists", "typesetters.paragraphs.normalize", nil, "nut", "enabled" ) -- "disabled" appendaction("finalizers", "lists", "typesetters.margins.localhandler", nil, "nut", "disabled" ) appendaction("finalizers", "lists", "builders.paragraphs.keeptogether", nil, "nut", "disabled" ) -appendaction("finalizers", "fonts", "builders.paragraphs.solutions.splitters.optimize", nil, "nut", "disabled" ) +appendaction("finalizers", "fonts", "builders.paragraphs.solutions.splitters.optimize", nil, "nonut", "disabled" ) appendaction("finalizers", "lists", "builders.paragraphs.tag", nil, "nut", "disabled" ) appendaction("finalizers", "lists", "nodes.linefillers.handler", nil, "nut", "disabled" ) diff --git a/tex/context/base/mkiv/util-tab.lua b/tex/context/base/mkiv/util-tab.lua index f395f43de..ed4cef996 100644 --- a/tex/context/base/mkiv/util-tab.lua +++ b/tex/context/base/mkiv/util-tab.lua @@ -820,3 +820,53 @@ if setinspector then end) end +-- ordered hashes (for now here but in the table namespace): + +-- local t = table.orderedhash() +-- +-- t["1"] = { "a", "b" } +-- t["2"] = { } +-- t["2a"] = { "a", "c", "d" } +-- +-- for k, v in table.ordered(t) do +-- ... +-- end + +local mt = { + __newindex = function(t,k,v) + local n = t.last + 1 + t.last = n + t.list[n] = k + t.hash[k] = v + end, + __index = function(t,k) + return t.hash[k] + end, + __len = function(t) + return t.last + end, +} + +function table.orderedhash() + return setmetatable({ list = { }, hash = { }, last = 0 }, mt) +end + +function table.ordered(t) + local n = t.last + if n > 0 then + local l = t.list + local i = 1 + local h = t.hash + local f = function() + if i <= n then + local k = i + local v = h[l[k]] + i = i + 1 + return k, v + end + end + return f, 1, h[l[1]] + else + return function() end + end +end diff --git a/tex/context/interface/mkiv/i-context.pdf b/tex/context/interface/mkiv/i-context.pdf Binary files differindex 744cc36a9..1809a7c91 100644 --- a/tex/context/interface/mkiv/i-context.pdf +++ b/tex/context/interface/mkiv/i-context.pdf diff --git a/tex/context/interface/mkiv/i-readme.pdf b/tex/context/interface/mkiv/i-readme.pdf Binary files differindex aa4551920..367a76106 100644 --- a/tex/context/interface/mkiv/i-readme.pdf +++ b/tex/context/interface/mkiv/i-readme.pdf diff --git a/tex/generic/context/luatex/luatex-basics-nod.lua b/tex/generic/context/luatex/luatex-basics-nod.lua index 4c9a13f9a..276c7efa5 100644 --- a/tex/generic/context/luatex/luatex-basics-nod.lua +++ b/tex/generic/context/luatex/luatex-basics-nod.lua @@ -234,6 +234,26 @@ nuts.traverse_char = direct.traverse_char nuts.traverse_glyph = direct.traverse_glyph nuts.traverse_id = direct.traverse_id +-- for now + +if not nuts.getdirection then + + local getdir = direct.getdir + + function nuts.getdirection(n) + local d = getdir(n) + if d == "TLT" then return 0 + elseif d == "TRT" then return 1 + elseif d == "+TLT" then return 0, false + elseif d == "+TRT" then return 1, false + elseif d == "-TLT" then return 0, true + elseif d == "-TRT" then return 1, true + else return 0 + end + end + +end + -- properties as used in the (new) injector: local propertydata = direct.get_properties_table() diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 1cecf7d9c..109d123fb 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 : 01/07/19 16:10:23 +-- merge date : 01/17/19 22:10:09 do -- begin closure to overcome local limits and interference @@ -4882,6 +4882,20 @@ nuts.traverse=direct.traverse nuts.traverse_char=direct.traverse_char nuts.traverse_glyph=direct.traverse_glyph nuts.traverse_id=direct.traverse_id +if not nuts.getdirection then + local getdir=direct.getdir + function nuts.getdirection(n) + local d=getdir(n) + if d=="TLT" then return 0 + elseif d=="TRT" then return 1 + elseif d=="+TLT" then return 0,false + elseif d=="+TRT" then return 1,false + elseif d=="-TLT" then return 0,true + elseif d=="-TRT" then return 1,true + else return 0 + end + end +end local propertydata=direct.get_properties_table() nodes.properties={ data=propertydata } direct.set_properties_mode(true,true) |