Class: Magick::RVG
- Inherits:
-
Object
- Object
- Magick::RVG
- 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
-
.dpi ⇒ Object
Returns the value of attribute dpi.
Instance Attribute Summary collapse
-
#background_fill ⇒ Object
The background fill color specified by background_fill=.
-
#background_fill_opacity ⇒ Object
The background fill color opacity specified by background_fill_opacity=.
-
#background_image ⇒ Object
The background image specified by background_image=.
-
#background_position ⇒ Object
The background image layout specified by background_position=.
-
#canvas ⇒ Object
readonly
The image after drawing has completed.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
For embedded RVG objects, the x-axis coordinate of the upper-left corner.
-
#y ⇒ Object
readonly
For embedded RVG objects, the x-axis coordinate of the upper-left corner.
Attributes included from Describable
Class Method Summary collapse
- .convert_one_to_float(arg) ⇒ Object
- .convert_to_float(*args) ⇒ Object
-
.fmsg(*args) ⇒ Object
Convert an array of method arguments to Float objects.
Instance Method Summary collapse
-
#add_outermost_primitives(gc) ⇒ Object
Primitives for the outermost RVG object.
-
#add_primitives(gc) ⇒ Object
Primitives for nested RVG objects.
-
#background_pattern=(filler) ⇒ Object
Sets an object to use to fill the canvas background.
-
#corner(x, y) ⇒ Object
Used by Magick::Embellishable.rvg to set non-0 x- and y-coordinates.
-
#draw ⇒ Object
Construct a canvas or reuse an existing canvas.
-
#initialize(width = nil, height = nil) {|_self| ... } ⇒ RVG
constructor
Draw a
width
xheight
image. -
#ref(x, y, rw, rh) ⇒ Object
Accept #use arguments.
Methods included from Duplicatable
Methods included from ImageConstructors
Methods included from UseConstructors
Methods included from TextConstructors
Methods included from ShapeConstructors
#circle, #ellipse, #line, #path, #polygon, #polyline, #rect
Methods included from StructureConstructors
Methods included from Stretchable
Methods included from PreserveAspectRatio
Methods included from Transformable
#matrix, #rotate, #scale, #skewX, #skewY, #translate
Methods included from Stylable
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.
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
.dpi ⇒ Object
Returns the value of attribute dpi.
8 9 10 |
# File 'lib/rvg/units.rb', line 8 def dpi @dpi end |
Instance Attribute Details
#background_fill ⇒ Object
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_opacity ⇒ Object
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_image ⇒ Object
The background image specified by background_image=
125 126 127 |
# File 'lib/rvg/rvg.rb', line 125 def background_image @background_image end |
#background_position ⇒ Object
The background image layout specified by background_position=
127 128 129 |
# File 'lib/rvg/rvg.rb', line 127 def background_position @background_position end |
#canvas ⇒ Object (readonly)
The image after drawing has completed
133 134 135 |
# File 'lib/rvg/rvg.rb', line 133 def canvas @canvas end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
138 139 140 |
# File 'lib/rvg/rvg.rb', line 138 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
138 139 140 |
# File 'lib/rvg/rvg.rb', line 138 def width @width end |
#x ⇒ Object (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 |
#y ⇒ Object (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 |
#draw ⇒ Object
Construct a canvas or reuse an existing canvas. Execute drawing commands. Return the canvas.
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 |