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', }.freeze | ||
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 (r), 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
# File lib/RMagick.rb, line 191 191: def bezier(*points) 192: if points.length == 0 193: Kernel.raise ArgumentError, "no points specified" 194: elsif points.length % 2 != 0 195: Kernel.raise ArgumentError, "odd number of arguments specified" 196: end 197: primitive "bezier " + points.join(',') 198: 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: Kernel.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: Kernel.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: Kernel.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
# File lib/RMagick.rb, line 287 287: def fill_rule(rule) 288: if ( not ["evenodd", "nonzero"].include?(rule.downcase) ) 289: Kernel.raise ArgumentError, "Unknown fill rule #{rule}" 290: end 291: primitive "fill-rule #{rule}" 292: 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: Kernel.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: Kernel.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: Kernel.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, method) 344: if ( not PAINT_METHOD_NAMES.has_key?(method.to_i) ) 345: Kernel.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: Kernel.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
# File lib/RMagick.rb, line 397 397: def polygon(*points) 398: if points.length == 0 399: Kernel.raise ArgumentError, "no points specified" 400: elsif points.length % 2 != 0 401: Kernel.raise ArgumentError, "odd number of points specified" 402: end 403: primitive "polygon " + points.join(',') 404: end
# File lib/RMagick.rb, line 407 407: def polyline(*points) 408: if points.length == 0 409: Kernel.raise ArgumentError, "no points specified" 410: elsif points.length % 2 != 0 411: Kernel.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
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
# 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: Kernel.raise ArgumentError, "dash array elements must be > 0 (#{x} given)" 496: end 497: } 498: primitive "stroke-dasharray #{list.join(',')}" 499: end 500: end
# File lib/RMagick.rb, line 507 507: def stroke_linecap(value) 508: if ( not ["butt", "round", "square"].include?(value.downcase) ) 509: Kernel.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: Kernel.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: Kernel.raise ArgumentError, "miterlimit must be >= 1" 524: end 525: primitive "stroke-miterlimit #{value}" 526: 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: Kernel.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: Kernel.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: Kernel.raise ArgumentError, "Unknown anchor constant: #{anchor}" 571: end 572: primitive "text-anchor #{ANCHOR_TYPE_NAMES[anchor.to_i]}" 573: 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