summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2013-08-24 01:32:00 +0200
committerHans Hagen <pragma@wxs.nl>2013-08-24 01:32:00 +0200
commitd1ee576345717d670c5ee5297222fab3a38762dc (patch)
treea68d6e992bcab7d8b138ea12aff23d6b6b34c6c7
parentdeb71b2066bcd0091e3e677b6bae59d4f7e07acf (diff)
downloadcontext-d1ee576345717d670c5ee5297222fab3a38762dc.tar.gz
beta 2013.08.24 01:32
-rw-r--r--metapost/context/base/mp-mlib.mpiv9
-rw-r--r--metapost/context/base/mp-text.mpii7
-rw-r--r--tex/context/base/cont-new.mkiv2
-rw-r--r--tex/context/base/context-version.pdfbin4102 -> 4105 bytes
-rw-r--r--tex/context/base/context.mkiv6
-rw-r--r--tex/context/base/core-def.mkiv3
-rw-r--r--tex/context/base/status-files.pdfbin24743 -> 24733 bytes
-rw-r--r--tex/context/base/status-lua.log2
-rw-r--r--tex/context/base/status-mkiv.lua18
-rw-r--r--tex/context/base/task-ini.lua6
-rw-r--r--tex/context/base/typo-drp.lua207
-rw-r--r--tex/context/base/typo-drp.mkiv (renamed from tex/context/base/typo-par.mkiv)73
-rw-r--r--tex/context/base/typo-fln.lua293
-rw-r--r--tex/context/base/typo-fln.mkiv66
-rw-r--r--tex/context/base/typo-par.lua186
-rw-r--r--tex/generic/context/luatex/luatex-fonts-merged.lua2
16 files changed, 448 insertions, 432 deletions
diff --git a/metapost/context/base/mp-mlib.mpiv b/metapost/context/base/mp-mlib.mpiv
index 9a2042924..e768efaec 100644
--- a/metapost/context/base/mp-mlib.mpiv
+++ b/metapost/context/base/mp-mlib.mpiv
@@ -255,6 +255,15 @@ mfun_labtype.drt := 12 ;
mfun_labtype.origin := 0 ;
mfun_labtype.raw := 0 ;
+% installlabel.foo ( 0, 1, 1, (.5,-1) ) ;
+
+vardef installlabel@# (expr type, x, y, offset) =
+ numeric labtype@# ; labtype@# := type ;
+ pair laboff @# ; laboff @# := offset ;
+ numeric labxf @# ; labxf @# := x ;
+ numeric labyf @# ; labyf @# := y ;
+enddef ;
+
vardef thetextext@#(expr p,z) =
% interim labeloffset := textextoffset ;
if string p :
diff --git a/metapost/context/base/mp-text.mpii b/metapost/context/base/mp-text.mpii
index d529e9242..5f96f6788 100644
--- a/metapost/context/base/mp-text.mpii
+++ b/metapost/context/base/mp-text.mpii
@@ -109,6 +109,13 @@ pair laboff.raw ; laboff.raw = (0,0) ; % (infinity,infinity) ;
laboff.origin = (0,0) ; labxf.origin := 0 ; labyf.origin := 0 ;
laboff.raw = (0,0) ; labxf.raw := 0 ; labyf.raw := 0 ;
+vardef installlabel@# (expr type, x, y, offset) =
+ numeric labtype@# ; labtype@# := type ;
+ pair laboff @# ; laboff @# := offset ;
+ numeric labxf @# ; labxf @# := x ;
+ numeric labyf @# ; labyf @# := y ;
+enddef ;
+
vardef thelabel@#(expr s, z) =
save p ; picture p ;
p = s if not picture s : infont defaultfont scaled defaultscale fi ;
diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv
index d9bd31615..c10ef048d 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{2013.08.23 13:16}
+\newcontextversion{2013.08.24 01:32}
%D This file is loaded at runtime, thereby providing an excellent place for
%D hacks, patches, extensions and new features.
diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf
index c4f7512db..c72b89b9b 100644
--- a/tex/context/base/context-version.pdf
+++ b/tex/context/base/context-version.pdf
Binary files differ
diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv
index b10febbb4..68f642e5d 100644
--- a/tex/context/base/context.mkiv
+++ b/tex/context/base/context.mkiv
@@ -25,7 +25,7 @@
%D up and the dependencies are more consistent.
\edef\contextformat {\jobname}
-\edef\contextversion{2013.08.23 13:16}
+\edef\contextversion{2013.08.24 01:32}
\edef\contextkind {beta}
%D For those who want to use this:
@@ -296,7 +296,6 @@
\loadmarkfile{typo-pag}
\loadmarkfile{typo-mar}
\loadmarkfile{typo-itm}
-\loadmarkfile{typo-fln}
\loadmarkfile{buff-ini}
\loadmarkfile{buff-ver}
@@ -385,7 +384,8 @@
\loadmarkfile{typo-dig}
\loadmarkfile{typo-rep}
\loadmkvifile{typo-txt}
-\loadmarkfile{typo-par}
+\loadmarkfile{typo-drp}
+\loadmarkfile{typo-fln}
\loadmkvifile{type-ini}
\loadmarkfile{type-set}
diff --git a/tex/context/base/core-def.mkiv b/tex/context/base/core-def.mkiv
index bc7432059..cc695ea90 100644
--- a/tex/context/base/core-def.mkiv
+++ b/tex/context/base/core-def.mkiv
@@ -45,7 +45,8 @@
\flushpostponednodedata
\typo_delimited_repeat
\insertparagraphintro
- \typo_firstline_set
+ \typo_initial_handle
+ \typo_firstline_handle
\to \everypar
\appendtoks
diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf
index 2c1009b02..97db9541d 100644
--- a/tex/context/base/status-files.pdf
+++ b/tex/context/base/status-files.pdf
Binary files differ
diff --git a/tex/context/base/status-lua.log b/tex/context/base/status-lua.log
index 064c85656..6c4402221 100644
--- a/tex/context/base/status-lua.log
+++ b/tex/context/base/status-lua.log
@@ -1,6 +1,6 @@
(cont-yes.mkiv
-ConTeXt ver: 2013.08.23 13:16 MKIV beta fmt: 2013.8.23 int: english/english
+ConTeXt ver: 2013.08.24 01:32 MKIV beta fmt: 2013.8.24 int: english/english
system > 'cont-new.mkiv' loaded
(cont-new.mkiv)
diff --git a/tex/context/base/status-mkiv.lua b/tex/context/base/status-mkiv.lua
index 6901db4cc..75ec24b99 100644
--- a/tex/context/base/status-mkiv.lua
+++ b/tex/context/base/status-mkiv.lua
@@ -1586,8 +1586,13 @@ return {
},
{
category = "mkiv",
- comment = "might get extended",
- filename = "typo-par",
+ filename = "typo-drp",
+ loading = "always",
+ status = "okay",
+ },
+ {
+ category = "mkiv",
+ filename = "typo-fln",
loading = "always",
status = "okay",
},
@@ -4788,8 +4793,13 @@ return {
},
{
category = "lua",
- filename = "typo-par",
- status = "todo",
+ filename = "typo-drp",
+ status = "okay",
+ },
+ {
+ category = "lua",
+ filename = "typo-fln",
+ status = "okay",
},
{
category = "lua",
diff --git a/tex/context/base/task-ini.lua b/tex/context/base/task-ini.lua
index ac3aee03a..5ee7e8994 100644
--- a/tex/context/base/task-ini.lua
+++ b/tex/context/base/task-ini.lua
@@ -33,6 +33,8 @@ appendaction("processors", "characters", "scripts.injectors.handler")
appendaction("processors", "words", "builders.kernel.hyphenation") -- always on
appendaction("processors", "words", "languages.words.check") -- disabled
+
+appendaction("processors", "words", "typesetters.initials.handler") -- disabled
appendaction("processors", "words", "typesetters.firstlines.handler") -- disabled
appendaction("processors", "fonts", "builders.paragraphs.solutions.splitters.split") -- experimental
@@ -48,7 +50,7 @@ appendaction("processors", "lists", "typesetters.spacings.handler")
appendaction("processors", "lists", "typesetters.kerns.handler") -- disabled
appendaction("processors", "lists", "typesetters.digits.handler") -- disabled (after otf handling)
appendaction("processors", "lists", "typesetters.italics.handler") -- disabled (after otf/kern handling)
-appendaction("processors", "lists", "typesetters.paragraphs.handler") -- disabled
+------------("processors", "lists", "typesetters.initials.handler") -- disabled
appendaction("shipouts", "normalizers", "nodes.handlers.cleanuppage") -- disabled
appendaction("shipouts", "normalizers", "typesetters.alignments.handler")
@@ -124,12 +126,12 @@ disableaction("processors", "typesetters.digits.handler")
disableaction("processors", "typesetters.breakpoints.handler")
disableaction("processors", "typesetters.directions.handler")
disableaction("processors", "languages.words.check")
+disableaction("processors", "typesetters.initials.handler")
disableaction("processors", "typesetters.firstlines.handler")
disableaction("processors", "typesetters.spacings.handler")
disableaction("processors", "typesetters.kerns.handler")
disableaction("processors", "typesetters.italics.handler")
disableaction("processors", "nodes.handlers.stripping")
-disableaction("processors", "typesetters.paragraphs.handler")
disableaction("shipouts", "typesetters.alignments.handler")
disableaction("shipouts", "nodes.rules.handler")
diff --git a/tex/context/base/typo-drp.lua b/tex/context/base/typo-drp.lua
new file mode 100644
index 000000000..b7815efc2
--- /dev/null
+++ b/tex/context/base/typo-drp.lua
@@ -0,0 +1,207 @@
+if not modules then modules = { } end modules ['typo-drp'] = {
+ version = 1.001,
+ comment = "companion to typo-drp.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- A playground for experiments. Currently we only have a dropped caps as special
+-- but there might be more, so for the moment we keep this 'paragraphs' namespace
+-- for this.
+
+local tonumber, type, next = tonumber, type, next
+local ceil = math.ceil
+
+local utfbyte = utf.byte
+local utfchar = utf.char
+
+local trace_initials = false trackers.register("typesetters.initials", function(v) trace_initials = v end)
+local report_initials = logs.reporter("nodes","initials")
+
+local initials = typesetters.paragraphs or { }
+typesetters.initials = initials or { }
+
+local nodes = nodes
+local tasks = nodes.tasks
+
+local hpack_nodes = nodes.hpack
+local nodecodes = nodes.nodecodes
+local whatsitcodes = nodes.whatsitcodes
+
+local new_kern = nodes.pool.kern
+local insert_before = nodes.insert_before
+local insert_after = nodes.insert_after
+
+local variables = interfaces.variables
+local v_default = variables.default
+local v_margin = variables.margin
+
+local texget = tex.get
+local texsetattribute = tex.setattribute
+local unsetvalue = attributes.unsetvalue
+
+local glyph_code = nodecodes.glyph
+local hlist_code = nodecodes.hlist
+local kern_node = nodecodes.kern
+local whatsit_code = nodecodes.whatsit
+local localpar_code = whatsitcodes.localpar
+
+local actions = { }
+initials.actions = actions
+
+local a_initial = attributes.private("initial")
+local a_color = attributes.private('color')
+local a_transparency = attributes.private('transparency')
+local a_colorspace = attributes.private('colormodel')
+
+local settings = nil
+
+function initials.set(specification)
+ settings = specification or { }
+ settings.enabled = true
+ tasks.enableaction("processors","typesetters.initials.handler")
+ if trace_initials then
+ report_initials("enabling initials")
+ end
+ texsetattribute(a_initial,1)
+end
+
+commands.setinitial = initials.set
+
+-- dropped caps experiment (will be done properly when luatex
+-- stores the state in the local par node) .. btw, search still
+-- works with dropped caps, as does an export
+
+-- we need a 'par' attribute and in fact for dropped caps we don't need
+-- need an attribute ... dropit will become s state counter (or end up
+-- in the localpar user data
+
+-- for the moment, each paragraph gets a number as id (attribute) ..problem
+-- with nesting .. or anyhow, needed for tagging anyway
+
+-- todo: prevent linebreak .. but normally a initial ends up at the top of
+-- a page so this has a low priority
+
+actions[v_default] = function(head,setting)
+ local done = false
+ if head.id == whatsit_code and head.subtype == localpar_code then
+ -- begin of par
+ local first = head.next
+ -- parbox .. needs to be set at 0
+ if first and first.id == hlist_code then
+ first = first.next
+ end
+ -- we need to skip over kerns and glues (signals)
+ while first and first.id ~= glyph_code do
+ first = first.next
+ end
+ if first and first.id == glyph_code then
+ local char = first.char
+ local prev = first.prev
+ local next = first.next
+ -- if prev.id == hlist_code then
+ -- -- set the width to 0
+ -- end
+ if next and next.id == kern_node then
+ next.kern = 0
+ end
+ if setting.font then
+ first.font = setting.font
+ end
+ -- can be a helper
+ local ma = setting.ma or 0
+ local ca = setting.ca
+ local ta = setting.ta
+ if ca and ca > 0 then
+ first[a_colorspace] = ma == 0 and 1 or ma
+ first[a_color] = ca
+ end
+ if ta and ta > 0 then
+ first[a_transparency] = ta
+ end
+ --
+ local width = first.width
+ local height = first.height
+ local depth = first.depth
+ local distance = setting.distance or 0
+ local voffset = setting.voffset or 0
+ local hoffset = setting.hoffset or 0
+ first.xoffset = - width - hoffset - distance - parindent
+ first.yoffset = - height - voffset
+ if true then
+ -- needed till we can store parindent with localpar
+ first.prev = nil
+ first.next = nil
+ local h = hpack_nodes(first)
+ h.width = 0
+ h.height = 0
+ h.depth = 0
+ prev.next = h
+ next.prev = h
+ h.next = next
+ h.prev = prev
+ end
+ if setting.location == v_margin then
+ -- okay
+ else
+ local lines = tonumber(setting.n) or 0
+ if lines == 0 then -- safeguard, not too precise
+ lines = ceil((height+voffset) / texget("baselineskip").width)
+ end
+ -- We cannot set parshape yet ... when we can I'll add a slope
+ -- option (positive and negative, in emwidth).
+ local hangafter = - lines
+ local hangindent = width + distance + parindent
+ if trace_initials then
+ report_initials("setting hangafter to %i and hangindent to %p",hangafter,hangindent)
+ end
+ tex.hangafter = hangafter
+ tex.hangindent = hangindent
+ if parindent ~= 0 then
+ insert_after(first,first,new_kern(-parindent))
+ end
+ end
+ done = true
+ end
+ end
+ return head, done
+end
+
+local function process(namespace,attribute,head)
+ local start = head
+ local attr = nil
+ while start do
+ attr = start[attribute]
+ if attr then
+ break
+ elseif start.id == glyph then
+ break
+ else
+ start = start.next
+ end
+ end
+ if attr then
+ -- here as we can process nested boxes first so we need to keep state
+ tasks.disableaction("processors","typesetters.initials.handler")
+ -- texsetattribute(attribute,unsetvalue)
+ local alternative = settings.alternative or v_default
+ local action = actions[alternative] or actions[v_default]
+ if action then
+ if trace_initials then
+ report_initials("processing initials, alternative %a",alternative)
+ end
+ local head, done = action(head,settings)
+ return head, done
+ end
+ end
+ return head, false
+end
+
+initials.attribute = a_initial
+
+initials.handler = nodes.installattributehandler {
+ name = "initials",
+ namespace = initials,
+ processor = process,
+}
diff --git a/tex/context/base/typo-par.mkiv b/tex/context/base/typo-drp.mkiv
index 73396716b..c78ed8d61 100644
--- a/tex/context/base/typo-par.mkiv
+++ b/tex/context/base/typo-drp.mkiv
@@ -1,8 +1,8 @@
%D \module
-%D [ file=typo-par,
+%D [ file=typo-drp, % was typo-par
%D version=2011.10.27,
%D title=\CONTEXT\ Typesetting Macros,
-%D subtitle=Paragraphs,
+%D subtitle=Initials,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
@@ -11,21 +11,18 @@
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
-\writestatus{loading}{ConTeXt Typesetting Macros / Paragraphs}
+\writestatus{loading}{ConTeXt Typesetting Macros / Initials}
%D This will change ... par specific attribute set and such.
\unprotect
-\registerctxluafile{typo-par}{1.001}
+\registerctxluafile{typo-drp}{1.001}
-\definesystemattribute[paragraphspecial][public]
-
-\unexpanded\def\setparagraphspecial[#1]%
- {\ctxlua{typesetters.paragraphs.set("#1")}}
+\definesystemattribute[initial][public]
\appendtoks
- \attribute\paragraphspecialattribute\attributeunsetvalue
+ \attribute\initialattribute\attributeunsetvalue
\to \everyforgetall
%D For the moment here: dropped caps redone. In addition to the
@@ -53,11 +50,7 @@
\installcorenamespace{initial}
-\installsimplecommandhandler \??initial {initial} \??initial
-
-\appendtoks
- \checkinitialparent % this might become automatic
-\to \everysetupinitial
+\installcommandhandler \??initial {initial} \??initial
\def\v_typo_initials_auto_scale % magic
{\the\dimexpr\lineheight*\initialparameter\c!n-\initialparameter\c!voffset\relax}
@@ -77,33 +70,43 @@
\unexpanded\def\placeinitial
{\dosingleempty\typo_initials_place}
-\def\typo_initials_place[#1]% todo: optional text
+\def\typo_initials_place[#1]% old command
{\par
+ \namedinitialparameter{#1}\c!before
+ \setinitial[#1]}
+
+\unexpanded\def\setinitial
+ {\dosingleempty\typo_initials_set}
+
+\unexpanded\def\typo_initials_set[#1]%
+ {\edef\typo_initial_handle{\typo_initial_handle_indeed{#1}}}
+
+\unexpanded\def\typo_initial_handle_indeed#1%
+ {\dontleavehmode
\begingroup
\edef\currentinitial{#1}%
- \begingroup
- \useinitialcolorparameter\c!color
- \ctxlua{typesetters.paragraphs.droppers.set {
- location = "\initialparameter\c!location",
- enabled = true,
- n = \number\initialparameter\c!n,
- distance = \number\dimexpr\initialparameter\c!distance,
- hoffset = \number\dimexpr\initialparameter\c!hoffset,
- voffset = \number\dimexpr\initialparameter\c!voffset,
- ma = \the\attribute\colormodelattribute ,
- ca = \the\attribute\colorattribute ,
- ta = \the\attribute\transparencyattribute
- }}%
- \stopluacode
- \endgroup
- \begingroup
\doifelsenothing{\initialparameter\c!style}
{\definedfont[\initialparameter\s!font]}
{\useinitialstyleparameter\c!style}%
- \ctxlua{typesetters.paragraphs.droppers.freeze()}%
- \endgroup
+ \useinitialcolorparameter\c!color
+ \ctxcommand{setinitial{
+ location = "\initialparameter\c!location",
+ enabled = true,
+ n = \number\initialparameter\c!n,
+ distance = \number\dimexpr\initialparameter\c!distance,
+ hoffset = \number\dimexpr\initialparameter\c!hoffset,
+ voffset = \number\dimexpr\initialparameter\c!voffset,
+ ma = \the\attribute\colormodelattribute ,
+ ca = \the\attribute\colorattribute ,
+ ta = \the\attribute\transparencyattribute,
+ font = \fontid\font,
+ dynamic = \number\attribute\zerocount,
+ }}%
+ \stopluacode
+ \kern\zeropoint % we need a node
\endgroup
- \setparagraphspecial[1]%
- \namedinitialparameter{#1}\c!before}
+ \globallet\typo_initial_handle\relax}
+
+\let\typo_initial_handle\relax
\protect \endinput
diff --git a/tex/context/base/typo-fln.lua b/tex/context/base/typo-fln.lua
index 322374ac0..b1a486779 100644
--- a/tex/context/base/typo-fln.lua
+++ b/tex/context/base/typo-fln.lua
@@ -14,126 +14,133 @@ if not modules then modules = { } end modules ['typo-fln'] = {
-- todo: only letters (no punctuation)
-- todo: nuts
-local trace_firstlines = false trackers.register("typesetters.firstlines", function(v) trace_firstlines = v end)
+local trace_firstlines = false trackers.register("typesetters.firstlines", function(v) trace_firstlines = v end)
+local report_firstlines = logs.reporter("nodes","firstlines")
-local report_firstlines = logs.reporter("nodes","firstlines")
+typesetters.firstlines = typesetters.firstlines or { }
+local firstlines = typesetters.firstlines
-local nodes = nodes
-local tasks = nodes.tasks
+local nodes = nodes
+local tasks = nodes.tasks
-local nodecodes = nodes.nodecodes
-local glyph = nodecodes.glyph
-local rule = nodecodes.rule
-local disc = nodecodes.disc
+local nodecodes = nodes.nodecodes
+local glyph = nodecodes.glyph
+local rule = nodecodes.rule
+local disc = nodecodes.disc
+local kern = nodecodes.kern
-local traverse_id = nodes.traverse_id
-local free_node_list = nodes.flush_list
-local copy_node_list = nodes.copy_list
-local insert_node_after = nodes.insert_after
-local hpack_node_list = nodes.hpack
+local traverse_id = nodes.traverse_id
+local free_node_list = nodes.flush_list
+local free_node = nodes.flush_node
+local copy_node_list = nodes.copy_list
+local insert_node_after = nodes.insert_after
+local insert_node_before = nodes.insert_before
+local hpack_node_list = nodes.hpack
-local hpack_filter = nodes.processors.hpack_filter
+local hpack_filter = nodes.processors.hpack_filter
-local newpenalty = nodes.pool.penalty
+local newpenalty = nodes.pool.penalty
+local newkern = nodes.pool.kern
+local tracerrule = nodes.tracers.pool.nodes.rule
-typesetters.firstlines = typesetters.firstlines or { }
-local firstlines = typesetters.firstlines
+local actions = { }
+firstlines.actions = actions
-local actions = { }
-firstlines.actions = actions
+local a_firstline = attributes.private('firstline')
+local a_color = attributes.private('color')
+local a_transparency = attributes.private('transparency')
+local a_colorspace = attributes.private('colormodel')
-local busy = false
-local settings = { }
+local texsetattribute = tex.setattribute
+local unsetvalue = attributes.unsetvalue
-local a_firstline = attributes.private('firstline')
-local a_color = attributes.private('color')
-local a_transparency = attributes.private('transparency')
-local a_colorspace = attributes.private('colormodel')
+local variables = interfaces.variables
+local v_default = variables.default
+local v_line = variables.line
+local v_word = variables.word
-local unsetvalue = attributes.unsetvalue
+----- is_letter = characters.is_letter
+----- categories = characters.categories
-local variables = interfaces.variables
+local settings = nil
------ is_letter = characters.is_letter
------ categories = characters.categories
+function firstlines.set(specification)
+ settings = specification or { }
+ tasks.enableaction("processors","typesetters.firstlines.handler")
+ if trace_firstlines then
+ report_firstlines("enabling firstlines")
+ end
+ texsetattribute(a_firstline,1)
+end
-firstlines.actions[variables.line] = function(head,setting)
+commands.setfirstline = firstlines.set
+
+actions[v_line] = function(head,setting)
-- local attribute = fonts.specifiers.contextnumber(setting.feature) -- was experimental
- local dynamic = setting.dynamic
- local font = setting.font
- -- make copy with dynamic feature attribute set
- local list = copy_node_list(head)
- for g in traverse_id(glyph,list) do
+ local dynamic = setting.dynamic
+ local font = setting.font
+ local noflines = setting.n or 1
+ local ma = setting.ma or 0
+ local ca = setting.ca
+ local ta = setting.ta
+ local hangafter = tex.hangafter
+ local hangindent = tex.hangindent
+ local parindent = tex.parindent
+ local nofchars = 0
+ local n = 0
+ local temp = copy_node_list(head)
+ local linebreaks = { }
+ for g in traverse_id(glyph,temp) do
if dynamic > 0 then
g[0] = dynamic
end
g.font = font
end
- local words = 0
- local nofchars = 0
- local nofwords = 1
- local going = true
- local lastnofchars = 0
- local hsize = tex.hsize - tex.parindent - tex.leftskip.width - tex.rightskip.width -- can be a helper
- while going do
- -- (slow) stepwise pass (okay, we could do do a vsplit and stitch but why do difficult)
- local temp = copy_node_list(list)
- local start = temp
- local ok = false
- lastnofchars = nofchars
- nofchars = 0
- words = 0
- local quit = false
+ local start = temp
+ local list = temp
+ local prev = temp
+ for i=1,noflines do
+ local hsize = tex.hsize - tex.leftskip.width - tex.rightskip.width
+ if i == 1 then
+ hsize = hsize - parindent
+ end
+ if i <= - hangafter then
+ hsize = hsize - hangindent
+ end
while start do
- -- also nicely quits on dics node
local id = start.id
if id == glyph then
- -- if not is_letter[categories[start.char]] then
- -- quit = true
- -- elseif not ok then
- if not ok then
- words = words + 1
- ok = true
- end
- nofchars = nofchars + 1
+ n = n + 1
elseif id == disc then
-- this could be an option
- else
- quit = true
- end
- if quit then
- ok = false
- if words == nofwords then
- local f = start.next
- start.next = nil
- free_node_list(f)
+ elseif id == kern then -- todo: fontkern
+ -- this could be an option
+ elseif n > 0 then
+ local pack = hpack_node_list(copy_node_list(list,start))
+ if pack.width > hsize then
+ free_node_list(pack)
+ list = prev
break
+ else
+ linebreaks[i] = n
+ prev = start
+ free_node_list(pack)
+ nofchars = n
end
- quit = false
end
start = start.next
end
- if not start then
- going = false
+ if not linebreaks[i] then
+ linebreaks[i] = n
end
- local pack = hpack_node_list(hpack_filter(temp))
- if pack.width > hsize then
- nofchars = lastnofchars
- break
- else
- nofwords = nofwords + 1
- end
- free_node_list(pack)
end
- -- set dynamic attribute in real list
local start = head
- local ma = setting.ma or 0
- local ca = setting.ca
- local ta = setting.ta
- while start do
- local id = start.id
- if id == glyph then -- or id == disc then
- if nofchars > 0 then
+ local n = 0
+ for i=1,noflines do
+ local linebreak = linebreaks[i]
+ while start and n < nofchars do
+ local id = start.id
+ if id == glyph then -- or id == disc then
if dynamic > 0 then
start[0] = dynamic
end
@@ -145,38 +152,28 @@ firstlines.actions[variables.line] = function(head,setting)
if ta and ta > 0 then
start[a_transparency] = ta
end
- nofchars = nofchars - 1
- if nofchars == 0 then
- insert_node_after(head,start,newpenalty(-10000)) -- break
+ n = n + 1
+ end
+ if linebreak == n then
+ if trace_firstlines then
+ head, start = insert_node_after(head,start,newpenalty(10000)) -- nobreak
+ head, start = insert_node_after(head,start,newkern(-65536))
+ head, start = insert_node_after(head,start,tracerrule(65536,4*65536,2*65536,"darkblue"))
end
- else
+ head, start = insert_node_after(head,start,newpenalty(-10000)) -- break
break
end
+ start = start.next
end
- start = start.next
end
- -- variant (no disc nodes)
- -- if false then
- -- for g in traverse_id(glyph,head) do
- -- if nofchars > 0 then
- -- if dynamic > 0 then
- -- g[0] = dynamic
- -- end
- -- g.font = font
- -- nofchars = nofchars - 1
- -- if nofchars == 0 then
- -- insert_node_after(head,g,newpenalty(-10000)) -- break
- -- end
- -- end
- -- end
- -- end
+ free_node_list(temp)
return head, true
end
-firstlines.actions[variables.word] = function(head,setting)
+actions[v_word] = function(head,setting)
-- local attribute = fonts.specifiers.contextnumber(setting.feature) -- was experimental
- local dynamic = setting.dynamic
- local font = setting.font
+ local dynamic = setting.dynamic
+ local font = setting.font
local words = 0
local nofwords = setting.n or 1
local start = head
@@ -205,6 +202,8 @@ firstlines.actions[variables.word] = function(head,setting)
start.font = font
elseif id == disc then
-- continue
+ elseif id == kern then -- todo: fontkern
+ -- continue
else
ok = false
if words == nofwords then
@@ -216,54 +215,37 @@ firstlines.actions[variables.word] = function(head,setting)
return head, true
end
+actions[v_default] = actions[v_line]
+
local function process(namespace,attribute,head)
- if not busy then
- local start, attr = head, nil
- while start do
- attr = start[attribute]
- if attr or start.id == glyph then
- break
- else
- start = start.next
- end
- end
+ local start = head
+ local attr = nil
+ while start do
+ attr = start[attribute]
if attr then
- local setting = settings[attr]
- if setting then
- local action = actions[setting.alternative]
- if action then
- busy = true
- head, done = action(head,setting)
- busy = false
- end
- end
- for g in traverse_id(glyph,head) do
- -- inefficient: we could quit at unset
- g[attribute] = unsetvalue
+ break
+ elseif start.id == glyph then
+ break
+ else
+ start = start.next
+ end
+ end
+ if attr then
+ -- here as we can process nested boxes first so we need to keep state
+ tasks.disableaction("processors","typesetters.firstlines.handler")
+ -- texsetattribute(attribute,unsetvalue)
+ local alternative = settings.alternative or v_default
+ local action = actions[alternative] or actions[v_default]
+ if action then
+ if trace_firstlines then
+ report_firstlines("processing firstlines, alternative %a",alternative)
end
- return head, true
+ return action(head,settings)
end
end
return head, false
end
--- local enabled = false
-
--- function firstlines.set(n)
--- if n == variables.reset or not tonumber(n) or n == 0 then
--- texsetattribute(a_firstline,unsetvalue)
--- else
--- if not enabled then
--- tasks.enableaction("processors","typesetters.firstlines.handler")
--- if trace_paragraphs then
--- report_firstlines("enabling firstlines")
--- end
--- enabled = true
--- end
--- texsetattribute(a_firstline,n)
--- end
--- end
-
firstlines.attribute = a_firstline
firstlines.handler = nodes.installattributehandler {
@@ -271,14 +253,3 @@ firstlines.handler = nodes.installattributehandler {
namespace = firstlines,
processor = process,
}
-
-function firstlines.define(setting)
- local n = #settings + 1
- settings[n] = setting
- tasks.enableaction("processors","typesetters.firstlines.handler")
- return n
-end
-
-function commands.definefirstline(setting)
- context(firstlines.define(setting))
-end
diff --git a/tex/context/base/typo-fln.mkiv b/tex/context/base/typo-fln.mkiv
index 10b99c809..c2c661afa 100644
--- a/tex/context/base/typo-fln.mkiv
+++ b/tex/context/base/typo-fln.mkiv
@@ -54,53 +54,45 @@
\definesystemattribute[firstline][public]
+\appendtoks
+ \attribute\firstlineattribute\attributeunsetvalue
+\to \everyforgetall
+
\installcorenamespace {firstline}
\installcommandhandler \??firstline {firstline} \??firstline
\setupfirstline
- [\c!alternative=\v!line,
- %\c!style=,
- %\c!color=,
- \c!n=0]
+ [\c!alternative=\v!line,
+ %\c!style=,
+ %\c!color=,
+ \c!n=1]
-\appendtoks
- \begingroup
- \usefirstlinestyleandcolor\c!style\c!color
- \setxvalue{\??firstline:\currentfirstline}{\ctxlua{commands.definefirstline {
- alternative = "\firstlineparameter\c!alternative",
- ma = \the\attribute\colormodelattribute,
- ca = \the\attribute\colorattribute,
- ta = \the\attribute\transparencyattribute,
- n = \number\firstlineparameter\c!n,
- font = \fontid\font,
- dynamic = \number\attribute\zerocount,
- }}}%
- \endgroup
-\to \everydefinefirstline
+\unexpanded\def\setfirstline
+ {\dosingleempty\typo_firstline_set}
-\unexpanded\def\setfirstline[#1]%
- {\ifcsname\??firstline:#1\endcsname
- \edef\typo_firstline_set{\typo_firstline_set_indeed{\number\csname\??firstline:#1\endcsname}}%
- \else
- \let\typo_firstline_set\relax
- \fi}
+\unexpanded\def\typo_firstline_set[#1]%
+ {\edef\typo_firstline_handle{\typo_firstline_handle_indeed{#1}}}
-\unexpanded\def\typo_firstline_set_indeed#1%
+\unexpanded\def\typo_firstline_handle_indeed#1%
{\dontleavehmode
\begingroup
- \attribute\firstlineattribute#1\relax
+ \edef\currentfirstline{#1}%
+ \usefirstlinestyleandcolor\c!style\c!color
+ \ctxlua{commands.setfirstline {
+ alternative = "\firstlineparameter\c!alternative",
+ ma = \the\attribute\colormodelattribute,
+ ca = \the\attribute\colorattribute,
+ ta = \the\attribute\transparencyattribute,
+ n = \number\firstlineparameter\c!n,
+ font = \fontid\font,
+ dynamic = \number\attribute\zerocount,
+ }}%
\kern\zeropoint % we need a node
- \hskip\zeropoint\s!plus\emwidth\relax % can be an option
- \globallet\typo_firstline_set\relax
- \endgroup}
-
-\let\typo_firstline_set\relax
-
-% \appendtoks
-% \typo_firstline_set % has to be done later
-% \to \everypar
+% \hskip\zeropoint\s!plus\emwidth\relax % can be an option
+ \endgroup
+ \globallet\typo_firstline_handle\relax}
-\protect
+\let\typo_firstline_handle\relax
-\endinput
+\protect \endinput
diff --git a/tex/context/base/typo-par.lua b/tex/context/base/typo-par.lua
deleted file mode 100644
index 5f8bd8d4a..000000000
--- a/tex/context/base/typo-par.lua
+++ /dev/null
@@ -1,186 +0,0 @@
-if not modules then modules = { } end modules ['typo-par'] = {
- version = 1.001,
- comment = "companion to typo-par.mkiv",
- author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
- copyright = "PRAGMA ADE / ConTeXt Development Team",
- license = "see context related readme files"
-}
-
--- A playground for experiments.
-
-local tonumber, type, next = tonumber, type, next
-local ceil = math.ceil
-
-local utfbyte = utf.byte
-local utfchar = utf.char
-
-local trace_paragraphs = false trackers.register("typesetters.paragraphs", function(v) trace_paragraphs = v end)
-local trace_dropper = false trackers.register("typesetters.paragraphs.dropper",function(v) trace_dropper = v end)
-
-local report_paragraphs = logs.reporter("nodes","paragraphs")
-local report_dropper = logs.reporter("nodes","dropped")
-
-typesetters.paragraphs = typesetters.paragraphs or { }
-local paragraphs = typesetters.paragraphs
-
-local nodecodes = nodes.nodecodes
-local whatsitcodes = nodes.whatsitcodes
-local tasks = nodes.tasks
-
-local variables = interfaces.variables
-
-local texsetattribute = tex.setattribute
-local unsetvalue = attributes.unsetvalue
-
-local glyph_code = nodecodes.glyph
-local hlist_code = nodecodes.hlist
-local kern_node = nodecodes.kern
-local whatsit_code = nodecodes.whatsit
-local localpar_code = whatsitcodes.localpar
-
-local a_paragraph = attributes.private("paragraphspecial")
-local a_color = attributes.private('color')
-local a_transparency = attributes.private('transparency')
-local a_colorspace = attributes.private('colormodel')
-
-local dropper = {
- enabled = false,
- -- font = 0,
- -- n = 0,
- -- distance = 0,
- -- hoffset = 0,
- -- voffset = 0,
-}
-
-local droppers = { }
-
-typesetters.paragraphs.droppers = droppers
-
-function droppers.set(specification)
- dropper = specification or { }
-end
-
-function droppers.freeze()
- if dropper.enabled then
- dropper.font = font.current()
- end
-end
-
--- dropped caps experiment (will be done properly when luatex
--- stores the state in the local par node) .. btw, search still
--- works with dropped caps, as does an export
-
--- we need a 'par' attribute and in fact for dropped caps we don't need
--- need an attribute ... dropit will become s state counter (or end up
--- in the localpar user data
-
--- for the moment, each paragraph gets a number as id (attribute) ..problem
--- with nesting .. or anyhow, needed for tagging anyway
-
--- todo: prevent linebreak .. but normally a dropper ends up atthe top of
--- a page so this has a low priority
-
-local function process(namespace,attribute,head)
- local done = false
- if head.id == whatsit_code and head.subtype == localpar_code then
- -- begin of par
- local a = head[attribute]
- if a and a > 0 then
- if dropper.enabled then
- dropper.enabled = false -- dangerous for e.g. nested || in tufte
- local first = head.next
- if first and first.id == hlist_code then
- -- parbox .. needs to be set at 0
- first = first.next
- end
- if first and first.id == glyph_code then
- -- if texgetattribute(a_paragraph) >= 0 then
- -- texsetattribute(a_paragraph,unsetvalue)
- -- end
- local char = first.char
- local prev = first.prev
- local next = first.next
- -- if prev.id == hlist_code then
- -- -- set the width to 0
- -- end
- if next and next.id == kern_node then
- next.kern = 0
- end
- if dropper.font then
- first.font = dropper.font
- end
- -- can be a helper
- local ma = dropper.ma or 0
- local ca = dropper.ca
- local ta = dropper.ta
- if ca and ca > 0 then
- first[a_colorspace] = ma == 0 and 1 or ma
- first[a_color] = ca
- end
- if ta and ta > 0 then
- first[a_transparency] = ta
- end
- --
- local width = first.width
- local height = first.height
- local depth = first.depth
- local distance = dropper.distance or 0
- local voffset = dropper.voffset or 0
- local hoffset = dropper.hoffset or 0
- first.xoffset = - width - hoffset - distance
- first.yoffset = - height - voffset
- if true then
- -- needed till we can store parindent with localpar
- first.prev = nil
- first.next = nil
- local h = node.hpack(first)
- h.width = 0
- h.height = 0
- h.depth = 0
- prev.next = h
- next.prev = h
- h.next = next
- h.prev = prev
- end
- if dropper.location == variables.margin then
- -- okay
- else
- local lines = tonumber(dropper.n) or 0
- if lines == 0 then -- safeguard, not too precise
- lines = ceil((height+voffset) / tex.baselineskip.width)
- end
- tex.hangafter = - lines
- tex.hangindent = width + distance
- end
- done = true
- end
- end
- end
- end
- return head, done
-end
-
-local enabled = false
-
-function paragraphs.set(n)
- if n == variables.reset or not tonumber(n) or n == 0 then
- texsetattribute(a_paragraph,unsetvalue)
- else
- if not enabled then
- tasks.enableaction("processors","typesetters.paragraphs.handler")
- if trace_paragraphs then
- report_paragraphs("enabling paragraphs")
- end
- enabled = true
- end
- texsetattribute(a_paragraph,n)
- end
-end
-
-paragraphs.attribute = a_paragraph
-
-paragraphs.handler = nodes.installattributehandler {
- name = "paragraphs",
- namespace = paragraphs,
- processor = process,
-}
diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua
index 9632faec5..6662c0a79 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 : 08/23/13 13:16:33
+-- merge date : 08/24/13 01:32:53
do -- begin closure to overcome local limits and interference