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, 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 ].freeze
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
-
#background_pattern=(filler) ⇒ Object
Sets an object to use to fill the canvas background.
-
#draw ⇒ Object
Construct a canvas or reuse an existing canvas.
-
#initialize(width = nil, height = nil) {|_self| ... } ⇒ RVG
constructor
Draw a
widthxheightimage.
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.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/rvg/rvg.rb', line 189 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
.dpi ⇒ Object
Returns the value of attribute dpi.
10 11 12 |
# File 'lib/rvg/units.rb', line 10 def dpi @dpi end |
Instance Attribute Details
#background_fill ⇒ Object
The background fill color specified by background_fill=
104 105 106 |
# File 'lib/rvg/rvg.rb', line 104 def background_fill @background_fill end |
#background_fill_opacity ⇒ Object
The background fill color opacity specified by background_fill_opacity=
106 107 108 |
# File 'lib/rvg/rvg.rb', line 106 def background_fill_opacity @background_fill_opacity end |
#background_image ⇒ Object
The background image specified by background_image=
100 101 102 |
# File 'lib/rvg/rvg.rb', line 100 def background_image @background_image end |
#background_position ⇒ Object
The background image layout specified by background_position=
102 103 104 |
# File 'lib/rvg/rvg.rb', line 102 def background_position @background_position end |
#canvas ⇒ Object (readonly)
The image after drawing has completed
108 109 110 |
# File 'lib/rvg/rvg.rb', line 108 def canvas @canvas end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
113 114 115 |
# File 'lib/rvg/rvg.rb', line 113 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
113 114 115 |
# File 'lib/rvg/rvg.rb', line 113 def width @width end |
#x ⇒ Object (readonly)
For embedded RVG objects, the x-axis coordinate of the upper-left corner
110 111 112 |
# File 'lib/rvg/rvg.rb', line 110 def x @x end |
#y ⇒ Object (readonly)
For embedded RVG objects, the x-axis coordinate of the upper-left corner
112 113 114 |
# File 'lib/rvg/rvg.rb', line 112 def y @y end |
Class Method Details
.convert_one_to_float(arg) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/rvg/misc.rb', line 57 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
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rvg/misc.rb', line 43 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.
39 40 41 |
# File 'lib/rvg/misc.rb', line 39 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.
126 127 128 129 |
# File 'lib/rvg/rvg.rb', line 126 def background_pattern=(filler) warn 'background_pattern= has no effect in nested RVG objects' if @nested @background_pattern = filler end |
#draw ⇒ Object
Construct a canvas or reuse an existing canvas. Execute drawing commands. Return the canvas.
207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/rvg/rvg.rb', line 207 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 |