Ticket #1848: 0002-cairo-Rework-cairo_matrix_t-to-use-records.patch

File 0002-cairo-Rework-cairo_matrix_t-to-use-records.patch, 1.7 KB (added by Vasilij Schneidermann, 4 days ago)
  • cairo/0.1.18/cairo.scm

    From 57b605dab42af45c7d16cfeb926714165bc63788 Mon Sep 17 00:00:00 2001
    From: Vasilij Schneidermann <mail@vasilij.de>
    Date: Thu, 2 Jan 2025 19:29:47 +0100
    Subject: [PATCH 2/4] cairo: Rework cairo_matrix_t to use records
    
    ---
     cairo/0.1.18/cairo.scm | 24 ++++++++++++++++++------
     1 file changed, 18 insertions(+), 6 deletions(-)
    
    diff --git a/cairo/0.1.18/cairo.scm b/cairo/0.1.18/cairo.scm
    index 2fe7bf92..6f8ff693 100644
    a b EOF 
    275275
    276276;; Matrix operations
    277277
    278 (define-foreign-type cairo_matrix_t (c-pointer "cairo_matrix_t")
    279   values
    280   (cut tag-pointer <> 'cairo-matrix))
     278(define-foreign-variable sizeof-cairo-matrix int "sizeof(cairo_matrix_t)")
     279
     280;; see cairo-font/text-extents for the construction
     281(define-record cairo-matrix-type buffer)
     282(let ((maker make-cairo-matrix-type))
     283  (set! make-cairo-matrix-type
     284    (lambda () (maker (make-blob sizeof-cairo-matrix)))))
     285
     286(define-foreign-type cairo_matrix_t scheme-pointer cairo-matrix-type-buffer)
    281287
    282288(define (cairo-transform/matrix ctx v)
    283289  (when (not (= (f64vector-length v) 6))
    284290    (error "Vector size mismatch should be 6, is " (f64vector-length v)))
    285   (cairo-transform ctx v))
     291  (let ((matrix (make-cairo-matrix-type)))
     292    (cairo-matrix-init matrix
     293                       (f64vector-ref v 0)
     294                       (f64vector-ref v 1)
     295                       (f64vector-ref v 2)
     296                       (f64vector-ref v 3)
     297                       (f64vector-ref v 4)
     298                       (f64vector-ref v 5))
     299    (cairo-transform ctx matrix)))
    286300
    287 (define cairo-new-matrix
    288   (make-f64vector 6 0))
    289301
    290302; accessors for each element might be nice, but probably not
    291303; immediately necessary