In addition to the methods listed above, class
RVG
also implements the styles method, the shape methods and the transform methods.
RVG.new(width=nil, height=nil) [ { |canvas| drawing method calls } ] -> anRVG
Creates a container that can have its own coordinate system. Within the block, call drawing methods on canvas to render shapes, text, and raster images in the container.
An RVG object is always the outermost container for a drawing. Call the draw method on the returned RVG object to produce the final image.
If the RVG object is the outermost container, width and height are required and specify the width and height of the final drawing in pixels. You can call conversion methods to use units such as inches and millimeters instead of pixels.
Otherwise, width and height specify the area of the viewbox. If the RVG
object will be used as an argument to the use method, then width
and height may be omitted here, then
specified as arguments to use
.
An RVG object
See the tutorial for a simple
example. The image below demonstrates an advanced use of
RVG.new
. This example creates an RVG object that
draws an orange-and-green target. The width and height
arguments are omitted in the RVG.new
call.
Instead, the viewport width and height are specified as
arguments to 4 invocations of use. Each
use
specifies a different viewport size, so the
same RVG object draws 4 different-sized targets.
Click the image to see the example script.
canvas.background_fill = value
Specify a background fill color. The attribute value may be either a pixel or a color name. The default fill color is "#000000ff". This color is usually called "none". This attribute has no effect on nested RVG objects.
canvas.background_fill = 'white'
canvas.background_fill_opacity = value
Specify the opacity of the background fill color when the
background fill is not the
default. The value is a number between 0.0 (fully transparent)
and 1.0 (fully opaque). The default is 1.0. The attribute is
ignored unless background_fill
is specified. This
attribute has no effect on nested RVG objects.
canvas.background_fill = 'white' canvas.background_fill_opacity = 0.50
canvas.background_image = anImage
Specify an image to be used as the canvas background. The value is an Image object. This attribute has no effect on nested RVG objects.
canvas.background_image = Magick::Image.read('myBackground.gif').first
canvas.background_pattern = aFill
Specify an Fill object to fill the canvas background. This attribute has no effect on nested RVG objects.
canvas.background_pattern = Magick::GradientFill.new(0, 0, 0, 100, "#900", "#000")
canvas.background_position = pos
If the dimensions of the image specified by background_image do not exactly match the canvas dimensions, this attribute specifies how to position the image on the background. This attribute has no effect on nested RVG objects.
canvas.background_image = Magick::Image.read('myBackground.gif').first canvas.background_position = :scaled
rvg.canvas -> anImage
After the draw method has been used, returns the rendered image. This is the same image that draw returns.
An image
rvg.desc -> aString
rvg.desc = aString
desc
attribute to
assign a text description to the drawing. The description will
be assigned to the "desc" property of the resulting image. This
attribute has no effect on nested RVG objects.
rvg.height -> height
rvg.metadata -> aString
rvg.metadata = aString
metadata
attribute to
assign additional metadata to the drawing. The metadata string
will be assigned to the "metadata" property of the resulting
image. This attribute has no effect on nested RVG objects.
rvg.title -> aString
rvg.title = aString
title
attribute to
assign a title to the drawing. The title will be assigned to
the "title" property of the resulting image. This attribute has
no effect on nested RVG objects.
rvg.width -> width
rvg.x -> x-offset
If this RVG object is nested within another RVG object, returns the x-offset in user coordinates from the upper-left corner of the enclosing RVG object.
rvg.y -> y-offset
If this RVG object is nested within another RVG object, returns the y-offset in user coordinates from the upper-left corner of the enclosing RVG object.
rvg.draw -> anImage
Causes all the drawing objects that have been added to the canvas to be rendered.
Regardless of the order in which methods were called,
draw
executes the methods in this order:
viewbox
and
preserve_aspect_ratio
Nested groups and RVG objects also follow this sequence.
An image
img = rvg.draw img.write('myDrawing.jpg')
rvg.g [{|grp| ...}] -> aGroup
Calls RVG::Group.new to construct a group and adds it to the enclosing RVG object. Yields to a block if one is present, passing the new group as an argument.
Returns the new group, so RVG::Group
methods
can be chained to this method.
rvg.image(raster_image, width=nil, height=nil, x=0, y=0) -> anImage
Calls RVG::Image.new to construct an image and adds it to the enclosing RVG object.
Returns the new image, so RVG::Image
methods
can be chained to this method.
An RVG::Image
object is not the same
as a Magick::Image object!
rvg.preserve_aspect_ratio(align, meet_or_slice='meet') [{|self| ...}] -> self
If you use the viewbox method and
the user coordinate system does not scale uniformly to the
default coordinate system (for example, the width and height of
the RVG object is 4x3 and the user coordinate system is 16x9),
use the preserve_aspect_ratio
method to specify
whether or not the content is stretched to fit. If not, you can
specify how to fit the content into the space.
Preserve_aspect_ratio
yields to a block if one
is present, passing self as an
argument.
meet_or_slice
argument
is 'meet' or 'slice', this argument controls the placement
of the content within the viewport. The align
argument is the concatenation of an x-aligment and
a y-alignment. The values are shown in these
lists:
Self, so other RVG
methods can be chained to this method.
rvg.rvg(width, height, x=0, y=0) [{|new_rvg| ...}] -> anRVG
This method constructs a new RVG object and adds it to the
enclosing RVG object. Each nested RVG object can use the
viewbox method to define its own
coordinate system. The rvg
method yields to a
block, passing the nested RVG object as an argument. Within the
block, any drawing objects added to the nested RVG object are
rendered within the nested RVG object's viewport.
See the example for preserve_aspect_ratio.
The RVG
object, so other RVG
methods can be chained to this method.
rvg.text(x=0, y=0, text=nil) [{|aText| ...}] -> aText
Calls RVG::Text.new to construct a text object and adds it to the enclosing RVG object. Yields to a block if one is present, passing the new text object as an argument.
The RVG::Text
object, so other
RVG::Text
methods can be chained to this
method.
rvg.use(obj, x=0, y=0, width=nil, height=nil) -> aUse
Calls RVG::Use.new to
constructs a use
object and adds it to the RVG
object.
When the referenced argument is another RVG object,
width and height can be used to specify the width and height
of the viewport. If present and non-nil, these arguments
override any width and height specified when the RVG object was
created. You must specify the viewport size either when
creating the RVG object or when referencing it with
use
.
See RVG::Use.new
The RVG::Use
object, so other
RVG::Use
methods can be chained to this
method.
rvg.viewbox(min_x, min_y, width, height) [{|self| ...}] -> rvg
The area of the RVG object is called the viewport.
By default the origin of the coordinate system for an RVG
object is (0,0). The user coordinates are pixels and the width
and height are established by the width and height
arguments to RVG.new
.
Use the viewbox
method to superimpose a user
coordinate system on the viewport. The viewbox
method lets you set up a coordinate system using the units of
your choice.
The viewbox
method yields to a block if one is
present, passing self
as an argument.
In the following examples, because the viewbox
method specifies the dimensions of the coordinate system, the
dimensions specified for the graphic objects can remain the
same while the size of the canvas changes.
Rendered into a 300x200 viewport
Rendered into a 150x200 viewport
Self, so other RVG
methods may be chained to viewbox
.