prawn 0.13.0 → 0.14.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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/Gemfile +7 -14
  4. data/Rakefile +5 -10
  5. data/data/images/16bit.alpha +0 -0
  6. data/data/images/16bit.color +0 -0
  7. data/data/images/dice.alpha +0 -0
  8. data/data/images/dice.color +0 -0
  9. data/data/images/page_white_text.alpha +0 -0
  10. data/data/images/page_white_text.color +0 -0
  11. data/lib/pdf/core/document_state.rb +3 -2
  12. data/lib/pdf/core/graphics_state.rb +29 -8
  13. data/lib/pdf/core/object_store.rb +6 -15
  14. data/lib/pdf/core/pdf_object.rb +8 -33
  15. data/lib/prawn/document/bounding_box.rb +11 -0
  16. data/lib/prawn/document/column_box.rb +12 -4
  17. data/lib/prawn/document.rb +30 -42
  18. data/lib/prawn/encoding.rb +1 -2
  19. data/lib/prawn/font/afm.rb +71 -30
  20. data/lib/prawn/font/dfont.rb +1 -1
  21. data/lib/prawn/font/ttf.rb +10 -2
  22. data/lib/prawn/font.rb +7 -8
  23. data/lib/prawn/graphics.rb +8 -7
  24. data/lib/prawn/image_handler.rb +4 -0
  25. data/lib/prawn/images/jpg.rb +9 -10
  26. data/lib/prawn/images/png.rb +46 -118
  27. data/lib/prawn/images.rb +2 -7
  28. data/lib/prawn/layout.rb +2 -2
  29. data/lib/prawn/measurement_extensions.rb +1 -1
  30. data/lib/prawn/table/cells.rb +6 -2
  31. data/lib/prawn/table/column_width_calculator.rb +55 -0
  32. data/lib/prawn/table.rb +9 -22
  33. data/lib/prawn/templates.rb +75 -0
  34. data/lib/prawn/text/formatted/arranger.rb +1 -5
  35. data/lib/prawn/text/formatted/box.rb +1 -1
  36. data/lib/prawn/text/formatted/fragment.rb +5 -11
  37. data/lib/prawn/text/formatted/line_wrap.rb +4 -25
  38. data/lib/prawn/text/formatted/wrap.rb +1 -4
  39. data/lib/prawn.rb +1 -2
  40. data/manual/document_and_page_options/document_and_page_options.rb +2 -1
  41. data/manual/document_and_page_options/metadata.rb +3 -3
  42. data/manual/document_and_page_options/print_scaling.rb +20 -0
  43. data/manual/example_file.rb +2 -7
  44. data/manual/manual/cover.rb +3 -2
  45. data/manual/manual/manual.rb +1 -2
  46. data/prawn.gemspec +10 -6
  47. data/spec/bounding_box_spec.rb +12 -0
  48. data/spec/column_box_spec.rb +32 -0
  49. data/spec/document_spec.rb +5 -7
  50. data/spec/extensions/encoding_helpers.rb +2 -3
  51. data/spec/filters_spec.rb +1 -1
  52. data/spec/font_spec.rb +3 -2
  53. data/spec/formatted_text_box_spec.rb +14 -25
  54. data/spec/graphics_spec.rb +18 -0
  55. data/spec/image_handler_spec.rb +12 -0
  56. data/spec/images_spec.rb +2 -6
  57. data/spec/line_wrap_spec.rb +2 -2
  58. data/spec/object_store_spec.rb +6 -0
  59. data/spec/outline_spec.rb +10 -10
  60. data/spec/png_spec.rb +9 -12
  61. data/spec/table_spec.rb +55 -2
  62. data/spec/{template_spec.rb → template_spec_obsolete.rb} +2 -1
  63. data/spec/text_at_spec.rb +11 -26
  64. data/spec/text_box_spec.rb +6 -2
  65. data/spec/text_spec.rb +39 -27
  66. metadata +58 -38
  67. data/README.md +0 -109
  68. data/data/images/16bit.dat +0 -0
  69. data/data/images/dice.dat +0 -0
  70. data/data/images/page_white_text.dat +0 -0
  71. data/lib/prawn/compatibility.rb +0 -91
  72. data/manual/templates/full_template.rb +0 -25
  73. data/manual/templates/page_template.rb +0 -48
  74. data/manual/templates/templates.rb +0 -27
@@ -119,7 +119,7 @@ module Prawn
119
119
  "[#{whitespace}]+|" +
120
120
  "#{hyphen}+[^#{break_chars}]*|" +
121
121
  "#{soft_hyphen}"
122
- new_regexp(pattern)
122
+ Regexp.new(pattern)
123
123
  end
124
124
 
125
125
  # The pattern used to determine whether any word breaks exist on a
@@ -127,7 +127,7 @@ module Prawn
127
127
  # word breaking is needed
128
128
  #
129
129
  def word_division_scan_pattern
130
- new_regexp("\\s|[#{zero_width_space}#{soft_hyphen}#{hyphen}]")
130
+ Regexp.new("\\s|[#{zero_width_space}#{soft_hyphen}#{hyphen}]")
131
131
  end
132
132
 
133
133
  def break_chars
@@ -241,18 +241,9 @@ module Prawn
241
241
  end
242
242
 
243
243
  def wrap_by_char(segment)
244
- # this conditional is only necessary for Ruby 1.8 compatibility
245
- # String#unicode_characters is a helper which iterates over UTF-8 characters
246
- # under Ruby 1.9, it is implemented simply by aliasing #each_char
247
244
  font = @document.font
248
- if font.unicode?
249
- segment.unicode_characters do |char|
250
- break unless append_char(char,font)
251
- end
252
- else
253
- segment.each_char do |char|
254
- break unless append_char(char,font)
255
- end
245
+ segment.each_char do |char|
246
+ break unless append_char(char,font)
256
247
  end
257
248
  end
258
249
 
@@ -268,18 +259,6 @@ module Prawn
268
259
  false
269
260
  end
270
261
  end
271
-
272
- def new_regexp(pattern)
273
- regexp = ruby_19 {
274
- Regexp.new(pattern)
275
- }
276
- regexp = regexp || ruby_18 {
277
- lang = @document.font.unicode? ? 'U' : 'N'
278
- Regexp.new(pattern, 0, lang)
279
- }
280
- regexp
281
- end
282
-
283
262
  end
284
263
  end
285
264
  end
@@ -87,10 +87,7 @@ module Prawn
87
87
  accumulated_width += fragment_this_line.width
88
88
  end
89
89
 
90
- if "".respond_to?(:force_encoding)
91
- printed_fragments.map! { |s| s.force_encoding("utf-8") }
92
- end
93
- @printed_lines << printed_fragments.join
90
+ @printed_lines << printed_fragments.map { |s| s.force_encoding(::Encoding::UTF_8) }.join
94
91
  end
95
92
 
96
93
  def word_spacing_for_this_line
data/lib/prawn.rb CHANGED
@@ -20,7 +20,7 @@ end
20
20
  require "set"
21
21
 
22
22
  module Prawn
23
- VERSION = "0.13.0"
23
+ VERSION = "0.14.0"
24
24
 
25
25
  extend self
26
26
 
@@ -73,7 +73,6 @@ module Prawn
73
73
  end
74
74
  end
75
75
 
76
- require_relative "prawn/compatibility"
77
76
  require_relative "prawn/errors"
78
77
 
79
78
  require_relative "pdf/core"
@@ -14,7 +14,8 @@ Prawn::Example.generate("document_and_page_options.pdf",
14
14
  p.example "page_margins", :eval_source => false, :full_source => true
15
15
  p.example "background", :eval_source => false, :full_source => true
16
16
  p.example "metadata", :eval_source => false, :full_source => true
17
-
17
+ p.example "print_scaling",:eval_source => false, :full_source => true
18
+
18
19
  p.intro do
19
20
  prose("So far we've already seen how to create new documents and start new pages. This chapter expands on the previous examples by showing other options avialable. Some of the options are only available when creating new documents.
20
21
 
@@ -2,6 +2,7 @@
2
2
  #
3
3
  # To set the document metadata just pass a hash to the <code>:info</code>
4
4
  # option when creating new documents.
5
+ # The keys in the example below are arbitrary, so you may add whatever keys you want
5
6
  #
6
7
  require File.expand_path(File.join(File.dirname(__FILE__),
7
8
  %w[.. example_helper]))
@@ -14,10 +15,9 @@ Prawn::Document.generate("metadata.pdf",
14
15
  :Keywords => "test metadata ruby pdf dry",
15
16
  :Creator => "ACME Soft App",
16
17
  :Producer => "Prawn",
17
- :CreationDate => Time.now,
18
- :Grok => "Test Property"
18
+ :CreationDate => Time.now
19
19
  }) do
20
20
 
21
21
  text "This is a test of setting metadata properties via the info option."
22
- text "It allows one to specify non standard properties like 'Grok'."
22
+ text "While the keys are arbitrary, the above example sets common attributes."
23
23
  end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ #
3
+ # (Optional; PDF 1.6) The page scaling option to be selected when a print dialog is displayed for this document.
4
+ # Valid values are <code>None</code>, which indicates that the print dialog should reflect no page scaling,
5
+ # and <code>AppDefault</code>, which indicates that applications should use the current print scaling.
6
+ # If this entry has an unrecognized value, applications should use the current print scaling.
7
+ # Default value: <code>AppDefault</code>.
8
+ #
9
+ # Note: If the print dialog is suppressed and its parameters are provided directly by the application, the value of this entry should still be used.
10
+ #
11
+
12
+ require File.expand_path(File.join(File.dirname(__FILE__),
13
+ %w[.. example_helper]))
14
+
15
+ Prawn::Document.generate("print_scaling.pdf",
16
+ :page_layout => :landscape,
17
+ :print_scaling => :none
18
+ ) do
19
+ text "When you print this document, the scale to fit in print preview should be disabled by default."
20
+ end
@@ -103,13 +103,8 @@ module Prawn
103
103
  def read_file(folder_name, filename)
104
104
  data = File.read(File.expand_path(File.join(
105
105
  File.dirname(__FILE__), folder_name, filename)))
106
-
107
- # XXX If we ever have manual files with source encodings other than
108
- # UTF-8, we will need to fix this to work on Ruby 1.9.
109
- if data.respond_to?(:encode!)
110
- data.encode!("UTF-8")
111
- end
112
- data
106
+
107
+ data.encode(::Encoding::UTF_8)
113
108
  end
114
109
 
115
110
  end
@@ -27,8 +27,9 @@ Prawn::Example.generate(filename) do
27
27
  #commit = `git show --pretty=%H`
28
28
  #short git commit hash
29
29
  commit = `git show --pretty=%h`
30
- formatted_text_box([ {:text => "Last Update: #{Time.now.strftime("%Y-%m-%d")}\n
31
- git commit: #{commit}",
30
+ formatted_text_box([ {:text => "Last Update: #{Time.now.strftime("%Y-%m-%d")}\n"+
31
+ "Prawn Version: #{Prawn::VERSION}\n"+
32
+ "git commit: #{commit}",
32
33
  :size => 12}
33
34
  ], :at => [390, cursor - 620])
34
35
 
@@ -3,7 +3,7 @@
3
3
  # Generates the Prawn by example manual.
4
4
  #
5
5
 
6
- Encoding.default_external = "UTF-8" if defined? Encoding
6
+ Encoding.default_external = Encoding::UTF_8
7
7
 
8
8
  require File.expand_path(File.join(File.dirname(__FILE__),
9
9
  %w[.. example_helper]))
@@ -30,6 +30,5 @@ Prawn::Example.generate("manual.pdf",
30
30
  load_package "document_and_page_options"
31
31
  load_package "outline"
32
32
  load_package "repeatable_content"
33
- load_package "templates"
34
33
  load_package "security"
35
34
  end
data/prawn.gemspec CHANGED
@@ -8,25 +8,29 @@ Gem::Specification.new do |spec|
8
8
  Dir.glob("data/fonts/{MustRead.html,*.afm}") +
9
9
  ["data/shift_jis_text.txt"] +
10
10
  ["Rakefile", "prawn.gemspec", "Gemfile",
11
- "COPYING", "LICENSE", "GPLv2", "GPLv3"]
11
+ "COPYING", "LICENSE", "GPLv2", "GPLv3",
12
+ ".yardopts"]
12
13
  spec.require_path = "lib"
13
14
  spec.required_ruby_version = '>= 1.9.3'
14
15
  spec.required_rubygems_version = ">= 1.3.6"
15
16
 
16
17
  spec.test_files = Dir[ "spec/*_spec.rb" ]
17
- spec.extra_rdoc_files = %w{README.md LICENSE COPYING GPLv2 GPLv3}
18
- spec.rdoc_options << '--title' << 'Prawn Documentation' <<
19
- '--main' << 'README.md' << '-q'
20
18
  spec.authors = ["Gregory Brown","Brad Ediger","Daniel Nelson","Jonathan Greenberg","James Healy"]
21
19
  spec.email = ["gregory.t.brown@gmail.com","brad@bradediger.com","dnelson@bluejade.com","greenberg@entryway.net","jimmy@deefa.com"]
22
20
  spec.rubyforge_project = "prawn"
21
+ spec.licenses = ['RUBY', 'GPL-2', 'GPL-3']
22
+
23
23
  spec.add_dependency('pdf-reader', '~>1.2')
24
24
  spec.add_dependency('ttfunk', '~>1.0.3')
25
25
  spec.add_dependency('ruby-rc4')
26
- spec.add_dependency('afm')
26
+
27
27
  spec.add_development_dependency('pdf-inspector', '~> 1.1.0')
28
28
  spec.add_development_dependency('coderay', '~> 1.0.7')
29
- spec.add_development_dependency('rdoc')
29
+ spec.add_development_dependency('yard')
30
+ spec.add_development_dependency('rspec')
31
+ spec.add_development_dependency('mocha')
32
+ spec.add_development_dependency('rake')
33
+
30
34
  spec.homepage = "http://prawn.majesticseacreature.com"
31
35
  spec.description = <<END_DESC
32
36
  Prawn is a fast, tiny, and nimble PDF generator for Ruby
@@ -378,6 +378,18 @@ describe "A canvas" do
378
378
  end
379
379
  @pdf.y.should == 450
380
380
  end
381
+
382
+ it "should restore the original ypos after execution", :issue => 523 do
383
+ doc = Prawn::Document.new(:skip_page_creation => true)
384
+ doc.start_new_page
385
+
386
+ original_ypos = doc.y
387
+
388
+ doc.canvas {}
389
+
390
+ doc.y.should == original_ypos
391
+ end
392
+
381
393
  end
382
394
 
383
395
  describe "Deep-copying" do
@@ -30,4 +30,36 @@ describe "A column box" do
30
30
  @pdf.bounds.right.should == 500
31
31
  end
32
32
  end
33
+
34
+ it "does not reset the top margin on a new page by default" do
35
+ create_pdf
36
+ page_top = @pdf.cursor
37
+ @pdf.move_down 50
38
+ init_column_top = @pdf.cursor
39
+ @pdf.column_box [0, @pdf.cursor], :width => 500,
40
+ :height => 200, :columns => 2 do
41
+
42
+ @pdf.bounds.move_past_bottom
43
+ @pdf.bounds.move_past_bottom
44
+
45
+ @pdf.bounds.absolute_top.should == init_column_top
46
+ @pdf.bounds.absolute_top.should_not == page_top
47
+ end
48
+ end
49
+
50
+ it "does reset the top margin when reflow_margins is set" do
51
+ create_pdf
52
+ page_top = @pdf.cursor
53
+ @pdf.move_down 50
54
+ init_column_top = @pdf.cursor
55
+ @pdf.column_box [0, @pdf.cursor], :width => 500, :reflow_margins => true,
56
+ :height => 200, :columns => 2 do
57
+
58
+ @pdf.bounds.move_past_bottom
59
+ @pdf.bounds.move_past_bottom
60
+
61
+ @pdf.bounds.absolute_top.should == page_top
62
+ @pdf.bounds.absolute_top.should_not == init_column_top
63
+ end
64
+ end
33
65
  end
@@ -447,13 +447,11 @@ describe "The group() feature" do
447
447
  end
448
448
 
449
449
  describe "The render() feature" do
450
- if "spec".respond_to?(:encode!)
451
- it "should return a 8 bit encoded string on a m17n aware VM" do
452
- @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
453
- @pdf.line [100,100], [200,200]
454
- str = @pdf.render
455
- str.encoding.to_s.should == "ASCII-8BIT"
456
- end
450
+ it "should return a 8 bit encoded string on a m17n aware VM" do
451
+ @pdf = Prawn::Document.new(:page_size => "A4", :page_layout => :landscape)
452
+ @pdf.line [100,100], [200,200]
453
+ str = @pdf.render
454
+ str.encoding.to_s.should == "ASCII-8BIT"
457
455
  end
458
456
 
459
457
  it "should trigger before_render callbacks just before rendering" do
@@ -1,10 +1,9 @@
1
1
  module EncodingHelpers
2
2
  def win1252_string(str)
3
- ruby_19 { str.force_encoding("Windows-1252") }
4
- str
3
+ str.force_encoding(Encoding::Windows_1252)
5
4
  end
6
5
 
7
6
  def bin_string(str)
8
- ruby_19 { str.force_encoding("ASCII-8BIT") } || ruby_18 { str }
7
+ str.force_encoding(Encoding::ASCII_8BIT)
9
8
  end
10
9
  end
data/spec/filters_spec.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
4
4
 
5
5
  FILTERS = {
6
- :FlateDecode => {'test' => ruby_19 { "x\x9C+I-.\x01\x00\x04]\x01\xC1".force_encoding(Encoding::ASCII_8BIT) } || "x\x9C+I-.\x01\x00\x04]\x01\xC1" },
6
+ :FlateDecode => {'test' => "x\x9C+I-.\x01\x00\x04]\x01\xC1".force_encoding(Encoding::ASCII_8BIT) },
7
7
  :DCTDecode => {'test' => "test"}
8
8
  }
9
9
 
data/spec/font_spec.rb CHANGED
@@ -80,8 +80,9 @@ describe "#width_of" do
80
80
  styled_bold_hello.should == @bold_hello
81
81
  end
82
82
 
83
- # This is not a fully confirmed bug report... needs further investigation
84
- it "should not treat minus as if it were a hyphen", :unresolved, :issue => 578 do
83
+ it "should not treat minus as if it were a hyphen", :issue => 578 do
84
+ create_pdf
85
+
85
86
  @pdf.width_of("-0.75").should be < @pdf.width_of("25.00")
86
87
  end
87
88
  end
@@ -20,19 +20,17 @@ describe "Text::Formatted::Box wrapping" do
20
20
 
21
21
  it "should not raise an Encoding::CompatibilityError when keeping a TTF and an " +
22
22
  "AFM font together" do
23
- ruby_19 do
24
- file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
25
- @pdf.font_families["Kai"] = {
26
- :normal => { :file => file, :font => "Kai" }
27
- }
23
+ file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
24
+ @pdf.font_families["Kai"] = {
25
+ :normal => { :file => file, :font => "Kai" }
26
+ }
28
27
 
29
- texts = [{ :text => "Hello " },
30
- { :text => "再见", :font => "Kai"},
31
- { :text => "World" }]
32
- text_box = Prawn::Text::Formatted::Box.new(texts, :document => @pdf, :width => @pdf.width_of("Hello World"))
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"))
33
32
 
34
- text_box.render
35
- end
33
+ text_box.render
36
34
  end
37
35
 
38
36
  it "should wrap between two fragments when the preceding fragment ends with white space" do
@@ -86,23 +84,14 @@ describe "Text::Formatted::Box wrapping" do
86
84
 
87
85
  describe "Unicode" do
88
86
  before do
89
- if RUBY_VERSION < '1.9'
90
- @reset_value = $KCODE
91
- $KCODE='u'
92
- else
93
- @reset_value = [Encoding.default_external, Encoding.default_internal]
94
- Encoding.default_external = Encoding::UTF_8
95
- Encoding.default_internal = Encoding::UTF_8
96
- end
87
+ @reset_value = [Encoding.default_external, Encoding.default_internal]
88
+ Encoding.default_external = Encoding::UTF_8
89
+ Encoding.default_internal = Encoding::UTF_8
97
90
  end
98
91
 
99
92
  after do
100
- if RUBY_VERSION < '1.9'
101
- $KCODE=@reset_value
102
- else
103
- Encoding.default_external = @reset_value[0]
104
- Encoding.default_internal = @reset_value[1]
105
- end
93
+ Encoding.default_external = @reset_value[0]
94
+ Encoding.default_internal = @reset_value[1]
106
95
  end
107
96
 
108
97
  it "should properly handle empty slices using Unicode encoding" do
@@ -478,6 +478,24 @@ describe "When using graphics states" do
478
478
  @pdf.restore_graphics_state
479
479
  }.should raise_error(PDF::Core::Errors::EmptyGraphicStateStack)
480
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
498
+ end
481
499
  end
482
500
 
483
501
  describe "When using transformation matrix" do
@@ -28,6 +28,18 @@ describe "ImageHandler" do
28
28
  handler.should == handler_b
29
29
  end
30
30
 
31
+ it "can unregister a handler" do
32
+ handler_b.expects(:can_render? => true)
33
+
34
+ image_handler.register(handler_a)
35
+ image_handler.register(handler_b)
36
+
37
+ image_handler.unregister(handler_a)
38
+
39
+ handler = image_handler.find('arbitrary blob')
40
+ handler.should == handler_b
41
+ end
42
+
31
43
  it "raises an error when no matching handler is found" do
32
44
  handler_a.expects(:can_render? => false)
33
45
  handler_b.expects(:can_render? => false)
data/spec/images_spec.rb CHANGED
@@ -83,16 +83,12 @@ describe "the image() function" do
83
83
  @pdf.state.version.should >= 1.5
84
84
  end
85
85
 
86
- # to support Adobe Reader, which apparently doesn't handle 16-bit alpha
87
- # channels. Verified experimentally [BE] but not confirmed in documentation
88
- # or anything. OS X Preview handles those files just fine.
89
- #
90
- it "should embed 8-bit alpha channels for 16-bit PNGs" do
86
+ it "should embed 16-bit alpha channels for 16-bit PNGs" do
91
87
  @pdf.image "#{Prawn::DATADIR}/images/16bit.png"
92
88
 
93
89
  output = @pdf.render
94
90
  output.should =~ /\/BitsPerComponent 16/
95
- output.should =~ /\/BitsPerComponent 8/
91
+ output.should_not =~ /\/BitsPerComponent 8/
96
92
  end
97
93
 
98
94
  it "should flow an image to a new page if it will not fit on a page" do
@@ -113,7 +113,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
113
113
  :width => @one_word_width,
114
114
  :document => @pdf)
115
115
  expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
116
- expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
116
+ expected.force_encoding(Encoding::UTF_8)
117
117
  string.should == expected
118
118
 
119
119
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
@@ -202,7 +202,7 @@ describe "Core::Text::Formatted::LineWrap#wrap_line" do
202
202
  :width => @one_word_width,
203
203
  :document => @pdf)
204
204
  expected = @pdf.font.normalize_encoding("hello#{Prawn::Text::SHY}")
205
- expected.force_encoding("utf-8") if "".respond_to?(:force_encoding)
205
+ expected.force_encoding(Encoding::UTF_8)
206
206
  string.should == expected
207
207
 
208
208
  @pdf.font("#{Prawn::DATADIR}/fonts/DejaVuSans.ttf")
@@ -82,6 +82,12 @@ describe "Prawn::ObjectStore" do
82
82
  end
83
83
  @store.map{|ref| ref.identifier}[-3..-1].should == [10, 11, 12]
84
84
  end
85
+
86
+ it "should accept option to disabling PDF scaling in PDF clients" do
87
+ @store = PDF::Core::ObjectStore.new(:print_scaling => :none)
88
+ @store.root.data[:ViewerPreferences].should == {:PrintScaling => :None}
89
+ end
90
+
85
91
  end
86
92
 
87
93
  describe "Prawn::ObjectStore#compact" do
data/spec/outline_spec.rb CHANGED
@@ -16,20 +16,20 @@ describe "Outline" do
16
16
  end
17
17
  end
18
18
  end
19
- if RUBY_VERSION >= "1.9"
20
- describe "outline encoding" do
21
- it "should store all outline titles as UTF-16" do
22
- render_and_find_objects
23
- @hash.values.each do |obj|
24
- if obj.is_a?(Hash) && obj[:Title]
25
- title = obj[:Title].dup
26
- title.force_encoding("UTF-16LE")
27
- title.valid_encoding?.should == true
28
- end
19
+
20
+ describe "outline encoding" do
21
+ it "should store all outline titles as UTF-16" do
22
+ render_and_find_objects
23
+ @hash.values.each do |obj|
24
+ if obj.is_a?(Hash) && obj[:Title]
25
+ title = obj[:Title].dup
26
+ title.force_encoding(Encoding::UTF_16LE)
27
+ title.valid_encoding?.should == true
29
28
  end
30
29
  end
31
30
  end
32
31
  end
32
+
33
33
  describe "#generate_outline" do
34
34
  before(:each) do
35
35
  render_and_find_objects
data/spec/png_spec.rb CHANGED
@@ -131,7 +131,7 @@ describe "When reading a greyscale+alpha PNG file (color type 4)" do
131
131
 
132
132
  before(:each) do
133
133
  @filename = "#{Prawn::DATADIR}/images/page_white_text.png"
134
- @data_filename = "#{Prawn::DATADIR}/images/page_white_text.dat"
134
+ @color_data_filename = "#{Prawn::DATADIR}/images/page_white_text.color"
135
135
  @alpha_data_filename = "#{Prawn::DATADIR}/images/page_white_text.alpha"
136
136
  @img_data = File.binread(@filename)
137
137
  end
@@ -151,14 +151,14 @@ describe "When reading a greyscale+alpha PNG file (color type 4)" do
151
151
  it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
152
152
  png = Prawn::Images::PNG.new(@img_data)
153
153
  png.split_alpha_channel!
154
- data = Zlib::Inflate.inflate(File.binread(@data_filename))
154
+ data = File.binread(@color_data_filename)
155
155
  png.img_data.should == data
156
156
  end
157
157
 
158
158
  it "should correctly extract the alpha channel data from the image data chunk" do
159
159
  png = Prawn::Images::PNG.new(@img_data)
160
160
  png.split_alpha_channel!
161
- data = Zlib::Inflate.inflate(File.binread(@alpha_data_filename))
161
+ data = File.binread(@alpha_data_filename)
162
162
  png.alpha_channel.should == data
163
163
  end
164
164
  end
@@ -167,7 +167,7 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
167
167
 
168
168
  before(:each) do
169
169
  @filename = "#{Prawn::DATADIR}/images/dice.png"
170
- @data_filename = "#{Prawn::DATADIR}/images/dice.dat"
170
+ @color_data_filename = "#{Prawn::DATADIR}/images/dice.color"
171
171
  @alpha_data_filename = "#{Prawn::DATADIR}/images/dice.alpha"
172
172
  @img_data = File.binread(@filename)
173
173
  end
@@ -187,17 +187,14 @@ describe "When reading an RGB+alpha PNG file (color type 6)" do
187
187
  it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
188
188
  png = Prawn::Images::PNG.new(@img_data)
189
189
  png.split_alpha_channel!
190
- data = Zlib::Inflate.inflate(File.binread(@data_filename))
191
- # compare decompressed rather than compressed image data
192
- # because JRuby's implementation of Zlib is different from MRI --
193
- # both generate valid gzipped data, but not bit-identical to each other
190
+ data = File.binread(@color_data_filename)
194
191
  png.img_data.should == data
195
192
  end
196
193
 
197
194
  it "should correctly extract the alpha channel data from the image data chunk" do
198
195
  png = Prawn::Images::PNG.new(@img_data)
199
196
  png.split_alpha_channel!
200
- data = Zlib::Inflate.inflate(File.binread(@alpha_data_filename))
197
+ data = File.binread(@alpha_data_filename)
201
198
  png.alpha_channel.should == data
202
199
  end
203
200
  end
@@ -206,7 +203,7 @@ describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
206
203
 
207
204
  before(:each) do
208
205
  @filename = "#{Prawn::DATADIR}/images/16bit.png"
209
- @data_filename = "#{Prawn::DATADIR}/images/16bit.dat"
206
+ @color_data_filename = "#{Prawn::DATADIR}/images/16bit.color"
210
207
  # alpha channel truncated to 8-bit
211
208
  @alpha_data_filename = "#{Prawn::DATADIR}/images/16bit.alpha"
212
209
  @img_data = File.binread(@filename)
@@ -227,14 +224,14 @@ describe "When reading a 16bit RGB+alpha PNG file (color type 6)" do
227
224
  it "should correctly return the raw image data (with no alpha channel) from the image data chunk" do
228
225
  png = Prawn::Images::PNG.new(@img_data)
229
226
  png.split_alpha_channel!
230
- data = Zlib::Inflate.inflate(File.binread(@data_filename))
227
+ data = File.binread(@color_data_filename)
231
228
  png.img_data.should == data
232
229
  end
233
230
 
234
231
  it "should correctly extract the alpha channel data from the image data chunk" do
235
232
  png = Prawn::Images::PNG.new(@img_data)
236
233
  png.split_alpha_channel!
237
- data = Zlib::Inflate.inflate(File.binread(@alpha_data_filename))
234
+ data = File.binread(@alpha_data_filename)
238
235
  png.alpha_channel.should == data
239
236
  end
240
237
  end