Class: Magick::RVG::Group

Inherits:
Object
  • Object
show all
Includes:
Describable, Duplicatable, Embellishable, Stylable, Transformable
Defined in:
lib/rvg/container.rb

Overview

Define a collection of shapes, text, etc. that can be reused. Group objects are containers. That is, styles and transforms defined on the group are used by contained objects such as shapes, text, and nested groups unless overridden by a nested container or the object itself. Groups can be reused with the RVG::UseConstructors#use method. Create groups within containers with the RVG::StructureConstructors#g method.

Example:

# All elements in the group will be translated by 50 in the
# x-direction and 10 in the y-direction.
rvg.g.translate(50, 10).styles(:stroke=>'red',:fill=>'none') do |grp|
    # The line will be red.
    grp.line(10,10, 20,20)
    # The circle will be blue.
    grp.circle(10, 20, 20).styles(:stroke=>'blue')
end

Instance Attribute Summary

Attributes included from Describable

#desc, #metadata, #title

Instance Method Summary collapse

Methods included from Duplicatable

#deep_copy

Methods included from ImageConstructors

#image

Methods included from UseConstructors

#use

Methods included from TextConstructors

#text

Methods included from ShapeConstructors

#circle, #ellipse, #line, #path, #polygon, #polyline, #rect

Methods included from StructureConstructors

#g, #rvg

Methods included from Transformable

#matrix, #rotate, #scale, #skewX, #skewY, #translate

Methods included from Stylable

#styles

Constructor Details

#initialize {|_self| ... } ⇒ Group

Returns a new instance of Group.

Yields:

  • (_self)

Yield Parameters:



59
60
61
62
63
# File 'lib/rvg/container.rb', line 59

def initialize
    super
    @content = Content.new
    yield(self) if block_given?
end

Instance Method Details

#<<(obj) ⇒ Object

Append an arbitrary object to the group’s content. Called by #use to insert a non-container object into a group.



80
81
82
# File 'lib/rvg/container.rb', line 80

def <<(obj)                     #:nodoc:
    @content << obj
end

#add_primitives(gc) ⇒ Object

:nodoc:



65
66
67
68
69
70
71
# File 'lib/rvg/container.rb', line 65

def add_primitives(gc)          #:nodoc:
    gc.push
    add_transform_primitives(gc)
    add_style_primitives(gc)
    @content.each { |element| element.add_primitives(gc) }
    gc.pop
end

#ref(x, y, width, height) ⇒ Object

Translate container according to #use arguments



74
75
76
# File 'lib/rvg/container.rb', line 74

def ref(x, y, width, height)    #:nodoc:
    translate(x, y) if x != 0 || y != 0
end