Skip to content

Commit

Permalink
Add support for link to another page (foliojs#701)
Browse files Browse the repository at this point in the history
* Link to a page

* Text link can go to page 0

* Update annotations.coffee
  • Loading branch information
alafr authored and devongovett committed Jul 30, 2017
1 parent b9fc5b0 commit a531f43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 21 additions & 7 deletions lib/mixins/annotations.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,27 @@ module.exports =

link: (x, y, w, h, url, options = {}) ->
options.Subtype = 'Link'
options.A = @ref
S: 'URI'
URI: new String url

options.A.end()

if typeof url is 'number'
# Link to a page in the document (the page must already exist)
pages = @_root.data.Pages.data
if url >= 0 and url < pages.Kids.length
options.A = @ref
S: 'GoTo'
D: [pages.Kids[url], 'XYZ', null, null, null]
options.A.end()
else
throw new Error "The document has no page #{url}"

else
# Link to an external url
options.A = @ref
S: 'URI'
URI: new String url
options.A.end()

@annotate x, y, w, h, options

_markup: (x, y, w, h, options = {}) ->
[x1, y1, x2, y2] = @_convertRect x, y, w, h
options.QuadPoints = [x1, y2, x2, y2, x1, y1, x2, y1]
Expand Down Expand Up @@ -90,4 +104,4 @@ module.exports =
x2 = m0 * x2 + m2 * y2 + m4
y2 = m1 * x2 + m3 * y2 + m5

return [x1, y1, x2, y2]
return [x1, y1, x2, y2]
2 changes: 1 addition & 1 deletion lib/mixins/text.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ module.exports =
renderedWidth = options.textWidth + (wordSpacing * (options.wordCount - 1)) + (characterSpacing * (text.length - 1))

# create link annotations if the link option is given
if options.link
if options.link?
@link x, y, renderedWidth, @currentLineHeight(), options.link

# create underline or strikethrough line
Expand Down

0 comments on commit a531f43

Please sign in to comment.