AtlatestRepositorysigil-cairo

sigil-cairo / tree / srccairo.sgl

1;;; (cairo) — Cairo 2D graphics bindings for Sigil
2;;;
3;;; Pure-Scheme bindings using the dynamic FFI. No native C code required.
4;;; Requires libcairo.so / libcairo.dylib to be installed on the system.
5
6(define-library (cairo)
7 (import (sigil core)
8 (sigil ffi))
9
10 (export
11 ;; Library handle
12 cairo-lib
14 ;; Constants — Format
15 CAIRO_FORMAT_INVALID
16 CAIRO_FORMAT_ARGB32
17 CAIRO_FORMAT_RGB24
18 CAIRO_FORMAT_A8
19 CAIRO_FORMAT_A1
21 ;; Constants — Status
22 CAIRO_STATUS_SUCCESS
23 CAIRO_STATUS_NO_MEMORY
24 CAIRO_STATUS_INVALID_RESTORE
25 CAIRO_STATUS_INVALID_POP_GROUP
26 CAIRO_STATUS_NO_CURRENT_POINT
27 CAIRO_STATUS_INVALID_MATRIX
28 CAIRO_STATUS_INVALID_STATUS
29 CAIRO_STATUS_NULL_POINTER
30 CAIRO_STATUS_INVALID_STRING
31 CAIRO_STATUS_INVALID_PATH_DATA
32 CAIRO_STATUS_READ_ERROR
33 CAIRO_STATUS_WRITE_ERROR
34 CAIRO_STATUS_SURFACE_FINISHED
35 CAIRO_STATUS_SURFACE_TYPE_MISMATCH
36 CAIRO_STATUS_PATTERN_TYPE_MISMATCH
38 ;; Constants — Operator
39 CAIRO_OPERATOR_CLEAR
40 CAIRO_OPERATOR_SOURCE
41 CAIRO_OPERATOR_OVER
42 CAIRO_OPERATOR_IN
43 CAIRO_OPERATOR_OUT
44 CAIRO_OPERATOR_ATOP
45 CAIRO_OPERATOR_DEST
46 CAIRO_OPERATOR_DEST_OVER
47 CAIRO_OPERATOR_DEST_IN
48 CAIRO_OPERATOR_DEST_OUT
49 CAIRO_OPERATOR_DEST_ATOP
50 CAIRO_OPERATOR_XOR
51 CAIRO_OPERATOR_ADD
52 CAIRO_OPERATOR_SATURATE
53 CAIRO_OPERATOR_MULTIPLY
54 CAIRO_OPERATOR_SCREEN
55 CAIRO_OPERATOR_OVERLAY
56 CAIRO_OPERATOR_DARKEN
57 CAIRO_OPERATOR_LIGHTEN
58 CAIRO_OPERATOR_COLOR_DODGE
59 CAIRO_OPERATOR_COLOR_BURN
60 CAIRO_OPERATOR_HARD_LIGHT
61 CAIRO_OPERATOR_SOFT_LIGHT
62 CAIRO_OPERATOR_DIFFERENCE
63 CAIRO_OPERATOR_EXCLUSION
65 ;; Constants — Line cap/join
66 CAIRO_LINE_CAP_BUTT
67 CAIRO_LINE_CAP_ROUND
68 CAIRO_LINE_CAP_SQUARE
69 CAIRO_LINE_JOIN_MITER
70 CAIRO_LINE_JOIN_ROUND
71 CAIRO_LINE_JOIN_BEVEL
73 ;; Constants — Fill rule
74 CAIRO_FILL_RULE_WINDING
75 CAIRO_FILL_RULE_EVEN_ODD
77 ;; Constants — Antialias
78 CAIRO_ANTIALIAS_DEFAULT
79 CAIRO_ANTIALIAS_NONE
80 CAIRO_ANTIALIAS_GRAY
81 CAIRO_ANTIALIAS_SUBPIXEL
82 CAIRO_ANTIALIAS_FAST
83 CAIRO_ANTIALIAS_GOOD
84 CAIRO_ANTIALIAS_BEST
86 ;; Constants — Font
87 CAIRO_FONT_SLANT_NORMAL
88 CAIRO_FONT_SLANT_ITALIC
89 CAIRO_FONT_SLANT_OBLIQUE
90 CAIRO_FONT_WEIGHT_NORMAL
91 CAIRO_FONT_WEIGHT_BOLD
93 ;; Constants — Extend
94 CAIRO_EXTEND_NONE
95 CAIRO_EXTEND_REPEAT
96 CAIRO_EXTEND_REFLECT
97 CAIRO_EXTEND_PAD
99 ;; Constants — Content
100 CAIRO_CONTENT_COLOR
101 CAIRO_CONTENT_ALPHA
102 CAIRO_CONTENT_COLOR_ALPHA
104 ;; Struct layouts
105 cairo-text-extents-layout
106 cairo-font-extents-layout
107 cairo-matrix-layout
109 ;; Surfaces
110 cairo-image-surface-create
111 cairo-image-surface-create-from-png
112 cairo-surface-destroy
113 cairo-surface-write-to-png
114 cairo-surface-flush
115 cairo-surface-finish
116 cairo-surface-status
117 cairo-surface-create-similar
118 cairo-image-surface-get-width
119 cairo-image-surface-get-height
120 cairo-image-surface-get-stride
121 cairo-image-surface-get-format
122 cairo-image-surface-get-data
123 cairo-pdf-surface-create
124 cairo-svg-surface-create
125 cairo-pdf-surface-set-size
127 ;; Context
128 cairo-create
129 cairo-destroy
130 cairo-save
131 cairo-restore
132 cairo-status
133 cairo-status-to-string
134 cairo-push-group
135 cairo-pop-group
136 cairo-pop-group-to-source
137 cairo-get-target
139 ;; Drawing state
140 cairo-set-source-rgb
141 cairo-set-source-rgba
142 cairo-set-source-surface
143 cairo-set-source
144 cairo-set-line-width
145 cairo-get-line-width
146 cairo-set-line-cap
147 cairo-set-line-join
148 cairo-set-miter-limit
149 cairo-set-dash
150 cairo-set-fill-rule
151 cairo-set-operator
152 cairo-set-antialias
154 ;; Paths
155 cairo-new-path
156 cairo-new-sub-path
157 cairo-close-path
158 cairo-move-to
159 cairo-line-to
160 cairo-curve-to
161 cairo-arc
162 cairo-arc-negative
163 cairo-rectangle
164 cairo-rel-move-to
165 cairo-rel-line-to
166 cairo-rel-curve-to
168 ;; Drawing ops
169 cairo-stroke
170 cairo-fill
171 cairo-paint
172 cairo-stroke-preserve
173 cairo-fill-preserve
174 cairo-paint-with-alpha
175 cairo-clip
176 cairo-clip-preserve
177 cairo-reset-clip
178 cairo-mask
179 cairo-mask-surface
181 ;; Text
182 cairo-select-font-face
183 cairo-set-font-size
184 cairo-show-text
185 cairo-text-extents
186 cairo-font-extents
188 ;; Glyph rendering
189 cairo-glyph-layout
190 cairo-show-glyphs
191 cairo-glyph-path
192 cairo-ft-font-face-create
193 cairo-set-font-face
194 cairo-font-face-destroy
196 ;; Transforms
197 cairo-translate
198 cairo-scale
199 cairo-rotate
200 cairo-identity-matrix
201 cairo-get-matrix
202 cairo-set-matrix
204 ;; Patterns
205 cairo-pattern-create-rgb
206 cairo-pattern-create-rgba
207 cairo-pattern-create-linear
208 cairo-pattern-create-radial
209 cairo-pattern-add-color-stop-rgb
210 cairo-pattern-add-color-stop-rgba
211 cairo-pattern-destroy
212 cairo-pattern-set-extend
213 cairo-pattern-create-for-surface
215 ;; Convenience
216 with-cairo-surface
217 with-cairo-context)
219 (begin
221 ;; ============================================================
222 ;; Library Loading
223 ;; ============================================================
225 (define cairo-lib (c-library "libcairo"))
227 ;; ============================================================
228 ;; Constants
229 ;; ============================================================
231 ;; Format
232 (define CAIRO_FORMAT_INVALID -1)
233 (define CAIRO_FORMAT_ARGB32 0)
234 (define CAIRO_FORMAT_RGB24 1)
235 (define CAIRO_FORMAT_A8 2)
236 (define CAIRO_FORMAT_A1 3)
238 ;; Status
239 (define CAIRO_STATUS_SUCCESS 0)
240 (define CAIRO_STATUS_NO_MEMORY 1)
241 (define CAIRO_STATUS_INVALID_RESTORE 2)
242 (define CAIRO_STATUS_INVALID_POP_GROUP 3)
243 (define CAIRO_STATUS_NO_CURRENT_POINT 4)
244 (define CAIRO_STATUS_INVALID_MATRIX 5)
245 (define CAIRO_STATUS_INVALID_STATUS 6)
246 (define CAIRO_STATUS_NULL_POINTER 7)
247 (define CAIRO_STATUS_INVALID_STRING 8)
248 (define CAIRO_STATUS_INVALID_PATH_DATA 9)
249 (define CAIRO_STATUS_READ_ERROR 10)
250 (define CAIRO_STATUS_WRITE_ERROR 11)
251 (define CAIRO_STATUS_SURFACE_FINISHED 12)
252 (define CAIRO_STATUS_SURFACE_TYPE_MISMATCH 13)
253 (define CAIRO_STATUS_PATTERN_TYPE_MISMATCH 14)
255 ;; Operator
256 (define CAIRO_OPERATOR_CLEAR 0)
257 (define CAIRO_OPERATOR_SOURCE 1)
258 (define CAIRO_OPERATOR_OVER 2)
259 (define CAIRO_OPERATOR_IN 3)
260 (define CAIRO_OPERATOR_OUT 4)
261 (define CAIRO_OPERATOR_ATOP 5)
262 (define CAIRO_OPERATOR_DEST 6)
263 (define CAIRO_OPERATOR_DEST_OVER 7)
264 (define CAIRO_OPERATOR_DEST_IN 8)
265 (define CAIRO_OPERATOR_DEST_OUT 9)
266 (define CAIRO_OPERATOR_DEST_ATOP 10)
267 (define CAIRO_OPERATOR_XOR 11)
268 (define CAIRO_OPERATOR_ADD 12)
269 (define CAIRO_OPERATOR_SATURATE 13)
270 (define CAIRO_OPERATOR_MULTIPLY 14)
271 (define CAIRO_OPERATOR_SCREEN 15)
272 (define CAIRO_OPERATOR_OVERLAY 16)
273 (define CAIRO_OPERATOR_DARKEN 17)
274 (define CAIRO_OPERATOR_LIGHTEN 18)
275 (define CAIRO_OPERATOR_COLOR_DODGE 19)
276 (define CAIRO_OPERATOR_COLOR_BURN 20)
277 (define CAIRO_OPERATOR_HARD_LIGHT 21)
278 (define CAIRO_OPERATOR_SOFT_LIGHT 22)
279 (define CAIRO_OPERATOR_DIFFERENCE 23)
280 (define CAIRO_OPERATOR_EXCLUSION 24)
282 ;; Line cap
283 (define CAIRO_LINE_CAP_BUTT 0)
284 (define CAIRO_LINE_CAP_ROUND 1)
285 (define CAIRO_LINE_CAP_SQUARE 2)
287 ;; Line join
288 (define CAIRO_LINE_JOIN_MITER 0)
289 (define CAIRO_LINE_JOIN_ROUND 1)
290 (define CAIRO_LINE_JOIN_BEVEL 2)
292 ;; Fill rule
293 (define CAIRO_FILL_RULE_WINDING 0)
294 (define CAIRO_FILL_RULE_EVEN_ODD 1)
296 ;; Antialias
297 (define CAIRO_ANTIALIAS_DEFAULT 0)
298 (define CAIRO_ANTIALIAS_NONE 1)
299 (define CAIRO_ANTIALIAS_GRAY 2)
300 (define CAIRO_ANTIALIAS_SUBPIXEL 3)
301 (define CAIRO_ANTIALIAS_FAST 4)
302 (define CAIRO_ANTIALIAS_GOOD 5)
303 (define CAIRO_ANTIALIAS_BEST 6)
305 ;; Font slant/weight
306 (define CAIRO_FONT_SLANT_NORMAL 0)
307 (define CAIRO_FONT_SLANT_ITALIC 1)
308 (define CAIRO_FONT_SLANT_OBLIQUE 2)
309 (define CAIRO_FONT_WEIGHT_NORMAL 0)
310 (define CAIRO_FONT_WEIGHT_BOLD 1)
312 ;; Extend
313 (define CAIRO_EXTEND_NONE 0)
314 (define CAIRO_EXTEND_REPEAT 1)
315 (define CAIRO_EXTEND_REFLECT 2)
316 (define CAIRO_EXTEND_PAD 3)
318 ;; Content
319 (define CAIRO_CONTENT_COLOR #x1000)
320 (define CAIRO_CONTENT_ALPHA #x2000)
321 (define CAIRO_CONTENT_COLOR_ALPHA #x3000)
323 ;; ============================================================
324 ;; Struct Layouts
325 ;; ============================================================
327 (define cairo-text-extents-layout
328 (c-struct-layout
329 x-bearing: ffi/double
330 y-bearing: ffi/double
331 width: ffi/double
332 height: ffi/double
333 x-advance: ffi/double
334 y-advance: ffi/double))
336 (define cairo-font-extents-layout
337 (c-struct-layout
338 ascent: ffi/double
339 descent: ffi/double
340 height: ffi/double
341 max-x-advance: ffi/double
342 max-y-advance: ffi/double))
344 (define cairo-matrix-layout
345 (c-struct-layout
346 xx: ffi/double
347 yx: ffi/double
348 xy: ffi/double
349 yy: ffi/double
350 x0: ffi/double
351 y0: ffi/double))
353 ;; cairo_glyph_t — for glyph-level text rendering
354 (define cairo-glyph-layout
355 (c-struct-layout
356 index: ffi/ulong
357 x: ffi/double
358 y: ffi/double))
360 ;; ============================================================
361 ;; Finalizer Pointers (looked up once)
362 ;; ============================================================
364 (define %cairo-destroy-ptr (c-symbol cairo-lib "cairo_destroy"))
365 (define %surface-destroy-ptr (c-symbol cairo-lib "cairo_surface_destroy"))
366 (define %pattern-destroy-ptr (c-symbol cairo-lib "cairo_pattern_destroy"))
367 (define %font-face-destroy-ptr (c-symbol cairo-lib "cairo_font_face_destroy"))
369 ;; ============================================================
370 ;; Raw Function Bindings
371 ;; ============================================================
373 ;; Surfaces
374 (define %image-surface-create
375 (c-function cairo-lib "cairo_image_surface_create"
376 (list ffi/int ffi/int ffi/int) ffi/pointer))
378 (define %image-surface-create-from-png
379 (c-function cairo-lib "cairo_image_surface_create_from_png"
380 (list ffi/string) ffi/pointer))
382 (define %surface-destroy
383 (c-function cairo-lib "cairo_surface_destroy"
384 (list ffi/pointer) ffi/void))
386 (define %surface-write-to-png
387 (c-function cairo-lib "cairo_surface_write_to_png"
388 (list ffi/pointer ffi/string) ffi/int))
390 (define %surface-flush
391 (c-function cairo-lib "cairo_surface_flush"
392 (list ffi/pointer) ffi/void))
394 (define %surface-finish
395 (c-function cairo-lib "cairo_surface_finish"
396 (list ffi/pointer) ffi/void))
398 (define %surface-status
399 (c-function cairo-lib "cairo_surface_status"
400 (list ffi/pointer) ffi/int))
402 (define %surface-create-similar
403 (c-function cairo-lib "cairo_surface_create_similar"
404 (list ffi/pointer ffi/int ffi/int ffi/int) ffi/pointer))
406 (define %image-surface-get-width
407 (c-function cairo-lib "cairo_image_surface_get_width"
408 (list ffi/pointer) ffi/int))
410 (define %image-surface-get-height
411 (c-function cairo-lib "cairo_image_surface_get_height"
412 (list ffi/pointer) ffi/int))
414 (define %image-surface-get-stride
415 (c-function cairo-lib "cairo_image_surface_get_stride"
416 (list ffi/pointer) ffi/int))
418 (define %image-surface-get-format
419 (c-function cairo-lib "cairo_image_surface_get_format"
420 (list ffi/pointer) ffi/int))
422 (define %image-surface-get-data
423 (c-function cairo-lib "cairo_image_surface_get_data"
424 (list ffi/pointer) ffi/pointer))
426 ;; PDF/SVG surfaces (may not be available on all systems)
427 (define %pdf-surface-create
428 (c-function cairo-lib "cairo_pdf_surface_create"
429 (list ffi/string ffi/double ffi/double) ffi/pointer))
431 (define %svg-surface-create
432 (c-function cairo-lib "cairo_svg_surface_create"
433 (list ffi/string ffi/double ffi/double) ffi/pointer))
435 (define %pdf-surface-set-size
436 (c-function cairo-lib "cairo_pdf_surface_set_size"
437 (list ffi/pointer ffi/double ffi/double) ffi/void))
439 ;; Context
440 (define %cairo-create
441 (c-function cairo-lib "cairo_create"
442 (list ffi/pointer) ffi/pointer))
444 (define %cairo-destroy
445 (c-function cairo-lib "cairo_destroy"
446 (list ffi/pointer) ffi/void))
448 (define %cairo-save
449 (c-function cairo-lib "cairo_save"
450 (list ffi/pointer) ffi/void))
452 (define %cairo-restore
453 (c-function cairo-lib "cairo_restore"
454 (list ffi/pointer) ffi/void))
456 (define %cairo-status
457 (c-function cairo-lib "cairo_status"
458 (list ffi/pointer) ffi/int))
460 (define %cairo-status-to-string
461 (c-function cairo-lib "cairo_status_to_string"
462 (list ffi/int) ffi/string))
464 (define %cairo-push-group
465 (c-function cairo-lib "cairo_push_group"
466 (list ffi/pointer) ffi/void))
468 (define %cairo-pop-group
469 (c-function cairo-lib "cairo_pop_group"
470 (list ffi/pointer) ffi/pointer))
472 (define %cairo-pop-group-to-source
473 (c-function cairo-lib "cairo_pop_group_to_source"
474 (list ffi/pointer) ffi/void))
476 (define %cairo-get-target
477 (c-function cairo-lib "cairo_get_target"
478 (list ffi/pointer) ffi/pointer))
480 ;; Drawing state
481 (define %set-source-rgb
482 (c-function cairo-lib "cairo_set_source_rgb"
483 (list ffi/pointer ffi/double ffi/double ffi/double) ffi/void))
485 (define %set-source-rgba
486 (c-function cairo-lib "cairo_set_source_rgba"
487 (list ffi/pointer ffi/double ffi/double ffi/double ffi/double) ffi/void))
489 (define %set-source-surface
490 (c-function cairo-lib "cairo_set_source_surface"
491 (list ffi/pointer ffi/pointer ffi/double ffi/double) ffi/void))
493 (define %set-source
494 (c-function cairo-lib "cairo_set_source"
495 (list ffi/pointer ffi/pointer) ffi/void))
497 (define %set-line-width
498 (c-function cairo-lib "cairo_set_line_width"
499 (list ffi/pointer ffi/double) ffi/void))
501 (define %get-line-width
502 (c-function cairo-lib "cairo_get_line_width"
503 (list ffi/pointer) ffi/double))
505 (define %set-line-cap
506 (c-function cairo-lib "cairo_set_line_cap"
507 (list ffi/pointer ffi/int) ffi/void))
509 (define %set-line-join
510 (c-function cairo-lib "cairo_set_line_join"
511 (list ffi/pointer ffi/int) ffi/void))
513 (define %set-miter-limit
514 (c-function cairo-lib "cairo_set_miter_limit"
515 (list ffi/pointer ffi/double) ffi/void))
517 (define %set-dash
518 (c-function cairo-lib "cairo_set_dash"
519 (list ffi/pointer ffi/pointer ffi/int ffi/double) ffi/void))
521 (define %set-fill-rule
522 (c-function cairo-lib "cairo_set_fill_rule"
523 (list ffi/pointer ffi/int) ffi/void))
525 (define %set-operator
526 (c-function cairo-lib "cairo_set_operator"
527 (list ffi/pointer ffi/int) ffi/void))
529 (define %set-antialias
530 (c-function cairo-lib "cairo_set_antialias"
531 (list ffi/pointer ffi/int) ffi/void))
533 ;; Paths
534 (define %new-path
535 (c-function cairo-lib "cairo_new_path"
536 (list ffi/pointer) ffi/void))
538 (define %new-sub-path
539 (c-function cairo-lib "cairo_new_sub_path"
540 (list ffi/pointer) ffi/void))
542 (define %close-path
543 (c-function cairo-lib "cairo_close_path"
544 (list ffi/pointer) ffi/void))
546 (define %move-to
547 (c-function cairo-lib "cairo_move_to"
548 (list ffi/pointer ffi/double ffi/double) ffi/void))
550 (define %line-to
551 (c-function cairo-lib "cairo_line_to"
552 (list ffi/pointer ffi/double ffi/double) ffi/void))
554 (define %curve-to
555 (c-function cairo-lib "cairo_curve_to"
556 (list ffi/pointer ffi/double ffi/double ffi/double ffi/double ffi/double ffi/double) ffi/void))
558 (define %arc
559 (c-function cairo-lib "cairo_arc"
560 (list ffi/pointer ffi/double ffi/double ffi/double ffi/double ffi/double) ffi/void))
562 (define %arc-negative
563 (c-function cairo-lib "cairo_arc_negative"
564 (list ffi/pointer ffi/double ffi/double ffi/double ffi/double ffi/double) ffi/void))
566 (define %rectangle
567 (c-function cairo-lib "cairo_rectangle"
568 (list ffi/pointer ffi/double ffi/double ffi/double ffi/double) ffi/void))
570 (define %rel-move-to
571 (c-function cairo-lib "cairo_rel_move_to"
572 (list ffi/pointer ffi/double ffi/double) ffi/void))
574 (define %rel-line-to
575 (c-function cairo-lib "cairo_rel_line_to"
576 (list ffi/pointer ffi/double ffi/double) ffi/void))
578 (define %rel-curve-to
579 (c-function cairo-lib "cairo_rel_curve_to"
580 (list ffi/pointer ffi/double ffi/double ffi/double ffi/double ffi/double ffi/double) ffi/void))
582 ;; Drawing ops
583 (define %stroke
584 (c-function cairo-lib "cairo_stroke"
585 (list ffi/pointer) ffi/void))
587 (define %fill
588 (c-function cairo-lib "cairo_fill"
589 (list ffi/pointer) ffi/void))
591 (define %paint
592 (c-function cairo-lib "cairo_paint"
593 (list ffi/pointer) ffi/void))
595 (define %stroke-preserve
596 (c-function cairo-lib "cairo_stroke_preserve"
597 (list ffi/pointer) ffi/void))
599 (define %fill-preserve
600 (c-function cairo-lib "cairo_fill_preserve"
601 (list ffi/pointer) ffi/void))
603 (define %paint-with-alpha
604 (c-function cairo-lib "cairo_paint_with_alpha"
605 (list ffi/pointer ffi/double) ffi/void))
607 (define %clip
608 (c-function cairo-lib "cairo_clip"
609 (list ffi/pointer) ffi/void))
611 (define %clip-preserve
612 (c-function cairo-lib "cairo_clip_preserve"
613 (list ffi/pointer) ffi/void))
615 (define %reset-clip
616 (c-function cairo-lib "cairo_reset_clip"
617 (list ffi/pointer) ffi/void))
619 (define %mask
620 (c-function cairo-lib "cairo_mask"
621 (list ffi/pointer ffi/pointer) ffi/void))
623 (define %mask-surface
624 (c-function cairo-lib "cairo_mask_surface"
625 (list ffi/pointer ffi/pointer ffi/double ffi/double) ffi/void))
627 ;; Text
628 (define %select-font-face
629 (c-function cairo-lib "cairo_select_font_face"
630 (list ffi/pointer ffi/string ffi/int ffi/int) ffi/void))
632 (define %set-font-size
633 (c-function cairo-lib "cairo_set_font_size"
634 (list ffi/pointer ffi/double) ffi/void))
636 (define %show-text
637 (c-function cairo-lib "cairo_show_text"
638 (list ffi/pointer ffi/string) ffi/void))
640 (define %text-extents
641 (c-function cairo-lib "cairo_text_extents"
642 (list ffi/pointer ffi/string ffi/pointer) ffi/void))
644 (define %font-extents
645 (c-function cairo-lib "cairo_font_extents"
646 (list ffi/pointer ffi/pointer) ffi/void))
648 ;; Glyph rendering
649 (define %show-glyphs
650 (c-function cairo-lib "cairo_show_glyphs"
651 (list ffi/pointer ffi/pointer ffi/int) ffi/void))
653 (define %set-font-face
654 (c-function cairo-lib "cairo_set_font_face"
655 (list ffi/pointer ffi/pointer) ffi/void))
657 (define %font-face-destroy
658 (c-function cairo-lib "cairo_font_face_destroy"
659 (list ffi/pointer) ffi/void))
661 (define %ft-font-face-create
662 (c-function cairo-lib "cairo_ft_font_face_create_for_ft_face"
663 (list ffi/pointer ffi/int) ffi/pointer))
665 ;; Transforms
666 (define %translate
667 (c-function cairo-lib "cairo_translate"
668 (list ffi/pointer ffi/double ffi/double) ffi/void))
670 (define %scale
671 (c-function cairo-lib "cairo_scale"
672 (list ffi/pointer ffi/double ffi/double) ffi/void))
674 (define %rotate
675 (c-function cairo-lib "cairo_rotate"
676 (list ffi/pointer ffi/double) ffi/void))
678 (define %identity-matrix
679 (c-function cairo-lib "cairo_identity_matrix"
680 (list ffi/pointer) ffi/void))
682 (define %get-matrix
683 (c-function cairo-lib "cairo_get_matrix"
684 (list ffi/pointer ffi/pointer) ffi/void))
686 (define %set-matrix
687 (c-function cairo-lib "cairo_set_matrix"
688 (list ffi/pointer ffi/pointer) ffi/void))
690 ;; Patterns
691 (define %pattern-create-rgb
692 (c-function cairo-lib "cairo_pattern_create_rgb"
693 (list ffi/double ffi/double ffi/double) ffi/pointer))
695 (define %pattern-create-rgba
696 (c-function cairo-lib "cairo_pattern_create_rgba"
697 (list ffi/double ffi/double ffi/double ffi/double) ffi/pointer))
699 (define %pattern-create-linear
700 (c-function cairo-lib "cairo_pattern_create_linear"
701 (list ffi/double ffi/double ffi/double ffi/double) ffi/pointer))
703 (define %pattern-create-radial
704 (c-function cairo-lib "cairo_pattern_create_radial"
705 (list ffi/double ffi/double ffi/double ffi/double ffi/double ffi/double) ffi/pointer))
707 (define %pattern-add-color-stop-rgb
708 (c-function cairo-lib "cairo_pattern_add_color_stop_rgb"
709 (list ffi/pointer ffi/double ffi/double ffi/double ffi/double) ffi/void))
711 (define %pattern-add-color-stop-rgba
712 (c-function cairo-lib "cairo_pattern_add_color_stop_rgba"
713 (list ffi/pointer ffi/double ffi/double ffi/double ffi/double ffi/double) ffi/void))
715 (define %pattern-destroy
716 (c-function cairo-lib "cairo_pattern_destroy"
717 (list ffi/pointer) ffi/void))
719 (define %pattern-set-extend
720 (c-function cairo-lib "cairo_pattern_set_extend"
721 (list ffi/pointer ffi/int) ffi/void))
723 (define %pattern-create-for-surface
724 (c-function cairo-lib "cairo_pattern_create_for_surface"
725 (list ffi/pointer) ffi/pointer))
727 ;; ============================================================
728 ;; Public API — Surfaces
729 ;; ============================================================
731 ;;; Create an image surface with the given format and dimensions.
732 (define (cairo-image-surface-create format width height)
733 (: integer? integer? integer? -> pointer?)
734 (let ((surface (%image-surface-create format width height)))
735 (set-pointer-finalizer! surface %surface-destroy-ptr)
736 surface))
738 ;;; Create an image surface from a PNG file.
739 (define (cairo-image-surface-create-from-png filename)
740 (: string? -> pointer?)
741 (let ((surface (%image-surface-create-from-png filename)))
742 (set-pointer-finalizer! surface %surface-destroy-ptr)
743 surface))
745 ;;; Destroy a surface, freeing its resources.
746 (define (cairo-surface-destroy surface)
747 (: pointer? -> void?)
748 (set-pointer-finalizer! surface #f)
749 (%surface-destroy surface))
751 ;;; Write surface contents to a PNG file.
752 (define (cairo-surface-write-to-png surface filename)
753 (: pointer? string? -> integer?)
754 (%surface-write-to-png surface filename))
756 ;;; Flush pending drawing operations to the surface.
757 (define (cairo-surface-flush surface)
758 (: pointer? -> void?)
759 (%surface-flush surface))
761 ;;; Finish the surface, preventing further drawing.
762 (define (cairo-surface-finish surface)
763 (: pointer? -> void?)
764 (%surface-finish surface))
766 ;;; Get the status of a surface.
767 (define (cairo-surface-status surface)
768 (: pointer? -> integer?)
769 (%surface-status surface))
771 ;;; Create a new surface similar to an existing one.
772 (define (cairo-surface-create-similar surface content width height)
773 (: pointer? integer? integer? integer? -> pointer?)
774 (let ((s (%surface-create-similar surface content width height)))
775 (set-pointer-finalizer! s %surface-destroy-ptr)
776 s))
778 ;;; Get the width of an image surface in pixels.
779 (define (cairo-image-surface-get-width surface)
780 (: pointer? -> integer?)
781 (%image-surface-get-width surface))
783 ;;; Get the height of an image surface in pixels.
784 (define (cairo-image-surface-get-height surface)
785 (: pointer? -> integer?)
786 (%image-surface-get-height surface))
788 ;;; Get the stride of an image surface in bytes.
789 (define (cairo-image-surface-get-stride surface)
790 (: pointer? -> integer?)
791 (%image-surface-get-stride surface))
793 ;;; Get the pixel format of an image surface.
794 (define (cairo-image-surface-get-format surface)
795 (: pointer? -> integer?)
796 (%image-surface-get-format surface))
798 ;;; Get a pointer to the raw pixel data of an image surface.
799 (define (cairo-image-surface-get-data surface)
800 (: pointer? -> pointer?)
801 (%image-surface-get-data surface))
803 ;;; Create a PDF surface that writes to a file.
804 (define (cairo-pdf-surface-create filename width-pts height-pts)
805 (: string? number? number? -> pointer?)
806 (let ((surface (%pdf-surface-create filename width-pts height-pts)))
807 (set-pointer-finalizer! surface %surface-destroy-ptr)
808 surface))
810 ;;; Create an SVG surface that writes to a file.
811 (define (cairo-svg-surface-create filename width-pts height-pts)
812 (: string? number? number? -> pointer?)
813 (let ((surface (%svg-surface-create filename width-pts height-pts)))
814 (set-pointer-finalizer! surface %surface-destroy-ptr)
815 surface))
817 ;;; Set the size of a PDF surface page in points.
818 (define (cairo-pdf-surface-set-size surface width-pts height-pts)
819 (: pointer? number? number? -> void?)
820 (%pdf-surface-set-size surface width-pts height-pts))
822 ;; ============================================================
823 ;; Public API — Context
824 ;; ============================================================
826 ;;; Create a new drawing context for a surface.
827 (define (cairo-create surface)
828 (: pointer? -> pointer?)
829 (let ((cr (%cairo-create surface)))
830 (set-pointer-finalizer! cr %cairo-destroy-ptr)
831 cr))
833 ;;; Destroy a drawing context.
834 (define (cairo-destroy cr)
835 (: pointer? -> void?)
836 (set-pointer-finalizer! cr #f)
837 (%cairo-destroy cr))
839 ;;; Save the current drawing state.
840 (define (cairo-save cr)
841 (: pointer? -> void?)
842 (%cairo-save cr))
844 ;;; Restore a previously saved drawing state.
845 (define (cairo-restore cr)
846 (: pointer? -> void?)
847 (%cairo-restore cr))
849 ;;; Get the status of a drawing context.
850 (define (cairo-status cr)
851 (: pointer? -> integer?)
852 (%cairo-status cr))
854 ;;; Convert a status code to a human-readable string.
855 (define (cairo-status-to-string status)
856 (: integer? -> string?)
857 (%cairo-status-to-string status))
859 ;;; Push a temporary group for compositing.
860 (define (cairo-push-group cr)
861 (: pointer? -> void?)
862 (%cairo-push-group cr))
864 ;;; Pop a group and return as a pattern.
865 (define (cairo-pop-group cr)
866 (: pointer? -> pointer?)
867 (let ((pat (%cairo-pop-group cr)))
868 (set-pointer-finalizer! pat %pattern-destroy-ptr)
869 pat))
871 ;;; Pop a group and set it as the source.
872 (define (cairo-pop-group-to-source cr)
873 (: pointer? -> void?)
874 (%cairo-pop-group-to-source cr))
876 ;;; Get the target surface for a context.
877 (define (cairo-get-target cr)
878 (: pointer? -> pointer?)
879 (%cairo-get-target cr))
881 ;; ============================================================
882 ;; Public API — Drawing State
883 ;; ============================================================
885 ;;; Set the source color as RGB (each component 0.0 to 1.0).
886 (define (cairo-set-source-rgb cr r g b)
887 (: pointer? number? number? number? -> void?)
888 (%set-source-rgb cr r g b))
890 ;;; Set the source color as RGBA (each component 0.0 to 1.0).
891 (define (cairo-set-source-rgba cr r g b a)
892 (: pointer? number? number? number? number? -> void?)
893 (%set-source-rgba cr r g b a))
895 ;;; Set a surface as the source pattern with origin offset.
896 (define (cairo-set-source-surface cr surface x y)
897 (: pointer? pointer? number? number? -> void?)
898 (%set-source-surface cr surface x y))
900 ;;; Set a pattern as the source.
901 (define (cairo-set-source cr pattern)
902 (: pointer? pointer? -> void?)
903 (%set-source cr pattern))
905 ;;; Set the line width for stroking.
906 (define (cairo-set-line-width cr width)
907 (: pointer? number? -> void?)
908 (%set-line-width cr width))
910 ;;; Get the current line width.
911 (define (cairo-get-line-width cr)
912 (: pointer? -> number?)
913 (%get-line-width cr))
915 ;;; Set the line cap style.
916 (define (cairo-set-line-cap cr cap)
917 (: pointer? integer? -> void?)
918 (%set-line-cap cr cap))
920 ;;; Set the line join style.
921 (define (cairo-set-line-join cr join)
922 (: pointer? integer? -> void?)
923 (%set-line-join cr join))
925 ;;; Set the miter limit for line joins.
926 (define (cairo-set-miter-limit cr limit)
927 (: pointer? number? -> void?)
928 (%set-miter-limit cr limit))
930 ;;; Set the dash pattern from a list of doubles.
931 (define (cairo-set-dash cr dashes offset)
932 (: pointer? list? number? -> void?)
933 (let* ((n (length dashes))
934 (buf (c-alloc (* n 8))))
935 (let loop ((i 0) (ds dashes))
936 (when (pair? ds)
937 (pointer-set! buf ffi/double (* i 8) (car ds))
938 (loop (+ i 1) (cdr ds))))
939 (%set-dash cr buf n offset)
940 (c-free buf)))
942 ;;; Set the fill rule.
943 (define (cairo-set-fill-rule cr rule)
944 (: pointer? integer? -> void?)
945 (%set-fill-rule cr rule))
947 ;;; Set the compositing operator.
948 (define (cairo-set-operator cr op)
949 (: pointer? integer? -> void?)
950 (%set-operator cr op))
952 ;;; Set the antialiasing mode.
953 (define (cairo-set-antialias cr antialias)
954 (: pointer? integer? -> void?)
955 (%set-antialias cr antialias))
957 ;; ============================================================
958 ;; Public API — Paths
959 ;; ============================================================
961 ;;; Clear the current path.
962 (define (cairo-new-path cr)
963 (: pointer? -> void?)
964 (%new-path cr))
966 ;;; Start a new sub-path.
967 (define (cairo-new-sub-path cr)
968 (: pointer? -> void?)
969 (%new-sub-path cr))
971 ;;; Close the current sub-path.
972 (define (cairo-close-path cr)
973 (: pointer? -> void?)
974 (%close-path cr))
976 ;;; Move to a point without drawing.
977 (define (cairo-move-to cr x y)
978 (: pointer? number? number? -> void?)
979 (%move-to cr x y))
981 ;;; Draw a line from the current point.
982 (define (cairo-line-to cr x y)
983 (: pointer? number? number? -> void?)
984 (%line-to cr x y))
986 ;;; Draw a cubic Bezier curve.
987 (define (cairo-curve-to cr x1 y1 x2 y2 x3 y3)
988 (: pointer? number? number? number? number? number? number? -> void?)
989 (%curve-to cr x1 y1 x2 y2 x3 y3))
991 ;;; Draw a circular arc.
992 (define (cairo-arc cr xc yc radius angle1 angle2)
993 (: pointer? number? number? number? number? number? -> void?)
994 (%arc cr xc yc radius angle1 angle2))
996 ;;; Draw a circular arc in the negative direction.
997 (define (cairo-arc-negative cr xc yc radius angle1 angle2)
998 (: pointer? number? number? number? number? number? -> void?)
999 (%arc-negative cr xc yc radius angle1 angle2))
1001 ;;; Add a rectangle sub-path.
1002 (define (cairo-rectangle cr x y width height)
1003 (: pointer? number? number? number? number? -> void?)
1004 (%rectangle cr x y width height))
1006 ;;; Move by a relative offset.
1007 (define (cairo-rel-move-to cr dx dy)
1008 (: pointer? number? number? -> void?)
1009 (%rel-move-to cr dx dy))
1011 ;;; Draw a line by a relative offset.
1012 (define (cairo-rel-line-to cr dx dy)
1013 (: pointer? number? number? -> void?)
1014 (%rel-line-to cr dx dy))
1016 ;;; Draw a curve by relative offsets.
1017 (define (cairo-rel-curve-to cr dx1 dy1 dx2 dy2 dx3 dy3)
1018 (: pointer? number? number? number? number? number? number? -> void?)
1019 (%rel-curve-to cr dx1 dy1 dx2 dy2 dx3 dy3))
1021 ;; ============================================================
1022 ;; Public API — Drawing Operations
1023 ;; ============================================================
1025 ;;; Stroke the current path.
1026 (define (cairo-stroke cr)
1027 (: pointer? -> void?)
1028 (%stroke cr))
1030 ;;; Fill the current path.
1031 (define (cairo-fill cr)
1032 (: pointer? -> void?)
1033 (%fill cr))
1035 ;;; Paint the entire surface with the source.
1036 (define (cairo-paint cr)
1037 (: pointer? -> void?)
1038 (%paint cr))
1040 ;;; Stroke the current path, preserving it.
1041 (define (cairo-stroke-preserve cr)
1042 (: pointer? -> void?)
1043 (%stroke-preserve cr))
1045 ;;; Fill the current path, preserving it.
1046 (define (cairo-fill-preserve cr)
1047 (: pointer? -> void?)
1048 (%fill-preserve cr))
1050 ;;; Paint with a given alpha transparency.
1051 (define (cairo-paint-with-alpha cr alpha)
1052 (: pointer? number? -> void?)
1053 (%paint-with-alpha cr alpha))
1055 ;;; Set the clip region to the current path.
1056 (define (cairo-clip cr)
1057 (: pointer? -> void?)
1058 (%clip cr))
1060 ;;; Set the clip region, preserving the path.
1061 (define (cairo-clip-preserve cr)
1062 (: pointer? -> void?)
1063 (%clip-preserve cr))
1065 ;;; Reset the clip region to the entire surface.
1066 (define (cairo-reset-clip cr)
1067 (: pointer? -> void?)
1068 (%reset-clip cr))
1070 ;;; Mask with a pattern (paint where pattern has alpha).
1071 (define (cairo-mask cr pattern)
1072 (: pointer? pointer? -> void?)
1073 (%mask cr pattern))
1075 ;;; Mask with a surface at the given offset.
1076 (define (cairo-mask-surface cr surface x y)
1077 (: pointer? pointer? number? number? -> void?)
1078 (%mask-surface cr surface x y))
1080 ;; ============================================================
1081 ;; Public API — Text
1082 ;; ============================================================
1084 ;;; Select a font by family, slant, and weight.
1085 (define (cairo-select-font-face cr family slant weight)
1086 (: pointer? string? integer? integer? -> void?)
1087 (%select-font-face cr family slant weight))
1089 ;;; Set the font size.
1090 (define (cairo-set-font-size cr size)
1091 (: pointer? number? -> void?)
1092 (%set-font-size cr size))
1094 ;;; Show text at the current position.
1095 (define (cairo-show-text cr text)
1096 (: pointer? string? -> void?)
1097 (%show-text cr text))
1099 ;;; Get text extents as a dict with keys: x-bearing, y-bearing, width, height, x-advance, y-advance.
1100 (define (cairo-text-extents cr text)
1101 (: pointer? string? -> any?)
1102 (with-c-alloc cairo-text-extents-layout
1103 (lambda (extents)
1104 (%text-extents cr text extents)
1105 (c-struct->dict extents cairo-text-extents-layout))))
1107 ;;; Get font extents as a dict with keys: ascent, descent, height, max-x-advance, max-y-advance.
1108 (define (cairo-font-extents cr)
1109 (: pointer? -> any?)
1110 (with-c-alloc cairo-font-extents-layout
1111 (lambda (extents)
1112 (%font-extents cr extents)
1113 (c-struct->dict extents cairo-font-extents-layout))))
1115 ;; ============================================================
1116 ;; Public API — Glyph Rendering
1117 ;; ============================================================
1119 ;;; Render glyphs at specified positions on a Cairo context.
1120 ;;;
1121 ;;; GLYPHS is a list of dicts with keys: index: (glyph index),
1122 ;;; x: (x position), y: (y position).
1123 (define (cairo-show-glyphs cr glyphs)
1124 (: pointer? list? -> void?)
1125 (let* ((n (length glyphs))
1126 (glyph-size (c-struct-size cairo-glyph-layout))
1127 (buf (c-alloc (* n glyph-size))))
1128 (let loop ((i 0) (gs glyphs))
1129 (when (pair? gs)
1130 (let ((g (car gs))
1131 (ptr (pointer+ buf (* i glyph-size))))
1132 (c-struct-set! ptr cairo-glyph-layout index: (dict-ref g index:))
1133 (c-struct-set! ptr cairo-glyph-layout x: (dict-ref g x:))
1134 (c-struct-set! ptr cairo-glyph-layout y: (dict-ref g y:))
1135 (loop (+ i 1) (cdr gs)))))
1136 (%show-glyphs cr buf n)
1137 (c-free buf)))
1139 ;;; Add glyphs to the current path without rendering.
1140 ;;;
1141 ;;; GLYPHS is a list of dicts with keys: index: (glyph index),
1142 ;;; x: (x position), y: (y position).
1143 (define (cairo-glyph-path cr glyphs)
1144 (: pointer? list? -> void?)
1145 (let* ((gp (c-function cairo-lib "cairo_glyph_path"
1146 (list ffi/pointer ffi/pointer ffi/int) ffi/void))
1147 (n (length glyphs))
1148 (glyph-size (c-struct-size cairo-glyph-layout))
1149 (buf (c-alloc (* n glyph-size))))
1150 (let loop ((i 0) (gs glyphs))
1151 (when (pair? gs)
1152 (let ((g (car gs))
1153 (ptr (pointer+ buf (* i glyph-size))))
1154 (c-struct-set! ptr cairo-glyph-layout index: (dict-ref g index:))
1155 (c-struct-set! ptr cairo-glyph-layout x: (dict-ref g x:))
1156 (c-struct-set! ptr cairo-glyph-layout y: (dict-ref g y:))
1157 (loop (+ i 1) (cdr gs)))))
1158 (gp cr buf n)
1159 (c-free buf)))
1161 ;;; Create a Cairo font face from a FreeType face.
1162 ;;;
1163 ;;; Requires Cairo to be built with FreeType support.
1164 (define (cairo-ft-font-face-create ft-face load-flags)
1165 (: pointer? integer? -> pointer?)
1166 (let ((face (%ft-font-face-create ft-face load-flags)))
1167 (set-pointer-finalizer! face %font-face-destroy-ptr)
1168 face))
1170 ;;; Set the font face for a Cairo context.
1171 (define (cairo-set-font-face cr face)
1172 (: pointer? pointer? -> void?)
1173 (%set-font-face cr face))
1175 ;;; Destroy a Cairo font face.
1176 (define (cairo-font-face-destroy face)
1177 (: pointer? -> void?)
1178 (set-pointer-finalizer! face #f)
1179 (%font-face-destroy face))
1181 ;; ============================================================
1182 ;; Public API — Transforms
1183 ;; ============================================================
1185 ;;; Translate the coordinate origin.
1186 (define (cairo-translate cr tx ty)
1187 (: pointer? number? number? -> void?)
1188 (%translate cr tx ty))
1190 ;;; Scale the coordinate system.
1191 (define (cairo-scale cr sx sy)
1192 (: pointer? number? number? -> void?)
1193 (%scale cr sx sy))
1195 ;;; Rotate the coordinate system by angle in radians.
1196 (define (cairo-rotate cr angle)
1197 (: pointer? number? -> void?)
1198 (%rotate cr angle))
1200 ;;; Reset the transformation matrix to identity.
1201 (define (cairo-identity-matrix cr)
1202 (: pointer? -> void?)
1203 (%identity-matrix cr))
1205 ;;; Get the current transformation matrix.
1206 ;;; Returns a dict with xx: yx: xy: yy: x0: y0: fields.
1207 (define (cairo-get-matrix cr)
1208 (: pointer? -> dict?)
1209 (let* ((matrix-size (c-struct-size cairo-matrix-layout))
1210 (buf (c-alloc matrix-size)))
1211 (%get-matrix cr buf)
1212 (let ((result (dict xx: (c-struct-ref buf cairo-matrix-layout xx:)
1213 yx: (c-struct-ref buf cairo-matrix-layout yx:)
1214 xy: (c-struct-ref buf cairo-matrix-layout xy:)
1215 yy: (c-struct-ref buf cairo-matrix-layout yy:)
1216 x0: (c-struct-ref buf cairo-matrix-layout x0:)
1217 y0: (c-struct-ref buf cairo-matrix-layout y0:))))
1218 (c-free buf)
1219 result)))
1221 ;;; Set the transformation matrix from a dict with xx: yx: xy: yy: x0: y0:.
1222 (define (cairo-set-matrix cr matrix)
1223 (: pointer? dict? -> void?)
1224 (let* ((matrix-size (c-struct-size cairo-matrix-layout))
1225 (buf (c-alloc matrix-size)))
1226 (c-struct-set! buf cairo-matrix-layout xx: (dict-ref matrix xx:))
1227 (c-struct-set! buf cairo-matrix-layout yx: (dict-ref matrix yx:))
1228 (c-struct-set! buf cairo-matrix-layout xy: (dict-ref matrix xy:))
1229 (c-struct-set! buf cairo-matrix-layout yy: (dict-ref matrix yy:))
1230 (c-struct-set! buf cairo-matrix-layout x0: (dict-ref matrix x0:))
1231 (c-struct-set! buf cairo-matrix-layout y0: (dict-ref matrix y0:))
1232 (%set-matrix cr buf)
1233 (c-free buf)))
1235 ;; ============================================================
1236 ;; Public API — Patterns
1237 ;; ============================================================
1239 ;;; Create a solid RGB pattern.
1240 (define (cairo-pattern-create-rgb r g b)
1241 (: number? number? number? -> pointer?)
1242 (let ((pat (%pattern-create-rgb r g b)))
1243 (set-pointer-finalizer! pat %pattern-destroy-ptr)
1244 pat))
1246 ;;; Create a solid RGBA pattern.
1247 (define (cairo-pattern-create-rgba r g b a)
1248 (: number? number? number? number? -> pointer?)
1249 (let ((pat (%pattern-create-rgba r g b a)))
1250 (set-pointer-finalizer! pat %pattern-destroy-ptr)
1251 pat))
1253 ;;; Create a linear gradient pattern between two points.
1254 (define (cairo-pattern-create-linear x0 y0 x1 y1)
1255 (: number? number? number? number? -> pointer?)
1256 (let ((pat (%pattern-create-linear x0 y0 x1 y1)))
1257 (set-pointer-finalizer! pat %pattern-destroy-ptr)
1258 pat))
1260 ;;; Create a radial gradient pattern between two circles.
1261 (define (cairo-pattern-create-radial cx0 cy0 r0 cx1 cy1 r1)
1262 (: number? number? number? number? number? number? -> pointer?)
1263 (let ((pat (%pattern-create-radial cx0 cy0 r0 cx1 cy1 r1)))
1264 (set-pointer-finalizer! pat %pattern-destroy-ptr)
1265 pat))
1267 ;;; Add an RGB color stop to a gradient pattern.
1268 (define (cairo-pattern-add-color-stop-rgb pattern offset r g b)
1269 (: pointer? number? number? number? number? -> void?)
1270 (%pattern-add-color-stop-rgb pattern offset r g b))
1272 ;;; Add an RGBA color stop to a gradient pattern.
1273 (define (cairo-pattern-add-color-stop-rgba pattern offset r g b a)
1274 (: pointer? number? number? number? number? number? -> void?)
1275 (%pattern-add-color-stop-rgba pattern offset r g b a))
1277 ;;; Destroy a pattern.
1278 (define (cairo-pattern-destroy pattern)
1279 (: pointer? -> void?)
1280 (set-pointer-finalizer! pattern #f)
1281 (%pattern-destroy pattern))
1283 ;;; Set the extend mode for a pattern.
1284 (define (cairo-pattern-set-extend pattern extend)
1285 (: pointer? integer? -> void?)
1286 (%pattern-set-extend pattern extend))
1288 ;;; Create a pattern from a surface.
1289 (define (cairo-pattern-create-for-surface surface)
1290 (: pointer? -> pointer?)
1291 (let ((pat (%pattern-create-for-surface surface)))
1292 (set-pointer-finalizer! pat %pattern-destroy-ptr)
1293 pat))
1295 ;; ============================================================
1296 ;; Convenience
1297 ;; ============================================================
1299 ;;; Create a surface, call proc with it, then destroy it.
1300 (define (with-cairo-surface surface proc)
1301 (: pointer? procedure? -> any?)
1302 (let ((result (proc surface)))
1303 (cairo-surface-destroy surface)
1304 result))
1306 ;;; Create a context for a surface, call proc with it, then destroy it.
1307 (define (with-cairo-context surface proc)
1308 (: pointer? procedure? -> any?)
1309 (let* ((cr (cairo-create surface))
1310 (result (proc cr)))
1311 (cairo-destroy cr)
1312 result))))