Class: Magick::Draw

Inherits:
Object
  • Object
show all
Defined in:
lib/rmagick_internal.rb,
ext/RMagick/rmmain.c

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

#initializeObject

Initialize Draw object.

Ruby usage:

- @verbatim Draw#initialize <{ info initializers }> @endverbatim

Parameters:

  • self

    this object


1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
# File 'ext/RMagick/rmdraw.c', line 1523

VALUE
Draw_initialize(VALUE self)
{
    Draw *draw, *draw_options;
    VALUE options;

    Data_Get_Struct(self, Draw, draw);

    options = new_DrawOptions();
    Data_Get_Struct(options, Draw, draw_options);
    draw->info = draw_options->info;
    draw_options->info = NULL;

    RB_GC_GUARD(options);

    return self;
}

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.


223
224
225
# File 'lib/rmagick_internal.rb', line 223

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(image_arg, width_arg, height_arg, x_arg, y_arg, text) ⇒ Object

Annotates an image with text.

Ruby usage:

- @verbatim Draw#annotate(img, w, h, x, y, text) <{optional parms}> @endverbatim

Notes:

- Additional Draw attribute methods may be called in the optional block,
  which is executed in the context of an Draw object.

Parameters:

  • self

    this object

  • image_arg

    the image

  • width_arg

    the width

  • height_arg

    the height

  • x_arg

    x position

  • y_arg

    y position

  • text

    the annotation text

Returns:

  • self


974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
# File 'ext/RMagick/rmdraw.c', line 974

VALUE Draw_annotate(
                   VALUE self,
                   VALUE image_arg,
                   VALUE width_arg,
                   VALUE height_arg,
                   VALUE x_arg,
                   VALUE y_arg,
                   VALUE text)
{
    Draw *draw;
    Image *image;
    unsigned long width, height;
    long x, y;
    AffineMatrix keep;
    char geometry_str[50];

    // Save the affine matrix in case it is modified by
    // Draw#rotation=
    Data_Get_Struct(self, Draw, draw);
    keep = draw->info->affine;

    image_arg = rm_cur_image(image_arg);
    image = rm_check_frozen(image_arg);

    // If we have an optional parm block, run it in self's context,
    // allowing the app a chance to modify the object's attributes
    if (rb_block_given_p())
    {
        (void)rb_obj_instance_eval(0, NULL, self);
    }

    // Translate & store in Draw structure
    draw->info->text = InterpretImageProperties(NULL, image, StringValuePtr(text));
    if (!draw->info->text)
    {
        rb_raise(rb_eArgError, "no text");
    }

    // Create geometry string, copy to Draw structure, overriding
    // any previously existing value.
    width  = NUM2ULONG(width_arg);
    height = NUM2ULONG(height_arg);
    x      = NUM2LONG(x_arg);
    y      = NUM2LONG(y_arg);

    if (width == 0 && height == 0)
    {
        sprintf(geometry_str, "%+ld%+ld", x, y);
    }

    // WxH is non-zero
    else
    {
        sprintf(geometry_str, "%lux%lu%+ld%+ld", width, height, x, y);
    }

    magick_clone_string(&draw->info->geometry, geometry_str);

    (void) AnnotateImage(image, draw->info);

    magick_free(draw->info->text);
    draw->info->text = NULL;
    draw->info->affine = keep;

    rm_check_image_exception(image, RetainOnError);

    return self;
}

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

Draw an arc.


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

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.


234
235
236
237
238
239
240
241
# File 'lib/rmagick_internal.rb', line 234

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

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

Draw a circle


244
245
246
# File 'lib/rmagick_internal.rb', line 244

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.


249
250
251
# File 'lib/rmagick_internal.rb', line 249

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

#clip_rule(rule) ⇒ Object

Define the clipping rule.


254
255
256
257
258
259
# File 'lib/rmagick_internal.rb', line 254

def clip_rule(rule)
  unless  ['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


262
263
264
265
266
267
# File 'lib/rmagick_internal.rb', line 262

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

#cloneObject

Clones this object.

Ruby usage:

- @verbatim Draw#clone @endverbatim

Parameters:

  • self

    this object

Returns:

  • the clone

See Also:

  • Draw_dup
  • Draw_init_copy

1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
# File 'ext/RMagick/rmdraw.c', line 1055

VALUE
Draw_clone(VALUE self)
{
    VALUE clone;

    clone = Draw_dup(self);
    if (OBJ_FROZEN(self))
    {
        OBJ_FREEZE(clone);
    }

    RB_GC_GUARD(clone);

    return clone;
}

#color(x, y, method) ⇒ Object

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


271
272
273
274
275
276
# File 'lib/rmagick_internal.rb', line 271

def color(x, y, method)
  unless  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

#composite(*args) ⇒ Object

Implement the “image” drawing primitive.

Ruby usage:

- @verbatim Draw#composite(x,y,width,height,img) @endverbatim
- @verbatim Draw#composite(x,y,width,height,img,operator) @endverbatim

Notes:

- Default operator is overComposite
- The "img" argument can be either an ImageList object or an Image
  argument.

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • self

    this object

Returns:

  • self


1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
# File 'ext/RMagick/rmdraw.c', line 1089

VALUE
Draw_composite(int argc, VALUE *argv, VALUE self)
{
    Draw *draw;
    const char *op = "Over";
    double x, y, width, height;
    CompositeOperator cop = OverCompositeOp;
    VALUE image;
    Image *comp_img;
    struct TmpFile_Name *tmpfile_name;
    char name[MaxTextExtent];
    // Buffer for "image" primitive
    char primitive[MaxTextExtent];

    if (argc < 5 || argc > 6)
    {
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 5 or 6)", argc);
    }

    // Retrieve the image to composite
    image = rm_cur_image(argv[4]);
    (void) rm_check_destroyed(image);

    x = NUM2DBL(argv[0]);
    y = NUM2DBL(argv[1]);
    width  = NUM2DBL(argv[2]);
    height = NUM2DBL(argv[3]);

    // The default composition operator is "Over".
    if (argc == 6)
    {
        VALUE_TO_ENUM(argv[5], cop, CompositeOperator);

        switch (cop)
        {
            case AddCompositeOp:
                op = "Add";
                break;
            case AtopCompositeOp:
                op = "Atop";
                break;
            case BlendCompositeOp:
                op = "Blend";
                break;
#if defined(HAVE_ENUM_BLURCOMPOSITEOP)
            case BlurCompositeOp:
                op = "Blur";
                break;
#endif
            case BumpmapCompositeOp:
                op = "Bumpmap";
                break;
            case ChangeMaskCompositeOp:
                op = "ChangeMask";
                break;
            case ClearCompositeOp:
                op = "Clear";
                break;
            case ColorBurnCompositeOp:
                op = "ColorBurn";
                break;
            case ColorDodgeCompositeOp:
                op = "ColorDodge";
                break;
            case ColorizeCompositeOp:
                op = "Colorize";
                break;
            case CopyCompositeOp:
                op = "Copy";
                break;
            case CopyBlackCompositeOp:
                op = "CopyBlack";
                break;
            case CopyBlueCompositeOp:
                op = "CopyBlue";
                break;
            case CopyCyanCompositeOp:
                op = "CopyCyan";
                break;
            case CopyGreenCompositeOp:
                op = "CopyGreen";
                break;
            case CopyMagentaCompositeOp:
                op = "CopyMagenta";
                break;
            case CopyOpacityCompositeOp:
                op = "CopyOpacity";
                break;
            case CopyRedCompositeOp:
                op = "CopyRed";
                break;
            case CopyYellowCompositeOp:
                op = "CopyYellow";
                break;
            case DarkenCompositeOp:
                op = "Darken";
                break;
#if defined(HAVE_ENUM_DISTORTCOMPOSITEOP)
            case DistortCompositeOp:
                op = "Distort";
                break;
#endif
            case DivideCompositeOp:
                op = "Divide";
                break;
            case DstCompositeOp:
                op = "Dst";
                break;
            case DstAtopCompositeOp:
                op = "DstAtop";
                break;
            case DstInCompositeOp:
                op = "DstIn";
                break;
            case DstOutCompositeOp:
                op = "DstOut";
                break;
            case DstOverCompositeOp:
                op = "DstOver";
                break;
            case DifferenceCompositeOp:
                op = "Difference";
                break;
            case DisplaceCompositeOp:
                op = "Displace";
                break;
            case DissolveCompositeOp:
                op = "Dissolve";
                break;
            case ExclusionCompositeOp:
                op = "Exclusion";
                break;
            case HardLightCompositeOp:
                op = "HardLight";
                break;
            case HueCompositeOp:
                op = "Hue";
                break;
            case InCompositeOp:
                op = "In";
                break;
            case LightenCompositeOp:
                op = "Lighten";
                break;
#if defined(HAVE_ENUM_LINEARBURNCOMPOSITEOP)
            case LinearBurnCompositeOp:
                op = "LinearBurn";
                break;
#endif
#if defined(HAVE_ENUM_LINEARDODGECOMPOSITEOP)
            case LinearDodgeCompositeOp:
                op = "LinearDodge";
                break;
#endif
            case LinearLightCompositeOp:
                op = "LinearLight";
                break;
            case LuminizeCompositeOp:
                op = "Luminize";
                break;
            case MinusCompositeOp:
                op = "Minus";
                break;
            case ModulateCompositeOp:
                op = "Modulate";
                break;
            case MultiplyCompositeOp:
                op = "Multiply";
                break;
            case OutCompositeOp:
                op = "Out";
                break;
            case OverCompositeOp:
                op = "Over";
                break;
            case OverlayCompositeOp:
                op = "Overlay";
                break;
#if defined(HAVE_ENUM_PEGTOPLIGHTCOMPOSITEOP)
            case PegtopLightCompositeOp:
                op = "PegtopLight";
                break;
#endif
#if defined(HAVE_ENUM_PINLIGHTCOMPOSITEOP)
            case PinLightCompositeOp:
                op = "PinLight";
                break;
#endif
            case PlusCompositeOp:
                op = "Plus";
                break;
            case ReplaceCompositeOp:
                op = "Replace";
                break;
            case SaturateCompositeOp:
                op = "Saturate";
                break;
            case ScreenCompositeOp:
                op = "Screen";
                break;
            case SoftLightCompositeOp:
                op = "SoftLight";
                break;
            case SrcCompositeOp:
                op = "Src";
                break;
            case SrcAtopCompositeOp:
                op = "SrcAtop";
                break;
            case SrcInCompositeOp:
                op = "SrcIn";
                break;
            case SrcOutCompositeOp:
                op = "SrcOut";
                break;
            case SrcOverCompositeOp:
                op = "SrcOver";
                break;
            case SubtractCompositeOp:
                op = "Subtract";
                break;
            case ThresholdCompositeOp:
                op = "Threshold";
                break;
#if defined(HAVE_ENUM_VIVIDLIGHTCOMPOSITEOP)
            case VividLightCompositeOp:
                op = "VividLight";
                break;
#endif
            case XorCompositeOp:
                op = "Xor";
                break;
            default:
                rb_raise(rb_eArgError, "unknown composite operator (%d)", cop);
                break;
        }
    }

    Data_Get_Struct(self, Draw, draw);

    // Create a temp copy of the composite image
    Data_Get_Struct(image, Image, comp_img);
    rm_write_temp_image(comp_img, name);

    // Add the temp filename to the filename array.
    // Use Magick storage since we need to keep the list around
    // until destroy_Draw is called.
    tmpfile_name = magick_malloc(sizeof(struct TmpFile_Name)+strlen(name));
    strcpy(tmpfile_name->name, name);
    tmpfile_name->next = draw->tmpfile_ary;
    draw->tmpfile_ary = tmpfile_name;

    // Form the drawing primitive
    (void) sprintf(primitive, "image %s %g,%g,%g,%g '%s'", op, x, y, width, height, name);


    // Send "primitive" to self.
    (void) rb_funcall(self, rb_intern("primitive"), 1, rb_str_new2(primitive));

    RB_GC_GUARD(image);

    return self;
}

#decorate(decoration) ⇒ Object

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


280
281
282
283
284
285
286
# File 'lib/rmagick_internal.rb', line 280

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


293
294
295
296
297
298
299
300
301
302
# File 'lib/rmagick_internal.rb', line 293

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

#draw(image_arg) ⇒ Object

Execute the stored drawing primitives on the current image.

Ruby usage:

- @verbatim Draw#draw(i) @endverbatim

Parameters:

  • self

    this object

  • image_arg

    the image argument

Returns:

  • self


1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
# File 'ext/RMagick/rmdraw.c', line 1364

VALUE
Draw_draw(VALUE self, VALUE image_arg)
{
    Draw *draw;
    Image *image;

    image_arg = rm_cur_image(image_arg);
    image = rm_check_frozen(image_arg);

    Data_Get_Struct(self, Draw, draw);
    if (draw->primitives == 0)
    {
        rb_raise(rb_eArgError, "nothing to draw");
    }

    // Point the DrawInfo structure at the current set of primitives.
    magick_clone_string(&(draw->info->primitive), StringValuePtr(draw->primitives));

    (void) DrawImage(image, draw->info);
    rm_check_image_exception(image, RetainOnError);

    magick_free(draw->info->primitive);
    draw->info->primitive = NULL;

    return self;
}

#dupObject

Copy a Draw object.

Ruby usage:

- @verbatim Draw#dup @endverbatim

Notes:

- Constructs a new Draw object, then calls initialize_copy.

Parameters:

  • self

    this object

Returns:

  • the duplicate

See Also:

  • Draw_clone
  • Draw_init_copy

1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
# File 'ext/RMagick/rmdraw.c', line 1406

VALUE
Draw_dup(VALUE self)
{
    Draw *draw;
    VALUE dup;

    draw = ALLOC(Draw);
    memset(draw, 0, sizeof(Draw));
    dup = Data_Wrap_Struct(CLASS_OF(self), mark_Draw, destroy_Draw, draw);
    if (rb_obj_tainted(self))
    {
        (void)rb_obj_taint(dup);
    }

    RB_GC_GUARD(dup);

    return rb_funcall(dup, rm_ID_initialize_copy, 1, self);
}

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

Draw an ellipse


305
306
307
308
# File 'lib/rmagick_internal.rb', line 305

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.


312
313
314
# File 'lib/rmagick_internal.rb', line 312

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


317
318
319
# File 'lib/rmagick_internal.rb', line 317

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

#fill_opacity(opacity) ⇒ Object

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


324
325
326
# File 'lib/rmagick_internal.rb', line 324

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

#fill_rule(rule) ⇒ Object


328
329
330
331
332
333
# File 'lib/rmagick_internal.rb', line 328

def fill_rule(rule)
  unless  ['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


336
337
338
# File 'lib/rmagick_internal.rb', line 336

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

#font_family(name) ⇒ Object


340
341
342
# File 'lib/rmagick_internal.rb', line 340

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

#font_stretch(stretch) ⇒ Object


344
345
346
347
348
349
# File 'lib/rmagick_internal.rb', line 344

def font_stretch(stretch)
  unless  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


351
352
353
354
355
356
# File 'lib/rmagick_internal.rb', line 351

def font_style(style)
  unless  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]


360
361
362
363
364
365
366
# File 'lib/rmagick_internal.rb', line 360

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

#get_multiline_type_metrics(*args) ⇒ Object

Returns measurements for a given font and text string.

Ruby usage:

- @verbatim Draw#get_multiline_type_metrics(text) @endverbatim
- @verbatim Draw#get_multiline_type_metrics(image, text) @endverbatim

Notes:

- If the image argument has been omitted, use a dummy image, but make sure
  the text has none of the special characters that refer to image
  attributes.

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • self

    this object

Returns:

  • the duplicate


1470
1471
1472
1473
1474
1475
1476
1477
# File 'ext/RMagick/rmdraw.c', line 1470

VALUE
Draw_get_multiline_type_metrics(
                               int argc,
                               VALUE *argv,
                               VALUE self)
{
    return get_type_metrics(argc, argv, self, GetMultilineTypeMetrics);
}

#get_type_metrics(*args) ⇒ Object

Returns measurements for a given font and text string.

Ruby usage:

- @verbatim Draw#get_type_metrics(text) @endverbatim
- @verbatim Draw#get_type_metrics(image, text) @endverbatim

Notes:

- If the image argument has been omitted, use a dummy image, but make sure
  the text has none of the special characters that refer to image
  attributes.

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • self

    this object

Returns:

  • the duplicate


1443
1444
1445
1446
1447
1448
1449
1450
# File 'ext/RMagick/rmdraw.c', line 1443

VALUE
Draw_get_type_metrics(
                     int argc,
                     VALUE *argv,
                     VALUE self)
{
    return get_type_metrics(argc, argv, self, GetTypeMetrics);
}

#gravity(grav) ⇒ Object

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


370
371
372
373
374
375
# File 'lib/rmagick_internal.rb', line 370

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

#initialize_copy(orig) ⇒ Object

Initialize clone, dup methods.

Ruby usage:

- @verbatim Draw#initialize_copy @endverbatim

Parameters:

  • self

    this object

  • orig

    the original object

Returns:

  • self

See Also:

  • Draw_clone
  • Draw_dup

1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
# File 'ext/RMagick/rmdraw.c', line 1492

VALUE Draw_init_copy(VALUE self, VALUE orig)
{
    Draw *copy, *original;

    Data_Get_Struct(orig, Draw, original);
    Data_Get_Struct(self, Draw, copy);

    copy->info = CloneDrawInfo(NULL, original->info);
    if (!copy->info)
    {
        rb_raise(rb_eNoMemError, "not enough memory to continue");
    }

    if (original->primitives)
    {
        copy->primitives = rb_str_dup(original->primitives);
    }

    return self;
}

#inspectObject

Display the primitives.

Ruby usage:

- @verbatim Draw#inspect @endverbatim

they are not defined

Parameters:

  • self

    this object

Returns:

  • the draw primitives or the Ruby string “(no primitives defined)” if


1552
1553
1554
1555
1556
1557
1558
1559
# File 'ext/RMagick/rmdraw.c', line 1552

VALUE
Draw_inspect(VALUE self)
{
    Draw *draw;

    Data_Get_Struct(self, Draw, draw);
    return draw->primitives ? draw->primitives : rb_str_new2("(no primitives defined)");
}

#interline_spacing(space) ⇒ Object

IM 6.5.5-8 and later


378
379
380
381
382
383
384
385
386
387
# File 'lib/rmagick_internal.rb', line 378

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

#interword_spacing(space) ⇒ Object

IM 6.4.8-3 and later


390
391
392
393
394
395
396
397
398
399
# File 'lib/rmagick_internal.rb', line 390

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


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

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


414
415
416
# File 'lib/rmagick_internal.rb', line 414

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

#marshal_dumpObject

TODO:

Handle gradients when christy gets the new gradient support added (23Dec08)

Custom marshal for Draw objects.

Ruby usage:

- @verbatim Draw#marshal_dump @endverbatim

Notes:

- Instead of trying to replicate Ruby's support for cross-system
  marshalling, exploit it. Convert the Draw fields to Ruby objects and
  store them in a hash. Let Ruby marshal the hash.
- Commented out code that dumps/loads fields that are used internally by
  ImageMagick and shouldn't be marshaled. I left the code as placeholders
  so I'll know which fields have been deliberately omitted.

Parameters:

  • self

    this object

Returns:

  • the marshalled object (as a Ruby hash)


575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'ext/RMagick/rmdraw.c', line 575

VALUE
Draw_marshal_dump(VALUE self)
{
    Draw *draw;
    VALUE ddraw;

    Data_Get_Struct(self, Draw, draw);

    // Raise an exception if the Draw has a non-NULL gradient or element_reference field
    if (draw->info->element_reference.type != UndefinedReference
        || draw->info->gradient.type != UndefinedGradient)
    {
        rb_raise(rb_eTypeError, "can't dump gradient definition");
    }

    ddraw = rb_hash_new();

    // rb_hash_aset(ddraw, CSTR2SYM("primitive"), MAGICK_STRING_TO_OBJ(draw->info->primitive)); internal
    // rb_hash_aset(ddraw, CSTR2SYM("geometry"), MAGICK_STRING_TO_OBJ(draw->info->geometry)); set by "text" primitive
    // rb_hash_aset(ddraw, CSTR2SYM("viewbox"), Import_RectangleInfo(&draw->info->viewbox)); internal
    rb_hash_aset(ddraw, CSTR2SYM("affine"), Import_AffineMatrix(&draw->info->affine));
    rb_hash_aset(ddraw, CSTR2SYM("gravity"), INT2FIX(draw->info->gravity));
    rb_hash_aset(ddraw, CSTR2SYM("fill"), Pixel_from_PixelPacket(&draw->info->fill));
    rb_hash_aset(ddraw, CSTR2SYM("stroke"), Pixel_from_PixelPacket(&draw->info->stroke));
    rb_hash_aset(ddraw, CSTR2SYM("stroke_width"), rb_float_new(draw->info->stroke_width));
    // rb_hash_aset(ddraw, CSTR2SYM("gradient"), Qnil);  // not used yet
    rb_hash_aset(ddraw, CSTR2SYM("fill_pattern"), image_to_str(draw->info->fill_pattern));
    rb_hash_aset(ddraw, CSTR2SYM("tile"), Qnil); // deprecated
    rb_hash_aset(ddraw, CSTR2SYM("stroke_pattern"), image_to_str(draw->info->stroke_pattern));
    rb_hash_aset(ddraw, CSTR2SYM("stroke_antialias"), draw->info->stroke_antialias ? Qtrue : Qfalse);
    rb_hash_aset(ddraw, CSTR2SYM("text_antialias"), draw->info->text_antialias ? Qtrue : Qfalse);
    // rb_hash_aset(ddraw, CSTR2SYM("fill_rule"), INT2FIX(draw->info->fill_rule)); internal
    // rb_hash_aset(ddraw, CSTR2SYM("linecap"), INT2FIX(draw->info->linecap));
    // rb_hash_aset(ddraw, CSTR2SYM("linejoin"), INT2FIX(draw->info->linejoin));
    // rb_hash_aset(ddraw, CSTR2SYM("miterlimit"), ULONG2NUM(draw->info->miterlimit));
    // rb_hash_aset(ddraw, CSTR2SYM("dash_offset"), rb_float_new(draw->info->dash_offset));
    rb_hash_aset(ddraw, CSTR2SYM("decorate"), INT2FIX(draw->info->decorate));
    // rb_hash_aset(ddraw, CSTR2SYM("compose"), INT2FIX(draw->info->compose)); set via "image" primitive
    // rb_hash_aset(ddraw, CSTR2SYM("text"), MAGICK_STRING_TO_OBJ(draw->info->text)); set via "text" primitive
    // rb_hash_aset(ddraw, CSTR2SYM("face"), Qnil);  internal
    rb_hash_aset(ddraw, CSTR2SYM("font"), MAGICK_STRING_TO_OBJ(draw->info->font));
    // rb_hash_aset(ddraw, CSTR2SYM("metrics"), Qnil);   internal
    rb_hash_aset(ddraw, CSTR2SYM("family"), MAGICK_STRING_TO_OBJ(draw->info->family));
    rb_hash_aset(ddraw, CSTR2SYM("style"), INT2FIX(draw->info->style));
    rb_hash_aset(ddraw, CSTR2SYM("stretch"), INT2FIX(draw->info->stretch));
    rb_hash_aset(ddraw, CSTR2SYM("weight"), ULONG2NUM(draw->info->weight));
    rb_hash_aset(ddraw, CSTR2SYM("encoding"), MAGICK_STRING_TO_OBJ(draw->info->encoding));
    rb_hash_aset(ddraw, CSTR2SYM("pointsize"), rb_float_new(draw->info->pointsize));
    rb_hash_aset(ddraw, CSTR2SYM("density"), MAGICK_STRING_TO_OBJ(draw->info->density));
    rb_hash_aset(ddraw, CSTR2SYM("align"), INT2FIX(draw->info->align));
    rb_hash_aset(ddraw, CSTR2SYM("undercolor"), Pixel_from_PixelPacket(&draw->info->undercolor));
    // rb_hash_aset(ddraw, CSTR2SYM("border_color"), Pixel_from_PixelPacket(&draw->info->border_color)); Montage and Polaroid
    // rb_hash_aset(ddraw, CSTR2SYM("server_name"), MAGICK_STRING_TO_OBJ(draw->info->server_name));
    // rb_hash_aset(ddraw, CSTR2SYM("dash_pattern"), dash_pattern_to_array(draw->info->dash_pattern)); internal
    // rb_hash_aset(ddraw, CSTR2SYM("clip_mask"), MAGICK_STRING_TO_OBJ(draw->info->clip_mask)); internal
    // rb_hash_aset(ddraw, CSTR2SYM("bounds"), Import_SegmentInfo(&draw->info->bounds)); internal
    rb_hash_aset(ddraw, CSTR2SYM("clip_units"), INT2FIX(draw->info->clip_units));
    rb_hash_aset(ddraw, CSTR2SYM("opacity"), QUANTUM2NUM(draw->info->opacity));
    // rb_hash_aset(ddraw, CSTR2SYM("render"), draw->info->render ? Qtrue : Qfalse); internal
    // rb_hash_aset(ddraw, CSTR2SYM("element_reference"), Qnil);     // not used yet
    // rb_hash_aset(ddraw, CSTR2SYM("debug"), draw->info->debug ? Qtrue : Qfalse);
#if defined(HAVE_ST_KERNING)
    rb_hash_aset(ddraw, CSTR2SYM("kerning"), rb_float_new(draw->info->kerning));
#endif
#if defined(HAVE_ST_INTERWORD_SPACING)
    rb_hash_aset(ddraw, CSTR2SYM("interword_spacing"), rb_float_new(draw->info->interword_spacing));
#endif

    // Non-DrawInfo fields
    rb_hash_aset(ddraw, CSTR2SYM("primitives"), draw->primitives);
    // rb_hash_aset(ddraw, CSTR2SYM("shadow_color"), Pixel_from_PixelPacket(&draw->shadow_color)); Polaroid-only

    return ddraw;
}

#marshal_load(ddraw) ⇒ Object

Support Marsal.load.

Ruby usage:

- @verbatim Draw#marshal_load @endverbatim

Notes:

- On entry all fields are all-bits-0

Parameters:

  • self

    this object

  • ddraw

    the marshalled object

Returns:

  • self, once marshalled


664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
# File 'ext/RMagick/rmdraw.c', line 664

VALUE
Draw_marshal_load(VALUE self, VALUE ddraw)
{
    Draw *draw;
    Pixel *pixel;
    VALUE val;

    Data_Get_Struct(self, Draw, draw);

    draw->info = magick_malloc(sizeof(DrawInfo));
    if (!draw->info)
    {
        rb_raise(rb_eNoMemError, "not enough memory to continue");
    }
    GetDrawInfo(NULL, draw->info);

    OBJ_TO_MAGICK_STRING(draw->info->geometry, rb_hash_aref(ddraw, CSTR2SYM("geometry")));

    //val = rb_hash_aref(ddraw, CSTR2SYM("viewbox"));
    //Export_RectangleInfo(&draw->info->viewbox, val);

    val = rb_hash_aref(ddraw, CSTR2SYM("affine"));
    Export_AffineMatrix(&draw->info->affine, val);

    draw->info->gravity = (GravityType) FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("gravity")));

    val = rb_hash_aref(ddraw, CSTR2SYM("fill"));
    Data_Get_Struct(val, Pixel, pixel);
    draw->info->fill =  *pixel;

    val = rb_hash_aref(ddraw, CSTR2SYM("stroke"));
    Data_Get_Struct(val, Pixel, pixel);
    draw->info->stroke = *pixel;

    draw->info->stroke_width = NUM2DBL(rb_hash_aref(ddraw, CSTR2SYM("stroke_width")));
    draw->info->fill_pattern = str_to_image(rb_hash_aref(ddraw, CSTR2SYM("fill_pattern")));
    draw->info->stroke_pattern = str_to_image(rb_hash_aref(ddraw, CSTR2SYM("stroke_pattern")));
    draw->info->stroke_antialias = RTEST(rb_hash_aref(ddraw, CSTR2SYM("stroke_antialias")));
    draw->info->text_antialias = RTEST(rb_hash_aref(ddraw, CSTR2SYM("text_antialias")));
    draw->info->decorate = (DecorationType) FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("decorate")));
    OBJ_TO_MAGICK_STRING(draw->info->font, rb_hash_aref(ddraw, CSTR2SYM("font")));
    OBJ_TO_MAGICK_STRING(draw->info->family, rb_hash_aref(ddraw, CSTR2SYM("family")));

    draw->info->style = (StyleType) FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("style")));
    draw->info->stretch = (StretchType) FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("stretch")));
    draw->info->weight = NUM2ULONG(rb_hash_aref(ddraw, CSTR2SYM("weight")));
    OBJ_TO_MAGICK_STRING(draw->info->encoding, rb_hash_aref(ddraw, CSTR2SYM("encoding")));
    draw->info->pointsize = NUM2DBL(rb_hash_aref(ddraw, CSTR2SYM("pointsize")));
    OBJ_TO_MAGICK_STRING(draw->info->density, rb_hash_aref(ddraw, CSTR2SYM("density")));
    draw->info->align = (AlignType) FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("align")));

    val = rb_hash_aref(ddraw, CSTR2SYM("undercolor"));
    Data_Get_Struct(val, Pixel, pixel);
    draw->info->undercolor = *pixel;

    draw->info->clip_units = FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("clip_units")));
    draw->info->opacity = NUM2QUANTUM(rb_hash_aref(ddraw, CSTR2SYM("opacity")));
#if defined(HAVE_ST_KERNING)
    draw->info->kerning = NUM2DBL(rb_hash_aref(ddraw, CSTR2SYM("kerning")));
#endif
#if defined(HAVE_ST_INTERWORD_SPACING)
    draw->info->interword_spacing = NUM2DBL(rb_hash_aref(ddraw, CSTR2SYM("interword_spacing")));
#endif

    draw->primitives = rb_hash_aref(ddraw, CSTR2SYM("primitives"));

    RB_GC_GUARD(val);

    return self;
}

#matte(x, y, method) ⇒ Object

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


420
421
422
423
424
425
# File 'lib/rmagick_internal.rb', line 420

def matte(x, y, method)
  unless  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.


429
430
431
432
433
434
435
436
# File 'lib/rmagick_internal.rb', line 429

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.


441
442
443
# File 'lib/rmagick_internal.rb', line 441

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


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

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

#point(x, y) ⇒ Object

Set point to fill color.


460
461
462
# File 'lib/rmagick_internal.rb', line 460

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.


466
467
468
# File 'lib/rmagick_internal.rb', line 466

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

#polygon(*points) ⇒ Object

Draw a polygon


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

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

#polyline(*points) ⇒ Object

Draw a polyline


482
483
484
485
486
487
488
489
# File 'lib/rmagick_internal.rb', line 482

def polyline(*points)
  if points.length == 0
    Kernel.raise ArgumentError, 'no points specified'
  elsif points.length.odd?
    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')


497
498
499
500
501
502
503
504
# File 'lib/rmagick_internal.rb', line 497

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

Add a drawing primitive to the list of primitives in the Draw object.

Ruby usage:

- @verbatim Draw#primitive @endverbatim

Parameters:

  • self

    this object

  • primitive

    the primitive to add

Returns:

  • self


1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
# File 'ext/RMagick/rmdraw.c', line 1598

VALUE
Draw_primitive(VALUE self, VALUE primitive)
{
    Draw *draw;

    rb_check_frozen(self);
    Data_Get_Struct(self, Draw, draw);

    if (draw->primitives == (VALUE)0)
    {
        draw->primitives = primitive;
    }
    else
    {
        draw->primitives = rb_str_concat(draw->primitives, rb_str_new2("\n"));
        draw->primitives = rb_str_concat(draw->primitives, primitive);
    }

    return self;
}

#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')


511
512
513
514
515
516
517
518
# File 'lib/rmagick_internal.rb', line 511

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


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

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


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

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

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

Draw a rectangle with rounded corners


532
533
534
535
# File 'lib/rmagick_internal.rb', line 532

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.


538
539
540
# File 'lib/rmagick_internal.rb', line 538

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

#skewx(angle) ⇒ Object


542
543
544
# File 'lib/rmagick_internal.rb', line 542

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

#skewy(angle) ⇒ Object


546
547
548
# File 'lib/rmagick_internal.rb', line 546

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.


551
552
553
# File 'lib/rmagick_internal.rb', line 551

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

#stroke_antialias(bool) ⇒ Object

Specify if stroke should be antialiased or not


558
559
560
561
# File 'lib/rmagick_internal.rb', line 558

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

#stroke_dasharray(*list) ⇒ Object

Specify a stroke dash pattern


564
565
566
567
568
569
570
571
572
573
574
575
# File 'lib/rmagick_internal.rb', line 564

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

#stroke_dashoffset(value = 0) ⇒ Object

Specify the initial offset in the dash pattern


578
579
580
# File 'lib/rmagick_internal.rb', line 578

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

#stroke_linecap(value) ⇒ Object


582
583
584
585
586
587
# File 'lib/rmagick_internal.rb', line 582

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

#stroke_linejoin(value) ⇒ Object


589
590
591
592
593
594
# File 'lib/rmagick_internal.rb', line 589

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

#stroke_miterlimit(value) ⇒ Object


596
597
598
599
600
601
# File 'lib/rmagick_internal.rb', line 596

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)

605
606
607
# File 'lib/rmagick_internal.rb', line 605

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

#stroke_width(pixels) ⇒ Object

Specify stroke (outline) width in pixels.


610
611
612
# File 'lib/rmagick_internal.rb', line 610

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.


615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
# File 'lib/rmagick_internal.rb', line 615

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


635
636
637
638
639
640
# File 'lib/rmagick_internal.rb', line 635

def text_align(alignment)
  unless  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


643
644
645
646
647
648
# File 'lib/rmagick_internal.rb', line 643

def text_anchor(anchor)
  unless  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.


651
652
653
654
# File 'lib/rmagick_internal.rb', line 651

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

#text_undercolor(color) ⇒ Object

Specify color underneath text


657
658
659
# File 'lib/rmagick_internal.rb', line 657

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.


663
664
665
# File 'lib/rmagick_internal.rb', line 663

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