From 0f3ff6d078971ebf7d37ee32d2cebad83014e395 Mon Sep 17 00:00:00 2001 From: Gregory Brown Date: Mon, 6 Oct 2014 17:29:30 -0400 Subject: [PATCH 1/4] Fix failing tests --- Gemfile | 2 ++ prawn.gemspec | 2 +- spec/soft_mask_spec.rb | 2 +- spec/text_spacing_spec.rb | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 4c487543f..43ec5d543 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,7 @@ source "https://rubygems.org" +gem "pdf-core", :github => "prawnpdf/pdf-core", + :branch => "decimal-rounding" gemspec if ENV["CI"] diff --git a/prawn.gemspec b/prawn.gemspec index addd5e4ee..71c2772f2 100644 --- a/prawn.gemspec +++ b/prawn.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.licenses = ['RUBY', 'GPL-2', 'GPL-3'] spec.add_dependency('ttfunk', '~> 1.4.0') - spec.add_dependency('pdf-core', "~> 0.4.0") + spec.add_dependency('pdf-core', "~> 0.4.1") spec.add_development_dependency('pdf-inspector', '~> 1.1.0') spec.add_development_dependency('yard') diff --git a/spec/soft_mask_spec.rb b/spec/soft_mask_spec.rb index 633d6a843..1ef7ff29d 100644 --- a/spec/soft_mask_spec.rb +++ b/spec/soft_mask_spec.rb @@ -57,7 +57,7 @@ def make_soft_mask end extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates.first - 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" + 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" end it "should not create duplicate extended graphics states" do diff --git a/spec/text_spacing_spec.rb b/spec/text_spacing_spec.rb index db1cb3b02..2d034f5fe 100644 --- a/spec/text_spacing_spec.rb +++ b/spec/text_spacing_spec.rb @@ -9,7 +9,7 @@ @pdf.text("hello world") end contents = PDF::Inspector::Text.analyze(@pdf.render) - contents.character_spacing.first.should == 10.556 + contents.character_spacing.first.should == 10.5556 end it "should not draw the character spacing to the document" + " when the new character spacing matches the old" do @@ -63,7 +63,7 @@ @pdf.text("hello world") end contents = PDF::Inspector::Text.analyze(@pdf.render) - contents.word_spacing.first.should == 10.556 + contents.word_spacing.first.should == 10.5556 end it "should draw the word spacing to the document" + " when the new word spacing matches the old" do From dfe9a85d085ab5ebe9c836cd215291a7e96b1835 Mon Sep 17 00:00:00 2001 From: Gregory Brown Date: Fri, 10 Oct 2014 07:04:20 -0400 Subject: [PATCH 2/4] Let PDF::Core determine the level of decimal rounding precision --- lib/prawn/graphics.rb | 19 +++++++++++-------- lib/prawn/images.rb | 5 ++--- spec/graphics_spec.rb | 26 ++++++++++++++------------ spec/soft_mask_spec.rb | 2 +- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/lib/prawn/graphics.rb b/lib/prawn/graphics.rb index dbecca266..e22eeab19 100644 --- a/lib/prawn/graphics.rb +++ b/lib/prawn/graphics.rb @@ -46,8 +46,8 @@ module Graphics # pdf.move_to(100,50) # def move_to(*point) - x,y = map_to_absolute(point) - renderer.add_content("%.3f %.3f m" % [ x, y ]) + xy = PDF::Core.real_params(map_to_absolute(point)) + renderer.add_content("#{xy} m") end # Draws a line from the current drawing position to the specified point. @@ -57,8 +57,8 @@ def move_to(*point) # pdf.line_to(50,50) # def line_to(*point) - x,y = map_to_absolute(point) - renderer.add_content("%.3f %.3f l" % [ x, y ]) + xy = PDF::Core.real_params(map_to_absolute(point)) + renderer.add_content("#{xy} l") end # Draws a Bezier curve from the current drawing position to the @@ -71,9 +71,10 @@ def curve_to(dest,options={}) "Bounding points for bezier curve must be specified "+ "as :bounds => [[x1,y1],[x2,y2]]" - curve_points = (options[:bounds] << dest).map { |e| map_to_absolute(e) } - renderer.add_content("%.3f %.3f %.3f %.3f %.3f %.3f c" % - curve_points.flatten ) + curve_points = PDF::Core.real_params( + (options[:bounds] << dest).flat_map { |e| map_to_absolute(e) }) + + renderer.add_content("#{curve_points} c") end # Draws a rectangle given point, width and @@ -83,7 +84,9 @@ def curve_to(dest,options={}) # def rectangle(point,width,height) x,y = map_to_absolute(point) - renderer.add_content("%.3f %.3f %.3f %.3f re" % [ x, y - height, width, height ]) + box = PDF::Core.real_params([x, y - height, width, height]) + + renderer.add_content("#{box} re") end # Draws a rounded rectangle given point, width and diff --git a/lib/prawn/images.rb b/lib/prawn/images.rb index 3c6a8924e..cad2a79da 100644 --- a/lib/prawn/images.rb +++ b/lib/prawn/images.rb @@ -121,9 +121,8 @@ def embed_image(pdf_obj, info, options) label = "I#{next_image_id}" state.page.xobjects.merge!(label => pdf_obj) - # add the image to the current page - instruct = "\nq\n%.3f 0 0 %.3f %.3f %.3f cm\n/%s Do\nQ" - renderer.add_content instruct % [ w, h, x, y - h, label ] + cm_params = PDF::Core.real_params([ w, 0, 0, h, x, y - h]) + renderer.add_content("\nq\n#{cm_params} cm\n/#{label} Do\nQ") end private diff --git a/spec/graphics_spec.rb b/spec/graphics_spec.rb index e2603a9d7..44c8f016c 100644 --- a/spec/graphics_spec.rb +++ b/spec/graphics_spec.rb @@ -143,10 +143,12 @@ end it "should draw a rectangle by connecting lines with rounded bezier curves" do - @all_coords.should == [[60.0, 550.0],[90.0, 550.0], [95.523, 550.0], [100.0, 545.523], [100.0, 540.0], - [100.0, 460.0], [100.0, 454.477], [95.523, 450.0], [90.0, 450.0], - [60.0, 450.0], [54.477, 450.0], [50.0, 454.477], [50.0, 460.0], - [50.0, 540.0], [50.0, 545.523], [54.477, 550.0], [60.0, 550.0]] + @all_coords.should == [[60.0, 550.0],[90.0, 550.0], [95.5228, 550.0], + [100.0, 545.5228], [100.0, 540.0], [100.0, 460.0], + [100.0, 454.4772], [95.5228, 450.0], [90.0, 450.0], + [60.0, 450.0], [54.4772, 450.0], [50.0, 454.4772], + [50.0, 460.0], [50.0, 540.0], [50.0, 545.5228], + [54.4772, 550.0], [60.0, 550.0]] end it "should start and end with the same point" do @@ -167,20 +169,20 @@ @curve.coords.should == [125.0, 100.0, - 125.0, 127.614, - 113.807, 150, + 125.0, 127.6142, + 113.8071, 150, 100.0, 150.0, - 86.193, 150.0, - 75.0, 127.614, + 86.1929, 150.0, + 75.0, 127.6142, 75.0, 100.0, - 75.0, 72.386, - 86.193, 50.0, + 75.0, 72.3858, + 86.1929, 50.0, 100.0, 50.0, - 113.807, 50.0, - 125.0, 72.386, + 113.8071, 50.0, + 125.0, 72.3858, 125.0, 100.0, 100.0, 100.0] diff --git a/spec/soft_mask_spec.rb b/spec/soft_mask_spec.rb index 1ef7ff29d..e7b9eb03f 100644 --- a/spec/soft_mask_spec.rb +++ b/spec/soft_mask_spec.rb @@ -57,7 +57,7 @@ def make_soft_mask end extgstate = PDF::Inspector::ExtGState.analyze(@pdf.render).extgstates.first - 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" + 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" end it "should not create duplicate extended graphics states" do From 207ede4bf680191e763ac5ad25497253caf4e5be Mon Sep 17 00:00:00 2001 From: Gregory Brown Date: Fri, 10 Oct 2014 08:18:56 -0400 Subject: [PATCH 3/4] Cover dash rounding w. a test --- spec/graphics_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/graphics_spec.rb b/spec/graphics_spec.rb index 44c8f016c..c4fa425ad 100644 --- a/spec/graphics_spec.rb +++ b/spec/graphics_spec.rb @@ -429,6 +429,11 @@ @pdf.graphic_state.dash[:dash].should == 5 end + it "should round dash values to four decimal places" do + @pdf.dash 5.12345 + @pdf.graphic_state.dash_setting.should == "[5.1235 5.1235] 0.0 d" + end + it "the current graphic state should keep track of previous unchanged settings" do @pdf.stroke_color '000000' @pdf.save_graphics_state From 05f6cd84e74aed8c1cc2321cadca7d2316ad12fb Mon Sep 17 00:00:00 2001 From: Gregory Brown Date: Fri, 17 Oct 2014 08:25:50 -0400 Subject: [PATCH 4/4] Depend on released version of PDF::Core --- Gemfile | 2 -- prawn.gemspec | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 43ec5d543..4c487543f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,5 @@ source "https://rubygems.org" -gem "pdf-core", :github => "prawnpdf/pdf-core", - :branch => "decimal-rounding" gemspec if ENV["CI"] diff --git a/prawn.gemspec b/prawn.gemspec index 71c2772f2..09cdc1d24 100644 --- a/prawn.gemspec +++ b/prawn.gemspec @@ -25,7 +25,7 @@ Gem::Specification.new do |spec| spec.licenses = ['RUBY', 'GPL-2', 'GPL-3'] spec.add_dependency('ttfunk', '~> 1.4.0') - spec.add_dependency('pdf-core', "~> 0.4.1") + spec.add_dependency('pdf-core', "~> 0.5.0") spec.add_development_dependency('pdf-inspector', '~> 1.1.0') spec.add_development_dependency('yard')