Class: Magick::Draw

Inherits:
Object
  • Object
show all
Defined in:
lib/RMagick.rb,
lib/rmagick4j/draw.rb

Constant Summary collapse

ALIGN_TYPE_NAMES =

Thse hashes are used to map Magick constant values to the strings used in the primitives.

{
LeftAlign.to_i => 'left',
RightAlign.to_i => 'right',
CenterAlign.to_i => 'center'
}.freeze
ANCHOR_TYPE_NAMES =
{
StartAnchor.to_i => 'start',
MiddleAnchor.to_i => 'middle',
EndAnchor.to_i => 'end'
}.freeze
DECORATION_TYPE_NAMES =
{
NoDecoration.to_i => 'none',
UnderlineDecoration.to_i => 'underline',
OverlineDecoration.to_i => 'overline',
LineThroughDecoration.to_i => 'line-through'
}.freeze
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'
}.freeze
PAINT_METHOD_NAMES =
{
PointMethod.to_i => 'point',
ReplaceMethod.to_i => 'replace',
FloodfillMethod.to_i => 'floodfill',
FillToBorderMethod.to_i => 'filltoborder',
ResetMethod.to_i => 'reset'
}.freeze
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'
}.freeze
STYLE_TYPE_NAMES =
{
NormalStyle.to_i => 'normal',
ItalicStyle.to_i => 'italic',
ObliqueStyle.to_i => 'oblique',
AnyStyle.to_i => 'all'
}.freeze

Instance Method Summary collapse

Constructor Details

#initializeDraw

Returns a new instance of Draw.



62
63
64
65
66
67
# File 'lib/rmagick4j/draw.rb', line 62

def initialize
  # Docs say that you can initialize with a block, but it doesn't really work because it inits an ImageInfo not a DrawInfo.
  # instance_eval &add if add
  @draw = Magick4J::DrawInfo.new
  @primitives = ''
end

Instance Method Details

#affine(sx, rx, ry, sy, tx, ty) ⇒ Object

Apply coordinate transformations to support scaling (s), rotation ®, and translation (t). Angles are specified in radians.



207
208
209
# File 'lib/RMagick.rb', line 207

def affine(sx, rx, ry, sy, tx, ty)
    primitive "affine " + sprintf("%g,%g,%g,%g,%g,%g", sx, rx, ry, sy, tx, ty)
end

#annotate(img, width, height, x, y, text, &add) ⇒ Object



5
6
7
8
9
10
# File 'lib/rmagick4j/draw.rb', line 5

def annotate(img, width, height, x, y, text, &add)
  instance_eval &add if add
  text = parse_string(text)
  @draw.annotate(img._image, width, height, x, y, text)
  self
end

#arc(startX, startY, endX, endY, startDegrees, endDegrees) ⇒ Object

Draw an arc.



212
213
214
215
# File 'lib/RMagick.rb', line 212

def arc(startX, startY, endX, endY, startDegrees, endDegrees)
    primitive "arc " + sprintf("%g,%g %g,%g %g,%g",
                startX, startY, endX, endY, startDegrees, endDegrees)
end

#bezier(*points) ⇒ Object

Draw a bezier curve.



218
219
220
221
222
223
224
225
# File 'lib/RMagick.rb', line 218

def bezier(*points)
    if points.length == 0
        Kernel.raise ArgumentError, "no points specified"
    elsif points.length % 2 != 0
        Kernel.raise ArgumentError, "odd number of arguments specified"
    end
    primitive "bezier " + points.join(',')
end

#circle(originX, originY, perimX, perimY) ⇒ Object

Draw a circle



228
229
230
# File 'lib/RMagick.rb', line 228

def circle(originX, originY, perimX, perimY)
    primitive "circle " + sprintf("%g,%g %g,%g", originX, originY, perimX, perimY)
end

#clip_path(name) ⇒ Object

Invoke a clip-path defined by def_clip_path.



233
234
235
# File 'lib/RMagick.rb', line 233

def clip_path(name)
    primitive "clip-path #{name}"
end

#clip_rule(rule) ⇒ Object

Define the clipping rule.



238
239
240
241
242
243
# File 'lib/RMagick.rb', line 238

def clip_rule(rule)
    if ( not ["evenodd", "nonzero"].include?(rule.downcase) )
        Kernel.raise ArgumentError, "Unknown clipping rule #{rule}"
    end
    primitive "clip-rule #{rule}"
end

#clip_units(unit) ⇒ Object

Define the clip units



246
247
248
249
250
251
# File 'lib/RMagick.rb', line 246

def clip_units(unit)
    if ( not ["userspace", "userspaceonuse", "objectboundingbox"].include?(unit.downcase) )
        Kernel.raise ArgumentError, "Unknown clip unit #{unit}"
    end
    primitive "clip-units #{unit}"
end

#cloneObject



12
13
14
15
16
17
18
# File 'lib/rmagick4j/draw.rb', line 12

def clone
  b = Draw.new
  b.primitives = @primitives.clone
  b._draw = @draw.clone
  b.freeze if self.frozen?
  b
end

#color(x, y, method) ⇒ Object

Set color in image according to specified colorization rule. Rule is one of point, replace, floodfill, filltoborder,reset



255
256
257
258
259
260
# File 'lib/RMagick.rb', line 255

def color(x, y, method)
    if ( not PAINT_METHOD_NAMES.has_key?(method.to_i) )
        Kernel.raise ArgumentError, "Unknown PaintMethod: #{method}"
    end
    primitive "color #{x},#{y},#{PAINT_METHOD_NAMES[method.to_i]}"
end

#decorate(decoration) ⇒ Object

Specify EITHER the text decoration (none, underline, overline, line-through) OR the text solid background color (any color name or spec)



264
265
266
267
268
269
270
# File 'lib/RMagick.rb', line 264

def decorate(decoration)
    if ( DECORATION_TYPE_NAMES.has_key?(decoration.to_i) )
        primitive "decorate #{DECORATION_TYPE_NAMES[decoration.to_i]}"
    else
        primitive "decorate #{enquote(decoration)}"
    end
end

#define_clip_path(name) ⇒ Object

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”.



277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/RMagick.rb', line 277

def define_clip_path(name)
    begin
        push('defs')
        push('clip-path', name)
        push('graphic-context')
        yield
    ensure
        pop('graphic-context')
        pop('clip-path')
        pop('defs')
    end
end

#draw(image) ⇒ Object



20
21
22
23
# File 'lib/rmagick4j/draw.rb', line 20

def draw(image)
  @draw.clone.draw(image._image, Magick4J.CommandParser.parse(@primitives))
  self
end

#ellipse(originX, originY, width, height, arcStart, arcEnd) ⇒ Object

Draw an ellipse



291
292
293
294
# File 'lib/RMagick.rb', line 291

def ellipse(originX, originY, width, height, arcStart, arcEnd)
    primitive "ellipse " + sprintf("%g,%g %g,%g %g,%g",
                    originX, originY, width, height, arcStart, arcEnd)
end

#encoding(encoding) ⇒ Object

Let anything through, but the only defined argument is “UTF-8”. All others are apparently ignored.



298
299
300
# File 'lib/RMagick.rb', line 298

def encoding(encoding)
    primitive "encoding #{encoding}"
end

#fill(colorspec) ⇒ Object Also known as: fill_color, fill_pattern

Specify object fill, a color name or pattern name



303
304
305
# File 'lib/RMagick.rb', line 303

def fill(colorspec)
    primitive "fill #{enquote(colorspec)}"
end

#fill=(fill) ⇒ Object



25
26
27
28
# File 'lib/rmagick4j/draw.rb', line 25

def fill= fill
  @draw.fill = Magick4J.ColorDatabase.query_default(fill)
  self
end

#fill_opacity(opacity) ⇒ Object

Specify fill opacity (use “xx%” to indicate percentage)



310
311
312
# File 'lib/RMagick.rb', line 310

def fill_opacity(opacity)
    primitive "fill-opacity #{opacity}"
end

#fill_rule(rule) ⇒ Object



314
315
316
317
318
319
# File 'lib/RMagick.rb', line 314

def fill_rule(rule)
    if ( not ["evenodd", "nonzero"].include?(rule.downcase) )
        Kernel.raise ArgumentError, "Unknown fill rule #{rule}"
    end
    primitive "fill-rule #{rule}"
end

#font(name) ⇒ Object

Specify text drawing font



322
323
324
# File 'lib/RMagick.rb', line 322

def font(name)
    primitive "font #{name}"
end

#font=(font) ⇒ Object



54
55
56
# File 'lib/rmagick4j/draw.rb', line 54

def font= font
  # TODO
end

#font_family(name) ⇒ Object



326
327
328
# File 'lib/RMagick.rb', line 326

def font_family(name)
    primitive "font-family \'#{name}\'"
end

#font_family=(font_family) ⇒ Object



30
31
32
33
# File 'lib/rmagick4j/draw.rb', line 30

def font_family= font_family
  @draw.font_family = font_family
  self
end

#font_stretch(stretch) ⇒ Object



330
331
332
333
334
335
# File 'lib/RMagick.rb', line 330

def font_stretch(stretch)
    if ( not STRETCH_TYPE_NAMES.has_key?(stretch.to_i) )
        Kernel.raise ArgumentError, "Unknown stretch type"
    end
    primitive "font-stretch #{STRETCH_TYPE_NAMES[stretch.to_i]}"
end

#font_style(style) ⇒ Object



337
338
339
340
341
342
# File 'lib/RMagick.rb', line 337

def font_style(style)
    if ( not STYLE_TYPE_NAMES.has_key?(style.to_i) )
        Kernel.raise ArgumentError, "Unknown style type"
    end
    primitive "font-style #{STYLE_TYPE_NAMES[style.to_i]}"
end

#font_weight(weight) ⇒ Object

The font weight argument can be either a font weight constant or [100,200,…,900]



346
347
348
349
350
351
352
# File 'lib/RMagick.rb', line 346

def font_weight(weight)
    if ( FONT_WEIGHT_NAMES.has_key?(weight.to_i) )
        primitive "font-weight #{FONT_WEIGHT_NAMES[weight.to_i]}"
    else
        primitive "font-weight #{weight}"
    end
end

#font_weight=(font_weight) ⇒ Object



35
36
37
38
# File 'lib/rmagick4j/draw.rb', line 35

def font_weight= font_weight
  font_weight = {BoldWeight => 700, NormalWeight => 400}[font_weight]
  @draw.font_weight = font_weight
end

#get_multiline_type_metrics(*args) ⇒ Object

Raises:

  • (ArgumentError)


40
41
42
43
44
45
# File 'lib/rmagick4j/draw.rb', line 40

def get_multiline_type_metrics(*args)
  raise ArgumentError.new('wrong number of arguments (#{args.length})') if not (1..2) === args.length
  string = parse_string(args.last)
  image = args.first._image if args.length == 2
  type_metrics_from_java(@draw.getMultilineTypeMetrics(string, image))
end

#get_type_metrics(*args) ⇒ Object

Raises:

  • (ArgumentError)


47
48
49
50
51
52
# File 'lib/rmagick4j/draw.rb', line 47

def get_type_metrics(*args)
  raise ArgumentError.new('wrong number of arguments (#{args.length})') if not (1..2) === args.length
  string = parse_string(args.last)
  image = args.first._image if args.length == 2
  type_metrics_from_java(@draw.getTypeMetrics(string, image))
end

#gravity(grav) ⇒ Object

Specify the text positioning gravity, one of: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast



356
357
358
359
360
361
# File 'lib/RMagick.rb', line 356

def gravity(grav)
    if ( not GRAVITY_NAMES.has_key?(grav.to_i) )
        Kernel.raise ArgumentError, "Unknown text positioning gravity"
    end
    primitive "gravity #{GRAVITY_NAMES[grav.to_i]}"
end

#gravity=(gravity) ⇒ Object



58
59
60
# File 'lib/rmagick4j/draw.rb', line 58

def gravity= gravity
  @draw.setGravity(gravity._val)
end

#inspectObject



69
70
71
72
73
74
75
# File 'lib/rmagick4j/draw.rb', line 69

def inspect
  if @primitives == ''
    '(no primitives defined)'
  else
    @primitives
  end
end

#interword_spacing(space) ⇒ Object

IM 6.4.8-3 and later



364
365
366
367
368
369
370
371
372
373
# File 'lib/RMagick.rb', line 364

def interword_spacing(space)
    begin
        Float(space)
    rescue ArgumentError
        Kernel.raise ArgumentError, "invalid value for interword_spacing"
    rescue TypeError
        Kernel.raise TypeError, "can't convert #{space.class} into Float"
    end
    primitive "interword-spacing #{space}"
end

#kerning(space) ⇒ Object

IM 6.4.8-3 and later



376
377
378
379
380
381
382
383
384
385
# File 'lib/RMagick.rb', line 376

def kerning(space)
    begin
        Float(space)
    rescue ArgumentError
        Kernel.raise ArgumentError, "invalid value for kerning"
    rescue TypeError
        Kernel.raise TypeError, "can't convert #{space.class} into Float"
    end
    primitive "kerning #{space}"
end

#line(startX, startY, endX, endY) ⇒ Object

Draw a line



388
389
390
# File 'lib/RMagick.rb', line 388

def line(startX, startY, endX, endY)
    primitive "line " + sprintf("%g,%g %g,%g", startX, startY, endX, endY)
end

#matte(x, y, method) ⇒ Object

Set matte (make transparent) in image according to the specified colorization rule



394
395
396
397
398
399
# File 'lib/RMagick.rb', line 394

def matte(x, y, method)
    if ( not PAINT_METHOD_NAMES.has_key?(method.to_i) )
        Kernel.raise ArgumentError, "Unknown paint method"
    end
    primitive "matte #{x},#{y} #{PAINT_METHOD_NAMES[method.to_i]}"
end

#opacity(opacity) ⇒ Object

Specify drawing fill and stroke opacities. If the value is a string ending with a %, the number will be multiplied by 0.01.



403
404
405
406
407
408
409
410
# File 'lib/RMagick.rb', line 403

def opacity(opacity)
    if (Numeric === opacity)
        if (opacity < 0 || opacity > 1.0)
            Kernel.raise ArgumentError, "opacity must be >= 0 and <= 1.0"
        end
    end
    primitive "opacity #{opacity}"
end

#path(cmds) ⇒ Object

Draw using SVG-compatible path drawing commands. Note that the primitive requires that the commands be surrounded by quotes or apostrophes. Here we simply use apostrophes.



415
416
417
# File 'lib/RMagick.rb', line 415

def path(cmds)
    primitive "path '" + cmds + "'"
end

#pattern(name, x, y, width, height) ⇒ Object

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



422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/RMagick.rb', line 422

def pattern(name, x, y, width, height)
    begin
        push('defs')
        push("pattern #{name} #{x} #{y} #{width} #{height}")
        push('graphic-context')
        yield
    ensure
        pop('graphic-context')
        pop('pattern')
        pop('defs')
    end
end

#point(x, y) ⇒ Object

Set point to fill color.



436
437
438
# File 'lib/RMagick.rb', line 436

def point(x, y)
    primitive "point #{x},#{y}"
end

#pointsize(points) ⇒ Object Also known as: font_size

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.



442
443
444
# File 'lib/RMagick.rb', line 442

def pointsize(points)
    primitive "font-size #{points}"
end

#pointsize=(pointsize) ⇒ Object



77
78
79
# File 'lib/rmagick4j/draw.rb', line 77

def pointsize= pointsize
  @draw.setPointSize(pointsize)
end

#polygon(*points) ⇒ Object

Draw a polygon



448
449
450
451
452
453
454
455
# File 'lib/RMagick.rb', line 448

def polygon(*points)
    if points.length == 0
        Kernel.raise ArgumentError, "no points specified"
    elsif points.length % 2 != 0
        Kernel.raise ArgumentError, "odd number of points specified"
    end
    primitive "polygon " + points.join(',')
end

#polyline(*points) ⇒ Object

Draw a polyline



458
459
460
461
462
463
464
465
# File 'lib/RMagick.rb', line 458

def polyline(*points)
    if points.length == 0
        Kernel.raise ArgumentError, "no points specified"
    elsif points.length % 2 != 0
        Kernel.raise ArgumentError, "odd number of points specified"
    end
    primitive "polyline " + points.join(',')
end

#pop(*what) ⇒ Object

Return to the previously-saved set of whatever pop(‘graphic-context’) (the default if no arguments) pop(‘defs’) pop(‘gradient’) pop(‘pattern’)



473
474
475
476
477
478
479
480
# File 'lib/RMagick.rb', line 473

def pop(*what)
    if what.length == 0
        primitive "pop graphic-context"
    else
        # to_s allows a Symbol to be used instead of a String
        primitive "pop " + what.map {|w| w.to_s}.join(' ')
    end
end

#primitive(primitive) ⇒ Object



81
82
83
84
85
86
# File 'lib/rmagick4j/draw.rb', line 81

def primitive primitive
  # TODO Concat in a string like they do, then use helper to parse later
  @primitives << "\n" unless @primitives.empty?
  @primitives << primitive.gsub(/[\r|\n]/, '')
  self
end

#push(*what) ⇒ Object

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’)



487
488
489
490
491
492
493
494
# File 'lib/RMagick.rb', line 487

def push(*what)
    if what.length == 0
        primitive "push graphic-context"
    else
        # to_s allows a Symbol to be used instead of a String
        primitive "push " + what.map {|w| w.to_s}.join(' ')
    end
end

#rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y) ⇒ Object

Draw a rectangle



497
498
499
500
# File 'lib/RMagick.rb', line 497

def rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y)
    primitive "rectangle " + sprintf("%g,%g %g,%g",
            upper_left_x, upper_left_y, lower_right_x, lower_right_y)
end

#rotate(angle) ⇒ Object

Specify coordinate space rotation. “angle” is measured in degrees



503
504
505
# File 'lib/RMagick.rb', line 503

def rotate(angle)
    primitive "rotate #{angle}"
end

#rotation=(rotation) ⇒ Object



88
89
90
91
# File 'lib/rmagick4j/draw.rb', line 88

def rotation= rotation
  @draw.rotate(rotation)
  self
end

#roundrectangle(center_x, center_y, width, height, corner_width, corner_height) ⇒ Object

Draw a rectangle with rounded corners



508
509
510
511
# File 'lib/RMagick.rb', line 508

def roundrectangle(center_x, center_y, width, height, corner_width, corner_height)
    primitive "roundrectangle " + sprintf("%g,%g,%g,%g,%g,%g",
        center_x, center_y, width, height, corner_width, corner_height)
end

#scale(x, y) ⇒ Object

Specify scaling to be applied to coordinate space on subsequent drawing commands.



514
515
516
# File 'lib/RMagick.rb', line 514

def scale(x, y)
    primitive "scale #{x},#{y}"
end

#skewx(angle) ⇒ Object



518
519
520
# File 'lib/RMagick.rb', line 518

def skewx(angle)
    primitive "skewX #{angle}"
end

#skewy(angle) ⇒ Object



522
523
524
# File 'lib/RMagick.rb', line 522

def skewy(angle)
    primitive "skewY #{angle}"
end

#stroke(colorspec) ⇒ Object Also known as: stroke_color, stroke_pattern

Specify the object stroke, a color name or pattern name.



527
528
529
# File 'lib/RMagick.rb', line 527

def stroke(colorspec)
    primitive "stroke #{enquote(colorspec)}"
end

#stroke=(stroke) ⇒ Object



93
94
95
96
# File 'lib/rmagick4j/draw.rb', line 93

def stroke= stroke
  @draw.setStroke(Magick4J.ColorDatabase.queryDefault(stroke))
  self
end

#stroke_antialias(bool) ⇒ Object

Specify if stroke should be antialiased or not



534
535
536
537
# File 'lib/RMagick.rb', line 534

def stroke_antialias(bool)
    bool = bool ? '1' : '0'
    primitive "stroke-antialias #{bool}"
end

#stroke_dasharray(*list) ⇒ Object

Specify a stroke dash pattern



540
541
542
543
544
545
546
547
548
549
550
551
# File 'lib/RMagick.rb', line 540

def stroke_dasharray(*list)
    if list.length == 0
        primitive "stroke-dasharray none"
    else
        list.each { |x|
            if x <= 0 then
                Kernel.raise ArgumentError, "dash array elements must be > 0 (#{x} given)"
            end
        }
        primitive "stroke-dasharray #{list.join(',')}"
    end
end

#stroke_dashoffset(value = 0) ⇒ Object

Specify the initial offset in the dash pattern



554
555
556
# File 'lib/RMagick.rb', line 554

def stroke_dashoffset(value=0)
    primitive "stroke-dashoffset #{value}"
end

#stroke_linecap(value) ⇒ Object



558
559
560
561
562
563
# File 'lib/RMagick.rb', line 558

def stroke_linecap(value)
    if ( not ["butt", "round", "square"].include?(value.downcase) )
        Kernel.raise ArgumentError, "Unknown linecap type: #{value}"
    end
    primitive "stroke-linecap #{value}"
end

#stroke_linejoin(value) ⇒ Object



565
566
567
568
569
570
# File 'lib/RMagick.rb', line 565

def stroke_linejoin(value)
    if ( not ["round", "miter", "bevel"].include?(value.downcase) )
        Kernel.raise ArgumentError, "Unknown linejoin type: #{value}"
    end
    primitive "stroke-linejoin #{value}"
end

#stroke_miterlimit(value) ⇒ Object



572
573
574
575
576
577
# File 'lib/RMagick.rb', line 572

def stroke_miterlimit(value)
    if (value < 1)
        Kernel.raise ArgumentError, "miterlimit must be >= 1"
    end
    primitive "stroke-miterlimit #{value}"
end

#stroke_opacity(value) ⇒ Object

Specify opacity of stroke drawing color

(use "xx%" to indicate percentage)


581
582
583
# File 'lib/RMagick.rb', line 581

def stroke_opacity(value)
    primitive "stroke-opacity #{value}"
end

#stroke_width(pixels) ⇒ Object

Specify stroke (outline) width in pixels.



586
587
588
# File 'lib/RMagick.rb', line 586

def stroke_width(pixels)
    primitive "stroke-width #{pixels}"
end

#text(x, y, text) ⇒ Object

Draw text at position x,y. Add quotes to text that is not already quoted.



591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
# File 'lib/RMagick.rb', line 591

def text(x, y, text)
    if text.to_s.empty?
        Kernel.raise ArgumentError, "missing text argument"
    end
    if text.length > 2 && /\A(?:\"[^\"]+\"|\'[^\']+\'|\{[^\}]+\})\z/.match(text)
        ; # text already quoted
    elsif !text['\'']
        text = '\''+text+'\''
    elsif !text['"']
        text = '"'+text+'"'
    elsif !(text['{'] || text['}'])
        text = '{'+text+'}'
    else
        # escape existing braces, surround with braces
        text = '{' +  text.gsub(/[}]/) { |b| '\\' + b } + '}'
    end
    primitive "text #{x},#{y} #{text}"
end

#text_align(alignment) ⇒ Object

Specify text alignment relative to a given point



611
612
613
614
615
616
# File 'lib/RMagick.rb', line 611

def text_align(alignment)
    if ( not ALIGN_TYPE_NAMES.has_key?(alignment.to_i) )
        Kernel.raise ArgumentError, "Unknown alignment constant: #{alignment}"
    end
    primitive "text-align #{ALIGN_TYPE_NAMES[alignment.to_i]}"
end

#text_anchor(anchor) ⇒ Object

SVG-compatible version of text_align



619
620
621
622
623
624
# File 'lib/RMagick.rb', line 619

def text_anchor(anchor)
    if ( not ANCHOR_TYPE_NAMES.has_key?(anchor.to_i) )
        Kernel.raise ArgumentError, "Unknown anchor constant: #{anchor}"
    end
    primitive "text-anchor #{ANCHOR_TYPE_NAMES[anchor.to_i]}"
end

#text_antialias(boolean) ⇒ Object

Specify if rendered text is to be antialiased.



627
628
629
630
# File 'lib/RMagick.rb', line 627

def text_antialias(boolean)
    boolean = boolean ? '1' : '0'
    primitive "text-antialias #{boolean}"
end

#text_undercolor(color) ⇒ Object

Specify color underneath text



633
634
635
# File 'lib/RMagick.rb', line 633

def text_undercolor(color)
    primitive "text-undercolor #{enquote(color)}"
end

#translate(x, y) ⇒ Object

Specify center of coordinate space to use for subsequent drawing commands.



639
640
641
# File 'lib/RMagick.rb', line 639

def translate(x, y)
    primitive "translate #{x},#{y}"
end