diff options
Diffstat (limited to 'tex')
26 files changed, 1104 insertions, 387 deletions
diff --git a/tex/context/base/attr-eff.lua b/tex/context/base/attr-eff.lua index 023d1c51b..64a620bad 100644 --- a/tex/context/base/attr-eff.lua +++ b/tex/context/base/attr-eff.lua @@ -17,6 +17,9 @@ local settexattribute = tex.setattribute local allocate = utilities.storage.allocate local setmetatableindex = table.setmetatableindex +local variables = interfaces.variables +local v_normal = variables.normal + attributes.effects = attributes.effects or { } local effects = attributes.effects @@ -66,12 +69,22 @@ effects.handler = nodes.installattributehandler { processor = states.process, } -local function register(effect,stretch,rulethickness) - local stamp = format(template,effect,stretch,rulethickness) +local function register(specification) + local alternative, stretch, rulethickness + if specification then + alternative = specification.alternative or v_normal + stretch = specification.stretch or 0 + rulethickness = specification.rulethickness or 0 + else + alternative = v_normal + stretch = 0 + rulethickness = 0 + end + local stamp = format(template,alternative,stretch,rulethickness) local n = registered[stamp] if not n then n = #values + 1 - values[n] = { effect, stretch, rulethickness } + values[n] = { alternative, stretch, rulethickness } registered[stamp] = n end return n @@ -88,10 +101,10 @@ effects.enable = enable local enabled = false -function commands.triggereffect(effect,stretch,rulethickness) +function commands.triggereffect(specification) if not enabled then enable() enabled = true end - settexattribute(a_effect,register(effect,stretch,rulethickness)) + settexattribute(a_effect,register(specification)) end diff --git a/tex/context/base/attr-eff.mkiv b/tex/context/base/attr-eff.mkiv index c5c94537c..f76e498d9 100644 --- a/tex/context/base/attr-eff.mkiv +++ b/tex/context/base/attr-eff.mkiv @@ -17,38 +17,39 @@ \unprotect -\gdef\dotriggereffect#1#2#3% - {\ctxcommand{triggereffect('#1',#2,\number\dimexpr#3\relax)}} +\installcorenamespace{effect} -\unexpanded\def\setupeffect - {\dodoubleargument\dosetupeffect} +\installcommandhandler \??effect {effect} \??effect -\def\dosetupeffect[#1][#2]% - {\getparameters[\??et#1][#2]} +\setupeffect + [\c!method=\v!none, + \c!stretch=\zerocount, + \c!rulethickness=\zeropoint, + \c!alternative=\v!normal] -\unexpanded\def\defineeffect - {\dodoubleargument\dodefineeffect} - -\def\dodefineeffect[#1][#2]% - {\getparameters[\??et#1][\c!method=\v!none,\c!stretch=0,\c!rulethickness=\zeropoint,\c!alternative=\v!normal,#2]% - \doif{\getvalue{\??et#1\c!method}}\v!command - {\setugvalue{\e!start#1}{\starteffect[#1]}% - \setugvalue{\e!stop #1}{\stopeffect}}} - -% yes or no grouped +\appendtoks + \edef\p_method{\effectparameter\c!command}% + \ifx\p_method\v!command + \setuxvalue{\e!start\currenteffect}{\starteffect[#1]}% + \setuxvalue{\e!stop \currenteffect}{\stopeffect}% + \fi +\to \everydefineeffect \unexpanded\def\starteffect[#1]% - {\dotriggereffect - {\csname\??et#1\c!alternative \endcsname}% - {\csname\??et#1\c!stretch \endcsname}% - {\csname\??et#1\c!rulethickness\endcsname}} + {\ctxcommand{triggereffect{ + alternative = "\namedeffectparameter{#1}\c!alternative", + stretch = \number\namedeffectparameter{#1}\c!stretch, + rulethickness = \number\dimexpr\namedeffectparameter{#1}\c!rulethickness\relax + }}} \unexpanded\def\stopeffect % can be special - {\dotriggereffect\v!normal0\zeropoint} + {\ctxcommand{triggereffect()}} % v!normal 0 0 \unexpanded\def\effect[#1]% {\groupedcommand{\starteffect[#1]}{\stopeffect}} +% yes or no grouped + \defineeffect [\v!inner] [\c!alternative=\v!inner,\c!rulethickness=.25pt] \defineeffect [\v!outer] [\c!alternative=\v!outer,\c!rulethickness=.25pt] \defineeffect [\v!both] [\c!alternative=\v!both, \c!rulethickness=.25pt] diff --git a/tex/context/base/attr-lay.lua b/tex/context/base/attr-lay.lua index 75505d4c4..e154ee90d 100644 --- a/tex/context/base/attr-lay.lua +++ b/tex/context/base/attr-lay.lua @@ -12,7 +12,7 @@ if not modules then modules = { } end modules ['attr-lay'] = { local type = type local format = string.format -local insert, remove = table.insert, table.remove +local insert, remove, concat = table.insert, table.remove, table.concat local allocate = utilities.storage.allocate local setmetatableindex = table.setmetatableindex @@ -61,12 +61,26 @@ storage.register("attributes/viewerlayers/registered", viewerlayers.registered, storage.register("attributes/viewerlayers/values", viewerlayers.values, "attributes.viewerlayers.values") storage.register("attributes/viewerlayers/scopes", viewerlayers.scopes, "attributes.viewerlayers.scopes") -local data = viewerlayers.data -local values = viewerlayers.values -local listwise = viewerlayers.listwise -local registered = viewerlayers.registered -local scopes = viewerlayers.scopes -local template = "%s" +local data = viewerlayers.data +local values = viewerlayers.values +local listwise = viewerlayers.listwise +local registered = viewerlayers.registered +local scopes = viewerlayers.scopes +local template = "%s" + +local layerstacker = utilities.stacker.new("layers") -- experiment + +layerstacker.mode = "stack" +layerstacker.unset = attributes.unsetvalue + +viewerlayers.resolve_begin = layerstacker.resolve_begin +viewerlayers.resolve_step = layerstacker.resolve_step +viewerlayers.resolve_end = layerstacker.resolve_end + +function commands.cleanuplayers() + layerstacker.clean() + -- todo +end -- stacked @@ -94,6 +108,39 @@ end setmetatableindex(viewerlayers, extender) setmetatableindex(viewerlayers.data, reviver) +function layerstacker.start(s,t,first,last) -- move to lpdf-ren.lua + local r = { } + for i=first,last do + r[#r+1] = codeinjections.startlayer(values[t[i]]) + end + r = concat(r," ") +-- print("start",r) + return nodes.pool.pdfliteral(r) +end + +function layerstacker.stop(s,t,first,last) -- move to lpdf-ren.lua + local r = { } + for i=last,first,-1 do + r[#r+1] = codeinjections.stoplayer() + end + r = concat(r," ") +-- print("stop",r) + return nodes.pool.pdfliteral(r) +end + +function layerstacker.change(s,t1,first1,last1,t2,first2,last2) -- move to lpdf-ren.lua + local r = { } + for i=last1,first1,-1 do + r[#r+1] = codeinjections.stoplayer() + end + for i=first2,last2 do + r[#r+1] = codeinjections.startlayer(values[t2[i]]) + end + r = concat(r," ") +-- print("change",r) + return nodes.pool.pdfliteral(r) +end + local function initializer(...) return states.initialize(...) end @@ -103,7 +150,8 @@ attributes.viewerlayers.handler = nodes.installattributehandler { namespace = viewerlayers, initializer = initializer, finalizer = states.finalize, - processor = states.stacked, +-- processor = states.stacked, + processor = states.stacker, } local stack, enabled, global = { }, false, false @@ -149,9 +197,16 @@ function viewerlayers.setfeatures(hasorder) viewerlayers.hasorder = hasorder end +local usestacker = true -- new, experimental + function viewerlayers.start(name) - insert(stack,texgetattribute(a_viewerlayer)) - local a = register(name) or unsetvalue + local a + if usestacker then + a = layerstacker.push(register(name) or unsetvalue) + else + insert(stack,texgetattribute(a_viewerlayer)) + a = register(name) or unsetvalue + end if global or scopes[name] == v_global then scopes[a] = v_global -- messy but we don't know the attributes yet texsetattribute("global",a_viewerlayer,a) @@ -162,7 +217,12 @@ function viewerlayers.start(name) end function viewerlayers.stop() - local a = remove(stack) + local a + if usestacker then + a = layerstacker.pop() + else + a = remove(stack) + end if not a then -- error elseif a >= 0 then @@ -171,7 +231,7 @@ function viewerlayers.stop() else texsetattribute(a_viewerlayer,a) end - texsettokenlist("currentviewerlayertoks",values[a]) + texsettokenlist("currentviewerlayertoks",values[a] or "") else if global or scopes[a] == v_global then texsetattribute("global",a_viewerlayer,unsetvalue) diff --git a/tex/context/base/attr-lay.mkiv b/tex/context/base/attr-lay.mkiv index 2542ca5af..9c9c3318e 100644 --- a/tex/context/base/attr-lay.mkiv +++ b/tex/context/base/attr-lay.mkiv @@ -13,6 +13,13 @@ \writestatus{loading}{ConTeXt Attribute Macros / Viewerlayers} +%D Currently there is a limitation in mixed inline usage. This has to do with the fact +%D that we have a stacked model but cannot determine where to revert to (as we can +%D have AABBCCAA ranges). Maybe I'll solve that one day. It only affects nested inline +%D layers and these make not much sense anyway. We'd have to store the complete nesting +%D stack in the attribute in order to be able to cross pages and that demands a new +%D mechanism. + \unprotect \registerctxluafile{attr-lay}{1.001} @@ -91,4 +98,8 @@ \let\setlayoutcomponentattribute \attr_layoutcomponent_set \let\resetlayoutcomponentattribute\attr_layoutcomponent_reset} +\appendtoks + \ctxcommand{cleanuplayers()}% +\to \everyshipout + \protect \endinput diff --git a/tex/context/base/cont-new.mkii b/tex/context/base/cont-new.mkii index 52d37827c..e46c0fb4c 100644 --- a/tex/context/base/cont-new.mkii +++ b/tex/context/base/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2012.06.20 20:43} +\newcontextversion{2012.06.22 10:09} %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/cont-new.mkiv b/tex/context/base/cont-new.mkiv index af4692522..48f7a3b54 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2012.06.20 20:43} +\newcontextversion{2012.06.22 10:09} %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/context-version.pdf b/tex/context/base/context-version.pdf Binary files differindex 3349752b7..8358f6e2b 100644 --- a/tex/context/base/context-version.pdf +++ b/tex/context/base/context-version.pdf diff --git a/tex/context/base/context-version.png b/tex/context/base/context-version.png Binary files differindex 0d1b62401..6b2e33714 100644 --- a/tex/context/base/context-version.png +++ b/tex/context/base/context-version.png diff --git a/tex/context/base/context.mkii b/tex/context/base/context.mkii index 72aae0459..eb3391a6d 100644 --- a/tex/context/base/context.mkii +++ b/tex/context/base/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2012.06.20 20:43} +\edef\contextversion{2012.06.22 10:09} %D For those who want to use this: diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 9e00a274b..63a4cc8ef 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -23,7 +23,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2012.06.20 20:43} +\edef\contextversion{2012.06.22 10:09} %D For those who want to use this: @@ -289,7 +289,7 @@ \loadmarkfile{buff-ini} \loadmarkfile{buff-ver} -\loadmarkfile{buff-par} +\loadmkvifile{buff-par} \loadmarkfile{buff-imp-tex} % optional as also runtime if not loaded \loadmarkfile{buff-imp-mp} % optional as also runtime if not loaded diff --git a/tex/context/base/lpdf-nod.lua b/tex/context/base/lpdf-nod.lua index fe0c975f7..0d5a1bbd9 100644 --- a/tex/context/base/lpdf-nod.lua +++ b/tex/context/base/lpdf-nod.lua @@ -59,7 +59,7 @@ end function nodepool.pdfsetmatrix(rx,sx,sy,ry,tx,ty) local t = copy_node(pdfsetmatrix) - t.data = format("%s %s %s %s",rs or 0,sx or 0,sy or 0,rx or 0) -- todo: tx ty + t.data = format("%s %s %s %s",rx or 0,sx or 0,sy or 0,ry or 0) -- todo: tx ty return t end @@ -69,21 +69,73 @@ nodeinjections.transform = nodepool.pdfsetmatrix function nodepool.pdfannotation(w,h,d,data,n) local t = copy_node(pdfannot) - if w and w ~= 0 then t.width = w end - if h and h ~= 0 then t.height = h end - if d and d ~= 0 then t.depth = d end - if n then t.objnum = n end - if data and data ~= "" then t.data = data end + if w and w ~= 0 then + t.width = w + end + if h and h ~= 0 then + t.height = h + end + if d and d ~= 0 then + t.depth = d + end + if n then + t.objnum = n + end + if data and data ~= "" then + t.data = data + end return t end +-- (!) The next code in pdfdest.w is wrong: +-- +-- case pdf_dest_xyz: +-- if (matrixused()) { +-- set_rect_dimens(pdf, p, parent_box, cur, alt_rule, pdf_dest_margin) ; +-- } else { +-- pdf_ann_left(p) = pos.h ; +-- pdf_ann_top (p) = pos.v ; +-- } +-- break ; +-- +-- so we need to force a matrix. + function nodepool.pdfdestination(w,h,d,name,view,n) local t = copy_node(pdfdest) - if w and w ~= 0 then t.width = w end - if h and h ~= 0 then t.height = h end - if d and d ~= 0 then t.depth = d end - if n then t.objnum = n end + local hasdimensions = false + if w and w ~= 0 then + t.width = w + hasdimensions = true + end + if h and h ~= 0 then + t.height = h + hasdimensions = true + end + if d and d ~= 0 then + t.depth = d + hasdimensions = true + end + if n then + t.objnum = n + end + view = views[view] or view or 1 -- fit is default t.dest_id = name - t.dest_type = views[view] or view or 1 -- fit is default - return t + t.dest_type = view + if hasdimensions and view == 0 then -- xyz + -- see (!) + local s = copy_node(pdfsave) + local m = copy_node(pdfsetmatrix) + -- local t + local r = copy_node(pdfrestore) + m.data = format("1 0 0 1") + s.next = m + m.next = t + t.next = r + m.prev = s + t.prev = m + r.prev = t + return s + else + return t + end end diff --git a/tex/context/base/lpdf-ren.lua b/tex/context/base/lpdf-ren.lua index e0c4b1973..29b78313f 100644 --- a/tex/context/base/lpdf-ren.lua +++ b/tex/context/base/lpdf-ren.lua @@ -65,6 +65,9 @@ local lpdf_usage = pdfdictionary { Print = pdfdictionary { PrintState = pdf_off local cache = { } function codeinjections.startlayer(name) + if not name then + name = "unknown" + end codeinjections.useviewerlayer(name) return format("/OC /%s BDC",name) end diff --git a/tex/context/base/luat-lib.mkiv b/tex/context/base/luat-lib.mkiv index 5a53b7ea2..fb05a84c1 100644 --- a/tex/context/base/luat-lib.mkiv +++ b/tex/context/base/luat-lib.mkiv @@ -30,6 +30,8 @@ \registerctxluafile{trac-log}{1.001} %registerctxluafile{trac-pro}{1.001} +\registerctxluafile{util-sta}{1.001} + \registerctxluafile{data-ini}{1.001} \registerctxluafile{data-exp}{1.001} \registerctxluafile{data-env}{1.001} diff --git a/tex/context/base/mult-aux.mkiv b/tex/context/base/mult-aux.mkiv index fae9bb0c8..aae94e835 100644 --- a/tex/context/base/mult-aux.mkiv +++ b/tex/context/base/mult-aux.mkiv @@ -713,8 +713,10 @@ \letvalue\??dummy\empty -\def\dummyparameter #1{\csname\??dummy\ifcsname\??dummy#1\endcsname#1\fi\endcsname} -\def\directdummyparameter#1{\csname\??dummy#1\endcsname} + \def\dummyparameter #1{\csname\??dummy\ifcsname\??dummy#1\endcsname#1\fi\endcsname} + \def\directdummyparameter#1{\csname\??dummy#1\endcsname} +\unexpanded\def\setdummyparameter #1{\expandafter\def\csname\??dummy#1\endcsname} +\unexpanded\def\letdummyparameter #1{\expandafter\let\csname\??dummy#1\endcsname} % \unexpanded\def\getdummyparameters % {\mult_interfaces_get_parameters\??dummy} diff --git a/tex/context/base/mult-low.lua b/tex/context/base/mult-low.lua index fe4a34337..586b54813 100644 --- a/tex/context/base/mult-low.lua +++ b/tex/context/base/mult-low.lua @@ -173,6 +173,9 @@ return { -- "scratchwidth", "scratchheight", "scratchdepth", "scratchoffset", "scratchdistance", "scratchhsize", "scratchvsize", + "scratchxoffset", "scratchyoffset", "scratchhoffset", "scratchvoffset", + "scratchxposition", "scratchyposition", + "scratchtopoffset", "scratchbottomoffset", "scratchleftoffset", "scratchrightoffset", -- "scratchcounterone", "scratchcountertwo", "scratchcounterthree", "scratchdimenone", "scratchdimentwo", "scratchdimenthree", @@ -180,6 +183,7 @@ return { "scratchmuskipone", "scratchmuskiptwo", "scratchmuskipthree", "scratchtoksone", "scratchtokstwo", "scratchtoksthree", "scratchboxone", "scratchboxtwo", "scratchboxthree", + "scratchnx", "scratchny", -- "doif", "doifnot", "doifelse", "doifinset", "doifnotinset", "doifinsetelse", @@ -214,7 +218,8 @@ return { "setuvalue", "setuevalue", "setugvalue", "setuxvalue", "globallet", "glet", "getparameters", "geteparameters", "getgparameters", "getxparameters", "forgetparameters", "copyparameters", - "getdummyparameters", "dummyparameter", "directdummyparameter", + -- + "getdummyparameters", "dummyparameter", "directdummyparameter", "setdummyparameter", "letdummyparameter", -- "processcommalist", "processcommacommand", "quitcommalist", "quitprevcommalist", "processaction", "processallactions", "processfirstactioninset", "processallactionsinset", diff --git a/tex/context/base/mult-sys.mkiv b/tex/context/base/mult-sys.mkiv index 65c456cdc..bb52dc518 100644 --- a/tex/context/base/mult-sys.mkiv +++ b/tex/context/base/mult-sys.mkiv @@ -458,7 +458,6 @@ \definesystemvariable {al} % ALinea's \definesystemvariable {an} % ANchor \definesystemvariable {as} % AlignmentSwitch -\definesystemvariable {bg} % BleedinG \definesystemvariable {bp} % BreakPoint \definesystemvariable {bx} % BackendExport \definesystemvariable {cb} % CollectBox @@ -473,8 +472,6 @@ \definesystemvariable {du} % DUmmy \definesystemvariable {ef} % ExternFiguur \definesystemvariable {en} % ENvironments -%definesystemvariable {er} % external resources -\definesystemvariable {et} % EffecT \definesystemvariable {ex} % ExterneFiguren \definesystemvariable {fc} % FramedContent \definesystemvariable {fi} % FIle Once @@ -506,7 +503,6 @@ \definesystemvariable {ll} % Layers \definesystemvariable {lr} % LayeR \definesystemvariable {lu} % LUacode -\definesystemvariable {lx} % LayerteXt \definesystemvariable {ma} % MargeAchtergrond \definesystemvariable {mc} % MultiColumn \definesystemvariable {mi} % MultilingualInterface @@ -523,7 +519,6 @@ \definesystemvariable {oi} % OmlijndInstellingen \definesystemvariable {ol} % OmLijnd \definesystemvariable {od} % Omlijnd Defaults (simple) -\definesystemvariable {ox} % OffsetBox \definesystemvariable {pb} % PuBlication \definesystemvariable {pc} % PageComment \definesystemvariable {ph} % ParagrapH diff --git a/tex/context/base/node-fin.lua b/tex/context/base/node-fin.lua index 069ef0b3a..d64c24479 100644 --- a/tex/context/base/node-fin.lua +++ b/tex/context/base/node-fin.lua @@ -36,6 +36,8 @@ local triggering = false local starttiming = statistics.starttiming local stoptiming = statistics.stoptiming +local unsetvalue = attributes.unsetvalue + -- these two will be like trackers function states.enabletriggering() @@ -176,6 +178,7 @@ local insert_node_after = node.insert_after local nsdata, nsnone, nslistwise, nsforced, nsselector, nstrigger local current, current_selector, done = 0, 0, false -- nb, stack has a local current ! +local nsbegin, nsend function states.initialize(namespace,attribute,head) nsdata = namespace.data @@ -187,6 +190,11 @@ function states.initialize(namespace,attribute,head) current = 0 current_selector = 0 done = false -- todo: done cleanup + nsstep = namespace.resolve_step + if nsstep then + nsbegin = namespace.resolve_begin + nsend = namespace.resolve_end + end end function states.finalize(namespace,attribute,head) -- is this one ok? @@ -389,6 +397,9 @@ states.selective = selective -- (as used in the stepper). In the stepper we cannot use the box branch as it involves -- paragraph lines and then gets mixed up. A messy business (esp since we want to be -- efficient). +-- +-- Todo: make a better stacker. Keep track (in attribute) about nesting level. Not +-- entirely trivial and a generic solution is nicer (compares to the exporter). local function stacked(namespace,attribute,head,default) -- no triggering, no inheritance, but list-wise local stack, done = head, false @@ -447,13 +458,76 @@ local function stacked(namespace,attribute,head,default) -- no triggering, no in end while depth > 0 do head = insert_node_after(head,stack,copy_node(nsnone)) - depth = depth -1 + depth = depth - 1 end return head, done end states.stacked = stacked +-- experimental + +local function stacker(namespace,attribute,head,default) -- no triggering, no inheritance, but list-wise + nsbegin() + local current, previous, done, okay = head, head, false, false + local attrib = default or unsetvalue + while current do + local id = current.id + if id == glyph_code or (id == rule_code and current.width ~= 0) or (id == glue_code and current.leader) then -- or disc_code + local a = has_attribute(current,attribute) or unsetvalue + if a ~= attrib then + local n = nsstep(a) + if n then + head = insert_node_before(head,current,n) -- copy_node(nsdata[a])) + end + attrib, done, okay = a, true, true + end + if id == glue_code then + local content = current.leader + if content then -- unchecked + local ok = false + current.leader, ok = stacker(namespace,attribute,content,attrib) + done = done or ok + end + end + elseif id == hlist_code or id == vlist_code then + local content = current.list + if content then + if nslistwise then + local a = has_attribute(current,attribute) + if a and attrib ~= a and nslistwise[a] then -- viewerlayer + local p = attrib + attrib, done = a, true + head = insert_node_before(head,current,copy_node(nsdata[a])) + current.list = stacker(namespace,attribute,content,attrib) + head, current = insert_node_after(head,current,copy_node(nsnone)) + attrib = p + else + local ok = false + current.list, ok = stacker(namespace,attribute,content,attrib) + done = done or ok + end + else + local ok = false + current.list, ok = stacker(namespace,attribute,content,default) + done = done or ok + end + end + end + previous = current + current = current.next + end + if okay then + local n = nsend() + if n then + head = insert_node_after(head,previous,n) -- copy_node(nsdata[a])) + end + end + return head, done +end + +states.stacker = stacker + -- -- -- statistics.register("attribute processing time", function() diff --git a/tex/context/base/node-tsk.lua b/tex/context/base/node-tsk.lua index efc51913c..ccaa6c6b4 100644 --- a/tex/context/base/node-tsk.lua +++ b/tex/context/base/node-tsk.lua @@ -14,9 +14,9 @@ local format = string.format local trace_tasks = false trackers.register("tasks.creation", function(v) trace_tasks = v end) -local report_tasks = logs.reporter("tasks") +local report_tasks = logs.reporter("tasks") -local allocate = utilities.storage.allocate +local allocate = utilities.storage.allocate local nodes = nodes diff --git a/tex/context/base/pack-box.mkiv b/tex/context/base/pack-box.mkiv index b36ae1f11..bcdb93875 100644 --- a/tex/context/base/pack-box.mkiv +++ b/tex/context/base/pack-box.mkiv @@ -13,21 +13,16 @@ \writestatus{loading}{ConTeXt Packaging Macros / Boxes} -% to be cleaned up (boring ... so when on long trip or so) -% to be documented (up to users) -% some code can be sped up - -%D This module contains all kind of macros for moving content -%D around. Many macros here come from other modules, but -%D depencies made it more clear to isolate them. - -% \placeornament +%D This module contains all kind of macros for moving content around. Many +%D macros here come from other modules, but depencies made it more clear +%D to isolate them. We invite users to document the macros. They can be +%D handy shortcuts for otherwise complex tasks. \unprotect -% we need to set the size, else we get dimensions depending -% on the content, which in itself is ok, but can lead to loops -% due to rounding errors (happened in demo-obv) +%D We need to set the size, else we get dimensions depending on the content, +%D which in itself is ok, but can lead to loops due to rounding errors (happened +%D in demo-obv). \definelayer[\v!text-2][\c!position=\v!yes,\c!region=,\c!width=\overlaywidth,\c!height=\overlayheight] \definelayer[\v!text-1][\c!position=\v!yes,\c!region=,\c!width=\overlaywidth,\c!height=\overlayheight] @@ -118,7 +113,7 @@ \c!offset=\zeropoint, #2,#3] {\setlayer[#1]{\box\b_pack_anchors}}% % #1 uses ovelaywidth/height - \framed + \framed % could be a predefined framed [\c!background=anchor, \c!offset=\v!overlay, \c!frame=\v!off, @@ -129,156 +124,181 @@ % collectors \installcorenamespace{collectorbox} +\installcorenamespace{collector} + +\installcommandhandler \??collector {collector} \??collector + +\setupcollector + [\c!state=\v!start, + \c!x=\zeropoint, + \c!y=\zeropoint, + \c!offset=\zeropoint, + \c!rotation=, % geen 0 ! + \c!hoffset=\zeropoint, + \c!voffset=\zeropoint, + \c!location=rb, + \c!corner=] + +\appendtoks + \ifcsname\??collectorbox\currentcollector\endcsname \else + \expandafter\newbox\csname\??collectorbox\currentcollector\endcsname + \fi +\to \everydefinecollector + +\unexpanded\def\resetcollector[#1]% + {\ifcsname\??collectorbox#1\endcsname + \global\setbox\csname\??collectorbox#1\endcsname\emptybox + \fi} -\unexpanded\def\definecollector - {\dodoubleargument\dodefinecollector} +\newconditional\c_pack_boxes_collector_valid_box -\def\dodefinecollector[#1][#2]% - {\ifcsname\??collectorbox#1\endcsname \else - \expandafter\newbox\csname\??collectorbox#1\endcsname - \fi - \resetcollector[#1]% - \setupcollector - [#1] - [\c!state=\v!start, - \c!x=\zeropoint,\c!y=\zeropoint, - \c!offset=\zeropoint,\c!rotation=, % geen 0 ! - \c!hoffset=\zeropoint,\c!voffset=\zeropoint, - \c!location=rb,\c!corner=,#2]} - -\unexpanded\def\setupcollector - {\dodoubleargument\dosetupcollector} - -\def\dosetupcollector[#1][#2]% - {\def\docommand##1{\getparameters[\??cb##1][#2]}% - \processcommalist[#1]\docommand} - -\def\setcollector - {\dodoubleargument\dosetcollector} - -\def\dosetcollector[#1][#2]% +\let\b_pack_boxes_collector\scratchbox + +\def\pack_boxes_collector_check_box#1% + {\edef\currentcollector{#1}% + \ifcsname\??collectorbox\currentcollector\endcsname + \settrue\c_pack_boxes_collector_valid_box + \expandafter\let\expandafter\b_pack_boxes_collector\csname\??collectorbox\currentcollector\endcsname + \else + \setfalse\c_pack_boxes_collector_valid_box + \writestatus{collector}{unknown collector \currentcollector}% + \fi} + +\unexpanded\def\setcollector {\bgroup - \forgetall + \dodoubleargument\pack_boxes_collector} + +\def\pack_boxes_collector[#1][#2]% todo: keep reference point + {\pack_boxes_collector_check_box{#1}% + \ifconditional\c_pack_boxes_collector_valid_box + \setupcurrentcollector[#2] + \expandafter\pack_boxes_collector_yes + \else + \expandafter\pack_boxes_collector_nop + \fi} + +\def\pack_boxes_collector_yes + {\forgetall \dontcomplain - \dowithnextbox - {\ifcsname\??collectorbox#1\endcsname - \dodosetcollector[#1][#2]% - \else - \writestatus{collector}{unknown layer #1}% - \fi - \egroup} - \hbox} + \dowithnextboxcs\pack_boxes_collector_finish\hbox} -\def\collectorparameter#1{\csname\??cb\currentcollector#1\endcsname} - -\def\dodosetcollector[#1][#2]% todo: keep reference point - {\def\currentcollector{#1}% - \chardef\collectorbox\csname\??collectorbox#1\endcsname - \getparameters[\??cb#1][#2]% - \d_pack_layers_x_size\wd\collectorbox - \d_pack_layers_y_size\ht\collectorbox - \doifvaluesomething{\??cb#1\c!rotation} - {\setbox\nextbox\hbox - {\rotate - [\c!location=\v!high, - \c!rotation=\collectorparameter\c!rotation] - {\flushnextbox}}}% - \advance\d_pack_layers_y_size\dp\collectorbox - \d_pack_layers_x_position\collectorparameter\c!x - \advance\d_pack_layers_x_position\collectorparameter\c!hoffset - \d_pack_layers_y_position\collectorparameter\c!y - \advance\d_pack_layers_y_position\collectorparameter\c!voffset - \doifelse\v!middle{\collectorparameter\c!corner} - {\ifdim\d_pack_layers_x_size>\zeropoint - \advance\d_pack_layers_x_position.5\d_pack_layers_x_size - \fi - \ifdim\d_pack_layers_y_size>\zeropoint - \advance\d_pack_layers_y_position.5\d_pack_layers_y_size - \fi}% - {\normalexpanded{\noexpand\doifinset{\v!bottom}{\collectorparameter\c!corner}} - {\ifdim\d_pack_layers_y_size>\zeropoint - \advance\d_pack_layers_y_position-\d_pack_layers_y_size - \d_pack_layers_y_position-\d_pack_layers_y_position - \fi}% - \normalexpanded{\noexpand\doifinset{\v!right}{\collectorparameter\c!corner}} - {\ifdim\d_pack_layers_x_size>\zeropoint - \advance\d_pack_layers_x_position-\d_pack_layers_x_size - \d_pack_layers_x_position-\d_pack_layers_x_position - \fi}}% +\def\pack_boxes_collector_nop + {\egroup} + +\installcorenamespace{collectorcorners} + +\setvalue{\??collectorcorners\v!middle}% + {\ifdim\d_pack_layers_x_size>\zeropoint + \advance\d_pack_layers_x_position.5\d_pack_layers_x_size + \fi + \ifdim\d_pack_layers_y_size>\zeropoint + \advance\d_pack_layers_y_position.5\d_pack_layers_y_size + \fi} + +\setvalue{\??collectorcorners\v!bottom}% + {\ifdim\d_pack_layers_y_size>\zeropoint + \advance\d_pack_layers_y_position-\d_pack_layers_y_size + \d_pack_layers_y_position-\d_pack_layers_y_position + \fi} + +\setvalue{\??collectorcorners\v!right}% + {\ifdim\d_pack_layers_x_size>\zeropoint + \advance\d_pack_layers_x_position-\d_pack_layers_x_size + \d_pack_layers_x_position-\d_pack_layers_x_position + \fi} + +\def\pack_boxes_collector_check_corner#1% + {\ifcsname\??collectorcorners#1\endcsname + \csname\??collectorcorners#1\endcsname + \fi} + +\def\pack_boxes_collector_finish + {\edef\p_collector_rotation{\collectorparameter\c!rotation}% + \edef\p_collector_corner {\collectorparameter\c!corner}% + \ifx\p_collector_rotation\empty \else + \setbox\nextbox\hbox + {\rotate + [\c!location=\v!high, + \c!rotation=\p_collector_rotation] + {\box\nextbox}}% + \fi + \d_pack_layers_x_size\wd\b_pack_boxes_collector + \d_pack_layers_y_size\htdp\b_pack_boxes_collector + \d_pack_layers_x_position\dimexpr\collectorparameter\c!x+\collectorparameter\c!hoffset\relax + \d_pack_layers_y_position\dimexpr\collectorparameter\c!y+\collectorparameter\c!voffset\relax + \rawprocesscommacommand[\p_collector_corner]\pack_boxes_collector_check_corner \setbox\nextbox\hbox - {\alignedbox[\collectorparameter\c!location]\vbox{\flushnextbox}}% + {\alignedbox[\collectorparameter\c!location]\vbox{\box\nextbox}}% \boxmaxdepth\zeropoint % really needed, nice example \global\advance\boxhdisplacement\d_pack_layers_x_position \ifdim\boxhdisplacement<\zeropoint - \global\setbox\collectorbox\hbox + \global\setbox\b_pack_boxes_collector\hbox {\hskip-\boxhdisplacement - \box\collectorbox}% + \box\b_pack_boxes_collector}% \fi \global\advance\boxvdisplacement\d_pack_layers_y_position \ifdim\boxvdisplacement<\zeropoint - \global\setbox\collectorbox\hbox + \global\setbox\b_pack_boxes_collector\hbox {\lower-\boxvdisplacement - \box\collectorbox}% + \box\b_pack_boxes_collector}% \fi - \d_pack_layers_x_size\wd\collectorbox - \d_pack_layers_y_size\ht\collectorbox - \advance\d_pack_layers_y_size\dp\collectorbox - \global\setbox\collectorbox\hbox - {\box\collectorbox - \hskip-\d_pack_layers_x_size - \hskip\d_pack_layers_x_position\relax - \ifdim\boxhdisplacement<\zeropoint - \hskip-\boxhdisplacement - \fi + \d_pack_layers_x_size\wd\b_pack_boxes_collector + \d_pack_layers_y_size\htdp\b_pack_boxes_collector + \global\setbox\b_pack_boxes_collector\hbox + {\box\b_pack_boxes_collector + \hskip\dimexpr + -\d_pack_layers_x_size + +\d_pack_layers_x_position + \ifdim\boxhdisplacement<\zeropoint + -\boxhdisplacement + \fi + \relax \lower\d_pack_layers_y_position\hbox {\ifdim\boxvdisplacement<\zeropoint - \lower-\boxvdisplacement\flushnextbox - \else - \flushnextbox - \fi}}% + \lower-\boxvdisplacement + \fi + \box\nextbox}}% % combine height and depth into depth only (later flushed as height) - \global\setbox\collectorbox\hbox - {\lower\ht\collectorbox\box\collectorbox}% + \global\setbox\b_pack_boxes_collector\hbox + {\lower\ht\b_pack_boxes_collector\box\b_pack_boxes_collector}% % just to be sure - \ifdim\wd\collectorbox<\d_pack_layers_x_size - \wd\collectorbox\d_pack_layers_x_size - \fi} + \ifdim\wd\b_pack_boxes_collector<\d_pack_layers_x_size + \wd\b_pack_boxes_collector\d_pack_layers_x_size + \fi + \egroup} -\def\flushcollector[#1]% - {\ifcsname\??collectorbox#1\endcsname - \doifnotvalue{\??cb#1\c!state}\v!stop - {\vbox - {\hbox - {\doifelsevalue{\??cb#1\c!state}\v!repeat - {\let\next\copy}{\let\next\box}% - \raise\dp\csname\??collectorbox#1\endcsname - \next\csname\??collectorbox#1\endcsname}}}% - \else - \writestatus{collector}{unknown collector #1}% - \fi} +\unexpanded\def\flushcollector[#1]% + {\bgroup + \pack_boxes_collector_check_box{#1}% + \ifconditional\c_pack_boxes_collector_valid_box + \edef\p_collector_state{\collectorparameter\c!state}% + \ifx\p_collector_state\v!stop \else + \vbox{\hbox{\raise + \dp\b_pack_boxes_collector + \ifx\p_collector_state\v!repeat\copy\else\box\fi\b_pack_boxes_collector}}% + \fi + \fi + \egroup} -\def\composedcollector#1{\flushcollector[#1]} +\unexpanded\def\composedcollector#1% no [], handy as argument + {\flushcollector[#1]} -\def\resetcollector[#1]% - {\ifcsname\??collectorbox#1\endcsname - \global\setbox\csname\??collectorbox#1\endcsname\emptybox - \fi} - -\def\adaptcollector - {\dodoubleargument\doadaptcollector} +\unexpanded\def\adaptcollector + {\dodoubleargument\pack_boxes_collector_adapt} -\def\doadaptcollector[#1][#2]% % a typical case where \global\wd looks better in the code - {\bgroup - \def\currentcollector{#1}% - \chardef\collectorbox\csname\??collectorbox#1\endcsname - \getparameters[\??cb#1][\c!voffset=\zeropoint,\c!hoffset=\zeropoint,#2]% - \scratchdimen\wd\collectorbox - \advance\scratchdimen\collectorparameter\c!hoffset - \global\wd\collectorbox\scratchdimen - \scratchdimen\ht\collectorbox - \advance\scratchdimen\collectorparameter\c!voffset - \global\ht\collectorbox\scratchdimen - \egroup} +\def\pack_boxes_collector_adapt[#1][#2]% % a typical case where \global\wd looks better in the code + {\begingroup + \pack_boxes_collector_check_box{#1}% + \ifconditional\c_pack_boxes_collector_valid_box + \letcollectorparameter\c!voffset\zeropoint + \letcollectorparameter\h!voffset\zeropoint + \ifsecondargument + \setupcurrentcollector[#2]% + \fi + \global\wd\b_pack_boxes_collector\dimexpr\wd\b_pack_boxes_collector+\collectorparameter\c!hoffset\relax + \global\ht\b_pack_boxes_collector\dimexpr\ht\b_pack_boxes_collector+\collectorparameter\c!voffset\relax + \fi + \endgroup} %\definecollector[test] %\setcollector[test] @@ -292,23 +312,23 @@ \definecollector [caption] -\def\collectedtext - {\dodoubleempty\docollectedtext} - -\def\docollectedtext[#1][#2]#3% +\unexpanded\def\collectedtext % for captions {\bgroup - \dowithnextbox + \dodoubleempty\pack_boxes_collector_text} + +\def\pack_boxes_collector_text[#1][#2]#3% + {\dowithnextbox {\setcollector [caption] - {\flushnextbox}% + {\box\nextbox}% \setcollector [caption][#1] - {\getparameters[\??du][\c!style=,\c!color=,#2]% - \dousestyleparameter\@@dustyle + {\letdummyparameter\c!style\empty + \letdummyparameter\c!color\empty + \getdummyparameters[#2]% + \dousestyleparameter{\directdummyparameter\c!style}% \setupinterlinespace - \framed % watch the special setting of kader/overlay - [\c!frame=\v!overlay,\c!foregroundcolor=\@@ducolor,\c!foregroundstyle=\@@dustyle,#2] - {#3}}% + \normalexpanded{\framed[\c!foregroundcolor=\directdummyparameter\c!color,\c!foregroundstyle=\directdummyparameter\c!style},\c!frame=\v!overlay,#2]{#3}}% \composedcollector{caption}% \egroup}% \hbox} @@ -417,7 +437,8 @@ \def\pack_ornament_text[#1][#2]% {\bgroup \doifassignmentelse{#1} - {\getdummyparameters[\c!alternative=\v!a,#1]% + {\letdummyparameter\c!alternative\v!a + \getdummyparameters[#1]% \doifelse{\directdummyparameter\c!alternative}\v!a {\egroup\collectedtext}% {\egroup\layeredtext }% @@ -462,12 +483,11 @@ % % \affiliation{drawing}{\externalfigure[hakker][width=3cm]} -% pas op: aanpassen aan nieuwe layer hoek ankers en columnset +\newcount\c_pack_boxes_bleeds -\newcount\nofbleeds % per pag +\installcorenamespace {bleeding} -\unexpanded\def\setupbleeding - {\dodoubleempty\getparameters[\??bg]} +\installdirectcommandhandler \??bleeding {bleeding} % \??bleeding \setupbleeding [\c!location=l, @@ -476,92 +496,113 @@ \c!height=3cm, \c!offset=2mm, \c!page=\v!no, - \c!voffset=\@@bgoffset, - \c!hoffset=\@@bgoffset] + \c!voffset=\scratchoffset, % is set to \bleedingparameter\c!offset + \c!hoffset=\scratchoffset] % which often saves one resolve -\unexpanded\def\bleed - {\dosingleempty\pack_boxes_bleed} +\def\bleedwidth {\the\hsize} % these are global ! +\def\bleedheight{\the\vsize} % these are global ! -\def\bleedwidth {\the\hsize}% -\def\bleedheight{\the\vsize}% +\newconditional\c_pack_boxes_l +\newconditional\c_pack_boxes_r +\newconditional\c_pack_boxes_t +\newconditional\c_pack_boxes_b -\def\pack_boxes_bleed[#1]#2% +\unexpanded\def\bleed {\hbox\bgroup + \dosingleempty\pack_boxes_bleed} + +\installcorenamespace{bleedinglocation} + +\setvalue{\??bleedinglocation t}{\settrue\c_pack_boxes_t\scratchhoffset\zeropoint} +\setvalue{\??bleedinglocation b}{\settrue\c_pack_boxes_b\scratchhoffset\zeropoint} +\setvalue{\??bleedinglocation l}{\settrue\c_pack_boxes_l\scratchvoffset\zeropoint} +\setvalue{\??bleedinglocation r}{\settrue\c_pack_boxes_r\scratchvoffset\zeropoint} +\setvalue{\??bleedinglocation bl}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_b} +\setvalue{\??bleedinglocation lb}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_b} +\setvalue{\??bleedinglocation br}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_b} +\setvalue{\??bleedinglocation rb}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_b} +\setvalue{\??bleedinglocation tl}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_t} +\setvalue{\??bleedinglocation lt}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_t} +\setvalue{\??bleedinglocation tr}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_t} +\setvalue{\??bleedinglocation rt}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_t} + +\def\pack_boxes_bleed[#1]% + {\global\advance\c_pack_boxes_bleeds\plusone + % \xdef\bleedwidth {\the\hsize}% \xdef\bleedheight{\the\vsize}% - \global\advance\nofbleeds\plusone - \getparameters[\??bg][#1]% - \!!doneafalse % left - \!!donebfalse % right - \!!donecfalse % top - \!!donedfalse % bottom - % replace this part ! todo: default location - \processaction - [\@@bglocation] - [ t=>\!!donectrue\let\@@bghoffset\!!zeropoint, - b=>\!!donedtrue\let\@@bghoffset\!!zeropoint, - l=>\!!doneatrue\let\@@bgvoffset\!!zeropoint, - r=>\!!donebtrue\let\@@bgvoffset\!!zeropoint, - bl=>\!!doneatrue\!!donedtrue, - lb=>\!!doneatrue\!!donedtrue, - br=>\!!donebtrue\!!donedtrue, - rb=>\!!donebtrue\!!donedtrue, - tl=>\!!doneatrue\!!donectrue, - lt=>\!!doneatrue\!!donectrue, - tr=>\!!donebtrue\!!donectrue, - rt=>\!!donebtrue\!!donectrue]% - \doifelse\@@bgstretch\v!yes\donetrue\donefalse - \scratchdimen\@@bgwidth - \edef\currentbgposition {\??bg:\number\nofbleeds}% + % + \edef\currentbgposition {bleed:\number\c_pack_boxes_bleeds}% \edef\currentpageposition{page:0}% todo: per page - \ifdone - \if!!donea - \advance\scratchdimen\dimexpr \MPx\currentbgposition-\MPx\currentpageposition\relax - \else\if!!doneb - \scratchdimen\dimexpr\paperwidth-\MPx\currentbgposition+\MPx\currentpageposition\relax % not checked - \fi\fi - \fi - \advance\scratchdimen\@@bghoffset - \xdef\bleedwidth{\the\scratchdimen}% - \scratchdimen\@@bgheight - \ifdone - \if!!donec - \scratchdimen\dimexpr\paperheight-\MPy\currentbgposition+\MPy\currentpageposition\relax % not checked - \else\if!!doned - \advance\scratchdimen\dimexpr \MPy\currentbgposition-\MPy\currentpageposition\relax % not checked - \fi\fi - \fi - \advance\scratchdimen\@@bgvoffset - \xdef\bleedheight{\the\scratchdimen}% % - \bgroup - \hsize\bleedwidth - \vsize\bleedheight - \global\setbox\globalscratchbox\hbox{#2}% - \egroup - \setbox\scratchbox\box\globalscratchbox + \setupcurrentbleeding[#1]% + % + \scratchwidth \bleedingparameter\c!width + \scratchheight \bleedingparameter\c!height + \scratchoffset \bleedingparameter\c!offset + \scratchhoffset\bleedingparameter\c!hoffset + \scratchvoffset\bleedingparameter\c!voffset + % + \setfalse\c_pack_boxes_l % left + \setfalse\c_pack_boxes_r % right + \setfalse\c_pack_boxes_t % top + \setfalse\c_pack_boxes_b % bottom + % + \csname\??bleedinglocation\bleedingparameter\c!location\endcsname % - \doif\@@bgpage\v!yes - {\setbox\scratchbox\topskippedbox{\box\scratchbox}}% - \setbox\scratchbox\hbox to \@@bgwidth - {\if!!donea\hss\fi\box\scratchbox\if!!doneb\hss\fi}% - \if!!doned - \setbox\scratchbox\hbox - {\lower\bleedheight\hbox{\raise\@@bgheight\box\scratchbox}}% + \doifelse{\bleedingparameter\c!stretch}\v!yes\donetrue\donefalse + % + \xdef\bleedwidth{\dimexpr + \ifdone + \ifconditional\c_pack_boxes_l + \scratchwidth+\MPx\currentbgposition-\MPx\currentpageposition + \else\ifconditional\c_pack_boxes_r + \paperwidth -\MPx\currentbgposition+\MPx\currentpageposition % not checked + \else + \scratchwidth + \fi\fi + \else + \scratchwidth + \fi+\scratchhoffset}% + \xdef\bleedheight{\dimexpr + \ifdone + \ifconditional\c_pack_boxes_t + \paperheight -\MPy\currentbgposition+\MPy\currentpageposition % not checked + \else\ifconditional\c_pack_boxes_b + \scratchheight+\MPy\currentbgposition-\MPy\currentpageposition % not checked + \else + \scratchheight + \fi\fi + \else + \scratchheight + \fi+\scratchvoffset}% + \dowithnextboxcontentcs\pack_boxes_bleed_settings\pack_boxes_bleed_finish\hbox} + +\def\pack_boxes_bleed_settings + {\hsize\bleedwidth + \vsize\bleedheight} + +\def\pack_boxes_bleed_finish + {\doif{\bleedingparameter\c!page}\v!yes + {\setbox\nextbox\topskippedbox{\box\nextbox}}% + \setbox\nextbox\hbox to \scratchwidth + {\ifconditional\c_pack_boxes_l\hss\fi + \box\nextbox + \ifconditional\c_pack_boxes_r\hss\fi}% + \ifconditional\c_pack_boxes_b + \setbox\nextbox\hbox + {\lower\bleedheight\hbox{\raise\scratchheight\box\nextbox}}% \fi - \wd\scratchbox\@@bgwidth - \ht\scratchbox\@@bgheight - \dp\scratchbox\zeropoint + \wd\nextbox\scratchwidth + \ht\nextbox\scratchheight + \dp\nextbox\zeropoint \ifdone - \hpos\currentbgposition{\box\scratchbox}% + \hpos\currentbgposition{\box\nextbox}% \else - \box\scratchbox + \box\nextbox \fi \egroup} -\setupbleeding - [\c!stretch=\v!yes] - \defineexternalfigure [bleed] % should be \v!bleed [\c!width=\bleedwidth, @@ -600,7 +641,7 @@ % tricky: offsets apply to both the layer and the framed; it makes sense to % only apply the offset to ... -\def\setlayerframed +\unexpanded\def\setlayerframed {\dotripleempty\pack_layers_set_framed} \def\pack_layers_set_framed @@ -624,24 +665,22 @@ {\setlayer[#1][#2]% \normalframedwithsettings[#3]} -\def\setlayertext +\unexpanded\def\setlayertext {\dotripleempty\pack_layers_set_text} \def\pack_layers_set_text[#1][#2][#3]% {\bgroup - \getparameters - [\??lx] - [\c!align=, - \c!width=\hsize, - \c!color=, - \c!style=, - #3]% + \letdummyparameter\c!align\empty + \letdummyparameter\c!width\hsize + \letdummyparameter\c!color\empty + \letdummyparameter\c!style\empty + \getdummyparameters[#3]% \dowithnextboxcontent {\forgetall - \hsize\@@lxwidth - \normalexpanded{\setupalign[\@@lxalign]}% - \dousestyleparameter\@@lxstyle} - {\setlayer[#1][#2]{\strut\dousecolorparameter\@@lxcolor\flushnextbox}% + \hsize\directdummyparameter\c!width + \normalexpanded{\setupalign[\directdummyparameter\c!align]}% + \dousestyleparameter{\directdummyparameter\c!style}} + {\setlayer[#1][#2]{\strut\dousecolorparameter{\directdummyparameter\c!color}\flushnextbox}% maybe expand the color \egroup}% \vtop} @@ -768,93 +807,133 @@ % left/right/top/bottomoffset -> dimensions change % x/y | method=fixed -> dimensions don't change +\installcorenamespace{offsetbox} + +\installautocommandhandler \??offsetbox {offsetbox} \??offsetbox + +\setupoffsetbox + [\c!x=\zeropoint, + \c!y=\zeropoint, + \c!width=\wd\nextbox, + \c!height=\ht\nextbox, + \c!depth=\dp\nextbox, + \c!location=, + \c!leftoffset=\zeropoint, + \c!rightoffset=\zeropoint, + \c!topoffset=\zeropoint, + \c!bottomoffset=\zeropoint, + \c!method=] + +\let\setupoffset\setupoffsetbox + \unexpanded\def\offsetbox{\dosingleempty\pack_boxes_offset_box} \unexpanded\def\offset {\dosingleempty\pack_boxes_offset} -\def\pack_boxes_offset_box[#1]{\bgroup\dowithnextbox{\pack_boxes_offsetfinish{#1}}} -\def\pack_boxes_offset [#1]{\bgroup\dowithnextbox{\pack_boxes_offsetfinish{#1}}\hbox} - -\def\pack_boxes_offsetfinish#1% - {\getparameters[\??ox] - [\c!x=\zeropoint, - \c!y=\zeropoint, - \c!width=\wd\nextbox, - \c!height=\ht\nextbox, - \c!depth=\dp\nextbox, - \c!location=, - \c!leftoffset=\zeropoint, - \c!rightoffset=\zeropoint, - \c!topoffset=\zeropoint, - \c!bottomoffset=\zeropoint, - \c!method=, - #1]% - \donefalse - \ifdim\@@oxleftoffset =\zeropoint\else\donetrue\fi - \ifdim\@@oxrightoffset =\zeropoint\else\donetrue\fi - \ifdim\@@oxtopoffset =\zeropoint\else\donetrue\fi - \ifdim\@@oxbottomoffset=\zeropoint\else\donetrue\fi +\def\pack_boxes_offset_box[#1]% + {\bgroup + \pack_boxes_offset_check[#1]% + \dowithnextboxcs\pack_boxes_offsetfinish} + +\def\pack_boxes_offset[#1]% + {\bgroup + \pack_boxes_offset_check[#1]% + \dowithnextboxcs\pack_boxes_offsetfinish\hbox} + +\newcount\c_pack_boxes_offset_level + +\def\pack_boxes_offset_check + {\advance\c_pack_boxes_offset_level\plusone + \edef\currentoffsetbox{\the\c_pack_boxes_offset_level}% + \checkoffsetboxparent + \setupcurrentoffsetbox} + +\def\pack_boxes_offsetfinish + {\donefalse + \scratchxposition \offsetboxparameter\c!x + \scratchyposition \offsetboxparameter\c!y + \scratchleftoffset \offsetboxparameter\c!leftoffset + \scratchrightoffset \offsetboxparameter\c!rightoffset + \scratchtopoffset \offsetboxparameter\c!topoffset + \scratchbottomoffset\offsetboxparameter\c!bottomoffset + \relax % really needed + \ifdim\scratchleftoffset =\zeropoint\else\donetrue\fi + \ifdim\scratchrightoffset =\zeropoint\else\donetrue\fi + \ifdim\scratchtopoffset =\zeropoint\else\donetrue\fi + \ifdim\scratchbottomoffset=\zeropoint\else\donetrue\fi \ifdone - \doif\@@oxmethod\v!fixed % new - {\ifdim\@@oxleftoffset=\zeropoint - \ifdim\@@oxrightoffset=\zeropoint \else - \edef\@@oxx{\the\dimexpr-\@@oxrightoffset}% - \let\@@oxrightoffset\zeropoint - \fi - \else - \let\@@oxx\@@oxleftoffset - \let\@@oxleftoffset\zeropoint - \fi - \ifdim\@@oxtopoffset=\zeropoint - \ifdim\@@oxbottomoffset=\zeropoint \else - \edef\@@oxy{\the\dimexpr-\@@oxbottomoffset}% - \let\@@oxbottomoffset\zeropoint - \fi - \else - \let\@@oxy\@@oxtopoffset - \let\@@oxtopoffset\zeropoint - \fi - \donefalse}% + \edef\p_method{\offsetboxparameter\c!method}% + \ifx\p_method\v!fixed % new + \ifdim\scratchleftoffset=\zeropoint + \ifdim\scratchrightoffset=\zeropoint \else + \scratchxposition-\scratchrightoffset + \scratchrightoffset\zeropoint + \fi + \else + \scratchxposition\scratchleftoffset + \scratchleftoffset\zeropoint + \fi + \ifdim\scratchtopoffset=\zeropoint + \ifdim\scratchbottomoffset=\zeropoint \else + \scratchyposition-\scratchbottomoffset + \scratchbottomoffset\zeropoint + \fi + \else + \scratchyposition\scratchtopoffset + \scratchtopoffset\zeropoint + \fi + \donefalse + \fi \fi \ifdone \setbox\nextbox\vbox {\forgetall % already done \offinterlineskip - \vskip\@@oxtopoffset + \vskip\scratchtopoffset \hbox - {\hskip\@@oxleftoffset + {\hskip\scratchleftoffset \box\nextbox - \hskip\@@oxrightoffset}% - \vskip\@@oxbottomoffset}% + \hskip\scratchrightoffset}% + \vskip\scratchbottomoffset}% \ht\nextbox\htdp\nextbox \dp\nextbox\zeropoint \fi - \freezedimenmacro\@@oxwidth - \freezedimenmacro\@@oxheight - \freezedimenmacro\@@oxdepth + \scratchwidth \offsetboxparameter\c!width + \scratchheight\offsetboxparameter\c!height + \scratchdepth \offsetboxparameter\c!depth + \edef\p_location{\offsetboxparameter\c!location}% \setbox\nextbox\hbox - {\hskip\@@oxx\lower\@@oxy\hbox - {\doifelsenothing\@@oxlocation - {\box\nextbox} - {\alignedbox[\@@oxlocation]\hbox{\box\nextbox}}}}% - \wd\nextbox\@@oxwidth - \ht\nextbox\@@oxheight - \dp\nextbox\@@oxdepth + {\hskip\scratchxposition + \lower\scratchyposition\hbox + {\ifx\p_location\empty + \box\nextbox + \else + \alignedbox[\p_location]\hbox{\box\nextbox}% + \fi}}% + \wd\nextbox\scratchwidth + \ht\nextbox\scratchheight + \dp\nextbox\scratchdepth \box\nextbox \egroup} +%D \starttyping +%D \framed[offset=overlay]{\offset[leftoffset=1cm] +%D {\framed[offset=overlay]{\offset[rightoffset=1cm] +%D {\externalfigure[koe][width=1cm]}}}} +%D +%D \blank +%D +%D \framed[offset=overlay]{\offset[leftoffset=1cm] {\externalfigure[koe][width=5cm]}} \blank +%D \framed[offset=overlay]{\offset[rightoffset=1cm] {\externalfigure[koe][width=5cm]}} \blank +%D \framed[offset=overlay]{\offset[topoffset=1cm] {\externalfigure[koe][width=5cm]}} \blank +%D \framed[offset=overlay]{\offset[bottomoffset=1cm]{\externalfigure[koe][width=5cm]}} \blank +%D \stoptyping + % \useMPlibrary[pre] \setupbackgrounds[page][background=pagegrid] % -% \placefigure[left,none]{}{\offset[leftoffset=1cm]{\externalfigure[koe][breedte=3cm]}} -% \input tufte -% \placefigure[left,none]{}{\offset[rightoffset=1cm]{\externalfigure[koe][breedte=3cm]}} -% \input tufte -% \placefigure[left,none]{}{\offset[topoffset=1cm]{\externalfigure[koe][breedte=3cm]}} -% \input tufte -% \placefigure[left,none]{}{\offset[bottomoffset=1cm]{\externalfigure[koe][breedte=3cm]}} -% \input tufte - -%\ruledhbox{\offsetbox[x=-1cm,y=-1cm,location=c] -% {\framed[width=4cm,height=4cm]{x}}} +% \placefigure[left,none]{}{\offset[leftoffset=1cm] {\externalfigure[cow][width=3cm]}} \input tufte +% \placefigure[left,none]{}{\offset[rightoffset=1cm] {\externalfigure[cow][width=3cm]}} \input tufte +% \placefigure[left,none]{}{\offset[topoffset=1cm] {\externalfigure[cow][width=3cm]}} \input tufte +% \placefigure[left,none]{}{\offset[bottomoffset=1cm]{\externalfigure[cow][width=3cm]}} \input tufte % Some old code: % @@ -887,10 +966,10 @@ \unexpanded\def\phantombox[#1]% == \framed[\c!empty=\v!yes,\c!offset=\v!overlay,#1]{} {\hbox\bgroup - \getdummyparameters - [\c!width=\zeropoint,% - \c!height=\zeropoint,% - \c!depth=\zeropoint,#1]% + \letdummyparameter\c!width \zeropoint + \letdummyparameter\c!height\zeropoint + \letdummyparameter\c!depth \zeropoint + \getdummyparameters[#1]% \setbox\scratchbox\emptyhbox \wd\scratchbox\directdummyparameter\c!width \ht\scratchbox\directdummyparameter\c!height @@ -910,17 +989,17 @@ \ifcase#1\relax % just one \else - \scratchdimen#2\divide\scratchdimen\wd\nextbox\count0\scratchdimen\advance\count0\plusone - \scratchdimen#3\divide\scratchdimen\ht\nextbox\count2\scratchdimen\advance\count2\plusone + \scratchdimen#2\divide\scratchdimen\wd\nextbox\scratchnx\scratchdimen\advance\scratchnx\plusone\relax + \scratchdimen#3\divide\scratchdimen\ht\nextbox\scratchny\scratchdimen\advance\scratchny\plusone\relax % to be considered: methods \ifcase#1% \or % x and y - \setbox\nextbox\hbox{\dorecurse{\count0}{\copy\nextbox}}% - \setbox\nextbox\vbox{\dorecurse{\count2}{\copy\nextbox\endgraf}}% + \setbox\nextbox\hbox{\dorecurse\scratchnx{\copy\nextbox}}% + \setbox\nextbox\vbox{\dorecurse\scratchny{\copy\nextbox\endgraf}}% \or % x - \setbox\nextbox\hbox{\dorecurse{\count0}{\copy\nextbox}}% + \setbox\nextbox\hbox{\dorecurse\scratchnx{\copy\nextbox}}% \or % y - \setbox\nextbox\vbox{\dorecurse{\count2}{\copy\nextbox\endgraf}}% + \setbox\nextbox\vbox{\dorecurse\scratchny{\copy\nextbox\endgraf}}% \fi \fi \ifdim\wd\nextbox>#2\relax diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf Binary files differindex 0b2e4f2da..68edf2788 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf Binary files differindex 43d7748cd..5f78b3656 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/status-mkiv.lua b/tex/context/base/status-mkiv.lua index 563fc7fd8..14727c77b 100644 --- a/tex/context/base/status-mkiv.lua +++ b/tex/context/base/status-mkiv.lua @@ -250,7 +250,6 @@ return { filename = "attr-lay", marktype = "mkiv", status = "okay", - comment = "at least for now", }, { filename = "attr-neg", @@ -260,7 +259,7 @@ return { { filename = "attr-eff", marktype = "mkiv", - status = "unknown", + status = "okay", }, { filename = "trac-tex", @@ -1418,7 +1417,7 @@ return { { filename = "pack-box", marktype = "mkiv", - status = "unknown", + status = "okay", }, { filename = "pack-bar", diff --git a/tex/context/base/strc-ref.mkvi b/tex/context/base/strc-ref.mkvi index 91b807696..760a6babb 100644 --- a/tex/context/base/strc-ref.mkvi +++ b/tex/context/base/strc-ref.mkvi @@ -297,6 +297,67 @@ \fi} %D \macros +%D {contentreference} +%D +%D \starttyping +%D \setupinteraction +%D [state=start, +%D focus=standard] +%D +%D \setupheader +%D [state=stop] +%D +%D See page \goto{page 2}[page2] \page +%D +%D \contentreference +%D [page2] +%D [offset=1cm,toffset=2cm,frame=on] +%D {\externalfigure[cow.pdf][factor=fit]} +%D +%D \stoptyping + +\unexpanded\def\contentreference + {\hbox\bgroup + \dodoubleempty\strc_references_content_pickup} + +\def\strc_references_content_pickup + {\ifsecondargument + \expandafter\strc_references_content_pickup_yes + \else + \expandafter\strc_references_content_pickup_yes + \fi} + +\def\strc_references_content_pickup_yes[#1][#2]% + {\dowithnextbox{\strc_references_content_yes_finish{#1}{#2}}\hbox} + +\def\strc_references_content_pickup_nop[#1][#2]% + {\dowithnextbox{\strc_references_content_nop_finish{#1}{#2}}\hbox} + +\def\strc_references_content_yes_finish#1#2% + {\scratchwidth \wd\nextbox + \scratchheight\ht\nextbox + \scratchdepth \dp\nextbox + \setbox\nextbox\hbox + {\framed[\c!frame=\v!off,#2]{\box\nextbox}}% + \strc_references_set_simple_page_reference{#1}% + \setbox\nextbox\hbox attr \destinationattribute \currentdestinationattribute + {\strc_references_flush_destination_nodes + \box\nextbox}% + \setbox\nextbox\hbox{\box\nextbox}% + \wd\nextbox\scratchwidth + \ht\nextbox\scratchheight + \dp\nextbox\scratchdepth + \box\nextbox + \egroup} + +\def\strc_references_content_nop_finish#1#2% + {\strc_references_set_simple_page_reference{#1}% + \hbox attr \destinationattribute \currentdestinationattribute + {\strc_references_flush_destination_nodes + \box\nextbox}% + \egroup} + +%D \macros %D {everyreference} %D %D For rather tricky purposes, one can assign sanitizing diff --git a/tex/context/base/syst-ini.mkiv b/tex/context/base/syst-ini.mkiv index 983bedc52..4ebac304d 100644 --- a/tex/context/base/syst-ini.mkiv +++ b/tex/context/base/syst-ini.mkiv @@ -343,11 +343,29 @@ \newdimen\scratchwidth \newdimen\scratchheight \newdimen\scratchdepth + \newdimen\scratchoffset +\newdimen\scratchleftoffset +\newdimen\scratchrightoffset +\newdimen\scratchtopoffset +\newdimen\scratchbottomoffset + \newdimen\scratchdistance + \newdimen\scratchhsize \newdimen\scratchvsize +\newdimen\scratchxoffset +\newdimen\scratchyoffset +\newdimen\scratchhoffset +\newdimen\scratchvoffset + +\newdimen\scratchxposition +\newdimen\scratchyposition + +\newcount\scratchnx +\newcount\scratchny + %D More allocations: \newskip \zeroskip \zeroskip = 0pt plus 0pt minus 0pt diff --git a/tex/context/base/util-sta.lua b/tex/context/base/util-sta.lua new file mode 100644 index 000000000..f94c1acdf --- /dev/null +++ b/tex/context/base/util-sta.lua @@ -0,0 +1,342 @@ +if not modules then modules = { } end modules ['util-sta'] = { + version = 1.001, + comment = "companion to util-ini.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local insert, remove, fastcopy, concat = table.insert, table.remove, table.fastcopy, table.concat +local format = string.format + +local trace_stacker = false trackers.register("stacker.resolve", function(v) trace_stacker = v end) + +local stacker = stacker or { } + +utilities.stacker = stacker + +local function start(s,t,first,last) + if s.mode == "switch" then + local n = tostring(t[last]) + if trace_stacker then + s.report("start: %s",n) + end + return n + else + local r = { } + for i=first,last do + r[#r+1] = tostring(t[i]) + end + local n = concat(r," ") + if trace_stacker then + s.report("start: %s",n) + end + return n + end +end + +local function stop(s,t,first,last) + if s.mode == "switch" then + local n = tostring(false) + if trace_stacker then + s.report("stop: %s",n) + end + return n + else + local r = { } + for i=last,first,-1 do + r[#r+1] = tostring(false) + end + local n = concat(r," ") + if trace_stacker then + s.report("stop: %s",n) + end + return n + end +end + +local function change(s,t1,first1,last1,t2,first2,last2) + if s.mode == "switch" then + local n = tostring(t2[last2]) + if trace_stacker then + s.report("change: %s",n) + end + return n + else + local r = { } + for i=last1,first1,-1 do + r[#r+1] = tostring(false) + end + local n = concat(r," ") + for i=first2,last2 do + r[#r+1] = tostring(t2[i]) + end + if trace_stacker then + s.report("change: %s",n) + end + return n + end +end + +function stacker.new(name) + + local s + + local stack = { } + local list = { } + local ids = { } + local hash = { } + + local hashing = true + + local function push(...) + local t = { ... } + for i=1,#t do + insert(stack,t[i]) + end + if hashing then + local c = concat(stack,"|") + local n = hash[c] + if not n then + n = #list+1 + hash[c] = n + list[n] = fastcopy(stack) + end + insert(ids,n) + return n + else + local n = #list+1 + list[n] = fastcopy(stack) + insert(ids,n) + return n + end + end + + local function pop() + remove(stack) + remove(ids) + return ids[#ids] or s.unset or -1 + end + + local function clean() + if #stack == 0 then + if trace_stacker then + s.report("%s list entries, %s stack entries",#list,#stack) + end + end + end + + local tops = { } + local top, switch + + local function resolve_begin(mode) + if mode then + switch = mode == "switch" + else + switch = s.mode == "switch" + end + top = { switch = switch } + insert(tops,top) + end + + local function resolve_step(ti) -- keep track of changes outside function ! + -- todo: optimize for n=1 etc + local result = nil + local noftop = #top + if ti > 0 then + local current = list[ti] + if current then + local noflist = #current + local nofsame = 0 + if noflist > noftop then + for i=1,noflist do + if current[i] == top[i] then + nofsame = i + else + break + end + end + else + for i=1,noflist do + if current[i] == top[i] then + nofsame = i + else + break + end + end + end + local plus = nofsame + 1 + if plus <= noftop then + if plus <= noflist then + if switch then + result = s.change(s,top,plus,noftop,current,nofsame,noflist) + else + result = s.change(s,top,plus,noftop,current,plus,noflist) + end + else + if switch then + result = s.change(s,top,plus,noftop,current,nofsame,noflist) + else + result = s.stop(s,top,plus,noftop) + end + end + elseif plus <= noflist then + if switch then + result = s.start(s,current,nofsame,noflist) + else + result = s.start(s,current,plus,noflist) + end + end + top = current + else + if 1 <= noftop then + result = s.stop(s,top,1,noftop) + end + top = { } + end + return result + else + if 1 <= noftop then + result = s.stop(s,top,1,noftop) + end + top = { } + return result + end + end + + local function resolve_end() + -- resolve_step(s.unset) + local noftop = #top + if noftop > 0 then + local result = s.stop(s,top,1,#top) + remove(tops) + top = tops[#tops] + switch = top and top.switch + return result + end + end + + local function resolve(t) + resolve_begin() + for i=1,#t do + resolve_step(t[i]) + end + resolve_end() + end + + local report = logs.reporter("stacker",name or nil) + + s = { + name = name or "unknown", + unset = -1, + report = report, + start = start, + stop = stop, + change = change, + push = push, + pop = pop, + clean = clean, + resolve = resolve, + resolve_begin = resolve_begin, + resolve_step = resolve_step, + resolve_end = resolve_end, + } + + return s -- we can overload functions + +end + +-- local s = utilities.stacker.new("demo") +-- +-- local unset = s.unset +-- local push = s.push +-- local pop = s.pop +-- +-- local t = { +-- unset, +-- unset, +-- push("a"), -- a +-- push("b","c"), -- a b c +-- pop(), -- a b +-- push("d"), -- a b d +-- pop(), -- a b +-- unset, +-- pop(), -- a +-- pop(), -- b +-- unset, +-- unset, +-- } +-- +-- s.resolve(t) + +-- demostacker = utilities.stacker.new("demos") +-- +-- local whatever = { +-- one = "1 0 0 RG 1 0 0 rg", +-- two = "1 1 0 RG 1 1 0 rg", +-- [false] = "0 G 0 g", +-- } +-- +-- local concat = table.concat +-- +-- local pdfliteral = nodes.pool.pdfliteral +-- +-- function demostacker.start(s,t,first,last) +-- local n = whatever[t[last]] +-- -- s.report("start: %s",n) +-- return pdfliteral(n) +-- end +-- +-- function demostacker.stop(s,t,first,last) +-- local n = whatever[false] +-- -- s.report("stop: %s",n) +-- return pdfliteral(n) +-- end +-- +-- function demostacker.change(s,t1,first1,last1,t2,first2,last2) +-- local n = whatever[t2[last2]] +-- -- s.report("change: %s",n) +-- return pdfliteral(n) +-- end +-- +-- demostacker.mode = "switch" +-- +-- local whatever = { +-- one = "/OC /test1 BDC", +-- two = "/OC /test2 BDC", +-- [false] = "EMC", +-- } +-- +-- demostacker = utilities.stacker.new("demos") +-- +-- function demostacker.start(s,t,first,last) +-- local r = { } +-- for i=first,last do +-- r[#r+1] = whatever[t[i]] +-- end +-- -- s.report("start: %s",concat(r," ")) +-- return pdfliteral(concat(r," ")) +-- end +-- +-- function demostacker.stop(s,t,first,last) +-- local r = { } +-- for i=last,first,-1 do +-- r[#r+1] = whatever[false] +-- end +-- -- s.report("stop: %s",concat(r," ")) +-- return pdfliteral(concat(r," ")) +-- end +-- +-- function demostacker.change(s,t1,first1,last1,t2,first2,last2) +-- local r = { } +-- for i=last1,first1,-1 do +-- r[#r+1] = whatever[false] +-- end +-- for i=first2,last2 do +-- r[#r+1] = whatever[t2[i]] +-- end +-- -- s.report("change: %s",concat(r," ")) +-- return pdfliteral(concat(r," ")) +-- end +-- +-- demostacker.mode = "stack" diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index eef140a33..a46ee2a44 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 : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 06/20/12 20:43:06 +-- merge date : 06/22/12 10:09:32 do -- begin closure to overcome local limits and interference |