summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lpdf-epa.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
committerKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
commit824f7b0903de8ad7f6ee3d7656005e4c59155e06 (patch)
treeabfc8673ef9916f3ab7074e811207384c301492b /Master/texmf-dist/tex/context/base/lpdf-epa.lua
parent689aefb0727676ed3cddf331337b4be226495e72 (diff)
context import for TL13, from www.pragma-ade.com/context/beta/cont-tmf.zip
git-svn-id: svn://tug.org/texlive/trunk@29731 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lpdf-epa.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/lpdf-epa.lua160
1 files changed, 97 insertions, 63 deletions
diff --git a/Master/texmf-dist/tex/context/base/lpdf-epa.lua b/Master/texmf-dist/tex/context/base/lpdf-epa.lua
index c8d23a61825..034e6d7e241 100644
--- a/Master/texmf-dist/tex/context/base/lpdf-epa.lua
+++ b/Master/texmf-dist/tex/context/base/lpdf-epa.lua
@@ -11,6 +11,9 @@ if not modules then modules = { } end modules ['lpdf-epa'] = {
local type, tonumber = type, tonumber
local format, gsub = string.format, string.gsub
+local formatters = string.formatters
+
+----- lpegmatch, lpegpatterns = lpeg.match, lpeg.patterns
local trace_links = false trackers.register("figures.links", function(v) trace_links = v end)
@@ -20,6 +23,9 @@ local backends, lpdf = backends, lpdf
local variables = interfaces.variables
local codeinjections = backends.pdf.codeinjections
+----- urlescaper = lpegpatterns.urlescaper
+----- utftohigh = lpegpatterns.utftohigh
+local escapetex = characters.filters.utf.private.escape
local layerspec = { -- predefining saves time
"epdflinks"
@@ -30,17 +36,21 @@ local function makenamespace(filename)
end
local function add_link(x,y,w,h,destination,what)
+ x = x .. "bp"
+ y = y .. "bp"
+ w = w .. "bp"
+ h = h .. "bp"
if trace_links then
- report_link("dx: % 4i, dy: % 4i, wd: % 4i, ht: % 4i, destination: %s, type: %s",x,y,w,h,destination,what)
+ report_link("destination %a, type %a, dx %s, dy %s, wd %s, ht %s",destination,what,x,y,w,h)
end
local locationspec = { -- predefining saves time
- x = x .. "bp",
- y = y .. "bp",
+ x = x,
+ y = y,
preset = "leftbottom",
}
local buttonspec = {
- width = w .. "bp",
- height = h .. "bp",
+ width = w,
+ height = h,
offset = variables.overlay,
frame = trace_links and variables.on or variables.off,
}
@@ -53,19 +63,22 @@ local function add_link(x,y,w,h,destination,what)
end
local function link_goto(x,y,w,h,document,annotation,pagedata,namespace)
- local destination = annotation.A.D -- [ 18 0 R /Fit ]
- local what = "page"
- if type(destination) == "string" then
- local destinations = document.destinations
- local wanted = destinations[destination]
- destination = wanted and wanted.D
- if destination then what = "named" end
- end
- local pagedata = destination and destination[1]
- if pagedata then
- local destinationpage = pagedata.number
- if destinationpage then
- add_link(x,y,w,h,namespace .. destinationpage,what)
+ local a = annotation.A
+ if a then
+ local destination = a.D -- [ 18 0 R /Fit ]
+ local what = "page"
+ if type(destination) == "string" then
+ local destinations = document.destinations
+ local wanted = destinations[destination]
+ destination = wanted and wanted.D
+ if destination then what = "named" end
+ end
+ local pagedata = destination and destination[1]
+ if pagedata then
+ local destinationpage = pagedata.number
+ if destinationpage then
+ add_link(x,y,w,h,namespace .. destinationpage,what)
+ end
end
end
end
@@ -73,24 +86,31 @@ end
local function link_uri(x,y,w,h,document,annotation)
local url = annotation.A.URI
if url then
- add_link(x,y,w,h,format("url(%s)",url),"url")
+ -- url = lpegmatch(urlescaper,url)
+ -- url = lpegmatch(utftohigh,url)
+ url = escapetex(url)
+ add_link(x,y,w,h,formatters["url(%s)"](url),"url")
end
end
local function link_file(x,y,w,h,document,annotation)
- local filename = annotation.A.F
- if filename then
- local destination = annotation.A.D
- if not destination then
- add_link(x,y,w,h,format("file(%s)",filename),"file")
- elseif type(destination) == "string" then
- add_link(x,y,w,h,format("%s::%s",filename,destination),"file (named)")
- else
- destination = destination[1] -- array
- if tonumber(destination) then
- add_link(x,y,w,h,format("%s::page(%s)",filename,destination),"file (page)")
+ local a = annotation.A
+ if a then
+ local filename = a.F
+ if filename then
+ filename = escapetex(filename)
+ local destination = a.D
+ if not destination then
+ add_link(x,y,w,h,formatters["file(%s)"](filename),"file")
+ elseif type(destination) == "string" then
+ add_link(x,y,w,h,formatters["%s::%s"](filename,destination),"file (named)")
else
- add_link(x,y,w,h,format("file(%s)",filename),"file")
+ destination = destination[1] -- array
+ if tonumber(destination) then
+ add_link(x,y,w,h,formatters["%s::page(%s)"](filename,destination),"file (page)")
+ else
+ add_link(x,y,w,h,formatters["file(%s)"](filename),"file")
+ end
end
end
end
@@ -110,41 +130,50 @@ function codeinjections.mergereferences(specification)
local yscale = specification.yscale or 1
local size = specification.size or "crop" -- todo
local pagedata = document.pages[pagenumber]
- local annotations = pagedata.Annots
- local namespace = format("lpdf-epa-%s-",file.removesuffix(file.basename(fullname)))
- local reference = namespace .. pagenumber
- if annotations.n > 0 then
+ local annotations = pagedata and pagedata.Annots
+ if annotations and annotations.n > 0 then
+ local namespace = format("lpdf-epa-%s-",file.removesuffix(file.basename(fullname)))
+ local reference = namespace .. pagenumber
local mediabox = pagedata.MediaBox
local llx, lly, urx, ury = mediabox[1], mediabox[2], mediabox[3], mediabox[4]
local width, height = xscale * (urx - llx), yscale * (ury - lly) -- \\overlaywidth, \\overlayheight
context.definelayer( { "epdflinks" }, { height = height.."bp" , width = width.."bp" })
for i=1,annotations.n do
local annotation = annotations[i]
- local subtype = annotation.Subtype
- local rectangle = annotation.Rect
- local a_llx, a_lly, a_urx, a_ury = rectangle[1], rectangle[2], rectangle[3], rectangle[4]
- local x, y = xscale * (a_llx - llx), yscale * (a_lly - lly)
- local w, h = xscale * (a_urx - a_llx), yscale * (a_ury - a_lly)
- if subtype == "Link" then
- local linktype = annotation.A.S
- if linktype == "GoTo" then
- link_goto(x,y,w,h,document,annotation,pagedata,namespace)
- elseif linktype == "GoToR" then
- link_file(x,y,w,h,document,annotation)
- elseif linktype == "URI" then
- link_uri(x,y,w,h,document,annotation)
+ if annotation then
+ local subtype = annotation.Subtype
+ local rectangle = annotation.Rect
+ local a_llx, a_lly, a_urx, a_ury = rectangle[1], rectangle[2], rectangle[3], rectangle[4]
+ local x, y = xscale * (a_llx - llx), yscale * (a_lly - lly)
+ local w, h = xscale * (a_urx - a_llx), yscale * (a_ury - a_lly)
+ if subtype == "Link" then
+ local a = annotation.A
+ if a then
+ local linktype = a.S
+ if linktype == "GoTo" then
+ link_goto(x,y,w,h,document,annotation,pagedata,namespace)
+ elseif linktype == "GoToR" then
+ link_file(x,y,w,h,document,annotation)
+ elseif linktype == "URI" then
+ link_uri(x,y,w,h,document,annotation)
+ elseif trace_links then
+ report_link("unsupported link annotation %a",linktype)
+ end
+ else
+ report_link("mising link annotation")
+ end
elseif trace_links then
- report_link("unsupported link annotation '%s'",linktype)
+ report_link("unsupported annotation %a",subtype)
end
elseif trace_links then
- report_link("unsupported annotation '%s'",subtype)
+ report_link("broken annotation, index %a",i)
end
end
context.flushlayer { "epdflinks" }
-- context("\\gdef\\figurereference{%s}",reference) -- global
context.setgvalue("figurereference",reference) -- global
if trace_links then
- report_link("setting figure reference to '%s'",reference)
+ report_link("setting figure reference to %a",reference)
end
specification.reference = reference
return namespace
@@ -171,19 +200,24 @@ function codeinjections.mergeviewerlayers(specification)
local layers = document.layers
if layers then
for i=1,layers.n do
- local tag = namespace .. gsub(layers[i]," ",":")
- local title = tag
- if trace_links then
- report_link("using layer '%s'",tag)
+ local layer = layers[i]
+ if layer then
+ local tag = namespace .. gsub(layer," ",":")
+ local title = tag
+ if trace_links then
+ report_link("using layer %a",tag)
+ end
+ attributes.viewerlayers.define { -- also does some cleaning
+ tag = tag, -- todo: #3A or so
+ title = title,
+ visible = variables.start,
+ editable = variables.yes,
+ printable = variables.yes,
+ }
+ codeinjections.useviewerlayer(tag)
+ elseif trace_links then
+ report_link("broken layer, index %a",i)
end
- attributes.viewerlayers.define { -- also does some cleaning
- tag = tag, -- todo: #3A or so
- title = title,
- visible = variables.start,
- editable = variables.yes,
- printable = variables.yes,
- }
- codeinjections.useviewerlayer(tag)
end
end
end