Class: PDF::TechBook::TagTocDots

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

Overview

A stand-alone callback that draws a dotted line over to the right and appends a page number. The info will be like a standard XML tag with three named parameters:

level

The table of contents level that corresponds to a particular style. In the current TechBook implementation, there are only two levels. Level 1 uses a 16 point font and #level1_style; level 2 uses a 12 point font and #level2_style.

page

The page number that is to be printed.

xref

The target destination that will be used as a link.

All parameters are required.

Constant Summary collapse

DEFAULT_L1_STYLE =
{
  :width      => 1,
  :cap        => :round,
  :dash       => { :pattern => [ 1, 3 ], :phase => 1 },
  :font_size  => 16
}
DEFAULT_L2_STYLE =
{
  :width      => 1,
  :cap        => :round,
  :dash       => { :pattern => [ 1, 5 ], :phase => 1 },
  :font_size  => 12
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.level1_styleObject

Controls the level 1 style.



308
309
310
# File 'lib/pdf/techbook.rb', line 308

def level1_style
  @level1_style
end

.level2_styleObject

Controls the level 2 style.



310
311
312
# File 'lib/pdf/techbook.rb', line 310

def level2_style
  @level2_style
end

Class Method Details

.[](pdf, info) ⇒ Object



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/pdf/techbook.rb', line 312

def [](pdf, info)
  if @level1_style.nil?
    @level1_style = sh = DEFAULT_L1_STYLE
    ss      = PDF::Writer::StrokeStyle.new(sh[:width])
    ss.cap  = sh[:cap] if sh[:cap]
    ss.dash = sh[:dash] if sh[:dash]
    @_level1_style = ss
  end
  if @level2_style.nil?
    @level2_style = sh = DEFAULT_L2_STYLE
    ss      = PDF::Writer::StrokeStyle.new(sh[:width])
    ss.cap  = sh[:cap] if sh[:cap]
    ss.dash = sh[:dash] if sh[:dash]
    @_level2_style = ss
  end

  level = info[:params]["level"]
  page  = info[:params]["page"]
  xref  = info[:params]["xref"]

  xpos = 520

  pdf.save_state
  case level
  when "1"
    pdf.stroke_style @_level1_style
    size = @level1_style[:font_size]
  when "2"
    pdf.stroke_style @_level2_style
    size = @level2_style[:font_size]
  end

  page = "<c:ilink dest='#{xref}'>#{page}</c:ilink>" if xref

  pdf.line(xpos, info[:y], info[:x] + 5, info[:y]).stroke
  pdf.restore_state
  pdf.add_text(xpos + 5, info[:y], page, size)
end