1ed0a2c5 |
1 | ;; Common Lisp bindings for Cairo |
2 | ;; Copyright 2005 Espen S. Johnsen <espen@users.sf.net> |
3 | ;; |
4 | ;; Permission is hereby granted, free of charge, to any person obtaining |
5 | ;; a copy of this software and associated documentation files (the |
6 | ;; "Software"), to deal in the Software without restriction, including |
7 | ;; without limitation the rights to use, copy, modify, merge, publish, |
8 | ;; distribute, sublicense, and/or sell copies of the Software, and to |
9 | ;; permit persons to whom the Software is furnished to do so, subject to |
10 | ;; the following conditions: |
11 | ;; |
12 | ;; The above copyright notice and this permission notice shall be |
13 | ;; included in all copies or substantial portions of the Software. |
14 | ;; |
15 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
16 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
17 | ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
18 | ;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
19 | ;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
20 | ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
21 | ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | |
af338f4a |
23 | ;; $Id: cairo.lisp,v 1.9 2007-01-12 10:32:43 espen Exp $ |
1ed0a2c5 |
24 | |
25 | (in-package "CAIRO") |
26 | |
27 | (eval-when (:compile-toplevel :load-toplevel :execute) |
28 | (define-enum-type surface-format :argb32 :rgb24 :a8 :a1) |
81240b33 |
29 | #?(pkg-exists-p "cairo" :atleast-version "1.2") |
30 | (define-enum-type content :color :alpha :color-alpha) |
31 | #?(pkg-exists-p "cairo" :atleast-version "1.2") |
32 | (define-enum-type surface-type |
33 | :image :pdf :ps :xlib :xcb :glitz :quartz :win32 :beos :directfb |
34 | :svg :nquartz :os2) |
35 | |
1ed0a2c5 |
36 | |
37 | (define-enum-type status |
38 | :success :no-memory :invalid-restore :invalid-pop-group |
39 | :no-current-point :invalid-matrix :invalid-status :null-pointer |
40 | :invalid-string :invalid-path-data :read-error :write-error |
41 | :surface-finished :surface-type-mismatch :pattern-type-mismatch |
42 | :invalid-content :invalid-format :invalid-visual :file-not-found |
43 | :invalid-dash) |
44 | |
45 | (define-enum-type fill-rule :winding :even-odd) |
46 | (define-enum-type line-cap :butt :round :square) |
47 | (define-enum-type line-join :miter :round :bevel) |
48 | (define-enum-type font-slant :normal :itaic :oblique) |
49 | (define-enum-type font-weight :normal :bold) |
50 | |
51 | (define-enum-type operator |
52 | :clear :source :over :in :out :atop :dest :dest-over |
53 | :dest-in :dest-out :dest-atop :xor :add :saturate) |
54 | |
55 | (define-enum-type antialias :default :none :gray :subpixel) |
56 | (define-enum-type extend :none :repeat :reflect) |
57 | (define-enum-type filter :fast :good :best :nearest :bilinear :gaussian) |
58 | (define-enum-type subpixel-order :default :rgb :bgr :vrgb :vbgr) |
59 | (define-enum-type hint-style :default :none :slight :medium :full) |
60 | (define-enum-type hint-metrics :default :off :on) |
61 | |
c7d11ab8 |
62 | (defclass glyph (struct) |
1ed0a2c5 |
63 | ((index |
64 | :allocation :alien |
65 | :initarg :index |
66 | :accessor glyph-index |
67 | :type unsigned-long) |
68 | (x |
69 | :allocation :alien |
70 | :initarg :x |
71 | :accessor glyph-x |
72 | :type double-float) |
73 | (y |
74 | :allocation :alien |
75 | :initarg :y |
76 | :accessor glyph-y |
77 | :type double-float)) |
78 | (:metaclass struct-class)) |
79 | |
af338f4a |
80 | (defclass font-face (ref-counted-object) |
1ed0a2c5 |
81 | () |
a82cea45 |
82 | (:metaclass proxy-class) |
83 | (:ref %font-face-reference) |
84 | (:unref %font-face-destroy)) |
1ed0a2c5 |
85 | |
af338f4a |
86 | (defclass font-options (ref-counted-object) |
1ed0a2c5 |
87 | ((antialias |
88 | :allocation :virtual |
89 | :getter "font_options_get_antialias" |
90 | :setter "font_options_set_antialias" |
91 | :accessor font-options-antialias |
92 | :type antialias) |
93 | (subpixel-order |
94 | :allocation :virtual |
95 | :getter "font_options_get_subpixel_order" |
96 | :setter "font_options_set_subpixel_order" |
97 | :accessor font-options-subpixel-order |
98 | :type subpixel-order) |
99 | (hint-style |
100 | :allocation :virtual |
101 | :getter "font_options_get_hint_style" |
102 | :setter "font_options_set_hint_style" |
103 | :accessor font-options-hint-style |
104 | :type hint-style) |
105 | (hint-metrics |
106 | :allocation :virtual |
107 | :getter "font_options_get_hint_metrics" |
108 | :setter "font_options_set_hint_metrics" |
109 | :accessor font-options-hint-metrics |
110 | :type hint-metrics)) |
a82cea45 |
111 | (:metaclass proxy-class) |
112 | (:ref %font-options-reference) |
113 | (:unref %font-options-destroy)) |
1ed0a2c5 |
114 | |
af338f4a |
115 | (defclass scaled-font (ref-counted-object) |
1ed0a2c5 |
116 | () |
a82cea45 |
117 | (:metaclass proxy-class) |
118 | (:ref %scaled-font-reference) |
119 | (:unref %scaled-font-destroy)) |
1ed0a2c5 |
120 | |
121 | (defclass matrix (struct) |
122 | ((xx :allocation :alien :initarg :xx :initform 1.0 |
123 | :accessor matrix-xx :type double-float) |
124 | (yx :allocation :alien :initarg :yx :initform 0.0 |
125 | :accessor matrix-yx :type double-float) |
126 | (xy :allocation :alien :initarg :xy :initform 1.0 |
127 | :accessor matrix-xy :type double-float) |
128 | (yy :allocation :alien :initarg :yy :initform 0.0 |
129 | :accessor matrix-yy :type double-float) |
130 | (x0 :allocation :alien :initarg :x0 :initform 0.0 |
131 | :accessor matrix-x0 :type double-float) |
132 | (y0 :allocation :alien :initarg :y0 :initform 0.0 |
133 | :accessor matrix-y0 :type double-float)) |
134 | (:metaclass struct-class)) |
135 | |
136 | |
137 | (defclass text-extents (struct) |
138 | ((x-bearing :allocation :alien :reader text-extents-x-bearing :type double-float) |
139 | (y-bearing :allocation :alien :reader text-extents-y-bearing :type double-float) |
140 | (width :allocation :alien :reader text-extents-width :type double-float) |
141 | (height :allocation :alien :reader text-extents-height :type double-float) |
142 | (x-advance :allocation :alien :reader text-extents-x-advance :type double-float) |
143 | (y-advance :allocation :alien :reader text-extents-y-advance :type double-float)) |
144 | (:metaclass struct-class)) |
145 | |
af338f4a |
146 | (defclass pattern (ref-counted-object) |
1ed0a2c5 |
147 | ((extend |
148 | :allocation :virtual |
149 | :getter "cairo_pattern_get_extend" |
150 | :setter "cairo_pattern_set_extend" |
151 | :accessor pattern-extend |
152 | :type extend) |
153 | (filter |
154 | :allocation :virtual |
155 | :getter "cairo_pattern_get_filter" |
156 | :setter "cairo_pattern_set_filter" |
157 | :accessor pattern-filter |
158 | :type filter) |
159 | (matrix |
160 | :allocation :virtual |
161 | :getter "cairo_pattern_get_matrix" |
162 | :setter "cairo_pattern_set_matrix" |
163 | :accessor pattern-matrix |
164 | :type matrix)) |
a82cea45 |
165 | (:metaclass proxy-class) |
166 | (:ref %pattern-reference) |
167 | (:unref %pattern-destroy)) |
168 | |
169 | |
af338f4a |
170 | (defclass surface (ref-counted-object) |
81240b33 |
171 | (#?(pkg-exists-p "cairo" :atleast-version "1.2") |
172 | (type |
173 | :allocation :virtual |
174 | :getter "cairo_surface_get_tyoe" |
175 | :reader surface-type |
176 | :type surface-type) |
177 | #?(pkg-exists-p "cairo" :atleast-version "1.2") |
178 | (content |
179 | :allocation :virtual |
180 | :getter "cairo_surface_get_content" |
181 | :reader surface-content |
182 | :type content)) |
a82cea45 |
183 | (:metaclass proxy-class) |
184 | (:ref %surface-reference) |
185 | (:unref %surface-destroy)) |
1ed0a2c5 |
186 | |
af338f4a |
187 | (defclass context (ref-counted-object) |
1ed0a2c5 |
188 | ((target |
189 | :allocation :virtual |
190 | :getter "cairo_get_target" |
191 | :reader target |
192 | :type surface) |
193 | (source |
194 | :allocation :virtual |
195 | :getter "cairo_get_source" |
196 | :setter "cairo_set_source" |
197 | :accessor source |
198 | :type pattern) |
199 | (antialias |
200 | :allocation :virtual |
201 | :getter "cairo_get_antialias" |
202 | :setter "cairo_set_antialias" |
203 | :accessor antialias |
204 | :type antialias) |
205 | (tolerance |
206 | :allocation :virtual |
207 | :getter "cairo_get_tolerance" |
208 | :setter "cairo_set_tolerance" |
209 | :accessor tolerance |
210 | :type double-float) |
211 | (fill-rule |
212 | :allocation :virtual |
213 | :getter "cairo_get_fill_rule" |
214 | :setter "cairo_set_fill_rule" |
215 | :accessor fill-rule |
216 | :type fill-rule) |
217 | (line-width |
218 | :allocation :virtual |
219 | :getter "cairo_get_line_width" |
220 | :setter "cairo_set_line_width" |
221 | :accessor line-width |
222 | :type double-float) |
223 | (line-cap |
224 | :allocation :virtual |
225 | :getter "cairo_get_line_cap" |
226 | :setter "cairo_set_line_cap" |
227 | :accessor line-cap |
228 | :type line-cap) |
229 | (line-join |
230 | :allocation :virtual |
231 | :getter "cairo_get_line_join" |
232 | :setter "cairo_set_line_join" |
233 | :accessor line-join |
234 | :type line-join) |
235 | (miter-limit |
236 | :allocation :virtual |
237 | :getter "cairo_get_miter_limit" |
238 | :setter "cairo_set_miter_limit" |
239 | :accessor miter-limit |
240 | :type double-float) |
241 | (font-matrix |
242 | :allocation :virtual |
243 | :getter "cairo_get_font_matrix" |
244 | :setter "cairo_set_font_matrix" |
245 | :accessor font-matrix |
246 | :type matrix) |
247 | (font-options |
248 | :allocation :virtual |
249 | :getter "cairo_get_font_options" |
250 | :setter "cairo_set_font_options" |
251 | :accessor font-options |
252 | :type font-options) |
253 | (font-face |
254 | :allocation :virtual |
255 | :getter "cairo_get_font_face" |
256 | :setter "cairo_set_font_face" |
257 | :accessor font-face |
258 | :type font-face) |
259 | (operator |
260 | :allocation :virtual |
261 | :getter "cairo_get_operator" |
262 | :setter "cairo_set_operator" |
263 | :accessor operator |
264 | :type operator) |
265 | (matrix |
266 | :allocation :virtual |
267 | :getter matrix |
268 | :setter "cairo_set_matrix" |
269 | :writer (setf matrix) |
270 | :type matrix) |
271 | ) |
a82cea45 |
272 | (:metaclass proxy-class) |
273 | (:ref %reference) |
274 | (:unref %destroy)) |
1ed0a2c5 |
275 | |
276 | (defclass image-surface (surface) |
277 | ((width |
278 | :allocation :virtual |
279 | :getter "cairo_image_surface_get_width" |
280 | :reader surface-width |
281 | :type int) |
282 | (height |
283 | :allocation :virtual |
284 | :getter "cairo_image_surface_get_height" |
285 | :reader surface-height |
286 | :type int)) |
af338f4a |
287 | (:metaclass proxy-class)) |
a82cea45 |
288 | |
1ed0a2c5 |
289 | |
290 | ;; (defclass path (proxy) |
291 | ;; () |
292 | ;; (:metaclass proxy-class)) |
293 | |
294 | ) |
295 | |
296 | |
297 | ;;; Cairo context |
298 | |
299 | (defbinding %reference () nil |
300 | (location pointer)) |
301 | |
302 | (defbinding %destroy () nil |
303 | (location pointer)) |
304 | |
1ed0a2c5 |
305 | (defbinding (save-context "cairo_save") () nil |
306 | (cr context)) |
307 | |
308 | (defbinding (restore-context "cairo_restore") () nil |
309 | (cr context)) |
310 | |
311 | (defmacro with-context ((cr) &body body) |
312 | (let ((context (make-symbol "CONTEXT"))) |
313 | `(let ((,context ,cr)) |
314 | (save-context ,context) |
315 | (unwind-protect |
316 | (progn ,@body) |
317 | (restore-context ,context))))) |
318 | |
319 | (defbinding status () status |
320 | (cr context)) |
321 | |
4372fce2 |
322 | (defun ensure-color-component (component) |
323 | (etypecase component |
324 | (float component) |
325 | (integer (/ component 256.0)))) |
326 | |
1ed0a2c5 |
327 | (defbinding (set-source-color "cairo_set_source_rgba") (cr red green blue &optional (alpha 1.0)) nil |
328 | (cr context) |
4372fce2 |
329 | ((ensure-color-component red) double-float) |
330 | ((ensure-color-component green) double-float) |
331 | ((ensure-color-component blue) double-float) |
332 | ((ensure-color-component alpha) double-float)) |
1ed0a2c5 |
333 | |
81240b33 |
334 | (defbinding set-source-surface (cr surface &optional (x 0.0) (y 0.0)) nil |
1ed0a2c5 |
335 | (cr context) |
336 | (surface surface) |
337 | (x double-float) |
338 | (y double-float)) |
339 | |
81240b33 |
340 | (defun set-source (cr source) |
341 | (etypecase source |
342 | (pattern (setf (source cr) source)) |
343 | (surface (set-source-surface cr source)) |
344 | (list (apply #'set-source-color cr source)) |
345 | (vector (apply #'set-source-color cr (coerce source 'list))) |
346 | (null (set-source-color cr 0.0 0.0 0.0)))) |
347 | |
1ed0a2c5 |
348 | (defbinding set-dash (cr dashes &optional (offset 0.0)) nil |
349 | (cr context) |
350 | (dashes (vector double-float)) |
351 | ((length dashes) int) |
352 | (offset double-float)) |
353 | |
354 | (defbinding (paint "cairo_paint_with_alpha") (cr &optional (alpha 1.0)) nil |
355 | (cr context) |
356 | (alpha double-float)) |
357 | |
358 | (defbinding mask () nil |
359 | (cr context) |
360 | (pattern pattern)) |
361 | |
362 | (defbinding mask-surface () nil |
363 | (cr context) |
364 | (surface surface) |
365 | (surface-x double-float) |
366 | (surface-y double-float)) |
367 | |
368 | (defmacro defoperator (name &optional clip-p) |
369 | (let ((iname (intern (format nil "%~A" name))) |
370 | (pname (intern (format nil "%~A-PRESERVE" name)))) |
371 | `(progn |
372 | (defbinding ,iname () nil |
373 | (cr context)) |
374 | (defbinding ,pname () nil |
375 | (cr context)) |
376 | (defun ,name (cr &optional preserve) |
377 | (if preserve |
378 | (,pname cr) |
379 | (,iname cr))) |
380 | ,(unless clip-p |
2f60440d |
381 | (let ((tname (intern (format nil "IN-~A-P" name))) |
1ed0a2c5 |
382 | (ename (intern (format nil "~A-EXTENTS" name)))) |
383 | `(progn |
384 | (defbinding ,tname () boolean |
385 | (cr context) |
386 | (x double-float) |
387 | (y double-float)) |
388 | (defbinding ,ename () boolean |
389 | (cr context) |
390 | (x1 double-float :out) |
391 | (y1 double-float :out) |
392 | (x2 double-float :out) |
393 | (y2 double-float :out)))))))) |
394 | |
395 | (defoperator clip t) |
396 | (defoperator stroke) |
397 | (defoperator fill) |
398 | |
399 | (defbinding reset-clip () nil |
400 | (cr context)) |
401 | |
402 | (defbinding copy-page () nil |
403 | (cr context)) |
404 | |
405 | (defbinding show-page () nil |
406 | (cr context)) |
407 | |
408 | |
409 | ;;; Paths |
410 | |
411 | (defbinding get-current-point () nil |
412 | (cr context) |
413 | (x double-float :out) |
414 | (y double-float :out)) |
415 | |
416 | (defbinding new-path () nil |
417 | (cr context)) |
418 | |
4372fce2 |
419 | #?(pkg-exists-p "cairo" :atleast-version "1.2") |
420 | (defbinding new-sub-path () nil |
421 | (cr context)) |
422 | |
1ed0a2c5 |
423 | (defbinding close-path () nil |
424 | (cr context)) |
425 | |
81240b33 |
426 | (defmacro defpath (name args &optional relative-p) |
427 | (flet ((def (name type) |
428 | `(progn |
429 | ,(when (eq type 'optimized-double-float) |
430 | `(declaim (ftype (function (context ,@(loop repeat (length args) collect 'double-float))) ,(first name)))) |
431 | (defbinding ,name () nil |
432 | (cr context) |
433 | ,@(mapcar #'(lambda (arg) (list arg type)) args))))) |
434 | |
435 | `(progn |
436 | ,(def name 'double-float) |
437 | ,(let ((name (intern (format nil "FAST-~A" name))) |
438 | (cname (gffi::default-alien-fname name))) |
439 | (def (list name cname) 'optimized-double-float)) |
440 | ,@(when relative-p |
441 | (let* ((rel-name (intern (format nil "REL-~A" name))) |
442 | (fast-rel-name (intern (format nil "FAST-REL-~A" name))) |
443 | (cname (gffi::default-alien-fname rel-name))) |
444 | (list |
445 | (def rel-name 'double-float) |
446 | (def (list fast-rel-name cname) 'optimized-double-float))))))) |
447 | |
448 | |
449 | (defpath arc (xc yc radius angle1 angle2)) |
450 | (defpath arc-negative (xc yc radius angle1 angle2)) |
451 | (defpath curve-to (x1 y1 x2 y2 x3 y3) t) |
452 | (defpath line-to (x y) t) |
453 | (defpath move-to (x y) t) |
454 | (defpath rectangle (x y width height)) |
1ed0a2c5 |
455 | |
456 | (defun circle (cr x y radius) |
457 | (arc cr x y radius 0.0 (* pi 2))) |
458 | |
1ed0a2c5 |
459 | (defbinding glyph-path (cr glyphs) nil |
460 | (cr context) |
461 | (glyphs (vector glyph)) |
462 | ((length glyphs) int)) |
463 | |
464 | (defbinding text-path () nil |
465 | (cr context) |
466 | (text string)) |
467 | |
468 | |
469 | |
470 | ;;; Patterns |
471 | |
472 | (defbinding (pattern-add-color-stop "cairo_pattern_add_color_stop_rgba") |
473 | (pattern offset red green blue &optional (alpha 1.0)) nil |
474 | (pattern pattern) |
475 | (offset double-float) |
81240b33 |
476 | ((ensure-color-component red) double-float) |
477 | ((ensure-color-component green) double-float) |
478 | ((ensure-color-component blue) double-float) |
479 | ((ensure-color-component alpha) double-float)) |
1ed0a2c5 |
480 | |
481 | (defbinding (pattern-create "cairo_pattern_create_rgba") |
482 | (red green blue &optional (alpha 1.0)) pattern |
81240b33 |
483 | ((ensure-color-component red) double-float) |
484 | ((ensure-color-component green) double-float) |
485 | ((ensure-color-component blue) double-float) |
486 | ((ensure-color-component alpha) double-float)) |
1ed0a2c5 |
487 | |
488 | (defbinding pattern-create-for-surface () pattern |
489 | (surface surface)) |
490 | |
491 | (defbinding pattern-create-linear () pattern |
492 | (x0 double-float) |
493 | (y0 double-float) |
494 | (x1 double-float) |
495 | (y1 double-float)) |
496 | |
497 | (defbinding pattern-create-radial () pattern |
498 | (cx0 double-float) |
499 | (cy0 double-float) |
500 | (radius0 double-float) |
501 | (cx1 double-float) |
502 | (cy1 double-float) |
503 | (radius1 double-float)) |
504 | |
505 | (defbinding %pattern-reference () nil |
506 | (location pointer)) |
507 | |
508 | (defbinding %pattern-destroy () nil |
509 | (location pointer)) |
510 | |
1ed0a2c5 |
511 | (defbinding pattern-status () status |
512 | (pattern pattern)) |
513 | |
514 | |
515 | |
516 | ;;; Transformations |
517 | |
518 | (defbinding translate () nil |
519 | (cr context) |
520 | (tx double-float) |
521 | (ty double-float)) |
522 | |
81240b33 |
523 | (defbinding scale (cr sx &optional (sy sx)) nil |
1ed0a2c5 |
524 | (cr context) |
525 | (sx double-float) |
526 | (sy double-float)) |
527 | |
81240b33 |
528 | (defun scale-to-device (cr &optional keep-rotation-p) |
529 | (if keep-rotation-p |
530 | (multiple-value-call #'scale cr (device-to-user-distance cr 1.0)) |
531 | (multiple-value-bind (x y) |
532 | (multiple-value-call #'user-to-device cr (get-current-point cr)) |
533 | (identity-matrix cr) |
534 | (translate cr x y)))) |
535 | |
1ed0a2c5 |
536 | (defbinding rotate () nil |
537 | (cr context) |
538 | (angle double-float)) |
539 | |
540 | (defbinding transform () nil |
541 | (cr context) |
542 | (matrix matrix)) |
543 | |
544 | (defbinding (matrix "cairo_get_matrix") () nil |
545 | (cr context) |
a82cea45 |
546 | ((make-instance 'matrix) matrix :in/return)) |
1ed0a2c5 |
547 | |
548 | (defbinding identity-matrix () nil |
549 | (cr context)) |
550 | |
551 | (defbinding user-to-device () nil |
552 | (cr context) |
a82cea45 |
553 | (x double-float :in/out) |
554 | (y double-float :in/out)) |
1ed0a2c5 |
555 | |
81240b33 |
556 | (defbinding user-to-device-distance (cr dx &optional (dy dx)) nil |
1ed0a2c5 |
557 | (cr context) |
a82cea45 |
558 | (dx double-float :in/out) |
559 | (dy double-float :in/out)) |
1ed0a2c5 |
560 | |
561 | (defbinding device-to-user () nil |
562 | (cr context) |
a82cea45 |
563 | (x double-float :in/out) |
564 | (y double-float :in/out)) |
1ed0a2c5 |
565 | |
81240b33 |
566 | (defbinding device-to-user-distance (cr dx &optional (dy dx)) nil |
1ed0a2c5 |
567 | (cr context) |
a82cea45 |
568 | (dx double-float :in/out) |
569 | (dy double-float :in/out)) |
1ed0a2c5 |
570 | |
571 | |
572 | ;;; Text |
573 | |
574 | (defbinding select-font-face () nil |
575 | (cr context) |
576 | (family string) |
577 | (slant font-slant) |
578 | (weight font-weight)) |
579 | |
580 | (defbinding set-font-size () nil |
581 | (cr context) |
582 | (size double-float)) |
583 | |
584 | (defbinding show-text () nil |
585 | (cr context) |
586 | (text string)) |
587 | |
588 | (defbinding show-glyphs () nil |
589 | (cr context) |
590 | (glyphs (vector glyph)) |
591 | ((length glyphs) int)) |
592 | |
593 | (defbinding font-extents () boolean |
594 | (cr context)) |
595 | |
596 | (defbinding text-extents (cr text &optional (extents (make-instance 'text-extents))) nil |
597 | (cr context) |
598 | (text string) |
a82cea45 |
599 | (extents text-extents :in/return)) |
1ed0a2c5 |
600 | |
601 | (defbinding glyph-extents (cr glyphs &optional (extents (make-instance 'text-extents))) nil |
602 | (cr context) |
603 | (glyphs (vector glyph)) |
604 | ((length glyphs) int) |
a82cea45 |
605 | (extents text-extents :in/return)) |
1ed0a2c5 |
606 | |
607 | |
608 | ;;; Fonts |
609 | |
610 | (defbinding %font-face-reference () nil |
611 | (location pointer)) |
612 | |
613 | (defbinding %font-face-destroy () nil |
614 | (location pointer)) |
615 | |
1ed0a2c5 |
616 | (defbinding font-face-status () status |
617 | (font-face font-face)) |
618 | |
619 | |
620 | |
621 | ;;; Scaled Fonts |
622 | |
623 | (defbinding %scaled-font-reference () nil |
624 | (location pointer)) |
625 | |
626 | (defbinding %scaled-font-destroy () nil |
627 | (location pointer)) |
628 | |
1ed0a2c5 |
629 | (defbinding scaled-font-status () status |
630 | (scaled-font scaled-font)) |
631 | |
632 | (defbinding scaled-font-extents (scaled-font &optional (extents (make-instance 'text-extents))) nil |
633 | (scaled-font scaled-font) |
a82cea45 |
634 | (extents text-extents :in/return)) |
1ed0a2c5 |
635 | |
636 | (defbinding scaled-font-glyph-extents (scaled-font glyphs &optional (extents (make-instance 'text-extents))) nil |
637 | (scaled-font scaled-font) |
638 | (glyphs (vector glyph)) |
639 | ((length glyphs) int) |
a82cea45 |
640 | (extents text-extents :in/return)) |
1ed0a2c5 |
641 | |
642 | (defbinding %scaled-font-create () pointer |
643 | (font-face font-face) |
644 | (font-matrix matrix) |
645 | (ctm matrix) |
646 | (options font-options)) |
647 | |
c1a5cdbb |
648 | (defmethod allocate-foreign ((scaled-font scaled-font) &key font-face font-matrix cmt options) |
649 | (%scaled-font-create font-face font-matrix cmt options)) |
1ed0a2c5 |
650 | |
651 | |
652 | |
653 | ;;; Font Options |
654 | |
655 | |
656 | (defbinding %font-options-copy () nil |
657 | (location pointer)) |
658 | |
659 | (defbinding %font-options-destroy () nil |
660 | (location pointer)) |
661 | |
1ed0a2c5 |
662 | (defbinding font-options-status () status |
663 | (font-options font-options)) |
664 | |
665 | (defbinding %font-options-create () pointer) |
666 | |
c1a5cdbb |
667 | (defmethod allocate-foreign ((font-options font-options) &rest initargs) |
1ed0a2c5 |
668 | (declare (ignore initargs)) |
c1a5cdbb |
669 | (%font-options-create)) |
1ed0a2c5 |
670 | |
671 | (defbinding font-options-merge () nil |
a82cea45 |
672 | (options1 font-options :in/return) |
1ed0a2c5 |
673 | (options2 font-options)) |
674 | |
675 | (defbinding font-options-hash () unsigned-int |
676 | (options font-options)) |
677 | |
678 | (defbinding font-options-equal-p () boolean |
679 | (options1 font-options) |
680 | (options2 font-options)) |
681 | |
682 | |
683 | |
684 | ;;; Surfaces |
685 | |
686 | (defbinding %surface-reference () nil |
687 | (location pointer)) |
688 | |
689 | (defbinding %surface-destroy () nil |
690 | (location pointer)) |
691 | |
1ed0a2c5 |
692 | (defbinding surface-create-similar () surface |
693 | (other surface) |
694 | (format surface-format ) |
695 | (width int) |
696 | (height int)) |
697 | |
698 | (defbinding surface-finish () nil |
699 | (surface surface)) |
700 | |
701 | (defbinding surface-flush () nil |
702 | (surface surface)) |
703 | |
704 | (defbinding surface-get-font-options () nil |
705 | (surface surface) |
a82cea45 |
706 | ((make-instance 'font-options) font-options :in/return)) |
1ed0a2c5 |
707 | |
708 | (defbinding surface-set-device-offset () nil |
709 | (surface surface) |
710 | (x-offset double-float) |
711 | (y-offset double-float)) |
712 | |
713 | (defbinding surface-status () status |
714 | (surface surface)) |
715 | |
716 | (defbinding %surface-mark-dirty () nil |
717 | (surface surface)) |
718 | |
719 | (defbinding %surface-mark-dirty-rectangle () nil |
720 | (surface surface) |
721 | (x int) |
722 | (y int) |
723 | (width int) |
724 | (height int)) |
725 | |
726 | (defun surface-mark-dirty (surface &optional x y width height) |
727 | (if x |
728 | (%surface-mark-dirty-rectangle surface x y width height) |
729 | (%surface-mark-dirty surface))) |
730 | |
81240b33 |
731 | #?(pkg-exists-p "cairo" :atleast-version "1.2") |
732 | (defbinding surface-set-fallback-resolution () nil |
733 | (surface surface) |
734 | (x-pixels-per-inch double-float) |
735 | (y-pixels-per-inch double-float)) |
1ed0a2c5 |
736 | |
737 | |
738 | ;; Image Surface |
739 | |
740 | ;; Should data be automatically freed when the surface is GCed? |
c1a5cdbb |
741 | (defmethod allocate-foreign ((surface image-surface) |
742 | &key width height stride format data) |
743 | (if (not data) |
744 | (%image-surface-create format width height) |
745 | (%image-surface-create-for-data data format width height |
746 | (or |
747 | stride |
748 | (let ((element-size (cdr (assoc format '((:argb32 . 4) (:rgb24 . 4) (:a8 . 1) (:a1 1/8)))))) |
749 | (ceiling (* width element-size))))))) |
1ed0a2c5 |
750 | |
751 | |
752 | (defbinding %image-surface-create () image-surface |
753 | (format surface-format) |
754 | (width int) |
755 | (hegit int)) |
756 | |
757 | (defbinding %image-surface-create-for-data () image-surface |
758 | (data pointer) |
759 | (format surface-format) |
760 | (width int) |
761 | (hegit int) |
762 | (stride int)) |
763 | |
764 | |
765 | |
766 | ;;; PNG Surface |
767 | |
768 | (defbinding image-surface-create-from-png (filename) image-surface |
769 | ((truename filename) pathname)) |
770 | |
771 | |
772 | |
773 | |
774 | ;;; Matrices |
775 | |
776 | (defbinding matrix-init () nil |
a82cea45 |
777 | (matrix matrix :in/return) |
1ed0a2c5 |
778 | (xx double-float) (yx double-float) |
779 | (xy double-float) (yy double-float) |
780 | (x0 double-float) (y0 double-float)) |
781 | |
782 | (defbinding matrix-init-identity () nil |
a82cea45 |
783 | (matrix matrix :in/return)) |
1ed0a2c5 |
784 | |
785 | (defbinding matrix-init-translate () nil |
a82cea45 |
786 | (matrix matrix :in/return) |
1ed0a2c5 |
787 | (tx double-float) |
788 | (ty double-float)) |
789 | |
790 | (defbinding matrix-init-scale () nil |
a82cea45 |
791 | (matrix matrix :in/return) |
1ed0a2c5 |
792 | (sx double-float) |
793 | (sy double-float)) |
794 | |
795 | (defbinding matrix-init-rotate () nil |
a82cea45 |
796 | (matrix matrix :in/return) |
1ed0a2c5 |
797 | (radians double-float)) |
798 | |
799 | (defbinding matrix-translate () nil |
a82cea45 |
800 | (matrix matrix :in/return) |
1ed0a2c5 |
801 | (tx double-float) |
802 | (ty double-float)) |
803 | |
804 | (defbinding matrix-scale () nil |
a82cea45 |
805 | (matrix matrix :in/return) |
1ed0a2c5 |
806 | (sx double-float) |
807 | (sy double-float)) |
808 | |
809 | (defbinding matrix-rotate () nil |
a82cea45 |
810 | (matrix matrix :in/return) |
1ed0a2c5 |
811 | (radians double-float)) |
812 | |
813 | (defbinding matrix-invert () nil |
a82cea45 |
814 | (matrix matrix :in/return)) |
1ed0a2c5 |
815 | |
816 | (defbinding matrix-multiply () nil |
817 | (result matrix :out) |
818 | (a matrix) |
819 | (b matrix)) |
820 | |
821 | (defbinding matrix-transform-distance () nil |
a82cea45 |
822 | (matrix matrix :in/return) |
1ed0a2c5 |
823 | (dx double-float) |
824 | (dy double-float)) |
825 | |
826 | (defbinding matrix-transform-point () nil |
a82cea45 |
827 | (matrix matrix :in/return) |
1ed0a2c5 |
828 | (x double-float) |
829 | (y double-float)) |
830 | |
831 | |
832 | |