/
Cairo.pm6
1376 lines (1155 loc) · 36.2 KB
/
Cairo.pm6
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
unit module Cairo;
our $cairolib;
BEGIN {
if $*VM.config<dll> ~~ /dll/ {
$cairolib = 'libcairo-2';
} else {
$cairolib = ('cairo', v2);
}
}
use NativeCall;
our enum cairo_status_t is export <
CAIRO_STATUS_SUCCESS
CAIRO_STATUS_NO_MEMORY
CAIRO_STATUS_INVALID_RESTORE
CAIRO_STATUS_INVALID_POP_GROUP
CAIRO_STATUS_NO_CURRENT_POINT
CAIRO_STATUS_INVALID_MATRIX
CAIRO_STATUS_INVALID_STATUS
CAIRO_STATUS_NULL_POINTER
CAIRO_STATUS_INVALID_STRING
CAIRO_STATUS_INVALID_PATH_DATA
CAIRO_STATUS_READ_ERROR
CAIRO_STATUS_WRITE_ERROR
CAIRO_STATUS_SURFACE_FINISHED
CAIRO_STATUS_SURFACE_TYPE_MISMATCH
CAIRO_STATUS_PATTERN_TYPE_MISMATCH
CAIRO_STATUS_INVALID_CONTENT
CAIRO_STATUS_INVALID_FORMAT
CAIRO_STATUS_INVALID_VISUAL
CAIRO_STATUS_FILE_NOT_FOUND
CAIRO_STATUS_INVALID_DASH
CAIRO_STATUS_INVALID_DSC_COMMENT
CAIRO_STATUS_INVALID_INDEX
CAIRO_STATUS_CLIP_NOT_REPRESENTABLE
CAIRO_STATUS_TEMP_FILE_ERROR
CAIRO_STATUS_INVALID_STRIDE
CAIRO_STATUS_FONT_TYPE_MISMATCH
CAIRO_STATUS_USER_FONT_IMMUTABLE
CAIRO_STATUS_USER_FONT_ERROR
CAIRO_STATUS_NEGATIVE_COUNT
CAIRO_STATUS_INVALID_CLUSTERS
CAIRO_STATUS_INVALID_SLANT
CAIRO_STATUS_INVALID_WEIGHT
CAIRO_STATUS_INVALID_SIZE
CAIRO_STATUS_USER_FONT_NOT_IMPLEMENTED
CAIRO_STATUS_DEVICE_TYPE_MISMATCH
CAIRO_STATUS_DEVICE_ERROR
CAIRO_STATUS_INVALID_MESH_CONSTRUCTION
CAIRO_STATUS_DEVICE_FINISHED
CAIRO_STATUS_LAST_STATUS
>;
our enum cairo_operator_t is export <
CAIRO_OPERATOR_CLEAR
CAIRO_OPERATOR_SOURCE
CAIRO_OPERATOR_OVER
CAIRO_OPERATOR_IN
CAIRO_OPERATOR_OUT
CAIRO_OPERATOR_ATOP
CAIRO_OPERATOR_DEST
CAIRO_OPERATOR_DEST_OVER
CAIRO_OPERATOR_DEST_IN
CAIRO_OPERATOR_DEST_OUT
CAIRO_OPERATOR_DEST_ATOP
CAIRO_OPERATOR_XOR
CAIRO_OPERATOR_ADD
CAIRO_OPERATOR_SATURATE
CAIRO_OPERATOR_MULTIPLY
CAIRO_OPERATOR_SCREEN
CAIRO_OPERATOR_OVERLAY
CAIRO_OPERATOR_DARKEN
CAIRO_OPERATOR_LIGHTEN
CAIRO_OPERATOR_COLOR_DODGE
CAIRO_OPERATOR_COLOR_BURN
CAIRO_OPERATOR_HARD_LIGHT
CAIRO_OPERATOR_SOFT_LIGHT
CAIRO_OPERATOR_DIFFERENCE
CAIRO_OPERATOR_EXCLUSION
CAIRO_OPERATOR_HSL_HUE
CAIRO_OPERATOR_HSL_SATURATION
CAIRO_OPERATOR_HSL_COLOR
CAIRO_OPERATOR_HSL_LUMINOSITY
>;
our enum cairo_format_t is export (
CAIRO_FORMAT_INVALID => -1,
CAIRO_FORMAT_ARGB32 => 0,
CAIRO_FORMAT_RGB24 => 1,
CAIRO_FORMAT_A8 => 2,
CAIRO_FORMAT_A1 => 3,
CAIRO_FORMAT_RGB16_565 => 4,
CAIRO_FORMAT_RGB30 => 5
);
our enum CairoStatus is export <
STATUS_SUCCESS
STATUS_NO_MEMORY
STATUS_INVALID_RESTORE
STATUS_INVALID_POP_GROUP
STATUS_NO_CURRENT_POINT
STATUS_INVALID_MATRIX
STATUS_INVALID_STATUS
STATUS_NULL_POINTER
STATUS_INVALID_STRING
STATUS_INVALID_PATH_DATA
STATUS_READ_ERROR
STATUS_WRITE_ERROR
STATUS_SURFACE_FINISHED
STATUS_SURFACE_TYPE_MISMATCH
STATUS_PATTERN_TYPE_MISMATCH
STATUS_INVALID_CONTENT
STATUS_INVALID_FORMAT
STATUS_INVALID_VISUAL
STATUS_FILE_NOT_FOUND
STATUS_INVALID_DASH
STATUS_INVALID_DSC_COMMENT
STATUS_INVALID_INDEX
STATUS_CLIP_NOT_REPRESENTABLE
STATUS_TEMP_FILE_ERROR
STATUS_INVALID_STRIDE
STATUS_FONT_TYPE_MISMATCH
STATUS_USER_FONT_IMMUTABLE
STATUS_USER_FONT_ERROR
STATUS_NEGATIVE_COUNT
STATUS_INVALID_CLUSTERS
STATUS_INVALID_SLANT
STATUS_INVALID_WEIGHT
STATUS_INVALID_SIZE
STATUS_USER_FONT_NOT_IMPLEMENTED
STATUS_DEVICE_TYPE_MISMATCH
STATUS_DEVICE_ERROR
STATUS_INVALID_MESH_CONSTRUCTION
STATUS_DEVICE_FINISHED
STATUS_LAST_STATUS
>;
my class StreamClosure is repr('CStruct') is rw {
sub memcpy(Pointer[uint8] $dest, Pointer[uint8] $src, size_t $n)
is native
{*}
has CArray[uint8] $!buf;
has size_t $.buf-len;
has size_t $.n-read;
has size_t $.size;
method TWEAK(CArray :$buf!) { $!buf := $buf }
method buf-pointer(--> Pointer[uint8]) {
nativecast(Pointer[uint8], $!buf);
}
method read-pointer(--> Pointer) {
Pointer[uint8].new: +$.buf-pointer + $!n-read;
}
method write-pointer(--> Pointer) {
Pointer[uint8].new: +$.buf-pointer + $!buf-len;
}
our method read(Pointer $out, uint32 $len --> int32) {
return STATUS_READ_ERROR
if $len > self.buf-len - self.n-read;
memcpy($out, self.read-pointer, $len);
self.n-read += $len;
return STATUS_SUCCESS;
}
our method write(Pointer $in, uint32 $len --> int32) {
return STATUS_WRITE_ERROR
if $len > self.size - self.buf-len;
memcpy(self.write-pointer, $in, $len);
self.buf-len += $len;
return STATUS_SUCCESS;
}
}
our class cairo_surface_t is repr('CPointer') {
method write_to_png(Str $filename)
returns int32
is native($cairolib)
is symbol('cairo_surface_write_to_png')
{*}
method write_to_png_stream(
&write-func (StreamClosure, Pointer[uint8], uint32 --> int32),
StreamClosure)
returns int32
is native($cairolib)
is symbol('cairo_surface_write_to_png_stream')
{*}
method reference
returns cairo_surface_t
is native($cairolib)
is symbol('cairo_surface_reference')
{*}
method show_page
is native($cairolib)
is symbol('cairo_surface_show_page')
{*}
method flush
is native($cairolib)
is symbol('cairo_surface_flush')
{*}
method finish
is native($cairolib)
is symbol('cairo_surface_finish')
{*}
method destroy
is native($cairolib)
is symbol('cairo_surface_destroy')
{*}
method get_image_data
returns OpaquePointer
is native($cairolib)
is symbol('cairo_image_surface_get_data')
{*}
method get_image_stride
returns int32
is native($cairolib)
is symbol('cairo_image_surface_get_stride')
{*}
method get_image_width
returns int32
is native($cairolib)
is symbol('cairo_image_surface_get_width')
{*}
method get_image_height
returns int32
is native($cairolib)
is symbol('cairo_image_surface_get_height')
{*}
}
our class cairo_rectangle_t is repr('CPointer') { }
our class cairo_path_t is repr('CPointer') { }
our class cairo_text_extents_t is repr('CStruct') {
has num64 $.x_bearing;
has num64 $.y_bearing;
has num64 $.width;
has num64 $.height;
has num64 $.x_advance;
has num64 $.y_advance;
}
our class cairo_font_extents_t is repr('CStruct') {
has num64 $.ascent;
has num64 $.descent;
has num64 $.height;
has num64 $.max_x_advance;
has num64 $.max_y_advance;
}
our class cairo_font_face_t is repr('CPointer') {
method destroy
is native($cairolib)
is symbol('cairo_font_face_destroy')
{*}
}
our class cairo_matrix_t is repr('CStruct') {
has num64 $.xx; has num64 $.yx;
has num64 $.xy; has num64 $.yy;
has num64 $.x0; has num64 $.y0;
method init(num64 $xx, num64 $yx, num64 $xy, num64 $yy, num64 $x0, num64 $y0)
is native($cairolib)
is symbol('cairo_matrix_init')
{*}
method scale(num64 $sx, num64 $sy)
is native($cairolib)
is symbol('cairo_matrix_scale')
{*}
method translate(num64 $tx, num64 $ty)
is native($cairolib)
is symbol('cairo_matrix_translate')
{*}
method rotate(cairo_matrix_t $b)
is native($cairolib)
is symbol('cairo_matrix_rotate')
{*}
method invert
is native($cairolib)
is symbol('cairo_matrix_invert')
{*}
method multiply(cairo_matrix_t $a, cairo_matrix_t $b)
is native($cairolib)
is symbol('cairo_matrix_multiply')
{*}
}
our class cairo_pattern_t is repr('CPointer') {
method destroy
is native($cairolib)
is symbol('cairo_pattern_destroy')
{*}
method get_extend
returns int32
is native($cairolib)
is symbol('cairo_pattern_get_extend')
{*}
method set_extend(uint32 $extend)
is native($cairolib)
is symbol('cairo_pattern_set_extend')
{*}
method set_matrix(cairo_matrix_t $matrix)
is native($cairolib)
is symbol('cairo_pattern_set_matrix')
{*}
method get_matrix(cairo_matrix_t $matrix)
is native($cairolib)
is symbol('cairo_pattern_get_matrix')
{*}
method add_color_stop_rgb(num64 $offset, num64 $r, num64 $g, num64 $b)
returns int32
is native($cairolib)
is symbol('cairo_pattern_add_color_stop_rgb')
{*}
method add_color_stop_rgba(num64 $offset, num64 $r, num64 $g, num64 $b, num64 $a)
returns int32
is native($cairolib)
is symbol('cairo_pattern_add_color_stop_rgba')
{*}
}
our class cairo_t is repr('CPointer') {
method destroy
is native($cairolib)
is symbol('cairo_destroy')
{*}
method sub_path
returns cairo_path_t
is native($cairolib)
is symbol('cairo_new_sub_path')
{*}
method copy_path
returns cairo_path_t
is native($cairolib)
is symbol('cairo_copy_path')
{*}
method copy_path_flat
returns cairo_path_t
is native($cairolib)
is symbol('cairo_copy_path_flat')
{*}
method append_path(cairo_path_t $path)
returns cairo_path_t
is native($cairolib)
is symbol('cairo_append_path')
{*}
method push_group
is native($cairolib)
is symbol('cairo_push_group')
{*}
method pop_group
returns cairo_pattern_t
is native($cairolib)
is symbol('cairo_pop_group')
{*}
method pop_group_to_source
is native($cairolib)
is symbol('cairo_pop_group_to_source')
{*}
method line_to(num64 $x, num64 $y)
is native($cairolib)
is symbol('cairo_line_to')
{*}
method move_to(num64 $x, num64 $y)
is native($cairolib)
is symbol('cairo_move_to')
{*}
method rel_line_to(num64 $x, num64 $y)
is native($cairolib)
is symbol('cairo_rel_line_to')
{*}
method rel_move_to(num64 $x, num64 $y)
is native($cairolib)
is symbol('cairo_rel_move_to')
{*}
method curve_to(num64 $x1, num64 $y1, num64 $x2, num64 $y2, num64 $x3, num64 $y3)
is native($cairolib)
is symbol('cairo_curve_to')
{*}
method arc(num64 $xc, num64 $yc, num64 $radius, num64 $angle1, num64 $angle2)
is native($cairolib)
is symbol('cairo_arc')
{*}
method arc_negative(num64 $xc, num64 $yc, num64 $radius, num64 $angle1, num64 $angle2)
is native($cairolib)
is symbol('cairo_arc_negative')
{*}
method close_path
is native($cairolib)
is symbol('cairo_close_path')
{*}
method new_path
is native($cairolib)
is symbol('cairo_new_path')
{*}
method rectangle(num64 $x, num64 $y, num64 $w, num64 $h)
is native($cairolib)
is symbol('cairo_rectangle')
{*}
method set_source_rgb(num64 $r, num64 $g, num64 $b)
is native($cairolib)
is symbol('cairo_set_source_rgb')
{*}
method set_source_rgba(num64 $r, num64 $g, num64 $b, num64 $a)
is native($cairolib)
is symbol('cairo_set_source_rgba')
{*}
method set_source(cairo_pattern_t $pat)
is native($cairolib)
is symbol('cairo_set_source')
{*}
method set_line_cap(int32 $cap)
is native($cairolib)
is symbol('cairo_set_line_cap')
{*}
method get_line_cap
returns int32
is native($cairolib)
is symbol('cairo_get_line_cap')
{*}
method set_line_join(int32 $join)
is native($cairolib)
is symbol('cairo_set_line_join')
{*}
method get_line_join
returns int32
is native($cairolib)
is symbol('cairo_get_line_join')
{*}
method set_fill_rule(int32 $cap)
is native($cairolib)
is symbol('cairo_set_fill_rule')
{*}
method get_fill_rule
returns int32
is native($cairolib)
is symbol('cairo_get_fill_rule')
{*}
method set_line_width(num64 $width)
is native($cairolib)
is symbol('cairo_set_line_width')
{*}
method get_line_width
returns num64
is native($cairolib)
is symbol('cairo_get_line_width')
{*}
method set_dash(CArray[num64] $dashes, int32 $len, num64 $offset)
is native($cairolib)
is symbol('cairo_set_dash')
{*}
method get_operator
returns int32
is native($cairolib)
is symbol('cairo_get_operator')
{*}
method set_operator(int32 $op)
is native($cairolib)
is symbol('cairo_set_operator')
{*}
method get_antialias
returns int32
is native($cairolib)
is symbol('cairo_get_antialias')
{*}
method set_antialias(int32 $op)
is native($cairolib)
is symbol('cairo_set_antialias')
{*}
method set_source_surface(cairo_surface_t $surface, num64 $x, num64 $y)
is native($cairolib)
is symbol('cairo_set_source_surface')
{*}
method mask(cairo_pattern_t $pattern)
is native($cairolib)
is symbol('cairo_mask')
{*}
method mask_surface(cairo_surface_t $surface, num64 $sx, num64 $sy)
is native($cairolib)
is symbol('cairo_mask_surface')
{*}
method clip
is native($cairolib)
is symbol('cairo_clip')
{*}
method clip_preserve
is native($cairolib)
is symbol('cairo_clip_preserve')
{*}
method fill
is native($cairolib)
is symbol('cairo_fill')
{*}
method stroke
is native($cairolib)
is symbol('cairo_stroke')
{*}
method fill_preserve
is native($cairolib)
is symbol('cairo_fill_preserve')
{*}
method stroke_preserve
is native($cairolib)
is symbol('cairo_stroke_preserve')
{*}
method paint
is native($cairolib)
is symbol('cairo_paint')
{*}
method paint_with_alpha(num64 $alpha)
is native($cairolib)
is symbol('cairo_paint_with_alpha')
{*}
method translate(num64 $tx, num64 $ty)
is native($cairolib)
is symbol('cairo_translate')
{*}
method scale(num64 $sx, num64 $sy)
is native($cairolib)
is symbol('cairo_scale')
{*}
method rotate(num64 $angle)
is native($cairolib)
is symbol('cairo_rotate')
{*}
method transform(cairo_matrix_t $matrix)
is native($cairolib)
is symbol('cairo_transform')
{*}
method identity_matrix
is native($cairolib)
is symbol('cairo_identity_matrix')
{*}
method set_matrix(cairo_matrix_t $matrix)
is native($cairolib)
is symbol('cairo_set_matrix')
{*}
method get_matrix(cairo_matrix_t $matrix)
is native($cairolib)
is symbol('cairo_get_matrix')
{*}
method save
is native($cairolib)
is symbol('cairo_save')
{*}
method restore
is native($cairolib)
is symbol('cairo_restore')
{*}
method status
returns int32
is native($cairolib)
is symbol('cairo_status')
{*}
method select_font_face(Str $family, int32 $slant, int32 $weight)
is native($cairolib)
is symbol('cairo_select_font_face')
{*}
method set_font_face(cairo_font_face_t $font)
is native($cairolib)
is symbol('cairo_set_font_face')
{*}
method set_font_size(num64 $size)
is native($cairolib)
is symbol('cairo_set_font_size')
{*}
method show_text(Str $utf8)
is native($cairolib)
is symbol('cairo_show_text')
{*}
method text_path(Str $utf8)
is native($cairolib)
is symbol('cairo_text_path')
{*}
method text_extents(Str $utf8, cairo_text_extents_t $extents)
is native($cairolib)
is symbol('cairo_text_extents')
{*}
method font_extents(cairo_font_extents_t $extents)
is native($cairolib)
is symbol('cairo_font_extents')
{*}
}
our class Matrix { ... }
our class Surface { ... }
our class Image { ... }
our class Pattern { ... }
our class Context { ... }
our class Font { ... }
our enum Format (
FORMAT_INVALID => -1,
"FORMAT_ARGB32" ,
"FORMAT_RGB24" ,
"FORMAT_A8" ,
"FORMAT_A1" ,
"FORMAT_RGB16_565",
"FORMAT_RGB30" ,
);
our enum Operator <
OPERATOR_CLEAR
OPERATOR_SOURCE
OPERATOR_OVER
OPERATOR_IN
OPERATOR_OUT
OPERATOR_ATOP
OPERATOR_DEST
OPERATOR_DEST_OVER
OPERATOR_DEST_IN
OPERATOR_DEST_OUT
OPERATOR_DEST_ATOP
OPERATOR_XOR
OPERATOR_ADD
OPERATOR_SATURATE
OPERATOR_MULTIPLY
OPERATOR_SCREEN
OPERATOR_OVERLAY
OPERATOR_DARKEN
OPERATOR_LIGHTEN
OPERATOR_COLOR_DODGE
OPERATOR_COLOR_BURN
OPERATOR_HARD_LIGHT
OPERATOR_SOFT_LIGHT
OPERATOR_DIFFERENCE
OPERATOR_EXCLUSION
OPERATOR_HSL_HUE
OPERATOR_HSL_SATURATION
OPERATOR_HSL_COLOR
OPERATOR_HSL_LUMINOSITY
>;
our enum LineCap <
LINE_CAP_BUTT
LINE_CAP_ROUND
LINE_CAP_SQUARE
>;
our enum LineJoin <
LINE_JOIN_MITER
LINE_JOIN_ROUND
LINE_JOIN_BEVEL
>;
our enum Content (
CONTENT_COLOR => 0x1000,
CONTENT_ALPHA => 0x2000,
CONTENT_COLOR_ALPHA => 0x3000,
);
our enum Antialias <
ANTIALIAS_DEFAULT
ANTIALIAS_NONE
ANTIALIAS_GRAY
ANTIALIAS_SUBPIXEL
ANTIALIAS_FAST
ANTIALIAS_GOOD
ANTIALIAS_BEST
>;
our enum FontWeight <
FONT_WEIGHT_NORMAL
FONT_WEIGHT_BOLD
>;
our enum FontSlant <
FONT_SLANT_NORMAL
FONT_SLANT_ITALIC
FONT_SLANT_OBLIQUE
>;
our enum Extend <
EXTEND_NONE
EXTEND_REPEAT
EXTEND_REFLECT
CAIRO_EXTEND_PAD
>;
our enum FillRule <
FILL_RULE_WINDING
FILL_RULE_EVEN_ODD
>;
class Matrix {
has cairo_matrix_t $.matrix handles <
xx yx xy yy x0 y0
> .= new: :xx(1e0), :yy(1e0);
multi method init(Num(Cool) :$xx = 1e0, Num(Cool) :$yx = 0e0, Num(Cool) :$xy = 0e0, Num(Cool) :$yy = 1e0, Num(Cool) :$x0 = 0e0, Num(Cool) :$y0 = 0e0) {
$!matrix.init( $xx, $yx, $xy, $yy, $x0, $y0 );
self;
}
multi method init(Num(Cool) $xx, Num(Cool) $yx = 0e0,
Num(Cool) $xy = 0e0, Num(Cool) $yy = 1e0,
Num(Cool) $x0 = 0e0, Num(Cool) $y0 = 0e0) {
$!matrix.init( $xx, $yx, $xy, $yy, $x0, $y0 );
self;
}
method scale(Num(Cool) $sx, Num(Cool) $sy) {
$!matrix.scale($sx, $sy);
self;
}
method translate(Num(Cool) $tx, Num(Cool) $ty) {
$!matrix.translate($tx, $ty);
self;
}
method rotate(Num(Cool) $rad) {
$!matrix.rotate($rad);
self;
}
method invert {
$!matrix.invert;
self;
}
method multiply(Matrix $b) {
my cairo_matrix_t $a-matrix = $!matrix;
$!matrix = cairo_matrix_t.new;
$!matrix.multiply($a-matrix, $b.matrix);
self;
}
}
class Surface {
has cairo_surface_t $.surface handles <reference destroy flush finish show_page>;
method write_png(Str $filename) {
my $result = $!surface.write_to_png($filename);
fail cairo_status_t($result) if $result != STATUS_SUCCESS;
cairo_status_t($result);
}
method Blob(UInt :$size = 64_000 --> Blob) {
my $buf = CArray[uint8].new;
$buf[$size] = 0;
my $closure = StreamClosure.new: :$buf, :buf-len(0), :n-read(0), :$size;
$!surface.write_to_png_stream(&StreamClosure::write, $closure);
return Blob[uint8].new: $buf[0 ..^ $closure.buf-len];
}
method record(&things) {
my $ctx = Context.new(self);
&things($ctx);
$ctx.destroy();
return self;
}
}
class Surface::PDF is Surface {
sub cairo_pdf_surface_create(str $filename, num64 $width, num64 $height)
returns cairo_surface_t
is native($cairolib)
{*}
has Num $.width;
has Num $.height;
multi method create(str $filename, num64 $width, num64 $height) {
return self.new(
surface => cairo_pdf_surface_create($filename, $width, $height),
:$width, :$height,
)
}
multi method create(Str(Cool) $filename, Num(Cool) $width, Num(Cool) $height) {
return self.new(
surface => cairo_pdf_surface_create($filename, $width, $height),
:$width, :$height,
)
}
}
class Surface::SVG is Surface {
sub cairo_svg_surface_create(str $filename, num64 $width, num64 $height)
returns cairo_surface_t
is native($cairolib)
{*}
has Num $.width;
has Num $.height;
multi method create(str $filename, num64 $width, num64 $height) {
return self.new(
surface => cairo_svg_surface_create($filename, $width, $height),
:$width, :$height,
)
}
multi method create(Str(Cool) $filename, Num(Cool) $width, Num(Cool) $height) {
return self.new(
surface => cairo_svg_surface_create($filename, $width, $height),
:$width, :$height,
)
}
}
class RecordingSurface {
sub cairo_recording_surface_create(int32 $content, cairo_rectangle_t $extents)
returns cairo_surface_t
is native($cairolib)
{*}
method new(Content $content = CONTENT_COLOR_ALPHA) {
my cairo_surface_t $surface = cairo_recording_surface_create($content.Int, OpaquePointer);
my RecordingSurface $rsurf = self.bless: :$surface;
$rsurf.reference;
$rsurf;
}
method record(&things, Content :$content = CONTENT_COLOR_ALPHA) {
my Context $ctx .= new(my $surface = self.new($content));
&things($ctx);
$ctx.destroy();
return $surface;
}
}
class Image is Surface {
sub cairo_image_surface_create(int32 $format, int32 $width, int32 $height)
returns cairo_surface_t
is native($cairolib)
{*}
sub cairo_image_surface_create_for_data(Blob[uint8] $data, int32 $format, int32 $width, int32 $height, int32 $stride)
returns cairo_surface_t
is native($cairolib)
{*}
sub cairo_image_surface_create_from_png(Str $filename)
returns cairo_surface_t
is native($cairolib)
{*}
sub cairo_image_surface_create_from_png_stream(
&read-func (StreamClosure, Pointer[uint8], uint32 --> int32),
StreamClosure)
returns cairo_surface_t
is native($cairolib)
{*}
sub cairo_format_stride_for_width(int32 $format, int32 $width)
returns int32
is native($cairolib)
{*}
multi method create(Format $format, Cool $width, Cool $height) {
return self.new(surface => cairo_image_surface_create($format.Int, $width.Int, $height.Int));
}
multi method create(Format $format, Cool $width, Cool $height, Blob[uint8] $data, Cool $stride?) {
if $stride eqv False {
$stride = $width.Int;
} elsif $stride eqv True {
$stride = cairo_format_stride_for_width($format.Int, $width.Int);
}
return self.new(surface => cairo_image_surface_create_for_data($data, $format.Int, $width.Int, $height.Int, $stride));
}
multi method create(Blob[uint8] $data, Int(Cool) $buf-len = $data.elems) {
my $buf = CArray[uint8].new: $data;
my $closure = StreamClosure.new: :$buf, :$buf-len, :n-read(0);
return self.new(surface => cairo_image_surface_create_from_png_stream(&StreamClosure::read, $closure));
}
multi method open(str $filename) {
return self.new(surface => cairo_image_surface_create_from_png($filename));
}
multi method open(Str(Cool) $filename) {
return self.new(surface => cairo_image_surface_create_from_png($filename));
}
method record(&things, Cool $width?, Cool $height?, Format $format = FORMAT_ARGB32) {
if defined $width and defined $height {
my $surface = self.create($format, $width, $height);
my $ctx = Context.new($surface);
&things($ctx);
return $surface;
} else {
die "recording surfaces are currently NYI. please specify a width and height for your Cairo::Image.";
}
}
method data() { $.surface.get_image_data }
method stride() { $.surface.get_image_stride }
method width() { $.surface.get_image_width }
method height() { $.surface.get_image_height }
}
class Pattern::Solid { ... }
class Pattern::Surface { ... }
class Pattern::Gradient { ... }
class Pattern::Gradient::Linear { ... }
class Pattern::Gradient::Radial { ... }
class Pattern {
has cairo_pattern_t $.pattern handles <destroy>;
multi method new(cairo_pattern_t $pattern) {
self.bless(:$pattern)
}
method extend() is rw {