Class: Magick::RVG

Inherits:
Object
  • Object
show all
Includes:
Describable, Duplicatable, Embellishable, Stretchable, Stylable, Transformable
Defined in:
lib/rvg/rvg.rb,
lib/rvg/misc.rb,
lib/rvg/misc.rb,
lib/rvg/misc.rb,
lib/rvg/text.rb,
lib/rvg/paint.rb,
lib/rvg/units.rb,
lib/rvg/clippath.rb,
lib/rvg/pathdata.rb,
lib/rvg/stylable.rb,
lib/rvg/container.rb,
lib/rvg/deep_equal.rb,
lib/rvg/describable.rb,
lib/rvg/stretchable.rb,
lib/rvg/embellishable.rb,
lib/rvg/transformable.rb

Defined Under Namespace

Modules: Describable, Duplicatable, Embellishable, ImageConstructors, PreserveAspectRatio, ShapeConstructors, Stretchable, StructureConstructors, Stylable, TextConstructors, Transformable, UseConstructors Classes: Circle, ClipPath, Ellipse, Group, Image, Line, Path, PathData, Pattern, PolyShape, Polygon, Polyline, Rect, Styles, Text, TextBase, Use, Utility

Constant Summary collapse

WORD_SEP =

Regexp to separate words

/ /
STYLES =

:stopdoc:

%i[
  clip_path clip_rule fill fill_opacity fill_rule font
  font_family font_size font_stretch font_style font_weight
  opacity stroke stroke_dasharray stroke_dashoffset stroke_linecap
  stroke_linejoin stroke_miterlimit stroke_opacity stroke_width
  text_anchor text_decoration
  glyph_orientation_vertical glyph_orientation_horizontal
  letter_spacing word_spacing baseline_shift writing_mode
]

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes included from Describable

#desc, #metadata, #title

Class Method Summary collapse

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 Stretchable

#viewbox

Methods included from PreserveAspectRatio

#preserve_aspect_ratio

Methods included from Transformable

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

Methods included from Stylable

#styles

Constructor Details

#initialize(width = nil, height = nil) {|_self| ... } ⇒ RVG

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.

Yields:

  • (_self)

Yield Parameters:

  • _self (Magick::RVG)

    the object that the method was called on



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/rvg/rvg.rb', line 213

def initialize(width = nil, height = nil)
  super
  @width = width
  @height = height
  @content = Content.new
  @canvas = nil
  @background_fill = nil
  @background_fill_opacity = 1.0 # applies only if background_fill= is used
  @background_position = :scaled
  @background_pattern, @background_image, @desc, @title, @metadata = nil
  @x = 0.0
  @y = 0.0
  @nested = false
  yield(self) if block_given?
end

Class Attribute Details

.dpiObject

Returns the value of attribute dpi.



7
8
9
# File 'lib/rvg/units.rb', line 7

def dpi
  @dpi
end

Instance Attribute Details

#background_fillObject

The background fill color specified by background_fill=



128
129
130
# File 'lib/rvg/rvg.rb', line 128

def background_fill
  @background_fill
end

#background_fill_opacityObject

The background fill color opacity specified by background_fill_opacity=



130
131
132
# File 'lib/rvg/rvg.rb', line 130

def background_fill_opacity
  @background_fill_opacity
end

#background_imageObject

The background image specified by background_image=



124
125
126
# File 'lib/rvg/rvg.rb', line 124

def background_image
  @background_image
end

#background_positionObject

The background image layout specified by background_position=



126
127
128
# File 'lib/rvg/rvg.rb', line 126

def background_position
  @background_position
end

#canvasObject (readonly)

The image after drawing has completed



132
133
134
# File 'lib/rvg/rvg.rb', line 132

def canvas
  @canvas
end

#heightObject (readonly)

Returns the value of attribute height.



137
138
139
# File 'lib/rvg/rvg.rb', line 137

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



137
138
139
# File 'lib/rvg/rvg.rb', line 137

def width
  @width
end

#xObject (readonly)

For embedded RVG objects, the x-axis coordinate of the upper-left corner



134
135
136
# File 'lib/rvg/rvg.rb', line 134

def x
  @x
end

#yObject (readonly)

For embedded RVG objects, the x-axis coordinate of the upper-left corner



136
137
138
# File 'lib/rvg/rvg.rb', line 136

def y
  @y
end

Class Method Details

.convert_one_to_float(arg) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/rvg/misc.rb', line 54

def self.convert_one_to_float(arg)
  begin
    farg = Float(arg)
  rescue ArgumentError, TypeError
    raise ArgumentError, "argument cannot be converted to Float (got #{arg.class})"
  end
  farg
end

.convert_to_float(*args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rvg/misc.rb', line 40

def self.convert_to_float(*args)
  allow_nil = false
  if args.last == :allow_nil
    allow_nil = true
    args.pop
  end
  begin
    fargs = args.map { |a| allow_nil && a.nil? ? a : Float(a) }
  rescue ArgumentError, TypeError
    raise ArgumentError, fmsg(*args)
  end
  fargs
end

.fmsg(*args) ⇒ Object

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



36
37
38
# File 'lib/rvg/misc.rb', line 36

def self.fmsg(*args)
  "at least one argument cannot be converted to Float (got #{args.map(&:class).join(', ')})"
end

Instance Method Details

#background_pattern=(filler) ⇒ Object

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.



150
151
152
153
# File 'lib/rvg/rvg.rb', line 150

def background_pattern=(filler)
  warn 'background_pattern= has no effect in nested RVG objects' if @nested
  @background_pattern = filler
end

#drawObject

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

Raises:

  • (StandardError)


231
232
233
234
235
236
237
238
239
240
241
# File 'lib/rvg/rvg.rb', line 231

def draw
  raise StandardError, 'draw not permitted in nested RVG objects' if @nested

  @canvas ||= new_canvas # allow drawing over existing canvas
  gc = Utility::GraphicContext.new
  add_outermost_primitives(gc)
  pp(self) if ENV['debug_rvg']
  print_gc(gc) if ENV['debug_prim']
  gc.draw(@canvas)
  @canvas
end