From 4a6b49038ccb940e1f429b5aca907ee779cc8bd9 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Fri, 18 Dec 2020 21:35:53 +0100 Subject: 2020-12-18 18:31:00 --- tex/context/base/mkii/cont-new.mkii | 2 +- tex/context/base/mkii/context.mkii | 2 +- tex/context/base/mkiv/cont-new.mkiv | 2 +- tex/context/base/mkiv/context.mkiv | 2 +- tex/context/base/mkiv/mult-mps.lua | 2 + tex/context/base/mkiv/status-files.pdf | Bin 26103 -> 26101 bytes tex/context/base/mkiv/status-lua.pdf | Bin 253364 -> 253610 bytes tex/context/base/mkxl/cont-new.mkxl | 2 +- tex/context/base/mkxl/context.mkxl | 2 +- tex/context/base/mkxl/font-ctx.lmt | 14 +- tex/context/base/mkxl/font-def.lmt | 23 +- tex/context/base/mkxl/meta-tex.mkxl | 8 +- tex/context/base/mkxl/mlib-fio.lmt | 68 +++++- tex/context/base/mkxl/mlib-lmp.lmt | 66 +++-- tex/context/base/mkxl/mlib-lua.lmt | 7 + tex/context/base/mkxl/mlib-run.lmt | 35 ++- tex/context/base/mkxl/mlib-scn.lmt | 1 + tex/context/base/mkxl/mlib-svg.lmt | 272 +++++++++++++-------- tex/generic/context/luatex/luatex-fonts-merged.lua | 2 +- 19 files changed, 344 insertions(+), 166 deletions(-) (limited to 'tex') diff --git a/tex/context/base/mkii/cont-new.mkii b/tex/context/base/mkii/cont-new.mkii index 01555af45..146a3ad9c 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{2020.12.15 10:10} +\newcontextversion{2020.12.18 18:28} %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 8b46e9081..b036f7229 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{2020.12.15 10:10} +\edef\contextversion{2020.12.18 18:28} %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 beded1600..2e7c722bf 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{2020.12.15 10:10} +\newcontextversion{2020.12.18 18:28} %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 4aaaf492d..59cc03096 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{2020.12.15 10:10} +\edef\contextversion{2020.12.18 18:28} %D Kind of special: diff --git a/tex/context/base/mkiv/mult-mps.lua b/tex/context/base/mkiv/mult-mps.lua index d994a3f65..a2a74b3b3 100644 --- a/tex/context/base/mkiv/mult-mps.lua +++ b/tex/context/base/mkiv/mult-mps.lua @@ -122,6 +122,8 @@ return { "triplet", "quadruplet", "totransform", "bymatrix", -- "primitive", "permanent", "immutable", "mutable", "frozen", + -- + "showproperty", "showhashentry", }, internals = { -- we need to remove duplicates above -- diff --git a/tex/context/base/mkiv/status-files.pdf b/tex/context/base/mkiv/status-files.pdf index e4baa5bde..b58ba82d8 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 03b142f98..069320e47 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 c3af4c00f..e93c21f01 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{2020.12.15 10:10} +\newcontextversion{2020.12.18 18:28} %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 39a9490a9..9f7bc755f 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{2020.12.15 10:10} +\immutable\edef\contextversion{2020.12.18 18:28} %overloadmode 1 % check frozen / warning %overloadmode 2 % check frozen / error diff --git a/tex/context/base/mkxl/font-ctx.lmt b/tex/context/base/mkxl/font-ctx.lmt index 3d269d8cb..13785f8dd 100644 --- a/tex/context/base/mkxl/font-ctx.lmt +++ b/tex/context/base/mkxl/font-ctx.lmt @@ -1092,6 +1092,15 @@ do -- else too many locals local setmacro = tokens.setters.macro + local reported = setmetatableindex(function(t,k) + local v = setmetatableindex(function(t,k) + t[k] = true + return false + end) + t[k] = v + return v + end) + implement { name = "definefont_one", arguments = "string", @@ -1399,7 +1408,10 @@ tfmdata.original = specification.specification texsetcount("scaledfontsize",size) lastfontid = tfmdata else - report_defining("unable to define %a as %a",name,nice_cs(cs)) + local nice = nice_cs(cs) + if not reported[name][nice] then + report_defining("unable to define %a as %a",name,nice) + end lastfontid = -1 texsetcount("scaledfontsize",0) -- ctx_letvaluerelax(cs) -- otherwise the current definition takes the previous one diff --git a/tex/context/base/mkxl/font-def.lmt b/tex/context/base/mkxl/font-def.lmt index 4b6616cd9..01513f1e6 100644 --- a/tex/context/base/mkxl/font-def.lmt +++ b/tex/context/base/mkxl/font-def.lmt @@ -13,7 +13,7 @@ local tostring, next = tostring, next local lpegmatch = lpeg.match local suffixonly, removesuffix, basename = file.suffix, file.removesuffix, file.basename local formatters = string.formatters -local sortedhash, sortedkeys = table.sortedhash, table.sortedkeys +local sortedhash, sortedkeys, setmetatableindex = table.sortedhash, table.sortedkeys, table.setmetatableindex local allocate = utilities.storage.allocate @@ -355,18 +355,24 @@ local function checkfeatures(tfmdata) end end +local reported = setmetatableindex(function(t,k) + t[k] = true + return false +end) + function definers.loadfont(specification) local hash = constructors.hashinstance(specification) -- todo: also hash by instance / factors local tfmdata = loadedfonts[hash] -- hashes by size ! + local name = specification.name if not tfmdata then -- normally context will not end up here often (if so there is an issue somewhere) local forced = specification.forced or "" if forced ~= "" then local reader = readers[lower(forced)] -- normally forced is already lowered tfmdata = reader and reader(specification) - if not tfmdata then - report_defining("forced type %a of %a not found",forced,specification.name) + if not tfmdata and not reported[name] then + report_defining("forced type %a of %a not found",forced,name) end else local sequence = readers.sequence -- can be overloaded so only a shortcut here @@ -392,8 +398,8 @@ function definers.loadfont(specification) checkfeatures(tfmdata) end end - if not tfmdata then - report_defining("font with asked name %a is not found using lookup %a",specification.name,specification.lookup) + if not tfmdata and not reported[name] then + report_defining("font with asked name %a is not found using lookup %a",name,specification.lookup) end return tfmdata end @@ -462,8 +468,9 @@ function definers.read(specification,size,id) -- id can be optional, name can al specification = variants[method](specification) end specification = definers.resolve(specification) - local hash = constructors.hashinstance(specification) + local hash = constructors.hashinstance(specification) local tfmdata = definers.registered(hash) -- id + local name = specification.name if tfmdata then if trace_defining then report_defining("already hashed: %s",hash) @@ -487,7 +494,9 @@ function definers.read(specification,size,id) -- id can be optional, name can al end end if not tfmdata then -- or id? - report_defining( "unknown font %a, loading aborted",specification.name) + if not reported[name] then + report_defining( "unknown font %a, loading aborted",name) + end elseif trace_defining and type(tfmdata) == "table" then local properties = tfmdata.properties or { } local parameters = tfmdata.parameters or { } diff --git a/tex/context/base/mkxl/meta-tex.mkxl b/tex/context/base/mkxl/meta-tex.mkxl index fc8456c73..a2377c321 100644 --- a/tex/context/base/mkxl/meta-tex.mkxl +++ b/tex/context/base/mkxl/meta-tex.mkxl @@ -199,11 +199,17 @@ \permanent\protected\def\svgcolored#1#2#3#4% r g b text {\colored[r=#1,g=#2,b=#3]{#4}} +% \permanent\protected\def\svgplaced#1#2#3#4% dx dy width text +% {\doifelsenothing{#3}% +% {\hpack}% +% {\hpack to #3}% +% {\raise#2\onebasepoint\hbox{\kern#1\onebasepoint\relax#4}}} + \permanent\protected\def\svgplaced#1#2#3#4% dx dy width text {\doifelsenothing{#3}% {\hpack}% {\hpack to #3}% - {\raise#2\onebasepoint\hbox{\kern#1\onebasepoint\relax#4}}} + {\offsetbox[\c!y=#2]\hbox{\kern#1\relax#4}}} \newdimen\grph_svg_scratchwidth % maybe \startsvgpos etc diff --git a/tex/context/base/mkxl/mlib-fio.lmt b/tex/context/base/mkxl/mlib-fio.lmt index 895178b04..92efcdf48 100644 --- a/tex/context/base/mkxl/mlib-fio.lmt +++ b/tex/context/base/mkxl/mlib-fio.lmt @@ -9,6 +9,10 @@ if not modules then modules = { } end modules ['mlib-fio'] = { local type = type local find = string.find local concat = table.concat +local suffix, addsuffix = file.suffix, file.addsuffix + +local findfile = resolvers.findfile +local new_instance = mplib.new local trace_terminal = false trackers.register("metapost.terminal", function(v) trace_terminal = v end) @@ -49,7 +53,6 @@ end local finders = { } mplib.finders = finders -- also used in meta-lua.lua -local new_instance = mplib.new local function validftype(ftype) if ftype == "mp" then @@ -59,8 +62,32 @@ local function validftype(ftype) end end +-- We can have a list! + +local suffixlist = { "mpxl", "mpiv", "mp" } -- no "mf" + +local function findmpfile(name,ftype) + local validtyp = validftype(ftype) + local fullname = findfile(name,validtyp) + if fullname and fulllname ~= "" then + return fullname + elseif suffix(name) == "" then + for i=1,#suffixlist do + fullname = findfile(addsuffix(name,suffixlist[i]),validtyp) + if fullname and fulllname ~= "" then + return fullname + end + end + end + return nil +end + finders.file = function(specification,name,mode,ftype) - return resolvers.findfile(name,validftype(ftype)) + return findmpfile(name,ftype) +end + +local function finder(name,mode,kind) + return findmpfile(name,kind) end local findtexfile = resolvers.findtexfile @@ -175,10 +202,6 @@ local function fileopener() end -local function finder(name,mode,kind) - return findtexfile(name,kind) -end - local overloadmode = "warning" directives.register("metapost.overloadmode",function(v) @@ -198,10 +221,13 @@ local propertycodes = { mplib.propertycodes = propertycodes +local report = logs.reporter("metafun", "log") + local function overload(property,name) if overloadmode then + local iserror = -- turn of warning after format is loaded - report_metapost("overloading %s %a",propertycodes[property] or "unknown", name) + report("overloading %s %a",propertycodes[property] or "unknown", name) -- no overload permitted if overloadmode == "error" then luatex.abort() @@ -213,15 +239,41 @@ local function overload(property,name) end end +local showcontext = mplib.showcontext + +local function handleerror(instance, message, helpinfo, interaction) + report() + report("error: %s", message) + report() + showcontext(instance) + report() + report(helpinfo) + report() + if interaction == 5 then + -- todo +-- luatex.abort() + end +end + +local function handlewarning(instance, message) + report() + report("warning: %s", message) + report() +end + function mplib.new(specification) + local instance local openfile = fileopener() specification.find_file = finder specification.run_logger = logger specification.run_overload = overload + specification.run_error = function(...) handleerror (instance,...) end + specification.run_warning = function(...) handlewarning(instance,...) end specification.open_file = openfile specification.interaction = "silent" + specification.job_name = tex.jobname -- mandate in order to get something back specification.halt_on_error = true - local instance = new_instance(specification) + instance = new_instance(specification) return instance, openfile("terminal") end diff --git a/tex/context/base/mkxl/mlib-lmp.lmt b/tex/context/base/mkxl/mlib-lmp.lmt index ff9682e87..19288b32b 100644 --- a/tex/context/base/mkxl/mlib-lmp.lmt +++ b/tex/context/base/mkxl/mlib-lmp.lmt @@ -10,45 +10,51 @@ if not modules then modules = { } end modules ['mlib-lmp'] = { local type = type -local aux = mp.aux -local mpnumeric = aux.numeric -local mppair = aux.pair +local aux = mp.aux +local mpnumeric = aux.numeric +local mppair = aux.pair + +local registerscript = metapost.registerscript + +local scan = mp.scan +local get = mp.get +local scannumber = scan.number +local scanstring = scan.string +local scanpath = scan.path +local scanproperty = scan.property +local gethashentry = get.hashentry local p = nil local n = 0 -local function mf_path_reset() +registerscript("pathreset", function() p = nil n = 0 -end +end) -local scan = mp.scan -local scannumber = scan.number -local scanpath = scan.path - -local function mf_path_length() +registerscript("pathlengthof", function() p = scanpath() n = p and #p or 1 mpnumeric(n) -end +end) -local function mf_path_point() +registerscript("pathpointof", function() local i = scannumber() if i > 0 and i <= n then local pi = p[i] mppair(pi[1],pi[2]) end -end +end) -local function mf_path_left() +registerscript("pathleftof", function() local i = scannumber() if i > 0 and i <= n then local pi = p[i] mppair(pi[5],pi[6]) end -end +end) -local function mf_path_right() +registerscript("pathrightof", function() local i = scannumber() if i > 0 and i <= n then local pn @@ -59,12 +65,26 @@ local function mf_path_right() end mppair(pn[3],pn[4]) end -end +end) -local registerscript = metapost.registerscript +local report = logs.reporter("metapost", "log") +local codes = metapost.codes +local types = metapost.types +local procodes = mplib.propertycodes -registerscript("pathreset", mf_path_reset) -registerscript("pathlengthof", mf_path_length) -registerscript("pathpointof", mf_path_point) -registerscript("pathleftof", mf_path_left) -registerscript("pathrightof", mf_path_right) +registerscript("showproperty", function() + local k, s, p, d = scanproperty() + if k then + report("name %a, property %a, command %a, detail %a",s,procodes[p] or "-",codes[k] or "-",types[d] or "-") + end +end) + +registerscript("showhashentry", function() + local s = scanstring() + if s then + local k, p, d = gethashentry(s) + if k then + report("name %a, property %a, command %a, detail %a",s,procodes[p] or "-",codes[k] or "-",types[d] or "-") + end + end +end) diff --git a/tex/context/base/mkxl/mlib-lua.lmt b/tex/context/base/mkxl/mlib-lua.lmt index c4a1965a2..cb2718f9b 100644 --- a/tex/context/base/mkxl/mlib-lua.lmt +++ b/tex/context/base/mkxl/mlib-lua.lmt @@ -20,6 +20,7 @@ metapost.types = types local scan = mp.scan local skip = mp.skip +local get = mp.get local inject = mp.inject local currentmpx = nil @@ -29,6 +30,7 @@ local scan_next = mplib.scan_next local scan_expression = mplib.scan_expression local scan_token = mplib.scan_token local scan_symbol = mplib.scan_symbol +local scan_property = mplib.scan_property local scan_numeric = mplib.scan_numeric local scan_integer = mplib.scan_integer local scan_boolean = mplib.scan_boolean @@ -42,10 +44,13 @@ local scan_pen = mplib.scan_pen local skip_token = mplib.skip_token +local get_hashentry = mplib.gethashentry + scan.next = function(k) return scan_next (currentmpx,k) end scan.expression = function(k) return scan_expression(currentmpx,k) end scan.token = function(k) return scan_token (currentmpx,k) end scan.symbol = function(k,e) return scan_symbol (currentmpx,k,e) end +scan.property = function(k) return scan_property (currentmpx,k) end scan.numeric = function() return scan_numeric (currentmpx) end scan.integer = function() return scan_integer (currentmpx) end scan.boolean = function() return scan_boolean (currentmpx) end @@ -59,6 +64,8 @@ scan.pen = function(t) return scan_pen (currentmpx,t) end skip.token = function(t) return skip_token (currentmpx,t) end +get.hashentry = function(n) return get_hashentry (currentmpx,n) end + local solvepath = mplib.solvepath local getstatus = mplib.getstatus diff --git a/tex/context/base/mkxl/mlib-run.lmt b/tex/context/base/mkxl/mlib-run.lmt index 2af504feb..8ab998bb8 100644 --- a/tex/context/base/mkxl/mlib-run.lmt +++ b/tex/context/base/mkxl/mlib-run.lmt @@ -90,11 +90,23 @@ local function prepareddata(data) end end +-- local function executempx(mpx,data) +-- local terminal = mpxterminals[mpx] +-- if terminal then +-- terminal.writer(data) +-- data = "" +-- elseif type(data) == "table" then +-- data = prepareddata(data,collapse) +-- end +-- metapost.nofruns = metapost.nofruns + 1 +-- return mpx:execute(data) +-- end + local function executempx(mpx,data) local terminal = mpxterminals[mpx] if terminal then terminal.writer(data) - data = "" + data = nil elseif type(data) == "table" then data = prepareddata(data,collapse) end @@ -184,15 +196,16 @@ function metapost.load(name,method) end method = method and methods[method] or "scaled" local mpx, terminal = new_instance { - ini_version = true, - math_mode = method, - run_script = metapost.runscript, - script_error = metapost.scripterror, - make_text = metapost.maketext, - extensions = 1, - -- random_seed = seed, - utf8_mode = true, - text_mode = true, +-- noninteractive = true; +-- ini_version = true, + math_mode = method, + run_script = metapost.runscript, + script_error = metapost.scripterror, + make_text = metapost.maketext, + extensions = 1, + -- random_seed = seed, + utf8_mode = true, + text_mode = true, } report_metapost("initializing number mode %a",method) local result @@ -219,7 +232,7 @@ function metapost.checkformat(mpsinput,method) -- if foundfile == "" then -- foundfile = find_file(file.replacesuffix(mpsinput,"mpvi")) or "" -- end - if CONTEXTLMTXMODE > 0 and foundfile == "" then + if foundfile == "" then foundfile = find_file(file.replacesuffix(mpsinput,"mpxl")) or "" end if foundfile == "" then diff --git a/tex/context/base/mkxl/mlib-scn.lmt b/tex/context/base/mkxl/mlib-scn.lmt index 64e5d9763..4c022ea5b 100644 --- a/tex/context/base/mkxl/mlib-scn.lmt +++ b/tex/context/base/mkxl/mlib-scn.lmt @@ -45,6 +45,7 @@ local scannext = scanners.next local scanexpression = scanners.expression local scantoken = scanners.token local scansymbol = scanners.symbol +local scanproperty = scanners.property local scannumeric = scanners.numeric local scannumber = scanners.number local scaninteger = scanners.integer diff --git a/tex/context/base/mkxl/mlib-svg.lmt b/tex/context/base/mkxl/mlib-svg.lmt index 4c4122476..dca2b6d19 100644 --- a/tex/context/base/mkxl/mlib-svg.lmt +++ b/tex/context/base/mkxl/mlib-svg.lmt @@ -83,7 +83,7 @@ local P, S, R, C, Ct, Cs, Cc, Cp, Cg, Cf, Carg = lpeg.P, lpeg.S, lpeg.R, lpeg.C, local lpegmatch, lpegpatterns = lpeg.match, lpeg.patterns local sqrt, abs = math.sqrt, math.abs local concat, setmetatableindex, sortedhash = table.concat, table.setmetatableindex, table.sortedhash -local gmatch, gsub, find, match, rep = string.gmatch, string.gsub, string.find, string.match, string.rep +local gmatch, gsub, find, match = string.gmatch, string.gsub, string.find, string.match local formatters, fullstrip = string.formatters, string.fullstrip local utfsplit, utfbyte = utf.split, utf.byte @@ -124,14 +124,7 @@ local trace_text = false trackers.register("metapost.svg.text", function(v) local trace_path = false trackers.register("metapost.svg.path", function(v) trace_path = v end) local trace_result = false trackers.register("metapost.svg.result", function(v) trace_result = v end) local trace_colors = false trackers.register("metapost.svg.colors", function(v) trace_colors = v end) - -local pathtracer = { - ["stroke"] = "darkred", - ["stroke-opacity"] = ".5", - ["stroke-width"] = ".5", - ["fill"] = "darkgray", - ["fill-opacity"] = ".75", -} +local trace_fonts = false trackers.register("metapost.svg.fonts", function(v) trace_fonts = v end) -- This is just an experiment. Todo: reset hash etc. Also implement -- an option handler. @@ -301,7 +294,7 @@ local p_digit = lpegpatterns.digit local p_hexdigit = lpegpatterns.hexdigit local p_space = lpegpatterns.whitespace -local factors = { +local factors = { ["pt"] = 1.25, ["mm"] = 3.543307, ["cm"] = 35.43307, @@ -312,76 +305,88 @@ local factors = { ["ex"] = 8 * 1.25, } +metapost.svgfactors = factors + local percentage_r = 1/100 local percentage_x = percentage_r local percentage_y = percentage_r --- incredible: we can find .123.456 => 0.123 0.456 ... - -local p_command_x = C(S("Hh")) -local p_command_y = C(S("Vv")) -local p_command_xy = C(S("CcLlMmQqSsTt")) -local p_command_a = C(S("Aa")) -local p_command = C(S("Zz")) - -local p_optseparator = S("\t\n\r ,")^0 -local p_separator = S("\t\n\r ,")^1 -local p_number = (S("+-")^0 * (p_digit^0 * P(".") * p_digit^1 + p_digit^1 * P(".") + p_digit^1)) - * (P("e") * S("+-")^0 * p_digit^1)^-1 - -local function convert (n) n = tonumber(n) return n end -local function convert_r (n,u) n = tonumber(n) if u == true then return percentage_r * n elseif u then return u * n else return n end end -local function convert_x (n,u) n = tonumber(n) if u == true then return percentage_x * n elseif u then return u * n else return n end end -local function convert_y (n,u) n = tonumber(n) if u == true then return percentage_y * n elseif u then return u * n else return n end end -local function convert_vx(n,u) n = tonumber(n) if u == true then return percentage_x * n elseif u then return u * n else return n end end -local function convert_vy(n,u) n = - tonumber(n) if u == true then return percentage_y * n elseif u then return u * n else return n end end - -local p_unit = (P("p") * S("txc") + P("e") * S("xm") + S("mc") * P("m") + P("in")) / factors -local p_percent = P("%") * Cc(true) - -local c_number_n = C(p_number) -local c_number_u = C(p_number) * (p_unit + p_percent)^-1 - -local p_number_n = c_number_n / convert -local p_number_x = c_number_u / convert_x -local p_number_vx = c_number_u / convert_vx -local p_number_y = c_number_u / convert_y -local p_number_vy = c_number_u / convert_vy -local p_number_r = c_number_u / convert_r - -local function asnumber (s) return s and lpegmatch(p_number, s) or 0 end -local function asnumber_r (s) return s and lpegmatch(p_number_r, s) or 0 end -local function asnumber_x (s) return s and lpegmatch(p_number_x, s) or 0 end -local function asnumber_y (s) return s and lpegmatch(p_number_y, s) or 0 end -local function asnumber_vx(s) return s and lpegmatch(p_number_vx,s) or 0 end -local function asnumber_vy(s) return s and lpegmatch(p_number_vy,s) or 0 end - -local p_number_vx_t = Ct { (p_number_vx + p_separator)^1 } -local p_number_vy_t = Ct { (p_number_vy + p_separator)^1 } - -local zerotable = { 0 } - -local function asnumber_vx_t(s) return s and lpegmatch(p_number_vx_t,s) or zerotable end -local function asnumber_vy_t(s) return s and lpegmatch(p_number_vy_t,s) or zerotable end - -local p_numbersep = p_number_n + p_separator -local p_numbers = p_optseparator * P("(") * p_numbersep^0 * p_optseparator * P(")") -local p_fournumbers = p_numbersep^4 -local p_path = Ct ( ( - p_command_xy * (p_optseparator * p_number_vx * - p_optseparator * p_number_vy )^1 - + p_command_x * (p_optseparator * p_number_vx )^1 - + p_command_y * (p_optseparator * p_number_vy )^1 - + p_command_a * (p_optseparator * p_number_vx * - p_optseparator * p_number_vy * - p_optseparator * p_number_r * - p_optseparator * p_number_n * -- flags - p_optseparator * p_number_n * -- flags - p_optseparator * p_number_vx * - p_optseparator * p_number_vy )^1 - + p_command - + p_separator -)^1 ) +local asnumber, asnumber_r, asnumber_x, asnumber_y, asnumber_vx, asnumber_vy +local asnumber_vx_t, asnumber_vy_t +local p_number, p_separator, p_optseparator, p_numbers, p_fournumbers, p_path +local p_number_n, p_number_x, p_number_vx, p_number_y, p_number_vy, p_number_r + +do + + -- incredible: we can find .123.456 => 0.123 0.456 ... + + local p_command_x = C(S("Hh")) + local p_command_y = C(S("Vv")) + local p_command_xy = C(S("CcLlMmQqSsTt")) + local p_command_a = C(S("Aa")) + local p_command = C(S("Zz")) + + p_optseparator = S("\t\n\r ,")^0 + p_separator = S("\t\n\r ,")^1 + p_number = (S("+-")^0 * (p_digit^0 * P(".") * p_digit^1 + p_digit^1 * P(".") + p_digit^1)) + * (P("e") * S("+-")^0 * p_digit^1)^-1 + + local function convert (n) n = tonumber(n) return n end + local function convert_r (n,u) n = tonumber(n) if u == true then return percentage_r * n elseif u then return u * n else return n end end + local function convert_x (n,u) n = tonumber(n) if u == true then return percentage_x * n elseif u then return u * n else return n end end + local function convert_y (n,u) n = tonumber(n) if u == true then return percentage_y * n elseif u then return u * n else return n end end + local function convert_vx(n,u) n = tonumber(n) if u == true then return percentage_x * n elseif u then return u * n else return n end end + local function convert_vy(n,u) n = - tonumber(n) if u == true then return percentage_y * n elseif u then return u * n else return n end end + + local p_unit = (P("p") * S("txc") + P("e") * S("xm") + S("mc") * P("m") + P("in")) / factors + local p_percent = P("%") * Cc(true) + + local c_number_n = C(p_number) + local c_number_u = C(p_number) * (p_unit + p_percent)^-1 + + p_number_n = c_number_n / convert + p_number_x = c_number_u / convert_x + p_number_vx = c_number_u / convert_vx + p_number_y = c_number_u / convert_y + p_number_vy = c_number_u / convert_vy + p_number_r = c_number_u / convert_r + + asnumber = function(s) return s and lpegmatch(p_number, s) or 0 end + asnumber_r = function(s) return s and lpegmatch(p_number_r, s) or 0 end + asnumber_x = function(s) return s and lpegmatch(p_number_x, s) or 0 end + asnumber_y = function(s) return s and lpegmatch(p_number_y, s) or 0 end + asnumber_vx = function(s) return s and lpegmatch(p_number_vx,s) or 0 end + asnumber_vy = function(s) return s and lpegmatch(p_number_vy,s) or 0 end + + local p_number_vx_t = Ct { (p_number_vx + p_separator)^1 } + local p_number_vy_t = Ct { (p_number_vy + p_separator)^1 } + + local zerotable = { 0 } + + asnumber_vx_t = function(s) return s and lpegmatch(p_number_vx_t,s) or zerotable end + asnumber_vy_t = function(s) return s and lpegmatch(p_number_vy_t,s) or zerotable end + + local p_numbersep = p_number_n + p_separator + p_numbers = p_optseparator * P("(") * p_numbersep^0 * p_optseparator * P(")") + p_fournumbers = p_numbersep^4 + p_path = Ct ( ( + p_command_xy * (p_optseparator * p_number_vx * + p_optseparator * p_number_vy )^1 + + p_command_x * (p_optseparator * p_number_vx )^1 + + p_command_y * (p_optseparator * p_number_vy )^1 + + p_command_a * (p_optseparator * p_number_vx * + p_optseparator * p_number_vy * + p_optseparator * p_number_r * + p_optseparator * p_number_n * -- flags + p_optseparator * p_number_n * -- flags + p_optseparator * p_number_vx * + p_optseparator * p_number_vy )^1 + + p_command + + p_separator + )^1 ) + + +end -- We can actually use the svg color definitions from the tex end but maybe a user -- doesn't want those replace the normal definitions. @@ -1365,6 +1370,14 @@ do -- ["vkern"] = true, } + local pathtracer = { + ["stroke"] = "darkred", + ["stroke-opacity"] = ".5", + ["stroke-width"] = ".5", + ["fill"] = "darkgray", + ["fill-opacity"] = ".75", + } + local function handlechains(c) if tags[c.tg] then local at = c.at @@ -1769,7 +1782,8 @@ do end end - local uselevel = 0 + local uselevel = 0 + local bodyfontscale = 1 function handlers.use(c) local at = c.at @@ -1826,12 +1840,19 @@ do local f_do_fill = f_do_fill_c local f_eo_fill = f_eo_fill_c local f_no_fill = f_no_fill_c - local s_clip_start = 'draw image (' - local f_clip_stop_c = formatters[') ; clip currentpicture to (%s..cycle) ;'] - local f_clip_stop_l = formatters[') ; clip currentpicture to (%s--cycle) ;'] +-- local s_clip_start = 'draw image (' +-- local f_clip_stop_c = formatters[') ; clip currentpicture to (%s..cycle) ;'] +-- local f_clip_stop_l = formatters[') ; clip currentpicture to (%s--cycle) ;'] +-- local f_clip_stop = f_clip_stop_c +-- local f_eoclip_stop_c = formatters[') ; eoclip currentpicture to (%s..cycle) ;'] +-- local f_eoclip_stop_l = formatters[') ; eoclip currentpicture to (%s--cycle) ;'] +-- local f_eoclip_stop = f_eoclip_stop_c + local s_clip_start = 'save p ; picture p ; p := image (' + local f_clip_stop_c = formatters[') ; clip p to (%s..cycle) ; draw p ;'] + local f_clip_stop_l = formatters[') ; clip p to (%s--cycle) ; draw p ;'] local f_clip_stop = f_clip_stop_c - local f_eoclip_stop_c = formatters[') ; eoclip currentpicture to (%s..cycle) ;'] - local f_eoclip_stop_l = formatters[') ; eoclip currentpicture to (%s--cycle) ;'] + local f_eoclip_stop_c = formatters[') ; eoclip p to (%s..cycle) ; draw p ;'] + local f_eoclip_stop_l = formatters[') ; eoclip p to (%s--cycle) ; draw p ;'] local f_eoclip_stop = f_eoclip_stop_c -- could be shared and then beginobject | endobject @@ -2537,7 +2558,8 @@ do local f_styled = formatters["\\svgstyled{%s}{%s}{%s}{%s}"] local f_colored = formatters["\\svgcolored{%.3N}{%.3N}{%.3N}{"] - local f_placed = formatters["\\svgplaced{%.3N}{%.3N}{}{"] +-- local f_placed = formatters["\\svgplaced{%.3N}{%.3N}{}{"] +local f_placed = formatters["\\svgplaced{%s}{%s}{}{"] local f_poschar = formatters["\\svgposchar{%.3N}{%.3N}{%s}"] local f_char = formatters["\\svgchar{%s}"] @@ -2606,20 +2628,32 @@ do -- ax = ax and asnumber_vx(ax) or x ay = ay and asnumber_vy(ay) or y - dx = dx and asnumber_vx(dx) or 0 - dy = dy and asnumber_vy(dy) or 0 + -- +local d_x = dx and asnumber_vx(dx) or 0 +local d_y = dy and asnumber_vy(dy) or 0 -- if v_family then v_family = cssfamily(v_family) end if v_style then v_style = cssstyle (v_style) end if v_weight then v_weight = cssweight(v_weight) end - if v_size then v_size = csssize (v_size,factors) end + if v_size then v_size = csssize (v_size,factors) or tonumber(v_size) end + -- + if not v_family then v_family = family end + if not v_weight then v_weight = "normal" end + if not v_style then v_style = "normal" end + -- + if v_family then + v_family = fonts.names.cleanname(v_family) + v_family = checkedfamily(v_family) + end + -- + usedfonts[v_family][v_weight][v_style] = true -- ax = ax - x ay = ay - y -- local elayered = ax ~= 0 or ay ~= 0 or false - local eplaced = dx ~= 0 or dy ~= 0 or false - +-- local eplaced = dx ~= 0 or dy ~= 0 or false +local eplaced = d_x ~= 0 or d_y ~= 0 or false local usedsize, usedscaled if elayered then @@ -2633,30 +2667,30 @@ do usedsize = v_size or size usedscale = (usedsize / defaultsize) / scale end - -- - -- print("element ",c.tg) - -- print(" layered ",elayered) - -- print(" font size ",v_size) - -- print(" parent size ",size) - -- print(" parent scale",scale) - -- print(" used size ",usedsize) - -- print(" used scale ",usedscale) +usedscale = (10 / bodyfontscale) * usedscale -- if eplaced then +if dx then + if not find(dx,"%a") then + dx = dx .. "bp" + elseif find(dx,"e") then + dx = formatters["%s\\dimexpr %s\\relax"](usedscale,dx) + end +else + dx = "0pt" +end +if dy then + if not find(dy,"%a") then + dy = dy .. "bp" + elseif find(dy,"e") then + dy = formatters["%s\\dimexpr %s\\relax"](usedscale,dy) + end +else + dy = "0pt" +end t[#t+1] = f_placed(dx,dy) end -- - if not v_family then v_family = family end - if not v_weight then v_weight = "normal" end - if not v_style then v_style = "normal" end - -- - if v_family then - v_family = fonts.names.cleanname(v_family) - v_family = checkedfamily(v_family) - end - -- - usedfonts[v_family][v_weight][v_style] = true - -- -- if usedscale == 1 then -- t[#t+1] = f_normal( v_family,v_weight,v_style) -- else @@ -2664,6 +2698,18 @@ do -- end t[#t+1] = "{" -- + if trace_fonts then + report("element : %s",c.tg) + report(" font family : %s",v_family) + report(" font weight : %s",v_weight) + report(" font style : %s",v_style) + report(" parent size : %s",size) + report(" parent scale : %s",scale) + report(" used size : %s",usedsize) + report(" used scale : %s",usedscale) + report(" layered : %l",elayered) + end + -- local ecolored = v_fill and v_fill ~= "" or false if ecolored then -- todo cmyk @@ -2741,9 +2787,15 @@ do local x = rawget(at,"x") local y = rawget(at,"y") +-- local dx = rawget(at,"dx") +-- local dy = rawget(at,"dy") + local tx = asnumber_vx_t(x) local ty = asnumber_vy_t(y) +-- dx = dx and asnumber_vx(dx) or 0 +-- dy = dy and asnumber_vy(dy) or 0 + x = tx[1] or 0 -- catch bad x/y spec y = ty[1] or 0 -- catch bad x/y spec @@ -2754,6 +2806,8 @@ do local color, opacity, invisible = fillproperties(v_fill,at) local anchor = anchors[at["text-anchor"] or "start"] or "drt" local r = metapost.remappedtext(only) +-- x = x + dx +-- y = y + dy if r then if x == 0 and y == 0 then only = f_mapped_simple_svg(r.index) @@ -2827,7 +2881,7 @@ do end function handlers.svg(c,x,y,w,h,noclip,notransform,normalize) - local at = c.at + local at = c.at local wrapupviewport local bhacked @@ -2838,6 +2892,8 @@ do local btransform, etransform, transform = handletransform(at) +bodyfontscale = tex.getdimen("bodyfontsize") / 65536 + if trace then report("view: %s, xpct %N, ypct %N","before",percentage_x,percentage_y) end diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 256bf1175..479ac5491 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 : 2020-12-15 10:10 +-- merge date : 2020-12-18 18:28 do -- begin closure to overcome local limits and interference -- cgit v1.2.3