lib/rvg/rvg.rb in rmagick-2.13.4 vs lib/rvg/rvg.rb in rmagick-2.14.0

- old
+ new

@@ -26,11 +26,11 @@ # This software is OSI Certified Open Source Software. # OSI Certified is a certification mark of the Open Source Initiative. # #++############################################################################ -require 'RMagick' +require 'rmagick' require 'rvg/misc' require 'rvg/describable' require 'rvg/stylable' require 'rvg/transformable' require 'rvg/stretchable' @@ -46,11 +46,10 @@ # RVG is the main class in this library. All graphic elements # must be contained within an RVG object. module Magick class RVG - include Stylable include Transformable include Stretchable include Embellishable include Describable @@ -58,18 +57,18 @@ private # background_fill defaults to 'none'. If background_fill has been set to something # else, combine it with the background_fill_opacity. - def bgfill() + def bgfill if @background_fill.nil? color = Magick::Pixel.new(0,0,0,Magick::TransparentOpacity) else color = @background_fill color.opacity = (1.0 - @background_fill_opacity) * Magick::TransparentOpacity end - return color + color end def new_canvas if @background_pattern canvas = Magick::Image.new(@width, @height, @background_pattern) @@ -80,11 +79,11 @@ @background_image.resize(@width, @height) when :tiled Magick::Image.new(@width, @height, Magick::TextureFill.new(@background_image)) when :fit width, height = @width, @height - bgcolor = bgfill() + bgcolor = bgfill @background_image.change_geometry(Magick::Geometry.new(width, height)) do |new_cols, new_rows| bg_image = @background_image.resize(new_cols, new_rows) if bg_image.columns != width || bg_image.rows != height bg = Magick::Image.new(width, height) { self.background_color = bgcolor } bg_image = bg.composite!(bg_image, Magick::CenterGravity, Magick::OverCompositeOp) @@ -94,17 +93,17 @@ end else canvas = @background_image.copy end else - bgcolor = bgfill() + bgcolor = bgfill canvas = Magick::Image.new(Integer(@width), Integer(@height)) { self.background_color = bgcolor } end canvas[:desc] = @desc if @desc canvas[:title] = @title if @title canvas[:metadata] = @metadata if @metadata - return canvas + canvas end if ENV['debug_prim'] def print_gc(gc) primitives = gc.inspect.split(/\n/) @@ -137,45 +136,45 @@ attr_reader :y attr_reader :width, :height # Sets an image to use as the canvas background. See background_position= for layout options. def background_image=(bg_image) - warn "background_image= has no effect in nested RVG objects" if @nested - if bg_image && ! bg_image.kind_of?(Magick::Image) - raise ArgumentError, "background image must be an Image (got #{bg_image.class})" + warn 'background_image= has no effect in nested RVG objects' if @nested + if bg_image && !bg_image.is_a?(Magick::Image) + fail ArgumentError, "background image must be an Image (got #{bg_image.class})" end @background_image = bg_image end # Sets an object to use to fill the canvas background. # The object must have a <tt>fill</tt> method. See the <b>Fill Classes</b> # section in the RMagick doc for more information. def background_pattern=(filler) - warn "background_pattern= has no effect in nested RVG objects" if @nested + warn 'background_pattern= has no effect in nested RVG objects' if @nested @background_pattern = filler end # How to position the background image on the canvas. One of the following symbols: # [:scaled] Scale the image to the canvas width and height. # [:tiled] Tile the image across the canvas. # [:fit] Scale the image to fit within the canvas while retaining the # image proportions. Center the image on the canvas. Color any part of # the canvas not covered by the image with the background color. def background_position=(pos) - warn "background_position= has no effect in nested RVG objects" if @nested + warn 'background_position= has no effect in nested RVG objects' if @nested bg_pos = pos.to_s.downcase - if ! ['scaled', 'tiled', 'fit'].include?(bg_pos) - raise ArgumentError, "background position must be `scaled', `tiled', or `fit' (#{pos} given)" + unless ['scaled', 'tiled', 'fit'].include?(bg_pos) + fail ArgumentError, "background position must be `scaled', `tiled', or `fit' (#{pos} given)" end @background_position = bg_pos.to_sym end # Sets the canvas background color. Either a Magick::Pixel or a color name. # The default fill is "none", that is, transparent black. def background_fill=(color) - warn "background_fill= has no effect in nested RVG objects" if @nested - if ! color.kind_of?(Magick::Pixel) + warn 'background_fill= has no effect in nested RVG objects' if @nested + if !color.is_a?(Magick::Pixel) begin @background_fill = Magick::Pixel.from_color(color) rescue Magick::ImageMagickError raise ArgumentError, "unknown color `#{color}'" rescue TypeError @@ -189,11 +188,11 @@ end # Opacity of the background fill color, a number between 0.0 (transparent) and # 1.0 (opaque). The default is 1.0 when the background_fill= attribute has been set. def background_fill_opacity=(opacity) - warn "background_fill_opacity= has no effect in nested RVG objects" if @nested + warn 'background_fill_opacity= has no effect in nested RVG objects' if @nested begin @background_fill_opacity = Float(opacity) rescue ArgumentError raise ArgumentError, "background_fill_opacity must be a number between 0 and 1 (#{opacity} given)" end @@ -228,33 +227,33 @@ end # Construct a canvas or reuse an existing canvas. # Execute drawing commands. Return the canvas. def draw - raise StandardError, "draw not permitted in nested RVG objects" if @nested + fail StandardError, 'draw not permitted in nested RVG objects' if @nested @canvas ||= new_canvas # allow drawing over existing canvas gc = Utility::GraphicContext.new add_outermost_primitives(gc) pp(self) if ENV['debug_rvg'] print_gc(gc) if ENV['debug_prim'] gc.draw(@canvas) - return @canvas + @canvas end # Accept #use arguments. Use (x,y) to generate an additional translate. # Override @width and @height if new values are supplied. def ref(x, y, rw, rh) #:nodoc: - translate(x, y) if (x != 0 || y != 0) + translate(x, y) if x != 0 || y != 0 @width = rw if rw @height = rh if rh end # Used by Magick::Embellishable.rvg to set non-0 x- and y-coordinates def corner(x, y) #:nodoc: @nested = true @x, @y = Float(x), Float(y) - translate(@x, @y) if (@x != 0.0 || @y != 0.0) + translate(@x, @y) if @x != 0.0 || @y != 0.0 end # Primitives for the outermost RVG object def add_outermost_primitives(gc) #:nodoc: add_transform_primitives(gc) @@ -267,17 +266,15 @@ end # Primitives for nested RVG objects def add_primitives(gc) #:nodoc: if @width.nil? || @height.nil? - raise ArgumentError, "RVG width or height undefined" + fail ArgumentError, 'RVG width or height undefined' elsif @width == 0 || @height == 0 return self end gc.push add_outermost_primitives(gc) gc.pop end - end # end class RVG end # end module Magick -