module Prawn::Grouping

Constants

VERSION

Public Instance Methods

group(options = {}) { |pdf| ... } click to toggle source

Groups a given block vertiacally within the current context, if possible.

Parameters are:

options

A hash for grouping options.

:too_tall

A proc called before the content is rendered and does not fit a single context.

:fits_new_context

A proc called before the content is rendered and does fit a single context.

:fits_current_context

A proc called before the content is rendered and does fit context.

# File lib/prawn/grouping.rb, line 19
def group(options = {})
  too_tall             = options[:too_tall]
  fits_new_context     = options[:fits_new_context]
  fits_current_context = options[:fits_current_context]

  # create a temporary document with current context and offset
  pdf = create_box_clone
  pdf.y = y
  yield pdf

  if pdf.page_count > 1
    # create a temporary document without offset
    pdf = create_box_clone
    yield pdf

    if pdf.page_count > 1
      # does not fit new context
      too_tall.call if too_tall
      yield self
    else
      fits_new_context.call if fits_new_context
      bounds.move_past_bottom
      yield self
    end
    return false
  else
    # just render it
    fits_current_context.call if fits_current_context
    yield self
    return true
  end
end

Private Instance Methods

create_box_clone() click to toggle source
# File lib/prawn/grouping.rb, line 54
def create_box_clone
  Prawn::Document.new(:page_size => state.page.size, :page_layout => state.page.layout) do |pdf|
    pdf.margin_box = @bounding_box.dup
    pdf.text_formatter = @text_formatter.dup
    pdf.font_families.update font_families
    pdf.font font.family
    pdf.font_size font_size
    pdf.default_leading = default_leading
  end
end