module Prawn::Markup::Processor::Headings

Public Class Methods

prepended(base) click to toggle source
# File lib/prawn/markup/processor/headings.rb, line 6
def self.prepended(base)
  base.known_elements.push('h1', 'h2', 'h3', 'h4', 'h5', 'h6')
end

Public Instance Methods

end_heading(level) click to toggle source
# File lib/prawn/markup/processor/headings.rb, line 31
def end_heading(level)
  options = heading_options(level)
  if current_table
    add_cell_text_node(current_cell, options)
  elsif current_list
    add_cell_text_node(current_list_item, options)
  else
    add_current_text(options)
    put_bottom_margin(options[:margin_bottom])
  end
end
start_heading(level) click to toggle source
# File lib/prawn/markup/processor/headings.rb, line 20
def start_heading(level)
  if current_table
    add_cell_text_node(current_cell)
  elsif current_list
    add_cell_text_node(current_list_item)
  else
    add_current_text if buffered_text?
    pdf.move_down(current_heading_margin_top(level))
  end
end

Private Instance Methods

current_heading_margin_top(level) click to toggle source
# File lib/prawn/markup/processor/headings.rb, line 45
def current_heading_margin_top(level)
  top_margin = heading_options(level)[:margin_top] || 0
  margin = [top_margin, @bottom_margin || 0].max
  put_bottom_margin(nil)
  margin
end
default_options_with_size(level) click to toggle source
# File lib/prawn/markup/processor/headings.rb, line 57
def default_options_with_size(level)
  default = text_options.dup
  default[:size] ||= pdf.font_size
  default[:size] *= 2.5 - level * 0.25
  HashMerger.deep(default, options[:"heading#{level}"] || {})
end
heading_options(level) click to toggle source
# File lib/prawn/markup/processor/headings.rb, line 52
def heading_options(level)
  @heading_options ||= {}
  @heading_options[level] ||= default_options_with_size(level)
end