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/prawn.gemspec b/prawn.gemspec
index addd5e4ee..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.0")
+ spec.add_dependency('pdf-core', "~> 0.5.0")
spec.add_development_dependency('pdf-inspector', '~> 1.1.0')
spec.add_development_dependency('yard')
diff --git a/spec/graphics_spec.rb b/spec/graphics_spec.rb
index 91fea1b3a..7b862c3cc 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]
@@ -427,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 "should raise an error when dash is called w. a zero length or space" do
expect { @pdf.dash(0) }.to raise_error(ArgumentError)
expect { @pdf.dash([0]) }.to raise_error(ArgumentError)
@@ -434,7 +441,6 @@
expect { @pdf.dash([0,0,0,1]) }.to raise_error(ArgumentError)
end
-
it "the current graphic state should keep track of previous unchanged settings" do
@pdf.stroke_color '000000'
@pdf.save_graphics_state
diff --git a/spec/soft_mask_spec.rb b/spec/soft_mask_spec.rb
index 633d6a843..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
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