Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | more tests and improvements on cairo |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
6ea4d2df39e2ea26795d1932e887cc14 |
| User & Date: | ovenpasta@pizzahack.eu 2016-07-24 21:23:10.000 |
Context
|
2016-07-24
| ||
| 21:24 | add romeladen.png for cairo tests check-in: 647578553e user: ovenpasta@pizzahack.eu tags: trunk | |
| 21:23 | more tests and improvements on cairo check-in: 6ea4d2df39 user: ovenpasta@pizzahack.eu tags: trunk | |
|
2016-07-23
| ||
| 07:46 | cairo improvements, added some tests check-in: ecd5997790 user: ovenpasta@pizzahack.eu tags: trunk | |
Changes
Changes to cairo-test.scm.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
(import (cairo))
(cairo-library-init)
(define (test-cairo name proc)
(let* ([surface (cairo-image-surface-create (cairo-format 'argb-32) 120 120)]
[cr (cairo-create surface)])
(cairo-scale cr 120. 120.)
(proc surface cr)
(cairo-surface-write-to-png surface (string-append name ".png"))))
(test-cairo "stroke"
(lambda (surface cr)
(cairo-set-line-width cr 0.1)
(cairo-set-source-rgb cr 0. 0. 0.)
(cairo-rectangle cr 0.25 0.25 0.25 0.25)
(cairo-stroke cr)))
(test-cairo "showtext"
(lambda (surface cr)
| > > > > > > > > < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
(import (cairo))
(cairo-library-init)
(define pi 3.1415926536)
(define (test-cairo name proc)
(let* ([surface (cairo-image-surface-create (cairo-format 'argb-32) 120 120)]
[cr (cairo-create surface)])
(cairo-scale cr 120. 120.)
(proc surface cr)
(cairo-surface-write-to-png surface (string-append name ".png"))))
(define (sample-cairo name proc)
(let* ([surface (cairo-image-surface-create (cairo-format 'argb-32) 256 256)]
[cr (cairo-create surface)])
(proc surface cr)
(cairo-surface-write-to-png surface (string-append name ".png"))))
;; FROM https://www.cairographics.org/tutorial/
(test-cairo "stroke"
(lambda (surface cr)
(cairo-set-line-width cr 0.1)
(cairo-set-source-rgb cr 0. 0. 0.)
(cairo-rectangle cr 0.25 0.25 0.25 0.25)
(cairo-stroke cr)))
(test-cairo "showtext"
(lambda (surface cr)
(cairo-set-source-rgb cr 0. 0. 0.)
(cairo-select-font-face cr "Georgia" (cairo-font-slant 'normal) (cairo-font-weight 'bold))
(cairo-set-font-size cr 1.2)
(let ([extents (cairo-text-extents-create)])
(cairo-text-extents cr "a" extents)
(cairo-move-to cr
(- 0.5 (/ (ftype-ref cairo-text-extents-t (width) extents) 2) (ftype-ref cairo-text-extents-t (x-bearing) extents))
|
| ︙ | ︙ | |||
90 91 92 93 94 95 96 | (cairo-rectangle cr 0.0 0.0 1. 1.) (cairo-set-source cr linpat) (cairo-fill cr)))) (test-cairo "tips-ellipse" (lambda (surface cr) | < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
(cairo-rectangle cr 0.0 0.0 1. 1.)
(cairo-set-source cr linpat)
(cairo-fill cr))))
(test-cairo "tips-ellipse"
(lambda (surface cr)
(cairo-set-line-width cr 0.1)
(cairo-save cr)
(cairo-scale cr 0.5 1.)
(cairo-arc cr 0.5 0.5 0.40 0. (* 2. pi))
(cairo-stroke cr)
(cairo-translate cr 1. 0.)
(cairo-arc cr 0.5 0.5 0.40 0. (* 2. pi))
(cairo-restore cr)
(cairo-stroke cr)))
;; FROM https://www.cairographics.org/samples/
(sample-cairo "arc"
(lambda (surface cr)
(let ([xc 128.] [yc 128.] [radius 100.]
[angle1 (* 45. (/ pi 180.))] [angle2 (* 180. (/ pi 180.))])
(cairo-set-line-width cr 10.0)
(cairo-arc cr xc yc radius angle1 angle2)
(cairo-stroke cr)
;;/* draw helping lines */
(cairo-set-source-rgba cr 1. 0.2 0.2 0.6)
(cairo-set-line-width cr 6.0)
(cairo-arc cr xc yc 10.0 0. (* 2 pi))
(cairo-fill cr)
(cairo-arc cr xc yc radius angle1 angle1)
(cairo-line-to cr xc yc)
(cairo-arc cr xc yc radius angle2 angle2)
(cairo-line-to cr xc yc)
(cairo-stroke cr))))
(sample-cairo "arc-negative"
(lambda (surface cr)
(let ([xc 128.] [yc 128.] [radius 100.]
[angle1 (* 45. (/ pi 180.))] [angle2 (* 180. (/ pi 180.))])
(cairo-set-line-width cr 10.0)
(cairo-arc-negative cr xc yc radius angle1 angle2)
(cairo-stroke cr)
;;/* draw helping lines */
(cairo-set-source-rgba cr 1. 0.2 0.2 0.6)
(cairo-set-line-width cr 6.0)
(cairo-arc cr xc yc 10.0 0. (* 2 pi))
(cairo-fill cr)
(cairo-arc cr xc yc radius angle1 angle1)
(cairo-line-to cr xc yc)
(cairo-arc cr xc yc radius angle2 angle2)
(cairo-line-to cr xc yc)
(cairo-stroke cr))))
(sample-cairo "clip"
(lambda (surface cr)
(cairo-arc cr 128.0 128.0 76.8 0. (* 2. pi))
(cairo-clip cr)
(cairo-new-path cr) ; /* current path is not
; consumed by (cairo-clip() */
(cairo-rectangle cr 0. 0. 256. 256.)
(cairo-fill cr)
(cairo-set-source-rgb cr 0. 1. 0.)
(cairo-move-to cr 0. 0.)
(cairo-line-to cr 256. 256.)
(cairo-move-to cr 256. 0.)
(cairo-line-to cr 0. 256.)
(cairo-set-line-width cr 10.0)
(cairo-stroke cr)))
(sample-cairo "clip-image"
(lambda (surface cr)
(cairo-arc cr 128.0 128.0 76.8 0. (* 2 pi))
(cairo-clip cr)
(cairo-new-path cr); /* path not consumed by clip()*/
(let* ([image (cairo-image-surface-create-from-png "romedalen.png")]
[w (cairo-image-surface-get-width image)]
[h (cairo-image-surface-get-height image)])
(cairo-scale cr (/ 256.0 w) (/ 256.0 h))
(cairo-set-source-surface cr image 0. 0.)
(cairo-paint cr))))
(sample-cairo "curve-rectangle"
(lambda (surface cr)
; a custom shape that could be wrapped in a function
(let* ([x0 25.6] ; parameters like cairo_rectangle
[y0 25.6]
[rect-width 204.8]
[rect-height 204.8]
[radius 102.4] ; and an approximate curvature radius
[x1 (+ x0 rect-width)]
[y1 (+ y0 rect-height)])
;; WHAT IS THIS?
;;if (!rect_width || !rect_height)
;;return;
(cond [(< (/ rect-width 2) radius)
(cond [(< (/ rect-height 2) radius)
(cairo-move-to cr x0 (/ (+ y0 y1) 2))
(cairo-curve-to cr x0 y0 x0 y0 (/ (+ x0 x1) 2) y0)
(cairo-curve-to cr x1 y0 x1 y0 x1 (/ (+ y0 y1) 2))
(cairo-curve-to cr x1 y1 x1 y1 (/ (+ x1 x0) 2) y1)
(cairo-curve-to cr x0 y1 x0 y1 x0 (/ (+ y0 y1) 2))]
[else
(cairo-move-to cr x0 (+ y0 radius))
(cairo-curve-to cr x0 y0 x0 y0 (/ (+ x0 x1) 2) y0)
(cairo-curve-to cr x1 y0 x1 y0 x1 (+ y0 radius))
(cairo-line-to cr x1 y1 - radius)
(cairo-curve-to cr x1 y1 x1 y1 (/ (+ x1 x0) 2) y1)
(cairo-curve-to cr x0 y1 x0 y1 x0 (- y1 radius))])]
[else
(cond [(< (/ rect-height 2) radius)
(cairo-move-to cr x0 (/ (+ y0 y1) 2))
(cairo-curve-to cr x0 y0 x0 y0 (+ x0 radius) y0)
(cairo-line-to cr (- x1 radius) y0)
(cairo-curve-to cr x1 y0 x1 y0 x1 (/ (+ y0 y1) 2))
(cairo-curve-to cr x1 y1 x1 y1 (- x1 radius) y1)
(cairo-line-to cr (+ x0 radius) y1)
(cairo-curve-to cr x0 y1 x0 y1 x0 (/ (+ y0 y1) 2))]
[else
(cairo-move-to cr x0 (+ y0 radius))
(cairo-curve-to cr x0 y0 x0 y0 (+ x0 radius) y0)
(cairo-line-to cr (- x1 radius) y0)
(cairo-curve-to cr x1 y0 x1 y0 x1 (+ y0 radius))
(cairo-line-to cr x1 (- y1 radius))
(cairo-curve-to cr x1 y1 x1 y1 (- x1 radius) y1)
(cairo-line-to cr (+ x0 radius) y1)
(cairo-curve-to cr x0 y1 x0 y1 x0 (- y1 radius))])])
(cairo-close-path cr)
(cairo-set-source-rgb cr 0.5 0.5 1.)
(cairo-fill-preserve cr)
(cairo-set-source-rgba cr 0.5 0. 0. 0.5)
(cairo-set-line-width cr 10.0)
(cairo-stroke cr))))
(sample-cairo "curve-to"
(lambda (surface cr)
(let ([x 25.6] [y 128.0]
[x1 102.4] [y1 230.4]
[x2 153.6] [y2 25.6]
[x3 230.4] [y3 128.0])
(cairo-move-to cr x y)
(cairo-curve-to cr x1 y1 x2 y2 x3 y3)
(cairo-set-line-width cr 10.0)
(cairo-stroke cr)
(cairo-set-source-rgba cr 1. 0.2 0.2 0.6)
(cairo-set-line-width cr 6.0)
(cairo-move-to cr x y) (cairo-line-to cr x1 y1)
(cairo-move-to cr x2 y2) (cairo-line-to cr x3 y3)
(cairo-stroke cr))))
(sample-cairo "dash"
(lambda (surface cr)
(let ([dashes '#(50.0 ; ink
10.0 ; skip
10.0 ; ink
10.0)] ; skip
[offset -50.])
(cairo-set-dash cr dashes (vector-length dashes) offset)
(cairo-set-line-width cr 10.0)
(cairo-move-to cr 128.0 25.6)
(cairo-line-to cr 230.4 230.4)
(cairo-rel-line-to cr -102.4 0.0)
(cairo-curve-to cr 51.2 230.4 51.2 128.0 128.0 128.0)
(cairo-stroke cr))))
(sample-cairo "fill-and-stroke2"
(lambda (surface cr)
(cairo-move-to cr 128.0 25.6)
(cairo-line-to cr 230.4 230.4)
(cairo-rel-line-to cr -102.4 0.0)
(cairo-curve-to cr 51.2 230.4 51.2 128.0 128.0 128.0)
(cairo-close-path cr)
(cairo-move-to cr 64.0 25.6)
(cairo-rel-line-to cr 51.2 51.2)
(cairo-rel-line-to cr -51.2 51.2)
(cairo-rel-line-to cr -51.2 -51.2)
(cairo-close-path cr)
(cairo-set-line-width cr 10.0)
(cairo-set-source-rgb cr 0. 0. 1.)
(cairo-fill-preserve cr)
(cairo-set-source-rgb cr 0. 0. 0.)
(cairo-stroke cr)))
(sample-cairo "fill style"
(lambda (surface cr)
(cairo-set-line-width cr 6.)
(cairo-rectangle cr 12. 12. 232. 70.)
(cairo-new-sub-path cr) (cairo-arc cr 64. 64. 40. 0. (* 2 pi))
(cairo-new-sub-path cr) (cairo-arc-negative cr 192. 64. 40. 0. (* -2 pi))
(cairo-set-fill-rule cr (cairo-fill-rule 'even-odd))
(cairo-set-source-rgb cr 0. 0.7 0.) (cairo-fill-preserve cr)
(cairo-set-source-rgb cr 0. 0. 0.) (cairo-stroke cr)
(cairo-translate cr 0. 128.)
(cairo-rectangle cr 12. 12. 232. 70.)
(cairo-new-sub-path cr) (cairo-arc cr 64. 64. 40. 0. (* 2 pi))
(cairo-new-sub-path cr) (cairo-arc-negative cr 192. 64. 40. 0. (* -2 pi))
(cairo-set-fill-rule cr (cairo-fill-rule 'winding))
(cairo-set-source-rgb cr 0. 0. 0.9) (cairo-fill-preserve cr)
(cairo-set-source-rgb cr 0. 0. 0.) (cairo-stroke cr)))
(sample-cairo "gradient"
(lambda (surface cr)
(let ([pat (cairo-pattern-create-linear 0.0 0.0 0.0 256.0)])
(cairo-pattern-add-color-stop-rgba pat 1 0 0 0 1)
(cairo-pattern-add-color-stop-rgba pat 0 1 1 1 1)
(cairo-rectangle cr 0 0 256 256)
(cairo-set-source cr pat)
(cairo-fill cr))
(let ([pat (cairo-pattern-create-radial 115.2 102.4 25.6 102.4 102.4 128.0)])
(cairo-pattern-add-color-stop-rgba pat 0 1 1 1 1)
(cairo-pattern-add-color-stop-rgba pat 1 0 0 0 1)
(cairo-set-source cr pat)
(cairo-arc cr 128.0 128.0 76.8 0 (* 2 pi))
(cairo-fill cr))))
(sample-cairo "image"
(lambda (surface cr)
(let* ([image (cairo-image-surface-create-from-png "romedalen.png")]
[w (cairo-image-surface-get-width image)]
[h (cairo-image-surface-get-height image)])
(cairo-translate cr 128.0 128.0)
(cairo-rotate cr (* 45 (/ pi 180)))
(cairo-scale cr (/ 256.0 w) (/ 256.0 h))
(cairo-translate cr (* -0.5 w) (* -0.5 h))
(cairo-set-source-surface cr image 0 0)
(cairo-paint cr))))
(sample-cairo "image-pattern"
(lambda (surface cr)
(let* ([image (cairo-image-surface-create-from-png "romedalen.png")]
[w (cairo-image-surface-get-width image)]
[h (cairo-image-surface-get-height image)])
(let ([pattern (cairo-pattern-create-for-surface image)]
[matrix (cairo-matrix-create)])
(cairo-pattern-set-extend pattern (cairo-extend 'repeat))
(cairo-translate cr 128.0 128.0)
(cairo-rotate cr (/ pi 4))
(cairo-scale cr (/ 1 (sqrt 2)) (/ 1 (sqrt 2)))
(cairo-translate cr -128.0 -128.0)
(cairo-matrix-init-scale matrix (* (/ w 256.0) 5.0) (* (/ h 256.0) 5.0))
(cairo-pattern-set-matrix pattern matrix)
(cairo-set-source cr pattern)
(cairo-rectangle cr 0 0 256.0 256.0)
(cairo-fill cr)))))
(sample-cairo "multi-segment-caps"
(lambda (surface cr)
(cairo-move-to cr 50.0 75.0)
(cairo-line-to cr 200.0 75.0)
(cairo-move-to cr 50.0 125.0)
(cairo-line-to cr 200.0 125.0)
(cairo-move-to cr 50.0 175.0)
(cairo-line-to cr 200.0 175.0)
(cairo-set-line-width cr 30.0)
(cairo-set-line-cap cr (cairo-line-cap 'round))
(cairo-stroke cr)))
(sample-cairo "rounded-rectangle"
(lambda (surface cr)
;/* a custom shape that could be wrapped in a function */
(let* ([x 25.6] ;/* parameters like (cairo-rectangle */
[y 25.6]
[width 204.8]
[height 204.8]
[aspect 1.0] ; /* aspect ratio */
[corner-radius (/ height 10.0)] ; /* and corner curvature radius */
[radius (/ corner-radius aspect)]
[degrees (/ pi 180.0)])
(cairo-new-sub-path cr)
(cairo-arc cr (- (+ x width) radius) (+ y radius) radius (* -90 degrees) (* 0 degrees))
(cairo-arc cr (- (+ x width) radius) (- (+ y height) radius) radius (* 0 degrees) (* 90 degrees))
(cairo-arc cr (+ x radius) (- (+ y height) radius) radius (* 90 degrees) (* 180 degrees))
(cairo-arc cr (+ x radius) (+ y radius) radius (* 180 degrees) (* 270 degrees))
(cairo-close-path cr)
(cairo-set-source-rgb cr 0.5 0.5 1)
(cairo-fill-preserve cr)
(cairo-set-source-rgba cr 0.5 0 0 0.5)
(cairo-set-line-width cr 10.0)
(cairo-stroke cr))))
(sample-cairo "set-line-cap"
(lambda (surface cr)
(cairo-set-line-width cr 30.0)
(cairo-set-line-cap cr (CAIRO-LINE-CAP-BUTT) /* default */
(cairo-move-to cr 64.0 50.0) (cairo-line-to cr 64.0 200.0)
(cairo-stroke cr)
(cairo-set-line-cap cr (CAIRO-LINE-CAP-ROUND)
(cairo-move-to cr 128.0 50.0) (cairo-line-to cr 128.0 200.0)
(cairo-stroke cr)
(cairo-set-line-cap cr (CAIRO-LINE-CAP-SQUARE)
(cairo-move-to cr 192.0 50.0) (cairo-line-to cr 192.0 200.0)
(cairo-stroke cr)
/* draw helping lines */
(cairo-set-source-rgb cr 1 0.2 0.2)
(cairo-set-line-width cr 2.56)
(cairo-move-to cr 64.0 50.0) (cairo-line-to cr 64.0 200.0)
(cairo-move-to cr 128.0 50.0) (cairo-line-to cr 128.0 200.0)
(cairo-move-to cr 192.0 50.0) (cairo-line-to cr 192.0 200.0)
(cairo-stroke cr)
(sample-cairo "set-line-join"
(lambda (surface cr)
(cairo-set-line-width cr 40.96)
(cairo-move-to cr 76.8 84.48)
(cairo-rel-line-to cr 51.2 -51.2)
(cairo-rel-line-to cr 51.2 51.2)
(cairo-set-line-join cr (CAIRO-LINE-JOIN-MITER) /* default */
(cairo-stroke cr)
(cairo-move-to cr 76.8 161.28)
(cairo-rel-line-to cr 51.2 -51.2)
(cairo-rel-line-to cr 51.2 51.2)
(cairo-set-line-join cr (CAIRO-LINE-JOIN-BEVEL)
(cairo-stroke cr)
(cairo-move-to cr 76.8 238.08)
(cairo-rel-line-to cr 51.2 -51.2)
(cairo-rel-line-to cr 51.2 51.2)
(cairo-set-line-join cr (CAIRO-LINE-JOIN-ROUND)
(cairo-stroke cr)
(sample-cairo "text"
(lambda (surface cr)
(cairo-select-font-face cr "Sans" (CAIRO-FONT-SLANT-NORMAL
(CAIRO-FONT-WEIGHT-BOLD)
(cairo-set-font-size cr 90.0)
(cairo-move-to cr 10.0 135.0)
(cairo-show-text cr "Hello")
(cairo-move-to cr 70.0 165.0)
(cairo-text-path cr "void")
(cairo-set-source-rgb cr 0.5 0.5 1)
(cairo-fill-preserve cr)
(cairo-set-source-rgb cr 0 0 0)
(cairo-set-line-width cr 2.56)
(cairo-stroke cr)
/* draw helping lines */
(cairo-set-source-rgba cr 1 0.2 0.2 0.6)
(cairo-arc cr 10.0 135.0 5.12 0 2*M-PI)
(cairo-close-path cr)
(cairo-arc cr 70.0 165.0 5.12 0 2*M-PI)
(cairo-fill cr)
(sample-cairo "text-align-center"
(lambda (surface cr)
(let ([utf8 "cairo"]
[extents (cairo-text-extents-create)])
(cairo-select-font-face cr "Sans" (cairo-font-slant 'normal) (cairo-font-weight 'normal))
(cairo-set-font-size cr 52.0)
(cairo-text-extents cr utf8 extents)
(let ([x (- 128.0 (+ (/ (ftype-ref cairo-text-extents-t (width) extents) 2) (ftype-ref cairo-text-extents-t (x-bearing) extents)))]
[y (- 128.0 (+ (/ (ftype-ref cairo-text-extents-t (height) extents) 2) (ftype-ref cairo-text-extents-t (y-bearing) extents)))])
(cairo-move-to cr x y)
(cairo-show-text cr utf8)
;/* draw helping lines */
(cairo-set-source-rgba cr 1 0.2 0.2 0.6)
(cairo-set-line-width cr 6.0)
(cairo-arc cr x y 10.0 0 (* 2 pi))
(cairo-fill cr)
(cairo-move-to cr 128.0 0)
(cairo-rel-line-to cr 0 256)
(cairo-move-to cr 0 128.0)
(cairo-rel-line-to cr 256 0)
(cairo-stroke cr)))))
(sample-cairo "text-extents"
(lambda (surface cr)
(let ([utf8 "cairo"]
[extents (cairo-text-extents-create)]
[x 25] [y 150])
(cairo-select-font-face cr "Sans" (cairo-font-slant 'normal) (cairo-font-weight 'normal))
(cairo-set-font-size cr 100.0)
(cairo-text-extents cr utf8 extents)
(cairo-move-to cr x y)
(cairo-show-text cr utf8)
;/* draw helping lines */
(cairo-set-source-rgba cr 1 0.2 0.2 0.6)
(cairo-set-line-width cr 6.0)
(cairo-arc cr x y 10.0 0 (* 2 pi))
(cairo-fill cr)
(cairo-move-to cr x y)
(cairo-rel-line-to cr 0 (- (ftype-ref cairo-text-extents-t (height) extents)))
(cairo-rel-line-to cr (ftype-ref cairo-text-extents-t (width) extents) 0)
(cairo-rel-line-to cr (ftype-ref cairo-text-extents-t (x-bearing) extents) (- (ftype-ref cairo-text-extents-t (y-bearing) extents)))
(cairo-stroke cr))))
(system "eog .")
|
Changes to cairo.sls.
| ︙ | ︙ | |||
202 203 204 205 206 207 208 209 210 211 212 213 214 215 | cairo-rectangle-int-t* cairo-operator-t cairo-antialias-t cairo-fill-rule-t cairo-line-cap-t cairo-line-join-t double* cairo-rectangle-t cairo-rectangle-t* cairo-rectangle-list-t cairo-rectangle-list-t* cairo-scaled-font-t cairo-font-face-t cairo-glyph-t | > | 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | cairo-rectangle-int-t* cairo-operator-t cairo-antialias-t cairo-fill-rule-t cairo-line-cap-t cairo-line-join-t double* double-array cairo-rectangle-t cairo-rectangle-t* cairo-rectangle-list-t cairo-rectangle-list-t* cairo-scaled-font-t cairo-font-face-t cairo-glyph-t |
| ︙ | ︙ | |||
294 295 296 297 298 299 300 301 | cairo-rectangle-create cairo-rectangle-list-create cairo-glyph-create cairo-text-cluster-create cairo-text-extents-create cairo-font-extents-create cairo-path-create | > > > > | | | < < | 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
cairo-rectangle-create
cairo-rectangle-list-create
cairo-glyph-create
cairo-text-cluster-create
cairo-text-extents-create
cairo-font-extents-create
cairo-path-create
double-array-create
double-array-create-from-vector
cairo-matrix-create
cairo-guardian
cairo-free-garbage
cairo-guard-pointer
)
(import (chezscheme) (ffi-utils))
(define-syntax define-function*
(lambda (x)
(define (string-replace s x y)
|
| ︙ | ︙ | |||
356 357 358 359 360 361 362 |
(define (convert-scheme->c function-name name type)
(import (only (srfi s13 strings)
string-delete string-suffix? string-prefix?))
(define (remove-* x)
(string->symbol (string-delete #\* (symbol->string x))))
| | > > > > > | 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
(define (convert-scheme->c function-name name type)
(import (only (srfi s13 strings)
string-delete string-suffix? string-prefix?))
(define (remove-* x)
(string->symbol (string-delete #\* (symbol->string x))))
(let ([t (syntax->datum (rename-scheme->c type))]
[t* (syntax->datum type)])
(cond
[(eq? t* 'const-double*)
#`(ftype-pointer-address
(double-array-create-from-vector #,name))]
[(eq? t* 'double) #`(real->flonum #,name)]
[(and (string-prefix? "cairo-" (symbol->string t))
(string-suffix? "*" (symbol->string t)))
#`(if (ftype-pointer? #,(datum->syntax type (remove-* t)) #,name)
(ftype-pointer-address #,name)
(assertion-violation 'convert-scheme->c "wrong pointer type for argument" (quote #,function-name) (quote #,name) (quote #,type) #,name))]
[else name])))
|
| ︙ | ︙ | |||
405 406 407 408 409 410 411 |
[(cairo-path-t*) #'(cairo-guard-pointer (make-ftype-pointer cairo-path-t result))]
[(cairo-device-t*) #'(cairo-guard-pointer (make-ftype-pointer cairo-device-t result))]
[else #'result]))))))])))
(define-syntax define-ftype-allocator
(lambda (x)
(syntax-case x ()
| > > | > > > > > > > | 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
[(cairo-path-t*) #'(cairo-guard-pointer (make-ftype-pointer cairo-path-t result))]
[(cairo-device-t*) #'(cairo-guard-pointer (make-ftype-pointer cairo-device-t result))]
[else #'result]))))))])))
(define-syntax define-ftype-allocator
(lambda (x)
(syntax-case x ()
[(_ name type)
#'(define (name)
(cairo-guard-pointer (make-ftype-pointer type (foreign-alloc (ftype-sizeof type)))))])))
(define-syntax define-ftype-array-allocator
(lambda (x)
(syntax-case x ()
[(_ name type element-type)
#'(define (name size)
(cairo-guard-pointer (make-ftype-pointer type (foreign-alloc (* (ftype-sizeof element-type) size)))))])))
(define (cairo-library-init . t) (load-shared-object (if (null? t) "libcairo.so" (car t))))
(define-ftype cairo-bool-t int)
(define-ftype int* void*)
|
| ︙ | ︙ | |||
438 439 440 441 442 443 444 |
[yx double]
[xy double]
[yy double]
[x0 double]
[y0 double]))
(define-ftype cairo-matrix-t* void*)
| | | 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
[yx double]
[xy double]
[yy double]
[x0 double]
[y0 double]))
(define-ftype cairo-matrix-t* void*)
(define-ftype-allocator cairo-matrix-create cairo-matrix-t)
(define-ftype cairo-pattern-t (struct))
(define-ftype cairo-pattern-t* void*)
(define-ftype cairo-destroy-func-t (function (void*) void))
(define-ftype cairo-destroy-func-t* void*)
|
| ︙ | ︙ | |||
492 493 494 495 496 497 498 | (function (void* void* unsigned-int) cairo-status-t)) (define-ftype cairo-read-func-t* void*) (define-ftype cairo-rectangle-int-t (struct [x int] [y int] [width int] [height int])) | | | 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | (function (void* void* unsigned-int) cairo-status-t)) (define-ftype cairo-read-func-t* void*) (define-ftype cairo-rectangle-int-t (struct [x int] [y int] [width int] [height int])) (define-ftype-allocator cairo-rectangle-int-create cairo-rectangle-int-t) (define-ftype cairo-rectangle-int-t* void*) (define-enumeration* cairo-operator (clear source over in out atop dest dest-over dest-in dest-out dest-atop xor add saturate multiply screen overlay darken lighten color-dodge color-burn hard-light soft-light |
| ︙ | ︙ | |||
526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
(define-enumeration* cairo-line-join
(miter round bevel))
(define-ftype cairo-line-join-t int)
(define-ftype double* void*)
(define-ftype cairo-rectangle-t
(struct
[x double]
[y double]
[width double]
[height double]))
| > > > > > > > > > > > > > | 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
(define-enumeration* cairo-line-join
(miter round bevel))
(define-ftype cairo-line-join-t int)
(define-ftype double* void*)
(define-ftype double-array (array 0 double))
(define-ftype-array-allocator double-array-create double-array double)
(define (double-array-create-from-vector l)
(let* ([ls (vector->list l)]
[size (vector-length l)]
[array (double-array-create size)])
(do ([i 0 (fx1+ i)])
((fx>= i size))
(let ([x (vector-ref l i)]
[r (ftype-&ref double-array (i) array)])
(ftype-set! double () r x)))
array))
(define-ftype cairo-rectangle-t
(struct
[x double]
[y double]
[width double]
[height double]))
|
| ︙ | ︙ |