Class: PDF::TechBook::TagXref

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/techbook.rb

Overview

A stand-alone replacement callback that will return an internal link with either the name of the cross-reference or the page on which the cross-reference appears as the label. If the page number is not yet known (when the cross-referenced item has not yet been rendered, e.g., forward-references), the label will be used in any case.

The parameters are:

name

The name of the cross-reference.

label

Either page, title, or text. page will not be used for forward references; only title or text will be used.

text

Required if label has a value of text. Ignored if label is title, optional if label is page. This value will be used as the display text for the internal link. text takes precedence over title if label is page.

Class Method Summary collapse

Class Method Details

.[](pdf, params) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/pdf/techbook.rb', line 249

def self.[](pdf, params)
  name  = params["name"]
  item  = params["label"]
  text  = params["text"]

  xref = pdf.xref_table[name]
  if xref
    case item
    when 'page'
      label = xref[:page]
      if text.nil? or text.empty?
        label ||= xref[:title]
      else
        label ||= text
      end
    when 'title'
      label = xref[:title]
    when 'text'
      label = text
    end

    "<c:ilink dest='#{xref[:xref]}'>#{label}</c:ilink>"
  else
    warn PDF::Writer::Lang[:techbook_unknown_xref] % [ name ]
    PDF::Writer::Lang[:techbook_unknown_xref] % [ name ]
  end
end