| 1 |
Guile-Cairo README |
| 2 |
Last updated 1 October 2018. |
| 3 |
|
| 4 |
|
| 5 |
About Guile-Cairo |
| 6 |
================= |
| 7 |
|
| 8 |
Guile-Cairo wraps the Cairo graphics library for Guile Scheme. |
| 9 |
|
| 10 |
|
| 11 |
A pasteable introduction to using Guile-Cairo |
| 12 |
============================================= |
| 13 |
|
| 14 |
;; Paste this into your guile interpreter! |
| 15 |
|
| 16 |
;; This wrapset defines a module `(cairo)' |
| 17 |
|
| 18 |
(use-modules (cairo)) |
| 19 |
|
| 20 |
;; Cairo procedures all start with `cairo-' |
| 21 |
|
| 22 |
(cairo-version-string) |
| 23 |
;; => "1.14.8" |
| 24 |
|
| 25 |
;; For most useful things, you have to make a surface first |
| 26 |
|
| 27 |
(define surf (cairo-image-surface-create 'argb32 140 100)) |
| 28 |
|
| 29 |
;; Given a surface, you can create a cairo context, and start drawing |
| 30 |
|
| 31 |
(define cr (cairo-create surf)) |
| 32 |
|
| 33 |
;; You then need to make a source |
| 34 |
|
| 35 |
(cairo-select-font-face cr "Bitstream Vera Sans" 'normal 'normal) |
| 36 |
(cairo-scale cr 100 100) |
| 37 |
(define pat (cairo-pattern-create-linear 0 0 1 1)) |
| 38 |
(cairo-pattern-add-color-stop-rgba pat 1 1 0 0 1) |
| 39 |
(cairo-pattern-add-color-stop-rgba pat 0 0 0 1 1) |
| 40 |
(cairo-set-source cr pat) |
| 41 |
|
| 42 |
;; Then you make your mask |
| 43 |
|
| 44 |
(cairo-set-font-size cr 0.4) |
| 45 |
(cairo-move-to cr 0.0 0.6) |
| 46 |
(cairo-show-text cr "(cairo)") |
| 47 |
|
| 48 |
;; Finally you can write the surface out to a file if you want |
| 49 |
|
| 50 |
(cairo-surface-write-to-png surf "/tmp/guile-cairo.png") |
| 51 |
|
| 52 |
;; Functions that write out to files always take the filename as their |
| 53 |
;; last argument, which is optional. If you leave it out, guile-cairo |
| 54 |
;; will write to the current output port. So this is another way of |
| 55 |
;; doing the same thing: |
| 56 |
|
| 57 |
(with-output-to-file "/tmp/guile-cairo.png" |
| 58 |
(lambda () (cairo-surface-write-to-png surf))) |
| 59 |
|
| 60 |
;; Enumerated types are represented as symbols. The available set of |
| 61 |
;; symbols for any given type can be retrieved at runtime |
| 62 |
|
| 63 |
(cairo-format-get-values) |
| 64 |
;; => (argb32 rgb24 a8 a1) |
| 65 |
|
| 66 |
;; That's it! |
| 67 |
|
| 68 |
|
| 69 |
Notes |
| 70 |
===== |
| 71 |
|
| 72 |
Guile-Cairo wraps almost all of Cairo's procedures. Notable exceptions |
| 73 |
include functions that read or write from streams instead of files and |
| 74 |
raw access to image data. |
| 75 |
|
| 76 |
Guile-Cairo wraps all of Cairo's types. As mentioned above, enumerated |
| 77 |
values are represented by symbols, but functions accept integers as |
| 78 |
well. Struct types like cairo_rectangle_t are represented as vectors. |
| 79 |
Constructors of the form cairo-make-rectangle are provided, as well as |
| 80 |
accessors like cairo-rectangle:x. |
| 81 |
|
| 82 |
|
| 83 |
Using Guile-Cairo's C interface |
| 84 |
=============================== |
| 85 |
|
| 86 |
These days Cairo forms a part of many software stacks; its types are |
| 87 |
seen in the APIs of a number of other libraries. Guile-Cairo provides an |
| 88 |
interface to represent all cairo C types as scheme values. |
| 89 |
|
| 90 |
To build against this library in your C program, first you will need to |
| 91 |
get the CFLAGS and LDFLAGS to link against libguile-cairo. Autoconf |
| 92 |
users should use: |
| 93 |
|
| 94 |
PKG_CHECK_MODULES(GUILE_CAIRO, guile-cairo >= 1.3.0) |
| 95 |
AC_SUBST(GUILE_CAIRO_CFLAGS) |
| 96 |
AC_SUBST(GUILE_CAIRO_LDFLAGS) |
| 97 |
|
| 98 |
In your C files you should then: |
| 99 |
|
| 100 |
#include <guile-cairo.h> |
| 101 |
|
| 102 |
The type wrapping functions are all in the form scm_to_TYPE and |
| 103 |
scm_from_TYPE, where TYPE could be cairo_surface, for example. For |
| 104 |
vector types there is also scm_fill_TYPE, which expects you to have an |
| 105 |
already-allocated structure to fill. Additionally there are |
| 106 |
scm_take_TYPE functions that will take ownership of the pointer in |
| 107 |
question, for example for constructors and for non-refcounted opaque |
| 108 |
objects like cairo_font_options_t. |
| 109 |
|
| 110 |
|
| 111 |
Known bugs |
| 112 |
================== |
| 113 |
|
| 114 |
(Yay?!) |
| 115 |
|
| 116 |
Copying Guile-Cairo |
| 117 |
=================== |
| 118 |
|
| 119 |
Distribution of Guile-Cairo is under the LGPL. See the COPYING file for |
| 120 |
more information. |
| 121 |
|
| 122 |
|
| 123 |
Contact info |
| 124 |
============ |
| 125 |
|
| 126 |
Mailing List: [email protected] |
| 127 |
Homepage: http://www.non-gnu.org/guile-cairo/ |
| 128 |
Download: http://www.non-gnu.org/guile-cairo/download/ |
| 129 |
|
| 130 |
|
| 131 |
Build dependencies |
| 132 |
================== |
| 133 |
|
| 134 |
* Guile 1.8.0 or newer |
| 135 |
http://www.gnu.org/software/guile/ |
| 136 |
* Cairo 1.10.0 or newer |
| 137 |
http://cairographics.org/ |
| 138 |
* guile-lib 0.1.6 or newer (only for `make check') |
| 139 |
https://www.nongnu.org/guile-lib |
| 140 |
|
| 141 |
See 'Known bugs' in this file and doc/README if you wish to rebuild the |
| 142 |
documentation. |
| 143 |
|
| 144 |
Installation quickstart |
| 145 |
======================= |
| 146 |
|
| 147 |
Install using the standard autotools incantation: |
| 148 |
./configure --prefix=/opt/guile-cairo && make && make install. |
| 149 |
|
| 150 |
Build from CVS or Arch using ./autogen.sh --prefix=/opt/guile-cairo && make. |
| 151 |
|
| 152 |
You can run without installing, just run './env guile'. |
| 153 |
|
| 154 |
|
| 155 |
Copying this file |
| 156 |
================= |
| 157 |
|
| 158 |
Copyright (C) 2007,2011 Andy Wingo <wingo pobox.com> |
| 159 |
|
| 160 |
Copying and distribution of this file, with or without modification, are |
| 161 |
permitted in any medium without royalty provided the copyright notice |
| 162 |
and this notice are preserved. |