Class: Prawn::Format::Effects::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/format/effects/link.rb

Instance Method Summary collapse

Constructor Details

#initialize(target, x) ⇒ Link

Returns a new instance of Link.



8
9
10
11
# File 'lib/prawn/format/effects/link.rb', line 8

def initialize(target, x)
  @target = target
  @x = x
end

Instance Method Details

#finish(document, draw_state) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/prawn/format/effects/link.rb', line 13

def finish(document, draw_state)
  x1 = draw_state[:real_x] + @x
  x2 = draw_state[:real_x] + draw_state[:dx]
  y  = draw_state[:real_y] + draw_state[:dy]

  rect = [x1, y + draw_state[:line].descent, x2, y + draw_state[:line].ascent]
  if @target.match(/^#/)
	    document.link_annotation(rect, :Dest => @target.sub(/^#/,""), :Border => [0,0,0])
	  else
	    document.link_annotation(rect, :Border => [0,0,0], :A => { :Type => :Action, :S => :URI, :URI => Prawn::LiteralString.new(@target) } )
	  end #new
end

#wrap(document, draw_state) ⇒ Object



26
27
28
29
# File 'lib/prawn/format/effects/link.rb', line 26

def wrap(document, draw_state)
  finish(document, draw_state)
  @x = 0
end