Class: Magick::Image::DrawOptions

Inherits:
Object
  • Object
show all
Defined in:
ext/RMagick/rmmain.c

Instance Method Summary collapse

Constructor Details

#initializeMagick::Image::DrawOptions

Initialize a DrawOptions object.


1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
# File 'ext/RMagick/rmdraw.c', line 1378

VALUE
DrawOptions_initialize(VALUE self)
{
    Draw *draw_options;

    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw_options);
    draw_options->info = AcquireDrawInfo();
    if (!draw_options->info)
    {
        rb_raise(rb_eNoMemError, "not enough memory to continue");
    }

    GetDrawInfo(NULL, draw_options->info);

    if (rb_block_given_p())
    {
        rb_yield(self);
    }

    return self;
}

Instance Method Details

#affine=(matrix) ⇒ Magick::AffineMatrix

Set the affine matrix from an AffineMatrix.

Parameters:

  • matrix (Magick::AffineMatrix)

    the affine matrix

Returns:

  • (Magick::AffineMatrix)

    the given matrix


51
52
53
54
55
56
57
58
59
60
# File 'ext/RMagick/rmdraw.c', line 51

VALUE
Draw_affine_eq(VALUE self, VALUE matrix)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    Export_AffineMatrix(&draw->info->affine, matrix);
    return matrix;
}

#align=(align) ⇒ Magick::AlignType

Set the text alignment from an AlignType.

Parameters:

  • align (Magick::AlignType)

    the text alignment

Returns:

  • (Magick::AlignType)

    the given align


69
70
71
72
73
74
75
76
77
78
# File 'ext/RMagick/rmdraw.c', line 69

VALUE
Draw_align_eq(VALUE self, VALUE align)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    VALUE_TO_ENUM(align, draw->info->align, AlignType);
    return align;
}

#decorate=(decorate) ⇒ Magick::DecorationType

Set text decorate from an DecorationType.

Parameters:

  • decorate (Magick::DecorationType)

    the decorate type

Returns:

  • (Magick::DecorationType)

    the given decorate


87
88
89
90
91
92
93
94
95
96
# File 'ext/RMagick/rmdraw.c', line 87

VALUE
Draw_decorate_eq(VALUE self, VALUE decorate)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    VALUE_TO_ENUM(decorate, draw->info->decorate, DecorationType);
    return decorate;
}

#density=(density) ⇒ String

Set density.

Parameters:

  • density (String)

    the density

Returns:

  • (String)

    the given density


105
106
107
108
109
110
111
112
113
114
115
# File 'ext/RMagick/rmdraw.c', line 105

VALUE
Draw_density_eq(VALUE self, VALUE density)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    magick_clone_string(&draw->info->density, StringValueCStr(density));

    return density;
}

#encoding=(encoding) ⇒ String

Set text encoding.

Parameters:

  • encoding (String)

    the encoding name

Returns:

  • (String)

    the given encoding name


124
125
126
127
128
129
130
131
132
133
134
# File 'ext/RMagick/rmdraw.c', line 124

VALUE
Draw_encoding_eq(VALUE self, VALUE encoding)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    magick_clone_string(&draw->info->encoding, StringValueCStr(encoding));

    return encoding;
}

#fill=(fill) ⇒ Magick::Pixel, String

Set fill color.

Parameters:

Returns:


143
144
145
146
147
148
149
150
151
152
# File 'ext/RMagick/rmdraw.c', line 143

VALUE
Draw_fill_eq(VALUE self, VALUE fill)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    Color_to_PixelColor(&draw->info->fill, fill);
    return fill;
}

#fill_pattern=(pattern) ⇒ Magick::Image

Accept an image as a fill pattern.

Parameters:

Returns:

See Also:


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'ext/RMagick/rmdraw.c', line 164

VALUE
Draw_fill_pattern_eq(VALUE self, VALUE pattern)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);

    if (draw->info->fill_pattern != NULL)
    {
        // Do not trace destruction
        DestroyImage(draw->info->fill_pattern);
        draw->info->fill_pattern = NULL;
    }

    if (!NIL_P(pattern))
    {
        Image *image;

        pattern = rm_cur_image(pattern);
        image = rm_check_destroyed(pattern);
        // Do not trace creation
        draw->info->fill_pattern = rm_clone_image(image);
    }

    return pattern;
}

#font=(font) ⇒ String

Set the font name.

Parameters:

  • font (String)

    the font name

Returns:

  • (String)

    the given font name


199
200
201
202
203
204
205
206
207
208
209
# File 'ext/RMagick/rmdraw.c', line 199

VALUE
Draw_font_eq(VALUE self, VALUE font)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    magick_clone_string(&draw->info->font, StringValueCStr(font));

    return font;
}

#font_family=(family) ⇒ String

Set the font family name.

Parameters:

  • family (String)

    the font family name

Returns:

  • (String)

    the given family name


218
219
220
221
222
223
224
225
226
227
228
# File 'ext/RMagick/rmdraw.c', line 218

VALUE
Draw_font_family_eq(VALUE self, VALUE family)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    magick_clone_string(&draw->info->family, StringValueCStr(family));

    return family;
}

#font_stretch=(stretch) ⇒ Magick::StretchType

Set the stretch as spacing between text characters.

Parameters:

  • stretch (Magick::StretchType)

    the stretch type

Returns:

  • (Magick::StretchType)

    the given stretch type


237
238
239
240
241
242
243
244
245
246
# File 'ext/RMagick/rmdraw.c', line 237

VALUE
Draw_font_stretch_eq(VALUE self, VALUE stretch)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    VALUE_TO_ENUM(stretch, draw->info->stretch, StretchType);
    return stretch;
}

#font_style=(style) ⇒ Magick::StyleType

Set font style.

Parameters:

  • style (Magick::StyleType)

    the font style

Returns:

  • (Magick::StyleType)

    the given font style


255
256
257
258
259
260
261
262
263
264
# File 'ext/RMagick/rmdraw.c', line 255

VALUE
Draw_font_style_eq(VALUE self, VALUE style)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    VALUE_TO_ENUM(style, draw->info->style, StyleType);
    return style;
}

#font_weight=(weight) ⇒ Magick::WeightType, Numeric

Note:

The font weight can be one of the font weight constants or a number between 100 and 900

Set font weight.

Parameters:

  • weight (Magick::WeightType, Numeric)

    the font weight

Returns:

  • (Magick::WeightType, Numeric)

    the given font weight


274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'ext/RMagick/rmdraw.c', line 274

VALUE
Draw_font_weight_eq(VALUE self, VALUE weight)
{
    Draw *draw;
    size_t w;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);

    if (FIXNUM_P(weight))
    {
        w = FIX2INT(weight);
        if (w < 100 || w > 900)
        {
            rb_raise(rb_eArgError, "invalid font weight (%"RMIuSIZE" given)", w);
        }
        draw->info->weight = w;
    }
    else
    {
        VALUE_TO_ENUM(weight, w, WeightType);
        switch (w)
        {
            case AnyWeight:
                draw->info->weight = 0;
                break;
            case NormalWeight:
                draw->info->weight = 400;
                break;
            case BoldWeight:
                draw->info->weight = 700;
                break;
            case BolderWeight:
                if (draw->info->weight <= 800)
                    draw->info->weight += 100;
                break;
            case LighterWeight:
                if (draw->info->weight >= 100)
                    draw->info->weight -= 100;
                break;
            default:
                rb_raise(rb_eArgError, "unknown font weight");
                break;
        }
    }

    return weight;
}

#gravity=(grav) ⇒ Magick::GravityType

Set gravity to draw text. Gravity affects text placement in bounding area according to rules:

  • NorthWestGravity - text bottom-left corner placed at top-left

  • NorthGravity - text bottom-center placed at top-center

  • NorthEastGravity - text bottom-right corner placed at top-right

  • WestGravity - text left-center placed at left-center

  • CenterGravity - text center placed at center

  • EastGravity - text right-center placed at right-center

  • SouthWestGravity - text top-left placed at bottom-left

  • SouthGravity - text top-center placed at bottom-center

  • SouthEastGravity - text top-right placed at bottom-right

Parameters:

  • grav (Magick::GravityType)

    this gravity type

Returns:

  • (Magick::GravityType)

    the given gravity type


341
342
343
344
345
346
347
348
349
350
351
# File 'ext/RMagick/rmdraw.c', line 341

VALUE
Draw_gravity_eq(VALUE self, VALUE grav)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    VALUE_TO_ENUM(grav, draw->info->gravity, GravityType);

    return grav;
}

#pointsize=(pointsize) ⇒ Float

Set point size to draw text.

Parameters:

  • pointsize (Float)

    the pointsize

Returns:

  • (Float)

    the given pointsize


628
629
630
631
632
633
634
635
636
637
# File 'ext/RMagick/rmdraw.c', line 628

VALUE
Draw_pointsize_eq(VALUE self, VALUE pointsize)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    draw->info->pointsize = NUM2DBL(pointsize);
    return pointsize;
}

#rotation=(deg) ⇒ Float

Set rotation. The argument should be in degrees.

Parameters:

  • deg (Float)

    the number of degrees

Returns:

  • (Float)

    the given degrees


646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'ext/RMagick/rmdraw.c', line 646

VALUE
Draw_rotation_eq(VALUE self, VALUE deg)
{
    Draw *draw;
    double degrees;
    AffineMatrix affine, current;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);

    degrees = NUM2DBL(deg);
    if (fabs(degrees) > DBL_EPSILON)
    {
        current   = draw->info->affine;
        affine.sx = cos(DegreesToRadians(fmod(degrees, 360.0)));
        affine.rx = sin(DegreesToRadians(fmod(degrees, 360.0)));
        affine.tx = 0.0;
        affine.ry = (-sin(DegreesToRadians(fmod(degrees, 360.0))));
        affine.sy = cos(DegreesToRadians(fmod(degrees, 360.0)));
        affine.ty = 0.0;

        draw->info->affine.sx = current.sx*affine.sx+current.ry*affine.rx;
        draw->info->affine.rx = current.rx*affine.sx+current.sy*affine.rx;
        draw->info->affine.ry = current.sx*affine.ry+current.ry*affine.sy;
        draw->info->affine.sy = current.rx*affine.ry+current.sy*affine.sy;
        draw->info->affine.tx = current.sx*affine.tx+current.ry*affine.ty+current.tx;
    }

    return deg;
}

#stroke=(stroke) ⇒ Magick::Pixel, String

Set stroke.

Parameters:

Returns:


684
685
686
687
688
689
690
691
692
693
# File 'ext/RMagick/rmdraw.c', line 684

VALUE
Draw_stroke_eq(VALUE self, VALUE stroke)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    Color_to_PixelColor(&draw->info->stroke, stroke);
    return stroke;
}

#stroke_pattern=(pattern) ⇒ Magick::Image

Accept an image as a stroke pattern.

Parameters:

Returns:

See Also:

  • #fill_pattern

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
# File 'ext/RMagick/rmdraw.c', line 704

VALUE
Draw_stroke_pattern_eq(VALUE self, VALUE pattern)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);

    if (draw->info->stroke_pattern != NULL)
    {
        // Do not trace destruction
        DestroyImage(draw->info->stroke_pattern);
        draw->info->stroke_pattern = NULL;
    }

    if (!NIL_P(pattern))
    {
        Image *image;

        // DestroyDrawInfo destroys the clone
        pattern = rm_cur_image(pattern);
        image = rm_check_destroyed(pattern);
        // Do not trace creation
        draw->info->stroke_pattern = rm_clone_image(image);
    }

    return pattern;
}

#stroke_width=(stroke_width) ⇒ Float

Set stroke width.

Parameters:

  • stroke_width (Float)

    the stroke width

Returns:

  • (Float)

    the given stroke width


740
741
742
743
744
745
746
747
748
749
# File 'ext/RMagick/rmdraw.c', line 740

VALUE
Draw_stroke_width_eq(VALUE self, VALUE stroke_width)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    draw->info->stroke_width = NUM2DBL(stroke_width);
    return stroke_width;
}

#text_antialias=(text_antialias) ⇒ Boolean

Set whether to enable text antialias.

Parameters:

  • text_antialias (Boolean)

    true if enable text antialias

Returns:

  • (Boolean)

    the given value


758
759
760
761
762
763
764
765
766
767
# File 'ext/RMagick/rmdraw.c', line 758

VALUE
Draw_text_antialias_eq(VALUE self, VALUE text_antialias)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    draw->info->text_antialias = (MagickBooleanType) RTEST(text_antialias);
    return text_antialias;
}

#tile=(image) ⇒ Magick::Image

Accept an image as a fill pattern. This is alias of Draw#fill_pattern=.

Parameters:

Returns:


776
777
778
779
780
# File 'ext/RMagick/rmdraw.c', line 776

VALUE
Draw_tile_eq(VALUE self, VALUE image)
{
    return Draw_fill_pattern_eq(self, image);
}

#undercolor=(undercolor) ⇒ Magick::Pixel, String

Set undercolor.

Parameters:

Returns:


789
790
791
792
793
794
795
796
797
798
# File 'ext/RMagick/rmdraw.c', line 789

VALUE
Draw_undercolor_eq(VALUE self, VALUE undercolor)
{
    Draw *draw;

    rb_check_frozen(self);
    TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
    Color_to_PixelColor(&draw->info->undercolor, undercolor);
    return undercolor;
}