Class: MagickWand::Drawing

Inherits:
Object
  • Object
show all
Defined in:
lib/magickwand.rb,
ext/magickwand/drawing.c

Instance Method Summary collapse

Constructor Details

#initializeObject

drawing = MagickWand::Drawing.new



40
41
42
43
44
45
46
47
# File 'ext/magickwand/drawing.c', line 40

static VALUE drawing_initialize(VALUE obj)
{
    Drawing *drawing;

    Data_Get_Struct(obj, Drawing, drawing);
    drawing->wand = NewDrawingWand();
    return obj;
}

Instance Method Details

#add_pathObject

add an SVG path to the drawing



56
57
58
59
60
61
62
63
# File 'lib/magickwand.rb', line 56

def add_path()
   begin
      start_path
      yield self if block_given?
   ensure
      finish_path
   end
end

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

drawing.affine(sx, sy, rx, ry, tx, ty)



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'ext/magickwand/drawing.c', line 150

static VALUE drawing_affine(VALUE obj, VALUE sx, VALUE sy, VALUE rx, VALUE ry, VALUE tx, VALUE ty)
{
    Drawing *drawing;
    AffineMatrix affine;

    rb_check_frozen(obj);
    Data_Get_Struct(obj, Drawing, drawing);

    affine.sx = NUM2DBL(sx);
    affine.sy = NUM2DBL(sy);
    affine.rx = NUM2DBL(rx);
    affine.ry = NUM2DBL(ry);
    affine.tx = NUM2DBL(tx);
    affine.ty = NUM2DBL(ty);

    DrawAffine(drawing->wand, &affine);
    mwr_check_drawingwand_error(drawing->wand);
    return obj;
}

#annotation(*args) ⇒ Object

drawing.annotation text, :x=>0, y=>0



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'ext/magickwand/drawing.c', line 176

static VALUE drawing_annotation(int argc, VALUE *argv, VALUE obj)
{
    Drawing *drawing;
    VALUE str, options, v;
    double x, y;
    unsigned char *text;

    rb_check_frozen(obj);
    Data_Get_Struct(obj, Drawing, drawing);

    (void)rb_scan_args(argc, argv, "11", &str, &options);
    text = (unsigned char *)StringValuePtr(str);

    x = mwr_get_option(options, "x", &v) ? NUM2DBL(v) : 0.0;
    y = mwr_get_option(options, "y", &v) ? NUM2DBL(v) : 0.0;
    DrawAnnotation(drawing->wand, x, y, text);
    mwr_check_drawingwand_error(drawing->wand);
    return obj;
}

#arc(*args) ⇒ Object

drawing.arc(width, height, start, end, :x=>0, :y=>0)



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'ext/magickwand/drawing.c', line 201

static VALUE drawing_arc(int argc, VALUE *argv, VALUE obj)
{
    Drawing *drawing;
    double sx, sy, ex, ey, sd, ed;
    VALUE width, height, start, end, options, v;

    rb_check_frozen(obj);
    Data_Get_Struct(obj, Drawing, drawing);

    (void)rb_scan_args(argc, argv, "41", &width, &height, &start, &end, &options);
    sx = mwr_get_option(options, "x", &v) ? NUM2DBL(v) : 0.0;
    sy = mwr_get_option(options, "y", &v) ? NUM2DBL(v) : 0.0;
    ex = sx + NUM2DBL(width);
    ey = sy + NUM2DBL(height);
    sd = NUM2DBL(start);
    ed = NUM2DBL(end);

    DrawArc(drawing->wand, sx, sy, ex, ey, sd, ed);
    mwr_check_drawingwand_error(drawing->wand);
    return obj;
}

#bezier(*args) ⇒ Object

drawing.bezier(x1, y1, …, xN, yN)



229
230
231
232
# File 'ext/magickwand/drawing.c', line 229

static VALUE drawing_bezier(int argc, VALUE *argv, VALUE obj)
{
    return polyshape(argc, argv, obj, DrawBezier);
}

#circle(*args) ⇒ Object

drawing.circle r, :x=>0, :y=>0



240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'ext/magickwand/drawing.c', line 240

static VALUE drawing_circle(int argc, VALUE *argv, VALUE obj)
{
    Drawing *drawing;
    VALUE r, v, options;
    double x, y;
    double radius;

    rb_check_frozen(obj);
    Data_Get_Struct(obj, Drawing, drawing);

    (void)rb_scan_args(argc, argv, "11", &r, &options);
    radius = NUM2DBL(r);
    if (radius <= 0.0)
    {
        rb_raise(rb_eArgError, "radius must be positive (got %g)", radius);
    }

    x = mwr_get_option(options, "x", &v) ? NUM2DBL(v) : 0.0;
    y = mwr_get_option(options, "y", &v) ? NUM2DBL(v) : 0.0;
    DrawCircle(drawing->wand, x, y, x+radius, y);
    mwr_check_drawingwand_error(drawing->wand);
    return obj;
}

#close_pathObject

drawing.close_path()



411
412
413
414
415
416
417
418
419
420
# File 'ext/magickwand/drawing.c', line 411

static VALUE drawing_path_close(VALUE obj)
{
    Drawing *drawing;

    rb_check_frozen(obj);
    Data_Get_Struct(obj, Drawing, drawing);
    DrawPathClose(drawing->wand);
    mwr_check_drawingwand_error(drawing->wand);
    return obj;
}

#color(*args) ⇒ Object

drawing.color(x, y, :method=>“point”, :bordercolor=>“#dfdfdfdfdfdf”)



309
310
311
312
# File 'ext/magickwand/drawing.c', line 309

static VALUE drawing_color(int argc, VALUE *argv, VALUE obj)
{
    return draw_color(argc, argv, obj, DrawColor);
}

#composite(*args) ⇒ Object

drawing.composite(wand, :x=>0, :y=>0, :width=>0, :height=>0, :compose=>“over”)



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'ext/magickwand/drawing.c', line 320

static VALUE drawing_composite(int argc, VALUE *argv, VALUE obj)
{
    Drawing *drawing;
    Wand *composite_wand;
    VALUE v, options, compose_obj;
    double x, y, width, height;
    CompositeOperator compose;

    rb_check_frozen(obj);

    (void)rb_scan_args(argc, argv, "11", &compose_obj, &options);
    x = mwr_get_option(options, "x", &v) ? NUM2DBL(v) : 0.0;
    y = mwr_get_option(options, "y", &v) ? NUM2DBL(v) : 0.0;
    width = mwr_get_option(options, "width", &v) ? NUM2DBL(v) : 0.0;
    height = mwr_get_option(options, "height", &v) ? NUM2DBL(v) : 0.0;
    (void) mwr_get_option(options, "compose", &v);
    compose = mwr_string_to_composetype(v, OverCompositeOp, RaiseUndefinedOption);

    Data_Get_Struct(obj, Drawing, drawing);
    Data_Get_Struct(compose_obj, Wand, composite_wand);

    DrawComposite(drawing->wand, compose, x, y, width, height, composite_wand->magickwand);
    mwr_check_drawingwand_error(drawing->wand);
    return obj;
}

#curve_to_absolute(x1, y1, x2, y2, x, y) ⇒ Object

path.curve_to_absolute(x1, y1, x2, y2, x, y)



444
445
446
447
448
# File 'ext/magickwand/drawing.c', line 444

static VALUE drawing_path_curve_to_absolute(VALUE obj, VALUE x1, VALUE y1,
    VALUE x2, VALUE y2, VALUE x, VALUE y)
{
    return path_curve_to(obj, x1, y1, x2, y2, x, y, DrawPathCurveToAbsolute);
}

#curve_to_quadratic_bezier_absolute(x1, y1, x, y) ⇒ Object

path.curve_to_quadratic_bezier_absolute(x1, y1, x, y)



484
485
486
487
488
# File 'ext/magickwand/drawing.c', line 484

static VALUE drawing_path_curve_to_quadratic_bezier_absolute(VALUE obj,
    VALUE x1, VALUE y1, VALUE x, VALUE y)
{
    return path_curve_to_quadratic_bezier(obj, x1, y1, x, y, DrawPathCurveToQuadraticBezierAbsolute);
}

#curve_to_quadratic_bezier_relative(x1, y1, x, y) ⇒ Object

path.curve_to_quadratic_bezier_relative(x1, y1, x, y)



496
497
498
499
500
# File 'ext/magickwand/drawing.c', line 496

static VALUE drawing_path_curve_to_quadratic_bezier_relative(VALUE obj,
    VALUE x1, VALUE y1, VALUE x, VALUE y)
{
    return path_curve_to_quadratic_bezier(obj, x1, y1, x, y, DrawPathCurveToQuadraticBezierRelative);
}

#curve_to_quadratic_bezier_smooth_absolute(x, y) ⇒ Object

path.curve_to_quadratic_bezier_smooth_absolute(x, y)



523
524
525
526
# File 'ext/magickwand/drawing.c', line 523

static VALUE drawing_path_curve_to_quadratic_bezier_smooth_absolute(VALUE obj, VALUE x, VALUE y)
{
    return path_curve_to_quadratic_bezier_smooth(obj, x, y, DrawPathCurveToQuadraticBezierSmoothAbsolute);
}

#curve_to_quadratic_bezier_smooth_relative(x, y) ⇒ Object

path.curve_to_quadratic_bezier_smooth_relative(x, y)



534
535
536
537
# File 'ext/magickwand/drawing.c', line 534

static VALUE drawing_path_curve_to_quadratic_bezier_smooth_relative(VALUE obj, VALUE x, VALUE y)
{
    return path_curve_to_quadratic_bezier_smooth(obj, x, y, DrawPathCurveToQuadraticBezierSmoothRelative);
}

#curve_to_relative(x1, y1, x2, y2, x, y) ⇒ Object

path.curve_to_relative(x1, y1, x2, y2, x, y)



456
457
458
459
460
# File 'ext/magickwand/drawing.c', line 456

static VALUE drawing_path_curve_to_relative(VALUE obj, VALUE x1, VALUE y1,
    VALUE x2, VALUE y2, VALUE x, VALUE y)
{
    return path_curve_to(obj, x1, y1, x2, y2, x, y, DrawPathCurveToRelative);
}

#curve_to_smooth_absolute(x2, y2, x, y) ⇒ Object

path.curve_to_smooth_absolute(x2, y2, x, y)



560
561
562
563
# File 'ext/magickwand/drawing.c', line 560

static VALUE drawing_path_curve_to_smooth_absolute(VALUE obj, VALUE x2, VALUE y2, VALUE x, VALUE y)
{
    return path_curve_to_smooth(obj, x2, y2, x, y, DrawPathCurveToSmoothAbsolute);
}

#curve_to_smooth_relative(x2, y2, x, y) ⇒ Object

path.curve_to_smooth_relative(x2, y2, x, y)



571
572
573
574
# File 'ext/magickwand/drawing.c', line 571

static VALUE drawing_path_curve_to_smooth_relative(VALUE obj, VALUE x2, VALUE y2, VALUE x, VALUE y)
{
    return path_curve_to_smooth(obj, x2, y2, x, y, DrawPathCurveToSmoothRelative);
}

#define_clip_path(name, &block) ⇒ Object

drawing.define_clip_path(name) do … end



51
52
53
# File 'lib/magickwand.rb', line 51

def define_clip_path(name, &block)
   define_element("clip_path", name, &block)
end

#define_pattern(name, options = nil, &block) ⇒ Object

drawing.define_pattern(name, :x=>0, :y=>0, :width=>0, :height=>0) do … end



46
47
48
# File 'lib/magickwand.rb', line 46

def define_pattern(name, options=nil, &block)
   define_element("pattern", name, options, &block)
end

#ellipse(*args) ⇒ Object

drawing.ellipse(rx, ry, :start=>0, :end=>360, :x=>0, :y=>0) :x and :y are the origin.



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'ext/magickwand/drawing.c', line 353

static VALUE drawing_ellipse(int argc, VALUE *argv, VALUE obj)
{
    Drawing *drawing;
    VALUE x_rad, y_rad, options, v;
    double rx, ry, cx, cy;
    double start, end;

    rb_check_frozen(obj);
    Data_Get_Struct(obj, Drawing, drawing);

    (void)rb_scan_args(argc, argv, "21", &x_rad, &y_rad, &options);
    rx = NUM2DBL(x_rad);
    ry = NUM2DBL(y_rad);
    cx = mwr_get_option(options, "x", &v) ? NUM2DBL(v) : 0.0;
    cy = mwr_get_option(options, "y", &v) ? NUM2DBL(v) : 0.0;
    start = mwr_get_option(options, "start", &v) ? NUM2DBL(v) : 0.0;
    end = mwr_get_option(options, "end", &v) ? NUM2DBL(v) : 360.0;

    DrawEllipse(drawing->wand, cx, cy, rx, ry, start, end);
    mwr_check_drawingwand_error(drawing->wand);
    return obj;
}

#elliptic_arc_absolute(rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y) ⇒ Object

path.elliptic_arc_absolute(rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y)



600
601
602
603
604
605
# File 'ext/magickwand/drawing.c', line 600

static VALUE drawing_path_elliptic_arc_absolute(VALUE obj, VALUE rx, VALUE ry,
    VALUE x_axis_rotation, VALUE large_arc_flag, VALUE sweep_flag, VALUE x, VALUE y)
{
    return path_elliptic_arc(obj, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y,
                             DrawPathEllipticArcAbsolute);
}

#elliptic_arc_relative(rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y) ⇒ Object

path.elliptic_arc_relative(rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y)



613
614
615
616
617
618
# File 'ext/magickwand/drawing.c', line 613

static VALUE drawing_path_elliptic_arc_relative(VALUE obj, VALUE rx, VALUE ry,
    VALUE x_axis_rotation, VALUE large_arc_flag, VALUE sweep_flag, VALUE x, VALUE y)
{
    return path_elliptic_arc(obj, rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y,
                             DrawPathEllipticArcRelative);
}

#initialize_copy(obj2) ⇒ Object

drawing2 = drawing.dup drawing2 = drawing.clone



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'ext/magickwand/drawing.c', line 72

static VALUE drawing_initialize_copy(VALUE obj, VALUE obj2)
{
    Drawing *drawing, *drawing2;

    if (obj == obj2)
    {
        return obj;
    }

    Data_Get_Struct(obj, Drawing, drawing);
    Data_Get_Struct(obj2, Drawing, drawing2);

    drawing->wand = CloneDrawingWand(drawing2->wand);
    return obj;
}

#inspectObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'ext/magickwand/drawing.c', line 91

static VALUE drawing_inspect(VALUE obj)
{
    Drawing *drawing;
    volatile VALUE string;
    char *text, *start, *end;
    size_t len;

    Data_Get_Struct(obj, Drawing, drawing);

    text = DrawGetVectorGraphics(drawing->wand);

    // The drawing primitives are contained in the <vector-graphics> element.
    // Delete everything else.
    if (text)
    {
        start = strstr(text, "<vector-graphics>");
        if (start)
        {
            end = strstr(start, "</vector-graphics>");
            if (end)
            {
                start += 17;
                len = end - start;
                if (start[len-1] == '\n')
                {
                    len -= 1;
                }
                string = rb_str_new(start, len);
            }
            else
            {
                goto no_graphics;
            }
        }
        else
        {
            goto no_graphics;
        }

        RelinquishMagickMemory(text);
    }
    else
    {
        goto no_graphics;
    }

    return string;

no_graphics:
    return rb_call_super(0, NULL);

}

#line(x1, y1, x2, y2) ⇒ Object

drawing.line(x1, y1, x2, y2)



382
383
384
385
386
387
388
389
390
391
392
# File 'ext/magickwand/drawing.c', line 382

static VALUE drawing_line(VALUE obj, VALUE x1, VALUE y1, VALUE x2, VALUE y2)
{
    Drawing *drawing;

    rb_check_frozen(obj);
    Data_Get_Struct(obj, Drawing, drawing);

    DrawLine(drawing->wand, NUM2DBL(x1), NUM2DBL(y1), NUM2DBL(x2), NUM2DBL(y2));
    mwr_check_drawingwand_error(drawing->wand);
    return obj;
}

#line_to_absolute(x, y) ⇒ Object

path.line_to_absolute(x, y)



652
653
654
655
# File 'ext/magickwand/drawing.c', line 652

static VALUE drawing_path_line_to_absolute(VALUE obj, VALUE x, VALUE y)
{
    return path_line_to(obj, x, y, DrawPathLineToAbsolute);
}

#line_to_horizontal_absolute(x) ⇒ Object

path.line_to_horizontal_absolute(x)



678
679
680
681
# File 'ext/magickwand/drawing.c', line 678

static VALUE drawing_path_line_to_horizontal_absolute(VALUE obj, VALUE x)
{
    return path_line_to_direction(obj, x, DrawPathLineToHorizontalAbsolute);
}

#line_to_horizontal_relative(x) ⇒ Object

path.line_to_horizontal_relative(x)



689
690
691
692
# File 'ext/magickwand/drawing.c', line 689

static VALUE drawing_path_line_to_horizontal_relative(VALUE obj, VALUE x)
{
    return path_line_to_direction(obj, x, DrawPathLineToHorizontalRelative);
}

#line_to_relative(x, y) ⇒ Object

path.line_to_relative(x, y)



641
642
643
644
# File 'ext/magickwand/drawing.c', line 641

static VALUE drawing_path_line_to_relative(VALUE obj, VALUE x, VALUE y)
{
    return path_line_to(obj, x, y, DrawPathLineToRelative);
}

#line_to_vertical_absolute(y) ⇒ Object

path.line_to_vertical_absolute(y)



700
701
702
703
# File 'ext/magickwand/drawing.c', line 700

static VALUE drawing_path_line_to_vertical_absolute(VALUE obj, VALUE y)
{
    return path_line_to_direction(obj, y, DrawPathLineToVerticalAbsolute);
}

#line_to_vertical_relative(y) ⇒ Object

path.line_to_vertical_relative(y)



711
712
713
714
# File 'ext/magickwand/drawing.c', line 711

static VALUE drawing_path_line_to_vertical_relative(VALUE obj, VALUE y)
{
    return path_line_to_direction(obj, y, DrawPathLineToVerticalRelative);
}

#matte(*args) ⇒ Object

drawing.matte(x, y, :method=>“point”, :bordermatte=>“#dfdfdfdfdfdf”)



400
401
402
403
# File 'ext/magickwand/drawing.c', line 400

static VALUE drawing_matte(int argc, VALUE *argv, VALUE obj)
{
    return draw_color(argc, argv, obj, DrawMatte);
}

#move_to_absolute(x, y) ⇒ Object

path.move_to_absolute(x, y)



722
723
724
725
# File 'ext/magickwand/drawing.c', line 722

static VALUE drawing_path_move_to_absolute(VALUE obj, VALUE x, VALUE y)
{
    return path_line_to(obj, x, y, DrawPathMoveToAbsolute);
}

#move_to_relative(x, y) ⇒ Object

path.move_to_relative(x, y)



733
734
735
736
# File 'ext/magickwand/drawing.c', line 733

static VALUE drawing_path_move_to_relative(VALUE obj, VALUE x, VALUE y)
{
    return path_line_to(obj, x, y, DrawPathMoveToRelative);
}

#polygon(*args) ⇒ Object

drawing.polygon(x1, y1, …, xN, yN)



815
816
817
818
# File 'ext/magickwand/drawing.c', line 815

static VALUE drawing_polygon(int argc, VALUE *argv, VALUE obj)
{
    return polyshape(argc, argv, obj, DrawPolygon);
}

#polyline(*args) ⇒ Object

drawing.polyline(x1, y1, …, xN, yN)



826
827
828
829
# File 'ext/magickwand/drawing.c', line 826

static VALUE drawing_polyline(int argc, VALUE *argv, VALUE obj)
{
    return polyshape(argc, argv, obj, DrawPolyline);
}

#rectangle(*args) ⇒ Object

drawing.rectangle(width, height, :x=>0, :y=>0, :rx=>0, :ry=>rx)



952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
# File 'ext/magickwand/drawing.c', line 952

static VALUE drawing_rectangle(int argc, VALUE *argv, VALUE obj)
{
    Drawing *drawing;
    VALUE v, w, h, options;
    double x1,  y1, x2, y2, rx, ry;
    double width, height;

    rb_check_frozen(obj);
    Data_Get_Struct(obj, Drawing, drawing);

    (void)rb_scan_args(argc, argv, "21", &w, &h, &options);
    width = NUM2DBL(w);
    height = NUM2DBL(h);
    x1 = mwr_get_option(options, "x", &v) ? NUM2DBL(v) : 0.0;
    y1 = mwr_get_option(options, "y", &v) ? NUM2DBL(v) : 0.0;
    x2 = x1 + width;
    y2 = y1 + height;

    rx = mwr_get_option(options, "rx", &v) ? NUM2DBL(v) : 0.0;
    ry = mwr_get_option(options, "ry", &v) ? NUM2DBL(v) : rx;

    if (rx == 0.0 && ry != 0.0)
    {
        rb_raise(rb_eArgError, "When y corner radius is non-0 the x corner radius must also be non-0 (:ry=>%g)", ry);
    }

    if (rx == 0.0 && ry == 0.0)
    {
        DrawRectangle(drawing->wand, x1, y1, x2, y2);
    }
    else
    {
        DrawRoundRectangle(drawing->wand, x1, y1, x2, y2, rx, ry);
    }
    mwr_check_drawingwand_error(drawing->wand);

    return obj;
}

#rotate(*args) ⇒ Object

drawing.rotate(angle, x=0, y=0)



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
# File 'ext/magickwand/drawing.c', line 997

static VALUE drawing_rotate(int argc, VALUE *argv, VALUE obj)
{
    Drawing *drawing;
    VALUE angle, x, y;
    double degrees, cx = 0.0, cy = 0.0;

    rb_check_frozen(obj);
    Data_Get_Struct(obj, Drawing, drawing);

    (void)rb_scan_args(argc, argv, "12", &angle, &x, &y);
    degrees = NUM2DBL(angle);
    cx = !NIL_P(x) ? NUM2DBL(x) : 0.0;
    cy = !NIL_P(y) ? NUM2DBL(y) : 0.0;

    if (cx != 0.0 || cy != 0.0)
    {
        DrawTranslate(drawing->wand, cx, cy);
        mwr_check_drawingwand_error(drawing->wand);
    }
    DrawRotate(drawing->wand, degrees);
    mwr_check_drawingwand_error(drawing->wand);
    if (cx != 0.0 || cy != 0.0)
    {
        DrawTranslate(drawing->wand, -cx, -cy);
        mwr_check_drawingwand_error(drawing->wand);
    }

    return obj;
}

#scale(*args) ⇒ Object

drawing.scale(sx[, sy=sx])



1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
# File 'ext/magickwand/drawing.c', line 1032

static VALUE drawing_scale(int argc, VALUE *argv, VALUE obj)
{
    Drawing *drawing;
    VALUE x, y;
    double sx, sy;

    rb_check_frozen(obj);

    (void)rb_scan_args(argc, argv, "11", &x, &y);
    sx = NUM2DBL(x);
    sy = (y == Qnil) ? sx : NUM2DBL(y);

    Data_Get_Struct(obj, Drawing, drawing);
    DrawScale(drawing->wand, sx, sy);
    mwr_check_drawingwand_error(drawing->wand);
    return obj;
}

#skew(*args) ⇒ Object

drawing.skew(x, y=0.0)



1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
# File 'ext/magickwand/drawing.c', line 1439

static VALUE drawing_skew(int argc, VALUE *argv, VALUE obj)
{
    Drawing *drawing;
    VALUE x, y;
    double rx, ry;

    rb_check_frozen(obj);
    Data_Get_Struct(obj, Drawing, drawing);

    (void)rb_scan_args(argc, argv, "11", &x, &y);
    rx = NUM2DBL(x);
    ry = y != Qnil ? NUM2DBL(y) : 0.0;

    if (rx != 0.0)
    {
        DrawSkewX(drawing->wand, rx);
        mwr_check_drawingwand_error(drawing->wand);
    }
    if (ry != 0.0)
    {
        DrawSkewY(drawing->wand, ry);
        mwr_check_drawingwand_error(drawing->wand);
    }

    return obj;
}

#translate(*args) ⇒ Object

drawing.translate(tx, ty=0.0)



1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
# File 'ext/magickwand/drawing.c', line 1472

static VALUE drawing_translate(int argc, VALUE *argv, VALUE obj)
{
    Drawing *drawing;
    VALUE x, y;
    double tx, ty;

    rb_check_frozen(obj);
    Data_Get_Struct(obj, Drawing, drawing);

    (void)rb_scan_args(argc, argv, "11", &x, &y);
    tx = NUM2DBL(x);
    ty = (y != Qnil) ? NUM2DBL(y) : 0.0;

    DrawTranslate(drawing->wand, tx, ty);
    mwr_check_drawingwand_error(drawing->wand);
    return obj;
}

#with(styles) ⇒ Object

push new context, add styles, yield to block. Does not actually require a block but it’s not very useful otherwise.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/magickwand.rb', line 67

def with(styles)
   begin
      push
      unless styles.nil?
         # The :fill_opacity and :stroke_opacity styles must succeed
         # the :fill and :stroke styles, otherwise the opacity specified
         # by the :fill or :stroke color will override that specified by
         # the :xxx_opacity style. Therefore we make two passes over the
         # options hash. The first pass handles all options except
         # :fill_opacity and :stroke_opacity. Then 2nd pass handles only
         # those two options.
         styles.each do |style, value|
            next if style == :fill_opacity || style == :stroke_opacity
            begin
               __send__("with_"+style.to_s, *value)
            rescue NoMethodError
               raise ArgumentError, "unknown style `:#{style}'"
            end
         end

         styles.each do |style, value|
            next unless style == :fill_opacity || style == :stroke_opacity
            begin
               __send__("with_"+style.to_s, *value)
            rescue NoMethodError
               raise ArgumentError, "unknown style `:#{style}'"
            end
         end
      end
      yield if block_given?
   ensure
      pop
   end
end

#wrapObject

yield to block in new (temporary) drawing context. Accepts no arguments but requires a block.



104
105
106
107
108
109
110
111
# File 'lib/magickwand.rb', line 104

def wrap()
   begin
      push
      yield
   ensure
      pop
   end
end