class Magick::RVG

Constants

WORD_SEP

Attributes

dpi[R]
background_fill[R]

The background fill color specified by #background_fill=

background_fill_opacity[R]

The background fill color opacity specified by #background_fill_opacity=

background_image[R]

The background image specified by #background_image=

background_position[R]

The background image layout specified by #background_position=

canvas[R]

The image after drawing has completed

height[R]
width[R]
x[R]

For embedded RVG objects, the x-axis coordinate of the upper-left corner

y[R]

For embedded RVG objects, the x-axis coordinate of the upper-left corner

Public Class Methods

convert_one_to_float(arg) click to toggle source
# File lib/rvg/misc.rb, line 60
def self.convert_one_to_float(arg)
    begin
        farg = Float(arg)
    rescue ArgumentError, TypeError
        raise ArgumentError, "argument cannot be converted to Float (got #{arg.class})"
    end
    return farg
end
convert_to_float(*args) click to toggle source
# File lib/rvg/misc.rb, line 46
def self.convert_to_float(*args)
    allow_nil = false
    if args.last == :allow_nil
        allow_nil = true
        args.pop
    end
    begin
        fargs = args.collect { |a| (allow_nil && a.nil?) ? a : Float(a) }
    rescue ArgumentError, TypeError
        raise ArgumentError, self.fmsg(*args)
    end
    return fargs
end
dpi=(n) click to toggle source
# File lib/rvg/units.rb, line 9
            def dpi=(n)
                if !defined?(@dpi)
                    [Float, Fixnum].each do |c|
                        c.class_eval "                            # the default measurement - 1px is 1 pixel
                            def px
                                self
                            end
                            # inches
                            def in
                                self * ::Magick::RVG.dpi
                            end
                            # millimeters
                            def mm
                                self * ::Magick::RVG.dpi / 25.4
                            end
                            # centimeters
                            def cm
                                self * ::Magick::RVG.dpi / 2.54
                            end
                            # points
                            def pt
                                self * ::Magick::RVG.dpi / 72.0
                            end
                            # picas
                            def pc
                                self * ::Magick::RVG.dpi / 6.0
                            end
                            # percentage of the argument
                            def pct(of)
                                self * Float(of) / 100.0
                            end
                            # the default is deg
                            def deg
                                self
                            end
                            # radians -> degrees
                            def rad
                                self * 180.0 / Math::PI
                            end
                            # grads -> degrees
                            def grad
                                self * 9.0 / 10.0
                            end
"
                    end
                end

                @dpi = Float(n)
                return @dpi
            rescue ArgumentError
                raise TypeError, "Can't convert `#{n}' to Float"
            end
fmsg(*args) click to toggle source

Convert an array of method arguments to Float objects. If any cannot be converted, raise ArgumentError and issue a message.

# File lib/rvg/misc.rb, line 42
def self.fmsg(*args)
    "at least one argument cannot be converted to Float (got #{args.collect {|a| a.class}.join(', ')})"
end
new(width=nil, height=nil) { |self| ... } click to toggle source

Draw a width x height image. The image is specified by calling one or more drawing methods on the RVG object. You can group the drawing method calls in the optional associated block. The x and y arguments have no meaning for the outermost RVG object. On nested RVG objects [x, y] is the coordinate of the upper-left corner in the containing canvas on which the nested RVG object is placed.

Drawing occurs on a canvas created by the draw method. By default the canvas is transparent. You can specify a different canvas with the background_fill= or background_image= methods.

RVG objects are containers. That is, styles and transforms defined on the object are used by contained objects such as shapes, text, and groups unless overridden by an inner container or the object itself.

# File lib/rvg/rvg.rb, line 216
def initialize(width=nil, height=nil)
    super
    @width, @height = width, height
    @content = Content.new
    @canvas = nil
    @background_fill = nil
    @background_fill_opacity = 1.0  # applies only if background_fill= is used
    @background_position = :scaled
    @background_pattern, @background_image, @desc, @title, @metadata = nil
    @x, @y = 0.0, 0.0
    @nested = false
    yield(self) if block_given?
end

Public Instance Methods

background_fill=(color) click to toggle source

Sets the canvas background color. Either a Magick::Pixel or a color name. The default fill is “none”, that is, transparent black.

# File lib/rvg/rvg.rb, line 174
def background_fill=(color)
    warn "background_fill= has no effect in nested RVG objects" if @nested
    if ! color.kind_of?(Magick::Pixel)
        begin
            @background_fill = Magick::Pixel.from_color(color)
        rescue Magick::ImageMagickError
            raise ArgumentError, "unknown color `#{color}'"
        rescue TypeError
            raise TypeError, "cannot convert #{color.class} into Pixel"
        rescue
            raise ArgumentError, "argument must be a color name or a Pixel (got #{color.class})"
        end
    else
        @background_fill = color
    end
end
background_fill_opacity=(opacity) click to toggle source

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.

# File lib/rvg/rvg.rb, line 193
def background_fill_opacity=(opacity)
    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
end
background_image=(bg_image) click to toggle source

Sets an image to use as the canvas background. See #background_position= for layout options.

# File lib/rvg/rvg.rb, line 141
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})"
    end
    @background_image = bg_image
end
background_pattern=(filler) click to toggle source

Sets an object to use to fill the canvas background. The object must have a fill method. See the Fill Classes section in the RMagick doc for more information.

# File lib/rvg/rvg.rb, line 152
def background_pattern=(filler)
    warn "background_pattern= has no effect in nested RVG objects" if @nested
    @background_pattern = filler
end
background_position=(pos) click to toggle source

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.

# File lib/rvg/rvg.rb, line 163
def background_position=(pos)
    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)"
    end
    @background_position = bg_pos.to_sym
end
deep_equal(other) click to toggle source
# File lib/rvg/deep_equal.rb, line 6
def deep_equal(other)
    if self != other
        puts "#{c.inspect} not equal.\nself:#{self} != other:#{other}"
        return false
    end
    return true
end
draw() click to toggle source

Construct a canvas or reuse an existing canvas. Execute drawing commands. Return the canvas.

# File lib/rvg/rvg.rb, line 232
def draw
    raise 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
end