Sha256: 6c0eaea5dca50a8d0a90313422aaf731af8374389497708f8d61c36e9e511bcf

Contents?: true

Size: 764 Bytes

Versions: 10

Compression:

Stored size: 764 Bytes

Contents

$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require 'prawn'

class Array
  def combine(arr)
    output = []
    self.each do |i1|
      arr.each do |i2|
        output += [[i1,i2]]
      end
    end
    output
  end
end

def recurse_bounding_box(pdf, max_depth=5, depth=1)
  box = pdf.bounds
  width = (box.width-15)/2
  height = (box.height-15)/2
  left_top_corners = [5, box.right-width-5].combine [box.top-5, height+5]
  left_top_corners.each do |lt|
    pdf.bounding_box(lt, :width=>width, :height=>height) do
      pdf.stroke_rectangle [0,height], width, height
      recurse_bounding_box(pdf, max_depth, depth+1) if depth<max_depth
    end
  end
end


Prawn::Document.generate("russian_boxes.pdf") do |pdf|
  recurse_bounding_box(pdf)
end


Version data entries

10 entries across 10 versions & 4 rubygems

Version Path
fullcirclegroup-fullcirclegroup-prawn-0.2.99.2 examples/russian_boxes.rb
fullcirclegroup-prawn-0.2.99.3 examples/russian_boxes.rb
satoko-prawn-0.2.99.6 examples/russian_boxes.rb
prawn-0.1.0 examples/russian_boxes.rb
prawn-0.1.1 examples/russian_boxes.rb
prawn-0.1.2 examples/russian_boxes.rb
prawn-0.2.2 examples/russian_boxes.rb
prawn-0.2.1 examples/russian_boxes.rb
prawn-0.2.0 examples/russian_boxes.rb
prawn-0.2.3 examples/russian_boxes.rb