Class: Magick::Draw
- Inherits:
-
Object
- Object
- Magick::Draw
- Defined in:
- lib/RMagick.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' }
- ANCHOR_TYPE_NAMES =
{ StartAnchor.to_i => 'start', MiddleAnchor.to_i => 'middle', EndAnchor.to_i => 'end' }
- DECORATION_TYPE_NAMES =
{ NoDecoration.to_i => 'none', UnderlineDecoration.to_i => 'underline', OverlineDecoration.to_i => 'overline', LineThroughDecoration.to_i => 'line-through' }
- FONT_WEIGHT_NAMES =
{ AnyWeight.to_i => 'all', NormalWeight.to_i => 'normal', BoldWeight.to_i => 'bold', BolderWeight.to_i => 'bolder', LighterWeight.to_i => 'lighter', }
- GRAVITY_NAMES =
{ NorthWestGravity.to_i => 'northwest', NorthGravity.to_i => 'north', NorthEastGravity.to_i => 'northeast', WestGravity.to_i => 'west', CenterGravity.to_i => 'center', EastGravity.to_i => 'east', SouthWestGravity.to_i => 'southwest', SouthGravity.to_i => 'south', SouthEastGravity.to_i => 'southeast' }
- PAINT_METHOD_NAMES =
{ PointMethod.to_i => 'point', ReplaceMethod.to_i => 'replace', FloodfillMethod.to_i => 'floodfill', FillToBorderMethod.to_i => 'filltoborder', ResetMethod.to_i => 'reset' }
- STRETCH_TYPE_NAMES =
{ NormalStretch.to_i => 'normal', UltraCondensedStretch.to_i => 'ultra-condensed', ExtraCondensedStretch.to_i => 'extra-condensed', CondensedStretch.to_i => 'condensed', SemiCondensedStretch.to_i => 'semi-condensed', SemiExpandedStretch.to_i => 'semi-expanded', ExpandedStretch.to_i => 'expanded', ExtraExpandedStretch.to_i => 'extra-expanded', UltraExpandedStretch.to_i => 'ultra-expanded', AnyStretch.to_i => 'all' }
- STYLE_TYPE_NAMES =
{ NormalStyle.to_i => 'normal', ItalicStyle.to_i => 'italic', ObliqueStyle.to_i => 'oblique', AnyStyle.to_i => 'all' }
Class Method Summary collapse
Instance Method Summary collapse
-
#affine(sx, rx, ry, sy, tx, ty) ⇒ Object
Apply coordinate transformations to support scaling (s), rotation ®, and translation (t).
-
#annotate(image_arg, width_arg, height_arg, x_arg, y_arg, text) ⇒ Object
Method: Draw#annotate(img, w, h, x, y, text) <parms> Purpose: annotates an image with text Returns: self Notes: Additional Draw attribute methods may be called in the optional block, which is executed in the context of an Draw object.
-
#arc(startX, startY, endX, endY, startDegrees, endDegrees) ⇒ Object
Draw an arc.
-
#bezier(*points) ⇒ Object
Draw a bezier curve.
-
#circle(originX, originY, perimX, perimY) ⇒ Object
Draw a circle.
-
#clip_path(name) ⇒ Object
Invoke a clip-path defined by def_clip_path.
-
#clip_rule(rule) ⇒ Object
Define the clipping rule.
-
#clip_units(unit) ⇒ Object
Define the clip units.
-
#clone ⇒ Object
Method: Draw#clone Notes: see dup, init_copy.
-
#color(x, y, method) ⇒ Object
Set color in image according to specified colorization rule.
-
#composite(*args) ⇒ Object
Method: Draw#composite(x,y,width,height,img,operator=OverCompositeOp) Purpose: Implement the “image” drawing primitive Notes: The “img” argument can be either an ImageList object or an Image argument.
-
#decorate(decoration) ⇒ Object
Specify EITHER the text decoration (none, underline, overline, line-through) OR the text solid background color (any color name or spec).
-
#define_clip_path(name) ⇒ Object
Define a clip-path.
-
#draw(image_arg) ⇒ Object
Method: Draw#draw(i) Purpose: Execute the stored drawing primitives on the current image image.
-
#dup ⇒ Object
Methods: Draw#dup Purpose: Copy a Draw object Notes: Constructs a new Draw object, then calls initialize_copy.
-
#ellipse(originX, originY, width, height, arcStart, arcEnd) ⇒ Object
Draw an ellipse.
-
#encoding(encoding) ⇒ Object
Let anything through, but the only defined argument is “UTF-8”.
-
#fill(colorspec) ⇒ Object
(also: #fill_color, #fill_pattern)
Specify object fill, a color name or pattern name.
-
#fill_opacity(opacity) ⇒ Object
Specify fill opacity (use “xx%” to indicate percentage).
- #fill_rule(rule) ⇒ Object
-
#font(name) ⇒ Object
Specify text drawing font.
- #font_family(name) ⇒ Object
- #font_stretch(stretch) ⇒ Object
- #font_style(style) ⇒ Object
-
#font_weight(weight) ⇒ Object
The font weight argument can be either a font weight constant or [100,200,…,900].
- #get_multiline_type_metrics(*args) ⇒ Object
-
#get_type_metrics(*args) ⇒ Object
Method: Draw#get_type_metrics([image, ]text) Draw#get_multiline_type_metrics([image, ]text) Purpose: returns measurements for a given font and text string 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.
-
#gravity(grav) ⇒ Object
Specify the text positioning gravity, one of: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast.
-
#initialize ⇒ Object
constructor
Method: Draw#initialize <{ info initializers }> Purpose: Initialize Draw object Notes: Here are the DrawInfo fields that are copied from Info.
-
#initialize_copy(orig) ⇒ Object
Method: Draw#initialize_copy Purpose: initialize clone, dup methods.
-
#inspect ⇒ Object
Method: inspect Purpose: display the primitives.
-
#line(startX, startY, endX, endY) ⇒ Object
Draw a line.
-
#matte(x, y, rule) ⇒ Object
Set matte (make transparent) in image according to the specified colorization rule.
-
#opacity(opacity) ⇒ Object
Specify drawing fill and stroke opacities.
-
#path(cmds) ⇒ Object
Draw using SVG-compatible path drawing commands.
-
#pattern(name, x, y, width, height) ⇒ Object
Define a pattern.
-
#point(x, y) ⇒ Object
Set point to fill color.
-
#pointsize(points) ⇒ Object
(also: #font_size)
Specify the font size in points.
-
#polygon(*points) ⇒ Object
Draw a polygon.
-
#polyline(*points) ⇒ Object
Draw a polyline.
-
#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’).
-
#primitive(primitive) ⇒ Object
Method: Draw#primitive Purpose: Add a drawing primitive to the list of primitives in the Draw object.
-
#push(*what) ⇒ Object
Push the current set of drawing options.
-
#rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y) ⇒ Object
Draw a rectangle.
-
#rotate(angle) ⇒ Object
Specify coordinate space rotation.
-
#roundrectangle(center_x, center_y, width, height, corner_width, corner_height) ⇒ Object
Draw a rectangle with rounded corners.
-
#scale(x, y) ⇒ Object
Specify scaling to be applied to coordinate space on subsequent drawing commands.
- #skewx(angle) ⇒ Object
- #skewy(angle) ⇒ Object
-
#stroke(colorspec) ⇒ Object
(also: #stroke_color, #stroke_pattern)
Specify the object stroke, a color name or pattern name.
-
#stroke_antialias(bool) ⇒ Object
Specify if stroke should be antialiased or not.
-
#stroke_dasharray(*list) ⇒ Object
Specify a stroke dash pattern.
-
#stroke_dashoffset(value = 0) ⇒ Object
Specify the initial offset in the dash pattern.
- #stroke_linecap(value) ⇒ Object
- #stroke_linejoin(value) ⇒ Object
- #stroke_miterlimit(value) ⇒ Object
-
#stroke_opacity(value) ⇒ Object
Specify opacity of stroke drawing color (use “xx%” to indicate percentage).
-
#stroke_width(pixels) ⇒ Object
Specify stroke (outline) width in pixels.
-
#text(x, y, text) ⇒ Object
Draw text at position x,y.
-
#text_align(alignment) ⇒ Object
Specify text alignment relative to a given point.
-
#text_anchor(anchor) ⇒ Object
SVG-compatible version of text_align.
-
#text_antialias(boolean) ⇒ Object
Specify if rendered text is to be antialiased.
-
#text_undercolor(color) ⇒ Object
Specify color underneath text.
-
#translate(x, y) ⇒ Object
Specify center of coordinate space to use for subsequent drawing commands.
Constructor Details
#initialize ⇒ Object
Method: Draw#initialize <{ info initializers }> Purpose: Initialize Draw object Notes: Here are the DrawInfo fields that are copied from Info.
These are the only Info fields that can be usefully
set in the initializer block.
DrawInfo Info
-------- ---------
stroke_antialias antialias
font font
density density
text_antialias antialias
pointsize pointsize
border_color border_color
server_name server_name
debug debug
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
# File 'ext/RMagick/rmdraw.c', line 726
VALUE
Draw_initialize(VALUE self)
{
Draw *draw;
Info *info;
volatile VALUE info_obj;
Data_Get_Struct(self, Draw, draw);
// Create a new Info object, running the info parms block in the process
info_obj = rm_info_new();
// Use the Info structure to create the DrawInfo structure
Data_Get_Struct(info_obj, Info, info);
draw->info = CloneDrawInfo(info, NULL);
draw->primitives = (VALUE)0;
draw->tmpfile_ary = NULL;
return self;
}
|
Class Method Details
.new ⇒ Object
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.
169 170 171 |
# File 'lib/RMagick.rb', line 169 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
Method: Draw#annotate(img, w, h, x, y, text) <parms> Purpose: annotates an image with text Returns: self Notes: Additional Draw attribute methods may be called in the
optional block, which is executed in the context of an
Draw object.
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
# File 'ext/RMagick/rmdraw.c', line 384
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;
// 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);
}
rm_check_frozen(ImageList_cur_image(image_arg));
Data_Get_Struct(ImageList_cur_image(image_arg), Image, image);
// Copy text to Draw structure
magick_clone_string(&draw->info->text, STRING_PTR(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 either the width or height is 0, both must be 0.
if (width == 0 || height == 0)
{
if (width != 0 || height != 0)
{
rb_raise(rb_eArgError, "invalid geometry %lux%lu%+ld%+ld", width, height, x, y);
}
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);
draw->info->affine = keep;
HANDLE_ERROR_IMG(image)
return self;
}
|
#arc(startX, startY, endX, endY, startDegrees, endDegrees) ⇒ Object
Draw an arc.
174 175 176 177 |
# File 'lib/RMagick.rb', line 174 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.
180 181 182 183 184 185 186 187 |
# File 'lib/RMagick.rb', line 180 def bezier(*points) if points.length == 0 raise ArgumentError, "no points specified" elsif points.length % 2 != 0 raise ArgumentError, "odd number of arguments specified" end primitive "bezier " + points.join(',') end |
#circle(originX, originY, perimX, perimY) ⇒ Object
Draw a circle
190 191 192 |
# File 'lib/RMagick.rb', line 190 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.
195 196 197 |
# File 'lib/RMagick.rb', line 195 def clip_path(name) primitive "clip-path #{name}" end |
#clip_rule(rule) ⇒ Object
Define the clipping rule.
200 201 202 203 204 205 |
# File 'lib/RMagick.rb', line 200 def clip_rule(rule) if ( not ["evenodd", "nonzero"].include?(rule.downcase) ) raise ArgumentError, "Unknown clipping rule #{rule}" end primitive "clip-rule #{rule}" end |
#clip_units(unit) ⇒ Object
Define the clip units
208 209 210 211 212 213 |
# File 'lib/RMagick.rb', line 208 def clip_units(unit) if ( not ["userspace", "userspaceonuse", "objectboundingbox"].include?(unit.downcase) ) raise ArgumentError, "Unknown clip unit #{unit}" end primitive "clip-units #{unit}" end |
#clone ⇒ Object
Method: Draw#clone Notes: see dup, init_copy
457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'ext/RMagick/rmdraw.c', line 457
VALUE
Draw_clone(VALUE self)
{
volatile VALUE clone;
clone = Draw_dup(self);
if (OBJ_FROZEN(self))
{
(void)rb_obj_freeze(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
217 218 219 220 221 222 |
# File 'lib/RMagick.rb', line 217 def color(x, y, method) if ( not PAINT_METHOD_NAMES.has_key?(method.to_i) ) raise ArgumentError, "Unknown PaintMethod: #{method}" end primitive "color #{x},#{y},#{PAINT_METHOD_NAMES[method.to_i]}" end |
#composite(*args) ⇒ Object
Method: Draw#composite(x,y,width,height,img,operator=OverCompositeOp) Purpose: Implement the “image” drawing primitive Notes: The “img” argument can be either an ImageList object
or an Image argument.
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
# File 'ext/RMagick/rmdraw.c', line 478
VALUE
Draw_composite(int argc, VALUE *argv, VALUE self)
{
Draw *draw;
const char *op = "Over";
double x, y, width, height;
CompositeOperator cop = OverCompositeOp;
volatile VALUE image;
Image *comp_img;
struct TmpFile_Name *tmpfile;
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);
}
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 BumpmapCompositeOp:
op = "Bumpmap";
break;
case ClearCompositeOp:
op = "Clear";
break;
case CopyBlueCompositeOp:
op = "CopyBlue";
break;
case CopyGreenCompositeOp:
op = "CopyGreen";
break;
case CopyOpacityCompositeOp:
op = "CopyOpacity";
break;
case CopyRedCompositeOp:
op = "CopyRed";
break;
case CopyCompositeOp:
op = "Copy";
break;
case DifferenceCompositeOp:
op = "Difference";
break;
case InCompositeOp:
op = "In";
break;
case MinusCompositeOp:
op = "Minus";
break;
case MultiplyCompositeOp:
op = "Multiply";
break;
case OutCompositeOp:
op = "Out";
break;
case OverCompositeOp:
op = "Over";
break;
case PlusCompositeOp:
op = "Plus";
break;
case SubtractCompositeOp:
op = "Subtract";
break;
case XorCompositeOp:
op = "Xor";
break;
default:
rb_raise(rb_eArgError, "unknown composite operator (%d)", cop);
break;
}
}
Data_Get_Struct(self, Draw, draw);
// Retrieve the image to composite
image = ImageList_cur_image(argv[4]);
// 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 = magick_malloc(sizeof(struct TmpFile_Name)+strlen(name));
strcpy(tmpfile->name, name);
tmpfile->next = draw->tmpfile_ary;
draw->tmpfile_ary = tmpfile;
// 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));
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)
226 227 228 229 230 231 232 |
# File 'lib/RMagick.rb', line 226 def decorate(decoration) if ( DECORATION_TYPE_NAMES.has_key?(decoration.to_i) ) primitive "decorate #{DECORATION_TYPE_NAMES[decoration.to_i]}" else primitive "decorate #{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”.
239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/RMagick.rb', line 239 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_arg) ⇒ Object
Method: Draw#draw(i) Purpose: Execute the stored drawing primitives on the current image
image
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 |
# File 'ext/RMagick/rmdraw.c', line 601
VALUE
Draw_draw(VALUE self, VALUE image_arg)
{
Draw *draw;
Image *image;
Data_Get_Struct(self, Draw, draw);
if (draw->primitives == 0)
{
rb_raise(rb_eArgError, "nothing to draw");
}
rm_check_frozen(ImageList_cur_image(image_arg));
Data_Get_Struct(ImageList_cur_image(image_arg), Image, image);
// Point the DrawInfo structure at the current set of primitives.
magick_clone_string(&(draw->info->primitive), STRING_PTR(draw->primitives));
(void) DrawImage(image, draw->info);
HANDLE_ERROR_IMG(image)
magick_free(draw->info->primitive);
draw->info->primitive = NULL;
return self;
}
|
#dup ⇒ Object
Methods: Draw#dup Purpose: Copy a Draw object Notes: Constructs a new Draw object, then calls initialize_copy
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
# File 'ext/RMagick/rmdraw.c', line 634
VALUE
Draw_dup(VALUE self)
{
Draw *draw;
volatile 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);
}
return rb_funcall(dup, ID_initialize_copy, 1, self);
}
|
#ellipse(originX, originY, width, height, arcStart, arcEnd) ⇒ Object
Draw an ellipse
253 254 255 256 |
# File 'lib/RMagick.rb', line 253 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.
260 261 262 |
# File 'lib/RMagick.rb', line 260 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
265 266 267 |
# File 'lib/RMagick.rb', line 265 def fill(colorspec) primitive "fill #{colorspec}" end |
#fill_opacity(opacity) ⇒ Object
Specify fill opacity (use “xx%” to indicate percentage)
272 273 274 |
# File 'lib/RMagick.rb', line 272 def fill_opacity(opacity) primitive "fill-opacity #{opacity}" end |
#fill_rule(rule) ⇒ Object
276 277 278 279 280 281 |
# File 'lib/RMagick.rb', line 276 def fill_rule(rule) if ( not ["evenodd", "nonzero"].include?(rule.downcase) ) raise ArgumentError, "Unknown fill rule #{rule}" end primitive "fill-rule #{rule}" end |
#font(name) ⇒ Object
Specify text drawing font
284 285 286 |
# File 'lib/RMagick.rb', line 284 def font(name) primitive "font #{name}" end |
#font_family(name) ⇒ Object
288 289 290 |
# File 'lib/RMagick.rb', line 288 def font_family(name) primitive "font-family \'#{name}\'" end |
#font_stretch(stretch) ⇒ Object
292 293 294 295 296 297 |
# File 'lib/RMagick.rb', line 292 def font_stretch(stretch) if ( not STRETCH_TYPE_NAMES.has_key?(stretch.to_i) ) raise ArgumentError, "Unknown stretch type" end primitive "font-stretch #{STRETCH_TYPE_NAMES[stretch.to_i]}" end |
#font_style(style) ⇒ Object
299 300 301 302 303 304 |
# File 'lib/RMagick.rb', line 299 def font_style(style) if ( not STYLE_TYPE_NAMES.has_key?(style.to_i) ) 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]
308 309 310 311 312 313 314 |
# File 'lib/RMagick.rb', line 308 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
669 670 671 672 673 674 675 676 677 678 679 680 681 |
# File 'ext/RMagick/rmdraw.c', line 669
VALUE
Draw_get_multiline_type_metrics(
int argc,
VALUE *argv,
VALUE self)
{
#if defined(HAVE_GETMULTILINETYPEMETRICS)
return get_type_metrics(argc, argv, self, GetMultilineTypeMetrics);
#else
rm_not_implemented();
return (VALUE)0;
#endif
}
|
#get_type_metrics(*args) ⇒ Object
Method: Draw#get_type_metrics([image, ]text)
Draw#get_multiline_type_metrics([image, ]text)
Purpose: returns measurements for a given font and text string 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.
659 660 661 662 663 664 665 666 |
# File 'ext/RMagick/rmdraw.c', line 659
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
318 319 320 321 322 323 |
# File 'lib/RMagick.rb', line 318 def gravity(grav) if ( not GRAVITY_NAMES.has_key?(grav.to_i) ) raise ArgumentError, "Unknown text positioning gravity" end primitive "gravity #{GRAVITY_NAMES[grav.to_i]}" end |
#initialize_copy(orig) ⇒ Object
Method: Draw#initialize_copy Purpose: initialize clone, dup methods
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
# File 'ext/RMagick/rmdraw.c', line 687
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;
}
|
#inspect ⇒ Object
Method: inspect Purpose: display the primitives
752 753 754 755 756 757 758 759 |
# File 'ext/RMagick/rmdraw.c', line 752
VALUE
Draw_inspect(VALUE self)
{
Draw *draw;
Data_Get_Struct(self, Draw, draw);
return draw->primitives ? draw->primitives : rb_str_new2("(no primitives defined)");
}
|
#line(startX, startY, endX, endY) ⇒ Object
Draw a line
326 327 328 |
# File 'lib/RMagick.rb', line 326 def line(startX, startY, endX, endY) primitive "line " + sprintf("%g,%g %g,%g", startX, startY, endX, endY) end |
#matte(x, y, rule) ⇒ Object
Set matte (make transparent) in image according to the specified colorization rule
332 333 334 335 336 337 |
# File 'lib/RMagick.rb', line 332 def matte(x, y, rule) if ( not PAINT_METHOD_NAMES.has_key?(method.to_i) ) 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.
341 342 343 344 345 346 347 348 |
# File 'lib/RMagick.rb', line 341 def opacity(opacity) if (Numeric === opacity) if (opacity < 0 || opacity > 1.0) 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.
353 354 355 |
# File 'lib/RMagick.rb', line 353 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
360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/RMagick.rb', line 360 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.
374 375 376 |
# File 'lib/RMagick.rb', line 374 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.
380 381 382 |
# File 'lib/RMagick.rb', line 380 def pointsize(points) primitive "font-size #{points}" end |
#polygon(*points) ⇒ Object
Draw a polygon
386 387 388 389 390 391 392 393 |
# File 'lib/RMagick.rb', line 386 def polygon(*points) if points.length == 0 raise ArgumentError, "no points specified" elsif points.length % 2 != 0 raise ArgumentError, "odd number of points specified" end primitive "polygon " + points.join(',') end |
#polyline(*points) ⇒ Object
Draw a polyline
396 397 398 399 400 401 402 403 |
# File 'lib/RMagick.rb', line 396 def polyline(*points) if points.length == 0 raise ArgumentError, "no points specified" elsif points.length % 2 != 0 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’)
411 412 413 414 415 416 417 418 |
# File 'lib/RMagick.rb', line 411 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.to_s end end |
#primitive(primitive) ⇒ Object
Method: Draw#primitive Purpose: Add a drawing primitive to the list of primitives in the
Draw object
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
# File 'ext/RMagick/rmdraw.c', line 792
VALUE
Draw_primitive(VALUE self, VALUE primitive)
{
Draw *draw;
rm_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’)
425 426 427 428 429 430 431 432 |
# File 'lib/RMagick.rb', line 425 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.to_s end end |
#rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y) ⇒ Object
Draw a rectangle
435 436 437 438 |
# File 'lib/RMagick.rb', line 435 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
441 442 443 |
# File 'lib/RMagick.rb', line 441 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
446 447 448 449 |
# File 'lib/RMagick.rb', line 446 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.
452 453 454 |
# File 'lib/RMagick.rb', line 452 def scale(x, y) primitive "scale #{x},#{y}" end |
#skewx(angle) ⇒ Object
456 457 458 |
# File 'lib/RMagick.rb', line 456 def skewx(angle) primitive "skewX #{angle}" end |
#skewy(angle) ⇒ Object
460 461 462 |
# File 'lib/RMagick.rb', line 460 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.
465 466 467 |
# File 'lib/RMagick.rb', line 465 def stroke(colorspec) primitive "stroke #{colorspec}" end |
#stroke_antialias(bool) ⇒ Object
Specify if stroke should be antialiased or not
472 473 474 475 |
# File 'lib/RMagick.rb', line 472 def stroke_antialias(bool) bool = bool ? '1' : '0' primitive "stroke-antialias #{bool}" end |
#stroke_dasharray(*list) ⇒ Object
Specify a stroke dash pattern
478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/RMagick.rb', line 478 def stroke_dasharray(*list) if list.length == 0 primitive "stroke-dasharray none" else list.each { |x| if x <= 0 then 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
492 493 494 |
# File 'lib/RMagick.rb', line 492 def stroke_dashoffset(value=0) primitive "stroke-dashoffset #{value}" end |
#stroke_linecap(value) ⇒ Object
496 497 498 499 500 501 |
# File 'lib/RMagick.rb', line 496 def stroke_linecap(value) if ( not ["butt", "round", "square"].include?(value.downcase) ) raise ArgumentError, "Unknown linecap type: #{value}" end primitive "stroke-linecap #{value}" end |
#stroke_linejoin(value) ⇒ Object
503 504 505 506 507 508 |
# File 'lib/RMagick.rb', line 503 def stroke_linejoin(value) if ( not ["round", "miter", "bevel"].include?(value.downcase) ) raise ArgumentError, "Unknown linejoin type: #{value}" end primitive "stroke-linejoin #{value}" end |
#stroke_miterlimit(value) ⇒ Object
510 511 512 513 514 515 |
# File 'lib/RMagick.rb', line 510 def stroke_miterlimit(value) if (value < 1) 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)
519 520 521 |
# File 'lib/RMagick.rb', line 519 def stroke_opacity(value) primitive "stroke-opacity #{value}" end |
#stroke_width(pixels) ⇒ Object
Specify stroke (outline) width in pixels.
524 525 526 |
# File 'lib/RMagick.rb', line 524 def stroke_width(pixels) primitive "stroke-width #{pixels}" end |
#text(x, y, text) ⇒ Object
Draw text at position x,y. Generally it’s best to surround the text with quotes. For example,
gc.text(100, 100, "'embedded blanks'")
531 532 533 534 535 536 |
# File 'lib/RMagick.rb', line 531 def text(x, y, text) if text.to_s.empty? raise ArgumentError, "missing text argument" end primitive "text #{x},#{y} #{text}" end |
#text_align(alignment) ⇒ Object
Specify text alignment relative to a given point
539 540 541 542 543 544 |
# File 'lib/RMagick.rb', line 539 def text_align(alignment) if ( not ALIGN_TYPE_NAMES.has_key?(alignment.to_i) ) 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
547 548 549 550 551 552 |
# File 'lib/RMagick.rb', line 547 def text_anchor(anchor) if ( not ANCHOR_TYPE_NAMES.has_key?(anchor.to_i) ) 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.
555 556 557 558 |
# File 'lib/RMagick.rb', line 555 def text_antialias(boolean) boolean = boolean ? '1' : '0' primitive "text-antialias #{boolean}" end |
#text_undercolor(color) ⇒ Object
Specify color underneath text
561 562 563 |
# File 'lib/RMagick.rb', line 561 def text_undercolor(color) primitive "text-undercolor #{color}" end |
#translate(x, y) ⇒ Object
Specify center of coordinate space to use for subsequent drawing commands.
567 568 569 |
# File 'lib/RMagick.rb', line 567 def translate(x, y) primitive "translate #{x},#{y}" end |