Commitbe39ecd4Recorded12 Mar 2026Repositorysigil-cairo

Add compositing operators, glyph path, and matrix bindings to sigil-cairo

Message

Add the extended Cairo compositing operators (Porter-Duff blend modes): MULTIPLY, SCREEN, OVERLAY, DARKEN, LIGHTEN, COLORDODGE, COLORBURN, HARDLIGHT, SOFTLIGHT, DIFFERENCE, EXCLUSION. These correspond to Cairo operators 14-24 and enable blend mode support in graphics applications built on sigil-cairo.

Add cairo-glyph-path, which adds glyphs to the current path without rendering them. This complements the existing cairo-show-glyphs by enabling text to be used as a clipping region, stroke outline, or gradient fill target — essential for text effects like outlined text and gradient-filled text.

Changed
 src/cairo.sgl | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
Diff
src/cairo.sglmodified
@@ -50,6 +50,17 @@
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
64
65
;; Constants — Line cap/join
66
CAIRO_LINE_CAP_BUTT
@@ -177,6 +188,7 @@
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
@@ -255,6 +267,17 @@
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)
281
282
;; Line cap
283
(define CAIRO_LINE_CAP_BUTT 0)
@@ -1113,6 +1136,28 @@
1136
(%show-glyphs cr buf n)
1137
(c-free buf)))
1138
+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)))
+1160
1161
;;; Create a Cairo font face from a FreeType face.
1162
;;;
1163
;;; Requires Cairo to be built with FreeType support.