summaryrefslogtreecommitdiff
path: root/tex
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2009-09-28 09:02:00 +0200
committerHans Hagen <pragma@wxs.nl>2009-09-28 09:02:00 +0200
commit29d92dfd14d30d1f304175d0abffb46fc86f5471 (patch)
tree62943c93911c0713181c5678fc169c1ddb01fa7d /tex
parentd83bd4e8a89d96bd9dfabf4427d02efb9623e5a2 (diff)
downloadcontext-29d92dfd14d30d1f304175d0abffb46fc86f5471.tar.gz
beta 2009.09.28 09:02
Diffstat (limited to 'tex')
-rw-r--r--tex/context/base/core-def.mkiv9
-rw-r--r--tex/context/base/lxml-ini.lua11
-rw-r--r--tex/context/base/lxml-sor.lua140
-rw-r--r--tex/context/base/lxml-sor.mkiv92
-rw-r--r--tex/context/base/page-lay.mkiv1
-rw-r--r--tex/context/base/spac-ver.lua43
-rw-r--r--tex/context/base/spac-ver.mkiv48
-rw-r--r--tex/context/base/strc-def.mkiv8
-rw-r--r--tex/context/base/strc-ren.mkiv29
-rw-r--r--tex/context/base/strc-sec.mkiv14
10 files changed, 351 insertions, 44 deletions
diff --git a/tex/context/base/core-def.mkiv b/tex/context/base/core-def.mkiv
index 583eb5870..0943a5cf9 100644
--- a/tex/context/base/core-def.mkiv
+++ b/tex/context/base/core-def.mkiv
@@ -69,4 +69,13 @@
\ifdefined\from \let\normalmathfrom \from \unexpanded\def\from {\mathortext\normalmathfrom \dospecialfrom } \else \let\from \dospecialfrom \fi
\ifdefined\over \let\normalmathover \over \unexpanded\def\over {\mathortext\normalmathover \dospecialabout} \else \let\over \dospecialabout \fi
+\appendtoks
+ \synchronizegloballinespecs
+ \synchronizelocallinespecs
+\to \everysetupbodyfont
+
+\appendtoks
+ \synchronizelocallinespecs
+\to \everyswitchtobodyfont
+
\protect \endinput
diff --git a/tex/context/base/lxml-ini.lua b/tex/context/base/lxml-ini.lua
index 4c6bae967..c8c54ea16 100644
--- a/tex/context/base/lxml-ini.lua
+++ b/tex/context/base/lxml-ini.lua
@@ -83,6 +83,17 @@ end
local splitter = lpeg.C((1-lpeg.P(":"))^1) * lpeg.P("::") * lpeg.C(lpeg.P(1)^1)
+lxml.idsplitter = splitter
+
+function lxml.splitid(id)
+ local d, i = splitter:match(id)
+ if d then
+ return d, i
+ else
+ return "", id
+ end
+end
+
local function get_id(id, qualified)
if type(id) == "table" then
return id
diff --git a/tex/context/base/lxml-sor.lua b/tex/context/base/lxml-sor.lua
new file mode 100644
index 000000000..5ef94cbf2
--- /dev/null
+++ b/tex/context/base/lxml-sor.lua
@@ -0,0 +1,140 @@
+if not modules then modules = { } end modules ['lxml-sor'] = {
+ version = 1.001,
+ comment = "companion to lxml-sor.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format, concat = string.format, table.concat
+local texsprint, ctxcatcodes = tex.sprint, tex.ctxcatcodes
+
+lxml.sorters = lxml.sorters or { }
+
+if not lxml.splitid then
+ local splitter = lpeg.C((1-lpeg.P(":"))^1) * lpeg.P("::") * lpeg.C(lpeg.P(1)^1)
+ function lxml.splitid(id)
+ local d, i = splitter:match(id)
+ if d then
+ return d, i
+ else
+ return "", id
+ end
+ end
+end
+
+local lists = { }
+
+function lxml.sorters.reset(name)
+ lists[name] = {
+ sorted = false,
+ entries = { },
+ reverse = { },
+ results = { },
+ }
+end
+
+function lxml.sorters.add(name,n,key)
+ local list = lists[name]
+ if list.sorted then
+ -- reverse is messed up, we could regenerate it and go on
+ else
+ local entries = list and list.entries
+ if entries then
+ local reverse = list.reverse
+ local e = reverse[n]
+ if e then
+ local keys = entries[e][2]
+ keys[#keys+1] = key
+ else
+ entries[#entries+1] = { n, { key } }
+ reverse[n] = #entries
+ end
+ end
+ end
+end
+
+function lxml.sorters.show(name)
+ local list = lists[name]
+ local entries = list and list.entries
+ local NC, NR, bold = context.NC, context.NR, context.bold -- somehow bold is not working
+ if entries then
+ context.starttabulate { "|Tr|Tr|Tl|" }
+ NC() bold("n") NC() bold("id") NC() bold("entry") NR() context.HL()
+ for i=1,#entries do
+ local entry = entries[i]
+ local document, node = lxml.splitid(entry[1])
+ NC() context(i) NC() context(node) NC() context(concat(entry[2]," ")) NR()
+ end
+ context.stoptabulate()
+ end
+end
+
+function lxml.sorters.compare(a,b)
+ return sorters.comparers.basic(a.split,b.split)
+end
+
+function lxml.sorters.sort(name)
+ local list = lists[name]
+ local entries = list and list.entries
+ if entries then
+ -- filtering
+ local results = { }
+ list.results = results
+ for i=1,#entries do
+ local entry = entries[i]
+ results[i] = {
+ entry = entry[1],
+ key = concat(entry[2], " "),
+ }
+ end
+ -- preparation
+ local strip = sorters.strip
+ local splitter = sorters.splitters.utf
+ for i=1, #results do
+ local r = results[i]
+ r.split = splitter(strip(r.key))
+ end
+ -- sorting
+ sorters.sort(results,lxml.sorters.compare)
+ -- finalizing
+ list.nofsorted = #results
+ local split = { }
+ for k=1,#results do -- rather generic so maybe we need a function
+ local v = results[k]
+ local entry, tag = sorters.firstofsplit(v.split)
+ local s = split[entry] -- keeps track of change
+ if not s then
+ s = { tag = tag, data = { } }
+ split[entry] = s
+ end
+ s.data[#s.data+1] = v
+ end
+ list.results = split
+ -- done
+ list.sorted = true
+ end
+end
+
+function lxml.sorters.flush(name,setup)
+ local list = lists[name]
+ local results = list and list.results
+ if results and next(results) then
+ for key, result in next, results do
+ local tag, data = result.tag, result.data
+--~ tex.sprint(ctxcatcodes,format("key=%s\\quad tag=%s\\blank",key,tag))
+ for d=1,#data do
+ local dr = data[d]
+ texsprint(ctxcatcodes,format("\\xmls{%s}{%s}",dr.entry,setup))
+ end
+--~ tex.sprint(ctxcatcodes,format("\\blank"))
+ end
+ else
+ local entries = list and list.entries
+ if entries then
+ for i=1,#entries do
+ texsprint(ctxcatcodes,format("\\xmls{%s}{%s}",entries[i][1],setup))
+ end
+ end
+ end
+end
diff --git a/tex/context/base/lxml-sor.mkiv b/tex/context/base/lxml-sor.mkiv
new file mode 100644
index 000000000..06ef5b6ab
--- /dev/null
+++ b/tex/context/base/lxml-sor.mkiv
@@ -0,0 +1,92 @@
+%D \module
+%D [ file=lxml-sor,
+%D version=2009.08.24,
+%D title=\CONTEXT\ \XML\ Support,
+%D subtitle=Sorting,
+%D author=Hans Hagen,
+%D date=\currentdate,
+%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
+%C
+%C This module is part of the \CONTEXT\ macro||package and is
+%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
+%C details.
+
+\writestatus{loading}{ConTeXt XML Support / Sorting}
+
+\registerctxluafile{lxml-sor}{1.001}
+
+\unprotect
+
+\def\xmlresetsorter #1{\ctxlua{lxml.sorters.reset("#1")}}
+\def\xmladdsortentry#1#2#3{\ctxlua{lxml.sorters.add("#1","#2","#3")}}
+\def\xmlshowsorter #1{\ctxlua{lxml.sorters.show("#1")}}
+\def\xmlflushsorter #1#2{\ctxlua{lxml.sorters.flush("#1","#2")}}
+\def\xmlsortentries #1{\ctxlua{lxml.sorters.sort("#1")}}
+
+\protect \endinput
+
+\startbuffer[test]
+<demo>
+ <entry>
+ <category>one</category>
+ <key>alpha</key>
+ <content>alpha indeed</content>
+ </entry>
+ <entry>
+ <category>one</category>
+ <key>gamma</key>
+ <content>gamma indeed</content>
+ </entry>
+ <entry>
+ <category>one</category>
+ <key>beta</key>
+ <content>beta indeed</content>
+ </entry>
+ <entry>
+ <category>two</category>
+ <key>alpha</key>
+ <content>alpha again</content>
+ </entry>
+ <entry>
+ <category>two</category>
+ <key>gamma</key>
+ <content>gamma again</content>
+ </entry>
+ <entry>
+ <category>two</category>
+ <key>beta</key>
+ <content>beta again</content>
+ </entry>
+</demo>
+\stopbuffer
+
+\startxmlsetups xml:mysetups
+ \xmlsetsetup{\xmldocument}{demo|entry|content}{xml:*}
+\stopxmlsetups
+
+\xmlregistersetup{xml:mysetups}
+
+\startxmlsetups xml:demo
+ \xmlresetsorter{demo}
+ \xmlfilter{#1}{entry/command(xml:entry:getkeys)}
+ \blank sortkeys: \blank\xmlshowsorter{demo}\blank
+ \xmlsortentries{demo}
+ \xmlflushsorter{demo}{xml:entry:flush}
+\stopxmlsetups
+
+\startxmlsetups xml:entry:getkeys
+ \xmladdsortentry{demo}{#1}{\xmltext{#1}{category}}
+ \xmladdsortentry{demo}{#1}{\xmltext{#1}{key|entry}}
+\stopxmlsetups
+
+\startxmlsetups xml:entry:flush
+ \xmltext{#1}{content}\par
+\stopxmlsetups
+
+\startxmlsetups xml:entry
+ \xmltext{#1}{content}\par
+\stopxmlsetups
+
+\starttext
+ \xmlprocessbuffer{main}{test}{}
+\stoptext
diff --git a/tex/context/base/page-lay.mkiv b/tex/context/base/page-lay.mkiv
index 179d9a29f..c7dabb66d 100644
--- a/tex/context/base/page-lay.mkiv
+++ b/tex/context/base/page-lay.mkiv
@@ -454,6 +454,7 @@
\setups[\layoutparameter\c!setups]% depends on gridsnapping !
\simplesetupwhitespace
\simplesetupblank
+ \setupinterlinespace[\v!reset]% \synchronizegloballinespecs
\global\cutspace\layoutparameter\c!cutspace
\relax
\doifelse{\layoutparameter\c!width}\v!middle
diff --git a/tex/context/base/spac-ver.lua b/tex/context/base/spac-ver.lua
index 4374eb4d4..2ef7afbf9 100644
--- a/tex/context/base/spac-ver.lua
+++ b/tex/context/base/spac-ver.lua
@@ -88,6 +88,7 @@ local default = {
local fractions = {
minheight = "hfraction", maxheight = "hfraction",
mindepth = "dfraction", maxdepth = "dfraction",
+ top = "tlines", bottom = "blines",
}
local colonsplitter = lpeg.splitat(":")
@@ -132,17 +133,17 @@ function vspacing.define_snap_method(name,method)
tex.write(n)
end
-local snapht, snapdp, snaphtdp = 0, 0, 0
-
-function vspacing.freeze_snap_method(ht,dp)
- snapht, snapdp = ht or texdimen.bodyfontstrutheight, dp or texdimen.bodyfontstrutdepth
- snaphtdp = snapht + snapdp
-end
-
local function snap_hlist(current,method,height,depth) -- method.strut is default
+ local snapht, snapdp
+ if method["local"] then
+ snapht, snapdp = texdimen.bodyfontstrutheight, texdimen.bodyfontstrutdepth
+ else
+ snapht, snapdp = texdimen.globalbodyfontstrutheight, texdimen.globalbodyfontstrutdepth
+ end
local h, d = height or current.height, depth or current.depth
local hr, dr, ch, cd = method.hfraction or 1, method.dfraction or 1, h, d
local done, plusht, plusdp = false, snapht, snapdp
+ local snaphtdp = snapht + snapdp
if method.none then
plusht, plusdp = 0, 0
end
@@ -203,6 +204,12 @@ local function snap_hlist(current,method,height,depth) -- method.strut is defaul
else
cd = plusdp
end
+ if method.top then
+ ch = ch + (method.tlines or 1) * snaphtdp
+ end
+ if method.bottom then
+ cd = cd + (method.blines or 1) * snaphtdp
+ end
if not height then
current.height = ch
end
@@ -217,23 +224,12 @@ local function snap_topskip(current,method)
local w = spec.width
local wd = w
if spec then
- wd = 0 -- snapht - w
+ wd = 0
spec.width = wd
end
return w, wd
end
-local function snapped_spec(current)
- local spec = current.spec
- if spec then
- local w = ceil(spec.width/snaphtdp)*snaphtdp
- spec.width = w
- return w
- else
- return 0
- end
-end
-
vspacing.categories = {
[0] = 'discard',
[1] = 'largest',
@@ -569,11 +565,8 @@ end
local function collapser(head,where,what,trace,snap) -- maybe also pass tail
if trace then
reset_tracing(head)
- trace_info("start analyzing",where,what)
end
local current, oldhead = head, head
- snapht, snapdp = ht or texdimen.bodyfontstrutheight, dp or texdimen.bodyfontstrutdepth
- snaphtdp = snapht + snapdp
local glue_order, glue_data, force_glue = 0, nil, false
local penalty_order, penalty_data, natural_penalty = 0, nil, nil
local parskip, ignore_parskip, ignore_following, ignore_whitespace, keep_together = nil, false, false, false, false
@@ -603,6 +596,11 @@ local function collapser(head,where,what,trace,snap) -- maybe also pass tail
penalty_order, penalty_data, natural_penalty = 0, nil, nil
parskip, ignore_parskip, ignore_following, ignore_whitespace = nil, false, false, false
end
+ if trace_vsnapping then
+ logs.report("snapper", "global ht/dp = %s/%s, local ht/dp = %s/%s",
+ texdimen.globalbodyfontstrutheight, texdimen.globalbodyfontstrutdepth,
+ texdimen.bodyfontstrutheight, texdimen.bodyfontstrutdepth)
+ end
while current do
local id, subtype = current.id, current.subtype
if id == hlist or id == vlist then
@@ -903,7 +901,6 @@ current = current.next
if glue_data then
if not tail then tail = find_node_tail(head) end
if trace then trace_done("result",glue_data) end
---~ snapped_spec(glue_data)
if force_glue then
head, tail = forced_skip(head,tail,glue_data.spec.width,"after",trace)
free_glue_node(glue_data)
diff --git a/tex/context/base/spac-ver.mkiv b/tex/context/base/spac-ver.mkiv
index ae0fbf003..bce0fb826 100644
--- a/tex/context/base/spac-ver.mkiv
+++ b/tex/context/base/spac-ver.mkiv
@@ -134,18 +134,23 @@
% \appendtoks \setrelativeinterlinespace \to \everybodyfont
+\newtoks \everysetupglobalinterlinespace
+\newtoks \everysetuplocalinterlinespace
+
\def\complexsetupinterlinespace[#1]% \commalistelement ipv #1
- {\doifassignmentelse{#1}\setupspecifiedinterlinespace\setuprelativeinterlinespace[#1]}
+ {\doifassignmentelse{#1}\setupspecifiedinterlinespace\setuprelativeinterlinespace[#1]%
+ \the\iflocalinterlinespace\everysetuplocalinterlinespace\else\everysetupglobalinterlinespace\fi}
\def\setuplocalinterlinespace[#1]%
{\localinterlinespacetrue
\setupinterlinespace[#1]%
\localinterlinespacefalse}
-\def\simplesetupinterlinespace
+\def\simplesetupinterlinespace % adapts to the font
{\localinterlinespacetrue
\setfontparameters
\updateraggedskips % funny one here
+ \the\everysetuplocalinterlinespace
\localinterlinespacefalse}
\definecomplexorsimple\setupinterlinespace
@@ -637,7 +642,7 @@
\normallineskip\minimumlinedistance\relax % \onepoint\relax
\normallineskiplimit\zeropoint\relax
\normalbaselines
- \dosetupgridsnapping
+ %\dosetupgridsnapping
}
\def\spacing#1%
@@ -1164,10 +1169,14 @@
% TODO: NAMED SNAPPERS
-\newdimen \bodyfontlineheight
+\newskip \bodyfontlineheight
\newdimen \bodyfontstrutheight
\newdimen \bodyfontstrutdepth
+\newskip \globalbodyfontlineheight
+\newdimen \globalbodyfontstrutheight
+\newdimen \globalbodyfontstrutdepth
+
% \appendtoks
% \dosetupgridsnapping
% \to \everysetupbodyfont
@@ -1242,16 +1251,33 @@
\definegridsnapping[\v!max] [\v!maxdepth,\v!maxheight,\v!strut]
\definegridsnapping[\v!min] [\v!mindepth,\v!minheight,\v!strut]
-\newtoks\everysetupgridsnapping
+\newtoks\everysetupgridsnapping % this only happens at the setuplayout level
+
+\def\dosetupgridsnapping{\the\everysetupgridsnapping} % not used !
+
+\def\synchronizelocallinespecs
+ {\bodyfontlineheight \normallineheight
+ \bodyfontstrutheight\strutheight
+ \bodyfontstrutdepth \strutdepth}
-\def\dosetupgridsnapping{\the\everysetupgridsnapping}
+\def\synchronizegloballinespecs
+ {\global\globalbodyfontlineheight \normallineheight
+ \global\globalbodyfontstrutheight\strutheight
+ \global\globalbodyfontstrutdepth \strutdepth}
+
+% \appendtoks
+% \synchronizegloballinespecs
+% \synchronizelocallinespecs
+% \to \everysetupgridsnapping
+
+\appendtoks
+ \synchronizegloballinespecs
+ \synchronizelocallinespecs
+\to \everysetupglobalinterlinespace
\appendtoks
- \bodyfontlineheight \normallineheight
- \bodyfontstrutheight \strutheight
- \bodyfontstrutdepth \strutdepth
- \ctxlua{vspacing.freeze_snap_method()}%
-\to \everysetupgridsnapping
+ \synchronizelocallinespecs
+\to \everysetuplocalinterlinespace
% \appendtoks
% \resetsnapvalues
diff --git a/tex/context/base/strc-def.mkiv b/tex/context/base/strc-def.mkiv
index 2395ddf6c..01336b4d9 100644
--- a/tex/context/base/strc-def.mkiv
+++ b/tex/context/base/strc-def.mkiv
@@ -76,8 +76,11 @@
%\c!margintext=,
\c!number=\v!yes,
\c!numbercolor=\structureheadparameter\c!color,
- %\c!numbercommand=,
+ \c!textcolor=\structureheadparameter\c!color,
\c!numberstyle=\structureheadparameter\c!style,
+ \c!textstyle=\structureheadparameter\c!style,
+ %\c!numbercommand=,
+ %\c!textcommand=,
\c!ownnumber=\v!no,
%\c!page=,
\c!placehead=\v!yes,
@@ -90,9 +93,6 @@
%\c!strut=,
%\c!style=,
%\c!text=,
- \c!textcolor=\structureheadparameter\c!color,
- %\c!textcommand=,
- \c!textstyle=\structureheadparameter\c!style,
%\c!tolerance=
]
diff --git a/tex/context/base/strc-ren.mkiv b/tex/context/base/strc-ren.mkiv
index 98cdca097..4a019837e 100644
--- a/tex/context/base/strc-ren.mkiv
+++ b/tex/context/base/strc-ren.mkiv
@@ -34,6 +34,12 @@
\def\doplaceheadtextcomponent#1#2%
{\begingroup
\dosetstructureheadattributes\c!style\c!color
+ % nasty, we need to adapt twice
+ \ifconditional\structureheadisdisplay % \ifdisplaysectionhead
+ \setupinterlinespace
+ \else
+ \setupspacing
+ \fi
\dosetstructureheadattributes\c!textstyle\c!textcolor
\dontconvertfont
\ifconditional\structureheadisdisplay % \ifdisplaysectionhead
@@ -240,10 +246,25 @@
\v!unknown=>\hangheadplacement\noflines\numexpr0\commalistelement-1\relax]%
% so far
\let\headlastlinewidth\!!zeropoint
- \snaptogrid[\structureheadparameter\c!grid]\hbox
- {\hskip\localheadskip
- \hskip\structureheadparameter\c!margin\relax
- \box\sectionheadbox}%
+ % kind of special, we want to snap heads also according to local specs local
+ \ifgridsnapping
+ \begingroup
+ \ifconditional\structureheadisdisplay
+ \edef\currentstructureheadgridsnapping{\structureheadparameter\c!grid}%
+ \ifx\currentstructureheadgridsnapping\empty\else
+ \dosetstructureheadattributes\c!style\c!color
+ \setupinterlinespace
+ \dosetstructureheadattributes\c!textstyle\c!textcolor
+ \setupinterlinespace
+ \fi
+ \fi
+ \snaptogrid[\structureheadparameter\c!grid]\hbox
+ {\hskip\localheadskip\hskip\structureheadparameter\c!margin\box\sectionheadbox}%
+ \endgroup
+ \else
+ \hbox
+ {\hskip\localheadskip\hskip\structureheadparameter\c!margin\box\sectionheadbox}%
+ \fi
\flushnotes % new, not really needed
\endgraf
\ifvmode
diff --git a/tex/context/base/strc-sec.mkiv b/tex/context/base/strc-sec.mkiv
index aa1d4721f..7510934fd 100644
--- a/tex/context/base/strc-sec.mkiv
+++ b/tex/context/base/strc-sec.mkiv
@@ -59,6 +59,8 @@
\def\dostructureheadparentparameter #1#2{\ifx#1\relax\s!empty\else\dostructureheadparameter #1#2\fi}
\def\dostructureheadparentparameterhash#1#2{\ifx#1\relax \else\dostructureheadparameterhash#1#2\fi}
+\def\structureheadparameterstrict#1{\csname\ifcsname\??nh\currentstructurehead#1\endcsname\??nh\currentstructurehead#1\else\s!empty\fi\endcsname}
+
\def\dosetstructureheadattributes#1#2% style color
{\edef\fontattributehash {\structureheadparameterhash#1}%
\edef\colorattributehash{\structureheadparameterhash#2}%
@@ -76,12 +78,20 @@
{\global\advance\maxstructuredepth\plusone
\setevalue{\??nh#1\c!level}{\the\maxstructuredepth}%
\setstructurelevel{#1}{\the\maxstructuredepth}%
-% \letvalue{\??nh#1\c!marking}\empty % ?
+% \letvalue{\??nh#1\c!marking}\empty % ?
%\writestatus{structure}{#1\ifx\laststructuresectionname\empty\else\space->\space\laststructuresectionname\fi}%
\normalexpanded{\noexpand\getparameters[\??nh#1][\s!parent=\??nh\laststructuresectionname]}%
+ % this is a rather practical default that we don't want to be part of the parent chain
+ % lookup mechanism; it's also mkii compativle; this might become \everystructureheaddefine
+ \getparameters[\??nh#1]
+ [ \c!textstyle=\structureheadparameterstrict\c!style,
+ \c!textcolor=\structureheadparameterstrict\c!color,
+ \c!numberstyle=\structureheadparameterstrict\c!style,
+ \c!numbercolor=\structureheadparameterstrict\c!color]%
+ % so far for these default inheritances
\definemarking[#1]%
\ifnum\maxstructuredepth>\plusone
-% \normalexpanded{\noexpand\couplemarking[#1][\laststructuresectionname]}% so, the child inherits settings from the parent
+% \normalexpanded{\noexpand\couplemarking[#1][\laststructuresectionname]}% so, the child inherits settings from the parent
\normalexpanded{\noexpand\relatemarking[#1][\laststructuresectionname]}% so, the parent will reset the child
\fi
\xdef\laststructuresectionname{#1}}}