class Prawn::Format::Instructions::TagOpen

Attributes

tag[R]

Public Class Methods

new(state, tag) click to toggle source
Calls superclass method Prawn::Format::Instructions::Base.new
# File lib/prawn/format/instructions/tag_open.rb, line 13
def initialize(state, tag)
  super(state)
  @tag = tag
end

Public Instance Methods

draw(document, draw_state, options={}) click to toggle source
# File lib/prawn/format/instructions/tag_open.rb, line 18
def draw(document, draw_state, options={})
  draw_width(document, draw_state)
  draw_destination(document, draw_state)
  draw_link(document, draw_state)
  draw_underline(document, draw_state)
end
start_verbatim?() click to toggle source
# File lib/prawn/format/instructions/tag_open.rb, line 25
def start_verbatim?
  @tag[:style][:white_space] == :pre
end
style() click to toggle source
# File lib/prawn/format/instructions/tag_open.rb, line 29
def style
  @tag[:style]
end
width() click to toggle source
# File lib/prawn/format/instructions/tag_open.rb, line 33
def width
  @state.width
end

Private Instance Methods

add_effect(effect, draw_state) click to toggle source
# File lib/prawn/format/instructions/tag_open.rb, line 84
def add_effect(effect, draw_state)
  tag[:effects] ||= []
  tag[:effects].push(effect)

  draw_state[:pending_effects].push(effect)
end
draw_destination(document, draw_state) click to toggle source
# File lib/prawn/format/instructions/tag_open.rb, line 46
def draw_destination(document, draw_state)
  return unless tag[:style][:anchor]

  x = draw_state[:real_x]
  y = draw_state[:real_y] + draw_state[:dy] + ascent

  label, destination = case tag[:style][:anchor]
    when /^zoom=([\d\.]+):(.*)$/
      [$2, document.dest_xyz(x, y, $1.to_f)]
    when /^fit:(.*)$/
      [$1, document.dest_fit]
    when /^fith:(.*)$/
      [$1, document.dest_fit_horizontally(y)]
    when /^fitv:(.*)$/
      [$1, document.dest_fit_vertically(x)]
    when /^fitb:(.*)$/
      [$1, document.dest_fit_bounds]
    when /^fitbh:(.*)$/
      [$1, document.dest_fit_bounds_horizontally(y)]
    when /^fitbv:(.*)$/
      [$1, document.dest_fit_bounds_vertically(x)]
    else
      [tag[:style][:anchor], document.dest_fit_bounds]
    end

  document.add_dest(label, destination)
end
draw_underline(document, draw_state) click to toggle source
# File lib/prawn/format/instructions/tag_open.rb, line 79
def draw_underline(document, draw_state)
  return unless tag[:style][:text_decoration] == :underline
  add_effect(Effects::Underline.new(draw_state[:dx], @state), draw_state)
end
draw_width(document, draw_state) click to toggle source
# File lib/prawn/format/instructions/tag_open.rb, line 39
def draw_width(document, draw_state)
  if width > 0
    draw_state[:dx] += width
    draw_state[:text].move_to(draw_state[:dx], draw_state[:dy])
  end
end