prawn 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -112,8 +112,7 @@ describe "When creating multi-page documents" do
112
112
  end
113
113
 
114
114
  describe "When beginning each new page" do
115
-
116
- describe "Background template feature" do
115
+ describe "Background image feature" do
117
116
  before(:each) do
118
117
  @filename = "#{Prawn::DATADIR}/images/pigs.jpg"
119
118
  @pdf = Prawn::Document.new(:background => @filename)
@@ -128,11 +127,7 @@ describe "When beginning each new page" do
128
127
  @pdf.instance_variable_defined?(:@background).should == true
129
128
  @pdf.instance_variable_get(:@background).should == @filename
130
129
  end
131
-
132
-
133
130
  end
134
-
135
-
136
131
  end
137
132
 
138
133
  describe "Prawn::Document#float" do
@@ -188,7 +183,7 @@ describe "on_page_create callback" do
188
183
  it "should be invoked with document" do
189
184
  called_with = nil
190
185
 
191
- @pdf.on_page_create { |*args| called_with = args }
186
+ @pdf.renderer.on_page_create { |*args| called_with = args }
192
187
 
193
188
  @pdf.start_new_page
194
189
 
@@ -199,7 +194,7 @@ describe "on_page_create callback" do
199
194
  trigger = mock()
200
195
  trigger.expects(:fire).times(5)
201
196
 
202
- @pdf.on_page_create { trigger.fire }
197
+ @pdf.renderer.on_page_create { trigger.fire }
203
198
 
204
199
  5.times { @pdf.start_new_page }
205
200
  end
@@ -211,11 +206,11 @@ describe "on_page_create callback" do
211
206
  trigger2 = mock()
212
207
  trigger2.expects(:fire).times(1)
213
208
 
214
- @pdf.on_page_create { trigger1.fire }
209
+ @pdf.renderer.on_page_create { trigger1.fire }
215
210
 
216
211
  @pdf.start_new_page
217
212
 
218
- @pdf.on_page_create { trigger2.fire }
213
+ @pdf.renderer.on_page_create { trigger2.fire }
219
214
 
220
215
  @pdf.start_new_page
221
216
  end
@@ -224,11 +219,11 @@ describe "on_page_create callback" do
224
219
  trigger = mock()
225
220
  trigger.expects(:fire).times(1)
226
221
 
227
- @pdf.on_page_create { trigger.fire }
222
+ @pdf.renderer.on_page_create { trigger.fire }
228
223
 
229
224
  @pdf.start_new_page
230
225
 
231
- @pdf.on_page_create
226
+ @pdf.renderer.on_page_create
232
227
 
233
228
  @pdf.start_new_page
234
229
  end
@@ -460,15 +455,15 @@ describe "The render() feature" do
460
455
  seq = sequence("callback_order")
461
456
 
462
457
  # Verify the order: finalize -> fire callbacks -> render body
463
- pdf.expects(:finalize_all_page_contents).in_sequence(seq)
458
+ pdf.renderer.expects(:finalize_all_page_contents).in_sequence(seq)
464
459
  trigger = mock()
465
460
  trigger.expects(:fire).in_sequence(seq)
466
461
 
467
462
  # Store away the render_body method to be called below
468
- render_body = pdf.method(:render_body)
469
- pdf.expects(:render_body).in_sequence(seq)
463
+ render_body = pdf.renderer.method(:render_body)
464
+ pdf.renderer.expects(:render_body).in_sequence(seq)
470
465
 
471
- pdf.before_render{ trigger.fire }
466
+ pdf.renderer.before_render{ trigger.fire }
472
467
 
473
468
  # Render the body to set up object offsets
474
469
  render_body.call(StringIO.new)
@@ -493,7 +488,7 @@ describe "PDF file versions" do
493
488
 
494
489
  it "should allow the default to be changed" do
495
490
  @pdf = Prawn::Document.new
496
- @pdf.__send__(:min_version, 1.4)
491
+ @pdf.renderer.min_version(1.4)
497
492
  str = @pdf.render
498
493
  str[0,8].should == "%PDF-1.4"
499
494
  end
@@ -530,7 +525,7 @@ describe "Documents that use go_to_page" do
530
525
  end
531
526
 
532
527
  describe "content stream characteristics" do
533
- it "should have 1 single content stream for a single page PDF with no templates" do
528
+ it "should have 1 single content stream for a single page PDF" do
534
529
  @pdf = Prawn::Document.new
535
530
  @pdf.text "James"
536
531
  output = StringIO.new(@pdf.render)
@@ -541,7 +536,7 @@ describe "content stream characteristics" do
541
536
  streams.size.should == 1
542
537
  end
543
538
 
544
- it "should have 1 single content stream for a single page PDF with no templates, even if go_to_page is used" do
539
+ it "should have 1 single content stream for a single page PDF, even if go_to_page is used" do
545
540
  @pdf = Prawn::Document.new
546
541
  @pdf.text "James"
547
542
  @pdf.go_to_page(1)
@@ -210,22 +210,22 @@ describe "When filling" do
210
210
  before(:each) { create_pdf }
211
211
 
212
212
  it "should default to the f operator (nonzero winding number rule)" do
213
- @pdf.expects(:add_content).with("f")
213
+ @pdf.renderer.expects(:add_content).with("f")
214
214
  @pdf.fill
215
215
  end
216
216
 
217
217
  it "should use f* for :fill_rule => :even_odd" do
218
- @pdf.expects(:add_content).with("f*")
218
+ @pdf.renderer.expects(:add_content).with("f*")
219
219
  @pdf.fill(:fill_rule => :even_odd)
220
220
  end
221
221
 
222
222
  it "should use b by default for fill_and_stroke (nonzero winding number)" do
223
- @pdf.expects(:add_content).with("b")
223
+ @pdf.renderer.expects(:add_content).with("b")
224
224
  @pdf.fill_and_stroke
225
225
  end
226
226
 
227
227
  it "should use b* for fill_and_stroke(:fill_rule => :even_odd)" do
228
- @pdf.expects(:add_content).with("b*")
228
+ @pdf.renderer.expects(:add_content).with("b*")
229
229
  @pdf.fill_and_stroke(:fill_rule => :even_odd)
230
230
  end
231
231
  end
@@ -383,22 +383,22 @@ 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
- @pdf.expects(:add_content).with('q')
386
+ @pdf.renderer.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
- @pdf.expects(:add_content).with('Q')
392
+ @pdf.renderer.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
- @pdf.expects(:add_content).with('q').in_sequence(state)
399
+ @pdf.renderer.expects(:add_content).with('q').in_sequence(state)
400
400
  @pdf.expects(:foo).in_sequence(state)
401
- @pdf.expects(:add_content).with('Q').in_sequence(state)
401
+ @pdf.renderer.expects(:add_content).with('Q').in_sequence(state)
402
402
 
403
403
  @pdf.save_graphics_state do
404
404
  @pdf.foo
@@ -505,14 +505,14 @@ describe "When using transformation matrix" do
505
505
  # part is 5 (PDF Reference, Third Edition, p. 706)
506
506
 
507
507
  it "should send the right content on transformation_matrix" do
508
- @pdf.expects(:add_content).with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm')
508
+ @pdf.renderer.expects(:add_content).with('1.00000 0.00000 0.12346 -1.00000 5.50000 20.00000 cm')
509
509
  @pdf.transformation_matrix 1, 0, 0.123456789, -1.0, 5.5, 20
510
510
  end
511
511
 
512
512
  it "should use fixed digits with very small number" do
513
513
  values = Array.new(6, 0.000000000001)
514
514
  string = Array.new(6, "0.00000").join " "
515
- @pdf.expects(:add_content).with("#{string} cm")
515
+ @pdf.renderer.expects(:add_content).with("#{string} cm")
516
516
  @pdf.transformation_matrix *values
517
517
  end
518
518
 
@@ -528,7 +528,7 @@ describe "When using transformation matrix" do
528
528
  process = sequence "process"
529
529
 
530
530
  @pdf.expects(:save_graphics_state).with().in_sequence(process)
531
- @pdf.expects(:add_content).with("#{string} cm").in_sequence(process)
531
+ @pdf.renderer.expects(:add_content).with("#{string} cm").in_sequence(process)
532
532
  @pdf.expects(:do_something).with().in_sequence(process)
533
533
  @pdf.expects(:restore_graphics_state).with().in_sequence(process)
534
534
  @pdf.transformation_matrix(*values) do
@@ -128,25 +128,28 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
128
128
  string.should == "hello#{Prawn::Text::SHY}"
129
129
  end
130
130
 
131
- it "should not display soft hyphens except at the end of a line" do
132
- string = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}world")
133
- array = [{ :text => string }]
131
+ it "should not display soft hyphens except at the end of a line " +
132
+ "for more than one element in format_array", :issue => 347 do
133
+ string1 = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}world ")
134
+ string2 = @pdf.font.normalize_encoding("hi#{Prawn::Text::SHY}earth")
135
+ array = [{ :text => string1 }, { :text => string2 }]
134
136
  @arranger.format_array = array
135
137
  string = @line_wrap.wrap_line(:arranger => @arranger,
136
138
  :width => 300,
137
139
  :document => @pdf)
138
- string.should == "helloworld"
140
+ string.should == "helloworld hiearth"
139
141
 
140
142
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
141
143
  @line_wrap = Prawn::Text::Formatted::LineWrap.new
142
144
 
143
- string = "hello#{Prawn::Text::SHY}world"
144
- array = [{ :text => string }]
145
+ string1 = "hello#{Prawn::Text::SHY}world "
146
+ string2 = @pdf.font.normalize_encoding("hi#{Prawn::Text::SHY}earth")
147
+ array = [{ :text => string1 }, { :text => string2 }]
145
148
  @arranger.format_array = array
146
149
  string = @line_wrap.wrap_line(:arranger => @arranger,
147
150
  :width => 300,
148
151
  :document => @pdf)
149
- string.should == "helloworld"
152
+ string.should == "helloworld hiearth"
150
153
  end
151
154
 
152
155
  it "should not break before a hard hyphen that follows a word" do
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative "spec_helper"
4
+
5
+ describe "Prawn::View" do
6
+ let(:view_object) { Object.new.tap { |o| o.extend(Prawn::View) } }
7
+
8
+ it "provides a Prawn::Document object by default" do
9
+ expect(view_object.document).to be_kind_of(Prawn::Document)
10
+ end
11
+
12
+ it "delegates unhandled methods to object returned by document method" do
13
+ doc = mock("Document")
14
+ view_object.stubs(:document => doc)
15
+
16
+ doc.expects(:some_delegated_method)
17
+
18
+ view_object.some_delegated_method
19
+ end
20
+
21
+ it "allows a block-like DSL via the update method" do
22
+ doc = mock("Document")
23
+ view_object.stubs(:document => doc)
24
+
25
+ doc.expects(:foo)
26
+ doc.expects(:bar)
27
+
28
+ view_object.update do
29
+ foo
30
+ bar
31
+ end
32
+ end
33
+
34
+ it "aliases save_as() to document.render_file()" do
35
+ doc = mock("Document")
36
+ doc.expects(:render_file)
37
+
38
+ view_object.stubs(:document => doc)
39
+
40
+ view_object.save_as("foo.pdf")
41
+ end
42
+ end
43
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prawn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Brown
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-07-27 00:00:00.000000000 Z
15
+ date: 2014-09-28 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: ttfunk
@@ -20,28 +20,28 @@ dependencies:
20
20
  requirements:
21
21
  - - "~>"
22
22
  - !ruby/object:Gem::Version
23
- version: 1.2.0
23
+ version: 1.4.0
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - "~>"
29
29
  - !ruby/object:Gem::Version
30
- version: 1.2.0
30
+ version: 1.4.0
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: pdf-core
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  requirements:
35
35
  - - "~>"
36
36
  - !ruby/object:Gem::Version
37
- version: 0.2.5
37
+ version: 0.4.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - "~>"
43
43
  - !ruby/object:Gem::Version
44
- version: 0.2.5
44
+ version: 0.4.0
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: pdf-inspector
47
47
  requirement: !ruby/object:Gem::Requirement
@@ -168,6 +168,20 @@ dependencies:
168
168
  - - '='
169
169
  - !ruby/object:Gem::Version
170
170
  version: 0.20.1
171
+ - !ruby/object:Gem::Dependency
172
+ name: code_statistics
173
+ requirement: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - '='
176
+ - !ruby/object:Gem::Version
177
+ version: 0.2.13
178
+ type: :development
179
+ prerelease: false
180
+ version_requirements: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - '='
183
+ - !ruby/object:Gem::Version
184
+ version: 0.2.13
171
185
  description: |2
172
186
  Prawn is a fast, tiny, and nimble PDF generator for Ruby
173
187
  email:
@@ -187,7 +201,6 @@ files:
187
201
  - Gemfile
188
202
  - LICENSE
189
203
  - Rakefile
190
- - VERSION
191
204
  - data/encodings/win_ansi.txt
192
205
  - data/fonts/Courier-Bold.afm
193
206
  - data/fonts/Courier-BoldOblique.afm
@@ -248,7 +261,6 @@ files:
248
261
  - lib/prawn/document.rb
249
262
  - lib/prawn/document/bounding_box.rb
250
263
  - lib/prawn/document/column_box.rb
251
- - lib/prawn/document/graphics_state.rb
252
264
  - lib/prawn/document/internals.rb
253
265
  - lib/prawn/document/span.rb
254
266
  - lib/prawn/encoding.rb
@@ -290,6 +302,8 @@ files:
290
302
  - lib/prawn/text/formatted/parser.rb
291
303
  - lib/prawn/text/formatted/wrap.rb
292
304
  - lib/prawn/utilities.rb
305
+ - lib/prawn/version.rb
306
+ - lib/prawn/view.rb
293
307
  - manual/absolute_position.pdf
294
308
  - manual/basic_concepts/adding_pages.rb
295
309
  - manual/basic_concepts/basic_concepts.rb
@@ -298,6 +312,7 @@ files:
298
312
  - manual/basic_concepts/measurement.rb
299
313
  - manual/basic_concepts/origin.rb
300
314
  - manual/basic_concepts/other_cursor_helpers.rb
315
+ - manual/basic_concepts/view.rb
301
316
  - manual/bounding_box/bounding_box.rb
302
317
  - manual/bounding_box/bounds.rb
303
318
  - manual/bounding_box/canvas.rb
@@ -427,6 +442,7 @@ files:
427
442
  - spec/text_spec.rb
428
443
  - spec/text_with_inline_formatting_spec.rb
429
444
  - spec/transparency_spec.rb
445
+ - spec/view_spec.rb
430
446
  homepage: http://prawn.majesticseacreature.com
431
447
  licenses:
432
448
  - RUBY
@@ -501,4 +517,5 @@ test_files:
501
517
  - spec/text_spec.rb
502
518
  - spec/text_with_inline_formatting_spec.rb
503
519
  - spec/transparency_spec.rb
520
+ - spec/view_spec.rb
504
521
  has_rdoc:
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.2.1
@@ -1,73 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- # graphics_state.rb: Implements graphics state saving and restoring
4
- #
5
- # Copyright January 2010, Michael Witrant. All Rights Reserved.
6
- #
7
- # This is free software. Please see the LICENSE and COPYING files for details.
8
- #
9
-
10
- module Prawn
11
- class Document
12
- module GraphicsState # @private
13
-
14
- # Pushes the current graphics state on to the graphics state stack so we
15
- # can restore it when finished with a change we want to isolate (such as
16
- # modifying the transformation matrix). Used in pairs with
17
- # restore_graphics_state or passed a block
18
- #
19
- # Example without a block:
20
- #
21
- # save_graphics_state
22
- # rotate 30
23
- # text "rotated text"
24
- # restore_graphics_state
25
- #
26
- # Example with a block:
27
- #
28
- # save_graphics_state do
29
- # rotate 30
30
- # text "rotated text"
31
- # end
32
- #
33
-
34
- def open_graphics_state
35
- add_content "q"
36
- end
37
-
38
- def close_graphics_state
39
- add_content "Q"
40
- end
41
-
42
- def save_graphics_state(graphic_state = nil)
43
- graphic_stack.save_graphic_state(graphic_state)
44
- open_graphics_state
45
- if block_given?
46
- yield
47
- restore_graphics_state
48
- end
49
- end
50
-
51
- # Pops the last saved graphics state off the graphics state stack and
52
- # restores the state to those values
53
- def restore_graphics_state
54
- if graphic_stack.empty?
55
- raise PDF::Core::Errors::EmptyGraphicStateStack,
56
- "\n You have reached the end of the graphic state stack"
57
- end
58
- close_graphics_state
59
- graphic_stack.restore_graphic_state
60
- end
61
-
62
- def graphic_stack
63
- state.page.stack
64
- end
65
-
66
- def graphic_state
67
- save_graphics_state unless graphic_stack.current_state
68
- graphic_stack.current_state
69
- end
70
-
71
- end
72
- end
73
- end