Class Magick::RVG
In: lib/rvg/pathdata.rb
lib/rvg/describable.rb
lib/rvg/units.rb
lib/rvg/clippath.rb
lib/rvg/container.rb
lib/rvg/embellishable.rb
lib/rvg/misc.rb
lib/rvg/text.rb
lib/rvg/stylable.rb
lib/rvg/stretchable.rb
lib/rvg/paint.rb
lib/rvg/transformable.rb
lib/rvg/deep_equal.rb
lib/rvg/rvg.rb
Parent: Object
Enum GeometryValue Stylable RVG\n[lib/rvg/clippath.rb\nlib/rvg/container.rb\nlib/rvg/deep_equal.rb\nlib/rvg/describable.rb\nlib/rvg/embellishable.rb\nlib/rvg/misc.rb\nlib/rvg/paint.rb\nlib/rvg/pathdata.rb\nlib/rvg/rvg.rb\nlib/rvg/stretchable.rb\nlib/rvg/stylable.rb\nlib/rvg/text.rb\nlib/rvg/transformable.rb\nlib/rvg/units.rb] Transformable Stretchable Embellishable Describable Duplicatable Comparable Image ImageList Array Geometry HatchFill Draw lib/RMagick.rb lib/rvg/rvg.rb Magick Module: Magick

RVG is the main class in this library. All graphic elements must be contained within an RVG object.

Methods

Included Modules

Stylable Transformable Stretchable Embellishable Describable Duplicatable

Classes and Modules

Module Magick::RVG::Describable
Module Magick::RVG::Duplicatable
Module Magick::RVG::Embellishable
Module Magick::RVG::ImageConstructors
Module Magick::RVG::PreserveAspectRatio
Module Magick::RVG::ShapeConstructors
Module Magick::RVG::Stretchable
Module Magick::RVG::StructureConstructors
Module Magick::RVG::Stylable
Module Magick::RVG::TextConstructors
Module Magick::RVG::Transformable
Module Magick::RVG::UseConstructors
Module Magick::RVG::Utility
Class Magick::RVG::Circle
Class Magick::RVG::ClipPath
Class Magick::RVG::Ellipse
Class Magick::RVG::Group
Class Magick::RVG::Image
Class Magick::RVG::Line
Class Magick::RVG::Path
Class Magick::RVG::PathData
Class Magick::RVG::Pattern
Class Magick::RVG::PolyShape
Class Magick::RVG::Polygon
Class Magick::RVG::Polyline
Class Magick::RVG::Rect
Class Magick::RVG::Text
Class Magick::RVG::TextBase
Class Magick::RVG::Use

Constants

WORD_SEP = / /

Attributes

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
dpi  [R] 
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

centimeters

[Source]

    # File lib/rvg/units.rb, line 25
25:                         def cm
26:                             self * ::Magick::RVG.dpi / 2.54
27:                         end

[Source]

    # File lib/rvg/misc.rb, line 59
59:     def self.convert_one_to_float(arg)
60:         begin
61:             farg = Float(arg)
62:         rescue ArgumentError, TypeError
63:             raise ArgumentError, "argument cannot be converted to Float (got #{arg.class})"
64:         end
65:         return farg
66:     end

[Source]

    # File lib/rvg/misc.rb, line 45
45:     def self.convert_to_float(*args)
46:         allow_nil = false
47:         if args.last == :allow_nil
48:             allow_nil = true
49:             args.pop
50:         end
51:         begin
52:             fargs = args.collect { |a| (allow_nil && a.nil?) ? a : Float(a) }
53:         rescue ArgumentError, TypeError
54:             raise ArgumentError, self.fmsg(*args)
55:         end
56:         return fargs
57:     end

the default is deg

[Source]

    # File lib/rvg/units.rb, line 41
41:                         def deg
42:                             self
43:                         end

[Source]

    # File lib/rvg/units.rb, line 8
 8:         def dpi=(n)
 9:             if !defined?(@dpi)
10:                 [Float, Fixnum].each do |c|
11:                     c.class_eval do
12:                         # the default measurement - 1px is 1 pixel
13:                         def px
14:                             self
15:                         end
16:                         # inches
17:                         def in
18:                             self * ::Magick::RVG.dpi
19:                         end
20:                         # millimeters
21:                         def mm
22:                             self * ::Magick::RVG.dpi / 25.4
23:                         end
24:                         # centimeters
25:                         def cm
26:                             self * ::Magick::RVG.dpi / 2.54
27:                         end
28:                         # points
29:                         def pt
30:                             self * ::Magick::RVG.dpi / 72.0
31:                         end
32:                         # picas
33:                         def pc
34:                             self * ::Magick::RVG.dpi / 6.0
35:                         end
36:                         # percentage of the argument
37:                         def pct(of)
38:                             self * Float(of) / 100.0
39:                         end
40:                         # the default is deg
41:                         def deg
42:                             self
43:                         end
44:                         # radians -> degrees
45:                         def rad
46:                             self * 180.0 / Math::PI
47:                         end
48:                         # grads -> degrees
49:                         def grad
50:                             self * 9.0 / 10.0
51:                         end
52:                     end
53:                 end
54:             end
55: 
56:             @dpi = Float(n)
57:             return @dpi
58:         rescue ArgumentError
59:             raise TypeError, "Can't convert `#{n}' to Float"
60:         end

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

[Source]

    # File lib/rvg/misc.rb, line 41
41:     def self.fmsg(*args)
42:         "at least one argument cannot be converted to Float (got #{args.collect {|a| a.class}.join(', ')})"
43:     end

grads -> degrees

[Source]

    # File lib/rvg/units.rb, line 49
49:                         def grad
50:                             self * 9.0 / 10.0
51:                         end

inches

[Source]

    # File lib/rvg/units.rb, line 17
17:                         def in
18:                             self * ::Magick::RVG.dpi
19:                         end

millimeters

[Source]

    # File lib/rvg/units.rb, line 21
21:                         def mm
22:                             self * ::Magick::RVG.dpi / 25.4
23:                         end

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.

[Source]

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

picas

[Source]

    # File lib/rvg/units.rb, line 33
33:                         def pc
34:                             self * ::Magick::RVG.dpi / 6.0
35:                         end

percentage of the argument

[Source]

    # File lib/rvg/units.rb, line 37
37:                         def pct(of)
38:                             self * Float(of) / 100.0
39:                         end

points

[Source]

    # File lib/rvg/units.rb, line 29
29:                         def pt
30:                             self * ::Magick::RVG.dpi / 72.0
31:                         end

the default measurement - 1px is 1 pixel

[Source]

    # File lib/rvg/units.rb, line 13
13:                         def px
14:                             self
15:                         end

radians -> degrees

[Source]

    # File lib/rvg/units.rb, line 45
45:                         def rad
46:                             self * 180.0 / Math::PI
47:                         end

Public Instance methods

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

[Source]

     # File lib/rvg/rvg.rb, line 173
173:     def background_fill=(color)
174:         warn "background_fill= has no effect in nested RVG objects" if @nested
175:         if ! color.kind_of?(Magick::Pixel)
176:             begin
177:                 @background_fill = Magick::Pixel.from_color(color)
178:             rescue Magick::ImageMagickError
179:                 raise ArgumentError, "unknown color `#{color}'"
180:             rescue TypeError
181:                 raise TypeError, "cannot convert #{color.class} into Pixel"
182:             rescue
183:                 raise ArgumentError, "argument must be a color name or a Pixel (got #{color.class})"
184:             end
185:         else
186:             @background_fill = color
187:         end
188:     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.

[Source]

     # File lib/rvg/rvg.rb, line 192
192:     def background_fill_opacity=(opacity)
193:         warn "background_fill_opacity= has no effect in nested RVG objects" if @nested
194:         begin
195:             @background_fill_opacity = Float(opacity)
196:         rescue ArgumentError
197:             raise ArgumentError, "background_fill_opacity must be a number between 0 and 1 (#{opacity} given)"
198:         end
199:     end

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

[Source]

     # File lib/rvg/rvg.rb, line 140
140:     def background_image=(bg_image)
141:         warn "background_image= has no effect in nested RVG objects" if @nested
142:         if bg_image && ! bg_image.kind_of?(Magick::Image)
143:             raise ArgumentError, "background image must be an Image (got #{bg_image.class})"
144:         end
145:         @background_image = bg_image
146:     end

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.

[Source]

     # File lib/rvg/rvg.rb, line 151
151:     def background_pattern=(filler)
152:         warn "background_pattern= has no effect in nested RVG objects" if @nested
153:         @background_pattern = filler
154:     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.

[Source]

     # File lib/rvg/rvg.rb, line 162
162:     def background_position=(pos)
163:         warn "background_position= has no effect in nested RVG objects" if @nested
164:         bg_pos = pos.to_s.downcase
165:         if ! ['scaled', 'tiled', 'fit'].include?(bg_pos)
166:             raise ArgumentError, "background position must be `scaled', `tiled', or `fit' (#{pos} given)"
167:         end
168:         @background_position = bg_pos.to_sym
169:     end

[Source]

    # File lib/rvg/deep_equal.rb, line 17
17:             def deep_equal(other)
18:                 ivs = self.instance_variables
19: 
20:                 ivs.each do |iv|
21:                     itv = self.instance_variable_get(iv)
22:                     otv = other.instance_variable_get(iv)
23:                     if itv.respond_to?(:deep_equal)
24:                         if itv.equal?(otv)
25:                             puts "#{iv} has deep_equal but self.#{iv} and other.#{iv} are the same object."
26:                             return false
27:                         end
28:                         if !itv.deep_equal(otv)
29:                             puts "Not equal.\nself.#{iv}=#{itv.inspect}\nother.#{iv}=#{otv.inspect}"
30:                             return false
31:                         end
32:                     else
33:                         case itv
34:                             when Float, Symbol, TrueClass, FalseClass, Fixnum, NilClass
35:                                 return false if itv != otv
36:                             else
37:                                 if itv.equal?(otv)
38:                                     puts "#{iv} is dup-able but self.#{iv} and other.#{iv} are the same object."
39:                                     return false
40:                                 end
41:                                 if itv != otv
42:                                     puts "Not equal.\nself.#{iv}=#{itv.inspect}\nother.#{iv}=#{otv.inspect}"
43:                                     return false
44:                                 end
45:                         end
46:                     end
47:                 end
48: 
49:                 return true
50:             end

[Source]

    # File lib/rvg/deep_equal.rb, line 5
 5:             def deep_equal(other)
 6:                 if self != other
 7:                     puts "#{c.inspect} not equal.\nself:#{self} != other:#{other}"
 8:                     return false
 9:                 end
10:                 return true
11:             end

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

[Source]

     # File lib/rvg/rvg.rb, line 231
231:     def draw
232:         raise StandardError, "draw not permitted in nested RVG objects" if @nested
233:         @canvas ||= new_canvas    # allow drawing over existing canvas
234:         gc = Utility::GraphicContext.new
235:         add_outermost_primitives(gc)
236:         pp(self) if ENV['debug_rvg']
237:         print_gc(gc) if ENV['debug_prim']
238:         gc.draw(@canvas)
239:         return @canvas
240:     end

Private Instance methods

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

[Source]

    # File lib/rvg/rvg.rb, line 62
62:     def bgfill()
63:         if @background_fill.nil?
64:             color = Magick::Pixel.new(0,0,0,Magick::TransparentOpacity)
65:         else
66:             color = @background_fill
67:             color.opacity = (1.0 - @background_fill_opacity) * Magick::TransparentOpacity
68:         end
69:         return color
70:     end

[Source]

     # File lib/rvg/rvg.rb, line 72
 72:     def new_canvas
 73:         if @background_pattern
 74:             canvas = Magick::Image.new(@width, @height, @background_pattern)
 75:         elsif @background_image
 76:             if @width != @background_image.columns || @height != @background_image.rows
 77:                 canvas = case @background_position
 78:                     when :scaled
 79:                         @background_image.resize(@width, @height)
 80:                     when :tiled
 81:                         Magick::Image.new(@width, @height, Magick::TextureFill.new(@background_image))
 82:                     when :fit
 83:                         width, height = @width, @height
 84:                         bgcolor = bgfill()
 85:                         @background_image.change_geometry(Magick::Geometry.new(width, height)) do |new_cols, new_rows|
 86:                             bg_image = @background_image.resize(new_cols, new_rows)
 87:                             if bg_image.columns != width || bg_image.rows != height
 88:                                 bg = Magick::Image.new(width, height) { self.background_color = bgcolor }
 89:                                 bg_image = bg.composite!(bg_image, Magick::CenterGravity, Magick::OverCompositeOp)
 90:                             end
 91:                             bg_image
 92:                         end
 93:                 end
 94:             else
 95:                 canvas = @background_image.copy
 96:             end
 97:         else
 98:             bgcolor = bgfill()
 99:             canvas = Magick::Image.new(Integer(@width), Integer(@height)) { self.background_color = bgcolor }
100:         end
101:         canvas[:desc] = @desc if @desc
102:         canvas[:title] = @title if @title
103:         canvas[:metadata] = @metadata if @metadata
104:         return canvas
105:     end

[Source]

     # File lib/rvg/rvg.rb, line 108
108:         def print_gc(gc)
109:             primitives = gc.inspect.split(/\n/)
110:             indent = 0
111:             primitives.each do |cmd|
112:                 indent -= 1 if cmd['pop ']
113:                 print(('   '*indent), cmd, "\n")
114:                 indent += 1 if cmd['push ']
115:             end
116:         end

[Validate]