Parent

Included Modules

Class Index [+]

Quicksearch

Magick::RVG

Constants

WORD_SEP

Attributes

dpi[R]
background_image[R]

The background image specified by background_image=

background_position[R]

The background image layout specified by background_position=

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=

canvas[R]

The image after drawing has completed

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

width[R]
height[R]

Public Class Methods

convert_one_to_float(arg) click to toggle source
    # File lib/rvg/misc.rb, line 60
60:         def self.convert_one_to_float(arg)
61:             begin
62:                 farg = Float(arg)
63:             rescue ArgumentError, TypeError
64:                 raise ArgumentError, "argument cannot be converted to Float (got #{arg.class})"
65:             end
66:             return farg
67:         end
convert_to_float(*args) click to toggle source
    # File lib/rvg/misc.rb, line 46
46:         def self.convert_to_float(*args)
47:             allow_nil = false
48:             if args.last == :allow_nil
49:                 allow_nil = true
50:                 args.pop
51:             end
52:             begin
53:                 fargs = args.collect { |a| (allow_nil && a.nil?) ? a : Float(a) }
54:             rescue ArgumentError, TypeError
55:                 raise ArgumentError, self.fmsg(*args)
56:             end
57:             return fargs
58:         end
dpi=(n) click to toggle source
    # File lib/rvg/units.rb, line 9
 9:             def dpi=(n)
10:                 if !defined?(@dpi)
11:                     [Float, Fixnum].each do |c|
12:                         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
13:                     end
14:                 end
15: 
16:                 @dpi = Float(n)
17:                 return @dpi
18:             rescue ArgumentError
19:                 raise TypeError, "Can't convert `#{n}' to Float"
20:             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
42:         def self.fmsg(*args)
43:             "at least one argument cannot be converted to Float (got #{args.collect {|a| a.class}.join(', ')})"
44:         end
new(width=nil, height=nil) 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 # method. By default the canvas is transparent. You can specify a different canvas with the # or # 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
216:         def initialize(width=nil, height=nil)
217:             super
218:             @width, @height = width, height
219:             @content = Content.new
220:             @canvas = nil
221:             @background_fill = nil
222:             @background_fill_opacity = 1.0  # applies only if background_fill= is used
223:             @background_position = :scaled
224:             @background_pattern, @background_image, @desc, @title, @metadata = nil
225:             @x, @y = 0.0, 0.0
226:             @nested = false
227:             yield(self) if block_given?
228:         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
174:         def background_fill=(color)
175:             warn "background_fill= has no effect in nested RVG objects" if @nested
176:             if ! color.kind_of?(Magick::Pixel)
177:                 begin
178:                     @background_fill = Magick::Pixel.from_color(color)
179:                 rescue Magick::ImageMagickError
180:                     raise ArgumentError, "unknown color `#{color}'"
181:                 rescue TypeError
182:                     raise TypeError, "cannot convert #{color.class} into Pixel"
183:                 rescue
184:                     raise ArgumentError, "argument must be a color name or a Pixel (got #{color.class})"
185:                 end
186:             else
187:                 @background_fill = color
188:             end
189:         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
193:         def background_fill_opacity=(opacity)
194:             warn "background_fill_opacity= has no effect in nested RVG objects" if @nested
195:             begin
196:                 @background_fill_opacity = Float(opacity)
197:             rescue ArgumentError
198:                 raise ArgumentError, "background_fill_opacity must be a number between 0 and 1 (#{opacity} given)"
199:             end
200:         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
141:         def background_image=(bg_image)
142:             warn "background_image= has no effect in nested RVG objects" if @nested
143:             if bg_image && ! bg_image.kind_of?(Magick::Image)
144:                 raise ArgumentError, "background image must be an Image (got #{bg_image.class})"
145:             end
146:             @background_image = bg_image
147:         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
152:         def background_pattern=(filler)
153:             warn "background_pattern= has no effect in nested RVG objects" if @nested
154:             @background_pattern = filler
155:         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
163:         def background_position=(pos)
164:             warn "background_position= has no effect in nested RVG objects" if @nested
165:             bg_pos = pos.to_s.downcase
166:             if ! ['scaled', 'tiled', 'fit'].include?(bg_pos)
167:                 raise ArgumentError, "background position must be `scaled', `tiled', or `fit' (#{pos} given)"
168:             end
169:             @background_position = bg_pos.to_sym
170:         end
deep_equal(other) click to toggle source
    # File lib/rvg/deep_equal.rb, line 18
18:                 def deep_equal(other)
19:                     ivs = self.instance_variables
20: 
21:                     ivs.each do |iv|
22:                         itv = self.instance_variable_get(iv)
23:                         otv = other.instance_variable_get(iv)
24:                         if itv.respond_to?(:deep_equal)
25:                             if itv.equal?(otv)
26:                                 puts "#{iv} has deep_equal but self.#{iv} and other.#{iv} are the same object."
27:                                 return false
28:                             end
29:                             if !itv.deep_equal(otv)
30:                                 puts "Not equal.\nself.#{iv}=#{itv.inspect}\nother.#{iv}=#{otv.inspect}"
31:                                 return false
32:                             end
33:                         else
34:                             case itv
35:                                 when Float, Symbol, TrueClass, FalseClass, Fixnum, NilClass
36:                                     return false if itv != otv
37:                                 else
38:                                     if itv.equal?(otv)
39:                                         puts "#{iv} is dup-able but self.#{iv} and other.#{iv} are the same object."
40:                                         return false
41:                                     end
42:                                     if itv != otv
43:                                         puts "Not equal.\nself.#{iv}=#{itv.inspect}\nother.#{iv}=#{otv.inspect}"
44:                                         return false
45:                                     end
46:                             end
47:                         end
48:                     end
49: 
50:                     return true
51:                 end
deep_equal(other) click to toggle source
    # File lib/rvg/deep_equal.rb, line 6
 6:                 def deep_equal(other)
 7:                     if self != other
 8:                         puts "#{c.inspect} not equal.\nself:#{self} != other:#{other}"
 9:                         return false
10:                     end
11:                     return true
12:                 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
232:         def draw
233:             raise StandardError, "draw not permitted in nested RVG objects" if @nested
234:             @canvas ||= new_canvas    # allow drawing over existing canvas
235:             gc = Utility::GraphicContext.new
236:             add_outermost_primitives(gc)
237:             pp(self) if ENV['debug_rvg']
238:             print_gc(gc) if ENV['debug_prim']
239:             gc.draw(@canvas)
240:             return @canvas
241:         end

Private Instance Methods

bgfill() click to toggle source

background_fill defaults to ‘none’. If background_fill has been set to something else, combine it with the background_fill_opacity.

    # File lib/rvg/rvg.rb, line 63
63:         def bgfill()
64:             if @background_fill.nil?
65:                 color = Magick::Pixel.new(0,0,0,Magick::TransparentOpacity)
66:             else
67:                 color = @background_fill
68:                 color.opacity = (1.0 - @background_fill_opacity) * Magick::TransparentOpacity
69:             end
70:             return color
71:         end
new_canvas() click to toggle source
     # File lib/rvg/rvg.rb, line 73
 73:         def new_canvas
 74:             if @background_pattern
 75:                 canvas = Magick::Image.new(@width, @height, @background_pattern)
 76:             elsif @background_image
 77:                 if @width != @background_image.columns || @height != @background_image.rows
 78:                     canvas = case @background_position
 79:                         when :scaled
 80:                             @background_image.resize(@width, @height)
 81:                         when :tiled
 82:                             Magick::Image.new(@width, @height, Magick::TextureFill.new(@background_image))
 83:                         when :fit
 84:                             width, height = @width, @height
 85:                             bgcolor = bgfill()
 86:                             @background_image.change_geometry(Magick::Geometry.new(width, height)) do |new_cols, new_rows|
 87:                                 bg_image = @background_image.resize(new_cols, new_rows)
 88:                                 if bg_image.columns != width || bg_image.rows != height
 89:                                     bg = Magick::Image.new(width, height) { self.background_color = bgcolor }
 90:                                     bg_image = bg.composite!(bg_image, Magick::CenterGravity, Magick::OverCompositeOp)
 91:                                 end
 92:                                 bg_image
 93:                             end
 94:                     end
 95:                 else
 96:                     canvas = @background_image.copy
 97:                 end
 98:             else
 99:                 bgcolor = bgfill()
100:                 canvas = Magick::Image.new(Integer(@width), Integer(@height)) { self.background_color = bgcolor }
101:             end
102:             canvas[:desc] = @desc if @desc
103:             canvas[:title] = @title if @title
104:             canvas[:metadata] = @metadata if @metadata
105:             return canvas
106:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.