Class: Magick::Draw
- Inherits:
-
Object
- Object
- Magick::Draw
- 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
-
#affine(sx, rx, ry, sy, tx, ty) ⇒ Object
Apply coordinate transformations to support scaling (s), rotation ®, and translation (t).
-
#affine=(matrix) ⇒ Magick::AffineMatrix
Set the affine matrix from an AffineMatrix.
-
#align=(align) ⇒ Magick::AlignType
Set the text alignment from an AlignType.
-
#alpha(x, y, method) ⇒ Object
Set alpha (make transparent) in image according to the specified colorization rule.
-
#annotate(image_arg, width_arg, height_arg, x_arg, y_arg, text) ⇒ Magick::Draw
Annotates an image with text.
-
#arc(start_x, start_y, end_x, end_y, start_degrees, end_degrees) ⇒ Object
Draw an arc.
-
#bezier(*points) ⇒ Object
Draw a bezier curve.
-
#circle(origin_x, origin_y, perim_x, perim_y) ⇒ 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 ⇒ Magick::Draw
Clones this object.
-
#color(x, y, method) ⇒ Object
Set color in image according to specified colorization rule.
-
#composite(*args) ⇒ Magick::Draw
Draw the image.
-
#decorate(decoration) ⇒ Object
Specify EITHER the text decoration (none, underline, overline, line-through) OR the text solid background color (any color name or spec).
-
#decorate=(decorate) ⇒ Magick::DecorationType
Set text decorate from an DecorationType.
-
#define_clip_path(name) ⇒ Object
Define a clip-path.
-
#density=(density) ⇒ String
Set density.
-
#draw(image_arg) ⇒ Magick::Draw
Execute the stored drawing primitives on the current image.
-
#dup ⇒ Magick::Draw
Duplicate a Draw object.
-
#ellipse(origin_x, origin_y, width, height, arc_start, arc_end) ⇒ Object
Draw an ellipse.
-
#encoding(encoding) ⇒ Object
Let anything through, but the only defined argument is “UTF-8”.
-
#encoding=(encoding) ⇒ String
Set text encoding.
-
#fill(colorspec) ⇒ Object
(also: #fill_color, #fill_pattern)
Specify object fill, a color name or pattern name.
-
#fill=(fill) ⇒ Magick::Pixel, String
Set fill color.
-
#fill_opacity(opacity) ⇒ Object
Specify fill opacity (use “xx%” to indicate percentage).
-
#fill_pattern=(pattern) ⇒ Magick::Image
Accept an image as a fill pattern.
- #fill_rule(rule) ⇒ Object
-
#font(name) ⇒ Object
Specify text drawing font.
-
#font=(font) ⇒ String
Set the font name.
- #font_family(name) ⇒ Object
-
#font_family=(family) ⇒ String
Set the font family name.
- #font_stretch(stretch) ⇒ Object
-
#font_stretch=(stretch) ⇒ Magick::StretchType
Set the stretch as spacing between text characters.
- #font_style(style) ⇒ Object
-
#font_style=(style) ⇒ Magick::StyleType
Set font style.
-
#font_weight(weight) ⇒ Object
The font weight argument can be either a font weight constant or [100,200,…,900].
-
#font_weight=(weight) ⇒ Magick::WeightType, Numeric
Set font weight.
-
#get_multiline_type_metrics(*args) ⇒ Magick::TypeMetric
Returns measurements for a given font and text string.
-
#get_type_metrics(*args) ⇒ Magick::TypeMetric
Returns measurements for a given font and text string.
-
#gravity(grav) ⇒ Object
Specify the text positioning gravity, one of: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast.
-
#gravity=(grav) ⇒ Magick::GravityType
Set gravity to draw text.
- #image(composite, x, y, width, height, image_file_path) ⇒ Object
-
#initialize ⇒ Magick::Draw
constructor
Initialize Draw object.
-
#initialize_copy(orig) ⇒ Magick::Draw
Initialize clone, dup methods.
-
#inspect ⇒ String
Display the primitives.
-
#interline_spacing(space) ⇒ Object
IM 6.5.5-8 and later.
-
#interline_spacing=(spacing) ⇒ Float
Set spacing between two lines.
-
#interword_spacing(space) ⇒ Object
IM 6.4.8-3 and later.
-
#interword_spacing=(spacing) ⇒ Float
Set spacing between two words.
-
#kerning(space) ⇒ Object
IM 6.4.8-3 and later.
-
#kerning=(kerning) ⇒ Float
Set kerning as spacing between two letters.
-
#line(start_x, start_y, end_x, end_y) ⇒ Object
Draw a line.
-
#marshal_dump ⇒ Hash
Dump custom marshal for Draw objects.
-
#marshal_load(ddraw) ⇒ Magick::Draw
Load the marshalled object.
-
#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.
-
#pointsize=(pointsize) ⇒ Float
Set point size to draw text.
-
#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) ⇒ Magick::Draw
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.
-
#rotation=(deg) ⇒ Float
Set 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=(stroke) ⇒ Magick::Pixel, String
Set stroke.
-
#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(opacity) ⇒ Object
Specify opacity of stroke drawing color (use “xx%” to indicate percentage).
-
#stroke_pattern=(pattern) ⇒ Magick::Image
Accept an image as a stroke pattern.
-
#stroke_width(pixels) ⇒ Object
Specify stroke (outline) width in pixels.
-
#stroke_width=(stroke_width) ⇒ Float
Set stroke width.
-
#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_antialias=(text_antialias) ⇒ Boolean
Set whether to enable text antialias.
-
#text_undercolor(color) ⇒ Object
Specify color underneath text.
-
#tile=(image) ⇒ Magick::Image
Accept an image as a fill pattern.
-
#translate(x, y) ⇒ Object
Specify center of coordinate space to use for subsequent drawing commands.
-
#undercolor=(undercolor) ⇒ Magick::Pixel, String
Set undercolor.
Constructor Details
#initialize ⇒ Magick::Draw
Initialize Draw object.
1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 |
# File 'ext/RMagick/rmdraw.c', line 1203
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.
277 278 279 |
# File 'lib/rmagick_internal.rb', line 277 def affine(sx, rx, ry, sy, tx, ty) primitive 'affine ' + sprintf('%g,%g,%g,%g,%g,%g', sx, rx, ry, sy, tx, ty) end |
#affine=(matrix) ⇒ Magick::AffineMatrix
Set the affine matrix from an AffineMatrix.
35 36 37 38 39 40 41 42 43 44 |
# File 'ext/RMagick/rmdraw.c', line 35
VALUE
Draw_affine_eq(VALUE self, VALUE matrix)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
Export_AffineMatrix(&draw->info->affine, matrix);
return matrix;
}
|
#align=(align) ⇒ Magick::AlignType
Set the text alignment from an AlignType.
53 54 55 56 57 58 59 60 61 62 |
# File 'ext/RMagick/rmdraw.c', line 53
VALUE
Draw_align_eq(VALUE self, VALUE align)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
VALUE_TO_ENUM(align, draw->info->align, AlignType);
return align;
}
|
#alpha(x, y, method) ⇒ Object
Set alpha (make transparent) in image according to the specified colorization rule
283 284 285 286 287 |
# File 'lib/rmagick_internal.rb', line 283 def alpha(x, y, method) Kernel.raise ArgumentError, 'Unknown paint method' unless PAINT_METHOD_NAMES.key?(method.to_i) name = Gem::Version.new(Magick::IMAGEMAGICK_VERSION) > Gem::Version.new('7.0.0') ? 'alpha ' : 'matte ' primitive name + sprintf('%g,%g, %s', x, y, PAINT_METHOD_NAMES[method.to_i]) end |
#annotate(image_arg, width_arg, height_arg, x_arg, y_arg, text) ⇒ Magick::Draw
Annotates an image with text.
-
Additional Draw attribute methods may be called in the optional block, which is executed in the context of an Draw object.
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 |
# File 'ext/RMagick/rmdraw.c', line 824
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[100];
char *embed_text;
#if defined(IMAGEMAGICK_7)
ExceptionInfo *exception;
#endif
// 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())
{
if (rb_proc_arity(rb_block_proc()) == 0)
{
// Run the block in self's context
rb_warn("passing a block without an image argument is deprecated");
rb_obj_instance_eval(0, NULL, self);
}
else
{
rb_yield(self);
}
}
// Translate & store in Draw structure
embed_text = StringValueCStr(text);
#if defined(IMAGEMAGICK_7)
exception = AcquireExceptionInfo();
draw->info->text = InterpretImageProperties(NULL, image, embed_text, exception);
if (rm_should_raise_exception(exception, RetainExceptionRetention))
{
if (draw->info->text)
{
magick_free(draw->info->text);
}
rm_raise_exception(exception);
}
#else
draw->info->text = InterpretImageProperties(NULL, image, embed_text);
#endif
if (!draw->info->text)
{
#if defined(IMAGEMAGICK_7)
DestroyExceptionInfo(exception);
#endif
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)
{
snprintf(geometry_str, sizeof(geometry_str), "%+ld%+ld", x, y);
}
// WxH is non-zero
else
{
snprintf(geometry_str, sizeof(geometry_str), "%lux%lu%+ld%+ld", width, height, x, y);
}
magick_clone_string(&draw->info->geometry, geometry_str);
#if defined(IMAGEMAGICK_7)
AnnotateImage(image, draw->info, exception);
#else
AnnotateImage(image, draw->info);
#endif
magick_free(draw->info->text);
draw->info->text = NULL;
draw->info->affine = keep;
#if defined(IMAGEMAGICK_7)
CHECK_EXCEPTION();
DestroyExceptionInfo(exception);
#else
rm_check_image_exception(image, RetainOnError);
#endif
return self;
}
|
#arc(start_x, start_y, end_x, end_y, start_degrees, end_degrees) ⇒ Object
Draw an arc.
290 291 292 293 294 295 |
# File 'lib/rmagick_internal.rb', line 290 def arc(start_x, start_y, end_x, end_y, start_degrees, end_degrees) primitive 'arc ' + sprintf( '%g,%g %g,%g %g,%g', start_x, start_y, end_x, end_y, start_degrees, end_degrees ) end |
#bezier(*points) ⇒ Object
Draw a bezier curve.
298 299 300 301 302 303 304 305 |
# File 'lib/rmagick_internal.rb', line 298 def bezier(*points) if points.length.zero? Kernel.raise ArgumentError, 'no points specified' elsif points.length.odd? Kernel.raise ArgumentError, 'odd number of arguments specified' end primitive 'bezier ' + points.map! { |x| sprintf('%g', x) }.join(',') end |
#circle(origin_x, origin_y, perim_x, perim_y) ⇒ Object
Draw a circle
308 309 310 |
# File 'lib/rmagick_internal.rb', line 308 def circle(origin_x, origin_y, perim_x, perim_y) primitive 'circle ' + sprintf('%g,%g %g,%g', origin_x, origin_y, perim_x, perim_y) end |
#clip_path(name) ⇒ Object
Invoke a clip-path defined by def_clip_path.
313 314 315 |
# File 'lib/rmagick_internal.rb', line 313 def clip_path(name) primitive "clip-path #{name}" end |
#clip_rule(rule) ⇒ Object
Define the clipping rule.
318 319 320 321 |
# File 'lib/rmagick_internal.rb', line 318 def clip_rule(rule) Kernel.raise ArgumentError, "Unknown clipping rule #{rule}" unless %w[evenodd nonzero].include?(rule.downcase) primitive "clip-rule #{rule}" end |
#clip_units(unit) ⇒ Object
Define the clip units
324 325 326 327 |
# File 'lib/rmagick_internal.rb', line 324 def clip_units(unit) Kernel.raise ArgumentError, "Unknown clip unit #{unit}" unless %w[userspace userspaceonuse objectboundingbox].include?(unit.downcase) primitive "clip-units #{unit}" end |
#clone ⇒ Magick::Draw
Clones this object.
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 |
# File 'ext/RMagick/rmdraw.c', line 938
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
331 332 333 334 |
# File 'lib/rmagick_internal.rb', line 331 def color(x, y, method) Kernel.raise ArgumentError, "Unknown PaintMethod: #{method}" unless PAINT_METHOD_NAMES.key?(method.to_i) primitive 'color ' + sprintf('%g,%g,%s', x, y, PAINT_METHOD_NAMES[method.to_i]) end |
#composite(x, y, width, height, image) ⇒ Magick::Draw #composite(x, y, width, height, image, operator = Magick::OverCompositeOp) ⇒ Magick::Draw
Draw the image.
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 1042 |
# File 'ext/RMagick/rmdraw.c', line 979
VALUE
Draw_composite(int argc, VALUE *argv, VALUE self)
{
Draw *draw;
const char *op;
double x, y, width, height;
CompositeOperator cop;
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]);
comp_img = rm_check_destroyed(image);
x = NUM2DBL(argv[0]);
y = NUM2DBL(argv[1]);
width = NUM2DBL(argv[2]);
height = NUM2DBL(argv[3]);
cop = OverCompositeOp;
if (argc == 6)
{
VALUE_TO_ENUM(argv[5], cop, CompositeOperator);
}
op = CommandOptionToMnemonic(MagickComposeOptions, cop);
if (rm_strcasecmp("Unrecognized", op) == 0)
{
rb_raise(rb_eArgError, "unknown composite operator (%d)", cop);
}
Data_Get_Struct(self, Draw, draw);
// Create a temp copy of the composite image
rm_write_temp_image(comp_img, name, sizeof(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) + rm_strnlen_s(name, sizeof(name)));
strcpy(tmpfile_name->name, name);
tmpfile_name->next = draw->tmpfile_ary;
draw->tmpfile_ary = tmpfile_name;
// Form the drawing primitive
snprintf(primitive, sizeof(primitive), "image %s %g,%g,%g,%g '%s'", op, x, y, width, height, name);
// Send "primitive" to self.
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)
338 339 340 341 342 343 344 |
# File 'lib/rmagick_internal.rb', line 338 def decorate(decoration) if DECORATION_TYPE_NAMES.key?(decoration.to_i) primitive "decorate #{DECORATION_TYPE_NAMES[decoration.to_i]}" else primitive "decorate #{enquote(decoration)}" end end |
#decorate=(decorate) ⇒ Magick::DecorationType
Set text decorate from an Magick::DecorationType.
71 72 73 74 75 76 77 78 79 80 |
# File 'ext/RMagick/rmdraw.c', line 71
VALUE
Draw_decorate_eq(VALUE self, VALUE decorate)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
VALUE_TO_ENUM(decorate, draw->info->decorate, DecorationType);
return decorate;
}
|
#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”.
351 352 353 354 355 356 357 358 359 360 |
# File 'lib/rmagick_internal.rb', line 351 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 |
#density=(density) ⇒ String
Set density.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'ext/RMagick/rmdraw.c', line 89
VALUE
Draw_density_eq(VALUE self, VALUE density)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
magick_clone_string(&draw->info->density, StringValueCStr(density));
return density;
}
|
#draw(image_arg) ⇒ Magick::Draw
Execute the stored drawing primitives on the current image.
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 |
# File 'ext/RMagick/rmdraw.c', line 1052
VALUE
Draw_draw(VALUE self, VALUE image_arg)
{
Draw *draw;
Image *image;
#if defined(IMAGEMAGICK_7)
ExceptionInfo *exception;
#endif
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), StringValueCStr(draw->primitives));
#if defined(IMAGEMAGICK_7)
exception = AcquireExceptionInfo();
DrawImage(image, draw->info, exception);
#else
DrawImage(image, draw->info);
#endif
magick_free(draw->info->primitive);
draw->info->primitive = NULL;
#if defined(IMAGEMAGICK_7)
CHECK_EXCEPTION();
DestroyExceptionInfo(exception);
#else
rm_check_image_exception(image, RetainOnError);
#endif
return self;
}
|
#dup ⇒ Magick::Draw
Duplicate a Draw object.
-
Constructs a new Draw object, then calls initialize_copy.
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 |
# File 'ext/RMagick/rmdraw.c', line 1101
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);
RB_GC_GUARD(dup);
return rb_funcall(dup, rm_ID_initialize_copy, 1, self);
}
|
#ellipse(origin_x, origin_y, width, height, arc_start, arc_end) ⇒ Object
Draw an ellipse
363 364 365 366 367 368 |
# File 'lib/rmagick_internal.rb', line 363 def ellipse(origin_x, origin_y, width, height, arc_start, arc_end) primitive 'ellipse ' + sprintf( '%g,%g %g,%g %g,%g', origin_x, origin_y, width, height, arc_start, arc_end ) end |
#encoding(encoding) ⇒ Object
Let anything through, but the only defined argument is “UTF-8”. All others are apparently ignored.
372 373 374 |
# File 'lib/rmagick_internal.rb', line 372 def encoding(encoding) primitive "encoding #{encoding}" end |
#encoding=(encoding) ⇒ String
Set text encoding.
108 109 110 111 112 113 114 115 116 117 118 |
# File 'ext/RMagick/rmdraw.c', line 108
VALUE
Draw_encoding_eq(VALUE self, VALUE encoding)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
magick_clone_string(&draw->info->encoding, StringValueCStr(encoding));
return encoding;
}
|
#fill(colorspec) ⇒ Object Also known as: fill_color, fill_pattern
Specify object fill, a color name or pattern name
377 378 379 |
# File 'lib/rmagick_internal.rb', line 377 def fill(colorspec) primitive "fill #{enquote(colorspec)}" end |
#fill=(fill) ⇒ Magick::Pixel, String
Set fill color.
127 128 129 130 131 132 133 134 135 136 |
# File 'ext/RMagick/rmdraw.c', line 127
VALUE
Draw_fill_eq(VALUE self, VALUE fill)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
Color_to_PixelColor(&draw->info->fill, fill);
return fill;
}
|
#fill_opacity(opacity) ⇒ Object
Specify fill opacity (use “xx%” to indicate percentage)
384 385 386 387 |
# File 'lib/rmagick_internal.rb', line 384 def fill_opacity(opacity) check_opacity(opacity) primitive "fill-opacity #{opacity}" end |
#fill_pattern=(pattern) ⇒ Magick::Image
Accept an image as a fill pattern.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'ext/RMagick/rmdraw.c', line 148
VALUE
Draw_fill_pattern_eq(VALUE self, VALUE pattern)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, 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;
}
|
#fill_rule(rule) ⇒ Object
389 390 391 392 |
# File 'lib/rmagick_internal.rb', line 389 def fill_rule(rule) Kernel.raise ArgumentError, "Unknown fill rule #{rule}" unless %w[evenodd nonzero].include?(rule.downcase) primitive "fill-rule #{rule}" end |
#font(name) ⇒ Object
Specify text drawing font
395 396 397 |
# File 'lib/rmagick_internal.rb', line 395 def font(name) primitive "font \'#{name}\'" end |
#font=(font) ⇒ String
Set the font name.
183 184 185 186 187 188 189 190 191 192 193 |
# File 'ext/RMagick/rmdraw.c', line 183
VALUE
Draw_font_eq(VALUE self, VALUE font)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
magick_clone_string(&draw->info->font, StringValueCStr(font));
return font;
}
|
#font_family(name) ⇒ Object
399 400 401 |
# File 'lib/rmagick_internal.rb', line 399 def font_family(name) primitive "font-family \'#{name}\'" end |
#font_family=(family) ⇒ String
Set the font family name.
202 203 204 205 206 207 208 209 210 211 212 |
# File 'ext/RMagick/rmdraw.c', line 202
VALUE
Draw_font_family_eq(VALUE self, VALUE family)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
magick_clone_string(&draw->info->family, StringValueCStr(family));
return family;
}
|
#font_stretch(stretch) ⇒ Object
403 404 405 406 |
# File 'lib/rmagick_internal.rb', line 403 def font_stretch(stretch) Kernel.raise ArgumentError, 'Unknown stretch type' unless STRETCH_TYPE_NAMES.key?(stretch.to_i) primitive "font-stretch #{STRETCH_TYPE_NAMES[stretch.to_i]}" end |
#font_stretch=(stretch) ⇒ Magick::StretchType
Set the stretch as spacing between text characters.
221 222 223 224 225 226 227 228 229 230 |
# File 'ext/RMagick/rmdraw.c', line 221
VALUE
Draw_font_stretch_eq(VALUE self, VALUE stretch)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
VALUE_TO_ENUM(stretch, draw->info->stretch, StretchType);
return stretch;
}
|
#font_style(style) ⇒ Object
408 409 410 411 |
# File 'lib/rmagick_internal.rb', line 408 def font_style(style) Kernel.raise ArgumentError, 'Unknown style type' unless STYLE_TYPE_NAMES.key?(style.to_i) primitive "font-style #{STYLE_TYPE_NAMES[style.to_i]}" end |
#font_style=(style) ⇒ Magick::StyleType
Set font style.
239 240 241 242 243 244 245 246 247 248 |
# File 'ext/RMagick/rmdraw.c', line 239
VALUE
Draw_font_style_eq(VALUE self, VALUE style)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
VALUE_TO_ENUM(style, draw->info->style, StyleType);
return style;
}
|
#font_weight(weight) ⇒ Object
The font weight argument can be either a font weight constant or [100,200,…,900]
415 416 417 418 419 420 421 |
# File 'lib/rmagick_internal.rb', line 415 def font_weight(weight) if weight.is_a?(WeightType) primitive "font-weight #{FONT_WEIGHT_NAMES[weight.to_i]}" else primitive "font-weight #{Integer(weight)}" end end |
#font_weight=(weight) ⇒ Magick::WeightType, Numeric
The font weight can be one of the font weight constants or a number between 100 and 900
Set font weight.
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 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 |
# File 'ext/RMagick/rmdraw.c', line 258
VALUE
Draw_font_weight_eq(VALUE self, VALUE weight)
{
Draw *draw;
size_t w;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, 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;
}
|
#get_multiline_type_metrics(text) ⇒ Magick::TypeMetric #Draw ⇒ Magick::TypeMetric
Returns measurements for a given font and text string.
-
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.
1160 1161 1162 1163 1164 1165 1166 1167 |
# File 'ext/RMagick/rmdraw.c', line 1160
VALUE
Draw_get_multiline_type_metrics(
int argc,
VALUE *argv,
VALUE self)
{
return get_type_metrics(argc, argv, self, GetMultilineTypeMetrics);
}
|
#get_type_metrics(text) ⇒ Magick::TypeMetric #get_type_metrics(image, text) ⇒ Magick::TypeMetric
Returns measurements for a given font and text string.
-
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.
1133 1134 1135 1136 1137 1138 1139 1140 |
# File 'ext/RMagick/rmdraw.c', line 1133
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
425 426 427 428 |
# File 'lib/rmagick_internal.rb', line 425 def gravity(grav) Kernel.raise ArgumentError, 'Unknown text positioning gravity' unless GRAVITY_NAMES.key?(grav.to_i) primitive "gravity #{GRAVITY_NAMES[grav.to_i]}" end |
#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
325 326 327 328 329 330 331 332 333 334 335 |
# File 'ext/RMagick/rmdraw.c', line 325
VALUE
Draw_gravity_eq(VALUE self, VALUE grav)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
VALUE_TO_ENUM(grav, draw->info->gravity, GravityType);
return grav;
}
|
#image(composite, x, y, width, height, image_file_path) ⇒ Object
430 431 432 433 434 |
# File 'lib/rmagick_internal.rb', line 430 def image(composite, x, y, width, height, image_file_path) Kernel.raise ArgumentError, 'Unknown composite' unless composite.is_a?(CompositeOperator) composite_name = composite.to_s.sub!('CompositeOp', '') primitive 'image ' + sprintf('%s %g,%g %g,%g %s', composite_name, x, y, width, height, enquote(image_file_path)) end |
#initialize_copy(orig) ⇒ Magick::Draw
Initialize clone, dup methods.
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 |
# File 'ext/RMagick/rmdraw.c', line 1176
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 ⇒ String
Display the primitives.
1228 1229 1230 1231 1232 1233 1234 1235 |
# File 'ext/RMagick/rmdraw.c', line 1228
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
437 438 439 440 441 442 443 444 445 446 |
# File 'lib/rmagick_internal.rb', line 437 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 |
#interline_spacing=(spacing) ⇒ Float
Set spacing between two lines.
362 363 364 365 366 367 368 369 370 371 |
# File 'ext/RMagick/rmdraw.c', line 362
VALUE
Draw_interline_spacing_eq(VALUE self, VALUE spacing)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
draw->info->interline_spacing = NUM2DBL(spacing);
return spacing;
}
|
#interword_spacing(space) ⇒ Object
IM 6.4.8-3 and later
449 450 451 452 453 454 455 456 457 458 |
# File 'lib/rmagick_internal.rb', line 449 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 |
#interword_spacing=(spacing) ⇒ Float
Set spacing between two words.
380 381 382 383 384 385 386 387 388 389 |
# File 'ext/RMagick/rmdraw.c', line 380
VALUE
Draw_interword_spacing_eq(VALUE self, VALUE spacing)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
draw->info->interword_spacing = NUM2DBL(spacing);
return spacing;
}
|
#kerning(space) ⇒ Object
IM 6.4.8-3 and later
461 462 463 464 465 466 467 468 469 470 |
# File 'lib/rmagick_internal.rb', line 461 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 |
#kerning=(kerning) ⇒ Float
Set kerning as spacing between two letters.
344 345 346 347 348 349 350 351 352 353 |
# File 'ext/RMagick/rmdraw.c', line 344
VALUE
Draw_kerning_eq(VALUE self, VALUE kerning)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
draw->info->kerning = NUM2DBL(kerning);
return kerning;
}
|
#line(start_x, start_y, end_x, end_y) ⇒ Object
Draw a line
473 474 475 |
# File 'lib/rmagick_internal.rb', line 473 def line(start_x, start_y, end_x, end_y) primitive 'line ' + sprintf('%g,%g %g,%g', start_x, start_y, end_x, end_y) end |
#marshal_dump ⇒ Hash
Handle gradients when christy gets the new gradient support added (23Dec08)
Dump custom marshal for Draw objects.
-
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.
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 |
# File 'ext/RMagick/rmdraw.c', line 479
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_PixelColor(&draw->info->fill));
rb_hash_aset(ddraw, CSTR2SYM("stroke"), Pixel_from_PixelColor(&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_PixelColor(&draw->info->undercolor));
// rb_hash_aset(ddraw, CSTR2SYM("border_color"), Pixel_from_PixelColor(&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));
#if defined(IMAGEMAGICK_7)
rb_hash_aset(ddraw, CSTR2SYM("alpha"), QUANTUM2NUM(draw->info->alpha));
#else
rb_hash_aset(ddraw, CSTR2SYM("opacity"), QUANTUM2NUM(draw->info->opacity));
#endif
// 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);
rb_hash_aset(ddraw, CSTR2SYM("kerning"), rb_float_new(draw->info->kerning));
rb_hash_aset(ddraw, CSTR2SYM("interword_spacing"), rb_float_new(draw->info->interword_spacing));
// Non-DrawInfo fields
rb_hash_aset(ddraw, CSTR2SYM("primitives"), draw->primitives);
// rb_hash_aset(ddraw, CSTR2SYM("shadow_color"), Pixel_from_PixelColor(&draw->shadow_color)); Polaroid-only
return ddraw;
}
|
#marshal_load(ddraw) ⇒ Magick::Draw
Load the marshalled object
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 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 |
# File 'ext/RMagick/rmdraw.c', line 561
VALUE
Draw_marshal_load(VALUE self, VALUE ddraw)
{
Draw *draw;
VALUE val;
Data_Get_Struct(self, Draw, draw);
if (draw->info == NULL)
{
ImageInfo *image_info;
image_info = CloneImageInfo(NULL);
draw->info = CloneDrawInfo(image_info, (DrawInfo *) NULL);
DestroyImageInfo(image_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"));
Color_to_PixelColor(&draw->info->fill, val);
val = rb_hash_aref(ddraw, CSTR2SYM("stroke"));
Color_to_PixelColor(&draw->info->stroke, val);
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"));
Color_to_PixelColor(&draw->info->undercolor, val);
draw->info->clip_units = FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("clip_units")));
#if defined(IMAGEMAGICK_7)
draw->info->alpha = NUM2QUANTUM(rb_hash_aref(ddraw, CSTR2SYM("alpha")));
#else
draw->info->opacity = NUM2QUANTUM(rb_hash_aref(ddraw, CSTR2SYM("opacity")));
#endif
draw->info->kerning = NUM2DBL(rb_hash_aref(ddraw, CSTR2SYM("kerning")));
draw->info->interword_spacing = NUM2DBL(rb_hash_aref(ddraw, CSTR2SYM("interword_spacing")));
draw->primitives = rb_hash_aref(ddraw, CSTR2SYM("primitives"));
RB_GC_GUARD(val);
return self;
}
|
#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.
479 480 481 482 |
# File 'lib/rmagick_internal.rb', line 479 def opacity(opacity) check_opacity(opacity) 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.
487 488 489 |
# File 'lib/rmagick_internal.rb', line 487 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
494 495 496 497 498 499 500 501 502 503 |
# File 'lib/rmagick_internal.rb', line 494 def pattern(name, x, y, width, height) push('defs') push("pattern #{name} " + sprintf('%g %g %g %g', 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.
506 507 508 |
# File 'lib/rmagick_internal.rb', line 506 def point(x, y) primitive 'point ' + sprintf('%g,%g', 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.
512 513 514 |
# File 'lib/rmagick_internal.rb', line 512 def pointsize(points) primitive 'font-size ' + sprintf('%g', points) end |
#pointsize=(pointsize) ⇒ Float
Set point size to draw text.
636 637 638 639 640 641 642 643 644 645 |
# File 'ext/RMagick/rmdraw.c', line 636
VALUE
Draw_pointsize_eq(VALUE self, VALUE pointsize)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
draw->info->pointsize = NUM2DBL(pointsize);
return pointsize;
}
|
#polygon(*points) ⇒ Object
Draw a polygon
518 519 520 521 522 523 524 525 |
# File 'lib/rmagick_internal.rb', line 518 def polygon(*points) if points.length.zero? Kernel.raise ArgumentError, 'no points specified' elsif points.length.odd? Kernel.raise ArgumentError, 'odd number of points specified' end primitive 'polygon ' + points.map! { |x| sprintf('%g', x) }.join(',') end |
#polyline(*points) ⇒ Object
Draw a polyline
528 529 530 531 532 533 534 535 |
# File 'lib/rmagick_internal.rb', line 528 def polyline(*points) if points.length.zero? Kernel.raise ArgumentError, 'no points specified' elsif points.length.odd? Kernel.raise ArgumentError, 'odd number of points specified' end primitive 'polyline ' + points.map! { |x| sprintf('%g', x) }.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’)
543 544 545 546 547 548 549 550 |
# File 'lib/rmagick_internal.rb', line 543 def pop(*what) if what.length.zero? primitive 'pop graphic-context' else # to_s allows a Symbol to be used instead of a String primitive 'pop ' + what.map(&:to_s).join(' ') end end |
#primitive(primitive) ⇒ Magick::Draw
Add a drawing primitive to the list of primitives in the Draw object.
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 |
# File 'ext/RMagick/rmdraw.c', line 1264
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’)
557 558 559 560 561 562 563 564 |
# File 'lib/rmagick_internal.rb', line 557 def push(*what) if what.length.zero? primitive 'push graphic-context' else # to_s allows a Symbol to be used instead of a String primitive 'push ' + what.map(&:to_s).join(' ') end end |
#rectangle(upper_left_x, upper_left_y, lower_right_x, lower_right_y) ⇒ Object
Draw a rectangle
567 568 569 570 571 572 |
# File 'lib/rmagick_internal.rb', line 567 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
575 576 577 |
# File 'lib/rmagick_internal.rb', line 575 def rotate(angle) primitive 'rotate ' + sprintf('%g', angle) end |
#rotation=(deg) ⇒ Float
Set rotation. The argument should be in degrees.
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 |
# File 'ext/RMagick/rmdraw.c', line 654
VALUE
Draw_rotation_eq(VALUE self, VALUE deg)
{
Draw *draw;
double degrees;
AffineMatrix affine, current;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, 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;
}
|
#roundrectangle(center_x, center_y, width, height, corner_width, corner_height) ⇒ Object
Draw a rectangle with rounded corners
580 581 582 583 584 585 |
# File 'lib/rmagick_internal.rb', line 580 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.
588 589 590 |
# File 'lib/rmagick_internal.rb', line 588 def scale(x, y) primitive 'scale ' + sprintf('%g,%g', x, y) end |
#skewx(angle) ⇒ Object
592 593 594 |
# File 'lib/rmagick_internal.rb', line 592 def skewx(angle) primitive 'skewX ' + sprintf('%g', angle) end |
#skewy(angle) ⇒ Object
596 597 598 |
# File 'lib/rmagick_internal.rb', line 596 def skewy(angle) primitive 'skewY ' + sprintf('%g', angle) end |
#stroke(colorspec) ⇒ Object Also known as: stroke_color, stroke_pattern
Specify the object stroke, a color name or pattern name.
601 602 603 |
# File 'lib/rmagick_internal.rb', line 601 def stroke(colorspec) primitive "stroke #{enquote(colorspec)}" end |
#stroke=(stroke) ⇒ Magick::Pixel, String
Set stroke.
692 693 694 695 696 697 698 699 700 701 |
# File 'ext/RMagick/rmdraw.c', line 692
VALUE
Draw_stroke_eq(VALUE self, VALUE stroke)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
Color_to_PixelColor(&draw->info->stroke, stroke);
return stroke;
}
|
#stroke_antialias(bool) ⇒ Object
Specify if stroke should be antialiased or not
608 609 610 611 |
# File 'lib/rmagick_internal.rb', line 608 def stroke_antialias(bool) bool = bool ? '1' : '0' primitive "stroke-antialias #{bool}" end |
#stroke_dasharray(*list) ⇒ Object
Specify a stroke dash pattern
614 615 616 617 618 619 620 621 622 623 |
# File 'lib/rmagick_internal.rb', line 614 def stroke_dasharray(*list) if list.length.zero? primitive 'stroke-dasharray none' else list.each do |x| Kernel.raise ArgumentError, "dash array elements must be > 0 (#{x} given)" if x <= 0 end primitive "stroke-dasharray #{list.join(',')}" end end |
#stroke_dashoffset(value = 0) ⇒ Object
Specify the initial offset in the dash pattern
626 627 628 |
# File 'lib/rmagick_internal.rb', line 626 def stroke_dashoffset(value = 0) primitive 'stroke-dashoffset ' + sprintf('%g', value) end |
#stroke_linecap(value) ⇒ Object
630 631 632 633 |
# File 'lib/rmagick_internal.rb', line 630 def stroke_linecap(value) Kernel.raise ArgumentError, "Unknown linecap type: #{value}" unless %w[butt round square].include?(value.downcase) primitive "stroke-linecap #{value}" end |
#stroke_linejoin(value) ⇒ Object
635 636 637 638 |
# File 'lib/rmagick_internal.rb', line 635 def stroke_linejoin(value) Kernel.raise ArgumentError, "Unknown linejoin type: #{value}" unless %w[round miter bevel].include?(value.downcase) primitive "stroke-linejoin #{value}" end |
#stroke_miterlimit(value) ⇒ Object
640 641 642 643 |
# File 'lib/rmagick_internal.rb', line 640 def stroke_miterlimit(value) Kernel.raise ArgumentError, 'miterlimit must be >= 1' if value < 1 primitive "stroke-miterlimit #{value}" end |
#stroke_opacity(opacity) ⇒ Object
Specify opacity of stroke drawing color
(use "xx%" to indicate percentage)
647 648 649 650 |
# File 'lib/rmagick_internal.rb', line 647 def stroke_opacity(opacity) check_opacity(opacity) primitive "stroke-opacity #{opacity}" end |
#stroke_pattern=(pattern) ⇒ Magick::Image
Accept an image as a stroke pattern.
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'ext/RMagick/rmdraw.c', line 712
VALUE
Draw_stroke_pattern_eq(VALUE self, VALUE pattern)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, 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(pixels) ⇒ Object
Specify stroke (outline) width in pixels.
653 654 655 |
# File 'lib/rmagick_internal.rb', line 653 def stroke_width(pixels) primitive 'stroke-width ' + sprintf('%g', pixels) end |
#stroke_width=(stroke_width) ⇒ Float
Set stroke width.
748 749 750 751 752 753 754 755 756 757 |
# File 'ext/RMagick/rmdraw.c', line 748
VALUE
Draw_stroke_width_eq(VALUE self, VALUE stroke_width)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
draw->info->stroke_width = NUM2DBL(stroke_width);
return stroke_width;
}
|
#text(x, y, text) ⇒ Object
Draw text at position x,y. Add quotes to text that is not already quoted.
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 |
# File 'lib/rmagick_internal.rb', line 658 def text(x, y, text) Kernel.raise ArgumentError, 'missing text argument' if text.to_s.empty? 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 ' + sprintf('%g,%g %s', x, y, text) end |
#text_align(alignment) ⇒ Object
Specify text alignment relative to a given point
676 677 678 679 |
# File 'lib/rmagick_internal.rb', line 676 def text_align(alignment) Kernel.raise ArgumentError, "Unknown alignment constant: #{alignment}" unless ALIGN_TYPE_NAMES.key?(alignment.to_i) primitive "text-align #{ALIGN_TYPE_NAMES[alignment.to_i]}" end |
#text_anchor(anchor) ⇒ Object
SVG-compatible version of text_align
682 683 684 685 |
# File 'lib/rmagick_internal.rb', line 682 def text_anchor(anchor) Kernel.raise ArgumentError, "Unknown anchor constant: #{anchor}" unless ANCHOR_TYPE_NAMES.key?(anchor.to_i) primitive "text-anchor #{ANCHOR_TYPE_NAMES[anchor.to_i]}" end |
#text_antialias(boolean) ⇒ Object
Specify if rendered text is to be antialiased.
688 689 690 691 |
# File 'lib/rmagick_internal.rb', line 688 def text_antialias(boolean) boolean = boolean ? '1' : '0' primitive "text-antialias #{boolean}" end |
#text_antialias=(text_antialias) ⇒ Boolean
Set whether to enable text antialias.
766 767 768 769 770 771 772 773 774 775 |
# File 'ext/RMagick/rmdraw.c', line 766
VALUE
Draw_text_antialias_eq(VALUE self, VALUE text_antialias)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
draw->info->text_antialias = (MagickBooleanType) RTEST(text_antialias);
return text_antialias;
}
|
#text_undercolor(color) ⇒ Object
Specify color underneath text
694 695 696 |
# File 'lib/rmagick_internal.rb', line 694 def text_undercolor(color) primitive "text-undercolor #{enquote(color)}" end |
#tile=(image) ⇒ Magick::Image
Accept an image as a fill pattern. This is alias of #fill_pattern=.
784 785 786 787 788 |
# File 'ext/RMagick/rmdraw.c', line 784
VALUE
Draw_tile_eq(VALUE self, VALUE image)
{
return Draw_fill_pattern_eq(self, image);
}
|
#translate(x, y) ⇒ Object
Specify center of coordinate space to use for subsequent drawing commands.
700 701 702 |
# File 'lib/rmagick_internal.rb', line 700 def translate(x, y) primitive 'translate ' + sprintf('%g,%g', x, y) end |
#undercolor=(undercolor) ⇒ Magick::Pixel, String
Set undercolor.
797 798 799 800 801 802 803 804 805 806 |
# File 'ext/RMagick/rmdraw.c', line 797
VALUE
Draw_undercolor_eq(VALUE self, VALUE undercolor)
{
Draw *draw;
rb_check_frozen(self);
Data_Get_Struct(self, Draw, draw);
Color_to_PixelColor(&draw->info->undercolor, undercolor);
return undercolor;
}
|