lib/RMagick.rb in rmagick4j-0.3.6 vs lib/RMagick.rb in rmagick4j-0.3.7
- old
+ new
@@ -1,6 +1,6 @@
-# $Id: RMagick.rb,v 1.72 2008/06/08 13:41:39 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
@@ -732,10 +756,12 @@
# Ruby-level Magick::Image methods
class Image
include Comparable
+ alias_method :affinity, :remap
+
# Provide an alternate version of Draw#annotate, for folks who
# want to find it in this class.
def annotate(draw, width, height, x, y, text, &block)
check_destroyed
draw.annotate(self, width, height, x, y, text, &block)
@@ -1407,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
@@ -1465,10 +1498,13 @@
# ImageList#map took over the "map" name. Use alternatives.
alias_method :__map__, :collect
alias_method :map!, :collect!
alias_method :__map__!, :collect!
+ # ImageMagic used affinity in 6.4.3, switch to remap in 6.4.4.
+ alias_method :affinity, :remap
+
def compact
current = get_current()
ilist = self.class.new
a = @images.compact
a.each {|image| ilist << image}
@@ -1569,15 +1605,15 @@
@scene = length - 1
self
end
# Initialize new instances
- def initialize(*filenames)
+ def initialize(*filenames, &block)
@images = []
@scene = nil
filenames.each { |f|
- Magick::Image.read(f).each { |n| @images << n }
+ Magick::Image.read(f, &block).each { |n| @images << n }
}
if length > 0
@scene = length - 1 # last image in array
end
self
@@ -1619,10 +1655,23 @@
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
# it up the line. Catch a NameError and emit a useful message.
def method_missing(methID, *args, &block)
@@ -1830,9 +1879,40 @@
end
alias_method :indexes, :values_at
alias_method :indices, :values_at
end # Magick::ImageList
+
+
+# Collects non-specific optional method arguments
+class OptionalMethodArguments
+ def initialize(img)
+ @img = img
+ end
+
+ # miscellaneous options like -verbose
+ def method_missing(mth, val)
+ @img.define(mth.to_s.tr('_', '-'), val)
+ end
+
+ # set(key, val) corresponds to -set option:key val
+ def define(key, val = nil)
+ @img.define(key, val)
+ end
+
+ # accepts Pixel object or color name
+ def highlight_color=(color)
+ color = @img.to_color(color) if color.respond_to?(:to_color)
+ @img.define("highlight-color", color)
+ end
+
+ # accepts Pixel object or color name
+ def lowlight_color=(color)
+ color = @img.to_color(color) if color.respond_to?(:to_color)
+ @img.define("lowlight-color", color)
+ end
+end
+
# Example fill class. Fills the image with the specified background
# color, then crosshatches with the specified crosshatch color.
# @dist is the number of pixels between hatch lines.
# See Magick::Draw examples.