prawn 1.3.0 → 2.0.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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/Gemfile +1 -1
  4. data/Rakefile +2 -2
  5. data/data/images/pal_bk.png +0 -0
  6. data/lib/prawn.rb +0 -1
  7. data/lib/prawn/document.rb +2 -2
  8. data/lib/prawn/document/internals.rb +2 -1
  9. data/lib/prawn/encoding.rb +0 -33
  10. data/lib/prawn/font/afm.rb +20 -11
  11. data/lib/prawn/font/ttf.rb +4 -0
  12. data/lib/prawn/font_metric_cache.rb +1 -2
  13. data/lib/prawn/graphics.rb +11 -8
  14. data/lib/prawn/graphics/dash.rb +5 -0
  15. data/lib/prawn/images.rb +2 -3
  16. data/lib/prawn/images/png.rb +3 -12
  17. data/lib/prawn/text.rb +15 -7
  18. data/lib/prawn/text/box.rb +1 -9
  19. data/lib/prawn/text/formatted/box.rb +9 -11
  20. data/lib/prawn/text/formatted/line_wrap.rb +5 -0
  21. data/lib/prawn/version.rb +1 -1
  22. data/manual/basic_concepts/measurement.rb +1 -1
  23. data/manual/bounding_box/bounds.rb +1 -1
  24. data/manual/cover.rb +1 -4
  25. data/manual/example_helper.rb +1 -0
  26. data/manual/how_to_read_this_manual.rb +2 -2
  27. data/manual/repeatable_content/alternate_page_numbering.rb +32 -0
  28. data/manual/repeatable_content/repeatable_content.rb +1 -0
  29. data/manual/security/security.rb +1 -1
  30. data/manual/text/paragraph_indentation.rb +8 -0
  31. data/manual/text/right_to_left_text.rb +4 -0
  32. data/manual/text/text.rb +1 -1
  33. data/manual/text/text_box_overflow.rb +1 -1
  34. data/manual/text/utf8.rb +4 -4
  35. data/manual/text/win_ansi_charset.rb +2 -1
  36. data/prawn.gemspec +4 -19
  37. data/spec/document_spec.rb +24 -1
  38. data/spec/font_spec.rb +25 -0
  39. data/spec/formatted_text_box_spec.rb +77 -33
  40. data/spec/graphics_spec.rb +26 -12
  41. data/spec/line_wrap_spec.rb +26 -10
  42. data/spec/png_spec.rb +9 -1
  43. data/spec/soft_mask_spec.rb +1 -1
  44. data/spec/spec_helper.rb +2 -2
  45. data/spec/text_at_spec.rb +0 -1
  46. data/spec/text_box_spec.rb +2 -21
  47. data/spec/text_spacing_spec.rb +2 -2
  48. data/spec/text_spec.rb +102 -1
  49. metadata +12 -24
  50. data/data/encodings/win_ansi.txt +0 -29
@@ -143,10 +143,12 @@ describe "When drawing a rounded rectangle" do
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],
149
- [50.0, 540.0], [50.0, 545.523], [54.477, 550.0], [60.0, 550.0]]
146
+ @all_coords.should == [[60.0, 550.0],[90.0, 550.0], [95.5228, 550.0],
147
+ [100.0, 545.5228], [100.0, 540.0], [100.0, 460.0],
148
+ [100.0, 454.4772], [95.5228, 450.0], [90.0, 450.0],
149
+ [60.0, 450.0], [54.4772, 450.0], [50.0, 454.4772],
150
+ [50.0, 460.0], [50.0, 540.0], [50.0, 545.5228],
151
+ [54.4772, 550.0], [60.0, 550.0]]
150
152
  end
151
153
 
152
154
  it "should start and end with the same point" do
@@ -167,20 +169,20 @@ describe "When drawing an ellipse" do
167
169
  @curve.coords.should ==
168
170
  [125.0, 100.0,
169
171
 
170
- 125.0, 127.614,
171
- 113.807, 150,
172
+ 125.0, 127.6142,
173
+ 113.8071, 150,
172
174
  100.0, 150.0,
173
175
 
174
- 86.193, 150.0,
175
- 75.0, 127.614,
176
+ 86.1929, 150.0,
177
+ 75.0, 127.6142,
176
178
  75.0, 100.0,
177
179
 
178
- 75.0, 72.386,
179
- 86.193, 50.0,
180
+ 75.0, 72.3858,
181
+ 86.1929, 50.0,
180
182
  100.0, 50.0,
181
183
 
182
- 113.807, 50.0,
183
- 125.0, 72.386,
184
+ 113.8071, 50.0,
185
+ 125.0, 72.3858,
184
186
  125.0, 100.0,
185
187
 
186
188
  100.0, 100.0]
@@ -427,6 +429,18 @@ describe "When using graphics states" do
427
429
  @pdf.graphic_state.dash[:dash].should == 5
428
430
  end
429
431
 
432
+ it "should round dash values to four decimal places" do
433
+ @pdf.dash 5.12345
434
+ @pdf.graphic_state.dash_setting.should == "[5.1235 5.1235] 0.0 d"
435
+ end
436
+
437
+ it "should raise an error when dash is called w. a zero length or space" do
438
+ expect { @pdf.dash(0) }.to raise_error(ArgumentError)
439
+ expect { @pdf.dash([0]) }.to raise_error(ArgumentError)
440
+ expect { @pdf.dash([0,0]) }.to raise_error(ArgumentError)
441
+ expect { @pdf.dash([0,0,0,1]) }.to raise_error(ArgumentError)
442
+ end
443
+
430
444
  it "the current graphic state should keep track of previous unchanged settings" do
431
445
  @pdf.stroke_color '000000'
432
446
  @pdf.save_graphics_state
@@ -128,21 +128,36 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
128
128
  string.should == "hello#{Prawn::Text::SHY}"
129
129
  end
130
130
 
131
+ it "should ignore width of a soft-hyphen during adding fragments to line", :issue =>775 do
132
+ hyphen_string = "Hy#{Prawn::Text::SHY}phe#{Prawn::Text::SHY}nat#{Prawn::Text::SHY}ions "
133
+ string1 = @pdf.font.normalize_encoding(hyphen_string * 5)
134
+ string2 = @pdf.font.normalize_encoding("Hyphenations " * 3 + hyphen_string)
135
+
136
+ array1 = [{text: string1}]
137
+ array2 = [{text: string2}]
138
+
139
+ @arranger.format_array = array1
140
+
141
+ res1 = @line_wrap.wrap_line(:arranger => @arranger,
142
+ :width => 300,
143
+ :document => @pdf)
144
+
145
+ @line_wrap = Prawn::Text::Formatted::LineWrap.new
146
+
147
+ @arranger.format_array = array2
148
+
149
+ res2 = @line_wrap.wrap_line(:arranger => @arranger,
150
+ :width => 300,
151
+ :document => @pdf)
152
+ res1.should == res2
153
+ end
154
+
131
155
  it "should not display soft hyphens except at the end of a line " +
132
156
  "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 }]
136
- @arranger.format_array = array
137
- string = @line_wrap.wrap_line(:arranger => @arranger,
138
- :width => 300,
139
- :document => @pdf)
140
- string.should == "helloworld hiearth"
141
-
142
157
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
143
158
  @line_wrap = Prawn::Text::Formatted::LineWrap.new
144
159
 
145
- string1 = "hello#{Prawn::Text::SHY}world "
160
+ string1 = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}world ")
146
161
  string2 = @pdf.font.normalize_encoding("hi#{Prawn::Text::SHY}earth")
147
162
  array = [{ :text => string1 }, { :text => string2 }]
148
163
  @arranger.format_array = array
@@ -349,3 +364,4 @@ describe "Core::Text::Formatted::LineWrap#paragraph_finished?" do
349
364
  @line_wrap.paragraph_finished?.should == true
350
365
  end
351
366
  end
367
+
@@ -98,7 +98,15 @@ describe "When reading an RGB PNG file with transparency (color type 2)" do
98
98
  end
99
99
  end
100
100
 
101
- # TODO: describe "When reading an indexed color PNG file wiih transparency (color type 3)"
101
+ describe "When reading an indexed color PNG file "+
102
+ "wiih transparency (color type 3)" do
103
+
104
+ it "raises a not supported error" do
105
+ bin = File.binread("#{Prawn::DATADIR}/images/pal_bk.png")
106
+ expect { Prawn::Images::PNG.new(bin)}.to(
107
+ raise_error(Prawn::Errors::UnsupportedImageType))
108
+ end
109
+ end
102
110
 
103
111
  describe "When reading an indexed color PNG file (color type 3)" do
104
112
 
@@ -57,7 +57,7 @@ describe "Document with soft masks" do
57
57
  end
58
58
 
59
59
  extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates.first
60
- extgstate[:soft_mask][:G].data.should == "q\n/DeviceRGB cs\n0.000 0.000 0.000 scn\n/DeviceRGB CS\n0.000 0.000 0.000 SCN\n1 w\n0 J\n0 j\n[ ] 0 d\n/DeviceRGB cs\n0.502 0.502 0.502 scn\n100.000 -100.000 200.000 200.000 re\nf\nQ\n"
60
+ extgstate[:soft_mask][:G].data.should == "q\n/DeviceRGB cs\n0.000 0.000 0.000 scn\n/DeviceRGB CS\n0.000 0.000 0.000 SCN\n1 w\n0 J\n0 j\n[] 0 d\n/DeviceRGB cs\n0.502 0.502 0.502 scn\n100.0 -100.0 200.0 200.0 re\nf\nQ\n"
61
61
  end
62
62
 
63
63
  it "should not create duplicate extended graphics states" do
@@ -12,10 +12,10 @@ if ENV["COVERAGE"]
12
12
  end
13
13
  end
14
14
 
15
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
16
- require "prawn"
15
+ require_relative "../lib/prawn"
17
16
 
18
17
  Prawn.debug = true
18
+ Prawn::Font::AFM.hide_m17n_warning = true
19
19
 
20
20
  #require "test/spec"
21
21
  require "rspec"
@@ -100,7 +100,6 @@ describe "#draw_text" do
100
100
 
101
101
  it "should raise_error an exception when a utf-8 incompatible string is rendered" do
102
102
  str = "Blah \xDD"
103
- str.force_encoding(Encoding::ASCII_8BIT)
104
103
  lambda { @pdf.draw_text(str, :at => [0, 0]) }.should raise_error(
105
104
  Prawn::Errors::IncompatibleStringEncoding)
106
105
  end
@@ -664,31 +664,12 @@ describe "Text::Box printing UTF-8 string with higher bit characters" do
664
664
  remaining_text = @text_box.render
665
665
  remaining_text.should == @text
666
666
  end
667
-
668
- it "subsequent calls to Text::Box need not include the" +
669
- " :skip_encoding => true option" do
670
- @pdf.font("Panic Sans")
671
- remaining_text = @text_box.render
672
-
673
- # expect that calling text_box will not raise an encoding error
674
- @pdf.text_box(remaining_text, :document => @pdf)
675
- end
676
667
  end
677
668
 
678
669
  describe "when using an AFM font" do
679
- it "unprinted text should be in WinAnsi encoding" do
680
- remaining_text = @text_box.render
681
- remaining_text.should == @pdf.font.normalize_encoding(@text)
682
- end
683
- it "subsequent calls to Text::Box must include the" +
684
- " :skip_encoding => true option" do
670
+ it "unprinted text should be in UTF-8 encoding" do
685
671
  remaining_text = @text_box.render
686
- lambda {
687
- @pdf.text_box(remaining_text, :document => @pdf)
688
- }.should raise_error(Prawn::Errors::IncompatibleStringEncoding)
689
-
690
- @pdf.text_box(remaining_text, :skip_encoding => true,
691
- :document => @pdf)
672
+ remaining_text.should == @text
692
673
  end
693
674
  end
694
675
  end
@@ -9,7 +9,7 @@ describe "#character_spacing" do
9
9
  @pdf.text("hello world")
10
10
  end
11
11
  contents = PDF::Inspector::Text.analyze(@pdf.render)
12
- contents.character_spacing.first.should == 10.556
12
+ contents.character_spacing.first.should == 10.5556
13
13
  end
14
14
  it "should not draw the character spacing to the document" +
15
15
  " when the new character spacing matches the old" do
@@ -63,7 +63,7 @@ describe "#word_spacing" do
63
63
  @pdf.text("hello world")
64
64
  end
65
65
  contents = PDF::Inspector::Text.analyze(@pdf.render)
66
- contents.word_spacing.first.should == 10.556
66
+ contents.word_spacing.first.should == 10.5556
67
67
  end
68
68
  it "should draw the word spacing to the document" +
69
69
  " when the new word spacing matches the old" do
@@ -315,7 +315,6 @@ describe "#text" do
315
315
 
316
316
  it "should raise_error an exception when a utf-8 incompatible string is rendered" do
317
317
  str = "Blah \xDD"
318
- str.force_encoding(Encoding::ASCII_8BIT)
319
318
  lambda { @pdf.text str }.should raise_error(
320
319
  Prawn::Errors::IncompatibleStringEncoding)
321
320
  end
@@ -351,6 +350,108 @@ describe "#text" do
351
350
  text.strings[3].should == ("hello " * 19).strip
352
351
  text.strings[4].should == ("hello " * 21).strip
353
352
  end
353
+
354
+
355
+ it "should indent from right side when using :rtl direction" do
356
+ para1 = "The rain in spain falls mainly on the plains " * 3
357
+ para2 = "The rain in spain falls mainly on the plains " * 3
358
+
359
+ @pdf.text(para1 + "\n" + para2, :indent_paragraphs => 60, :direction => :rtl)
360
+
361
+ text = PDF::Inspector::Text.analyze(@pdf.render)
362
+
363
+ lines = text.strings
364
+ x_positions = text.positions.map { |e| e[0] }
365
+
366
+ # NOTE: The code below reflects Prawn's current kerning behavior for RTL
367
+ # text, which isn't necessarily correct. If we change that behavior,
368
+ # this test will need to be updated.
369
+
370
+ x_positions[0].should(
371
+ be_within(0.001).of(@pdf.bounds.absolute_right - 60 -
372
+ @pdf.width_of(lines[0].reverse, :kerning => true)))
373
+
374
+ x_positions[1].should(
375
+ be_within(0.001).of(@pdf.bounds.absolute_right -
376
+ @pdf.width_of(lines[1].reverse, :kerning => true)))
377
+
378
+ x_positions[2].should(
379
+ be_within(0.001).of(@pdf.bounds.absolute_right - 60 -
380
+ @pdf.width_of(lines[2].reverse, :kerning => true)))
381
+
382
+ x_positions[3].should(
383
+ be_within(0.001).of(@pdf.bounds.absolute_right -
384
+ @pdf.width_of(lines[3].reverse, :kerning => true)))
385
+ end
386
+
387
+ it "should indent from right side when document has :rtl direction" do
388
+ para1 = "The rain in spain falls mainly on the plains " * 3
389
+ para2 = "The rain in spain falls mainly on the plains " * 3
390
+
391
+ @pdf.text_direction = :rtl
392
+ @pdf.text(para1 + "\n" + para2, :indent_paragraphs => 60)
393
+
394
+ text = PDF::Inspector::Text.analyze(@pdf.render)
395
+
396
+ lines = text.strings
397
+ x_positions = text.positions.map { |e| e[0] }
398
+
399
+ # NOTE: The code below reflects Prawn's current kerning behavior for RTL
400
+ # text, which isn't necessarily correct. If we change that behavior,
401
+ # this test will need to be updated.
402
+
403
+ x_positions[0].should(
404
+ be_within(0.001).of(@pdf.bounds.absolute_right - 60 -
405
+ @pdf.width_of(lines[0].reverse, :kerning => true)))
406
+
407
+ x_positions[1].should(
408
+ be_within(0.001).of(@pdf.bounds.absolute_right -
409
+ @pdf.width_of(lines[1].reverse, :kerning => true)))
410
+
411
+ x_positions[2].should(
412
+ be_within(0.001).of(@pdf.bounds.absolute_right - 60 -
413
+ @pdf.width_of(lines[2].reverse, :kerning => true)))
414
+
415
+ x_positions[3].should(
416
+ be_within(0.001).of(@pdf.bounds.absolute_right -
417
+ @pdf.width_of(lines[3].reverse, :kerning => true)))
418
+ end
419
+
420
+ it "should indent from left side when using :ltr direction" do
421
+ para1 = "The rain in spain falls mainly on the plains " * 3
422
+ para2 = "The rain in spain falls mainly on the plains " * 3
423
+
424
+ @pdf.text(para1 + "\n" + para2, :indent_paragraphs => 60, :direction => :ltr)
425
+
426
+ text = PDF::Inspector::Text.analyze(@pdf.render)
427
+
428
+ x_positions = text.positions.map { |e| e[0] }
429
+
430
+ x_positions[0].should == 60
431
+ x_positions[1].should == 0
432
+
433
+ x_positions[2].should == 60
434
+ x_positions[3].should == 0
435
+ end
436
+
437
+ it "should indent from left side when document has :ltr direction" do
438
+ para1 = "The rain in spain falls mainly on the plains " * 3
439
+ para2 = "The rain in spain falls mainly on the plains " * 3
440
+
441
+ @pdf.text_direction = :ltr
442
+ @pdf.text(para1 + "\n" + para2, :indent_paragraphs => 60)
443
+
444
+ text = PDF::Inspector::Text.analyze(@pdf.render)
445
+
446
+ x_positions = text.positions.map { |e| e[0] }
447
+
448
+ x_positions[0].should == 60
449
+ x_positions[1].should == 0
450
+
451
+ x_positions[2].should == 60
452
+ x_positions[3].should == 0
453
+ end
454
+
354
455
  describe "when wrap to new page, and first line of new page" +
355
456
  " is not the start of a new paragraph, that line should" +
356
457
  " not be indented" do
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.3.0
4
+ version: 2.0.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-09-28 00:00:00.000000000 Z
15
+ date: 2015-02-26 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: ttfunk
@@ -34,28 +34,28 @@ dependencies:
34
34
  requirements:
35
35
  - - "~>"
36
36
  - !ruby/object:Gem::Version
37
- version: 0.4.0
37
+ version: 0.5.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.4.0
44
+ version: 0.5.0
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: pdf-inspector
47
47
  requirement: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - "~>"
50
50
  - !ruby/object:Gem::Version
51
- version: 1.1.0
51
+ version: 1.2.0
52
52
  type: :development
53
53
  prerelease: false
54
54
  version_requirements: !ruby/object:Gem::Requirement
55
55
  requirements:
56
56
  - - "~>"
57
57
  - !ruby/object:Gem::Version
58
- version: 1.1.0
58
+ version: 1.2.0
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: yard
61
61
  requirement: !ruby/object:Gem::Requirement
@@ -160,14 +160,14 @@ dependencies:
160
160
  requirements:
161
161
  - - '='
162
162
  - !ruby/object:Gem::Version
163
- version: 0.20.1
163
+ version: 0.28.0
164
164
  type: :development
165
165
  prerelease: false
166
166
  version_requirements: !ruby/object:Gem::Requirement
167
167
  requirements:
168
168
  - - '='
169
169
  - !ruby/object:Gem::Version
170
- version: 0.20.1
170
+ version: 0.28.0
171
171
  - !ruby/object:Gem::Dependency
172
172
  name: code_statistics
173
173
  requirement: !ruby/object:Gem::Requirement
@@ -201,7 +201,6 @@ files:
201
201
  - Gemfile
202
202
  - LICENSE
203
203
  - Rakefile
204
- - data/encodings/win_ansi.txt
205
204
  - data/fonts/Courier-Bold.afm
206
205
  - data/fonts/Courier-BoldOblique.afm
207
206
  - data/fonts/Courier-Oblique.afm
@@ -234,6 +233,7 @@ files:
234
233
  - data/images/page_white_text.alpha
235
234
  - data/images/page_white_text.color
236
235
  - data/images/page_white_text.png
236
+ - data/images/pal_bk.png
237
237
  - data/images/pigs.jpg
238
238
  - data/images/prawn.png
239
239
  - data/images/ruport.png
@@ -367,6 +367,7 @@ files:
367
367
  - manual/outline/insert_section_after.rb
368
368
  - manual/outline/outline.rb
369
369
  - manual/outline/sections_and_pages.rb
370
+ - manual/repeatable_content/alternate_page_numbering.rb
370
371
  - manual/repeatable_content/page_numbering.rb
371
372
  - manual/repeatable_content/repeatable_content.rb
372
373
  - manual/repeatable_content/repeater.rb
@@ -449,20 +450,7 @@ licenses:
449
450
  - GPL-2
450
451
  - GPL-3
451
452
  metadata: {}
452
- post_install_message: |2+
453
-
454
- ********************************************
455
-
456
-
457
- A lot has changed recently in Prawn.
458
-
459
- Please read the changelog for details:
460
-
461
- https://github.com/prawnpdf/prawn/wiki/CHANGELOG
462
-
463
-
464
- ********************************************
465
-
453
+ post_install_message:
466
454
  rdoc_options: []
467
455
  require_paths:
468
456
  - lib
@@ -470,7 +458,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
470
458
  requirements:
471
459
  - - ">="
472
460
  - !ruby/object:Gem::Version
473
- version: 1.9.3
461
+ version: 2.0.0
474
462
  required_rubygems_version: !ruby/object:Gem::Requirement
475
463
  requirements:
476
464
  - - ">="