/
drawing_wand.go
1264 lines (1127 loc) · 43.2 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
// Copyright 2013 Herbert G. Fischer. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package imagick
/*
#include <MagickWand/MagickWand.h>
*/
import "C"
import (
"runtime"
"sync"
"sync/atomic"
"unsafe"
)
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())
}
// Clears resources associated with the drawing wand.
func (dw *DrawingWand) Clear() {
C.ClearDrawingWand(dw.dw)
runtime.KeepAlive(dw)
}
// Makes an exact copy of the specified wand.
func (dw *DrawingWand) Clone() *DrawingWand {
ret := newDrawingWand(C.CloneDrawingWand(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// 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() {
dw.dw = C.DestroyDrawingWand(dw.dw)
relinquishMemory(unsafe.Pointer(dw.dw))
runtime.SetFinalizer(dw, nil)
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.DrawAffine(dw.dw, affine.ptr())
runtime.KeepAlive(dw)
}
// 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.DrawAnnotation(dw.dw, C.double(x), C.double(y), cstext)
runtime.KeepAlive(dw)
}
// 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.DrawArc(dw.dw, C.double(sx), C.double(sy), C.double(ex), C.double(ey), C.double(sd), C.double(ed))
runtime.KeepAlive(dw)
}
// 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.DrawBezier(dw.dw, C.size_t(len(coordinates)), (*C.PointInfo)(&ccoordinates[0]))
runtime.KeepAlive(dw)
}
// 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.DrawCircle(dw.dw, C.double(ox), C.double(oy), C.double(px), C.double(py))
runtime.KeepAlive(dw)
}
// 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) error {
ok := C.DrawComposite(dw.dw, C.CompositeOperator(compose), C.double(x), C.double(y), C.double(width), C.double(height), mw.mw)
return dw.getLastErrorIfFailed(ok)
}
// 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.DrawColor(dw.dw, C.double(x), C.double(y), C.PaintMethod(pm))
runtime.KeepAlive(dw)
}
// 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.DrawComment(dw.dw, cscomment)
runtime.KeepAlive(dw)
}
// 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.DrawEllipse(dw.dw, C.double(ox), C.double(oy), C.double(rx), C.double(ry), C.double(start), C.double(end))
runtime.KeepAlive(dw)
}
// Returns the border color used for drawing bordered objects.
func (dw *DrawingWand) GetBorderColor() (pw *PixelWand) {
pw = NewPixelWand()
C.DrawGetBorderColor(dw.dw, pw.pw)
runtime.KeepAlive(dw)
return
}
// Obtains the current clipping path ID.
func (dw *DrawingWand) GetClipPath() string {
cscp := C.DrawGetClipPath(dw.dw)
runtime.KeepAlive(dw)
defer relinquishMemory(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 {
ret := FillRule(C.DrawGetClipRule(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns the interpretation of clip path units.
func (dw *DrawingWand) GetClipUnits() ClipPathUnits {
ret := ClipPathUnits(C.DrawGetClipUnits(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns the fill color used for drawing filled objects.
func (dw *DrawingWand) GetFillColor() (pw *PixelWand) {
pw = NewPixelWand()
C.DrawGetFillColor(dw.dw, pw.pw)
runtime.KeepAlive(dw)
return
}
// Returns the opacity used when drawing using the fill color or fill texture.
// Fully opaque is 1.0.
func (dw *DrawingWand) GetFillOpacity() float64 {
ret := float64(C.DrawGetFillOpacity(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns the fill rule used while drawing polygons.
func (dw *DrawingWand) GetFillRule() FillRule {
ret := FillRule(C.DrawGetFillRule(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns a string specifying the font used when annotating with text.
func (dw *DrawingWand) GetFont() string {
csfont := C.DrawGetFont(dw.dw)
runtime.KeepAlive(dw)
defer relinquishMemory(unsafe.Pointer(csfont))
return C.GoString(csfont)
}
// Returns the font family to use when annotating with text.
func (dw *DrawingWand) GetFontFamily() string {
csfamily := C.DrawGetFontFamily(dw.dw)
runtime.KeepAlive(dw)
defer relinquishMemory(unsafe.Pointer(csfamily))
return C.GoString(csfamily)
}
// Gets the image X and Y resolution.
func (dw *DrawingWand) GetFontResolution() (x, y float64, err error) {
ok := C.DrawGetFontResolution(dw.dw, (*C.double)(&x), (*C.double)(&y))
err = dw.getLastErrorIfFailed(ok)
return
}
// Returns the font stretch used when annotating with text.
func (dw *DrawingWand) GetFontStretch() StretchType {
ret := StretchType(C.DrawGetFontStretch(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns the font style used when annotating with text.
func (dw *DrawingWand) GetFontStyle() StyleType {
ret := StyleType(C.DrawGetFontStyle(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns the font weight used when annotating with text.
func (dw *DrawingWand) GetFontWeight() uint {
ret := uint(C.DrawGetFontWeight(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns the text placement gravity used when annotating with text.
func (dw *DrawingWand) GetGravity() GravityType {
ret := GravityType(C.DrawGetGravity(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns the opacity used when drawing with the fill or stroke color or
// texture. Fully opaque is 1.0.
func (dw *DrawingWand) GetOpacity() float64 {
ret := float64(C.DrawGetOpacity(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// 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 {
ret := 1 == C.DrawGetStrokeAntialias(dw.dw)
runtime.KeepAlive(dw)
return ret
}
// Returns the color used for stroking object outlines.
func (dw *DrawingWand) GetStrokeColor() (pw *PixelWand) {
pw = NewPixelWand()
C.DrawGetStrokeColor(dw.dw, pw.pw)
runtime.KeepAlive(dw)
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.size_t(0)
p := C.DrawGetStrokeDashArray(dw.dw, &count)
runtime.KeepAlive(dw)
nums = sizedDoubleArrayToFloat64Slice(p, count)
return
}
// Returns the offset into the dash pattern to start the dash.
func (dw *DrawingWand) GetStrokeDashOffset() float64 {
ret := float64(C.DrawGetStrokeDashOffset(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// 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 {
ret := LineCap(C.DrawGetStrokeLineCap(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// 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 {
ret := LineJoin(C.DrawGetStrokeLineJoin(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// 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 {
ret := uint(C.DrawGetStrokeMiterLimit(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns the opacity of stroked object outlines.
func (dw *DrawingWand) GetStrokeOpacity() float64 {
ret := float64(C.DrawGetStrokeOpacity(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns the width of the stroke used to draw object outlines.
func (dw *DrawingWand) GetStrokeWidth() float64 {
ret := float64(C.DrawGetStrokeWidth(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns the alignment applied when annotating with text.
func (dw *DrawingWand) GetTextAlignment() AlignType {
ret := AlignType(C.DrawGetTextAlignment(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns the current text antialias setting, which determines whether text
// is antialiased. Text is antialiased by default.
func (dw *DrawingWand) GetTextAntialias() bool {
ret := 1 == C.DrawGetTextAntialias(dw.dw)
runtime.KeepAlive(dw)
return ret
}
// Returns the decoration applied when annotating with text.
func (dw *DrawingWand) GetTextDecoration() DecorationType {
ret := DecorationType(C.DrawGetTextDecoration(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns a string which specifies the code set used for text annotations.
func (dw *DrawingWand) GetTextEncoding() string {
cstr := C.DrawGetTextEncoding(dw.dw)
runtime.KeepAlive(dw)
defer relinquishMemory(unsafe.Pointer(cstr))
return C.GoString(cstr)
}
// Gets the spacing between characters in text.
func (dw *DrawingWand) GetTextKerning() float64 {
ret := float64(C.DrawGetTextKerning(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Gets the spacing between lines in text.
func (dw *DrawingWand) GetTextInterlineSpacing() float64 {
ret := float64(C.DrawGetTextInterlineSpacing(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Gets the spacing between words in text.
func (dw *DrawingWand) GetTextInterwordSpacing() float64 {
ret := float64(C.DrawGetTextInterwordSpacing(dw.dw))
runtime.KeepAlive(dw)
return ret
}
// Returns a string which specifies the vector graphics generated by any
// graphics calls made since the wand was instantiated.
func (dw *DrawingWand) GetVectorGraphics() string {
cstr := C.DrawGetVectorGraphics(dw.dw)
runtime.KeepAlive(dw)
defer relinquishMemory(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.DrawGetTextUnderColor(dw.dw, pw.pw)
runtime.KeepAlive(dw)
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.DrawLine(dw.dw, C.double(sx), C.double(sy), C.double(ex), C.double(ey))
runtime.KeepAlive(dw)
}
// Deprecated in ImageMagick-7.x
// Use Alpha()
func (dw *DrawingWand) Matte(x, y float64, pmethod PaintMethod) {
C.DrawAlpha(dw.dw, C.double(x), C.double(y), C.PaintMethod(pmethod))
runtime.KeepAlive(dw)
}
// 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) Alpha(x, y float64, pmethod PaintMethod) {
C.DrawAlpha(dw.dw, C.double(x), C.double(y), C.PaintMethod(pmethod))
runtime.KeepAlive(dw)
}
// 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.DrawPathClose(dw.dw)
runtime.KeepAlive(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.DrawPathCurveToAbsolute(dw.dw, C.double(x1), C.double(y1), C.double(x2), C.double(y2), C.double(x), C.double(y))
runtime.KeepAlive(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 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.DrawPathCurveToRelative(dw.dw, C.double(x1), C.double(y1), C.double(x2), C.double(y2), C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathCurveToQuadraticBezierAbsolute(dw.dw, C.double(x1), C.double(y1), C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathCurveToQuadraticBezierRelative(dw.dw, C.double(x1), C.double(y1), C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathCurveToQuadraticBezierSmoothAbsolute(dw.dw, C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathCurveToQuadraticBezierSmoothRelative(dw.dw, C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathCurveToSmoothAbsolute(dw.dw, C.double(x2), C.double(y2), C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathCurveToSmoothRelative(dw.dw, C.double(x2), C.double(y2), C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathEllipticArcAbsolute(dw.dw, C.double(rx), C.double(ry), C.double(xAxisRotation), b2i(largeArcFlag), b2i(sweepFlag), C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathEllipticArcRelative(dw.dw, C.double(rx), C.double(ry), C.double(xAxisRotation), b2i(largeArcFlag), b2i(sweepFlag), C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// Terminates the current path.
func (dw *DrawingWand) PathFinish() {
C.DrawPathFinish(dw.dw)
runtime.KeepAlive(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.DrawPathLineToAbsolute(dw.dw, C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathLineToRelative(dw.dw, C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathLineToHorizontalAbsolute(dw.dw, C.double(x))
runtime.KeepAlive(dw)
}
// 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.DrawPathLineToHorizontalRelative(dw.dw, C.double(x))
runtime.KeepAlive(dw)
}
// 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.DrawPathLineToVerticalAbsolute(dw.dw, C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathLineToVerticalRelative(dw.dw, C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathMoveToAbsolute(dw.dw, C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathMoveToRelative(dw.dw, C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// 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.DrawPathStart(dw.dw)
runtime.KeepAlive(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))
runtime.KeepAlive(dw)
}
// 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.DrawPolygon(dw.dw, C.size_t(len(coordinates)), (*C.PointInfo)(&ccoordinates[0]))
runtime.KeepAlive(dw)
}
// 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.DrawPolyline(dw.dw, C.size_t(len(coordinates)), (*C.PointInfo)(&ccoordinates[0]))
runtime.KeepAlive(dw)
}
// Terminates a clip path definition.
func (dw *DrawingWand) PopClipPath() {
C.DrawPopClipPath(dw.dw)
runtime.KeepAlive(dw)
}
// Terminates a definition list.
func (dw *DrawingWand) PopDefs() {
C.DrawPopDefs(dw.dw)
runtime.KeepAlive(dw)
}
// Terminates a pattern definition.
func (dw *DrawingWand) PopPattern() error {
ok := C.DrawPopPattern(dw.dw)
return dw.getLastErrorIfFailed(ok)
}
// 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.DrawPushClipPath(dw.dw, cstr)
runtime.KeepAlive(dw)
}
// 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.DrawPushDefs(dw.dw)
runtime.KeepAlive(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) error {
cstr := C.CString(patternId)
defer C.free(unsafe.Pointer(cstr))
ok := C.DrawPushPattern(dw.dw, cstr, C.double(x), C.double(y), C.double(width), C.double(height))
return dw.getLastErrorIfFailed(ok)
}
// 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.DrawRectangle(dw.dw, C.double(x1), C.double(y1), C.double(x2), C.double(y2))
runtime.KeepAlive(dw)
}
// Resets the vector graphics associated with the specified wand.
func (dw *DrawingWand) ResetVectorGraphics() {
C.DrawResetVectorGraphics(dw.dw)
runtime.KeepAlive(dw)
}
// Applies the specified rotation to the current coordinate space.
//
// degrees: degrees of rotation
func (dw *DrawingWand) Rotate(degrees float64) {
C.DrawRotate(dw.dw, C.double(degrees))
runtime.KeepAlive(dw)
}
// 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.DrawRoundRectangle(dw.dw, C.double(x1), C.double(y1), C.double(x2), C.double(y2), C.double(rx), C.double(ry))
runtime.KeepAlive(dw)
}
// 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.DrawScale(dw.dw, C.double(x), C.double(y))
runtime.KeepAlive(dw)
}
// Sets the border color to be used for drawing bordered objects.
func (dw *DrawingWand) SetBorderColor(borderWand *PixelWand) {
C.DrawSetBorderColor(dw.dw, borderWand.pw)
runtime.KeepAlive(dw)
}
// 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) error {
cstr := C.CString(clipMaskId)
defer C.free(unsafe.Pointer(cstr))
ok := C.DrawSetClipPath(dw.dw, cstr)
return dw.getLastErrorIfFailed(ok)
}
// Set the polygon fill rule to be used by the clipping path.
func (dw *DrawingWand) SetClipRule(fillRule FillRule) {
C.DrawSetClipRule(dw.dw, C.FillRule(fillRule))
runtime.KeepAlive(dw)
}
// Sets the interpretation of clip path units.
// clipUnits: units to use
func (dw *DrawingWand) SetClipUnits(clipUnits ClipPathUnits) {
C.DrawSetClipUnits(dw.dw, C.ClipPathUnits(clipUnits))
runtime.KeepAlive(dw)
}
// Sets the fill color to be used for drawing filled objects.
func (dw *DrawingWand) SetFillColor(fillWand *PixelWand) {
C.DrawSetFillColor(dw.dw, fillWand.pw)
runtime.KeepAlive(dw)
}
// 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))
runtime.KeepAlive(dw)
}
// Sets the image resolution.
//
// xRes, yRes: the image x and y resolutions
func (dw *DrawingWand) SetFontResolution(xRes, yRes float64) error {
ok := C.DrawSetFontResolution(dw.dw, C.double(xRes), C.double(yRes))
return dw.getLastErrorIfFailed(ok)
}
// Sets the opacity to use when drawing using the fill or stroke color or
// texture. Fully opaque is 1.0.
func (dw *DrawingWand) SetOpacity(opacity float64) {
C.DrawSetOpacity(dw.dw, C.double(opacity))
runtime.KeepAlive(dw)
}
// 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) error {
cstr := C.CString(fillUrl)
defer C.free(unsafe.Pointer(cstr))
ok := C.DrawSetFillPatternURL(dw.dw, cstr)
return dw.getLastErrorIfFailed(ok)
}
// Sets the fill rule to use while drawing polygons.
func (dw *DrawingWand) SetFillRule(fillRule FillRule) {
C.DrawSetFillRule(dw.dw, C.FillRule(fillRule))
runtime.KeepAlive(dw)
}
// Sets the fully-sepecified font to use when annotating with text.
func (dw *DrawingWand) SetFont(fontName string) error {
csFontName := C.CString(fontName)
defer C.free(unsafe.Pointer(csFontName))
ok := C.DrawSetFont(dw.dw, csFontName)
return dw.getLastErrorIfFailed(ok)
}
// Sets the font family to use when annotating with text.
func (dw *DrawingWand) SetFontFamily(fontFamily string) error {
csFontFamily := C.CString(fontFamily)
defer C.free(unsafe.Pointer(csFontFamily))
ok := C.DrawSetFontFamily(dw.dw, csFontFamily)
return dw.getLastErrorIfFailed(ok)
}
// Sets the font pointsize to use when annotating with text.
//
// pointSize: text pointsize