From 28351dce705d3546bc4a67b554ee474d2f3cce4a Mon Sep 17 00:00:00 2001
From: Hans Hagen
We use a metatable to intercept errors. When no key is found in @@ -148,11 +150,18 @@ function string:todimen() return self else local value, unit = lpegmatch(pattern,self) - print(value,unit) return value/unit end end +local amount = S("+-")^0 * R("09")^0 * S(".,")^0 * R("09")^0 +local unit = P("pt") + P("cm") + P("mm") + P("sp") + P("bp") + P("in") + + P("pc") + P("dd") + P("cc") + P("nd") + P("nc") + +local pattern = amount * unit + +lpeg.patterns.validdimen = pattern + --[[ldx--
This converter accepts calls like:
diff --git a/tex/context/base/m-barcodes.mkiv b/tex/context/base/m-barcodes.mkiv index 1c352dd54..b0eae1485 100644 --- a/tex/context/base/m-barcodes.mkiv +++ b/tex/context/base/m-barcodes.mkiv @@ -31,11 +31,13 @@ \usePSTRICKSmodule[pst-barcode] +\definefont[barcodefont][file:ocrb10] +% \definefont[barcodefont][file:texgyreheros-regular] + \startluacode plugins.barcodes = { } -function plugins.barcodes.strip(original) - local code = string.gsub(original,"%-","") +local function split(code) local t = { string.byte(code,1,#code) } if #t >= 12 then local s = 0 @@ -47,6 +49,14 @@ function plugins.barcodes.strip(original) end local m = s % 10 local c = (m > 0 and (10 - m)) or 0 + return t, s, m, c + end +end + +function plugins.barcodes.isbn_1(original) + local code = string.gsub(original,"%-","") + local t, s, m, c = split(code) + if t then if #t == 13 then local e = ((c == t[13] - 48) and "correct") or "wrong" logs.report("isbn code","code=%s, sum=%s, checksum=%s, modulo=%s, status=%s",original,s,m,c,e) @@ -57,24 +67,40 @@ function plugins.barcodes.strip(original) end tex.sprint(code) end + +function plugins.barcodes.isbn_2(original) + local code = string.gsub(original,"%-","") + local t, s, m, c = split(code) + if t and #t == 12 then + original = original .. "-" .. c + end + tex.sprint(original) +end \stopluacode \startsetups barcode:isbn \scale [width=5cm] { - \normalexpanded { \noexpand \setPSTRICKS { - \noexpand \pspicture(-4mm,-1mm)(38mm,26mm) - \noexpand \psbarcode { - \ctxlua{plugins.barcodes.strip("\getvariable{barcode}{code}")} - } { - includetext guardwhitespace - } { - ean13 - } - \noexpand \endpspicture + \vbox { + \hbox { + \hskip3.7mm + \scale[width=34mm]{\barcodefont ISBN \ctxlua{plugins.barcodes.isbn_2("\getvariable{barcode}{code}")}} + } + \par + \normalexpanded { \noexpand \setPSTRICKS { + \noexpand \pspicture(-4mm,-1mm)(38mm,26mm) + \noexpand \psbarcode { + \ctxlua{plugins.barcodes.isbn_1("\getvariable{barcode}{code}")} + } { + includetext guardwhitespace + } { + ean13 + } + \noexpand \endpspicture + } + \noexpand \processPSTRICKS } } - \noexpand \processPSTRICKS } } \stopsetups diff --git a/tex/context/base/mult-sys.tex b/tex/context/base/mult-sys.tex index 5a718cc60..2a7cde0e2 100644 --- a/tex/context/base/mult-sys.tex +++ b/tex/context/base/mult-sys.tex @@ -258,6 +258,12 @@ \definesystemconstant {sp} \definesystemconstant {bp} \definesystemconstant {in} +\definesystemconstant {pc} +\definesystemconstant {cm} +\definesystemconstant {dd} +\definesystemconstant {cc} +\definesystemconstant {nd} +\definesystemconstant {nc} %D These constants are used for internal and utility %D commands. diff --git a/tex/context/base/node-aux.lua b/tex/context/base/node-aux.lua index 8bbfbe918..2dbc974a1 100644 --- a/tex/context/base/node-aux.lua +++ b/tex/context/base/node-aux.lua @@ -31,14 +31,14 @@ function nodes.merge(a,b) return a, b end -local fields, whatsits = { }, { } +local fields, whatsitfields = { }, { } for k, v in pairs(node.types()) do if v == "whatsit" then fields[k], fields[v] = { }, { } for kk, vv in pairs(node.whatsits()) do local f = node_fields(k,kk) - whatsits[kk], whatsits[vv] = f, f + whatsitfields[kk], whatsitfields[vv] = f, f end else local f = node_fields(k) @@ -46,11 +46,69 @@ for k, v in pairs(node.types()) do end end -nodes.fields, nodes.whatsits = fields, whatsits +nodes.fields, nodes.whatsitfields = fields, whatsitfields function nodes.info(n) - logs.report(format("%14s","type"),node.type(n.id)) - for k,v in pairs(fields[n.id]) do + local id = n.id + local tp = node.type(id) + local list = (tp == "whatsit" and whatsitfields[n.subtype]) or fields[id] + logs.report(format("%14s","type"),tp) + for k,v in pairs(list) do logs.report(format("%14s",v),gsub(gsub(tostring(n[v]),"%s+"," "),"node ","")) end end + +-- history: +-- +-- local function cp_skipable(a,id) -- skipable nodes at the margins during character protrusion +-- return ( +-- id ~= glyph_node +-- or id == ins_node +-- or id == mark_node +-- or id == adjust_node +-- or id == penalty_node +-- or (id == glue_node and a.spec == 0) +-- or (id == disc_node and a.pre == nil and a.post == nil and a.replace == nil) +-- or (id == math_node and a.surround == 0) +-- or (id == kern_node and (a.kern == 0 or a.subtype == NORMAL)) +-- or (id == hlist_node and a.width == 0 and a.height == 0 and a.depth == 0 and a.list == nil) +-- or (id == whatsit_node and a.subtype ~= pdf_refximage_node and a.subtype ~= pdf_refxform_node) +-- ) +-- end +-- +-- local function glyph_width(a) +-- local ch = chardata[a.font][a.char] +-- return (ch and ch.width) or 0 +-- end +-- +-- local function glyph_total(a) +-- local ch = chardata[a.font][a.char] +-- return (ch and (ch.height+ch.depth)) or 0 +-- end +-- +-- local function non_discardable(a) -- inline +-- return a.id < math_node -- brrrr +-- end +-- +-- local function calculate_badness(t,s) +-- if t == 0 then +-- return 0 +-- elseif s <= 0 then +-- return INF_BAD +-- else +-- local r +-- if t <= 7230584 then +-- r = t * 297 / s +-- elseif s >= 1663497 then +-- r = t / floor(s / 297) +-- else +-- r = t +-- end +-- r = floor(r) +-- if r > 1290 then +-- return INF_BAD +-- else +-- return floor((r * r * r + 0x20000) / 0x40000) -- 0400000 / 01000000 +-- end +-- end +-- end diff --git a/tex/context/base/node-ini.mkiv b/tex/context/base/node-ini.mkiv index 227533413..eea9ed16a 100644 --- a/tex/context/base/node-ini.mkiv +++ b/tex/context/base/node-ini.mkiv @@ -18,6 +18,7 @@ \newcount\filterstate \filterstate\plusone \registerctxluafile{node-ini}{1.001} +\registerctxluafile{node-mir}{1.001} \registerctxluafile{node-aux}{1.001} \registerctxluafile{node-tst}{1.001} \registerctxluafile{node-tra}{1.001} % we might split it off (module) diff --git a/tex/context/base/node-res.lua b/tex/context/base/node-res.lua index 47f0c8d60..f30f6db1e 100644 --- a/tex/context/base/node-res.lua +++ b/tex/context/base/node-res.lua @@ -64,7 +64,7 @@ local penalty = nodes.register(new_node("penalty")) local glue = nodes.register(new_node("glue")) local glue_spec = nodes.register(new_node("glue_spec")) local glyph = nodes.register(new_node("glyph",0)) -local textdir = nodes.register(new_node("whatsit",whatsits.dir)) -- 7 +local textdir = nodes.register(new_node("whatsit",whatsits.dir)) -- 7 (6 is local par node) local rule = nodes.register(new_node("rule")) local latelua = nodes.register(new_node("whatsit",whatsits.late_lua)) -- 35 local user_n = nodes.register(new_node("whatsit",whatsits.user_defined)) user_n.type = 100 -- 44 diff --git a/tex/context/base/spac-ver.mkiv b/tex/context/base/spac-ver.mkiv index efeb54c8f..3c3010340 100644 --- a/tex/context/base/spac-ver.mkiv +++ b/tex/context/base/spac-ver.mkiv @@ -154,8 +154,14 @@ % {\assignvalue{#1}\currentrelativeinterlinespace{1.00}{1.25}{1.50}% % \spacing\currentrelativeinterlinespace} +% \def\dosetspecifiedrelativeinterlinespace#1% fragile? +% {\doifdimensionelse{#1} +% {\setupspecifiedinterlinespace[\c!line=#1]} +% {\assignvalue{#1}\currentrelativeinterlinespace{1.00}{1.25}{1.50}% +% \spacing\currentrelativeinterlinespace}} + \def\dosetspecifiedrelativeinterlinespace#1% fragile? - {\doifdimensionelse{#1} + {\doifdimenstringelse{#1} {\setupspecifiedinterlinespace[\c!line=#1]} {\assignvalue{#1}\currentrelativeinterlinespace{1.00}{1.25}{1.50}% \spacing\currentrelativeinterlinespace}} diff --git a/tex/context/base/syst-aux.mkiv b/tex/context/base/syst-aux.mkiv index 95d260750..dbc679672 100644 --- a/tex/context/base/syst-aux.mkiv +++ b/tex/context/base/syst-aux.mkiv @@ -6332,6 +6332,71 @@ \expandafter\thirdoffourarguments \fi} +%D Ok, here's another one, slower but seldom used. This one scans the text. +%D +%D \starttabulate[|Tc|Tc|] +%D \NC pt \NC \doifdimenstringelse {pt}{yes}{no} \NC \NR +%D \NC 12pt \NC \doifdimenstringelse {-12pt}{yes}{no} \NC \NR +%D \NC 1pt \NC \doifdimenstringelse {1pt}{yes}{no} \NC \NR +%D \NC 12pt \NC \doifdimenstringelse {12pt}{yes}{no} \NC \NR +%D \NC 12.0pt \NC \doifdimenstringelse {12.0pt}{yes}{no} \NC \NR +%D \NC -.12pt \NC \doifdimenstringelse {-.12pt}{yes}{no} \NC \NR +%D \NC .12pt \NC \doifdimenstringelse {.12pt}{yes}{no} \NC \NR +%D \NC -12pt \NC \doifdimenstringelse {-12pt}{yes}{no} \NC \NR +%D \NC -12.0pt \NC \doifdimenstringelse{-12.0pt}{yes}{no} \NC \NR +%D \NC big \NC \doifdimenstringelse {big}{yes}{no} \NC \NR +%D \NC 10 \NC \doifdimenstringelse {10}{yes}{no} \NC \NR +%D \NC 1 \NC \doifdimenstringelse {1}{yes}{no} \NC \NR +%D \stoptabulate + +\def\doifdimenstringelse#1{\normalexpanded{\noexpand\dodimenteststageone#1}\empty\empty]} + +\def\dodimenteststageone #1#2{\csname d!1!\ifcsname d!1!#2\endcsname#2\else x\fi\endcsname#2} +\def\dodimenteststagetwo #1#2{\csname d!2!\ifcsname d!2!#2\endcsname#2\else x\fi\endcsname#2} +\def\dodimenteststagethree #1]{\csname d!3!\ifcsname d!3!#1\endcsname#1\else x\fi\endcsname} + +\expandafter\let\csname d!1!x\endcsname\dodimenteststagethree +\expandafter\let\csname d!2!x\endcsname\dodimenteststagethree +\expandafter\let\csname d!3!x\endcsname\secondoftwoarguments + +\expandafter\let\csname d!1!.\endcsname\dodimenteststagetwo +\expandafter\let\csname d!1!,\endcsname\dodimenteststagetwo +\expandafter\let\csname d!1!1\endcsname\dodimenteststageone +\expandafter\let\csname d!1!2\endcsname\dodimenteststageone +\expandafter\let\csname d!1!3\endcsname\dodimenteststageone +\expandafter\let\csname d!1!4\endcsname\dodimenteststageone +\expandafter\let\csname d!1!5\endcsname\dodimenteststageone +\expandafter\let\csname d!1!6\endcsname\dodimenteststageone +\expandafter\let\csname d!1!7\endcsname\dodimenteststageone +\expandafter\let\csname d!1!8\endcsname\dodimenteststageone +\expandafter\let\csname d!1!9\endcsname\dodimenteststageone +\expandafter\let\csname d!1!0\endcsname\dodimenteststageone + +\expandafter\let\csname d!2!1\endcsname\dodimenteststagetwo +\expandafter\let\csname d!2!2\endcsname\dodimenteststagetwo +\expandafter\let\csname d!2!3\endcsname\dodimenteststagetwo +\expandafter\let\csname d!2!4\endcsname\dodimenteststagetwo +\expandafter\let\csname d!2!5\endcsname\dodimenteststagetwo +\expandafter\let\csname d!2!6\endcsname\dodimenteststagetwo +\expandafter\let\csname d!2!7\endcsname\dodimenteststagetwo +\expandafter\let\csname d!2!8\endcsname\dodimenteststagetwo +\expandafter\let\csname d!2!9\endcsname\dodimenteststagetwo +\expandafter\let\csname d!2!0\endcsname\dodimenteststagetwo + +\expandafter\let\csname d!3!pt\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!pc\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!in\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!bp\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!cm\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!mm\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!dd\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!cc\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!sp\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!ex\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!em\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!nd\endcsname\firstoftwoarguments +\expandafter\let\csname d!3!nc\endcsname\firstoftwoarguments + %D \macros %D {comparedimension,comparedimensioneps} %D diff --git a/tex/context/base/syst-lua.lua b/tex/context/base/syst-lua.lua index bd4aad891..640282953 100644 --- a/tex/context/base/syst-lua.lua +++ b/tex/context/base/syst-lua.lua @@ -33,13 +33,17 @@ function commands.report(s,t,...) commands.writestatus("!"..s,format(t,...)) end -function commands.doifelse(b) +local function testcase(b) if b then -- faster with if than with expression texsprint(ctxcatcodes,"\\firstoftwoarguments") else texsprint(ctxcatcodes,"\\secondoftwoarguments") end end + +commands.testcase = testcase +commands.doifelse = testcase + function commands.doif(b) if b then texsprint(ctxcatcodes,"\\firstofoneargument") @@ -55,8 +59,6 @@ function commands.doifnot(b) end end -commands.testcase = commands.doifelse - function commands.boolcase(b) if b then texwrite(1) else texwrite(0) end end @@ -76,11 +78,11 @@ function commands.doifcommonelse(a,b) for i=1,#ha do for j=1,#hb do if ha[i] == hb[j] then - return commands.testcase(true) + return testcase(true) end end end - return commands.testcase(false) + return testcase(false) end function commands.doifinsetelse(a,b) @@ -88,10 +90,10 @@ function commands.doifinsetelse(a,b) if not hb then hb = lpegmatch(s,b) h[b] = hb end for i=1,#hb do if a == hb[i] then - return commands.testcase(true) + return testcase(true) end end - return commands.testcase(false) + return testcase(false) end function commands. def (cs,value) texsprint(ctxcatcodes,format( "\\def\\%s{%s}",cs,value)) end @@ -99,3 +101,9 @@ function commands.edef (cs,value) texsprint(ctxcatcodes,format("\\edef\\%s{%s} function commands.gdef (cs,value) texsprint(ctxcatcodes,format("\\gdef\\%s{%s}",cs,value)) end function commands.xdef (cs,value) texsprint(ctxcatcodes,format("\\xdef\\%s{%s}",cs,value)) end function commands.chardef(cs,value) texsprint(ctxcatcodes,format("\\chardef\\%s=%s\\relax",cs,value)) end + +local pattern = lpeg.patterns.validdimen + +function commands.doifdimenstringelse(str) + testcase(lpegmatch(pattern,str)) +end diff --git a/tex/context/base/trac-log.lua b/tex/context/base/trac-log.lua index 73ec0adb4..0d4a1b0a9 100644 --- a/tex/context/base/trac-log.lua +++ b/tex/context/base/trac-log.lua @@ -313,3 +313,8 @@ end --~ for i=1,10 do --~ logs.system(syslogname,"context","test","fonts","font %s recached due to newer version (%s)","blabla","123") --~ end + +function logs.fatal(where,...) + logs.report(where,"fatal error: %s, aborting now",format(...)) + os.exit() +end diff --git a/tex/generic/context/luatex-fonts-merged.lua b/tex/generic/context/luatex-fonts-merged.lua index 0a4a179c7..514a4e077 100644 --- a/tex/generic/context/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 03/18/10 14:42:03 +-- merge date : 03/20/10 22:59:11 do -- begin closure to overcome local limits and interference @@ -2430,7 +2430,7 @@ local penalty = nodes.register(new_node("penalty")) local glue = nodes.register(new_node("glue")) local glue_spec = nodes.register(new_node("glue_spec")) local glyph = nodes.register(new_node("glyph",0)) -local textdir = nodes.register(new_node("whatsit",whatsits.dir)) -- 7 +local textdir = nodes.register(new_node("whatsit",whatsits.dir)) -- 7 (6 is local par node) local rule = nodes.register(new_node("rule")) local latelua = nodes.register(new_node("whatsit",whatsits.late_lua)) -- 35 local user_n = nodes.register(new_node("whatsit",whatsits.user_defined)) user_n.type = 100 -- 44 -- cgit v1.2.3