prawn 1.0.0.rc2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +9 -0
- data/COPYING +2 -2
- data/Gemfile +8 -15
- data/LICENSE +1 -1
- data/Rakefile +25 -16
- data/data/images/16bit.alpha +0 -0
- data/data/images/16bit.color +0 -0
- data/data/images/dice.alpha +0 -0
- data/data/images/dice.color +0 -0
- data/data/images/indexed_color.dat +0 -0
- data/data/images/indexed_color.png +0 -0
- data/data/images/license.md +8 -0
- data/data/images/page_white_text.alpha +0 -0
- data/data/images/page_white_text.color +0 -0
- data/lib/prawn.rb +85 -23
- data/lib/prawn/document.rb +134 -116
- data/lib/prawn/document/bounding_box.rb +33 -4
- data/lib/prawn/document/column_box.rb +18 -6
- data/lib/prawn/document/graphics_state.rb +11 -74
- data/lib/prawn/document/internals.rb +24 -23
- data/lib/prawn/document/span.rb +12 -10
- data/lib/prawn/encoding.rb +8 -9
- data/lib/prawn/errors.rb +13 -32
- data/lib/prawn/font.rb +137 -105
- data/lib/prawn/font/afm.rb +76 -32
- data/lib/prawn/font/dfont.rb +4 -3
- data/lib/prawn/font/ttf.rb +33 -25
- data/lib/prawn/font_metric_cache.rb +47 -0
- data/lib/prawn/graphics.rb +177 -57
- data/lib/prawn/graphics/cap_style.rb +4 -3
- data/lib/prawn/graphics/color.rb +5 -4
- data/lib/prawn/graphics/dash.rb +53 -31
- data/lib/prawn/graphics/join_style.rb +9 -7
- data/lib/prawn/graphics/patterns.rb +4 -15
- data/lib/prawn/graphics/transformation.rb +10 -9
- data/lib/prawn/graphics/transparency.rb +3 -1
- data/lib/prawn/{layout/grid.rb → grid.rb} +72 -54
- data/lib/prawn/image_handler.rb +42 -0
- data/lib/prawn/images.rb +58 -54
- data/lib/prawn/images/image.rb +6 -22
- data/lib/prawn/images/jpg.rb +20 -14
- data/lib/prawn/images/png.rb +58 -121
- data/lib/prawn/layout.rb +12 -15
- data/lib/prawn/measurement_extensions.rb +10 -6
- data/lib/prawn/measurements.rb +27 -21
- data/lib/prawn/outline.rb +108 -147
- data/lib/prawn/repeater.rb +10 -8
- data/lib/prawn/security.rb +59 -40
- data/lib/prawn/security/arcfour.rb +52 -0
- data/lib/prawn/soft_mask.rb +4 -4
- data/lib/prawn/stamp.rb +5 -3
- data/lib/prawn/table.rb +83 -60
- data/lib/prawn/table/cell.rb +17 -21
- data/lib/prawn/table/cell/image.rb +2 -3
- data/lib/prawn/table/cell/in_table.rb +8 -2
- data/lib/prawn/table/cell/span_dummy.rb +5 -0
- data/lib/prawn/table/cell/subtable.rb +3 -2
- data/lib/prawn/table/cell/text.rb +14 -12
- data/lib/prawn/table/cells.rb +58 -14
- data/lib/prawn/table/column_width_calculator.rb +61 -0
- data/lib/prawn/text.rb +27 -26
- data/lib/prawn/text/box.rb +12 -6
- data/lib/prawn/text/formatted.rb +5 -4
- data/lib/prawn/text/formatted/arranger.rb +290 -0
- data/lib/prawn/text/formatted/box.rb +85 -57
- data/lib/prawn/text/formatted/fragment.rb +11 -11
- data/lib/prawn/text/formatted/line_wrap.rb +266 -0
- data/lib/prawn/text/formatted/parser.rb +11 -4
- data/lib/prawn/text/formatted/wrap.rb +156 -0
- data/lib/prawn/utilities.rb +5 -3
- data/manual/document_and_page_options/document_and_page_options.rb +2 -1
- data/manual/document_and_page_options/metadata.rb +3 -3
- data/manual/document_and_page_options/page_size.rb +2 -2
- data/manual/document_and_page_options/print_scaling.rb +20 -0
- data/manual/example_file.rb +2 -7
- data/manual/example_helper.rb +62 -81
- data/manual/graphics/common_lines.rb +2 -0
- data/manual/graphics/helper.rb +11 -4
- data/manual/graphics/stroke_dash.rb +19 -14
- data/manual/manual/cover.rb +16 -0
- data/manual/manual/manual.rb +1 -5
- data/manual/text/fallback_fonts.rb +4 -4
- data/manual/text/formatted_text.rb +5 -5
- data/manual/text/inline.rb +2 -4
- data/manual/text/registering_families.rb +12 -12
- data/manual/text/single_usage.rb +4 -4
- data/manual/text/text.rb +0 -2
- data/prawn.gemspec +21 -13
- data/spec/acceptance/png.rb +23 -0
- data/spec/annotations_spec.rb +16 -32
- data/spec/bounding_box_spec.rb +22 -5
- data/spec/cell_spec.rb +49 -5
- data/spec/column_box_spec.rb +32 -0
- data/spec/destinations_spec.rb +5 -5
- data/spec/document_spec.rb +112 -118
- data/spec/extensions/encoding_helpers.rb +5 -2
- data/spec/font_metric_cache_spec.rb +52 -0
- data/spec/font_spec.rb +121 -120
- data/spec/formatted_text_arranger_spec.rb +24 -24
- data/spec/formatted_text_box_spec.rb +31 -32
- data/spec/formatted_text_fragment_spec.rb +2 -2
- data/spec/graphics_spec.rb +63 -45
- data/spec/grid_spec.rb +24 -13
- data/spec/image_handler_spec.rb +54 -0
- data/spec/images_spec.rb +34 -21
- data/spec/inline_formatted_text_parser_spec.rb +69 -20
- data/spec/jpg_spec.rb +3 -3
- data/spec/line_wrap_spec.rb +25 -14
- data/spec/measurement_units_spec.rb +5 -5
- data/spec/outline_spec.rb +68 -64
- data/spec/png_spec.rb +15 -18
- data/spec/reference_spec.rb +2 -82
- data/spec/repeater_spec.rb +1 -1
- data/spec/security_spec.rb +41 -9
- data/spec/soft_mask_spec.rb +0 -40
- data/spec/span_spec.rb +6 -11
- data/spec/spec_helper.rb +20 -2
- data/spec/stamp_spec.rb +19 -20
- data/spec/stroke_styles_spec.rb +31 -13
- data/spec/table/span_dummy_spec.rb +17 -0
- data/spec/table_spec.rb +268 -43
- data/spec/text_at_spec.rb +13 -27
- data/spec/text_box_spec.rb +35 -30
- data/spec/text_spec.rb +56 -40
- data/spec/transparency_spec.rb +5 -5
- metadata +214 -217
- data/README.md +0 -98
- data/data/fonts/Action Man.dfont +0 -0
- data/data/fonts/Activa.ttf +0 -0
- data/data/fonts/Chalkboard.ttf +0 -0
- data/data/fonts/DejaVuSans.ttf +0 -0
- data/data/fonts/Dustismo_Roman.ttf +0 -0
- data/data/fonts/comicsans.ttf +0 -0
- data/data/fonts/gkai00mp.ttf +0 -0
- data/data/images/16bit.dat +0 -0
- data/data/images/barcode_issue.png +0 -0
- data/data/images/dice.dat +0 -0
- data/data/images/page_white_text.dat +0 -0
- data/data/images/rails.dat +0 -0
- data/data/images/rails.png +0 -0
- data/lib/prawn/compatibility.rb +0 -87
- data/lib/prawn/core.rb +0 -87
- data/lib/prawn/core/annotations.rb +0 -61
- data/lib/prawn/core/byte_string.rb +0 -9
- data/lib/prawn/core/destinations.rb +0 -90
- data/lib/prawn/core/document_state.rb +0 -79
- data/lib/prawn/core/literal_string.rb +0 -16
- data/lib/prawn/core/name_tree.rb +0 -177
- data/lib/prawn/core/object_store.rb +0 -320
- data/lib/prawn/core/page.rb +0 -212
- data/lib/prawn/core/pdf_object.rb +0 -125
- data/lib/prawn/core/reference.rb +0 -119
- data/lib/prawn/core/text.rb +0 -268
- data/lib/prawn/core/text/formatted/arranger.rb +0 -294
- data/lib/prawn/core/text/formatted/line_wrap.rb +0 -288
- data/lib/prawn/core/text/formatted/wrap.rb +0 -153
- data/lib/prawn/document/page_geometry.rb +0 -136
- data/lib/prawn/document/snapshot.rb +0 -89
- data/manual/manual/foreword.rb +0 -13
- data/manual/templates/full_template.rb +0 -23
- data/manual/templates/page_template.rb +0 -47
- data/manual/templates/templates.rb +0 -26
- data/manual/text/group.rb +0 -29
- data/spec/name_tree_spec.rb +0 -112
- data/spec/object_store_spec.rb +0 -170
- data/spec/pdf_object_spec.rb +0 -172
- data/spec/snapshot_spec.rb +0 -186
- data/spec/template_spec.rb +0 -351
@@ -5,7 +5,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
|
|
5
5
|
describe "Core::Text::Formatted::Arranger#format_array" do
|
6
6
|
it "should populate unconsumed array" do
|
7
7
|
create_pdf
|
8
|
-
arranger = Prawn::
|
8
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
9
9
|
array = [{ :text => "hello " },
|
10
10
|
{ :text => "world how ", :styles => [:bold] },
|
11
11
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -20,7 +20,7 @@ describe "Core::Text::Formatted::Arranger#format_array" do
|
|
20
20
|
end
|
21
21
|
it "should split newlines into their own elements" do
|
22
22
|
create_pdf
|
23
|
-
arranger = Prawn::
|
23
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
24
24
|
array = [{ :text => "\nhello\nworld" }]
|
25
25
|
arranger.format_array = array
|
26
26
|
arranger.unconsumed[0].should == { :text => "\n" }
|
@@ -32,7 +32,7 @@ end
|
|
32
32
|
describe "Core::Text::Formatted::Arranger#preview_next_string" do
|
33
33
|
it "should not populate the consumed array" do
|
34
34
|
create_pdf
|
35
|
-
arranger = Prawn::
|
35
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
36
36
|
array = [{ :text => "hello" }]
|
37
37
|
arranger.format_array = array
|
38
38
|
arranger.preview_next_string
|
@@ -40,7 +40,7 @@ describe "Core::Text::Formatted::Arranger#preview_next_string" do
|
|
40
40
|
end
|
41
41
|
it "should not consumed array" do
|
42
42
|
create_pdf
|
43
|
-
arranger = Prawn::
|
43
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
44
44
|
array = [{ :text => "hello" }]
|
45
45
|
arranger.format_array = array
|
46
46
|
arranger.preview_next_string.should == "hello"
|
@@ -49,7 +49,7 @@ end
|
|
49
49
|
describe "Core::Text::Formatted::Arranger#next_string" do
|
50
50
|
before(:each) do
|
51
51
|
create_pdf
|
52
|
-
@arranger = Prawn::
|
52
|
+
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
53
53
|
array = [{ :text => "hello " },
|
54
54
|
{ :text => "world how ", :styles => [:bold] },
|
55
55
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -75,7 +75,7 @@ describe "Core::Text::Formatted::Arranger#next_string" do
|
|
75
75
|
end
|
76
76
|
it "should populate current_format_state array" do
|
77
77
|
create_pdf
|
78
|
-
arranger = Prawn::
|
78
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
79
79
|
array = [{ :text => "hello " },
|
80
80
|
{ :text => "world how ", :styles => [:bold] },
|
81
81
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -101,7 +101,7 @@ end
|
|
101
101
|
describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
|
102
102
|
it "should raise_error an error if called before finalize_line was called" do
|
103
103
|
create_pdf
|
104
|
-
arranger = Prawn::
|
104
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
105
105
|
array = [{ :text => "hello " },
|
106
106
|
{ :text => "world how ", :styles => [:bold] },
|
107
107
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -116,7 +116,7 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
|
|
116
116
|
it "should return the consumed fragments in order of consumption" +
|
117
117
|
" and update" do
|
118
118
|
create_pdf
|
119
|
-
arranger = Prawn::
|
119
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
120
120
|
array = [{ :text => "hello " },
|
121
121
|
{ :text => "world how ", :styles => [:bold] },
|
122
122
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -132,7 +132,7 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
|
|
132
132
|
end
|
133
133
|
it "should never return a fragment whose text is an empty string" do
|
134
134
|
create_pdf
|
135
|
-
arranger = Prawn::
|
135
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
136
136
|
array = [{ :text => "hello\nworld\n\n\nhow are you?" },
|
137
137
|
{ :text => "\n" },
|
138
138
|
{ :text => "\n" },
|
@@ -152,7 +152,7 @@ describe "Core::Text::Formatted::Arranger#retrieve_fragment" do
|
|
152
152
|
end
|
153
153
|
it "should not alter the current font style" do
|
154
154
|
create_pdf
|
155
|
-
arranger = Prawn::
|
155
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
156
156
|
array = [{ :text => "hello " },
|
157
157
|
{ :text => "world how ", :styles => [:bold] },
|
158
158
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -170,7 +170,7 @@ describe "Core::Text::Formatted::Arranger#update_last_string" do
|
|
170
170
|
it "should update the last retrieved string with what actually fit on" +
|
171
171
|
"the line and the list of unconsumed with what did not" do
|
172
172
|
create_pdf
|
173
|
-
arranger = Prawn::
|
173
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
174
174
|
array = [{ :text => "hello " },
|
175
175
|
{ :text => "world how ", :styles => [:bold] },
|
176
176
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -186,7 +186,7 @@ describe "Core::Text::Formatted::Arranger#update_last_string" do
|
|
186
186
|
end
|
187
187
|
it "should set the format state to the previously processed fragment" do
|
188
188
|
create_pdf
|
189
|
-
arranger = Prawn::
|
189
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
190
190
|
array = [{ :text => "hello " },
|
191
191
|
{ :text => "world how ", :styles => [:bold] },
|
192
192
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -201,7 +201,7 @@ describe "Core::Text::Formatted::Arranger#update_last_string" do
|
|
201
201
|
context "when the entire string was used" do
|
202
202
|
it "should not push empty string onto unconsumed" do
|
203
203
|
create_pdf
|
204
|
-
arranger = Prawn::
|
204
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
205
205
|
array = [{ :text => "hello " },
|
206
206
|
{ :text => "world how ", :styles => [:bold] },
|
207
207
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -217,7 +217,7 @@ end
|
|
217
217
|
describe "Core::Text::Formatted::Arranger#space_count" do
|
218
218
|
before(:each) do
|
219
219
|
create_pdf
|
220
|
-
@arranger = Prawn::
|
220
|
+
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
221
221
|
array = [{ :text => "hello " },
|
222
222
|
{ :text => "world how ", :styles => [:bold] },
|
223
223
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -240,7 +240,7 @@ describe "Core::Text::Formatted::Arranger#finalize_line" do
|
|
240
240
|
it "should make it so that all trailing white space fragments " +
|
241
241
|
"exclude trailing white space" do
|
242
242
|
create_pdf
|
243
|
-
arranger = Prawn::
|
243
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
244
244
|
array = [{ :text => "hello " },
|
245
245
|
{ :text => "world how ", :styles => [:bold] },
|
246
246
|
{ :text => " ", :styles => [:bold, :italic] }]
|
@@ -264,7 +264,7 @@ end
|
|
264
264
|
describe "Core::Text::Formatted::Arranger#line_width" do
|
265
265
|
before(:each) do
|
266
266
|
create_pdf
|
267
|
-
@arranger = Prawn::
|
267
|
+
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
268
268
|
array = [{ :text => "hello " },
|
269
269
|
{ :text => "world", :styles => [:bold] }]
|
270
270
|
@arranger.format_array = array
|
@@ -285,7 +285,7 @@ end
|
|
285
285
|
describe "Core::Text::Formatted::Arranger#line_width with character_spacing > 0" do
|
286
286
|
it "should return a width greater than a line without a character_spacing" do
|
287
287
|
create_pdf
|
288
|
-
arranger = Prawn::
|
288
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
289
289
|
|
290
290
|
array = [{ :text => "hello " },
|
291
291
|
{ :text => "world", :styles => [:bold] }]
|
@@ -311,7 +311,7 @@ end
|
|
311
311
|
describe "Core::Text::Formatted::Arranger#line" do
|
312
312
|
before(:each) do
|
313
313
|
create_pdf
|
314
|
-
@arranger = Prawn::
|
314
|
+
@arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
315
315
|
array = [{ :text => "hello " },
|
316
316
|
{ :text => "world", :styles => [:bold] }]
|
317
317
|
@arranger.format_array = array
|
@@ -332,7 +332,7 @@ end
|
|
332
332
|
describe "Core::Text::Formatted::Arranger#unconsumed" do
|
333
333
|
it "should return the original array if nothing was consumed" do
|
334
334
|
create_pdf
|
335
|
-
arranger = Prawn::
|
335
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
336
336
|
array = [{ :text => "hello " },
|
337
337
|
{ :text => "world how ", :styles => [:bold] },
|
338
338
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -342,7 +342,7 @@ describe "Core::Text::Formatted::Arranger#unconsumed" do
|
|
342
342
|
end
|
343
343
|
it "should return an empty array if everything was consumed" do
|
344
344
|
create_pdf
|
345
|
-
arranger = Prawn::
|
345
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
346
346
|
array = [{ :text => "hello " },
|
347
347
|
{ :text => "world how ", :styles => [:bold] },
|
348
348
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -357,7 +357,7 @@ end
|
|
357
357
|
describe "Core::Text::Formatted::Arranger#finished" do
|
358
358
|
it "should be_false if anything was not printed" do
|
359
359
|
create_pdf
|
360
|
-
arranger = Prawn::
|
360
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
361
361
|
array = [{ :text => "hello " },
|
362
362
|
{ :text => "world how ", :styles => [:bold] },
|
363
363
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -370,7 +370,7 @@ describe "Core::Text::Formatted::Arranger#finished" do
|
|
370
370
|
end
|
371
371
|
it "should be_false if everything was printed" do
|
372
372
|
create_pdf
|
373
|
-
arranger = Prawn::
|
373
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
374
374
|
array = [{ :text => "hello " },
|
375
375
|
{ :text => "world how ", :styles => [:bold] },
|
376
376
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -385,7 +385,7 @@ end
|
|
385
385
|
describe "Core::Text::Formatted::Arranger.max_line_height" do
|
386
386
|
it "should be the height of the maximum consumed fragment" do
|
387
387
|
create_pdf
|
388
|
-
arranger = Prawn::
|
388
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
389
389
|
array = [{ :text => "hello " },
|
390
390
|
{ :text => "world how ", :styles => [:bold] },
|
391
391
|
{ :text => "are", :styles => [:bold, :italic],
|
@@ -402,7 +402,7 @@ end
|
|
402
402
|
describe "Core::Text::Formatted::Arranger#repack_unretrieved" do
|
403
403
|
it "should restore part of the original string" do
|
404
404
|
create_pdf
|
405
|
-
arranger = Prawn::
|
405
|
+
arranger = Prawn::Text::Formatted::Arranger.new(@pdf)
|
406
406
|
array = [{ :text => "hello " },
|
407
407
|
{ :text => "world how ", :styles => [:bold] },
|
408
408
|
{ :text => "are", :styles => [:bold, :italic] },
|
@@ -18,22 +18,19 @@ describe "Text::Formatted::Box wrapping" do
|
|
18
18
|
text_box.text.should == "Hello\nWorld2"
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
21
|
+
it "should not raise an Encoding::CompatibilityError when keeping a TTF and an " +
|
22
22
|
"AFM font together" do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
text_box.render
|
35
|
-
}.should_not raise_error(Encoding::CompatibilityError)
|
36
|
-
end
|
23
|
+
file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
|
24
|
+
@pdf.font_families["Kai"] = {
|
25
|
+
:normal => { :file => file, :font => "Kai" }
|
26
|
+
}
|
27
|
+
|
28
|
+
texts = [{ :text => "Hello " },
|
29
|
+
{ :text => "再见", :font => "Kai"},
|
30
|
+
{ :text => "World" }]
|
31
|
+
text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
|
32
|
+
|
33
|
+
text_box.render
|
37
34
|
end
|
38
35
|
|
39
36
|
it "should wrap between two fragments when the preceding fragment ends with white space" do
|
@@ -84,26 +81,17 @@ describe "Text::Formatted::Box wrapping" do
|
|
84
81
|
}.should_not raise_error
|
85
82
|
text_box.text.should == "Noua Delineatio Geographica\ngeneralis | Apostolicarum\nperegrinationum | S FRANCISCI\nXAUERII | Indiarum & Iaponi\346\nApostoli"
|
86
83
|
end
|
87
|
-
|
84
|
+
|
88
85
|
describe "Unicode" do
|
89
86
|
before do
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
else
|
94
|
-
@reset_value = [Encoding.default_external, Encoding.default_internal]
|
95
|
-
Encoding.default_external = Encoding::UTF_8
|
96
|
-
Encoding.default_internal = Encoding::UTF_8
|
97
|
-
end
|
87
|
+
@reset_value = [Encoding.default_external, Encoding.default_internal]
|
88
|
+
Encoding.default_external = Encoding::UTF_8
|
89
|
+
Encoding.default_internal = Encoding::UTF_8
|
98
90
|
end
|
99
|
-
|
91
|
+
|
100
92
|
after do
|
101
|
-
|
102
|
-
|
103
|
-
else
|
104
|
-
Encoding.default_external = @reset_value[0]
|
105
|
-
Encoding.default_internal = @reset_value[1]
|
106
|
-
end
|
93
|
+
Encoding.default_external = @reset_value[0]
|
94
|
+
Encoding.default_internal = @reset_value[1]
|
107
95
|
end
|
108
96
|
|
109
97
|
it "should properly handle empty slices using Unicode encoding" do
|
@@ -397,7 +385,8 @@ describe "Text::Formatted::Box#render" do
|
|
397
385
|
{ :text => "callback now",
|
398
386
|
:callback => [behind, in_front] }]
|
399
387
|
text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
|
400
|
-
|
388
|
+
|
389
|
+
text_box.render # trigger callbacks
|
401
390
|
end
|
402
391
|
it "should be able to set the font" do
|
403
392
|
create_pdf
|
@@ -512,6 +501,16 @@ describe "Text::Formatted::Box#render" do
|
|
512
501
|
text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
|
513
502
|
text_box.render
|
514
503
|
end
|
504
|
+
it "should be able to add local actions" do
|
505
|
+
create_pdf
|
506
|
+
@pdf.expects(:link_annotation).with(kind_of(Array), :Border => [0,0,0],
|
507
|
+
:A => { :Type => :Action, :S => :Launch, :F => "../example.pdf", :NewWindow => true })
|
508
|
+
array = [{ :text => "click " },
|
509
|
+
{ :text => "here", :local => "../example.pdf" },
|
510
|
+
{ :text => " to open a local file" }]
|
511
|
+
text_box = Prawn::Text::Formatted::Box.new(array, :document => @pdf)
|
512
|
+
text_box.render
|
513
|
+
end
|
515
514
|
it "should be able to set font size" do
|
516
515
|
create_pdf
|
517
516
|
array = [{ :text => "this contains " },
|
@@ -75,7 +75,7 @@ describe "Text::Formatted::Fragment#word_spacing=" do
|
|
75
75
|
@fragment.ascender = 17
|
76
76
|
@fragment.word_spacing = 10
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
it "should account for word_spacing in #width" do
|
80
80
|
@fragment.width.should == 110
|
81
81
|
end
|
@@ -122,7 +122,7 @@ describe "Text::Formatted::Fragment" do
|
|
122
122
|
@fragment.descender = 7
|
123
123
|
@fragment.ascender = 17
|
124
124
|
end
|
125
|
-
|
125
|
+
|
126
126
|
describe "#width" do
|
127
127
|
it "should return the width" do
|
128
128
|
@fragment.width.should == 100
|
data/spec/graphics_spec.rb
CHANGED
@@ -121,7 +121,7 @@ describe "When drawing a curve" do
|
|
121
121
|
curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
122
122
|
curve.coords.should == [100.0, 100.0, 20.0, 90.0, 90.0, 75.0, 50.0, 50.0]
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
|
126
126
|
end
|
127
127
|
|
@@ -141,19 +141,19 @@ describe "When drawing a rounded rectangle" do
|
|
141
141
|
line_points.zip(curves).flatten.each_slice(2) {|p| @all_coords << p }
|
142
142
|
@all_coords.unshift @original_point
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
it "should draw a rectangle by connecting lines with rounded bezier curves" do
|
146
|
-
@all_coords.should == [[60.0, 550.0],[90.0, 550.0], [95.523, 550.0], [100.0, 545.523], [100.0, 540.0],
|
147
|
-
[100.0, 460.0], [100.0, 454.477], [95.523, 450.0], [90.0, 450.0],
|
148
|
-
[60.0, 450.0], [54.477, 450.0], [50.0, 454.477], [50.0, 460.0],
|
146
|
+
@all_coords.should == [[60.0, 550.0],[90.0, 550.0], [95.523, 550.0], [100.0, 545.523], [100.0, 540.0],
|
147
|
+
[100.0, 460.0], [100.0, 454.477], [95.523, 450.0], [90.0, 450.0],
|
148
|
+
[60.0, 450.0], [54.477, 450.0], [50.0, 454.477], [50.0, 460.0],
|
149
149
|
[50.0, 540.0], [50.0, 545.523], [54.477, 550.0], [60.0, 550.0]]
|
150
150
|
end
|
151
|
-
|
151
|
+
|
152
152
|
it "should start and end with the same point" do
|
153
153
|
@original_point.should == @all_coords.last
|
154
154
|
end
|
155
|
-
|
156
|
-
|
155
|
+
|
156
|
+
|
157
157
|
end
|
158
158
|
|
159
159
|
describe "When drawing an ellipse" do
|
@@ -162,27 +162,27 @@ describe "When drawing an ellipse" do
|
|
162
162
|
@pdf.ellipse [100,100], 25, 50
|
163
163
|
@curve = PDF::Inspector::Graphics::Curve.analyze(@pdf.render)
|
164
164
|
end
|
165
|
-
|
165
|
+
|
166
166
|
it "should use a Bézier approximation" do
|
167
|
-
@curve.coords.should ==
|
167
|
+
@curve.coords.should ==
|
168
168
|
[125.0, 100.0,
|
169
169
|
|
170
170
|
125.0, 127.614,
|
171
171
|
113.807, 150,
|
172
172
|
100.0, 150.0,
|
173
|
-
|
173
|
+
|
174
174
|
86.193, 150.0,
|
175
175
|
75.0, 127.614,
|
176
176
|
75.0, 100.0,
|
177
|
-
|
177
|
+
|
178
178
|
75.0, 72.386,
|
179
179
|
86.193, 50.0,
|
180
180
|
100.0, 50.0,
|
181
|
-
|
181
|
+
|
182
182
|
113.807, 50.0,
|
183
183
|
125.0, 72.386,
|
184
184
|
125.0, 100.0,
|
185
|
-
|
185
|
+
|
186
186
|
100.0, 100.0]
|
187
187
|
end
|
188
188
|
|
@@ -268,7 +268,7 @@ describe "When setting colors" do
|
|
268
268
|
colors.fill_color.should == [0.8,1.0,0.0]
|
269
269
|
colors.stroke_color.should == [1.0,0.0,0.8]
|
270
270
|
end
|
271
|
-
|
271
|
+
|
272
272
|
it "should set the color space when setting colors on new pages to please fussy readers" do
|
273
273
|
@pdf.stroke_color "000000"
|
274
274
|
@pdf.stroke { @pdf.rectangle([10, 10], 10, 10) }
|
@@ -381,80 +381,80 @@ end
|
|
381
381
|
|
382
382
|
describe "When using graphics states" do
|
383
383
|
before(:each) { create_pdf }
|
384
|
-
|
384
|
+
|
385
385
|
it "should add the right content on save_graphics_state" do
|
386
386
|
@pdf.expects(:add_content).with('q')
|
387
|
-
|
387
|
+
|
388
388
|
@pdf.save_graphics_state
|
389
389
|
end
|
390
|
-
|
390
|
+
|
391
391
|
it "should add the right content on restore_graphics_state" do
|
392
392
|
@pdf.expects(:add_content).with('Q')
|
393
|
-
|
393
|
+
|
394
394
|
@pdf.restore_graphics_state
|
395
395
|
end
|
396
|
-
|
396
|
+
|
397
397
|
it "should save and restore when save_graphics_state is used with a block" do
|
398
398
|
state = sequence "state"
|
399
399
|
@pdf.expects(:add_content).with('q').in_sequence(state)
|
400
400
|
@pdf.expects(:foo).in_sequence(state)
|
401
401
|
@pdf.expects(:add_content).with('Q').in_sequence(state)
|
402
|
-
|
402
|
+
|
403
403
|
@pdf.save_graphics_state do
|
404
404
|
@pdf.foo
|
405
405
|
end
|
406
406
|
end
|
407
|
-
|
407
|
+
|
408
408
|
it "should add the previous color space when restoring to a graphic state with different color space" do
|
409
409
|
@pdf.stroke_color '000000'
|
410
410
|
@pdf.save_graphics_state
|
411
411
|
@pdf.stroke_color 0, 0, 0, 0
|
412
|
-
@pdf.restore_graphics_state
|
412
|
+
@pdf.restore_graphics_state
|
413
413
|
@pdf.stroke_color 0, 0, 100, 0
|
414
414
|
@pdf.graphic_state.color_space.should == {:stroke=>:DeviceCMYK}
|
415
415
|
colors = PDF::Inspector::Graphics::Color.analyze(@pdf.render)
|
416
416
|
colors.color_space.should == :DeviceCMYK
|
417
417
|
colors.stroke_color_space_count[:DeviceCMYK].should == 2
|
418
418
|
end
|
419
|
-
|
419
|
+
|
420
420
|
it "should use the correct dash setting after restoring and starting new page" do
|
421
421
|
@pdf.dash 5
|
422
422
|
@pdf.save_graphics_state
|
423
423
|
@pdf.dash 10
|
424
424
|
@pdf.graphic_state.dash[:dash].should == 10
|
425
|
-
@pdf.restore_graphics_state
|
425
|
+
@pdf.restore_graphics_state
|
426
426
|
@pdf.start_new_page
|
427
427
|
@pdf.graphic_state.dash[:dash].should == 5
|
428
428
|
end
|
429
|
-
|
429
|
+
|
430
430
|
it "the current graphic state should keep track of previous unchanged settings" do
|
431
431
|
@pdf.stroke_color '000000'
|
432
432
|
@pdf.save_graphics_state
|
433
433
|
@pdf.dash 5
|
434
434
|
@pdf.save_graphics_state
|
435
435
|
@pdf.cap_style :round
|
436
|
-
@pdf.save_graphics_state
|
436
|
+
@pdf.save_graphics_state
|
437
437
|
@pdf.fill_color 0, 0, 100, 0
|
438
438
|
@pdf.save_graphics_state
|
439
|
-
|
440
|
-
@pdf.graphic_state.stroke_color.should == "000000"
|
439
|
+
|
440
|
+
@pdf.graphic_state.stroke_color.should == "000000"
|
441
441
|
@pdf.graphic_state.join_style.should == :miter
|
442
|
-
@pdf.graphic_state.fill_color.should == [0, 0, 100, 0]
|
443
|
-
@pdf.graphic_state.cap_style.should == :round
|
444
|
-
@pdf.graphic_state.color_space.should == {:fill=>:DeviceCMYK, :stroke=>:DeviceRGB}
|
442
|
+
@pdf.graphic_state.fill_color.should == [0, 0, 100, 0]
|
443
|
+
@pdf.graphic_state.cap_style.should == :round
|
444
|
+
@pdf.graphic_state.color_space.should == {:fill=>:DeviceCMYK, :stroke=>:DeviceRGB}
|
445
445
|
@pdf.graphic_state.dash.should == {:space=>5, :phase=>0, :dash=>5}
|
446
446
|
@pdf.graphic_state.line_width.should == 1
|
447
447
|
end
|
448
|
-
|
449
|
-
|
450
|
-
|
448
|
+
|
449
|
+
|
450
|
+
|
451
451
|
it "should not add extra graphic space closings when rendering multiple times" do
|
452
452
|
@pdf.render
|
453
453
|
state = PDF::Inspector::Graphics::State.analyze(@pdf.render)
|
454
454
|
state.save_graphics_state_count.should == 1
|
455
455
|
state.restore_graphics_state_count.should == 1
|
456
456
|
end
|
457
|
-
|
457
|
+
|
458
458
|
it "should add extra graphic state enclosings when content is added on multiple renderings" do
|
459
459
|
@pdf.render
|
460
460
|
@pdf.text "Adding a bit more content"
|
@@ -462,7 +462,7 @@ describe "When using graphics states" do
|
|
462
462
|
state.save_graphics_state_count.should == 2
|
463
463
|
state.restore_graphics_state_count.should == 2
|
464
464
|
end
|
465
|
-
|
465
|
+
|
466
466
|
it "adds extra graphic state enclosings when new settings are applied on multiple renderings" do
|
467
467
|
@pdf.render
|
468
468
|
@pdf.stroke_color 0, 0, 0, 0
|
@@ -470,13 +470,31 @@ describe "When using graphics states" do
|
|
470
470
|
state.save_graphics_state_count.should == 2
|
471
471
|
state.restore_graphics_state_count.should == 2
|
472
472
|
end
|
473
|
-
|
474
|
-
|
473
|
+
|
474
|
+
|
475
475
|
it "should raise_error error if closing an empty graphic stack" do
|
476
476
|
lambda {
|
477
477
|
@pdf.render
|
478
478
|
@pdf.restore_graphics_state
|
479
|
-
}.should raise_error(
|
479
|
+
}.should raise_error(PDF::Core::Errors::EmptyGraphicStateStack)
|
480
|
+
end
|
481
|
+
|
482
|
+
it "should copy mutable attributes when passing a previous_state to the initializer" do
|
483
|
+
new_state = PDF::Core::GraphicState.new(@pdf.graphic_state)
|
484
|
+
|
485
|
+
[:color_space, :dash, :fill_color, :stroke_color].each do |attr|
|
486
|
+
new_state.send(attr).should == @pdf.graphic_state.send(attr)
|
487
|
+
new_state.send(attr).should_not equal(@pdf.graphic_state.send(attr))
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
it "should copy mutable attributes when duping" do
|
492
|
+
new_state = @pdf.graphic_state.dup
|
493
|
+
|
494
|
+
[:color_space, :dash, :fill_color, :stroke_color].each do |attr|
|
495
|
+
new_state.send(attr).should == @pdf.graphic_state.send(attr)
|
496
|
+
new_state.send(attr).should_not equal(@pdf.graphic_state.send(attr))
|
497
|
+
end
|
480
498
|
end
|
481
499
|
end
|
482
500
|
|
@@ -485,19 +503,19 @@ describe "When using transformation matrix" do
|
|
485
503
|
|
486
504
|
# Note: The (approximate) number of significant decimal digits of precision in fractional
|
487
505
|
# part is 5 (PDF Reference, Third Edition, p. 706)
|
488
|
-
|
506
|
+
|
489
507
|
it "should send the right content on transformation_matrix" do
|
490
508
|
@pdf.expects(:add_content).with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm')
|
491
509
|
@pdf.transformation_matrix 1, 0, 0.123456789, -1.0, 5.5, 20
|
492
510
|
end
|
493
|
-
|
511
|
+
|
494
512
|
it "should use fixed digits with very small number" do
|
495
513
|
values = Array.new(6, 0.000000000001)
|
496
514
|
string = Array.new(6, "0.00000").join " "
|
497
515
|
@pdf.expects(:add_content).with("#{string} cm")
|
498
516
|
@pdf.transformation_matrix *values
|
499
517
|
end
|
500
|
-
|
518
|
+
|
501
519
|
it "should be received by the inspector" do
|
502
520
|
@pdf.transformation_matrix 1, 0, 0, -1, 5.5, 20
|
503
521
|
matrices = PDF::Inspector::Graphics::Matrix.analyze(@pdf.render)
|
@@ -508,7 +526,7 @@ describe "When using transformation matrix" do
|
|
508
526
|
values = Array.new(6, 0.000000000001)
|
509
527
|
string = Array.new(6, "0.00000").join " "
|
510
528
|
process = sequence "process"
|
511
|
-
|
529
|
+
|
512
530
|
@pdf.expects(:save_graphics_state).with().in_sequence(process)
|
513
531
|
@pdf.expects(:add_content).with("#{string} cm").in_sequence(process)
|
514
532
|
@pdf.expects(:do_something).with().in_sequence(process)
|
@@ -517,7 +535,7 @@ describe "When using transformation matrix" do
|
|
517
535
|
@pdf.do_something
|
518
536
|
end
|
519
537
|
end
|
520
|
-
|
538
|
+
|
521
539
|
end
|
522
540
|
|
523
541
|
describe "When using transformations shortcuts" do
|