public
Description: Fast, Nimble PDF Writer for Ruby
Homepage: http://prawn.majesticseacreature.com
Clone URL: git://github.com/sandal/prawn.git
prawn / spec / bounding_box_spec.rb
100644 80 lines (57 sloc) 1.947 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
 
describe "A bounding box" do
 
  before(:each) do
    @box = Prawn::Document::BoundingBox.new(nil, [100,100], :width => 50,
                                                            :height => 75 )
  end
 
  it "should have an anchor at (x, y - height)" do
    @box.anchor.should == [100,25]
  end
 
  it "should have a left boundary of 0" do
    @box.left.should == 0
  end
  
  it "should have a right boundary equal to the width" do
    @box.right.should == 50
  end
 
  it "should have a top boundary of height" do
    @box.top.should == 75
  end
 
  it "should have a bottom boundary of 0" do
    @box.bottom.should == 0
  end
 
  it "should have an absolute left boundary of x" do
    @box.absolute_left.should == 100
  end
 
  it "should have an absolute right boundary of x + width" do
    @box.absolute_right.should == 150
  end
 
  it "should have an absolute top boundary of y" do
    @box.absolute_top.should == 100
  end
 
  it "should have an absolute bottom boundary of y - height" do
    @box.absolute_bottom.should == 25
  end
 
end
 
describe "drawing bounding boxes" do
 
  it "should restore the margin box when bounding box exits" do
    @pdf = Prawn::Document.new
    margin_box = @pdf.bounds
 
    @pdf.bounding_box [100,500] do
      #nothing
    end
 
    @pdf.bounds.should == margin_box
 
  end
 
  it "should restore the parent bounding box when calls are nested" do
    @pdf = Prawn::Document.new
    @pdf.bounding_box [100,500], :width => 300, :height => 300 do
 
      @pdf.bounds.absolute_top.should == 500
      @pdf.bounds.absolute_left.should == 100
 
      @pdf.bounding_box [50,200], :width => 100, :height => 100 do
        @pdf.bounds.absolute_top.should == 200
        @pdf.bounds.absolute_left.should == 50
      end
 
      @pdf.bounds.absolute_top.should == 500
      @pdf.bounds.absolute_left.should == 100
 
    end
  end
end