| Class | Magick::Draw |
| In: |
lib/RMagick.rb
|
| Parent: | Object |
| ALIGN_TYPE_NAMES | = | { LeftAlign.to_i => 'left', RightAlign.to_i => 'right', CenterAlign.to_i => 'center' | Thse hashes are used to map Magick constant values to the strings used in the primitives. | |
| ANCHOR_TYPE_NAMES | = | { StartAnchor.to_i => 'start', MiddleAnchor.to_i => 'middle', EndAnchor.to_i => 'end' | ||
| DECORATION_TYPE_NAMES | = | { NoDecoration.to_i => 'none', UnderlineDecoration.to_i => 'underline', OverlineDecoration.to_i => 'overline', LineThroughDecoration.to_i => 'line-through' | ||
| FONT_WEIGHT_NAMES | = | { AnyWeight.to_i => 'all', NormalWeight.to_i => 'normal', BoldWeight.to_i => 'bold', BolderWeight.to_i => 'bolder', LighterWeight.to_i => 'lighter', } | ||
| GRAVITY_NAMES | = | { NorthWestGravity.to_i => 'northwest', NorthGravity.to_i => 'north', NorthEastGravity.to_i => 'northeast', WestGravity.to_i => 'west', CenterGravity.to_i => 'center', EastGravity.to_i => 'east', SouthWestGravity.to_i => 'southwest', SouthGravity.to_i => 'south', SouthEastGravity.to_i => 'southeast' | ||
| PAINT_METHOD_NAMES | = | { PointMethod.to_i => 'point', ReplaceMethod.to_i => 'replace', FloodfillMethod.to_i => 'floodfill', FillToBorderMethod.to_i => 'filltoborder', ResetMethod.to_i => 'reset' | ||
| STRETCH_TYPE_NAMES | = | { NormalStretch.to_i => 'normal', UltraCondensedStretch.to_i => 'ultra-condensed', ExtraCondensedStretch.to_i => 'extra-condensed', CondensedStretch.to_i => 'condensed', SemiCondensedStretch.to_i => 'semi-condensed', SemiExpandedStretch.to_i => 'semi-expanded', ExpandedStretch.to_i => 'expanded', ExtraExpandedStretch.to_i => 'extra-expanded', UltraExpandedStretch.to_i => 'ultra-expanded', AnyStretch.to_i => 'all' | ||
| STYLE_TYPE_NAMES | = | { NormalStyle.to_i => 'normal', ItalicStyle.to_i => 'italic', ObliqueStyle.to_i => 'oblique', AnyStyle.to_i => 'all' |
Apply coordinate transformations to support scaling (s), rotation ®, and translation (t). Angles are specified in radians.
# File lib/RMagick.rb, line 180
180: def affine(sx, rx, ry, sy, tx, ty)
181: primitive "affine " + sprintf("%g,%g,%g,%g,%g,%g", sx, rx, ry, sy, tx, ty)
182: end
Draw a bezier curve.
# File lib/RMagick.rb, line 191
191: def bezier(*points)
192: if points.length == 0
193: raise ArgumentError, "no points specified"
194: elsif points.length % 2 != 0
195: raise ArgumentError, "odd number of arguments specified"
196: end
197: primitive "bezier " + points.join(',')
198: end
Invoke a clip-path defined by def_clip_path.
# File lib/RMagick.rb, line 206
206: def clip_path(name)
207: primitive "clip-path #{name}"
208: end
Define the clipping rule.
# File lib/RMagick.rb, line 211
211: def clip_rule(rule)
212: if ( not ["evenodd", "nonzero"].include?(rule.downcase) )
213: raise ArgumentError, "Unknown clipping rule #{rule}"
214: end
215: primitive "clip-rule #{rule}"
216: end
Define the clip units
# File lib/RMagick.rb, line 219
219: def clip_units(unit)
220: if ( not ["userspace", "userspaceonuse", "objectboundingbox"].include?(unit.downcase) )
221: raise ArgumentError, "Unknown clip unit #{unit}"
222: end
223: primitive "clip-units #{unit}"
224: end
Set color in image according to specified colorization rule. Rule is one of point, replace, floodfill, filltoborder,reset
# File lib/RMagick.rb, line 228
228: def color(x, y, method)
229: if ( not PAINT_METHOD_NAMES.has_key?(method.to_i) )
230: raise ArgumentError, "Unknown PaintMethod: #{method}"
231: end
232: primitive "color #{x},#{y},#{PAINT_METHOD_NAMES[method.to_i]}"
233: end
Specify EITHER the text decoration (none, underline, overline, line-through) OR the text solid background color (any color name or spec)
# File lib/RMagick.rb, line 237
237: def decorate(decoration)
238: if ( DECORATION_TYPE_NAMES.has_key?(decoration.to_i) )
239: primitive "decorate #{DECORATION_TYPE_NAMES[decoration.to_i]}"
240: else
241: primitive "decorate #{enquote(decoration)}"
242: end
243: end
Define a clip-path. A clip-path is a sequence of primitives bracketed by the "push clip-path <name>" and "pop clip-path" primitives. Upon advice from the IM guys, we also bracket the clip-path primitives with "push(pop) defs" and "push (pop) graphic-context".
# File lib/RMagick.rb, line 250
250: def define_clip_path(name)
251: begin
252: push('defs')
253: push('clip-path ', name)
254: push('graphic-context')
255: yield
256: ensure
257: pop('graphic-context')
258: pop('clip-path')
259: pop('defs')
260: end
261: end
Let anything through, but the only defined argument is "UTF-8". All others are apparently ignored.
# File lib/RMagick.rb, line 271
271: def encoding(encoding)
272: primitive "encoding #{encoding}"
273: end
Specify object fill, a color name or pattern name
# File lib/RMagick.rb, line 276
276: def fill(colorspec)
277: primitive "fill #{enquote(colorspec)}"
278: end
Specify fill opacity (use "xx%" to indicate percentage)
# File lib/RMagick.rb, line 283
283: def fill_opacity(opacity)
284: primitive "fill-opacity #{opacity}"
285: end
# File lib/RMagick.rb, line 287
287: def fill_rule(rule)
288: if ( not ["evenodd", "nonzero"].include?(rule.downcase) )
289: raise ArgumentError, "Unknown fill rule #{rule}"
290: end
291: primitive "fill-rule #{rule}"
292: end
Specify text drawing font
# File lib/RMagick.rb, line 295
295: def font(name)
296: primitive "font #{name}"
297: end
# File lib/RMagick.rb, line 299
299: def font_family(name)
300: primitive "font-family \'#{name}\'"
301: end
# File lib/RMagick.rb, line 303
303: def font_stretch(stretch)
304: if ( not STRETCH_TYPE_NAMES.has_key?(stretch.to_i) )
305: raise ArgumentError, "Unknown stretch type"
306: end
307: primitive "font-stretch #{STRETCH_TYPE_NAMES[stretch.to_i]}"
308: end
# File lib/RMagick.rb, line 310
310: def font_style(style)
311: if ( not STYLE_TYPE_NAMES.has_key?(style.to_i) )
312: raise ArgumentError, "Unknown style type"
313: end
314: primitive "font-style #{STYLE_TYPE_NAMES[style.to_i]}"
315: end
The font weight argument can be either a font weight constant or [100,200,…,900]
# File lib/RMagick.rb, line 319
319: def font_weight(weight)
320: if ( FONT_WEIGHT_NAMES.has_key?(weight.to_i) )
321: primitive "font-weight #{FONT_WEIGHT_NAMES[weight.to_i]}"
322: else
323: primitive "font-weight #{weight}"
324: end
325: end
Specify the text positioning gravity, one of: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast
# File lib/RMagick.rb, line 329
329: def gravity(grav)
330: if ( not GRAVITY_NAMES.has_key?(grav.to_i) )
331: raise ArgumentError, "Unknown text positioning gravity"
332: end
333: primitive "gravity #{GRAVITY_NAMES[grav.to_i]}"
334: end
Set matte (make transparent) in image according to the specified colorization rule
# File lib/RMagick.rb, line 343
343: def matte(x, y, rule)
344: if ( not PAINT_METHOD_NAMES.has_key?(method.to_i) )
345: raise ArgumentError, "Unknown paint method"
346: end
347: primitive "matte #{x},#{y} #{PAINT_METHOD_NAMES[method.to_i]}"
348: end
Specify drawing fill and stroke opacities. If the value is a string ending with a %, the number will be multiplied by 0.01.
# File lib/RMagick.rb, line 352
352: def opacity(opacity)
353: if (Numeric === opacity)
354: if (opacity < 0 || opacity > 1.0)
355: raise ArgumentError, "opacity must be >= 0 and <= 1.0"
356: end
357: end
358: primitive "opacity #{opacity}"
359: end
Define a pattern. In the block, call primitive methods to draw the pattern. Reference the pattern by using its name as the argument to the ‘fill’ or ‘stroke’ methods
# File lib/RMagick.rb, line 371
371: def pattern(name, x, y, width, height)
372: begin
373: push('defs')
374: push("pattern #{name} #{x} #{y} #{width} #{height}")
375: push('graphic-context')
376: yield
377: ensure
378: pop('graphic-context')
379: pop('pattern')
380: pop('defs')
381: end
382: end
Set point to fill color.
# File lib/RMagick.rb, line 385
385: def point(x, y)
386: primitive "point #{x},#{y}"
387: end
Specify the font size in points. Yes, the primitive is "font-size" but in other places this value is called the "pointsize". Give it both names.
# File lib/RMagick.rb, line 391
391: def pointsize(points)
392: primitive "font-size #{points}"
393: end
Draw a polygon
# File lib/RMagick.rb, line 397
397: def polygon(*points)
398: if points.length == 0
399: raise ArgumentError, "no points specified"
400: elsif points.length % 2 != 0
401: raise ArgumentError, "odd number of points specified"
402: end
403: primitive "polygon " + points.join(',')
404: end
Draw a polyline
# File lib/RMagick.rb, line 407
407: def polyline(*points)
408: if points.length == 0
409: raise ArgumentError, "no points specified"
410: elsif points.length % 2 != 0
411: raise ArgumentError, "odd number of points specified"
412: end
413: primitive "polyline " + points.join(',')
414: end
Return to the previously-saved set of whatever pop(‘graphic-context’) (the default if no arguments) pop(‘defs’) pop(‘gradient’) pop(‘pattern’)
# File lib/RMagick.rb, line 422
422: def pop(*what)
423: if what.length == 0
424: primitive "pop graphic-context"
425: else
426: # to_s allows a Symbol to be used instead of a String
427: primitive "pop " + what.to_s
428: end
429: end
Push the current set of drawing options. Also you can use push(‘graphic-context’) (the default if no arguments) push(‘defs’) push(‘gradient’) push(‘pattern’)
# File lib/RMagick.rb, line 436
436: def push(*what)
437: if what.length == 0
438: primitive "push graphic-context"
439: else
440: # to_s allows a Symbol to be used instead of a String
441: primitive "push " + what.to_s
442: end
443: end
Specify coordinate space rotation. "angle" is measured in degrees
# File lib/RMagick.rb, line 452
452: def rotate(angle)
453: primitive "rotate #{angle}"
454: end
Draw a rectangle with rounded corners
# File lib/RMagick.rb, line 457
457: def roundrectangle(center_x, center_y, width, height, corner_width, corner_height)
458: primitive "roundrectangle " + sprintf("%g,%g,%g,%g,%g,%g",
459: center_x, center_y, width, height, corner_width, corner_height)
460: end
Specify scaling to be applied to coordinate space on subsequent drawing commands.
# File lib/RMagick.rb, line 463
463: def scale(x, y)
464: primitive "scale #{x},#{y}"
465: end
Specify the object stroke, a color name or pattern name.
# File lib/RMagick.rb, line 476
476: def stroke(colorspec)
477: primitive "stroke #{enquote(colorspec)}"
478: end
Specify if stroke should be antialiased or not
# File lib/RMagick.rb, line 483
483: def stroke_antialias(bool)
484: bool = bool ? '1' : '0'
485: primitive "stroke-antialias #{bool}"
486: end
Specify a stroke dash pattern
# File lib/RMagick.rb, line 489
489: def stroke_dasharray(*list)
490: if list.length == 0
491: primitive "stroke-dasharray none"
492: else
493: list.each { |x|
494: if x <= 0 then
495: raise ArgumentError, "dash array elements must be > 0 (#{x} given)"
496: end
497: }
498: primitive "stroke-dasharray #{list.join(',')}"
499: end
500: end
Specify the initial offset in the dash pattern
# File lib/RMagick.rb, line 503
503: def stroke_dashoffset(value=0)
504: primitive "stroke-dashoffset #{value}"
505: end
# File lib/RMagick.rb, line 507
507: def stroke_linecap(value)
508: if ( not ["butt", "round", "square"].include?(value.downcase) )
509: raise ArgumentError, "Unknown linecap type: #{value}"
510: end
511: primitive "stroke-linecap #{value}"
512: end
# File lib/RMagick.rb, line 514
514: def stroke_linejoin(value)
515: if ( not ["round", "miter", "bevel"].include?(value.downcase) )
516: raise ArgumentError, "Unknown linejoin type: #{value}"
517: end
518: primitive "stroke-linejoin #{value}"
519: end
# File lib/RMagick.rb, line 521
521: def stroke_miterlimit(value)
522: if (value < 1)
523: raise ArgumentError, "miterlimit must be >= 1"
524: end
525: primitive "stroke-miterlimit #{value}"
526: end
Specify opacity of stroke drawing color
(use "xx%" to indicate percentage)
# File lib/RMagick.rb, line 530
530: def stroke_opacity(value)
531: primitive "stroke-opacity #{value}"
532: end
Specify stroke (outline) width in pixels.
# File lib/RMagick.rb, line 535
535: def stroke_width(pixels)
536: primitive "stroke-width #{pixels}"
537: end
Draw text at position x,y. Add quotes to text that is not already quoted.
# File lib/RMagick.rb, line 540
540: def text(x, y, text)
541: if text.to_s.empty?
542: raise ArgumentError, "missing text argument"
543: end
544: if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
545: ; # text already quoted
546: elsif !text['\'']
547: text = '\''+text+'\''
548: elsif !text['"']
549: text = '"'+text+'"'
550: elsif !(text['{'] || text['}'])
551: text = '{'+text+'}'
552: else
553: # escape existing braces, surround with braces
554: text = '{' + text.gsub(/[}]/) { |b| '\\' + b } + '}'
555: end
556: primitive "text #{x},#{y} #{text}"
557: end
Specify text alignment relative to a given point
# File lib/RMagick.rb, line 560
560: def text_align(alignment)
561: if ( not ALIGN_TYPE_NAMES.has_key?(alignment.to_i) )
562: raise ArgumentError, "Unknown alignment constant: #{alignment}"
563: end
564: primitive "text-align #{ALIGN_TYPE_NAMES[alignment.to_i]}"
565: end
SVG-compatible version of text_align
# File lib/RMagick.rb, line 568
568: def text_anchor(anchor)
569: if ( not ANCHOR_TYPE_NAMES.has_key?(anchor.to_i) )
570: raise ArgumentError, "Unknown anchor constant: #{anchor}"
571: end
572: primitive "text-anchor #{ANCHOR_TYPE_NAMES[anchor.to_i]}"
573: end
Specify if rendered text is to be antialiased.
# File lib/RMagick.rb, line 576
576: def text_antialias(boolean)
577: boolean = boolean ? '1' : '0'
578: primitive "text-antialias #{boolean}"
579: end
Specify color underneath text
# File lib/RMagick.rb, line 582
582: def text_undercolor(color)
583: primitive "text-undercolor #{enquote(color)}"
584: end
Specify center of coordinate space to use for subsequent drawing commands.
# File lib/RMagick.rb, line 588
588: def translate(x, y)
589: primitive "translate #{x},#{y}"
590: end