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



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

def initialize(width=nil, height=nil)
    super
    @width, @height = width, 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, @y = 0.0, 0.0
    @nested = false
    yield(self) if block_given?
end

Class Attribute Details

.dpiObject

Returns the value of attribute dpi.



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

def dpi
  @dpi
end

Instance Attribute Details

#background_fillObject

The background fill color specified by background_fill=



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

def background_fill
  @background_fill
end

#background_fill_opacityObject

The background fill color opacity specified by background_fill_opacity=



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

def background_fill_opacity
  @background_fill_opacity
end

#background_imageObject

The background image specified by background_image=



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

def background_image
  @background_image
end

#background_positionObject

The background image layout specified by background_position=



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

def background_position
  @background_position
end

#canvasObject (readonly)

The image after drawing has completed



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

def canvas
  @canvas
end

#heightObject (readonly)

Returns the value of attribute height.



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

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

#xObject (readonly)

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



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

def x
  @x
end

#yObject (readonly)

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



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

def y
  @y
end

Class Method Details

.convert_one_to_float(arg) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/rvg/misc.rb', line 60

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
    return farg
end

.convert_to_float(*args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rvg/misc.rb', line 46

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, self.fmsg(*args)
    end
    return 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.



42
43
44
# File 'lib/rvg/misc.rb', line 42

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



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

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



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

def add_primitives(gc)  #:nodoc:
    if @width.nil? || @height.nil?
        raise 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.



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

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



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

def corner(x, y)        #:nodoc:
    @nested = true
    @x, @y = Float(x), 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.

Raises:

  • (StandardError)


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

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)
    return @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.



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

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