summaryrefslogtreecommitdiff
path: root/tex/context/base/strc-bkm.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2010-08-14 15:56:20 +0300
committerMarius <mariausol@gmail.com>2010-08-14 15:56:20 +0300
commitb469b8ec1b494ab72cd462bfc539ce01440e6aaf (patch)
tree3a9c3fb8433c5f75020fef1d531bedb7c948f66c /tex/context/base/strc-bkm.lua
parent39e30629c15ae4a899532d84c4abea127f2847a6 (diff)
downloadcontext-b469b8ec1b494ab72cd462bfc539ce01440e6aaf.tar.gz
beta 2010.08.10 17:14
Diffstat (limited to 'tex/context/base/strc-bkm.lua')
-rw-r--r--tex/context/base/strc-bkm.lua99
1 files changed, 57 insertions, 42 deletions
diff --git a/tex/context/base/strc-bkm.lua b/tex/context/base/strc-bkm.lua
index 79ed867de..5fe9325a6 100644
--- a/tex/context/base/strc-bkm.lua
+++ b/tex/context/base/strc-bkm.lua
@@ -16,8 +16,9 @@ local texsprint, utfvalues = tex.sprint, string.utfvalues
local ctxcatcodes = tex.ctxcatcodes
-local lists = structure.lists
-local levelmap = structure.sections.levelmap
+local lists = structure.lists
+local levelmap = structure.sections.levelmap
+local variables = interfaces.variables
structure.bookmarks = structure.bookmarks or { }
@@ -25,11 +26,29 @@ local bookmarks = structure.bookmarks
bookmarks.method = "internal" -- or "page"
-local names, opened = "", ""
-
-function bookmarks.register(n,o)
- if names == "" then names = n else names = names .. "," .. n end
- if opened == "" then opened = o else opened = opened .. "," .. o end
+local names, opened, forced, numbered = { }, { }, { }, { }
+
+function bookmarks.register(settings)
+ local force = settings.force == variables.yes
+ local number = settings.number == variables.yes
+ local allopen = settings.opened == variables.all
+ for k, v in next, aux.settings_to_hash(settings.names or "") do
+ names[k] = true
+ if force then
+ forced[k] = true
+ if allopen then
+ opened[k] = true
+ end
+ end
+ if number then
+ numbered[k] = true
+ end
+ end
+ if not allopen then
+ for k, v in next, aux.settings_to_hash(settings.opened or "") do
+ opened[k] = true
+ end
+ end
end
function bookmarks.overload(name,text)
@@ -63,23 +82,32 @@ end
-- todo: collect specs and collect later i.e. multiple places
+local numberspec = { }
+
+function structure.bookmarks.setup(spec)
+ -- table.merge(numberspec,spec)
+ for k, v in next, spec do
+ numberspec[k] = v
+ end
+end
+
function bookmarks.place()
- if names ~= "" then
- local list = lists.filter(names,"all",nil,lists.collected)
- local lastlevel = 1
+ if next(names) then
+ local list = lists.filter_collected(names,"all",nil,lists.collected,forced)
if #list > 0 then
- local opened, levels = aux.settings_to_set(opened), { }
+ local levels, lastlevel = { }, 1
for i=1,#list do
local li = list[i]
local metadata = li.metadata
local name = metadata.name
- if not metadata.nolist then -- and levelmap[name] then
+ if not metadata.nolist or forced[name] then -- and levelmap[name] then
local titledata = li.titledata
if titledata then
local structural = levelmap[name]
lastlevel = structural or lastlevel
local title = titledata.bookmark
if not title or title == "" then
+ -- We could typeset the title and then convert it.
if not structural then
-- placeholder, todo: bookmarklabel
title = name .. ": " .. (titledata.title or "?")
@@ -87,47 +115,34 @@ function bookmarks.place()
title = titledata.title or "?"
end
end
+ if numbered[name] then
+ local sectiondata = jobsections.collected[li.references.section]
+ local numberdata = li.numberdata
+ if sectiondata and numberdata and not numberdata.hidenumber then
+ -- we could typeset the number and convert it
+ title = concat(structure.sections.typesetnumber(sectiondata,"direct",numberspec,sectiondata)) .. " " .. title
+ end
+ end
levels[#levels+1] = {
lastlevel,
- stripped(title),
+ stripped(title), -- can be replaced by converter
li.references, -- has internal and realpage
allopen or opened[name]
}
end
end
end
- backends.codeinjections.addbookmarks(levels,bookmarks.method)
+ bookmarks.finalize(levels)
end
function bookmarks.place() end -- prevent second run
end
end
-lpdf.registerdocumentfinalizer(function() structure.bookmarks.place() end,1,"bookmarks")
+function bookmarks.finalize(levels)
+ -- This function can be overloaded by an optional converter
+ -- that uses nodes.toutf on a typeset stream. This is something
+ -- that we will support when the main loop has become a coroutine.
+ backends.codeinjections.addbookmarks(levels,bookmarks.method)
+end
--- bkm
---~ function nodes.toutf(list)
---~ local t= { }
---~ for n in node.traverse(list) do
---~ local id = n.id
---~ if id == node.id("glyph") then
---~ local c = n.char
---~ local f = fonts.ids[n.font]
---~ if f then
---~ local u = f.characters[c].tounicode
---~ if u then
---~ for s in string.gmatch(u,"..") do
---~ t[#t+1] = utf.char(tonumber(s,16))
---~ end
---~ else
---~ t[#t+1] = utf.char(c)
---~ end
---~ else
---~ t[#t+1] = utf.char(c)
---~ end
---~ elseif id == node.id("glue") then
---~ t[#t+1] = " "
---~ end
---~ end
---~ return table.concat(t,"")
---~ end
---~ print(nodes.toutf(tex.box[999].list))
+lpdf.registerdocumentfinalizer(function() structure.bookmarks.place() end,1,"bookmarks")