###### RMagick 2.9.1 User's Guide and Reference

# class RVG::Pattern < Object

## class methods

### new

RVG::Pattern.new(width=0, height=0, x=0, y=0) [ { |pattern| drawing method calls } ] -> pattern

#### Description

Creates a pattern that can be used with the `:fill` and `:stroke` styles.

Define the pattern in the associated block. The pattern can be composed of shapes, text, raster images, groups, and RVG objects. You can use the use method to include graphic objects in the pattern.

#### Arguments

width, height
  These arguments define the pattern viewport.
x, y
  Specify the starting offset of the pattern. The pattern will be repeated at x`+m*width` and y`+n*height` offsets.

#### Example

## instance methods

### g

pattern.g [{|grp| ...}] -> group

#### Description

Calls RVG::Group.new to construct a group and adds it to the pattern. Yields to a block if one is present, passing the new group as an argument.

#### Returns

Returns the new group, so `RVG::Group` methods can be chained to this method.

### image

pattern.image(raster_image, width=nil, height=nil, x=0, y=0) -> image

#### Description

Calls RVG::Image.new to construct an image and adds it to the pattern.

#### Returns

Returns the new image, so `RVG::Image` methods can be chained to this method.

### preserve_aspect_ratio

pattern.preserve_aspect_ratio(align, meet_or_slice='meet') [{|self| ...}] -> self

#### Description

If you use the viewbox method and the user coordinate system does not scale uniformly to the default coordinate system, 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.

#### Arguments

align
  When the value of the `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-alignment and a y-alignment. The values are shown in these lists:

  ###### x-alignment

  xMin
    align the minimum x value of the content with the left corner of the viewport.
  xMid
    vertically center the content within the viewport.
  xMax
    align the maximum x value of the content with the right corner of the viewport.

  ###### y-alignment

  YMin
    align the minimum y value of the content with the top of the viewport.
  YMid
    horizontally center the content within the viewport.
  YMax
    align the maximum y value of the content with the bottom of the viewport
meet_or_slice
  This argument can have one of these three values:
  'none'
    The content is scaled as necessary so that it fits exactly within the viewport. The aspect ratio is not maintained.
  'meet'
    The content is scaled as necessary so that the larger dimension exactly fits the viewport. There may be some unused space in the viewport. The aspect ratio is maintained.
  'slice'
    The content is scaled as necessary so that the smaller dimension exactly fits the viewport. Some of the content in the larger dimension may be cut off. The aspect ratio is maintained.

#### Example

See the RVG class example.

#### Returns

Self, so other `RVG::Pattern` methods can be chained to this method.

#### See Also

viewbox

### rvg

pattern.rvg(width, height, x=0, y=0) [{|new_rvg| ...}] -> pattern

#### Description

This method constructs a new RVG object and adds it to the pattern. 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.

#### Arguments

width, height
  Specifies the viewport width and height. The units are in the user coordinate system of the parent container.
x, y
  The x- and y-axis offsets of the viewport upper-left corner. The units are in the user coordinate system of the parent container.

#### Example

See the example for preserve_aspect_ratio in `class RVG`.

#### Returns

The `RVG` object, so other `RVG` methods can be chained to this method.

### text

pattern.text(x=0, y=0, text=nil) [{|text| ...}] -> text

#### Description

Calls RVG::Text.new to construct a text object and adds it to the pattern. Yields to a block if one is present, passing the new text object as an argument.

#### Returns

The `RVG::Text` object, so other `RVG::Text` methods can be chained to this method.

### use

pattern.use(obj, x=0, y=0, width=nil, height=nil) -> use

#### Description

Calls RVG::Use.new to constructs a `use` object and adds it to the pattern.

When the referenced argument is an 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`.

#### Examples

See RVG::Use.new

#### Returns

The `RVG::Use` object, so other `RVG::Use` methods can be chained to this method.

### viewbox

pattern.viewbox(min_x, min_y, width, height) [{|self| ...}] -> self

#### Description

The area of the pattern is called the viewport. By default the origin of the coordinate system for an pattern is (0,0). The user coordinates are pixels and the width and height are established by the width and height arguments to `RVG::Pattern.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.

#### Arguments

min_x, min_y
  The minimum x-coordinate and y-coordinate of the user coordinate system.
width, height
  The width and height of the user coordinate system.

#### Example

See the example for the `RVG` class.

#### Returns

Self, so other `RVG::Pattern` methods may be chained to `viewbox`.

#### See Also

preserve_aspect_ratio