Sha256: ba386533512dc516d1f949dcdbe0430f6de08beddc054eb84ae82d3d766e95cf

Contents?: true

Size: 1.43 KB

Versions: 8

Compression:

Stored size: 1.43 KB

Contents

# encoding: utf-8
#
# Normally when we provide the top left corner of a bounding box we
# express the coordinates relative to the margin box. This is not the
# case when we have nested bounding boxes. Once nested the inner bounding box
# coordinates are relative to the outter bounding box.
#
# This example shows some nested bounding boxes with fixed and stretchy heights.
# Note how the <code>cursor</code> method returns coordinates relative to
# the current bounding box.
#
require File.expand_path(File.join(File.dirname(__FILE__),
                                   %w[.. example_helper]))

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualBuilder::Example.generate(filename) do
  def box_content(string)
    text string
    transparent(0.5) { stroke_bounds }
  end

  gap = 20
  bounding_box([50, cursor], :width => 400, :height => 200) do
    box_content("Fixed height")

    bounding_box([gap, cursor - gap], :width => 300) do
      text "Stretchy height"

      bounding_box([gap, bounds.top - gap], :width => 100) do
        text "Stretchy height"
        transparent(0.5) { dash(1); stroke_bounds; undash }
      end

      bounding_box([gap * 7, bounds.top - gap], :width => 100, :height => 50) do
        box_content("Fixed height")
      end

      transparent(0.5) { dash(1); stroke_bounds; undash }
    end

    bounding_box([gap, cursor - gap], :width => 300, :height => 50) do
      box_content("Fixed height")
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
prawn-2.1.0 manual/bounding_box/nesting.rb
prawn-git-2.0.1 manual/bounding_box/nesting.rb
prawn-2.0.2 manual/bounding_box/nesting.rb
prawn-2.0.1 manual/bounding_box/nesting.rb
prawn-2.0.0 manual/bounding_box/nesting.rb
prawn-1.3.0 manual/bounding_box/nesting.rb
prawn-1.2.1 manual/bounding_box/nesting.rb
prawn-1.1.0 manual/bounding_box/nesting.rb