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, TextLink, Transformable, UseConstructors Classes: Circle, ClipPath, Content, Ellipse, Group, Image, Line, Path, PathData, Pattern, PolyShape, Polygon, Polyline, Rect, Shape, Styles, Text, TextBase, Transforms, Tref, Tspan, Use, Utility

Constant Summary collapse

WORD_SEP =

Regexp to separate words

/ /
STYLES =

:stopdoc:

[: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



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

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



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

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



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

def self.convert_to_float(*args)
  allow_nil = false
  if args.last == :allow_nil
    allow_nil = true
    args.pop
  end
  begin
    fargs = args.collect { |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.



38
39
40
# File 'lib/rvg/misc.rb', line 38

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

Instance Method Details

#add_outermost_primitives(gc) ⇒ Object

Primitives for the outermost RVG object



261
262
263
264
265
266
267
268
269
# File 'lib/rvg/rvg.rb', line 261

def add_outermost_primitives(gc)    #:nodoc:
  add_transform_primitives(gc)
  gc.push
  add_viewbox_primitives(@width, @height, gc)
  add_style_primitives(gc)
  @content.each { |element| element.add_primitives(gc) }
  gc.pop
  self
end

#add_primitives(gc) ⇒ Object

Primitives for nested RVG objects



272
273
274
275
276
277
278
279
280
281
# File 'lib/rvg/rvg.rb', line 272

def add_primitives(gc)  #:nodoc:
  if @width.nil? || @height.nil?
    fail ArgumentError, 'RVG width or height undefined'
  elsif @width == 0 || @height == 0
    return self
  end
  gc.push
  add_outermost_primitives(gc)
  gc.pop
end

#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.



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

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

#corner(x, y) ⇒ Object

Used by Magick::Embellishable.rvg to set non-0 x- and y-coordinates



253
254
255
256
257
258
# File 'lib/rvg/rvg.rb', line 253

def corner(x, y)        #:nodoc:
  @nested = true
  @x = Float(x)
  @y = Float(y)
  translate(@x, @y) if @x != 0.0 || @y != 0.0
end

#drawObject

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



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

def draw
  fail 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

#ref(x, y, rw, rh) ⇒ Object

Accept #use arguments. Use (x,y) to generate an additional translate. Override @width and @height if new values are supplied.



246
247
248
249
250
# File 'lib/rvg/rvg.rb', line 246

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