magickwand 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,10 @@
1
1
  require 'test/unit'
2
2
  require 'magickwand'
3
+ require File.dirname(__FILE__) + '/freezer'
3
4
 
4
5
  # The test images are in the same directory as this file.
5
6
  BUTTON_IMAGES = Dir[File.dirname(__FILE__) + "/Button_*.gif"].freeze
6
7
 
7
- # Determine what exception is raised when you try to modify a frozen object
8
- begin
9
- f = "string"
10
- f.freeze
11
- f[0] = "x"
12
- rescue TypeError
13
- FreezeError = TypeError
14
- rescue RuntimeError
15
- FreezeError = RuntimeError
16
- end
17
8
 
18
9
 
19
10
  class TestMagickWand < Test::Unit::TestCase
@@ -297,6 +288,28 @@ class TestMagickWand < Test::Unit::TestCase
297
288
  assert_raise(FreezeError) { wand.border("black") }
298
289
  end
299
290
 
291
+ def test_bordercolor
292
+ wand = MagickWand::Wand.new
293
+ wand.add_canvas 20
294
+ bordercolor = nil
295
+ assert_nothing_raised {bordercolor = wand.bordercolor}
296
+ assert_equal("#DFDFDFDFDFDF", bordercolor)
297
+ assert_nothing_raised { wand.bordercolor = "red" }
298
+ assert_equal("#FFFF00000000", wand.bordercolor)
299
+ assert_nothing_raised { wand.bordercolor = "blue" }
300
+ assert_equal("#00000000FFFF", wand.bordercolor)
301
+
302
+ # sets the border color on all the images in the wand
303
+ wand.add_canvas 20
304
+ assert_equal("#DFDFDFDFDFDF", wand[1].bordercolor)
305
+ assert_nothing_raised { wand.bordercolor = "green" }
306
+ assert_equal("#000080800000", wand.bordercolor)
307
+ assert_equal("#000080800000", wand[1].bordercolor)
308
+
309
+ wand.freeze
310
+ assert_raise(FreezeError) { wand.bordercolor = "red" }
311
+ end
312
+
300
313
  def test_clone
301
314
  wand = MagickWand::Wand.new
302
315
  wand.read BUTTON_IMAGES[0]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magickwand
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Hunter
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-01 00:00:00 -04:00
12
+ date: 2009-08-17 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -27,9 +27,9 @@ files:
27
27
  - Rakefile
28
28
  - lib/magickwand.rb
29
29
  - ext/magickwand/magickwand.h
30
- - ext/magickwand/gc.c
31
30
  - ext/magickwand/utility.c
32
31
  - ext/magickwand/magickwand.c
32
+ - ext/magickwand/drawing.c
33
33
  - ext/magickwand/extconf.rb
34
34
  - ext/magickwand/wand.c
35
35
  has_rdoc: true
@@ -59,15 +59,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  requirements: []
60
60
 
61
61
  rubyforge_project: magickwand
62
- rubygems_version: 1.3.4
62
+ rubygems_version: 1.3.5
63
63
  signing_key:
64
64
  specification_version: 1
65
65
  summary: A binding to ImageMagick
66
66
  test_files:
67
67
  - test/Button_6.gif
68
68
  - test/Button_5.gif
69
+ - test/test_drawing.rb
69
70
  - test/Button_1.gif
70
71
  - test/Button_0.gif
72
+ - test/freezer.rb
71
73
  - test/Button_2.gif
72
74
  - test/Button_8.gif
73
75
  - test/Button_9.gif
@@ -1,464 +0,0 @@
1
-
2
- /*
3
- * gc.c
4
- * $Id: gc.c 118 2009-05-30 20:11:39Z rmagick $
5
- * Copyright (C) 2009 Timothy Paul Hunter
6
- */
7
-
8
- #include "magickwand.h"
9
-
10
-
11
- static void gc_destroy(void *);
12
-
13
-
14
-
15
- static VALUE gc_allocate(VALUE klass)
16
- {
17
- GC *gc;
18
- return Data_Make_Struct(klass, GC, NULL, gc_destroy, gc);
19
- }
20
-
21
-
22
-
23
-
24
- static void gc_destroy(void *p)
25
- {
26
- GC *gc = (GC *)p;
27
-
28
- if (gc->drawingwand)
29
- {
30
- gc->drawingwand = DestroyDrawingWand(gc->drawingwand);
31
- }
32
- }
33
-
34
-
35
-
36
-
37
- /*
38
- * Construct a new GC object
39
- */
40
- VALUE mwr_gc_new(void)
41
- {
42
- VALUE obj;
43
- GC *gc;
44
-
45
- obj = Data_Make_Struct(mwr_cGC, GC, NULL, gc_destroy, gc);
46
- gc->drawingwand = NewDrawingWand();
47
- return obj;
48
- }
49
-
50
-
51
-
52
-
53
- /*
54
- * :align => string
55
- * set text alignment
56
- */
57
- static VALUE gc_set_align(VALUE obj, VALUE align)
58
- {
59
- GC *gc;
60
- AlignType type;
61
-
62
- rb_check_frozen(obj);
63
- type = mwr_string_to_aligntype(align, LeftAlign, RaiseUndefinedOption);
64
- Data_Get_Struct(obj, GC, gc);
65
- DrawSetTextAlignment(gc->drawingwand, type);
66
- mwr_check_drawingwand_error(gc->drawingwand);
67
- return obj;
68
- }
69
-
70
-
71
-
72
-
73
-
74
- /*
75
- * :antialias => boolean
76
- * turn text antialias on or off
77
- */
78
- static VALUE gc_set_antialias(VALUE obj, VALUE antialias)
79
- {
80
- GC *gc;
81
-
82
- rb_check_frozen(obj);
83
- Data_Get_Struct(obj, GC, gc);
84
- DrawSetTextAntialias(gc->drawingwand, RTEST(antialias) ? MagickTrue : MagickFalse);
85
- mwr_check_drawingwand_error(gc->drawingwand);
86
- return obj;
87
- }
88
-
89
-
90
-
91
-
92
- /*
93
- * :decoration => string
94
- */
95
- static VALUE gc_set_decoration(VALUE obj, VALUE decoration)
96
- {
97
- GC *gc;
98
- DecorationType type;
99
-
100
- rb_check_frozen(obj);
101
- type = mwr_string_to_decorationtype(decoration, NoDecoration, RaiseUndefinedOption);
102
- Data_Get_Struct(obj, GC, gc);
103
- DrawSetTextDecoration(gc->drawingwand, type);
104
- mwr_check_drawingwand_error(gc->drawingwand);
105
- return obj;
106
- }
107
-
108
-
109
-
110
-
111
- /*
112
- * :encoding => string
113
- */
114
- static VALUE gc_set_encoding(VALUE obj, VALUE encoding)
115
- {
116
- GC *gc;
117
-
118
- rb_check_frozen(obj);
119
- Data_Get_Struct(obj, GC, gc);
120
- DrawSetTextEncoding(gc->drawingwand, StringValuePtr(encoding));
121
- mwr_check_drawingwand_error(gc->drawingwand);
122
- return obj;
123
- }
124
-
125
-
126
-
127
- /*
128
- * :family => string
129
- */
130
- static VALUE gc_set_family(VALUE obj, VALUE family)
131
- {
132
- GC *gc;
133
-
134
- rb_check_frozen(obj);
135
- Data_Get_Struct(obj, GC, gc);
136
- DrawSetFontFamily(gc->drawingwand, StringValuePtr(family));
137
- mwr_check_drawingwand_error(gc->drawingwand);
138
- return obj;
139
- }
140
-
141
-
142
-
143
-
144
- /*
145
- * :fill => string
146
- */
147
- static VALUE gc_set_fill(VALUE obj, VALUE fill)
148
- {
149
- GC *gc;
150
- PixelWand *pixelwand;
151
-
152
- rb_check_frozen(obj);
153
- pixelwand = NewPixelWand();
154
-
155
- PixelSetColor(pixelwand, StringValuePtr(fill));
156
- mwr_check_pixelwand_error(pixelwand);
157
- Data_Get_Struct(obj, GC, gc);
158
- DrawSetFillColor(gc->drawingwand, pixelwand);
159
- pixelwand = DestroyPixelWand(pixelwand);
160
- mwr_check_drawingwand_error(gc->drawingwand);
161
- return obj;
162
- }
163
-
164
-
165
-
166
-
167
- /*
168
- * :fill_opacity => float
169
- */
170
- static VALUE gc_set_fill_opacity(VALUE obj, VALUE fill_opacity)
171
- {
172
- GC *gc;
173
- double opacity;
174
-
175
- rb_check_frozen(obj);
176
- opacity = NUM2DBL(fill_opacity);
177
- if (opacity < 0.0)
178
- {
179
- opacity = 0.0;
180
- }
181
- else if (opacity > 1.0)
182
- {
183
- opacity = 1.0;
184
- }
185
-
186
- Data_Get_Struct(obj, GC, gc);
187
- DrawSetFillOpacity(gc->drawingwand, opacity);
188
- mwr_check_drawingwand_error(gc->drawingwand);
189
- return obj;
190
- }
191
-
192
-
193
-
194
-
195
- /*
196
- * :font => string
197
- */
198
- static VALUE gc_set_font(VALUE obj, VALUE font)
199
- {
200
- GC *gc;
201
-
202
- rb_check_frozen(obj);
203
- Data_Get_Struct(obj, GC, gc);
204
- DrawSetFont(gc->drawingwand, StringValuePtr(font));
205
- mwr_check_drawingwand_error(gc->drawingwand);
206
- return obj;
207
- }
208
-
209
-
210
-
211
-
212
- /*
213
- * :gravity => string
214
- */
215
- static VALUE gc_set_gravity(VALUE obj, VALUE gravity)
216
- {
217
- GC *gc;
218
- GravityType type;
219
-
220
- rb_check_frozen(obj);
221
- type = mwr_string_to_gravitytype(gravity, NorthWestGravity, RaiseUndefinedOption);
222
- Data_Get_Struct(obj, GC, gc);
223
- DrawSetGravity(gc->drawingwand, type);
224
- mwr_check_drawingwand_error(gc->drawingwand);
225
- return obj;
226
- }
227
-
228
-
229
-
230
-
231
- /*
232
- * :interword_spacing => float
233
- */
234
- static VALUE gc_set_interword_spacing(VALUE obj, VALUE interword_spacing)
235
- {
236
- GC *gc;
237
-
238
- rb_check_frozen(obj);
239
- Data_Get_Struct(obj, GC, gc);
240
- DrawSetTextInterwordSpacing(gc->drawingwand, NUM2DBL(interword_spacing));
241
- mwr_check_drawingwand_error(gc->drawingwand);
242
- return obj;
243
- }
244
-
245
-
246
-
247
-
248
- /*
249
- * :kerning => float
250
- */
251
- static VALUE gc_set_kerning(VALUE obj, VALUE kerning)
252
- {
253
- GC *gc;
254
-
255
- rb_check_frozen(obj);
256
- Data_Get_Struct(obj, GC, gc);
257
- DrawSetTextKerning(gc->drawingwand, NUM2DBL(kerning));
258
- mwr_check_drawingwand_error(gc->drawingwand);
259
- return obj;
260
- }
261
-
262
-
263
-
264
-
265
- /*
266
- * :pointsize => float
267
- */
268
- static VALUE gc_set_pointsize(VALUE obj, VALUE pointsize)
269
- {
270
- GC *gc;
271
-
272
- rb_check_frozen(obj);
273
- Data_Get_Struct(obj, GC, gc);
274
- DrawSetFontSize(gc->drawingwand, NUM2DBL(pointsize));
275
- mwr_check_drawingwand_error(gc->drawingwand);
276
- return obj;
277
- }
278
-
279
-
280
-
281
-
282
- /*
283
- * :stretch => string
284
- */
285
- static VALUE gc_set_stretch(VALUE obj, VALUE stretch)
286
- {
287
- GC *gc;
288
- StretchType type;
289
-
290
- rb_check_frozen(obj);
291
- type = mwr_string_to_stretchtype(stretch, AnyStretch, RaiseUndefinedOption);
292
- Data_Get_Struct(obj, GC, gc);
293
- DrawSetFontStretch(gc->drawingwand, type);
294
- mwr_check_drawingwand_error(gc->drawingwand);
295
- return obj;
296
- }
297
-
298
-
299
-
300
- /*
301
- * :stroke => string
302
- */
303
- static VALUE gc_set_stroke(VALUE obj, VALUE stroke)
304
- {
305
- GC *gc;
306
- PixelWand *pixelwand;
307
-
308
- rb_check_frozen(obj);
309
- pixelwand = NewPixelWand();
310
-
311
- PixelSetColor(pixelwand, StringValuePtr(stroke));
312
- mwr_check_pixelwand_error(pixelwand);
313
- Data_Get_Struct(obj, GC, gc);
314
- DrawSetStrokeColor(gc->drawingwand, pixelwand);
315
- pixelwand = DestroyPixelWand(pixelwand);
316
- mwr_check_drawingwand_error(gc->drawingwand);
317
- return obj;
318
- }
319
-
320
-
321
-
322
-
323
- /*
324
- * :stroke_opacity => float
325
- */
326
- static VALUE gc_set_stroke_opacity(VALUE obj, VALUE stroke_opacity)
327
- {
328
- GC *gc;
329
- double opacity;
330
-
331
- rb_check_frozen(obj);
332
- opacity = NUM2DBL(stroke_opacity);
333
- if (opacity < 0.0)
334
- {
335
- opacity = 0.0;
336
- }
337
- else if (opacity > 1.0)
338
- {
339
- opacity = 1.0;
340
- }
341
-
342
- Data_Get_Struct(obj, GC, gc);
343
- DrawSetStrokeOpacity(gc->drawingwand, opacity);
344
- mwr_check_drawingwand_error(gc->drawingwand);
345
- return obj;
346
- }
347
-
348
-
349
-
350
-
351
- /*
352
- * :strokewidth => float
353
- */
354
- static VALUE gc_set_strokewidth(VALUE obj, VALUE strokewidth)
355
- {
356
- GC *gc;
357
-
358
- rb_check_frozen(obj);
359
- Data_Get_Struct(obj, GC, gc);
360
- DrawSetStrokeWidth(gc->drawingwand, NUM2DBL(strokewidth));
361
- mwr_check_drawingwand_error(gc->drawingwand);
362
- return obj;
363
- }
364
-
365
-
366
-
367
-
368
- /*
369
- * :style => string
370
- */
371
- static VALUE gc_set_style(VALUE obj, VALUE style)
372
- {
373
- GC *gc;
374
- StyleType type;
375
-
376
- rb_check_frozen(obj);
377
- type = mwr_string_to_styletype(style, NormalStyle, RaiseUndefinedOption);
378
- Data_Get_Struct(obj, GC, gc);
379
- DrawSetFontStyle(gc->drawingwand, type);
380
- mwr_check_drawingwand_error(gc->drawingwand);
381
- return obj;
382
- }
383
-
384
-
385
-
386
-
387
- /*
388
- * :undercolor => string
389
- */
390
- static VALUE gc_set_undercolor(VALUE obj, VALUE undercolor)
391
- {
392
- GC *gc;
393
- PixelWand *pixelwand;
394
-
395
- rb_check_frozen(obj);
396
- pixelwand = NewPixelWand();
397
-
398
- PixelSetColor(pixelwand, StringValuePtr(undercolor));
399
- mwr_check_pixelwand_error(pixelwand);
400
- Data_Get_Struct(obj, GC, gc);
401
- DrawSetTextUnderColor(gc->drawingwand, pixelwand);
402
- pixelwand = DestroyPixelWand(pixelwand);
403
- mwr_check_drawingwand_error(gc->drawingwand);
404
- return obj;
405
- }
406
-
407
-
408
-
409
-
410
- /*
411
- * :weight => fixnum
412
- */
413
- static VALUE gc_set_weight(VALUE obj, VALUE weight)
414
- {
415
- GC *gc;
416
- unsigned long w;
417
-
418
- rb_check_frozen(obj);
419
- if (TYPE(weight) == T_STRING)
420
- {
421
- w = mwr_string_to_weight(weight, 0, RaiseUndefinedOption);
422
- }
423
- else
424
- {
425
- w = FIX2ULONG(weight);
426
- }
427
- Data_Get_Struct(obj, GC, gc);
428
- DrawSetFontWeight(gc->drawingwand, w);
429
- mwr_check_drawingwand_error(gc->drawingwand);
430
- return obj;
431
- }
432
-
433
-
434
-
435
-
436
- /*
437
- * MagickWand::GC class
438
- */
439
- void mwr_init_GC(void)
440
- {
441
- mwr_cGC = rb_define_class_under(mwr_mMagickWand, "GC", rb_cObject);
442
- rb_define_alloc_func(mwr_cGC, gc_allocate);
443
-
444
- // Private property setters are called during option processing.
445
- rb_define_private_method(mwr_cGC, "set_align", gc_set_align, 1);
446
- rb_define_private_method(mwr_cGC, "set_antialias", gc_set_antialias, 1);
447
- rb_define_private_method(mwr_cGC, "set_decoration", gc_set_decoration, 1);
448
- rb_define_private_method(mwr_cGC, "set_encoding", gc_set_encoding, 1);
449
- rb_define_private_method(mwr_cGC, "set_family", gc_set_family, 1);
450
- rb_define_private_method(mwr_cGC, "set_fill", gc_set_fill, 1);
451
- rb_define_private_method(mwr_cGC, "set_fill_opacity", gc_set_fill_opacity, 1);
452
- rb_define_private_method(mwr_cGC, "set_font", gc_set_font, 1);
453
- rb_define_private_method(mwr_cGC, "set_gravity", gc_set_gravity, 1);
454
- rb_define_private_method(mwr_cGC, "set_interword_spacing", gc_set_interword_spacing, 1);
455
- rb_define_private_method(mwr_cGC, "set_kerning", gc_set_kerning, 1);
456
- rb_define_private_method(mwr_cGC, "set_pointsize", gc_set_pointsize, 1);
457
- rb_define_private_method(mwr_cGC, "set_stretch", gc_set_stretch, 1);
458
- rb_define_private_method(mwr_cGC, "set_stroke", gc_set_stroke, 1);
459
- rb_define_private_method(mwr_cGC, "set_stroke_opacity", gc_set_stroke_opacity, 1);
460
- rb_define_private_method(mwr_cGC, "set_strokewidth", gc_set_strokewidth, 1);
461
- rb_define_private_method(mwr_cGC, "set_style", gc_set_style, 1);
462
- rb_define_private_method(mwr_cGC, "set_undercolor", gc_set_undercolor, 1);
463
- rb_define_private_method(mwr_cGC, "set_weight", gc_set_weight, 1);
464
- }