summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/supp-box.lua
diff options
context:
space:
mode:
authorTaco Hoekwater <taco@elvenkind.com>2011-06-01 08:54:21 +0000
committerTaco Hoekwater <taco@elvenkind.com>2011-06-01 08:54:21 +0000
commitd7ccb42582f85acf30568913610ccf4d602023fb (patch)
tree7292e3545a420676878e7451b68892d360c62cb6 /Master/texmf-dist/tex/context/base/supp-box.lua
parent2d62a6fe9b80def59c392268022f1f9a2d6e358f (diff)
commit context 2011.05.18
git-svn-id: svn://tug.org/texlive/trunk@22719 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/supp-box.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/supp-box.lua110
1 files changed, 110 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/context/base/supp-box.lua b/Master/texmf-dist/tex/context/base/supp-box.lua
new file mode 100644
index 00000000000..48baecf6fc2
--- /dev/null
+++ b/Master/texmf-dist/tex/context/base/supp-box.lua
@@ -0,0 +1,110 @@
+if not modules then modules = { } end modules ['supp-box'] = {
+ version = 1.001,
+ comment = "companion to supp-box.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- this is preliminary code
+
+local report_hyphenation = logs.reporter("languages","hyphenation")
+
+local nodecodes = nodes.nodecodes
+
+local disc_code = nodecodes.disc
+local hlist_code = nodecodes.hlist
+local vlist_code = nodecodes.vlist
+local glue_code = nodecodes.glue
+local glyph_code = nodecodes.glyph
+
+local new_penalty = nodes.pool.penalty
+local free_node = node.free
+local copynodelist = node.copy_list
+local copynode = node.copy
+local texbox = tex.box
+
+local function hyphenatedlist(list)
+ while list do
+ local id, next, prev = list.id, list.next, list.prev
+ if id == disc_code then
+ local hyphen = list.pre
+ if hyphen then
+ local penalty = new_penalty(-500)
+ hyphen.next, penalty.prev = penalty, hyphen
+ prev.next, next.prev = hyphen, penalty
+ penalty.next, hyphen.prev = next, prev
+ list.pre = nil
+ free_node(list)
+ end
+ elseif id == vlist_code or id == hlist_code then
+ hyphenatedlist(list.list)
+ end
+ list = next
+ end
+end
+
+commands.hyphenatedlist = hyphenatedlist
+
+function commands.showhyphenatedinlist(list)
+ report_hyphenation("show: %s",nodes.listtoutf(list))
+end
+
+local function checkedlist(list)
+ if type(list) == "number" then
+ return texbox[list].list
+ else
+ return list
+ end
+end
+
+local function applytochars(list,what,nested)
+ local doaction = context[what or "ruledhbox"]
+ local noaction = context
+ local current = checkedlist(list)
+ while current do
+ local id = current.id
+ if nested and (id == hlist_code or id == vlist_code) then
+ context.hbox()
+ context.bgroup()
+ applytochars(current.list,what,nested)
+ context.egroup()
+ elseif id ~= glyph_code then
+ noaction(copynode(current))
+ else
+ doaction(copynode(current))
+ end
+ current = current.next
+ end
+end
+
+local function applytowords(list,what,nested)
+ local doaction = context[what or "ruledhbox"]
+ local noaction = context
+ local current = checkedlist(list)
+ local start
+ while current do
+ local id = current.id
+ if id == glue_code then
+ if start then
+ doaction(copynodelist(start,current))
+ start = nil
+ end
+ noaction(copynode(current))
+ elseif nested and (id == hlist_code or id == vlist_code) then
+ context.hbox()
+ context.bgroup()
+ applytowords(current.list,what,nested)
+ context.egroup()
+ elseif not start then
+ start = current
+ end
+ current = current.next
+ end
+ if start then
+ doaction(copynodelist(start))
+ end
+end
+
+commands.applytochars = applytochars
+commands.applytowords = applytowords