-
Notifications
You must be signed in to change notification settings - Fork 21
/
drawing_wand.go
1006 lines (892 loc) · 36.3 KB
/
drawing_wand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
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
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
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
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
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package gmagick
import (
"runtime"
"sync"
"sync/atomic"
"unsafe"
)
/*
#include <wand/wand_api.h>
struct FakeMagickWand
{
char id[MaxTextExtent];
ExceptionInfo exception;
ImageInfo *image_info;
QuantizeInfo *quantize_info;
Image *image, *images;
unsigned int iterator;
unsigned long signature;
};
void draw_composite(DrawingWand *drawing_wand,
const CompositeOperator composite_operator,const double x,const double y,
const double width,const double height, MagickWand *wand) {
struct FakeMagickWand* fmw = (struct FakeMagickWand*)wand;
MagickDrawComposite(drawing_wand, composite_operator, x, y, width, height, fmw->image);
}
*/
import "C"
type DrawingWand struct {
dw *C.DrawingWand
init sync.Once
}
func newDrawingWand(cdw *C.DrawingWand) *DrawingWand {
dw := &DrawingWand{dw: cdw}
runtime.SetFinalizer(dw, Destroy)
dw.IncreaseCount()
return dw
}
// Returns a drawing wand required for all other methods in the API.
func NewDrawingWand() *DrawingWand {
return newDrawingWand(C.NewDrawingWand())
}
// Makes an exact copy of the specified wand.
func (dw *DrawingWand) Clone() *DrawingWand {
return newDrawingWand(C.CloneDrawingWand(dw.dw))
}
// Frees all resources associated with the drawing wand. Once the drawing wand
// has been freed, it should not be used and further unless it re-allocated.
func (dw *DrawingWand) Destroy() {
if dw.dw == nil {
return
}
dw.init.Do(func() {
C.DestroyDrawingWand(dw.dw)
dw.dw = nil
dw.DecreaseCount()
})
}
// Increase DrawingWand ref counter and set according "can`t be terminated status"
func (dw *DrawingWand) IncreaseCount() {
atomic.AddInt64(&drawingWandCounter, int64(1))
unsetCanTerminate()
}
// Decrease DrawingWand ref counter and set according "can be terminated status"
func (dw *DrawingWand) DecreaseCount() {
atomic.AddInt64(&drawingWandCounter, int64(-1))
setCanTerminate()
}
// Adjusts the current affine transformation matrix with the specified affine
// transformation matrix. Note that the current affine transform is adjusted
// rather than replaced.
//
// affine: Affine matrix parameters
//
func (dw *DrawingWand) Affine(affine *AffineMatrix) {
C.MagickDrawAffine(dw.dw, affine.ptr())
}
// Draws text on the image.
// x: x ordinate to left of text
// y: y ordinate to text baseline
// text: text to draw
func (dw *DrawingWand) Annotation(x, y float64, text string) {
cstext := (*C.uchar)((unsafe.Pointer)(C.CString(text)))
defer C.free(unsafe.Pointer(cstext))
C.MagickDrawAnnotation(dw.dw, C.double(x), C.double(y), cstext)
}
// Draws an arc falling within a specified bounding rectangle on the image.
//
// sx: starting x ordinate of bounding rectangle
//
// sy: starting y ordinate of bounding rectangle
//
// ex: ending x ordinate of bounding rectangle
//
// ey: ending y ordinate of bounding rectangle
//
// sd: starting degrees of rotation
//
// ed: ending degrees of rotation
//
func (dw *DrawingWand) Arc(sx, sy, ex, ey, sd, ed float64) {
C.MagickDrawArc(dw.dw, C.double(sx), C.double(sy), C.double(ex), C.double(ey), C.double(sd), C.double(ed))
}
// Draws a bezier curve through a set of points on the image.
func (dw *DrawingWand) Bezier(coordinates []PointInfo) {
ccoordinates := [1 << 16]C.PointInfo{}
for k, v := range coordinates {
ccoordinates[k] = C.PointInfo{C.double(v.X), C.double(v.Y)}
}
C.MagickDrawBezier(dw.dw, C.ulong(len(coordinates)), (*C.PointInfo)(&ccoordinates[0]))
}
// Draws a circle on the image.
//
// ox: origin x ordinate
//
// oy: origin y ordinate
//
// px: perimeter x ordinate
//
// py: perimeter y ordinate
//
func (dw *DrawingWand) Circle(ox, oy, px, py float64) {
C.MagickDrawCircle(dw.dw, C.double(ox), C.double(oy), C.double(px), C.double(py))
}
// Composites an image onto the current image, using the specified composition
// operator, specified position, and at the specified size.
//
// compose: composition operator
//
// x: x ordinate of top left corner
//
// y: y ordinate of top left corner
//
// width: Width to resize image to prior to compositing. Specify zero to use
// existing width.
//
// height: Height to resize image to prior to compositing. Specify zero to use
// existing height.
//
// mw: Image to composite is obtained from this wand.
//
func (dw *DrawingWand) Composite(compose CompositeOperator, x, y, width, height float64, mw *MagickWand) {
C.draw_composite(dw.dw, C.CompositeOperator(compose), C.double(x), C.double(y), C.double(width), C.double(height), mw.mw)
}
// Draws color on image using the current fill color, starting at specified
// position, and using specified paint method. The available paint methods are:
//
// x: x ordinate.
//
// y: y ordinate.
//
// pm: paint method. PointMethod: Recolors the target pixel. ReplaceMethod:
// Recolor any pixel that matches the target pixel. FloodfillMethod: Recolors
// target pixels and matching neighbors. ResetMethod: Recolor all pixels.
//
func (dw *DrawingWand) Color(x, y float64, pm PaintMethod) {
C.MagickDrawColor(dw.dw, C.double(x), C.double(y), C.PaintMethod(pm))
}
// Adds a comment to a vector output stream.
func (dw *DrawingWand) Comment(comment string) {
cscomment := C.CString(comment)
defer C.free(unsafe.Pointer(cscomment))
C.MagickDrawComment(dw.dw, cscomment)
}
// Draws an ellipse on the image.
//
// ox: origin x ordinate
//
// oy: origin y ordinate
//
// rx: radius in x
//
// ry: radius in y
//
// start: starting rotation in degrees
//
// end: ending rotation in degrees
//
func (dw *DrawingWand) Ellipse(ox, oy, rx, ry, start, end float64) {
C.MagickDrawEllipse(dw.dw, C.double(ox), C.double(oy), C.double(rx), C.double(ry), C.double(start), C.double(end))
}
// Obtains the current clipping path ID.
func (dw *DrawingWand) GetClipPath() string {
cscp := C.MagickDrawGetClipPath(dw.dw)
defer C.MagickRelinquishMemory(unsafe.Pointer(cscp))
return C.GoString(cscp)
}
// Returns the current polygon fill rule to be used by the clipping path.
func (dw *DrawingWand) GetClipRule() FillRule {
return FillRule(C.MagickDrawGetClipRule(dw.dw))
}
// Returns the interpretation of clip path units.
func (dw *DrawingWand) GetClipUnits() ClipPathUnits {
return ClipPathUnits(C.MagickDrawGetClipUnits(dw.dw))
}
// Returns the fill color used for drawing filled objects.
func (dw *DrawingWand) GetFillColor() (pw *PixelWand) {
pw = NewPixelWand()
C.MagickDrawGetFillColor(dw.dw, pw.pw)
return
}
// Returns the opacity used when drawing using the fill color or fill texture.
// Fully opaque is 1.0.
func (dw *DrawingWand) GetFillOpacity() float64 {
return float64(C.MagickDrawGetFillOpacity(dw.dw))
}
// Returns the fill rule used while drawing polygons.
func (dw *DrawingWand) GetFillRule() FillRule {
return FillRule(C.MagickDrawGetFillRule(dw.dw))
}
// Returns a string specifying the font used when annotating with text.
func (dw *DrawingWand) GetFont() string {
csfont := C.DrawGetFont(dw.dw)
defer C.MagickRelinquishMemory(unsafe.Pointer(csfont))
return C.GoString(csfont)
}
// Returns the font family to use when annotating with text.
func (dw *DrawingWand) GetFontFamily() string {
csfamily := C.MagickDrawGetFontFamily(dw.dw)
defer C.MagickRelinquishMemory(unsafe.Pointer(csfamily))
return C.GoString(csfamily)
}
func (dw *DrawingWand) GetFontSize() float64 {
return float64(C.MagickDrawGetFontSize(dw.dw))
}
// Returns the font stretch used when annotating with text.
func (dw *DrawingWand) GetFontStretch() StretchType {
return StretchType(C.MagickDrawGetFontStretch(dw.dw))
}
// Returns the font style used when annotating with text.
func (dw *DrawingWand) GetFontStyle() StyleType {
return StyleType(C.MagickDrawGetFontStyle(dw.dw))
}
// Returns the font weight used when annotating with text.
func (dw *DrawingWand) GetFontWeight() uint {
return uint(C.MagickDrawGetFontWeight(dw.dw))
}
// Returns the text placement gravity used when annotating with text.
func (dw *DrawingWand) GetGravity() GravityType {
return GravityType(C.MagickDrawGetGravity(dw.dw))
}
// Returns the current stroke antialias setting. Stroked outlines are
// antialiased by default. When antialiasing is disabled stroked pixels are
// thresholded to determine if the stroke color or underlying canvas color
// should be used.
func (dw *DrawingWand) GetStrokeAntialias() bool {
return 1 == C.MagickDrawGetStrokeAntialias(dw.dw)
}
// Returns the color used for stroking object outlines.
func (dw *DrawingWand) GetStrokeColor() (pw *PixelWand) {
pw = NewPixelWand()
C.MagickDrawGetStrokeColor(dw.dw, pw.pw)
return
}
// Returns an array representing the pattern of dashes and gaps used to stroke
// paths (see SetStrokeDashArray). The array must be freed once it is no longer
// required by the user.
func (dw *DrawingWand) GetStrokeDashArray() (nums []float64) {
count := C.ulong(0)
p := C.MagickDrawGetStrokeDashArray(dw.dw, &count)
nums = sizedDoubleArrayToFloat64Slice(p, count)
return
}
// Returns the offset into the dash pattern to start the dash.
func (dw *DrawingWand) GetStrokeDashOffset() float64 {
return float64(C.MagickDrawGetStrokeDashOffset(dw.dw))
}
// Returns the shape to be used at the end of open subpaths when they are
// stroked. Values of LineCap are UndefinedCap, ButtCap, RoundCap, and
// SquareCap.
func (dw *DrawingWand) GetStrokeLineCap() LineCap {
return LineCap(C.MagickDrawGetStrokeLineCap(dw.dw))
}
// Returns the shape to be used at the corners of paths (or other vector
// shapes) when they are stroked. Values of LineJoin are UndefinedJoin,
// MiterJoin, RoundJoin, and BevelJoin.
func (dw *DrawingWand) GetStrokeLineJoin() LineJoin {
return LineJoin(C.MagickDrawGetStrokeLineJoin(dw.dw))
}
// Returns the miter limit. When two line segments meet at a sharp angle and
// miter joins have been specified for 'lineJoin', it is possible for the
// miter to extend far beyond the thickness of the line stroking the path.
// The miterLimit' imposes a limit on the ratio of the miter length to the
// 'lineWidth'.
func (dw *DrawingWand) GetStrokeMiterLimit() uint {
return uint(C.MagickDrawGetStrokeMiterLimit(dw.dw))
}
// Returns the opacity of stroked object outlines.
func (dw *DrawingWand) GetStrokeOpacity() float64 {
return float64(C.MagickDrawGetStrokeOpacity(dw.dw))
}
// Returns the width of the stroke used to draw object outlines.
func (dw *DrawingWand) GetStrokeWidth() float64 {
return float64(C.MagickDrawGetStrokeWidth(dw.dw))
}
// Returns the current text antialias setting, which determines whether text
// is antialiased. Text is antialiased by default.
func (dw *DrawingWand) GetTextAntialias() bool {
return 1 == C.MagickDrawGetTextAntialias(dw.dw)
}
// Returns the decoration applied when annotating with text.
func (dw *DrawingWand) GetTextDecoration() DecorationType {
return DecorationType(C.MagickDrawGetTextDecoration(dw.dw))
}
// Returns a string which specifies the code set used for text annotations.
func (dw *DrawingWand) GetTextEncoding() string {
cstr := C.MagickDrawGetTextEncoding(dw.dw)
defer C.MagickRelinquishMemory(unsafe.Pointer(cstr))
return C.GoString(cstr)
}
// Returns the color of a background rectangle to place under text annotations.
func (dw *DrawingWand) GetTextUnderColor() (pw *PixelWand) {
pw = NewPixelWand()
C.MagickDrawGetTextUnderColor(dw.dw, pw.pw)
return
}
// Draws a line on the image using the current stroke color, stroke opacity,
// and stroke width.
//
//sx: starting x ordinate
//
//sy: starting y ordinate
//
//ex: ending x ordinate
//
//ey: ending y ordinate
//
func (dw *DrawingWand) Line(sx, sy, ex, ey float64) {
C.MagickDrawLine(dw.dw, C.double(sx), C.double(sy), C.double(ex), C.double(ey))
}
// Paints on the image's opacity channel in order to set effected pixels to
// transparent. to influence the opacity of pixels. The available paint
// methods are:
//
// ResetMethod: Select all pixels.
//
// PointMethod: Select the target pixel
//
// ReplaceMethod: Select any pixel that matches the target pixel.
//
// FloodfillMethod: Select the target pixel and matching neighbors.
//
// FillToBorderMethod: Select the target pixel and neighbors not matching
// border color.
//
// x, y: x, y ordinates
// pmethod: paint method
func (dw *DrawingWand) Matte(x, y float64, pmethod PaintMethod) {
C.MagickDrawMatte(dw.dw, C.double(x), C.double(y), C.PaintMethod(pmethod))
}
// Adds a path element to the current path which closes the current subpath by
// drawing a straight line from the current point to the current subpath's most
// recent starting point (usually, the most recent moveto point).
func (dw *DrawingWand) PathClose() {
C.MagickDrawPathClose(dw.dw)
}
// Draws a cubic Bezier curve from the current point to (x,y) using (x1,y1) as
// the control point at the beginning of the curve and (x2,y2) as the control
// point at the end of the curve using absolute coordinates. At the end of the
// command, the new current point becomes the final (x,y) coordinate pair used
// in the polybezier.
//
// x1, y1: x, y ordinates of control point for curve beginning
//
// x2, y2: x, y ordinates of control point for curve ending
//
// x, y: x, y ordinates of the end of the curve
//
func (dw *DrawingWand) PathCurveToAbsolute(x1, y1, x2, y2, x, y float64) {
C.MagickDrawPathCurveToAbsolute(dw.dw, C.double(x1), C.double(y1), C.double(x2), C.double(y2), C.double(x), C.double(y))
}
// Draws a cubic Bezier curve from the current point to (x,y) using (x1,y1) as
// the control point at the beginning of the curve and (x2,y2) as the control
// point at the end of the curve using relative coordinates. At the end of the
// command, the new current point becomes the final (x,y) coordinate pair used
// in the polybezier.
//
// x1, y1: x, y ordinates of control point for curve beginning
//
// x2, y2: x, y ordinates of control point for curve ending
//
// x, y: x, y ordinates of the end of the curve
//
func (dw *DrawingWand) PathCurveToRelative(x1, y1, x2, y2, x, y float64) {
C.MagickDrawPathCurveToRelative(dw.dw, C.double(x1), C.double(y1), C.double(x2), C.double(y2), C.double(x), C.double(y))
}
// Draws a quadratic Bezier curve from the current point to (x,y) using (x1,y1)
// as the control point using absolute coordinates. At the end of the command,
// the new current point becomes the final (x,y) coordinate pair used in the
// polybezier.
//
// x1, y1: ordinates of the control point
//
// x, y: ordinates of final point
//
func (dw *DrawingWand) PathCurveToQuadraticBezierAbsolute(x1, y1, x, y float64) {
C.MagickDrawPathCurveToQuadraticBezierAbsolute(dw.dw, C.double(x1), C.double(y1), C.double(x), C.double(y))
}
// Draws a quadratic Bezier curve from the current point to (x,y) using (x1,y1)
// as the control point using relative coordinates. At the end of the command,
// the new current point becomes the final (x,y) coordinate pair used in the
// polybezier.
// x1, y1: ordinates of the control point
// x, y: ordinates of final point
func (dw *DrawingWand) PathCurveToQuadraticBezierRelative(x1, y1, x, y float64) {
C.MagickDrawPathCurveToQuadraticBezierRelative(dw.dw, C.double(x1), C.double(y1), C.double(x), C.double(y))
}
// Draws a quadratic Bezier curve (using absolute coordinates) from the current
// point to (x,y). The control point is assumed to be the reflection of the
// control point on the previous command relative to the current point. (If
// there is no previous command or if the previous command was not a
// PathCurveToQuadraticBezierAbsolute, PathCurveToQuadraticBezierRelative,
// PathCurveToQuadraticBezierSmoothAbsolute or
// PathCurveToQuadraticBezierSmoothRelative, assume the control point is
// coincident with the current point.). At the end of the command, the new
// current point becomes the final (x,y) coordinate pair used in the polybezier.
//
//x, y: ordinates of final point
//
func (dw *DrawingWand) PathCurveToQuadraticBezierSmoothAbsolute(x, y float64) {
C.MagickDrawPathCurveToQuadraticBezierSmoothAbsolute(dw.dw, C.double(x), C.double(y))
}
// Draws a quadratic Bezier curve (using relative coordinates) from the current
// point to (x,y). The control point is assumed to be the reflection of the
// control point on the previous command relative to the current point. (If
// there is no previous command or if the previous command was not a
// PathCurveToQuadraticBezierAbsolute, PathCurveToQuadraticBezierRelative,
// PathCurveToQuadraticBezierSmoothAbsolute or
// PathCurveToQuadraticBezierSmoothRelative, assume the control point is
// coincident with the current point.). At the end of the command, the new
// current point becomes the final (x,y) coordinate pair used in the polybezier.
//
//x, y: ordinates of final point
//
func (dw *DrawingWand) PathCurveToQuadraticBezierSmoothRelative(x, y float64) {
C.MagickDrawPathCurveToQuadraticBezierSmoothRelative(dw.dw, C.double(x), C.double(y))
}
// Draws a cubic Bezier curve from the current point to (x,y) using absolute
// coordinates. The first control point is assumed to be the reflection of the
// second control point on the previous command relative to the current point.
// (If there is no previous command or if the previous command was not an
// PathCurveToAbsolute, PathCurveToRelative, PathCurveToSmoothAbsolute or
// PathCurveToSmoothRelative, assume the first control point is coincident
// with the current point.) (x2,y2) is the second control point (i.e., the
// control point at the end of the curve). At the end of the command, the new
// current point becomes the final (x,y) coordinate pair used in the polybezier.
//
// x2, y2: ordinates of second control point
//
// x, y: ordinates of termination point
//
func (dw *DrawingWand) PathCurveToSmoothAbsolute(x2, y2, x, y float64) {
C.MagickDrawPathCurveToSmoothAbsolute(dw.dw, C.double(x2), C.double(y2), C.double(x), C.double(y))
}
// Draws a cubic Bezier curve from the current point to (x,y) using relative
// coordinates. The first control point is assumed to be the reflection of the
// second control point on the previous command relative to the current point.
// (If there is no previous command or if the previous command was not an
// PathCurveToAbsolute, PathCurveToRelative, PathCurveToSmoothAbsolute or
// PathCurveToSmoothRelative, assume the first control point is coincident
// with the current point.) (x2,y2) is the second control point (i.e., the
// control point at the end of the curve). At the end of the command, the new
// current point becomes the final (x,y) coordinate pair used in the polybezier.
//
// x2, y2: ordinates of second control point
//
// x, y: ordinates of termination point
//
func (dw *DrawingWand) PathCurveToSmoothRelative(x2, y2, x, y float64) {
C.MagickDrawPathCurveToSmoothRelative(dw.dw, C.double(x2), C.double(y2), C.double(x), C.double(y))
}
// Draws an elliptical arc from the current point to (x, y) using absolute
// coordinates. The size and orientation of the ellipse are defined by two
// radii (rx, ry) and an xAxisRotation, which indicates how the ellipse as a
// whole is rotated relative to the current coordinate system. The center (cx,
// cy) of the ellipse is calculated automagically to satisfy the constraints
// imposed by the other parameters. largeArcFlag and sweepFlag contribute to
// the automatic calculations and help determine how the arc is drawn. If
// largeArcFlag is true then draw the larger of the available arcs. If
// sweepFlag is true, then draw the arc matching a clock-wise rotation.
//
// rx, ry: x, y radius
//
// xAxisRotation: indicates how the ellipse as a whole is rotated relative to
// the current coordinate system
//
// largeArcFlag: If true then draw the larger of the available arcs
//
// sweepFlag: If true then draw the arc matching a clock-wise rotation
//
func (dw *DrawingWand) PathEllipticArcAbsolute(rx, ry, xAxisRotation float64, largeArcFlag, sweepFlag bool, x, y float64) {
C.MagickDrawPathEllipticArcAbsolute(dw.dw, C.double(rx), C.double(ry), C.double(xAxisRotation), b2i(largeArcFlag), b2i(sweepFlag), C.double(x), C.double(y))
}
// Draws an elliptical arc from the current point to (x, y) using relative
// coordinates. The size and orientation of the ellipse are defined by two
// radii (rx, ry) and an xAxisRotation, which indicates how the ellipse as a
// whole is rotated relative to the current coordinate system. The center (cx,
// cy) of the ellipse is calculated automagically to satisfy the constraints
// imposed by the other parameters. largeArcFlag and sweepFlag contribute to
// the automatic calculations and help determine how the arc is drawn. If
// largeArcFlag is true then draw the larger of the available arcs. If
// sweepFlag is true, then draw the arc matching a clock-wise rotation.
//
// rx, ry: x, y radius
//
// xAxisRotation: indicates how the ellipse as a whole is rotated relative to
// the current coordinate system
//
// largeArcFlag: If true then draw the larger of the available arcs
//
// sweepFlag: If true then draw the arc matching a clock-wise rotation
//
func (dw *DrawingWand) PathEllipticArcRelative(rx, ry, xAxisRotation float64, largeArcFlag, sweepFlag bool, x, y float64) {
C.MagickDrawPathEllipticArcRelative(dw.dw, C.double(rx), C.double(ry), C.double(xAxisRotation), b2i(largeArcFlag), b2i(sweepFlag), C.double(x), C.double(y))
}
// Terminates the current path.
func (dw *DrawingWand) PathFinish() {
C.MagickDrawPathFinish(dw.dw)
}
// Draws a line path from the current point to the given coordinate using
// absolute coordinates. The coordinate then becomes the new current point.
//
// x, y: target x and y ordinates
func (dw *DrawingWand) PathLineToAbsolute(x, y float64) {
C.MagickDrawPathLineToAbsolute(dw.dw, C.double(x), C.double(y))
}
// Draws a line path from the current point to the given coordinate using
// relative coordinates. The coordinate then becomes the new current point.
//
// x, y: target x and y ordinates
//
func (dw *DrawingWand) PathLineToRelative(x, y float64) {
C.MagickDrawPathLineToRelative(dw.dw, C.double(x), C.double(y))
}
// Draws a horizontal line path from the current point to the target point
// using absolute coordinates. The target point then becomes the new current
// point.
//
// x: target x ordinate
func (dw *DrawingWand) PathLineToHorizontalAbsolute(x float64) {
C.MagickDrawPathLineToHorizontalAbsolute(dw.dw, C.double(x))
}
// Draws a horizontal line path from the current point to the target point
// using relative coordinates. The target point then becomes the new current
// point.
//
// x: target x ordinate
func (dw *DrawingWand) PathLineToHorizontalRelative(x float64) {
C.MagickDrawPathLineToHorizontalRelative(dw.dw, C.double(x))
}
// Draws a vertical line path from the current point to the target point using
// absolute coordinates. The target point then becomes the new current point.
//
// y: target y ordinate
func (dw *DrawingWand) PathLineToVerticalAbsolute(y float64) {
C.MagickDrawPathLineToVerticalAbsolute(dw.dw, C.double(y))
}
// Draws a vertical line path from the current point to the target point using
// relative coordinates. The target point then becomes the new current point.
//
// y: target y ordinate
func (dw *DrawingWand) PathLineToVerticalRelative(y float64) {
C.MagickDrawPathLineToVerticalRelative(dw.dw, C.double(y))
}
// Starts a new sub-path at the given coordinate using absolute coordinates.
// The current point then becomes the specified coordinate.
//
// x, y: target x and y ordinates
func (dw *DrawingWand) PathMoveToAbsolute(x, y float64) {
C.MagickDrawPathMoveToAbsolute(dw.dw, C.double(x), C.double(y))
}
// Starts a new sub-path at the given coordinate using relative coordinates.
// The current point then becomes the specified coordinate.
//
// x, y: target x and y ordinates
func (dw *DrawingWand) PathMoveToRelative(x, y float64) {
C.MagickDrawPathMoveToRelative(dw.dw, C.double(x), C.double(y))
}
// Declares the start of a path drawing list which is terminated by a matching
// PathFinish() command. All other Path commands must be enclosed between a
// PathStart() and a PathFinish() command. This is because path drawing
// commands are subordinate commands and they do not function by themselves.
func (dw *DrawingWand) PathStart() {
C.MagickDrawPathStart(dw.dw)
}
// Draws a point using the current fill color.
//
// x, y: target x, y coordinates
func (dw *DrawingWand) Point(x, y float64) {
C.DrawPoint(dw.dw, C.double(x), C.double(y))
}
// Draws a polygon using the current stroke, stroke width, and fill color or
// texture, using the specified array of coordinates.
func (dw *DrawingWand) Polygon(coordinates []PointInfo) {
ccoordinates := [1 << 16]C.PointInfo{}
for k, v := range coordinates {
ccoordinates[k] = C.PointInfo{C.double(v.X), C.double(v.Y)}
}
C.MagickDrawPolygon(dw.dw, C.ulong(len(coordinates)), (*C.PointInfo)(&ccoordinates[0]))
}
// Draws a polyline using the current stroke, stroke width, and fill color or
// texture, using the specified array of coordinates.
func (dw *DrawingWand) Polyline(coordinates []PointInfo) {
ccoordinates := [1 << 16]C.PointInfo{}
for k, v := range coordinates {
ccoordinates[k] = C.PointInfo{C.double(v.X), C.double(v.Y)}
}
C.MagickDrawPolyline(dw.dw, C.ulong(len(coordinates)), (*C.PointInfo)(&ccoordinates[0]))
}
// Terminates a clip path definition.
func (dw *DrawingWand) PopClipPath() {
C.DrawPopClipPath(dw.dw)
}
// Terminates a definition list.
func (dw *DrawingWand) PopDefs() {
C.MagickDrawPopDefs(dw.dw)
}
// Terminates a pattern definition.
func (dw *DrawingWand) PopPattern() {
C.MagickDrawPopPattern(dw.dw)
}
// Starts a clip path definition which is comprized of any number of drawing
// commands and terminated by a DrawPopClipPath() command.
//
// clipMaskId: string identifier to associate with the clip path for later use.
func (dw *DrawingWand) PushClipPath(clipMaskId string) {
cstr := C.CString(clipMaskId)
defer C.free(unsafe.Pointer(cstr))
C.MagickDrawPushClipPath(dw.dw, cstr)
}
// Indicates that commands up to a terminating PopDefs() command create named
// elements (e.g. clip-paths, textures, etc.) which may safely be processed
// earlier for the sake of efficiency.
func (dw *DrawingWand) PushDefs() {
C.MagickDrawPushDefs(dw.dw)
}
// Indicates that subsequent commands up to a PopPattern() command comprise the
// definition of a named pattern. The pattern space is assigned top left corner
// coordinates, a width and height, and becomes its own drawing space. Anything
// which can be drawn may be used in a pattern definition. Named patterns may
// be used as stroke or brush definitions.
//
// patternId: pattern identification for later reference
//
// x, y: ordinates of top left corner
//
// width, height of pattern space
func (dw *DrawingWand) PushPattern(patternId string, x, y, width, height float64) {
cstr := C.CString(patternId)
defer C.free(unsafe.Pointer(cstr))
C.MagickDrawPushPattern(dw.dw, cstr, C.double(x), C.double(y), C.double(width), C.double(height))
}
// Draws a rectangle given two coordinates and using the current stroke, stroke
// width, and fill settings.
//
// x1, y1: ordinates of first coordinate
//
// x2, y2: ordinates of second coordinate
func (dw *DrawingWand) Rectangle(x1, y1, x2, y2 float64) {
C.MagickDrawRectangle(dw.dw, C.double(x1), C.double(y1), C.double(x2), C.double(y2))
}
// Applies the specified rotation to the current coordinate space.
//
// degrees: degrees of rotation
func (dw *DrawingWand) Rotate(degrees float64) {
C.MagickDrawRotate(dw.dw, C.double(degrees))
}
// Draws a rounted rectangle given two coordinates, x & y corner radiuses and
// using the current stroke, stroke width, and fill settings.
//
// x1, y1: ordinates of first coordinate
//
// x2, y2: ordinates of second coordinate
//
// rx, ry: radius of corner in horizontal and vertical directions
func (dw *DrawingWand) RoundRectangle(x1, y1, x2, y2, rx, ry float64) {
C.MagickDrawRoundRectangle(dw.dw, C.double(x1), C.double(y1), C.double(x2), C.double(y2), C.double(rx), C.double(ry))
}
// Adjusts the scaling factor to apply in the horizontal and vertical
// directions to the current coordinate space.
//
// x: horizontal scale factor
//
// y: vertical scale factor
//
func (dw *DrawingWand) Scale(x, y float64) {
C.MagickDrawScale(dw.dw, C.double(x), C.double(y))
}
// Associates a named clipping path with the image. Only the areas drawn on by
// the clipping path will be modified as C.ssize_t(as) it remains in effect.
// clipMaskId: name of clipping path to associate with image
func (dw *DrawingWand) SetClipPath(clipMaskId string) {
cstr := C.CString(clipMaskId)
defer C.free(unsafe.Pointer(cstr))
C.MagickDrawSetClipPath(dw.dw, cstr)
}
// Set the polygon fill rule to be used by the clipping path.
func (dw *DrawingWand) SetClipRule(fillRule FillRule) {
C.MagickDrawSetClipRule(dw.dw, C.FillRule(fillRule))
}
// Sets the interpretation of clip path units.
// clipUnits: units to use
func (dw *DrawingWand) SetClipUnits(clipUnits ClipPathUnits) {
C.MagickDrawSetClipUnits(dw.dw, C.ClipPathUnits(clipUnits))
}
// Sets the fill color to be used for drawing filled objects.
func (dw *DrawingWand) SetFillColor(fillWand *PixelWand) {
C.MagickDrawSetFillColor(dw.dw, fillWand.pw)
}
// Sets the opacity to use when drawing using the fill color or fill texture.
// Fully opaque is 1.0.
func (dw *DrawingWand) SetFillOpacity(opacity float64) {
C.DrawSetFillOpacity(dw.dw, C.double(opacity))
}
// Sets the URL to use as a fill pattern for filling objects. Only local URLs
// ("#identifier") are supported at this time. These local URLs are normally
// created by defining a named fill pattern with PushPattern/PopPattern.
//
// fillUrl: URL to use to obtain fill pattern.
func (dw *DrawingWand) SetFillPatternURL(fillUrl string) {
cstr := C.CString(fillUrl)
defer C.free(unsafe.Pointer(cstr))
C.MagickDrawSetFillPatternURL(dw.dw, cstr)
}
// Sets the fill rule to use while drawing polygons.
func (dw *DrawingWand) SetFillRule(fillRule FillRule) {
C.MagickDrawSetFillRule(dw.dw, C.FillRule(fillRule))
}
// Sets the fully-sepecified font to use when annotating with text.
func (dw *DrawingWand) SetFont(fontName string) {
csFontName := C.CString(fontName)
defer C.free(unsafe.Pointer(csFontName))
C.MagickDrawSetFont(dw.dw, csFontName)
}
// Sets the font family to use when annotating with text.
func (dw *DrawingWand) SetFontFamily(fontFamily string) {
csFontFamily := C.CString(fontFamily)
defer C.free(unsafe.Pointer(csFontFamily))
C.MagickDrawSetFontFamily(dw.dw, csFontFamily)
}
// Sets the font pointsize to use when annotating with text.
//
// pointSize: text pointsize
func (dw *DrawingWand) SetFontSize(pointSize float64) {
C.MagickDrawSetFontSize(dw.dw, C.double(pointSize))
}
// Sets the font stretch to use when annotating with text. The AnyStretch
// enumeration acts as a wild-card "don't care" option.
func (dw *DrawingWand) SetFontStretch(fontStretch StretchType) {
C.MagickDrawSetFontStretch(dw.dw, C.StretchType(fontStretch))
}
// Sets the font style to use when annotating with text. The AnyStyle
// enumeration acts as a wild-card "don't care" option.
func (dw *DrawingWand) SetFontStyle(style StyleType) {
C.MagickDrawSetFontStyle(dw.dw, C.StyleType(style))
}
// Sets the font weight to use when annotating with text.
//
// fontWeight: font weight (valid range 100-900)
func (dw *DrawingWand) SetFontWeight(fontWeight uint) {
C.MagickDrawSetFontWeight(dw.dw, C.ulong(fontWeight))
}
// Sets the text placement gravity to use when annotating with text.
func (dw *DrawingWand) SetGravity(gravity GravityType) {
C.MagickDrawSetGravity(dw.dw, C.GravityType(gravity))
}
// Controls whether stroked outlines are antialiased. Stroked outlines are
// antialiased by default. When antialiasing is disabled stroked pixels are
// thresholded to determine if the stroke color or underlying canvas color
// should be used.
//
// antialias: set to false to disable antialiasing
func (dw *DrawingWand) SetStrokeAntialias(antialias bool) {
C.MagickDrawSetStrokeAntialias(dw.dw, b2i(antialias))
}
// Sets the color used for stroking object outlines.
func (dw *DrawingWand) SetStrokeColor(strokeWand *PixelWand) {
C.MagickDrawSetStrokeColor(dw.dw, strokeWand.pw)
}
// Specifies the pattern of dashes and gaps used to stroke paths. The stroke
// dash array represents an array of numbers that specify the lengths of
// alternating dashes and gaps in pixels. If an odd number of values is
// provided, then the list of values is repeated to yield an even number of
// values. To remove an existing dash array, pass an empty slice. A typical
// stroke dash array might contain the members 5 3 2.
func (dw *DrawingWand) SetStrokeDashArray(dash []float64) {
if len(dash) == 0 {
C.DrawSetStrokeDashArray(dw.dw, C.ulong(0), nil)
}
cdash := [1 << 16]C.double{}
for k, v := range dash {
cdash[k] = C.double(v)
}
C.MagickDrawSetStrokeDashArray(dw.dw, C.ulong(len(dash)), (*C.double)(&cdash[0]))
}
// Specifies the offset into the dash pattern to start the dash.
func (dw *DrawingWand) SetStrokeDashOffset(offset float64) {
C.MagickDrawSetStrokeDashOffset(dw.dw, C.double(offset))
}
// Specifies the shape to be used at the end of open subpaths when they are
// stroked.
func (dw *DrawingWand) SetStrokeLineCap(lineCap LineCap) {
C.MagickDrawSetStrokeLineCap(dw.dw, C.LineCap(lineCap))
}
// Specifies the shape to be used at the corners of paths (or other vector
// shapes) when they are stroked.
func (dw *DrawingWand) SetStrokeLineJoin(lineJoin LineJoin) {
C.MagickDrawSetStrokeLineJoin(dw.dw, C.LineJoin(lineJoin))
}
// Specifies the miter limit. When two line segments meet at a sharp angle and
// miter joins have been specified for 'lineJoin', it is possible for the miter
// to extend far beyond the thickness of the line stroking the path. The
// miterLimit' imposes a limit on the ratio of the miter length to the
// 'lineWidth'.
func (dw *DrawingWand) SetStrokeMiterLimit(miterLimit uint) {
C.MagickDrawSetStrokeMiterLimit(dw.dw, C.ulong(miterLimit))
}
// Specifies the opacity of stroked object outlines.
//
// opacity: stroke opacity. The value 1.0 is opaque.
func (dw *DrawingWand) SetStrokeOpacity(opacity float64) {
C.MagickDrawSetStrokeOpacity(dw.dw, C.double(opacity))
}
// Sets the pattern used for stroking object outlines.
//
// strokeUrl: URL specifying pattern ID (e.g. "#pattern_id")
func (dw *DrawingWand) SetStrokePatternURL(strokeUrl string) {
csStrokeUrl := C.CString(strokeUrl)
defer C.free(unsafe.Pointer(csStrokeUrl))
C.MagickDrawSetStrokePatternURL(dw.dw, csStrokeUrl)
}
// Sets the width of the stroke used to draw object outlines.
func (dw *DrawingWand) SetStrokeWidth(width float64) {
C.MagickDrawSetStrokeWidth(dw.dw, C.double(width))
}
// Controls whether text is antialiased. Text is antialiased by default.
func (dw *DrawingWand) SetTextAntialias(antialias bool) {
C.DrawSetTextAntialias(dw.dw, b2i(antialias))
}
// Specifies a decoration to be applied when annotating with text.
func (dw *DrawingWand) SetTextDecoration(decoration DecorationType) {
C.MagickDrawSetTextDecoration(dw.dw, C.DecorationType(decoration))
}
// Specifies the code set to use for text annotations. The only character
// encoding which may be specified at this time is "UTF-8" for representing
// Unicode as a sequence of bytes. Specify an empty string to set text
// encoding to the system's default. Successful text annotation using Unicode
// may require fonts designed to support Unicode.
func (dw *DrawingWand) SetTextEncoding(encoding string) {
csencoding := C.CString(encoding)
defer C.free(unsafe.Pointer(csencoding))
C.MagickDrawSetTextEncoding(dw.dw, csencoding)
}
// Specifies the color of a background rectangle to place under text
// annotations.
func (dw *DrawingWand) SetTextUnderColor(underWand *PixelWand) {
C.MagickDrawSetTextUnderColor(dw.dw, underWand.pw)
}
// Sets the overall canvas size to be recorded with the drawing vector data.
// Usually this will be specified using the same size as the canvas image.
// When the vector data is saved to SVG or MVG formats, the viewbox is use to
// specify the size of the canvas image that a viewer will render the vector
// data on.
//
// x1: left x ordinate
//
// y1: top y ordinate
//
// x2: right x ordinate
//
// y2: bottom y ordinate
func (dw *DrawingWand) SetViewbox(x1, y1, x2, y2 uint) {
C.MagickDrawSetViewbox(dw.dw, C.ulong(x1), C.ulong(y1), C.ulong(x2), C.ulong(y2))
}
// Skews the current coordinate system in the horizontal direction.
//
// degrees: number of degrees to skew the coordinates
func (dw *DrawingWand) SkewX(degrees float64) {
C.MagickDrawSkewX(dw.dw, C.double(degrees))
}
// Skews the current coordinate system in the vertical direction.
//
// degrees: number of degrees to skew the coordinates
func (dw *DrawingWand) SkewY(degrees float64) {
C.MagickDrawSkewY(dw.dw, C.double(degrees))
}
// Applies a translation to the current coordinate system which moves the