prawn 0.11.1.pre → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +2 -340
- data/HACKING +1 -1
- data/LICENSE +3 -3
- data/Rakefile +17 -6
- data/data/encodings/win_ansi.txt +1 -1
- data/data/images/prawn.png +0 -0
- data/data/pdfs/form.pdf +820 -0
- data/data/pdfs/multipage_template.pdf +127 -0
- data/examples/bounding_box/bounding_boxes.rb +4 -3
- data/examples/bounding_box/indentation.rb +2 -1
- data/examples/bounding_box/russian_boxes.rb +3 -2
- data/examples/bounding_box/stretched_nesting.rb +2 -1
- data/examples/general/background.rb +2 -1
- data/examples/general/canvas.rb +2 -1
- data/examples/general/context_sensitive_headers.rb +2 -1
- data/examples/general/float.rb +2 -1
- data/examples/general/margin.rb +2 -1
- data/examples/general/measurement_units.rb +2 -1
- data/examples/general/metadata-info.rb +2 -1
- data/examples/general/multi_page_layout.rb +2 -1
- data/examples/general/outlines.rb +2 -1
- data/examples/general/page_geometry.rb +2 -1
- data/examples/general/page_numbering.rb +27 -2
- data/examples/general/page_templates.rb +20 -0
- data/examples/general/repeaters.rb +2 -1
- data/examples/general/stamp.rb +4 -3
- data/examples/general/templates.rb +2 -1
- data/examples/graphics/basic_images.rb +2 -1
- data/examples/graphics/cmyk.rb +2 -1
- data/examples/graphics/curves.rb +4 -3
- data/examples/graphics/gradient.rb +23 -0
- data/examples/graphics/hexagon.rb +3 -2
- data/examples/graphics/image_fit.rb +3 -2
- data/examples/graphics/image_flow.rb +2 -1
- data/examples/graphics/image_position.rb +3 -2
- data/examples/graphics/line.rb +2 -1
- data/examples/graphics/png_types.rb +3 -2
- data/examples/graphics/polygons.rb +3 -2
- data/examples/graphics/remote_images.rb +2 -1
- data/examples/graphics/rounded_polygons.rb +2 -1
- data/examples/graphics/rounded_rectangle.rb +2 -1
- data/examples/graphics/ruport_style_helpers.rb +3 -2
- data/examples/graphics/stroke_bounds.rb +2 -1
- data/examples/graphics/stroke_cap_and_join.rb +2 -1
- data/examples/graphics/stroke_dash.rb +2 -1
- data/examples/graphics/transformations.rb +2 -1
- data/examples/graphics/transparency.rb +4 -3
- data/examples/grid/bounding_boxes.rb +2 -1
- data/examples/grid/column_gutter_grid.rb +2 -1
- data/examples/grid/multi_boxes.rb +2 -1
- data/examples/grid/show_grid.rb +2 -1
- data/examples/grid/simple_grid.rb +2 -1
- data/examples/m17n/chinese_text_wrapping.rb +2 -1
- data/examples/m17n/euro.rb +3 -2
- data/examples/m17n/full_win_ansi_character_list.rb +20 -0
- data/examples/m17n/sjis.rb +2 -1
- data/examples/m17n/utf8.rb +3 -2
- data/examples/m17n/win_ansi_charset.rb +2 -1
- data/examples/security/hello_foo.rb +2 -1
- data/examples/table/bill.rb +2 -1
- data/examples/table/borders.rb +25 -0
- data/examples/table/cell.rb +3 -2
- data/examples/table/checkerboard.rb +2 -1
- data/examples/table/header.rb +3 -2
- data/examples/table/inline_format_table.rb +2 -1
- data/examples/table/multi_page_table.rb +2 -1
- data/examples/table/simple_table.rb +2 -1
- data/examples/table/subtable.rb +2 -1
- data/examples/table/widths.rb +2 -1
- data/examples/text/alignment.rb +2 -1
- data/examples/text/character_spacing.rb +2 -1
- data/examples/text/dfont.rb +2 -1
- data/examples/text/family_based_styling.rb +3 -2
- data/examples/text/font_calculations.rb +2 -1
- data/examples/text/font_size.rb +2 -1
- data/examples/text/hyphenation.rb +2 -2
- data/examples/text/indent_paragraphs.rb +7 -5
- data/examples/text/inline_format.rb +7 -6
- data/examples/text/kerning.rb +2 -1
- data/examples/text/rendering_mode.rb +21 -0
- data/examples/text/rotated.rb +2 -1
- data/examples/text/shaped_text_box.rb +2 -1
- data/examples/text/simple_text.rb +2 -1
- data/examples/text/simple_text_ttf.rb +2 -1
- data/examples/text/span.rb +3 -2
- data/examples/text/text_box.rb +7 -5
- data/examples/text/text_box_returning_excess.rb +4 -3
- data/examples/text/text_flow.rb +2 -1
- data/lib/prawn.rb +1 -1
- data/lib/prawn/core/object_store.rb +42 -14
- data/lib/prawn/core/page.rb +22 -8
- data/lib/prawn/core/text.rb +141 -13
- data/lib/prawn/core/text/formatted/arranger.rb +39 -12
- data/lib/prawn/core/text/formatted/line_wrap.rb +205 -60
- data/lib/prawn/core/text/formatted/wrap.rb +72 -35
- data/lib/prawn/document.rb +174 -70
- data/lib/prawn/document/bounding_box.rb +122 -83
- data/lib/prawn/document/column_box.rb +113 -0
- data/lib/prawn/document/graphics_state.rb +90 -2
- data/lib/prawn/document/internals.rb +5 -3
- data/lib/prawn/errors.rb +5 -0
- data/lib/prawn/font.rb +4 -4
- data/lib/prawn/font/afm.rb +11 -0
- data/lib/prawn/font/ttf.rb +5 -0
- data/lib/prawn/graphics.rb +77 -14
- data/lib/prawn/graphics/cap_style.rb +13 -5
- data/lib/prawn/graphics/color.rb +54 -35
- data/lib/prawn/graphics/dash.rb +27 -16
- data/lib/prawn/graphics/gradient.rb +84 -0
- data/lib/prawn/graphics/join_style.rb +12 -3
- data/lib/prawn/graphics/transparency.rb +4 -4
- data/lib/prawn/images.rb +18 -160
- data/lib/prawn/images/jpg.rb +39 -0
- data/lib/prawn/images/png.rb +130 -0
- data/lib/prawn/repeater.rb +6 -13
- data/lib/prawn/security.rb +6 -1
- data/lib/prawn/stamp.rb +12 -4
- data/lib/prawn/table.rb +36 -4
- data/lib/prawn/table/cell.rb +224 -63
- data/lib/prawn/table/cell/text.rb +20 -10
- data/lib/prawn/table/cells.rb +23 -6
- data/lib/prawn/text.rb +54 -91
- data/lib/prawn/text/box.rb +29 -283
- data/lib/prawn/text/formatted/box.rb +349 -24
- data/lib/prawn/text/formatted/fragment.rb +63 -2
- data/lib/prawn/text/formatted/parser.rb +2 -1
- data/prawn.gemspec +21 -5
- data/spec/bounding_box_spec.rb +61 -28
- data/spec/cell_spec.rb +168 -30
- data/spec/document_spec.rb +187 -3
- data/spec/extensions/mocha.rb +45 -0
- data/spec/font_spec.rb +32 -1
- data/spec/formatted_text_arranger_spec.rb +35 -40
- data/spec/formatted_text_box_spec.rb +287 -443
- data/spec/formatted_text_fragment_spec.rb +87 -0
- data/spec/graphics_spec.rb +128 -12
- data/spec/grid_spec.rb +1 -1
- data/spec/images_spec.rb +11 -3
- data/spec/inline_formatted_text_parser_spec.rb +8 -0
- data/spec/line_wrap_spec.rb +200 -208
- data/spec/object_store_spec.rb +10 -0
- data/spec/outline_spec.rb +7 -3
- data/spec/repeater_spec.rb +58 -10
- data/spec/security_spec.rb +6 -0
- data/spec/spec_helper.rb +12 -8
- data/spec/stamp_spec.rb +52 -1
- data/spec/stroke_styles_spec.rb +30 -0
- data/spec/table_spec.rb +93 -3
- data/spec/template_spec.rb +132 -6
- data/spec/text_at_spec.rb +14 -4
- data/spec/text_box_spec.rb +309 -70
- data/spec/text_rendering_mode_spec.rb +45 -0
- data/spec/text_spec.rb +60 -17
- data/spec/text_with_inline_formatting_spec.rb +4 -162
- metadata +241 -241
- data/lib/prawn/core/text/line_wrap.rb +0 -211
- data/lib/prawn/core/text/wrap.rb +0 -82
- data/vendor/pdf-inspector/README +0 -18
- data/vendor/pdf-inspector/lib/pdf/inspector.rb +0 -26
- data/vendor/pdf-inspector/lib/pdf/inspector/extgstate.rb +0 -18
- data/vendor/pdf-inspector/lib/pdf/inspector/graphics.rb +0 -131
- data/vendor/pdf-inspector/lib/pdf/inspector/page.rb +0 -25
- data/vendor/pdf-inspector/lib/pdf/inspector/text.rb +0 -46
- data/vendor/pdf-inspector/lib/pdf/inspector/xobject.rb +0 -19
- data/vendor/ttfunk/data/fonts/DejaVuSans.ttf +0 -0
- data/vendor/ttfunk/data/fonts/comicsans.ttf +0 -0
- data/vendor/ttfunk/example.rb +0 -45
- data/vendor/ttfunk/lib/ttfunk.rb +0 -102
- data/vendor/ttfunk/lib/ttfunk/directory.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/encoding/mac_roman.rb +0 -88
- data/vendor/ttfunk/lib/ttfunk/encoding/windows_1252.rb +0 -69
- data/vendor/ttfunk/lib/ttfunk/reader.rb +0 -44
- data/vendor/ttfunk/lib/ttfunk/resource_file.rb +0 -78
- data/vendor/ttfunk/lib/ttfunk/subset.rb +0 -18
- data/vendor/ttfunk/lib/ttfunk/subset/base.rb +0 -141
- data/vendor/ttfunk/lib/ttfunk/subset/mac_roman.rb +0 -50
- data/vendor/ttfunk/lib/ttfunk/subset/unicode.rb +0 -48
- data/vendor/ttfunk/lib/ttfunk/subset/unicode_8bit.rb +0 -63
- data/vendor/ttfunk/lib/ttfunk/subset/windows_1252.rb +0 -55
- data/vendor/ttfunk/lib/ttfunk/subset_collection.rb +0 -72
- data/vendor/ttfunk/lib/ttfunk/table.rb +0 -46
- data/vendor/ttfunk/lib/ttfunk/table/cmap.rb +0 -34
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format00.rb +0 -54
- data/vendor/ttfunk/lib/ttfunk/table/cmap/format04.rb +0 -126
- data/vendor/ttfunk/lib/ttfunk/table/cmap/subtable.rb +0 -79
- data/vendor/ttfunk/lib/ttfunk/table/glyf.rb +0 -64
- data/vendor/ttfunk/lib/ttfunk/table/glyf/compound.rb +0 -81
- data/vendor/ttfunk/lib/ttfunk/table/glyf/simple.rb +0 -37
- data/vendor/ttfunk/lib/ttfunk/table/head.rb +0 -44
- data/vendor/ttfunk/lib/ttfunk/table/hhea.rb +0 -41
- data/vendor/ttfunk/lib/ttfunk/table/hmtx.rb +0 -47
- data/vendor/ttfunk/lib/ttfunk/table/kern.rb +0 -79
- data/vendor/ttfunk/lib/ttfunk/table/kern/format0.rb +0 -62
- data/vendor/ttfunk/lib/ttfunk/table/loca.rb +0 -43
- data/vendor/ttfunk/lib/ttfunk/table/maxp.rb +0 -40
- data/vendor/ttfunk/lib/ttfunk/table/name.rb +0 -125
- data/vendor/ttfunk/lib/ttfunk/table/os2.rb +0 -78
- data/vendor/ttfunk/lib/ttfunk/table/post.rb +0 -91
- data/vendor/ttfunk/lib/ttfunk/table/post/format10.rb +0 -43
- data/vendor/ttfunk/lib/ttfunk/table/post/format20.rb +0 -35
- data/vendor/ttfunk/lib/ttfunk/table/post/format25.rb +0 -23
- data/vendor/ttfunk/lib/ttfunk/table/post/format30.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/table/post/format40.rb +0 -17
- data/vendor/ttfunk/lib/ttfunk/table/simple.rb +0 -14
data/spec/object_store_spec.rb
CHANGED
@@ -157,4 +157,14 @@ describe "Prawn::ObjectStorie#object_id_for_page" do
|
|
157
157
|
store = Prawn::Core::ObjectStore.new
|
158
158
|
store.object_id_for_page(10).should == nil
|
159
159
|
end
|
160
|
+
|
161
|
+
it "should accept a stream instead of a filename" do
|
162
|
+
example = Prawn::Document.new()
|
163
|
+
example.text "An example doc, created in memory"
|
164
|
+
example.start_new_page
|
165
|
+
StringIO.open(example.render) do |stream|
|
166
|
+
@pdf = Prawn::Core::ObjectStore.new(:template => stream)
|
167
|
+
end
|
168
|
+
@pdf.page_count.should == 2
|
169
|
+
end
|
160
170
|
end
|
data/spec/outline_spec.rb
CHANGED
@@ -242,14 +242,15 @@ describe "Outline" do
|
|
242
242
|
page :destination => page_number, :title => "Inserted Page"
|
243
243
|
end
|
244
244
|
end
|
245
|
-
render_and_find_objects
|
246
245
|
end
|
247
246
|
|
248
247
|
it "should insert new outline items to document" do
|
248
|
+
render_and_find_objects
|
249
249
|
assert_not_nil @inserted_page
|
250
250
|
end
|
251
251
|
|
252
252
|
it "should adjust the count of all ancestors" do
|
253
|
+
render_and_find_objects
|
253
254
|
@outline_root[:Count].should == 4
|
254
255
|
@section_1[:Count].should.abs == 3
|
255
256
|
end
|
@@ -257,16 +258,19 @@ describe "Outline" do
|
|
257
258
|
describe "#adjust_relations" do
|
258
259
|
|
259
260
|
it "should reset the sibling relations of adjoining items to inserted item" do
|
261
|
+
render_and_find_objects
|
260
262
|
referenced_object(@page_1[:Next]).should == @inserted_page
|
261
263
|
referenced_object(@page_2[:Prev]).should == @inserted_page
|
262
264
|
end
|
263
265
|
|
264
266
|
it "should set the sibling relation of added item to adjoining items" do
|
267
|
+
render_and_find_objects
|
265
268
|
referenced_object(@inserted_page[:Next]).should == @page_2
|
266
269
|
referenced_object(@inserted_page[:Prev]).should == @page_1
|
267
270
|
end
|
268
271
|
|
269
272
|
it "should not affect the first and last relations of parent item" do
|
273
|
+
render_and_find_objects
|
270
274
|
referenced_object(@section_1[:First]).should == @page_1
|
271
275
|
referenced_object(@section_1[:Last]).should == @page_2
|
272
276
|
end
|
@@ -361,7 +365,7 @@ context "foreign character encoding" do
|
|
361
365
|
section 'La pomme croquée', :destination => 1, :closed => true
|
362
366
|
end
|
363
367
|
end
|
364
|
-
@hash = PDF::
|
368
|
+
@hash = PDF::Reader::ObjectHash.new(StringIO.new(pdf.render, 'r+'))
|
365
369
|
end
|
366
370
|
|
367
371
|
it "should handle other encodings for the title" do
|
@@ -372,7 +376,7 @@ end
|
|
372
376
|
|
373
377
|
def render_and_find_objects
|
374
378
|
output = StringIO.new(@pdf.render, 'r+')
|
375
|
-
@hash = PDF::
|
379
|
+
@hash = PDF::Reader::ObjectHash.new(output)
|
376
380
|
@outline_root = @hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Outlines}
|
377
381
|
@pages = @hash.values.find {|obj| obj.is_a?(Hash) && obj[:Type] == :Pages}[:Kids]
|
378
382
|
@section_1 = find_by_title('Chapter 1')
|
data/spec/repeater_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
2
2
|
|
3
3
|
describe "Repeaters" do
|
4
4
|
|
@@ -10,13 +10,13 @@ describe "Repeaters" do
|
|
10
10
|
|
11
11
|
r = repeater(doc, :all) { :do_nothing }
|
12
12
|
|
13
|
-
assert_equal orig_count + 1, Prawn::Repeater.count
|
13
|
+
assert_equal orig_count + 1, Prawn::Repeater.count
|
14
14
|
end
|
15
15
|
|
16
16
|
it "must provide an :all filter" do
|
17
17
|
doc = sample_document
|
18
18
|
r = repeater(doc, :all) { :do_nothing }
|
19
|
-
|
19
|
+
|
20
20
|
assert (1..doc.page_count).all? { |i| r.match?(i) }
|
21
21
|
end
|
22
22
|
|
@@ -64,23 +64,39 @@ describe "Repeaters" do
|
|
64
64
|
doc.expects(:stamp).never
|
65
65
|
repeater(doc, :odd).run(2)
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
it "must not try to run a stamp if dynamic is selected" do
|
69
69
|
doc = sample_document
|
70
70
|
|
71
71
|
doc.expects(:stamp).never
|
72
72
|
(1..10).each { |p| repeater(doc, :all, true){:do_nothing}.run(p) }
|
73
73
|
end
|
74
|
-
|
75
|
-
it "must
|
74
|
+
|
75
|
+
it "must treat any block as a closure" do
|
76
76
|
doc = sample_document
|
77
77
|
|
78
|
-
|
79
|
-
|
78
|
+
@page = "Page" # ensure access to ivars
|
79
|
+
doc.repeat(:all, :dynamic => true) do
|
80
|
+
doc.draw_text "#@page #{doc.page_number}", :at => [500, 0]
|
81
|
+
end
|
82
|
+
|
83
|
+
text = PDF::Inspector::Text.analyze(doc.render)
|
84
|
+
assert_equal (1..10).to_a.map{|p| "Page #{p}"}, text.strings
|
85
|
+
end
|
86
|
+
|
87
|
+
it "must treat any block as a closure (Document.new instance_eval form)" do
|
88
|
+
doc = Prawn::Document.new(:skip_page_creation => true) do
|
89
|
+
10.times { start_new_page }
|
90
|
+
|
91
|
+
@page = "Page"
|
92
|
+
repeat(:all, :dynamic => true) do
|
93
|
+
# ensure self is accessible here
|
94
|
+
draw_text "#@page #{page_number}", :at => [500, 0]
|
95
|
+
end
|
80
96
|
end
|
81
97
|
|
82
|
-
text = PDF::Inspector::Text.analyze(doc.render)
|
83
|
-
assert_equal (1..10).to_a.map{|p| p
|
98
|
+
text = PDF::Inspector::Text.analyze(doc.render)
|
99
|
+
assert_equal (1..10).to_a.map{|p| "Page #{p}"}, text.strings
|
84
100
|
end
|
85
101
|
|
86
102
|
def sample_document
|
@@ -93,4 +109,36 @@ describe "Repeaters" do
|
|
93
109
|
Prawn::Repeater.new(*args,&b)
|
94
110
|
end
|
95
111
|
|
112
|
+
context "graphic state" do
|
113
|
+
|
114
|
+
it "should not alter the graphic state stack color space" do
|
115
|
+
create_pdf
|
116
|
+
starting_color_space = @pdf.state.page.graphic_state.color_space.dup
|
117
|
+
@pdf.repeat :all do
|
118
|
+
@pdf.text "Testing", :size => 24, :style => :bold
|
119
|
+
end
|
120
|
+
@pdf.state.page.graphic_state.color_space.should == starting_color_space
|
121
|
+
end
|
122
|
+
|
123
|
+
context "dynamic repeaters" do
|
124
|
+
|
125
|
+
it "should preserve the graphic state at creation time" do
|
126
|
+
create_pdf
|
127
|
+
@pdf.repeat :all, :dynamic => true do
|
128
|
+
@pdf.text "fill_color: #{@pdf.graphic_state.fill_color}"
|
129
|
+
@pdf.text "cap_style: #{@pdf.graphic_state.cap_style}"
|
130
|
+
end
|
131
|
+
@pdf.fill_color "666666"
|
132
|
+
@pdf.cap_style :round
|
133
|
+
text = PDF::Inspector::Text.analyze(@pdf.render)
|
134
|
+
text.strings.include?("fill_color: 666666").should == false
|
135
|
+
text.strings.include?("fill_color: 000000").should == true
|
136
|
+
text.strings.include?("cap_style: round").should == false
|
137
|
+
text.strings.include?("cap_style: butt").should == true
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
96
144
|
end
|
data/spec/security_spec.rb
CHANGED
@@ -66,6 +66,12 @@ describe "Document encryption" do
|
|
66
66
|
should == 0b1111_1111_1111_1111_1111_1111_1101_1111
|
67
67
|
end
|
68
68
|
|
69
|
+
it "should raise ArgumentError if invalid option is provided" do
|
70
|
+
lambda {
|
71
|
+
doc_with_permissions(:modify_document => false)
|
72
|
+
}.should.raise(ArgumentError)
|
73
|
+
end
|
74
|
+
|
69
75
|
end
|
70
76
|
|
71
77
|
describe "Encryption keys" do
|
data/spec/spec_helper.rb
CHANGED
@@ -3,24 +3,28 @@
|
|
3
3
|
puts "Prawn specs: Running on Ruby Version: #{RUBY_VERSION}"
|
4
4
|
|
5
5
|
require "rubygems"
|
6
|
+
require "bundler"
|
7
|
+
Bundler.setup
|
8
|
+
|
6
9
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
7
|
-
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'vendor',
|
8
|
-
'pdf-inspector','lib')
|
9
10
|
require "prawn"
|
10
11
|
|
11
12
|
Prawn.debug = true
|
12
13
|
|
13
|
-
ruby_19 do
|
14
|
-
gem "test-unit", "=1.2.3"
|
15
|
-
end
|
16
14
|
require "test/spec"
|
17
15
|
require "mocha"
|
18
|
-
|
19
|
-
gem 'pdf-reader', ">=0.8"
|
20
|
-
require "pdf/reader"
|
16
|
+
require "pdf/reader"
|
21
17
|
require "pdf/inspector"
|
22
18
|
|
23
19
|
def create_pdf(klass=Prawn::Document)
|
24
20
|
@pdf = klass.new(:margin => 0)
|
25
21
|
end
|
26
22
|
|
23
|
+
# Make some methods public to assist in testing
|
24
|
+
module Prawn::Graphics
|
25
|
+
public :map_to_absolute
|
26
|
+
end
|
27
|
+
|
28
|
+
require File.expand_path(File.join(File.dirname(__FILE__),
|
29
|
+
%w[extensions mocha]))
|
30
|
+
|
data/spec/stamp_spec.rb
CHANGED
@@ -88,7 +88,7 @@ describe "Document with a stamp" do
|
|
88
88
|
"stamp XObject, not the page" do
|
89
89
|
create_pdf
|
90
90
|
@pdf.create_stamp("MyStamp") do
|
91
|
-
@pdf.transparent(0.5) { @pdf.
|
91
|
+
@pdf.transparent(0.5) { @pdf.circle([100, 100], 10)}
|
92
92
|
end
|
93
93
|
@pdf.stamp("MyStamp")
|
94
94
|
|
@@ -105,4 +105,55 @@ describe "Document with a stamp" do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
108
|
+
|
109
|
+
it "stamp stream should be wrapped in a graphic state" do
|
110
|
+
create_pdf
|
111
|
+
@pdf.create_stamp("MyStamp") do
|
112
|
+
@pdf.text "This should have a 'q' before it and a 'Q' after it"
|
113
|
+
end
|
114
|
+
@pdf.stamp("MyStamp")
|
115
|
+
stamps = PDF::Inspector::XObject.analyze(@pdf.render)
|
116
|
+
stamps.xobject_streams[:Stamp1].data.chomp.should =~ /q(.|\s)*Q\Z/
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should not add to the page graphic state stack " do
|
120
|
+
create_pdf
|
121
|
+
@pdf.state.page.stack.stack.size.should == 1
|
122
|
+
|
123
|
+
@pdf.create_stamp("MyStamp") do
|
124
|
+
@pdf.save_graphics_state
|
125
|
+
@pdf.save_graphics_state
|
126
|
+
@pdf.save_graphics_state
|
127
|
+
@pdf.text "This should have a 'q' before it and a 'Q' after it"
|
128
|
+
@pdf.restore_graphics_state
|
129
|
+
end
|
130
|
+
@pdf.state.page.stack.stack.size.should == 1
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should be able to change fill and stroke colors within the stamp stream" do
|
134
|
+
create_pdf
|
135
|
+
@pdf.create_stamp("MyStamp") do
|
136
|
+
@pdf.fill_color(100, 100, 20, 0)
|
137
|
+
@pdf.stroke_color(100, 100, 20, 0)
|
138
|
+
end
|
139
|
+
@pdf.stamp("MyStamp")
|
140
|
+
stamps = PDF::Inspector::XObject.analyze(@pdf.render)
|
141
|
+
stamp_stream = stamps.xobject_streams[:Stamp1].data
|
142
|
+
stamp_stream.should.include "/DeviceCMYK cs\n1.000 1.000 0.200 0.000 scn"
|
143
|
+
stamp_stream.should.include "/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN"
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should save the color space even when same as current page color space" do
|
147
|
+
create_pdf
|
148
|
+
@pdf.stroke_color(100, 100, 20, 0)
|
149
|
+
@pdf.create_stamp("MyStamp") do
|
150
|
+
@pdf.stroke_color(100, 100, 20, 0)
|
151
|
+
end
|
152
|
+
@pdf.stamp("MyStamp")
|
153
|
+
stamps = PDF::Inspector::XObject.analyze(@pdf.render)
|
154
|
+
stamp_stream = stamps.xobject_streams[:Stamp1].data
|
155
|
+
stamp_stream.should.include "/DeviceCMYK CS\n1.000 1.000 0.200 0.000 SCN"
|
156
|
+
end
|
157
|
+
|
158
|
+
|
108
159
|
end
|
data/spec/stroke_styles_spec.rb
CHANGED
@@ -159,5 +159,35 @@ describe "Dashes" do
|
|
159
159
|
dashes.stroke_dash_count.should == 2
|
160
160
|
dashes.stroke_dash.should == [[2, 2], 0]
|
161
161
|
end
|
162
|
+
|
163
|
+
describe "#dashed?" do
|
164
|
+
|
165
|
+
it "an initial document should not be dashed" do
|
166
|
+
@pdf.dashed?.should == false
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should return true if any of the currently active settings are dashed" do
|
170
|
+
@pdf.dash(2)
|
171
|
+
@pdf.save_graphics_state
|
172
|
+
@pdf.dashed?.should == true
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should return false if the document was most recently undashed" do
|
176
|
+
@pdf.dash(2)
|
177
|
+
@pdf.save_graphics_state
|
178
|
+
@pdf.undash
|
179
|
+
@pdf.save_graphics_state
|
180
|
+
@pdf.dashed?.should == false
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should return true when restoring to a state that was dashed" do
|
184
|
+
@pdf.dash(2)
|
185
|
+
@pdf.save_graphics_state
|
186
|
+
@pdf.undash
|
187
|
+
@pdf.restore_graphics_state
|
188
|
+
@pdf.dashed?.should == true
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
162
192
|
|
163
193
|
end
|
data/spec/table_spec.rb
CHANGED
@@ -32,6 +32,10 @@ describe "Prawn::Table" do
|
|
32
32
|
}.should.not.raise
|
33
33
|
end
|
34
34
|
|
35
|
+
it "should allow a table with a header but no body" do
|
36
|
+
lambda { @pdf.table([["Header"]], :header => true) }.should.not.raise
|
37
|
+
end
|
38
|
+
|
35
39
|
# TODO: pending colspan
|
36
40
|
xit "should accurately count columns from data" do
|
37
41
|
# First data row may contain colspan which would hide true column count
|
@@ -99,6 +103,15 @@ describe "Prawn::Table" do
|
|
99
103
|
Set.new(%w[R0C0 R0C1 R1C0 R1C1])
|
100
104
|
end
|
101
105
|
|
106
|
+
it "should allow negative row selectors" do
|
107
|
+
Set.new(@table.row(-1).map { |c| c.content }).should ==
|
108
|
+
Set.new(%w[R1C0 R1C1])
|
109
|
+
Set.new(@table.rows(-2..-1).map { |c| c.content }).should ==
|
110
|
+
Set.new(%w[R0C0 R0C1 R1C0 R1C1])
|
111
|
+
Set.new(@table.rows(0..-1).map { |c| c.content }).should ==
|
112
|
+
Set.new(%w[R0C0 R0C1 R1C0 R1C1])
|
113
|
+
end
|
114
|
+
|
102
115
|
it "should select columns by number or range" do
|
103
116
|
Set.new(@table.column(0).map { |c| c.content }).should ==
|
104
117
|
Set.new(%w[R0C0 R1C0])
|
@@ -106,6 +119,15 @@ describe "Prawn::Table" do
|
|
106
119
|
Set.new(%w[R0C0 R0C1 R1C0 R1C1])
|
107
120
|
end
|
108
121
|
|
122
|
+
it "should allow negative column selectors" do
|
123
|
+
Set.new(@table.column(-1).map { |c| c.content }).should ==
|
124
|
+
Set.new(%w[R0C1 R1C1])
|
125
|
+
Set.new(@table.columns(-2..-1).map { |c| c.content }).should ==
|
126
|
+
Set.new(%w[R0C0 R0C1 R1C0 R1C1])
|
127
|
+
Set.new(@table.columns(0..-1).map { |c| c.content }).should ==
|
128
|
+
Set.new(%w[R0C0 R0C1 R1C0 R1C1])
|
129
|
+
end
|
130
|
+
|
109
131
|
it "should allow rows and columns to be combined" do
|
110
132
|
@table.row(0).column(1).map { |c| c.content }.should == ["R0C1"]
|
111
133
|
end
|
@@ -137,6 +159,11 @@ describe "Prawn::Table" do
|
|
137
159
|
@table.cells[1, 0].width.should == 100
|
138
160
|
end
|
139
161
|
|
162
|
+
it "style method should accept a block, passing each cell to be styled" do
|
163
|
+
@table.cells.style { |c| c.height = 200 }
|
164
|
+
@table.cells[0, 1].height.should == 200
|
165
|
+
end
|
166
|
+
|
140
167
|
it "should return the width of selected columns for #width" do
|
141
168
|
c0_width = @table.column(0).map{ |c| c.width }.max
|
142
169
|
c1_width = @table.column(1).map{ |c| c.width }.max
|
@@ -293,6 +320,16 @@ describe "Prawn::Table" do
|
|
293
320
|
@table.column(0).width.should == @table.column(2).width
|
294
321
|
end
|
295
322
|
|
323
|
+
it "should allow table cells to be resized in block" do
|
324
|
+
lambda do
|
325
|
+
@pdf.table([%w[1 2 3 4 5]]) do |t|
|
326
|
+
t.width = 40
|
327
|
+
t.cells.size = 8
|
328
|
+
t.cells.padding = 0
|
329
|
+
end
|
330
|
+
end.should.not.raise(Prawn::Errors::CannotFit)
|
331
|
+
end
|
332
|
+
|
296
333
|
it "should be the width of the :width parameter" do
|
297
334
|
expected_width = 300
|
298
335
|
table = Prawn::Table.new( [%w[snake foo b apple],
|
@@ -378,10 +415,11 @@ describe "Prawn::Table" do
|
|
378
415
|
|
379
416
|
table_height = origin - @pdf.y
|
380
417
|
font_height = @pdf.font.height
|
418
|
+
line_gap = @pdf.font.line_gap
|
381
419
|
|
382
420
|
num_rows = data.length
|
383
421
|
table_height.should.be.close(
|
384
|
-
num_rows*font_height + 2*vpad*num_rows, 0.001 )
|
422
|
+
num_rows * font_height + 2*vpad*num_rows, 0.001 )
|
385
423
|
end
|
386
424
|
|
387
425
|
end
|
@@ -392,7 +430,7 @@ describe "Prawn::Table" do
|
|
392
430
|
it "should flow to the next page when hitting the bottom of the bounds" do
|
393
431
|
Prawn::Document.new { table([["foo"]] * 30) }.page_count.should == 1
|
394
432
|
Prawn::Document.new { table([["foo"]] * 31) }.page_count.should == 2
|
395
|
-
Prawn::Document.new { table([["foo"]] * 31); table([["foo"]] *
|
433
|
+
Prawn::Document.new { table([["foo"]] * 31); table([["foo"]] * 35) }.
|
396
434
|
page_count.should == 3
|
397
435
|
end
|
398
436
|
|
@@ -403,6 +441,50 @@ describe "Prawn::Table" do
|
|
403
441
|
end
|
404
442
|
end.page_count.should == 2
|
405
443
|
end
|
444
|
+
|
445
|
+
it "should not start a new page before finishing out a row" do
|
446
|
+
Prawn::Document.new do
|
447
|
+
table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]])
|
448
|
+
end.page_count.should == 1
|
449
|
+
end
|
450
|
+
|
451
|
+
it "should only start new page on long cells if it would gain us height" do
|
452
|
+
Prawn::Document.new do
|
453
|
+
text "Hello"
|
454
|
+
table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]])
|
455
|
+
end.page_count.should == 2
|
456
|
+
end
|
457
|
+
|
458
|
+
it "should not start a new page to gain height when at the top of " +
|
459
|
+
"a bounding box, even if stretchy" do
|
460
|
+
Prawn::Document.new do
|
461
|
+
bounding_box([bounds.left, bounds.top - 20], :width => 400) do
|
462
|
+
table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]])
|
463
|
+
end
|
464
|
+
end.page_count.should == 1
|
465
|
+
end
|
466
|
+
|
467
|
+
it "should still break to the next page if in a stretchy bounding box " +
|
468
|
+
"but not at the top" do
|
469
|
+
Prawn::Document.new do
|
470
|
+
bounding_box([bounds.left, bounds.top - 20], :width => 400) do
|
471
|
+
text "Hello"
|
472
|
+
table([[ (1..80).map{ |i| "Line #{i}" }.join("\n"), "Column 2" ]])
|
473
|
+
end
|
474
|
+
end.page_count.should == 2
|
475
|
+
end
|
476
|
+
|
477
|
+
it "should only draw first-page header if the first body row fits" do
|
478
|
+
pdf = Prawn::Document.new
|
479
|
+
|
480
|
+
pdf.y = 60 # not enough room for a table row
|
481
|
+
pdf.table [["Header"], ["Body"]], :header => true
|
482
|
+
|
483
|
+
output = PDF::Inspector::Page.analyze(pdf.render)
|
484
|
+
# Ensure we only drew the header once, on the second page
|
485
|
+
output.pages[0][:strings].should.be.empty
|
486
|
+
output.pages[1][:strings].should == ["Header", "Body"]
|
487
|
+
end
|
406
488
|
end
|
407
489
|
|
408
490
|
describe "#style" do
|
@@ -525,7 +607,7 @@ describe "Prawn::Table" do
|
|
525
607
|
end
|
526
608
|
|
527
609
|
it "should repeat headers across pages" do
|
528
|
-
data = [["foo","bar"]]*30
|
610
|
+
data = [["foo","bar"]] * 30
|
529
611
|
headers = ["baz","foobar"]
|
530
612
|
@pdf = Prawn::Document.new
|
531
613
|
@pdf.table([headers] + data, :header => true)
|
@@ -533,6 +615,14 @@ describe "Prawn::Table" do
|
|
533
615
|
output.strings.should == headers + data.flatten[0..-3] + headers +
|
534
616
|
data.flatten[-2..-1]
|
535
617
|
end
|
618
|
+
|
619
|
+
it "should not draw header twice when starting new page" do
|
620
|
+
@pdf = Prawn::Document.new
|
621
|
+
@pdf.y = 0
|
622
|
+
@pdf.table([["Header"], ["Body"]], :header => true)
|
623
|
+
output = PDF::Inspector::Text.analyze(@pdf.render)
|
624
|
+
output.strings.should == ["Header", "Body"]
|
625
|
+
end
|
536
626
|
end
|
537
627
|
|
538
628
|
describe "nested tables" do
|