module Prawn::Markup::Processor::Blocks
Public Class Methods
prepended(base)
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 6 def self.prepended(base) base.known_elements.push('p', 'br', 'div', 'hr') end
Public Instance Methods
end_div()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 31 def end_div handle_text_element end
end_document()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 45 def end_document add_current_text end
end_p()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 18 def end_p if inside_container? append_new_line append_text("\n") else add_paragraph end end
start_br()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 10 def start_br append_text("\n") end
start_div()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 27 def start_div handle_text_element end
start_hr()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 35 def start_hr return if inside_container? put_bottom_margin(nil) add_current_text pdf.move_down(hr_vertical_margin_top) pdf.stroke_horizontal_rule pdf.move_down(hr_vertical_margin_bottom) end
start_p()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 14 def start_p handle_text_element end
Private Instance Methods
add_bottom_margin()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 82 def add_bottom_margin if @bottom_margin pdf.move_down(@bottom_margin) @bottom_margin = nil end end
add_current_text(options = text_options)
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 73 def add_current_text(options = text_options) add_bottom_margin return unless buffered_text? string = dump_text string.strip! add_formatted_text(string, options) end
add_formatted_text(string, options = text_options)
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 89 def add_formatted_text(string, options = text_options) with_font(options) do pdf.text(string, options) end end
add_paragraph()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 63 def add_paragraph text = dump_text text.gsub!(/[^\n]/, '') if text.strip.empty? unless text.empty? add_bottom_margin add_formatted_text(text, text_options) put_bottom_margin(text_margin_bottom) end end
append_new_line()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 59 def append_new_line append_text("\n") if buffered_text? && text_buffer[-1] != "\n" end
default_text_margin_bottom()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 127 def default_text_margin_bottom text_line_gap + text_descender + text_leading end
default_text_options()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 149 def default_text_options { inline_format: true } end
handle_text_element()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 51 def handle_text_element if inside_container? append_new_line else add_current_text end end
hr_vertical_margin_bottom()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 108 def hr_vertical_margin_bottom @hr_vertical_margin_bottom ||= with_font(text_options) do hr_vertical_margin_top + pdf.font.descender + text_leading - pdf.line_width end end
hr_vertical_margin_top()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 103 def hr_vertical_margin_top @hr_vertical_margin_top ||= (text_options[:size] || pdf.font_size) / 2.0 end
reset()
click to toggle source
Calls superclass method
# File lib/prawn/markup/processor/blocks.rb, line 117 def reset super text_margin_bottom # pre-calculate end
text_descender()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 137 def text_descender @text_descender ||= with_font(text_options) { pdf.font.descender } end
text_leading()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 141 def text_leading text_options[:leading] || pdf.default_leading end
text_line_gap()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 133 def text_line_gap @text_line_gap ||= with_font(text_options) { pdf.font.line_gap } end
text_margin_bottom()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 122 def text_margin_bottom options[:text] ||= {} options[:text][:margin_bottom] ||= default_text_margin_bottom end
text_options()
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 145 def text_options @text_options ||= HashMerger.deep(default_text_options, options[:text] || {}) end
with_font(options) { || ... }
click to toggle source
# File lib/prawn/markup/processor/blocks.rb, line 95 def with_font(options) pdf.font(options[:font] || pdf.font.family, size: options[:size], style: options[:style]) do return yield end end