fullcirclegroup-fullcirclegroup-prawn 0.2.99.2
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +340 -0
- data/LICENSE +56 -0
- data/README +47 -0
- data/Rakefile +76 -0
- data/data/fonts/Activa.ttf +0 -0
- data/data/fonts/Chalkboard.ttf +0 -0
- data/data/fonts/Courier-Bold.afm +342 -0
- data/data/fonts/Courier-BoldOblique.afm +342 -0
- data/data/fonts/Courier-Oblique.afm +342 -0
- data/data/fonts/Courier.afm +342 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/Helvetica-Bold.afm +2827 -0
- data/data/fonts/Helvetica-BoldOblique.afm +2827 -0
- data/data/fonts/Helvetica-Oblique.afm +3051 -0
- data/data/fonts/Helvetica.afm +3051 -0
- data/data/fonts/MustRead.html +19 -0
- data/data/fonts/Symbol.afm +213 -0
- data/data/fonts/Times-Bold.afm +2588 -0
- data/data/fonts/Times-BoldItalic.afm +2384 -0
- data/data/fonts/Times-Italic.afm +2667 -0
- data/data/fonts/Times-Roman.afm +2419 -0
- data/data/fonts/ZapfDingbats.afm +225 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/arrow.png +0 -0
- data/data/images/arrow2.png +0 -0
- data/data/images/barcode_issue.png +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/dice.png +0 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/page_white_text.png +0 -0
- data/data/images/pigs.jpg +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/data/images/ruport.png +0 -0
- data/data/images/ruport_data.dat +0 -0
- data/data/images/ruport_transparent.png +0 -0
- data/data/images/ruport_type0.png +0 -0
- data/data/images/stef.jpg +0 -0
- data/data/images/web-links.dat +1 -0
- data/data/images/web-links.png +0 -0
- data/data/shift_jis_text.txt +1 -0
- data/examples/addressbook.csv +6 -0
- data/examples/alignment.rb +16 -0
- data/examples/bounding_boxes.rb +30 -0
- data/examples/canvas.rb +12 -0
- data/examples/cell.rb +38 -0
- data/examples/chinese_text_wrapping.rb +17 -0
- data/examples/currency.csv +1834 -0
- data/examples/curves.rb +10 -0
- data/examples/family_based_styling.rb +21 -0
- data/examples/fancy_table.rb +61 -0
- data/examples/flowing_text_with_header_and_footer.rb +72 -0
- data/examples/font_size.rb +27 -0
- data/examples/hexagon.rb +14 -0
- data/examples/image.rb +23 -0
- data/examples/image2.rb +13 -0
- data/examples/image_flow.rb +34 -0
- data/examples/kerning.rb +27 -0
- data/examples/lazy_bounding_boxes.rb +19 -0
- data/examples/line.rb +31 -0
- data/examples/multi_page_layout.rb +14 -0
- data/examples/page_geometry.rb +28 -0
- data/examples/png_types.rb +23 -0
- data/examples/polygons.rb +16 -0
- data/examples/position_by_baseline.rb +26 -0
- data/examples/ruport_formatter.rb +50 -0
- data/examples/ruport_helpers.rb +18 -0
- data/examples/russian_boxes.rb +34 -0
- data/examples/simple_text.rb +15 -0
- data/examples/simple_text_ttf.rb +16 -0
- data/examples/sjis.rb +21 -0
- data/examples/span.rb +27 -0
- data/examples/table.rb +47 -0
- data/examples/table_header_color.rb +16 -0
- data/examples/text_flow.rb +65 -0
- data/examples/top_and_bottom_cells.rb +40 -0
- data/examples/utf8.rb +12 -0
- data/lib/prawn.rb +67 -0
- data/lib/prawn/compatibility.rb +46 -0
- data/lib/prawn/document.rb +309 -0
- data/lib/prawn/document/bounding_box.rb +362 -0
- data/lib/prawn/document/internals.rb +113 -0
- data/lib/prawn/document/page_geometry.rb +79 -0
- data/lib/prawn/document/span.rb +47 -0
- data/lib/prawn/document/table.rb +350 -0
- data/lib/prawn/document/text.rb +196 -0
- data/lib/prawn/errors.rb +48 -0
- data/lib/prawn/font.rb +356 -0
- data/lib/prawn/font/cmap.rb +59 -0
- data/lib/prawn/font/metrics.rb +378 -0
- data/lib/prawn/font/wrapping.rb +47 -0
- data/lib/prawn/graphics.rb +252 -0
- data/lib/prawn/graphics/cell.rb +264 -0
- data/lib/prawn/graphics/color.rb +132 -0
- data/lib/prawn/images.rb +336 -0
- data/lib/prawn/images/jpg.rb +45 -0
- data/lib/prawn/images/png.rb +199 -0
- data/lib/prawn/pdf_object.rb +73 -0
- data/lib/prawn/reference.rb +56 -0
- data/spec/bounding_box_spec.rb +141 -0
- data/spec/document_spec.rb +181 -0
- data/spec/font_spec.rb +141 -0
- data/spec/graphics_spec.rb +209 -0
- data/spec/images_spec.rb +68 -0
- data/spec/jpg_spec.rb +25 -0
- data/spec/metrics_spec.rb +62 -0
- data/spec/pdf_object_spec.rb +112 -0
- data/spec/png_spec.rb +196 -0
- data/spec/reference_spec.rb +42 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/table_spec.rb +179 -0
- data/spec/text_spec.rb +135 -0
- metadata +181 -0
@@ -0,0 +1,181 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "The cursor" do
|
6
|
+
it "should equal pdf.y - bounds.absolute_bottom" do
|
7
|
+
pdf = Prawn::Document.new
|
8
|
+
pdf.cursor.should == pdf.bounds.top
|
9
|
+
|
10
|
+
pdf.y = 300
|
11
|
+
pdf.cursor.should == pdf.y - pdf.bounds.absolute_bottom
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "When creating multi-page documents" do
|
16
|
+
|
17
|
+
before(:each) { create_pdf }
|
18
|
+
|
19
|
+
it "should initialize with a single page" do
|
20
|
+
page_counter = PDF::Inspector::Page.analyze(@pdf.render)
|
21
|
+
|
22
|
+
page_counter.pages.size.should == 1
|
23
|
+
@pdf.page_count.should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should provide an accurate page_count" do
|
27
|
+
3.times { @pdf.start_new_page }
|
28
|
+
page_counter = PDF::Inspector::Page.analyze(@pdf.render)
|
29
|
+
|
30
|
+
page_counter.pages.size.should == 4
|
31
|
+
@pdf.page_count.should == 4
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "When beginning each new page" do
|
37
|
+
|
38
|
+
it "should execute codeblock given to Document#header" do
|
39
|
+
call_count = 0
|
40
|
+
|
41
|
+
pdf = Prawn::Document.new
|
42
|
+
pdf.header(pdf.margin_box.top_left) do
|
43
|
+
call_count += 1
|
44
|
+
end
|
45
|
+
|
46
|
+
pdf.start_new_page
|
47
|
+
pdf.start_new_page
|
48
|
+
pdf.render
|
49
|
+
|
50
|
+
call_count.should == 3
|
51
|
+
end
|
52
|
+
describe "Background template feature" do
|
53
|
+
before(:each) do
|
54
|
+
@filename = "#{Prawn::BASEDIR}/data/images/pigs.jpg"
|
55
|
+
@pdf = Prawn::Document.new(:background => @filename)
|
56
|
+
end
|
57
|
+
it "should place a background image if it is in options block" do
|
58
|
+
output = @pdf.render
|
59
|
+
images = PDF::Inspector::XObject.analyze(output)
|
60
|
+
# there should be 2 images in the page resources
|
61
|
+
images.page_xobjects.first.size.should == 1
|
62
|
+
end
|
63
|
+
it "should place a background image if it is in options block" do
|
64
|
+
@pdf.instance_variable_defined?(:@background).should == true
|
65
|
+
@pdf.instance_variable_get(:@background).should == @filename
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "When ending each page" do
|
72
|
+
|
73
|
+
it "should execute codeblock given to Document#footer" do
|
74
|
+
|
75
|
+
call_count = 0
|
76
|
+
|
77
|
+
pdf = Prawn::Document.new
|
78
|
+
pdf.footer([pdf.margin_box.left, pdf.margin_box.bottom + 50]) do
|
79
|
+
call_count += 1
|
80
|
+
end
|
81
|
+
|
82
|
+
pdf.start_new_page
|
83
|
+
pdf.start_new_page
|
84
|
+
pdf.render
|
85
|
+
|
86
|
+
call_count.should == 3
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should not compress the page content stream if compression is disabled" do
|
90
|
+
|
91
|
+
pdf = Prawn::Document.new(:compress => false)
|
92
|
+
content_stub = pdf.ref({})
|
93
|
+
content_stub.stubs(:compress_stream).returns(true)
|
94
|
+
content_stub.expects(:compress_stream).never
|
95
|
+
|
96
|
+
pdf.instance_variable_set("@page_content", content_stub)
|
97
|
+
pdf.text "Hi There" * 20
|
98
|
+
pdf.render
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should compress the page content stream if compression is enabled" do
|
102
|
+
|
103
|
+
pdf = Prawn::Document.new(:compress => true)
|
104
|
+
content_stub = pdf.ref({})
|
105
|
+
content_stub.stubs(:compress_stream).returns(true)
|
106
|
+
content_stub.expects(:compress_stream).once
|
107
|
+
|
108
|
+
pdf.instance_variable_set("@page_content", content_stub)
|
109
|
+
pdf.text "Hi There" * 20
|
110
|
+
pdf.render
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should result in a smaller file size when compressed" do
|
114
|
+
doc_uncompressed = Prawn::Document.new
|
115
|
+
doc_compressed = Prawn::Document.new(:compress => true)
|
116
|
+
[doc_compressed, doc_uncompressed].each do |pdf|
|
117
|
+
pdf.font "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf"
|
118
|
+
pdf.text "更可怕的是,同质化竞争对手可以按照URL中后面这个ID来遍历" * 10
|
119
|
+
end
|
120
|
+
|
121
|
+
doc_compressed.render.length.should.be < doc_uncompressed.render.length
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "When setting page size" do
|
127
|
+
it "should default to LETTER" do
|
128
|
+
@pdf = Prawn::Document.new
|
129
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
130
|
+
pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["LETTER"]
|
131
|
+
end
|
132
|
+
|
133
|
+
(Prawn::Document::PageGeometry::SIZES.keys - ["LETTER"]).each do |k|
|
134
|
+
it "should provide #{k} geometry" do
|
135
|
+
@pdf = Prawn::Document.new(:page_size => k)
|
136
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
137
|
+
pages.first[:size].should == Prawn::Document::PageGeometry::SIZES[k]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should allow custom page size" do
|
142
|
+
@pdf = Prawn::Document.new(:page_size => [1920, 1080] )
|
143
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
144
|
+
pages.first[:size].should == [1920, 1080]
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
describe "When setting page layout" do
|
150
|
+
it "should reverse coordinates for landscape" do
|
151
|
+
@pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
|
152
|
+
pages = PDF::Inspector::Page.analyze(@pdf.render).pages
|
153
|
+
pages.first[:size].should == Prawn::Document::PageGeometry::SIZES["A4"].reverse
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "The mask() feature" do
|
158
|
+
it "should allow transactional restoration of attributes" do
|
159
|
+
@pdf = Prawn::Document.new
|
160
|
+
y, line_width = @pdf.y, @pdf.line_width
|
161
|
+
@pdf.mask(:y, :line_width) do
|
162
|
+
@pdf.y = y + 1
|
163
|
+
@pdf.line_width = line_width + 1
|
164
|
+
@pdf.y.should.not == y
|
165
|
+
@pdf.line_width.should.not == line_width
|
166
|
+
end
|
167
|
+
@pdf.y.should == y
|
168
|
+
@pdf.line_width.should == line_width
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "The render() feature" do
|
173
|
+
if "spec".respond_to?(:encode!)
|
174
|
+
it "should return a 8 bit encoded string on a m17n aware VM" do
|
175
|
+
@pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
|
176
|
+
@pdf.line [100,100], [200,200]
|
177
|
+
str = @pdf.render
|
178
|
+
str.encoding.to_s.should == "ASCII-8BIT"
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
data/spec/font_spec.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "Font Metrics" do
|
6
|
+
|
7
|
+
it "should default to Helvetica if no font is specified" do
|
8
|
+
@pdf = Prawn::Document.new
|
9
|
+
@pdf.font.metrics.should == Prawn::Font::Metrics["Helvetica"]
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should use the currently set font for font_metrics" do
|
13
|
+
@pdf = Prawn::Document.new
|
14
|
+
@pdf.font "Courier"
|
15
|
+
@pdf.font.metrics.should == Prawn::Font::Metrics["Courier"]
|
16
|
+
|
17
|
+
comicsans = "#{Prawn::BASEDIR}/data/fonts/comicsans.ttf"
|
18
|
+
@pdf.font(comicsans)
|
19
|
+
@pdf.font.metrics.should == Prawn::Font::Metrics[comicsans]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should wrap text" do
|
23
|
+
@pdf = Prawn::Document.new
|
24
|
+
@pdf.font "Courier"
|
25
|
+
@pdf.font.metrics.naive_wrap("Please wrap this text about HERE. More text that should be wrapped", 220, @pdf.font.size).should ==
|
26
|
+
"Please wrap this text about\nHERE. More text that should be\nwrapped"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should respect end of line when wrapping text" do
|
30
|
+
@pdf = Prawn::Document.new
|
31
|
+
@pdf.font "Courier"
|
32
|
+
text = "Please wrap only before\nTHIS word. Don't wrap this"
|
33
|
+
@pdf.font.metrics.naive_wrap(text, 220, @pdf.font.size).should == text
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should respect end of line when wrapping text and mode is set to 'character'" do
|
37
|
+
@pdf = Prawn::Document.new
|
38
|
+
@pdf.font "Courier"
|
39
|
+
opts = {:mode => :character}
|
40
|
+
@pdf.font.metrics.naive_wrap("You can wrap this text HERE", 180, @pdf.font.size, opts).should ==
|
41
|
+
"You can wrap this text HE\nRE"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "font style support" do
|
47
|
+
before(:each) { create_pdf }
|
48
|
+
|
49
|
+
it "should allow specifying font style by style name and font family" do
|
50
|
+
@pdf.font "Courier", :style => :bold
|
51
|
+
@pdf.text "In Courier bold"
|
52
|
+
|
53
|
+
@pdf.font "Courier", :style => :bold_italic
|
54
|
+
@pdf.text "In Courier bold-italic"
|
55
|
+
|
56
|
+
@pdf.font "Courier", :style => :italic
|
57
|
+
@pdf.text "In Courier italic"
|
58
|
+
|
59
|
+
@pdf.font "Courier", :style => :normal
|
60
|
+
@pdf.text "In Normal Courier"
|
61
|
+
|
62
|
+
@pdf.font "Helvetica"
|
63
|
+
@pdf.text "In Normal Helvetica"
|
64
|
+
|
65
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
66
|
+
text.font_settings.map { |e| e[:name] }.should ==
|
67
|
+
[:"Courier-Bold", :"Courier-BoldOblique", :"Courier-Oblique",
|
68
|
+
:Courier, :Helvetica]
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "Transactional font handling" do
|
74
|
+
before(:each) { create_pdf }
|
75
|
+
|
76
|
+
it "should allow setting of size directly when font is created" do
|
77
|
+
@pdf.font "Courier", :size => 16
|
78
|
+
@pdf.font.size.should == 16
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should allow temporary setting of a new font using a transaction" do
|
82
|
+
original = @pdf.font
|
83
|
+
|
84
|
+
@pdf.font "Courier", :size => 16 do
|
85
|
+
@pdf.font.name.should == "Courier"
|
86
|
+
@pdf.font.size.should == 16
|
87
|
+
end
|
88
|
+
|
89
|
+
@pdf.font.should == original
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
describe "Document#page_fonts" do
|
96
|
+
before(:each) { create_pdf }
|
97
|
+
|
98
|
+
it "should register the current font when changing pages" do
|
99
|
+
@pdf.font "Courier"
|
100
|
+
page_should_include_font("Courier")
|
101
|
+
@pdf.start_new_page
|
102
|
+
page_should_include_font("Courier")
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should register fonts properly by page" do
|
106
|
+
@pdf.font "Courier"
|
107
|
+
@pdf.font "Helvetica"
|
108
|
+
@pdf.font "Times-Roman"
|
109
|
+
["Courier","Helvetica","Times-Roman"].each { |f|
|
110
|
+
page_should_include_font(f)
|
111
|
+
}
|
112
|
+
|
113
|
+
@pdf.start_new_page
|
114
|
+
@pdf.font "Helvetica"
|
115
|
+
["Times-Roman","Helvetica"].each { |f|
|
116
|
+
page_should_include_font(f)
|
117
|
+
}
|
118
|
+
page_should_not_include_font("Courier")
|
119
|
+
end
|
120
|
+
|
121
|
+
def page_includes_font?(font)
|
122
|
+
@pdf.page_fonts.values.map { |e| e.data[:BaseFont] }.include?(font.to_sym)
|
123
|
+
end
|
124
|
+
|
125
|
+
def page_should_include_font(font)
|
126
|
+
assert_block("Expected page to include font: #{font}") do
|
127
|
+
page_includes_font?(font)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def page_should_not_include_font(font)
|
132
|
+
assert_block("Did not expect page to include font: #{font}") do
|
133
|
+
not page_includes_font?(font)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
@@ -0,0 +1,209 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
4
|
+
|
5
|
+
describe "When drawing a line" do
|
6
|
+
|
7
|
+
before(:each) { create_pdf }
|
8
|
+
|
9
|
+
it "should draw a line from (100,600) to (100,500)" do
|
10
|
+
@pdf.line([100,600],[100,500])
|
11
|
+
|
12
|
+
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
13
|
+
|
14
|
+
line_drawing.points.should == [[100,600],[100,500]]
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should draw two lines at (100,600) to (100,500) " +
|
18
|
+
"and (75,100) to (50,125)" do
|
19
|
+
@pdf.line(100,600,100,500)
|
20
|
+
@pdf.line(75,100,50,125)
|
21
|
+
|
22
|
+
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
23
|
+
|
24
|
+
line_drawing.points.should ==
|
25
|
+
[[100.0, 600.0], [100.0, 500.0], [75.0, 100.0], [50.0, 125.0]]
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should properly set line width via line_width=" do
|
29
|
+
@pdf.line_width = 10
|
30
|
+
line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
31
|
+
line.widths.first.should == 10
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should properly set line width via line_width(width)" do
|
35
|
+
@pdf.line_width(10)
|
36
|
+
line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
37
|
+
line.widths.first.should == 10
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "(Horizontally)" do
|
41
|
+
it "should draw from [x1,pdf.y],[x2,pdf.y]" do
|
42
|
+
@pdf.horizontal_line(100,150)
|
43
|
+
@line = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
44
|
+
@line.points.should == [[100.0 + @pdf.bounds.absolute_left, @pdf.y],
|
45
|
+
[150.0 + @pdf.bounds.absolute_left, @pdf.y]]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should draw a line from (200, 250) to (300, 250)" do
|
49
|
+
@pdf.horizontal_line(200,300,:at => 250)
|
50
|
+
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
51
|
+
line_drawing.points.should == [[200,250],[300,250]]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "(Vertically)" do
|
56
|
+
it "should draw a line from (350, 300) to (350, 400)" do
|
57
|
+
@pdf.vertical_line(300,400,:at => 350)
|
58
|
+
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
59
|
+
line_drawing.points.should == [[350,300],[350,400]]
|
60
|
+
end
|
61
|
+
it "should require a y coordinate" do
|
62
|
+
lambda { @pdf.vertical_line(400,500) }.
|
63
|
+
should.raise(ArgumentError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "When drawing a polygon" do
|
70
|
+
|
71
|
+
before(:each) { create_pdf }
|
72
|
+
|
73
|
+
it "should draw each line passed to polygon()" do
|
74
|
+
@pdf.polygon([100,500],[100,400],[200,400])
|
75
|
+
|
76
|
+
line_drawing = PDF::Inspector::Graphics::Line.analyze(@pdf.render)
|
77
|
+
line_drawing.points.should == [[100,500],[100,400],[200,400],[100,500]]
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "When drawing a rectangle" do
|
83
|
+
|
84
|
+
before(:each) { create_pdf }
|
85
|
+
|
86
|
+
it "should use a point, width, and height for coords" do
|
87
|
+
@pdf.rectangle [200,200], 50, 100
|
88
|
+
|
89
|
+
rectangles = PDF::Inspector::Graphics::Rectangle.
|
90
|
+
analyze(@pdf.render).rectangles
|
91
|
+
# PDF uses bottom left corner
|
92
|
+
rectangles[0][:point].should == [200,100]
|
93
|
+
rectangles[0][:width].should == 50
|
94
|
+
rectangles[0][:height].should == 100
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "When drawing a curve" do
|
101
|
+
|
102
|
+
before(:each) { create_pdf }
|
103
|
+
|
104
|
+
it "should draw a bezier curve from 50,50 to 100,100" do
|
105
|
+
@pdf.move_to [50,50]
|
106
|
+
@pdf.curve_to [100,100],:bounds => [[20,90], [90,70]]
|
107
|
+
curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
108
|
+
curve.coords.should == [50.0, 50.0, 20.0, 90.0, 90.0, 70.0, 100.0, 100.0]
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should draw a bezier curve from 100,100 to 50,50" do
|
112
|
+
@pdf.curve [100,100], [50,50], :bounds => [[20,90], [90,75]]
|
113
|
+
curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
114
|
+
curve.coords.should == [100.0, 100.0, 20.0, 90.0, 90.0, 75.0, 50.0, 50.0]
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "When drawing an ellipse" do
|
120
|
+
before(:each) do
|
121
|
+
create_pdf
|
122
|
+
@pdf.ellipse_at [100,100], 25, 50
|
123
|
+
@curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should move the pointer to the center of the ellipse after drawing" do
|
127
|
+
@curve.coords[-2..-1].should == [100,100]
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "When drawing a circle" do
|
133
|
+
before(:each) do
|
134
|
+
create_pdf
|
135
|
+
@pdf.circle_at [100,100], :radius => 25
|
136
|
+
@pdf.ellipse_at [100,100], 25, 25
|
137
|
+
@curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should stroke the same path as the equivalent ellipse" do
|
141
|
+
middle = @curve.coords.length / 2
|
142
|
+
@curve.coords[0...middle].should == @curve.coords[middle..-1]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "When setting colors" do
|
147
|
+
|
148
|
+
before(:each) { create_pdf }
|
149
|
+
|
150
|
+
it "should set stroke colors" do
|
151
|
+
@pdf.stroke_color "ffcccc"
|
152
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
153
|
+
# 100% red, 80% green, 80% blue
|
154
|
+
colors.stroke_color.should == [1.0, 0.8, 0.8]
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should set fill colors" do
|
158
|
+
@pdf.fill_color "ccff00"
|
159
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
160
|
+
# 80% red, 100% green, 0% blue
|
161
|
+
colors.fill_color.should == [0.8,1.0,0]
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should reset the colors on each new page if they have been defined" do
|
165
|
+
@pdf.fill_color "ccff00"
|
166
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
167
|
+
|
168
|
+
colors.fill_color_count.should == 2
|
169
|
+
colors.stroke_color_count.should == 1
|
170
|
+
@pdf.start_new_page
|
171
|
+
@pdf.stroke_color "ff00cc"
|
172
|
+
|
173
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
174
|
+
colors.fill_color_count.should == 3
|
175
|
+
colors.stroke_color_count.should == 3
|
176
|
+
|
177
|
+
@pdf.start_new_page
|
178
|
+
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
179
|
+
colors.fill_color_count.should == 4
|
180
|
+
colors.stroke_color_count.should == 4
|
181
|
+
|
182
|
+
colors.fill_color.should == [0.8,1.0,0.0]
|
183
|
+
colors.stroke_color.should == [1.0,0.0,0.8]
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "When using painting shortcuts" do
|
189
|
+
before(:each) { create_pdf }
|
190
|
+
|
191
|
+
it "should convert stroke_some_method(args) into some_method(args); stroke" do
|
192
|
+
@pdf.expects(:line_to).with([100,100])
|
193
|
+
@pdf.expects(:stroke)
|
194
|
+
|
195
|
+
@pdf.stroke_line_to [100,100]
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should convert fill_some_method(args) into some_method(args); fill" do
|
199
|
+
@pdf.expects(:line_to).with([100,100])
|
200
|
+
@pdf.expects(:fill)
|
201
|
+
|
202
|
+
@pdf.fill_line_to [100,100]
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should not break method_missing" do
|
206
|
+
lambda { @pdf.i_have_a_pretty_girlfriend_named_jia }.
|
207
|
+
should.raise(NoMethodError)
|
208
|
+
end
|
209
|
+
end
|