lib/RMagick.rb in rmagick-2.8.0 vs lib/RMagick.rb in rmagick-2.9.0

- old
+ new

@@ -1,6 +1,6 @@ -# $Id: RMagick.rb,v 1.76 2008/10/27 22:17:54 rmagick Exp $ +# $Id: RMagick.rb,v 1.80 2009/01/02 21:08:14 rmagick Exp $ #============================================================================== # Copyright (C) 2008 by Timothy P. Hunter # Name: RMagick.rb # Author: Tim Hunter # Purpose: Extend Ruby to interface with ImageMagick. @@ -362,10 +362,34 @@ Kernel.raise ArgumentError, "Unknown text positioning gravity" end primitive "gravity #{GRAVITY_NAMES[grav.to_i]}" end + # IM 6.4.8-3 and later + def interword_spacing(space) + begin + Float(space) + rescue ArgumentError + Kernel.raise ArgumentError, "invalid value for interword_spacing" + rescue TypeError + Kernel.raise TypeError, "can't convert #{space.class} into Float" + end + primitive "interword-spacing #{space}" + end + + # IM 6.4.8-3 and later + def kerning(space) + begin + Float(space) + rescue ArgumentError + Kernel.raise ArgumentError, "invalid value for kerning" + rescue TypeError + Kernel.raise TypeError, "can't convert #{space.class} into Float" + end + primitive "kerning #{space}" + end + # Draw a line def line(startX, startY, endX, endY) primitive "line " + sprintf("%g,%g %g,%g", startX, startY, endX, endY) end @@ -1409,19 +1433,26 @@ end return obj end [:at, :each, :each_index, :empty?, :fetch, - :first, :hash, :include?, :index, :length, :nitems, :rindex, :sort!].each do |mth| + :first, :hash, :include?, :index, :length, :rindex, :sort!].each do |mth| module_eval <<-END_SIMPLE_DELEGATES def #{mth}(*args, &block) @images.#{mth}(*args, &block) end END_SIMPLE_DELEGATES end alias_method :size, :length + # Array#nitems is not available in 1.9 + if Array.instance_methods.include?("nitems") + def nitems() + @images.nitems() + end + end + def clear @scene = nil @images.clear end @@ -1622,9 +1653,22 @@ a.each {|img| ilist << img} @scene = a.length - 1 a = ilist end return a + end + + # Custom marshal/unmarshal for Ruby 1.8. + def marshal_dump() + ary = [@scene] + @images.each {|i| ary << Marshal.dump(i)} + ary + end + + def marshal_load(ary) + @scene = ary.shift + @images = [] + ary.each {|a| @images << Marshal.load(a)} end # The ImageList class supports the Magick::Image class methods by simply sending # the method to the current image. If the method isn't explicitly supported, # send it to the current image in the array. If there are no images, send