cairo 1.8.3-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of cairo might be problematic. Click here for more details.
- data/AUTHORS +4 -0
- data/COPYING +59 -0
- data/GPL +340 -0
- data/NEWS +163 -0
- data/Rakefile +190 -0
- data/doc/doc.css +91 -0
- data/doc/en/cairo-antialias.html +38 -0
- data/doc/en/cairo-clip-not-representable-error.html +47 -0
- data/doc/en/cairo-color-base.html +69 -0
- data/doc/en/cairo-color-cmyk.html +157 -0
- data/doc/en/cairo-color-hsv.html +137 -0
- data/doc/en/cairo-color-rgb.html +142 -0
- data/doc/en/cairo-color-x11.html +173 -0
- data/doc/en/cairo-color.html +238 -0
- data/doc/en/cairo-content.html +37 -0
- data/doc/en/cairo-context-blur.html +39 -0
- data/doc/en/cairo-context-circle.html +39 -0
- data/doc/en/cairo-context-color.html +39 -0
- data/doc/en/cairo-context-path.html +44 -0
- data/doc/en/cairo-context-rectangle.html +39 -0
- data/doc/en/cairo-context-triangle.html +39 -0
- data/doc/en/cairo-context.html +643 -0
- data/doc/en/cairo-error.html +44 -0
- data/doc/en/cairo-extend.html +38 -0
- data/doc/en/cairo-file-not-found.html +47 -0
- data/doc/en/cairo-fill-rule.html +36 -0
- data/doc/en/cairo-filter.html +40 -0
- data/doc/en/cairo-font-extents.html +129 -0
- data/doc/en/cairo-font-face.html +38 -0
- data/doc/en/cairo-font-options.html +139 -0
- data/doc/en/cairo-font-slant.html +37 -0
- data/doc/en/cairo-font-type-mismatch.html +47 -0
- data/doc/en/cairo-font-weight.html +36 -0
- data/doc/en/cairo-format.html +46 -0
- data/doc/en/cairo-glyph.html +99 -0
- data/doc/en/cairo-gradient-pattern.html +74 -0
- data/doc/en/cairo-hint-metrics.html +37 -0
- data/doc/en/cairo-hint-style.html +39 -0
- data/doc/en/cairo-image-surface.html +82 -0
- data/doc/en/cairo-invalid-clusters.html +47 -0
- data/doc/en/cairo-invalid-content-error.html +47 -0
- data/doc/en/cairo-invalid-dash-error.html +47 -0
- data/doc/en/cairo-invalid-dsc-comment-error.html +47 -0
- data/doc/en/cairo-invalid-format-error.html +47 -0
- data/doc/en/cairo-invalid-index-error.html +47 -0
- data/doc/en/cairo-invalid-matrix-error.html +47 -0
- data/doc/en/cairo-invalid-path-data-error.html +47 -0
- data/doc/en/cairo-invalid-pop-group-error.html +47 -0
- data/doc/en/cairo-invalid-restore-error.html +47 -0
- data/doc/en/cairo-invalid-slant.html +47 -0
- data/doc/en/cairo-invalid-status-error.html +47 -0
- data/doc/en/cairo-invalid-stride-error.html +47 -0
- data/doc/en/cairo-invalid-string-error.html +47 -0
- data/doc/en/cairo-invalid-visual-error.html +47 -0
- data/doc/en/cairo-invalid-weight.html +47 -0
- data/doc/en/cairo-line-cap.html +37 -0
- data/doc/en/cairo-line-join.html +37 -0
- data/doc/en/cairo-linear-pattern.html +60 -0
- data/doc/en/cairo-matrix.html +259 -0
- data/doc/en/cairo-negative-count.html +47 -0
- data/doc/en/cairo-no-current-point-error.html +47 -0
- data/doc/en/cairo-null-pointer-error.html +47 -0
- data/doc/en/cairo-operator.html +48 -0
- data/doc/en/cairo-paper-parse-error.html +47 -0
- data/doc/en/cairo-paper-unknown-paper-name.html +66 -0
- data/doc/en/cairo-paper-unknown-unit.html +66 -0
- data/doc/en/cairo-paper-unrecognized-paper-description.html +66 -0
- data/doc/en/cairo-paper.html +184 -0
- data/doc/en/cairo-path-close-path.html +49 -0
- data/doc/en/cairo-path-curve-to.html +49 -0
- data/doc/en/cairo-path-data-type.html +38 -0
- data/doc/en/cairo-path-data.html +98 -0
- data/doc/en/cairo-path-line-to.html +49 -0
- data/doc/en/cairo-path-move-to.html +49 -0
- data/doc/en/cairo-path.html +155 -0
- data/doc/en/cairo-pattern-type-mismatch-error.html +47 -0
- data/doc/en/cairo-pattern.html +99 -0
- data/doc/en/cairo-pdf-surface.html +57 -0
- data/doc/en/cairo-point.html +74 -0
- data/doc/en/cairo-ps-level.html +49 -0
- data/doc/en/cairo-ps-surface.html +92 -0
- data/doc/en/cairo-quartz-image-surface.html +57 -0
- data/doc/en/cairo-quartz-surface.html +57 -0
- data/doc/en/cairo-radial-pattern.html +60 -0
- data/doc/en/cairo-read-error.html +47 -0
- data/doc/en/cairo-rectangle.html +89 -0
- data/doc/en/cairo-scaled-font.html +94 -0
- data/doc/en/cairo-solid-pattern.html +62 -0
- data/doc/en/cairo-subpixel-order.html +39 -0
- data/doc/en/cairo-surface-finished-error.html +47 -0
- data/doc/en/cairo-surface-pattern.html +57 -0
- data/doc/en/cairo-surface-type-mismatch-error.html +47 -0
- data/doc/en/cairo-surface.html +121 -0
- data/doc/en/cairo-svg-surface.html +77 -0
- data/doc/en/cairo-svg-version.html +49 -0
- data/doc/en/cairo-temp-file-error.html +47 -0
- data/doc/en/cairo-text-cluster-flag.html +35 -0
- data/doc/en/cairo-text-cluster.html +84 -0
- data/doc/en/cairo-text-extents.html +144 -0
- data/doc/en/cairo-toy-font-face.html +67 -0
- data/doc/en/cairo-user-font-error.html +47 -0
- data/doc/en/cairo-user-font-face-text-to-glyphs-data.html +94 -0
- data/doc/en/cairo-user-font-face.html +72 -0
- data/doc/en/cairo-user-font-immutable.html +47 -0
- data/doc/en/cairo-win32-printing-surface.html +57 -0
- data/doc/en/cairo-win32-surface.html +62 -0
- data/doc/en/cairo-write-error.html +47 -0
- data/doc/en/cairo.html +131 -0
- data/doc/en/index.html +1154 -0
- data/doc/index.html +18 -0
- data/doc/ja/cairo-antialias.html +57 -0
- data/doc/ja/cairo-clip-not-representable-error.html +56 -0
- data/doc/ja/cairo-color-base.html +75 -0
- data/doc/ja/cairo-color-cmyk.html +152 -0
- data/doc/ja/cairo-color-hsv.html +135 -0
- data/doc/ja/cairo-color-rgb.html +145 -0
- data/doc/ja/cairo-color-x11.html +183 -0
- data/doc/ja/cairo-color.html +317 -0
- data/doc/ja/cairo-content.html +51 -0
- data/doc/ja/cairo-context-blur.html +53 -0
- data/doc/ja/cairo-context-circle.html +54 -0
- data/doc/ja/cairo-context-color.html +52 -0
- data/doc/ja/cairo-context-path.html +77 -0
- data/doc/ja/cairo-context-rectangle.html +60 -0
- data/doc/ja/cairo-context-triangle.html +47 -0
- data/doc/ja/cairo-context.html +1542 -0
- data/doc/ja/cairo-error.html +56 -0
- data/doc/ja/cairo-extend.html +56 -0
- data/doc/ja/cairo-file-not-found.html +51 -0
- data/doc/ja/cairo-fill-rule.html +58 -0
- data/doc/ja/cairo-filter.html +43 -0
- data/doc/ja/cairo-font-extents.html +164 -0
- data/doc/ja/cairo-font-face.html +55 -0
- data/doc/ja/cairo-font-options.html +189 -0
- data/doc/ja/cairo-font-slant.html +50 -0
- data/doc/ja/cairo-font-type-mismatch.html +52 -0
- data/doc/ja/cairo-font-weight.html +47 -0
- data/doc/ja/cairo-format.html +81 -0
- data/doc/ja/cairo-glyph.html +115 -0
- data/doc/ja/cairo-gradient-pattern.html +119 -0
- data/doc/ja/cairo-hint-metrics.html +57 -0
- data/doc/ja/cairo-hint-style.html +64 -0
- data/doc/ja/cairo-image-surface.html +131 -0
- data/doc/ja/cairo-invalid-clusters.html +55 -0
- data/doc/ja/cairo-invalid-content-error.html +54 -0
- data/doc/ja/cairo-invalid-dash-error.html +54 -0
- data/doc/ja/cairo-invalid-dsc-comment-error.html +54 -0
- data/doc/ja/cairo-invalid-format-error.html +54 -0
- data/doc/ja/cairo-invalid-index-error.html +54 -0
- data/doc/ja/cairo-invalid-matrix-error.html +54 -0
- data/doc/ja/cairo-invalid-path-data-error.html +54 -0
- data/doc/ja/cairo-invalid-pop-group-error.html +54 -0
- data/doc/ja/cairo-invalid-restore-error.html +55 -0
- data/doc/ja/cairo-invalid-slant.html +57 -0
- data/doc/ja/cairo-invalid-status-error.html +55 -0
- data/doc/ja/cairo-invalid-stride-error.html +55 -0
- data/doc/ja/cairo-invalid-string-error.html +54 -0
- data/doc/ja/cairo-invalid-visual-error.html +57 -0
- data/doc/ja/cairo-invalid-weight.html +57 -0
- data/doc/ja/cairo-line-cap.html +50 -0
- data/doc/ja/cairo-line-join.html +53 -0
- data/doc/ja/cairo-linear-pattern.html +87 -0
- data/doc/ja/cairo-matrix.html +354 -0
- data/doc/ja/cairo-negative-count.html +52 -0
- data/doc/ja/cairo-no-current-point-error.html +54 -0
- data/doc/ja/cairo-null-pointer-error.html +54 -0
- data/doc/ja/cairo-operator.html +51 -0
- data/doc/ja/cairo-paper-parse-error.html +55 -0
- data/doc/ja/cairo-paper-unknown-paper-name.html +76 -0
- data/doc/ja/cairo-paper-unknown-unit.html +75 -0
- data/doc/ja/cairo-paper-unrecognized-paper-description.html +76 -0
- data/doc/ja/cairo-paper.html +357 -0
- data/doc/ja/cairo-path-close-path.html +57 -0
- data/doc/ja/cairo-path-curve-to.html +70 -0
- data/doc/ja/cairo-path-data-type.html +53 -0
- data/doc/ja/cairo-path-data.html +127 -0
- data/doc/ja/cairo-path-line-to.html +62 -0
- data/doc/ja/cairo-path-move-to.html +62 -0
- data/doc/ja/cairo-path.html +144 -0
- data/doc/ja/cairo-pattern-type-mismatch-error.html +56 -0
- data/doc/ja/cairo-pattern.html +128 -0
- data/doc/ja/cairo-pdf-surface.html +86 -0
- data/doc/ja/cairo-point.html +90 -0
- data/doc/ja/cairo-ps-level.html +62 -0
- data/doc/ja/cairo-ps-surface.html +214 -0
- data/doc/ja/cairo-quartz-image-surface.html +75 -0
- data/doc/ja/cairo-quartz-surface.html +93 -0
- data/doc/ja/cairo-radial-pattern.html +93 -0
- data/doc/ja/cairo-read-error.html +55 -0
- data/doc/ja/cairo-rectangle.html +109 -0
- data/doc/ja/cairo-scaled-font.html +180 -0
- data/doc/ja/cairo-solid-pattern.html +87 -0
- data/doc/ja/cairo-subpixel-order.html +57 -0
- data/doc/ja/cairo-surface-finished-error.html +54 -0
- data/doc/ja/cairo-surface-pattern.html +68 -0
- data/doc/ja/cairo-surface-type-mismatch-error.html +56 -0
- data/doc/ja/cairo-surface.html +213 -0
- data/doc/ja/cairo-svg-surface.html +114 -0
- data/doc/ja/cairo-svg-version.html +66 -0
- data/doc/ja/cairo-temp-file-error.html +50 -0
- data/doc/ja/cairo-text-cluster-flag.html +46 -0
- data/doc/ja/cairo-text-cluster.html +102 -0
- data/doc/ja/cairo-text-extents.html +163 -0
- data/doc/ja/cairo-toy-font-face.html +107 -0
- data/doc/ja/cairo-user-font-error.html +55 -0
- data/doc/ja/cairo-user-font-face-text-to-glyphs-data.html +156 -0
- data/doc/ja/cairo-user-font-face.html +268 -0
- data/doc/ja/cairo-user-font-immutable.html +54 -0
- data/doc/ja/cairo-win32-printing-surface.html +80 -0
- data/doc/ja/cairo-win32-surface.html +100 -0
- data/doc/ja/cairo-write-error.html +55 -0
- data/doc/ja/cairo.html +177 -0
- data/doc/ja/index.html +1156 -0
- data/ext/cairo/cairo.def +104 -0
- data/ext/cairo/extconf.rb +80 -0
- data/ext/cairo/rb_cairo.c +104 -0
- data/ext/cairo/rb_cairo.h +275 -0
- data/ext/cairo/rb_cairo_constants.c +478 -0
- data/ext/cairo/rb_cairo_context.c +1693 -0
- data/ext/cairo/rb_cairo_exception.c +354 -0
- data/ext/cairo/rb_cairo_font_extents.c +200 -0
- data/ext/cairo/rb_cairo_font_face.c +713 -0
- data/ext/cairo/rb_cairo_font_options.c +197 -0
- data/ext/cairo/rb_cairo_glyph.c +161 -0
- data/ext/cairo/rb_cairo_matrix.c +366 -0
- data/ext/cairo/rb_cairo_path.c +459 -0
- data/ext/cairo/rb_cairo_pattern.c +540 -0
- data/ext/cairo/rb_cairo_private.c +242 -0
- data/ext/cairo/rb_cairo_private.h +114 -0
- data/ext/cairo/rb_cairo_scaled_font.c +235 -0
- data/ext/cairo/rb_cairo_surface.c +1371 -0
- data/ext/cairo/rb_cairo_text_cluster.c +151 -0
- data/ext/cairo/rb_cairo_text_extents.c +221 -0
- data/extconf.rb +45 -0
- data/lib/1.8/cairo.so +0 -0
- data/lib/1.9/cairo.so +0 -0
- data/lib/cairo.rb +151 -0
- data/lib/cairo/color.rb +267 -0
- data/lib/cairo/colors.rb +656 -0
- data/lib/cairo/constants.rb +24 -0
- data/lib/cairo/context.rb +29 -0
- data/lib/cairo/context/blur.rb +45 -0
- data/lib/cairo/context/circle.rb +9 -0
- data/lib/cairo/context/color.rb +11 -0
- data/lib/cairo/context/path.rb +116 -0
- data/lib/cairo/context/rectangle.rb +33 -0
- data/lib/cairo/context/triangle.rb +12 -0
- data/lib/cairo/paper.rb +183 -0
- data/lib/cairo/papers.rb +41 -0
- data/lib/cairo/path.rb +15 -0
- data/lib/cairo/point.rb +7 -0
- data/misc/update-colors.rb +143 -0
- data/pkg-config.rb +313 -0
- data/samples/agg/README +4 -0
- data/samples/agg/aa_test.rb +304 -0
- data/samples/blur.rb +47 -0
- data/samples/pac.rb +99 -0
- data/samples/pac2.rb +171 -0
- data/samples/png.rb +45 -0
- data/samples/scalable.rb +56 -0
- data/samples/text-on-path.rb +60 -0
- data/samples/text2.rb +131 -0
- data/test-unit/Rakefile +30 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/lib/test/unit.rb +280 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
- data/test-unit/lib/test/unit/assertions.rb +722 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +254 -0
- data/test-unit/lib/test/unit/collector.rb +43 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +135 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color.rb +61 -0
- data/test-unit/lib/test/unit/diff.rb +524 -0
- data/test-unit/lib/test/unit/error.rb +124 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +110 -0
- data/test-unit/lib/test/unit/fixture.rb +185 -0
- data/test-unit/lib/test/unit/notification.rb +125 -0
- data/test-unit/lib/test/unit/omission.rb +143 -0
- data/test-unit/lib/test/unit/pending.rb +146 -0
- data/test-unit/lib/test/unit/priority.rb +146 -0
- data/test-unit/lib/test/unit/runner/console.rb +46 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +281 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +195 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/tc_adder.rb +18 -0
- data/test-unit/sample/tc_subtracter.rb +18 -0
- data/test-unit/sample/ts_examples.rb +7 -0
- data/test-unit/test/collector/test_descendant.rb +135 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_load.rb +333 -0
- data/test-unit/test/collector/test_objectspace.rb +98 -0
- data/test-unit/test/run-test.rb +13 -0
- data/test-unit/test/test_assertions.rb +693 -0
- data/test-unit/test/test_attribute.rb +86 -0
- data/test-unit/test/test_color.rb +37 -0
- data/test-unit/test/test_diff.rb +477 -0
- data/test-unit/test/test_emacs_runner.rb +60 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_fixture.rb +252 -0
- data/test-unit/test/test_notification.rb +33 -0
- data/test-unit/test/test_omission.rb +81 -0
- data/test-unit/test/test_pending.rb +70 -0
- data/test-unit/test/test_priority.rb +89 -0
- data/test-unit/test/test_testcase.rb +430 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit_test_util.rb +14 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/cairo-test-utils.rb +18 -0
- data/test/run-test.rb +28 -0
- data/test/test_color.rb +17 -0
- data/test/test_constants.rb +16 -0
- data/test/test_context.rb +105 -0
- data/test/test_exception.rb +27 -0
- data/test/test_font_extents.rb +36 -0
- data/test/test_font_face.rb +244 -0
- data/test/test_font_options.rb +13 -0
- data/test/test_paper.rb +81 -0
- data/test/test_pkg_config.rb +123 -0
- data/test/test_scaled_font.rb +34 -0
- data/test/test_surface.rb +41 -0
- data/test/test_text_cluster.rb +32 -0
- data/test/test_text_extents.rb +40 -0
- data/test/test_text_to_glyphs_data.rb +51 -0
- data/tmp/x86-mingw32/cairo/1.8.7/fake.rb +6 -0
- data/tmp/x86-mingw32/cairo/1.8.7/mkmf.rb +1836 -0
- data/tmp/x86-mingw32/cairo/1.8.7/rbconfig.rb +183 -0
- data/tmp/x86-mingw32/cairo/1.9.2/fake.rb +6 -0
- data/tmp/x86-mingw32/cairo/1.9.2/mkmf.rb +2079 -0
- data/tmp/x86-mingw32/cairo/1.9.2/rbconfig.rb +226 -0
- metadata +437 -0
@@ -0,0 +1,1371 @@
|
|
1
|
+
/* -*- c-file-style: "gnu"; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Ruby Cairo Binding
|
4
|
+
*
|
5
|
+
* $Author: kou $
|
6
|
+
* $Date: 2008-11-01 14:23:14 $
|
7
|
+
*
|
8
|
+
* Copyright 2005 Øyvind Kolås <pippin@freedesktop.org>
|
9
|
+
* Copyright 2004-2005 MenTaLguY <mental@rydia.com>
|
10
|
+
*
|
11
|
+
* This file is made available under the same terms as Ruby
|
12
|
+
*
|
13
|
+
*/
|
14
|
+
|
15
|
+
#include "rb_cairo.h"
|
16
|
+
#include "rb_cairo_private.h"
|
17
|
+
|
18
|
+
#ifdef HAVE_RUBY_ST_H
|
19
|
+
# include <ruby/st.h>
|
20
|
+
#else
|
21
|
+
# include <st.h>
|
22
|
+
#endif
|
23
|
+
|
24
|
+
#ifdef CAIRO_HAS_WIN32_SURFACE
|
25
|
+
# define OpenFile OpenFile_win32
|
26
|
+
# include <cairo-win32.h>
|
27
|
+
# undef OpenFile
|
28
|
+
#endif
|
29
|
+
|
30
|
+
#ifdef HAVE_RUBY_IO_H
|
31
|
+
# include <ruby/io.h>
|
32
|
+
#else
|
33
|
+
# include <rubyio.h>
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#ifdef CAIRO_HAS_QUARTZ_SURFACE
|
37
|
+
# ifndef HAVE_TYPE_ENUM_RUBY_VALUE_TYPE
|
38
|
+
enum ruby_value_type {
|
39
|
+
RUBY_T_DATA = T_DATA
|
40
|
+
};
|
41
|
+
# endif
|
42
|
+
# undef T_DATA
|
43
|
+
# include <cairo-quartz.h>
|
44
|
+
# define T_DATA RUBY_T_DATA
|
45
|
+
#endif
|
46
|
+
|
47
|
+
#if defined(CAIRO_HAS_PS_SURFACE) || \
|
48
|
+
defined(CAIRO_HAS_PDF_SURFACE) || \
|
49
|
+
defined(CAIRO_HAS_SVG_SURFACE)
|
50
|
+
# define HAS_CREATE_CR_CLOSURE_SURFACE 1
|
51
|
+
#else
|
52
|
+
# define HAS_CREATE_CR_CLOSURE_SURFACE 0
|
53
|
+
#endif
|
54
|
+
|
55
|
+
|
56
|
+
VALUE rb_cCairo_Surface;
|
57
|
+
VALUE rb_cCairo_ImageSurface;
|
58
|
+
VALUE rb_cCairo_PDFSurface = Qnil;
|
59
|
+
VALUE rb_cCairo_PSSurface = Qnil;
|
60
|
+
VALUE rb_cCairo_SVGSurface = Qnil;
|
61
|
+
VALUE rb_cCairo_Win32Surface = Qnil;
|
62
|
+
VALUE rb_cCairo_Win32PrintingSurface = Qnil;
|
63
|
+
VALUE rb_cCairo_QuartzSurface = Qnil;
|
64
|
+
VALUE rb_cCairo_QuartzImageSurface = Qnil;
|
65
|
+
|
66
|
+
static ID cr_id_target;
|
67
|
+
static ID cr_id_read;
|
68
|
+
static ID cr_id_write;
|
69
|
+
static ID cr_id_inspect;
|
70
|
+
static ID cr_id_parse;
|
71
|
+
static ID cr_id_size;
|
72
|
+
static ID cr_id_set_unit;
|
73
|
+
static cairo_user_data_key_t cr_closure_key;
|
74
|
+
static cairo_user_data_key_t cr_object_holder_key;
|
75
|
+
static cairo_user_data_key_t cr_finished_key;
|
76
|
+
|
77
|
+
#define _SELF (RVAL2CRSURFACE(self))
|
78
|
+
|
79
|
+
static VALUE
|
80
|
+
cr_paper_parse (VALUE paper_description)
|
81
|
+
{
|
82
|
+
return rb_funcall (rb_cCairo_Paper, cr_id_parse, 2, paper_description, Qtrue);
|
83
|
+
}
|
84
|
+
|
85
|
+
static void
|
86
|
+
cr_paper_to_size_in_points (VALUE paper_description, VALUE *width, VALUE *height)
|
87
|
+
{
|
88
|
+
VALUE paper, size;
|
89
|
+
|
90
|
+
paper = cr_paper_parse (paper_description);
|
91
|
+
size = rb_funcall (paper, cr_id_size, 1, rb_str_new2 ("pt"));
|
92
|
+
*width = RARRAY_PTR (size)[0];
|
93
|
+
*height = RARRAY_PTR (size)[1];
|
94
|
+
}
|
95
|
+
|
96
|
+
static inline void
|
97
|
+
cr_surface_check_status (cairo_surface_t *surface)
|
98
|
+
{
|
99
|
+
rb_cairo_check_status (cairo_surface_status (surface));
|
100
|
+
}
|
101
|
+
|
102
|
+
static VALUE
|
103
|
+
cr_surface_get_klass (cairo_surface_t *surface)
|
104
|
+
{
|
105
|
+
VALUE klass;
|
106
|
+
cairo_surface_type_t type;
|
107
|
+
|
108
|
+
type = cairo_surface_get_type (surface);
|
109
|
+
switch (type)
|
110
|
+
{
|
111
|
+
case CAIRO_SURFACE_TYPE_IMAGE:
|
112
|
+
klass = rb_cCairo_ImageSurface;
|
113
|
+
break;
|
114
|
+
case CAIRO_SURFACE_TYPE_PDF:
|
115
|
+
klass = rb_cCairo_PDFSurface;
|
116
|
+
break;
|
117
|
+
case CAIRO_SURFACE_TYPE_PS:
|
118
|
+
klass = rb_cCairo_PSSurface;
|
119
|
+
break;
|
120
|
+
case CAIRO_SURFACE_TYPE_QUARTZ:
|
121
|
+
klass = rb_cCairo_QuartzSurface;
|
122
|
+
break;
|
123
|
+
case CAIRO_SURFACE_TYPE_WIN32:
|
124
|
+
klass = rb_cCairo_Win32Surface;
|
125
|
+
break;
|
126
|
+
case CAIRO_SURFACE_TYPE_SVG:
|
127
|
+
klass = rb_cCairo_SVGSurface;
|
128
|
+
break;
|
129
|
+
#if CAIRO_CHECK_VERSION(1, 5, 2)
|
130
|
+
case CAIRO_SURFACE_TYPE_WIN32_PRINTING:
|
131
|
+
klass = rb_cCairo_Win32PrintingSurface;
|
132
|
+
break;
|
133
|
+
#endif
|
134
|
+
#if CAIRO_CHECK_VERSION(1, 5, 12)
|
135
|
+
case CAIRO_SURFACE_TYPE_QUARTZ_IMAGE:
|
136
|
+
klass = rb_cCairo_QuartzImageSurface;
|
137
|
+
break;
|
138
|
+
#endif
|
139
|
+
default:
|
140
|
+
klass = rb_cCairo_Surface;
|
141
|
+
break;
|
142
|
+
}
|
143
|
+
|
144
|
+
if (NIL_P (klass))
|
145
|
+
rb_raise (rb_eArgError, "unknown source type: %d", type);
|
146
|
+
|
147
|
+
return klass;
|
148
|
+
}
|
149
|
+
|
150
|
+
static char *
|
151
|
+
inspect (VALUE object)
|
152
|
+
{
|
153
|
+
VALUE inspected;
|
154
|
+
inspected = rb_funcall (object, cr_id_inspect, 0);
|
155
|
+
return StringValueCStr(inspected);
|
156
|
+
}
|
157
|
+
|
158
|
+
/* read/write callback */
|
159
|
+
typedef struct cr_io_callback_closure {
|
160
|
+
VALUE target;
|
161
|
+
VALUE error;
|
162
|
+
unsigned char *data;
|
163
|
+
unsigned int length;
|
164
|
+
} cr_io_callback_closure_t;
|
165
|
+
|
166
|
+
typedef struct cr_invoke_data {
|
167
|
+
cr_callback_func_t func;
|
168
|
+
VALUE data;
|
169
|
+
} cr_invoke_data_t;
|
170
|
+
|
171
|
+
#if HAS_CREATE_CR_CLOSURE_SURFACE
|
172
|
+
static cr_io_callback_closure_t *
|
173
|
+
cr_closure_new (VALUE target)
|
174
|
+
{
|
175
|
+
cr_io_callback_closure_t *closure;
|
176
|
+
closure = ALLOC (cr_io_callback_closure_t);
|
177
|
+
|
178
|
+
closure->target = target;
|
179
|
+
closure->error = Qnil;
|
180
|
+
|
181
|
+
return closure;
|
182
|
+
}
|
183
|
+
|
184
|
+
static void
|
185
|
+
cr_closure_destroy (cr_io_callback_closure_t *closure)
|
186
|
+
{
|
187
|
+
xfree (closure);
|
188
|
+
}
|
189
|
+
|
190
|
+
static void
|
191
|
+
cr_closure_free (void *closure)
|
192
|
+
{
|
193
|
+
cr_closure_destroy ((cr_io_callback_closure_t *) closure);
|
194
|
+
}
|
195
|
+
#endif
|
196
|
+
|
197
|
+
static VALUE
|
198
|
+
cr_surface_io_func_rescue (VALUE io_closure)
|
199
|
+
{
|
200
|
+
cr_io_callback_closure_t *closure;
|
201
|
+
closure = (cr_io_callback_closure_t *)io_closure;
|
202
|
+
closure->error = RB_ERRINFO;
|
203
|
+
return Qnil;
|
204
|
+
}
|
205
|
+
|
206
|
+
static VALUE
|
207
|
+
cr_surface_invoke_io_func (VALUE user_data)
|
208
|
+
{
|
209
|
+
cr_invoke_data_t *data;
|
210
|
+
|
211
|
+
data = (cr_invoke_data_t *)user_data;
|
212
|
+
return rb_rescue2 (data->func, data->data,
|
213
|
+
cr_surface_io_func_rescue, data->data, rb_eException,
|
214
|
+
(VALUE)0);
|
215
|
+
}
|
216
|
+
|
217
|
+
/* write callback */
|
218
|
+
static VALUE
|
219
|
+
cr_surface_write_func_invoke (VALUE write_closure)
|
220
|
+
{
|
221
|
+
VALUE output, data;
|
222
|
+
long written_bytes;
|
223
|
+
cr_io_callback_closure_t *closure;
|
224
|
+
unsigned int length;
|
225
|
+
|
226
|
+
closure = (cr_io_callback_closure_t *)write_closure;
|
227
|
+
|
228
|
+
output = closure->target;
|
229
|
+
data = rb_str_new ((const char *)closure->data, closure->length);
|
230
|
+
|
231
|
+
length = RSTRING_LEN (data);
|
232
|
+
while (length != 0)
|
233
|
+
{
|
234
|
+
VALUE rb_written_bytes = rb_funcall (output, cr_id_write, 1, data);
|
235
|
+
written_bytes = NUM2LONG (rb_written_bytes);
|
236
|
+
data = rb_str_substr (data, written_bytes,
|
237
|
+
RSTRING_LEN (data) - written_bytes);
|
238
|
+
length -= written_bytes;
|
239
|
+
}
|
240
|
+
|
241
|
+
return Qnil;
|
242
|
+
}
|
243
|
+
|
244
|
+
static cairo_status_t
|
245
|
+
cr_surface_write_func (void *write_closure,
|
246
|
+
const unsigned char *data, unsigned int length)
|
247
|
+
{
|
248
|
+
cr_io_callback_closure_t *closure;
|
249
|
+
cr_invoke_data_t invoke_data;
|
250
|
+
|
251
|
+
closure = (cr_io_callback_closure_t *)write_closure;
|
252
|
+
closure->data = (unsigned char *)data;
|
253
|
+
closure->length = length;
|
254
|
+
|
255
|
+
invoke_data.func = cr_surface_write_func_invoke;
|
256
|
+
invoke_data.data = (VALUE)closure;
|
257
|
+
rb_cairo__invoke_callback (cr_surface_invoke_io_func, (VALUE)&invoke_data);
|
258
|
+
|
259
|
+
if (NIL_P (closure->error))
|
260
|
+
return CAIRO_STATUS_SUCCESS;
|
261
|
+
else
|
262
|
+
return CAIRO_STATUS_WRITE_ERROR;
|
263
|
+
}
|
264
|
+
|
265
|
+
/* read callback */
|
266
|
+
static VALUE
|
267
|
+
cr_surface_read_func_invoke (VALUE read_closure)
|
268
|
+
{
|
269
|
+
VALUE input, result;
|
270
|
+
cr_io_callback_closure_t *closure;
|
271
|
+
unsigned int length, rest;
|
272
|
+
|
273
|
+
closure = (cr_io_callback_closure_t *)read_closure;
|
274
|
+
input = closure->target;
|
275
|
+
length = closure->length;
|
276
|
+
|
277
|
+
result = rb_str_new2 ("");
|
278
|
+
|
279
|
+
for (rest = length; rest != 0; rest = length - RSTRING_LEN (result))
|
280
|
+
{
|
281
|
+
rb_str_concat (result, rb_funcall (input, cr_id_read, 1, INT2NUM (rest)));
|
282
|
+
}
|
283
|
+
|
284
|
+
memcpy ((void *)closure->data, (const void *)StringValuePtr (result), length);
|
285
|
+
|
286
|
+
return Qnil;
|
287
|
+
}
|
288
|
+
|
289
|
+
static cairo_status_t
|
290
|
+
cr_surface_read_func (void *read_closure,
|
291
|
+
unsigned char *data, unsigned int length)
|
292
|
+
{
|
293
|
+
cr_io_callback_closure_t *closure;
|
294
|
+
cr_invoke_data_t invoke_data;
|
295
|
+
|
296
|
+
closure = (cr_io_callback_closure_t *)read_closure;
|
297
|
+
closure->data = data;
|
298
|
+
closure->length = length;
|
299
|
+
|
300
|
+
invoke_data.func = cr_surface_read_func_invoke;
|
301
|
+
invoke_data.data = (VALUE)closure;
|
302
|
+
rb_cairo__invoke_callback (cr_surface_invoke_io_func, (VALUE)&invoke_data);
|
303
|
+
|
304
|
+
if (NIL_P (closure->error))
|
305
|
+
return CAIRO_STATUS_SUCCESS;
|
306
|
+
else
|
307
|
+
return CAIRO_STATUS_READ_ERROR;
|
308
|
+
}
|
309
|
+
|
310
|
+
/* constructor/de-constructor */
|
311
|
+
cairo_surface_t *
|
312
|
+
rb_cairo_surface_from_ruby_object (VALUE obj)
|
313
|
+
{
|
314
|
+
cairo_surface_t *surface;
|
315
|
+
if (!rb_cairo__is_kind_of (obj, rb_cCairo_Surface))
|
316
|
+
{
|
317
|
+
rb_raise (rb_eTypeError, "not a cairo surface");
|
318
|
+
}
|
319
|
+
Data_Get_Struct (obj, cairo_surface_t, surface);
|
320
|
+
if (!surface)
|
321
|
+
rb_cairo_check_status (CAIRO_STATUS_NULL_POINTER);
|
322
|
+
return surface;
|
323
|
+
}
|
324
|
+
|
325
|
+
static rb_cairo__object_holder_t *
|
326
|
+
cr_object_holder_new (VALUE object)
|
327
|
+
{
|
328
|
+
return rb_cairo__object_holder_new (rb_cCairo_Surface, object);
|
329
|
+
}
|
330
|
+
|
331
|
+
static void
|
332
|
+
cr_object_holder_free (void *ptr)
|
333
|
+
{
|
334
|
+
rb_cairo__object_holder_free (rb_cCairo_Surface, ptr);
|
335
|
+
}
|
336
|
+
|
337
|
+
static void
|
338
|
+
cr_surface_free (void *ptr)
|
339
|
+
{
|
340
|
+
cairo_surface_t *surface = ptr;
|
341
|
+
|
342
|
+
if (surface)
|
343
|
+
cairo_surface_destroy (surface);
|
344
|
+
}
|
345
|
+
|
346
|
+
VALUE
|
347
|
+
rb_cairo_surface_to_ruby_object (cairo_surface_t *surface)
|
348
|
+
{
|
349
|
+
if (surface)
|
350
|
+
{
|
351
|
+
VALUE klass;
|
352
|
+
klass = cr_surface_get_klass (surface);
|
353
|
+
cairo_surface_reference (surface);
|
354
|
+
return Data_Wrap_Struct (klass, NULL, cr_surface_free, surface);
|
355
|
+
}
|
356
|
+
else
|
357
|
+
{
|
358
|
+
return Qnil;
|
359
|
+
}
|
360
|
+
}
|
361
|
+
|
362
|
+
VALUE
|
363
|
+
rb_cairo_surface_to_ruby_object_with_destroy (cairo_surface_t *surface)
|
364
|
+
{
|
365
|
+
VALUE rb_surface;
|
366
|
+
|
367
|
+
rb_surface = rb_cairo_surface_to_ruby_object (surface);
|
368
|
+
if (surface)
|
369
|
+
cairo_surface_destroy (surface);
|
370
|
+
|
371
|
+
return rb_surface;
|
372
|
+
}
|
373
|
+
|
374
|
+
static VALUE
|
375
|
+
cr_surface_allocate (VALUE klass)
|
376
|
+
{
|
377
|
+
return Data_Wrap_Struct (klass, NULL, cr_surface_free, NULL);
|
378
|
+
}
|
379
|
+
|
380
|
+
/* Surface manipulation */
|
381
|
+
static VALUE
|
382
|
+
cr_surface_destroy (VALUE self)
|
383
|
+
{
|
384
|
+
cairo_surface_t *surface;
|
385
|
+
|
386
|
+
surface = _SELF;
|
387
|
+
cairo_surface_destroy (surface);
|
388
|
+
DATA_PTR (self) = NULL;
|
389
|
+
|
390
|
+
return self;
|
391
|
+
}
|
392
|
+
|
393
|
+
static VALUE
|
394
|
+
cr_surface_finish (VALUE self)
|
395
|
+
{
|
396
|
+
cairo_surface_t *surface;
|
397
|
+
cr_io_callback_closure_t *closure;
|
398
|
+
|
399
|
+
surface = _SELF;
|
400
|
+
closure = cairo_surface_get_user_data (surface, &cr_closure_key);
|
401
|
+
|
402
|
+
cairo_surface_finish (surface);
|
403
|
+
cairo_surface_set_user_data (surface, &cr_finished_key, (void *)CR_TRUE, NULL);
|
404
|
+
cairo_surface_set_user_data (surface, &cr_object_holder_key, NULL, NULL);
|
405
|
+
|
406
|
+
if (closure && !NIL_P (closure->error))
|
407
|
+
rb_exc_raise (closure->error);
|
408
|
+
cr_surface_check_status (surface);
|
409
|
+
|
410
|
+
return self;
|
411
|
+
}
|
412
|
+
|
413
|
+
static void
|
414
|
+
yield_and_finish (VALUE self)
|
415
|
+
{
|
416
|
+
cairo_surface_t *surface;
|
417
|
+
|
418
|
+
rb_yield (self);
|
419
|
+
|
420
|
+
surface = _SELF;
|
421
|
+
if (!cairo_surface_get_user_data (surface, &cr_finished_key))
|
422
|
+
cr_surface_finish (self);
|
423
|
+
}
|
424
|
+
|
425
|
+
static VALUE
|
426
|
+
cr_surface_create_similar (VALUE self, VALUE content, VALUE width, VALUE height)
|
427
|
+
{
|
428
|
+
cairo_surface_t *surface;
|
429
|
+
|
430
|
+
surface = cairo_surface_create_similar (RVAL2CRSURFACE (self),
|
431
|
+
RVAL2CRCONTENT (content),
|
432
|
+
NUM2INT (width), NUM2INT (height));
|
433
|
+
cr_surface_check_status (surface);
|
434
|
+
return CRSURFACE2RVAL_WITH_DESTROY (surface);
|
435
|
+
}
|
436
|
+
|
437
|
+
static VALUE
|
438
|
+
cr_surface_get_content (VALUE self)
|
439
|
+
{
|
440
|
+
return INT2NUM (cairo_surface_get_content (_SELF));
|
441
|
+
}
|
442
|
+
|
443
|
+
|
444
|
+
#ifdef CAIRO_HAS_PNG_FUNCTIONS
|
445
|
+
static VALUE
|
446
|
+
cr_surface_write_to_png_stream (VALUE self, VALUE target)
|
447
|
+
{
|
448
|
+
cairo_status_t status;
|
449
|
+
cr_io_callback_closure_t closure;
|
450
|
+
|
451
|
+
closure.target = target;
|
452
|
+
closure.error = Qnil;
|
453
|
+
|
454
|
+
status = cairo_surface_write_to_png_stream (_SELF, cr_surface_write_func,
|
455
|
+
(void *)&closure);
|
456
|
+
if (!NIL_P (closure.error))
|
457
|
+
rb_exc_raise (closure.error);
|
458
|
+
|
459
|
+
rb_cairo_check_status (status);
|
460
|
+
return self;
|
461
|
+
}
|
462
|
+
|
463
|
+
static VALUE
|
464
|
+
cr_surface_write_to_png (VALUE self, VALUE filename)
|
465
|
+
{
|
466
|
+
cairo_status_t status;
|
467
|
+
status = cairo_surface_write_to_png (_SELF, StringValueCStr (filename));
|
468
|
+
rb_cairo_check_status (status);
|
469
|
+
return self;
|
470
|
+
}
|
471
|
+
|
472
|
+
static VALUE
|
473
|
+
cr_surface_write_to_png_generic (VALUE self, VALUE target)
|
474
|
+
{
|
475
|
+
if (rb_respond_to (target, cr_id_write))
|
476
|
+
return cr_surface_write_to_png_stream (self, target);
|
477
|
+
else
|
478
|
+
return cr_surface_write_to_png (self, target);
|
479
|
+
}
|
480
|
+
#endif
|
481
|
+
|
482
|
+
static VALUE
|
483
|
+
cr_surface_get_font_options (VALUE self)
|
484
|
+
{
|
485
|
+
cairo_font_options_t *options = cairo_font_options_create();
|
486
|
+
cairo_surface_get_font_options (_SELF, options);
|
487
|
+
cr_surface_check_status (_SELF);
|
488
|
+
rb_cairo_check_status (cairo_font_options_status (options));
|
489
|
+
return CRFONTOPTIONS2RVAL (options);
|
490
|
+
}
|
491
|
+
|
492
|
+
static VALUE
|
493
|
+
cr_surface_flush (VALUE self)
|
494
|
+
{
|
495
|
+
cairo_surface_flush (_SELF);
|
496
|
+
cr_surface_check_status (_SELF);
|
497
|
+
return self;
|
498
|
+
}
|
499
|
+
|
500
|
+
static VALUE
|
501
|
+
cr_surface_mark_dirty (int argc, VALUE *argv, VALUE self)
|
502
|
+
{
|
503
|
+
VALUE x, y, width, height;
|
504
|
+
int n;
|
505
|
+
|
506
|
+
n = rb_scan_args (argc, argv, "04", &x, &y, &width, &height);
|
507
|
+
|
508
|
+
if (n == 0)
|
509
|
+
{
|
510
|
+
cairo_surface_mark_dirty (_SELF);
|
511
|
+
}
|
512
|
+
else if (n == 4)
|
513
|
+
{
|
514
|
+
cairo_surface_mark_dirty_rectangle (_SELF,
|
515
|
+
NUM2INT (x), NUM2INT (y),
|
516
|
+
NUM2INT (width), NUM2INT (height));
|
517
|
+
}
|
518
|
+
else
|
519
|
+
{
|
520
|
+
int i;
|
521
|
+
VALUE args;
|
522
|
+
|
523
|
+
args = rb_ary_new2 (n);
|
524
|
+
for (i = 0; i < n; i++)
|
525
|
+
{
|
526
|
+
rb_ary_push (args, argv[i]);
|
527
|
+
}
|
528
|
+
|
529
|
+
rb_raise (rb_eArgError,
|
530
|
+
"invalid argument (expect () or (x, y, width, height)): %s",
|
531
|
+
inspect (args));
|
532
|
+
}
|
533
|
+
|
534
|
+
cr_surface_check_status (_SELF);
|
535
|
+
return self;
|
536
|
+
}
|
537
|
+
|
538
|
+
static VALUE
|
539
|
+
cr_surface_set_device_offset (VALUE self, VALUE x_offset, VALUE y_offset)
|
540
|
+
{
|
541
|
+
cairo_surface_set_device_offset (_SELF,
|
542
|
+
NUM2DBL (x_offset),
|
543
|
+
NUM2DBL (y_offset));
|
544
|
+
cr_surface_check_status (_SELF);
|
545
|
+
return self;
|
546
|
+
}
|
547
|
+
|
548
|
+
static VALUE
|
549
|
+
cr_surface_get_device_offset (VALUE self)
|
550
|
+
{
|
551
|
+
double x_offset, y_offset;
|
552
|
+
|
553
|
+
cairo_surface_get_device_offset (_SELF, &x_offset, &y_offset);
|
554
|
+
cr_surface_check_status (_SELF);
|
555
|
+
return rb_ary_new3 (2, rb_float_new (x_offset), rb_float_new (y_offset));
|
556
|
+
}
|
557
|
+
|
558
|
+
static VALUE
|
559
|
+
cr_surface_set_fallback_resolution (VALUE self,
|
560
|
+
VALUE x_pixels_per_inch,
|
561
|
+
VALUE y_pixels_per_inch)
|
562
|
+
{
|
563
|
+
cairo_surface_set_fallback_resolution (_SELF,
|
564
|
+
NUM2DBL (x_pixels_per_inch),
|
565
|
+
NUM2DBL (y_pixels_per_inch));
|
566
|
+
cr_surface_check_status (_SELF);
|
567
|
+
return self;
|
568
|
+
}
|
569
|
+
|
570
|
+
#if CAIRO_CHECK_VERSION(1, 7, 2)
|
571
|
+
static VALUE
|
572
|
+
cr_surface_get_fallback_resolution (VALUE self)
|
573
|
+
{
|
574
|
+
double x_pixels_per_inch, y_pixels_per_inch;
|
575
|
+
|
576
|
+
cairo_surface_get_fallback_resolution (_SELF,
|
577
|
+
&x_pixels_per_inch,
|
578
|
+
&y_pixels_per_inch);
|
579
|
+
cr_surface_check_status (_SELF);
|
580
|
+
return rb_ary_new3 (2,
|
581
|
+
rb_float_new (x_pixels_per_inch),
|
582
|
+
rb_float_new (y_pixels_per_inch));
|
583
|
+
}
|
584
|
+
#endif
|
585
|
+
|
586
|
+
|
587
|
+
#if CAIRO_CHECK_VERSION(1, 5, 2)
|
588
|
+
static VALUE
|
589
|
+
cr_surface_copy_page (VALUE self)
|
590
|
+
{
|
591
|
+
cairo_surface_copy_page (_SELF);
|
592
|
+
cr_surface_check_status (_SELF);
|
593
|
+
return self;
|
594
|
+
}
|
595
|
+
|
596
|
+
static VALUE
|
597
|
+
cr_surface_show_page (VALUE self)
|
598
|
+
{
|
599
|
+
cairo_surface_show_page (_SELF);
|
600
|
+
cr_surface_check_status (_SELF);
|
601
|
+
return self;
|
602
|
+
}
|
603
|
+
#endif
|
604
|
+
|
605
|
+
/* Image-surface functions */
|
606
|
+
#ifdef CAIRO_HAS_PNG_FUNCTIONS
|
607
|
+
static cairo_surface_t *
|
608
|
+
cr_image_surface_create_from_png_stream (VALUE target)
|
609
|
+
{
|
610
|
+
cr_io_callback_closure_t closure;
|
611
|
+
cairo_surface_t *surface;
|
612
|
+
|
613
|
+
closure.target = target;
|
614
|
+
closure.error = Qnil;
|
615
|
+
|
616
|
+
surface = cairo_image_surface_create_from_png_stream (cr_surface_read_func,
|
617
|
+
(void *)&closure);
|
618
|
+
if (!NIL_P (closure.error))
|
619
|
+
rb_exc_raise (closure.error);
|
620
|
+
|
621
|
+
return surface;
|
622
|
+
}
|
623
|
+
|
624
|
+
static cairo_surface_t *
|
625
|
+
cr_image_surface_create_from_png (VALUE filename)
|
626
|
+
{
|
627
|
+
return cairo_image_surface_create_from_png (StringValueCStr (filename));
|
628
|
+
}
|
629
|
+
|
630
|
+
static VALUE
|
631
|
+
cr_image_surface_create_from_png_generic (VALUE klass, VALUE target)
|
632
|
+
{
|
633
|
+
VALUE rb_surface;
|
634
|
+
cairo_surface_t *surface;
|
635
|
+
|
636
|
+
if (rb_respond_to (target, cr_id_read))
|
637
|
+
surface = cr_image_surface_create_from_png_stream (target);
|
638
|
+
else
|
639
|
+
surface = cr_image_surface_create_from_png (target);
|
640
|
+
|
641
|
+
cr_surface_check_status (surface);
|
642
|
+
rb_surface = cr_surface_allocate (klass);
|
643
|
+
DATA_PTR (rb_surface) = surface;
|
644
|
+
return rb_surface;
|
645
|
+
}
|
646
|
+
#endif
|
647
|
+
|
648
|
+
static cairo_surface_t *
|
649
|
+
cr_image_surface_create (VALUE self, VALUE format, VALUE width, VALUE height)
|
650
|
+
{
|
651
|
+
cairo_format_t cr_format;
|
652
|
+
cr_format = NIL_P (format) ? CAIRO_FORMAT_ARGB32 : RVAL2CRFORMAT (format);
|
653
|
+
return cairo_image_surface_create (cr_format,
|
654
|
+
NUM2INT (width),
|
655
|
+
NUM2INT (height));
|
656
|
+
}
|
657
|
+
|
658
|
+
static cairo_surface_t *
|
659
|
+
cr_image_surface_create_for_data (VALUE self, VALUE rb_data, VALUE format,
|
660
|
+
VALUE width, VALUE height, VALUE stride)
|
661
|
+
{
|
662
|
+
unsigned char *data;
|
663
|
+
|
664
|
+
data = (unsigned char *)StringValuePtr (rb_data);
|
665
|
+
|
666
|
+
return cairo_image_surface_create_for_data (data,
|
667
|
+
RVAL2CRFORMAT (format),
|
668
|
+
NUM2INT (width),
|
669
|
+
NUM2INT (height),
|
670
|
+
NUM2INT (stride));
|
671
|
+
}
|
672
|
+
|
673
|
+
static VALUE
|
674
|
+
cr_image_surface_initialize (int argc, VALUE *argv, VALUE self)
|
675
|
+
{
|
676
|
+
cairo_surface_t *surface;
|
677
|
+
VALUE arg1, arg2, arg3, arg4, arg5;
|
678
|
+
int n;
|
679
|
+
|
680
|
+
n = rb_scan_args (argc, argv, "23", &arg1, &arg2, &arg3, &arg4, &arg5);
|
681
|
+
|
682
|
+
if (n == 2)
|
683
|
+
surface = cr_image_surface_create (self, Qnil, arg1, arg2);
|
684
|
+
else if (n == 3)
|
685
|
+
surface = cr_image_surface_create (self, arg1, arg2, arg3);
|
686
|
+
else if (n == 5)
|
687
|
+
surface =
|
688
|
+
cr_image_surface_create_for_data (self, arg1, arg2, arg3, arg4, arg5);
|
689
|
+
else
|
690
|
+
rb_raise (rb_eArgError,
|
691
|
+
"invalid argument (expect "
|
692
|
+
"(width, height) or "
|
693
|
+
"(format, width, height) or "
|
694
|
+
"(data, format, width, height, stride)): %s",
|
695
|
+
inspect (rb_ary_new3 (4, arg1, arg2, arg3, arg4)));
|
696
|
+
|
697
|
+
cr_surface_check_status (surface);
|
698
|
+
DATA_PTR (self) = surface;
|
699
|
+
if (rb_block_given_p ())
|
700
|
+
yield_and_finish (self);
|
701
|
+
return Qnil;
|
702
|
+
}
|
703
|
+
|
704
|
+
static VALUE
|
705
|
+
cr_image_surface_get_data (VALUE self)
|
706
|
+
{
|
707
|
+
unsigned char *data;
|
708
|
+
cairo_surface_t *surface;
|
709
|
+
|
710
|
+
surface = _SELF;
|
711
|
+
data = cairo_image_surface_get_data (surface);
|
712
|
+
|
713
|
+
if (data)
|
714
|
+
return rb_str_new ((const char *)data,
|
715
|
+
cairo_image_surface_get_stride (surface) *
|
716
|
+
cairo_image_surface_get_height (surface));
|
717
|
+
else
|
718
|
+
return Qnil;
|
719
|
+
}
|
720
|
+
|
721
|
+
static VALUE
|
722
|
+
cr_image_surface_get_format (VALUE self)
|
723
|
+
{
|
724
|
+
return INT2NUM (cairo_image_surface_get_format (_SELF));
|
725
|
+
}
|
726
|
+
|
727
|
+
static VALUE
|
728
|
+
cr_image_surface_get_width (VALUE self)
|
729
|
+
{
|
730
|
+
return INT2NUM (cairo_image_surface_get_width (_SELF));
|
731
|
+
}
|
732
|
+
|
733
|
+
static VALUE
|
734
|
+
cr_image_surface_get_height (VALUE self)
|
735
|
+
{
|
736
|
+
return INT2NUM (cairo_image_surface_get_height (_SELF));
|
737
|
+
}
|
738
|
+
|
739
|
+
static VALUE
|
740
|
+
cr_image_surface_get_stride (VALUE self)
|
741
|
+
{
|
742
|
+
return INT2NUM (cairo_image_surface_get_stride (_SELF));
|
743
|
+
}
|
744
|
+
|
745
|
+
|
746
|
+
/* Printing surfaces */
|
747
|
+
#define DEFINE_SURFACE(type) \
|
748
|
+
static VALUE \
|
749
|
+
cr_ ## type ## _surface_initialize (int argc, VALUE *argv, VALUE self) \
|
750
|
+
{ \
|
751
|
+
VALUE target, rb_width_in_points, rb_height_in_points; \
|
752
|
+
VALUE arg2, arg3; \
|
753
|
+
cairo_surface_t *surface; \
|
754
|
+
double width_in_points, height_in_points; \
|
755
|
+
\
|
756
|
+
rb_scan_args (argc, argv, "21", &target, &arg2, &arg3); \
|
757
|
+
if (argc == 2) \
|
758
|
+
{ \
|
759
|
+
VALUE paper; \
|
760
|
+
\
|
761
|
+
paper = arg2; \
|
762
|
+
cr_paper_to_size_in_points (paper, \
|
763
|
+
&rb_width_in_points, \
|
764
|
+
&rb_height_in_points); \
|
765
|
+
} \
|
766
|
+
else \
|
767
|
+
{ \
|
768
|
+
rb_width_in_points = arg2; \
|
769
|
+
rb_height_in_points = arg3; \
|
770
|
+
} \
|
771
|
+
\
|
772
|
+
width_in_points = NUM2DBL (rb_width_in_points); \
|
773
|
+
height_in_points = NUM2DBL (rb_height_in_points); \
|
774
|
+
\
|
775
|
+
if (rb_respond_to (target, cr_id_write)) \
|
776
|
+
{ \
|
777
|
+
cr_io_callback_closure_t *closure; \
|
778
|
+
\
|
779
|
+
closure = cr_closure_new (target); \
|
780
|
+
surface = \
|
781
|
+
cairo_ ## type ## _surface_create_for_stream ( \
|
782
|
+
cr_surface_write_func, \
|
783
|
+
(void *) closure, \
|
784
|
+
width_in_points, \
|
785
|
+
height_in_points); \
|
786
|
+
\
|
787
|
+
if (cairo_surface_status (surface)) \
|
788
|
+
{ \
|
789
|
+
cr_closure_destroy (closure); \
|
790
|
+
} \
|
791
|
+
else \
|
792
|
+
{ \
|
793
|
+
rb_ivar_set (self, cr_id_target, target); \
|
794
|
+
cairo_surface_set_user_data (surface, &cr_closure_key, \
|
795
|
+
closure, cr_closure_free); \
|
796
|
+
cairo_surface_set_user_data (surface, &cr_object_holder_key, \
|
797
|
+
cr_object_holder_new(self), \
|
798
|
+
cr_object_holder_free); \
|
799
|
+
} \
|
800
|
+
} \
|
801
|
+
else \
|
802
|
+
{ \
|
803
|
+
surface = \
|
804
|
+
cairo_ ## type ## _surface_create (StringValueCStr (target), \
|
805
|
+
width_in_points, \
|
806
|
+
height_in_points); \
|
807
|
+
} \
|
808
|
+
\
|
809
|
+
cr_surface_check_status (surface); \
|
810
|
+
DATA_PTR (self) = surface; \
|
811
|
+
if (rb_block_given_p ()) \
|
812
|
+
yield_and_finish (self); \
|
813
|
+
return Qnil; \
|
814
|
+
}
|
815
|
+
|
816
|
+
#define DEFINE_SURFACE_SET_SIZE(type) \
|
817
|
+
static VALUE \
|
818
|
+
cr_ ## type ## _surface_set_size (int argc, VALUE *argv, VALUE self) \
|
819
|
+
{ \
|
820
|
+
VALUE arg1, arg2; \
|
821
|
+
VALUE width_in_points, height_in_points; \
|
822
|
+
\
|
823
|
+
rb_scan_args(argc, argv, "11", &arg1, &arg2); \
|
824
|
+
if (argc == 1) \
|
825
|
+
{ \
|
826
|
+
VALUE paper; \
|
827
|
+
\
|
828
|
+
paper = arg1; \
|
829
|
+
cr_paper_to_size_in_points (paper, \
|
830
|
+
&width_in_points, \
|
831
|
+
&height_in_points); \
|
832
|
+
} \
|
833
|
+
else \
|
834
|
+
{ \
|
835
|
+
width_in_points = arg1; \
|
836
|
+
height_in_points = arg2; \
|
837
|
+
} \
|
838
|
+
\
|
839
|
+
cairo_ ## type ## _surface_set_size (_SELF, \
|
840
|
+
NUM2DBL (width_in_points), \
|
841
|
+
NUM2DBL (height_in_points)); \
|
842
|
+
cr_surface_check_status (_SELF); \
|
843
|
+
return Qnil; \
|
844
|
+
}
|
845
|
+
|
846
|
+
#ifdef CAIRO_HAS_PS_SURFACE
|
847
|
+
/* PS-surface functions */
|
848
|
+
DEFINE_SURFACE(ps)
|
849
|
+
DEFINE_SURFACE_SET_SIZE(ps)
|
850
|
+
|
851
|
+
static VALUE
|
852
|
+
cr_ps_surface_dsc_comment (VALUE self, VALUE comment)
|
853
|
+
{
|
854
|
+
cairo_ps_surface_dsc_comment (_SELF, StringValueCStr (comment));
|
855
|
+
cr_surface_check_status (_SELF);
|
856
|
+
return Qnil;
|
857
|
+
}
|
858
|
+
|
859
|
+
static VALUE
|
860
|
+
cr_ps_surface_dsc_begin_setup (VALUE self)
|
861
|
+
{
|
862
|
+
cairo_ps_surface_dsc_begin_setup (_SELF);
|
863
|
+
cr_surface_check_status (_SELF);
|
864
|
+
if (rb_block_given_p ())
|
865
|
+
return rb_yield (self);
|
866
|
+
else
|
867
|
+
return Qnil;
|
868
|
+
}
|
869
|
+
|
870
|
+
static VALUE
|
871
|
+
cr_ps_surface_dsc_begin_page_setup (VALUE self)
|
872
|
+
{
|
873
|
+
cairo_ps_surface_dsc_begin_page_setup (_SELF);
|
874
|
+
cr_surface_check_status (_SELF);
|
875
|
+
if (rb_block_given_p ())
|
876
|
+
return rb_yield (self);
|
877
|
+
else
|
878
|
+
return Qnil;
|
879
|
+
}
|
880
|
+
|
881
|
+
# if CAIRO_CHECK_VERSION(1, 5, 2)
|
882
|
+
static VALUE
|
883
|
+
cr_ps_surface_restrict_to_level (VALUE self, VALUE level)
|
884
|
+
{
|
885
|
+
cairo_ps_surface_restrict_to_level (_SELF, RVAL2CRPSLEVEL (level));
|
886
|
+
cr_surface_check_status (_SELF);
|
887
|
+
return Qnil;
|
888
|
+
}
|
889
|
+
|
890
|
+
static VALUE
|
891
|
+
cr_ps_surface_get_eps (VALUE self)
|
892
|
+
{
|
893
|
+
return cairo_ps_surface_get_eps (_SELF) ? Qtrue : Qfalse;
|
894
|
+
}
|
895
|
+
|
896
|
+
static VALUE
|
897
|
+
cr_ps_surface_set_eps (VALUE self, VALUE eps)
|
898
|
+
{
|
899
|
+
cairo_ps_surface_set_eps (_SELF, RTEST (eps));
|
900
|
+
cr_surface_check_status (_SELF);
|
901
|
+
return Qnil;
|
902
|
+
}
|
903
|
+
# endif
|
904
|
+
#endif
|
905
|
+
|
906
|
+
#ifdef CAIRO_HAS_PDF_SURFACE
|
907
|
+
/* PDF-surface functions */
|
908
|
+
DEFINE_SURFACE(pdf)
|
909
|
+
DEFINE_SURFACE_SET_SIZE(pdf)
|
910
|
+
#endif
|
911
|
+
|
912
|
+
#ifdef CAIRO_HAS_SVG_SURFACE
|
913
|
+
/* SVG-surface functions */
|
914
|
+
DEFINE_SURFACE(svg)
|
915
|
+
|
916
|
+
static VALUE
|
917
|
+
cr_svg_surface_restrict_to_version (VALUE self, VALUE version)
|
918
|
+
{
|
919
|
+
cairo_svg_surface_restrict_to_version (_SELF, RVAL2CRSVGVERSION (version));
|
920
|
+
cr_surface_check_status (_SELF);
|
921
|
+
return Qnil;
|
922
|
+
}
|
923
|
+
#endif
|
924
|
+
|
925
|
+
#ifdef CAIRO_HAS_WIN32_SURFACE
|
926
|
+
/* WIN32-surface functions */
|
927
|
+
|
928
|
+
/* from dl/dl.h (ruby 1.9) */
|
929
|
+
#if SIZEOF_LONG == SIZEOF_VOIDP
|
930
|
+
# define PTR2NUM(x) (ULONG2NUM((unsigned long)(x)))
|
931
|
+
# define NUM2PTR(x) ((void *)(NUM2ULONG(x)))
|
932
|
+
#else
|
933
|
+
# define PTR2NUM(x) (ULL2NUM((unsigned long long)(x)))
|
934
|
+
# define NUM2PTR(x) ((void *)(NUM2ULL(x)))
|
935
|
+
#endif
|
936
|
+
|
937
|
+
static VALUE
|
938
|
+
cr_win32_surface_initialize (int argc, VALUE *argv, VALUE self)
|
939
|
+
{
|
940
|
+
cairo_surface_t *surface = NULL;
|
941
|
+
VALUE arg1, arg2, arg3, arg4;
|
942
|
+
VALUE hdc, format, width, height;
|
943
|
+
|
944
|
+
rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4);
|
945
|
+
|
946
|
+
switch (argc)
|
947
|
+
{
|
948
|
+
case 1:
|
949
|
+
hdc = arg1;
|
950
|
+
surface = cairo_win32_surface_create (NUM2PTR (hdc));
|
951
|
+
break;
|
952
|
+
case 2:
|
953
|
+
width = arg1;
|
954
|
+
height = arg2;
|
955
|
+
surface = cairo_win32_surface_create_with_dib (CAIRO_FORMAT_ARGB32,
|
956
|
+
NUM2INT (width),
|
957
|
+
NUM2INT (height));
|
958
|
+
break;
|
959
|
+
case 3:
|
960
|
+
if (NIL_P (arg1) ||
|
961
|
+
(rb_cairo__is_kind_of (arg1, rb_cNumeric) &&
|
962
|
+
NUM2INT (arg1) != CAIRO_FORMAT_RGB24))
|
963
|
+
{
|
964
|
+
# if CAIRO_CHECK_VERSION(1, 4, 0)
|
965
|
+
HDC win32_hdc;
|
966
|
+
hdc = arg1;
|
967
|
+
width = arg2;
|
968
|
+
height = arg3;
|
969
|
+
win32_hdc = NIL_P (hdc) ? NULL : NUM2PTR (hdc);
|
970
|
+
surface = cairo_win32_surface_create_with_ddb (win32_hdc,
|
971
|
+
CAIRO_FORMAT_RGB24,
|
972
|
+
NUM2INT (width),
|
973
|
+
NUM2INT (height));
|
974
|
+
# else
|
975
|
+
rb_raise (rb_eArgError,
|
976
|
+
"Cairo::Win32Surface.new(hdc, width, height) "
|
977
|
+
"is available since cairo >= 1.4.0");
|
978
|
+
# endif
|
979
|
+
}
|
980
|
+
else
|
981
|
+
{
|
982
|
+
format = arg1;
|
983
|
+
width = arg2;
|
984
|
+
height = arg3;
|
985
|
+
surface = cairo_win32_surface_create_with_dib (RVAL2CRFORMAT (format),
|
986
|
+
NUM2INT (width),
|
987
|
+
NUM2INT (height));
|
988
|
+
}
|
989
|
+
break;
|
990
|
+
case 4:
|
991
|
+
{
|
992
|
+
# if CAIRO_CHECK_VERSION(1, 4, 0)
|
993
|
+
HDC win32_hdc;
|
994
|
+
hdc = arg1;
|
995
|
+
format = arg2;
|
996
|
+
width = arg3;
|
997
|
+
height = arg4;
|
998
|
+
win32_hdc = NIL_P (hdc) ? NULL : (HDC) NUM2UINT (hdc);
|
999
|
+
surface = cairo_win32_surface_create_with_ddb (win32_hdc,
|
1000
|
+
RVAL2CRFORMAT (format),
|
1001
|
+
NUM2INT (width),
|
1002
|
+
NUM2INT (height));
|
1003
|
+
# else
|
1004
|
+
rb_raise (rb_eArgError,
|
1005
|
+
"Cairo::Win32Surface.new(hdc, format, width, height) "
|
1006
|
+
"is available since cairo >= 1.4.0");
|
1007
|
+
# endif
|
1008
|
+
}
|
1009
|
+
break;
|
1010
|
+
}
|
1011
|
+
|
1012
|
+
if (!surface)
|
1013
|
+
rb_cairo_check_status (CAIRO_STATUS_INVALID_FORMAT);
|
1014
|
+
cr_surface_check_status (surface);
|
1015
|
+
DATA_PTR (self) = surface;
|
1016
|
+
if (rb_block_given_p ())
|
1017
|
+
yield_and_finish (self);
|
1018
|
+
return Qnil;
|
1019
|
+
}
|
1020
|
+
|
1021
|
+
# if CAIRO_CHECK_VERSION(1, 5, 2)
|
1022
|
+
static VALUE
|
1023
|
+
cr_win32_printing_surface_initialize (VALUE self, VALUE hdc)
|
1024
|
+
{
|
1025
|
+
cairo_surface_t *surface = NULL;
|
1026
|
+
|
1027
|
+
surface = cairo_win32_printing_surface_create (NUM2PTR (hdc));
|
1028
|
+
cr_surface_check_status (surface);
|
1029
|
+
DATA_PTR (self) = surface;
|
1030
|
+
if (rb_block_given_p ())
|
1031
|
+
yield_and_finish (self);
|
1032
|
+
return Qnil;
|
1033
|
+
}
|
1034
|
+
# endif
|
1035
|
+
|
1036
|
+
static VALUE
|
1037
|
+
cr_win32_surface_get_hdc (VALUE self)
|
1038
|
+
{
|
1039
|
+
HDC hdc;
|
1040
|
+
|
1041
|
+
hdc = cairo_win32_surface_get_dc (_SELF);
|
1042
|
+
if (!hdc)
|
1043
|
+
return Qnil;
|
1044
|
+
else
|
1045
|
+
return PTR2NUM (hdc);
|
1046
|
+
}
|
1047
|
+
|
1048
|
+
# if CAIRO_CHECK_VERSION(1, 4, 0)
|
1049
|
+
static VALUE
|
1050
|
+
cr_win32_surface_get_image (VALUE self)
|
1051
|
+
{
|
1052
|
+
cairo_surface_t *surface;
|
1053
|
+
|
1054
|
+
surface = cairo_win32_surface_get_image (_SELF);
|
1055
|
+
if (!surface)
|
1056
|
+
return Qnil;
|
1057
|
+
cr_surface_check_status (surface);
|
1058
|
+
return CRSURFACE2RVAL (surface);
|
1059
|
+
}
|
1060
|
+
# endif
|
1061
|
+
#endif
|
1062
|
+
|
1063
|
+
#if defined(CAIRO_HAS_QUARTZ_SURFACE) && defined(HAVE_RUBY_COCOA)
|
1064
|
+
/* Quartz-surface functions */
|
1065
|
+
|
1066
|
+
#include <objc/objc-runtime.h>
|
1067
|
+
|
1068
|
+
BOOL rbobj_to_nsobj (VALUE obj, id* nsobj);
|
1069
|
+
VALUE ocid_to_rbobj (VALUE context_obj, id ocid);
|
1070
|
+
|
1071
|
+
static VALUE
|
1072
|
+
cr_quartz_surface_initialize (int argc, VALUE *argv, VALUE self)
|
1073
|
+
{
|
1074
|
+
id objc_object = nil;
|
1075
|
+
CGContextRef context;
|
1076
|
+
unsigned int width, height;
|
1077
|
+
cairo_surface_t *surface = NULL;
|
1078
|
+
cairo_format_t format = CAIRO_FORMAT_ARGB32;
|
1079
|
+
VALUE arg1, arg2, arg3, rb_width, rb_height;
|
1080
|
+
static VALUE rb_cOSXCGContextRef = Qnil;
|
1081
|
+
|
1082
|
+
rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);
|
1083
|
+
|
1084
|
+
if (argc == 2)
|
1085
|
+
{
|
1086
|
+
rb_width = arg1;
|
1087
|
+
rb_height = arg2;
|
1088
|
+
}
|
1089
|
+
else
|
1090
|
+
{
|
1091
|
+
switch (TYPE (arg1))
|
1092
|
+
{
|
1093
|
+
case T_NIL:
|
1094
|
+
break;
|
1095
|
+
case T_STRING:
|
1096
|
+
case T_SYMBOL:
|
1097
|
+
case T_FIXNUM:
|
1098
|
+
format = RVAL2CRFORMAT (arg1);
|
1099
|
+
break;
|
1100
|
+
default:
|
1101
|
+
if (NIL_P (rb_cOSXCGContextRef))
|
1102
|
+
rb_cOSXCGContextRef =
|
1103
|
+
rb_const_get (rb_const_get (rb_cObject, rb_intern ("OSX")),
|
1104
|
+
rb_intern ("CGContextRef"));
|
1105
|
+
|
1106
|
+
if (RTEST (rb_obj_is_kind_of (arg1, rb_cOSXCGContextRef)))
|
1107
|
+
rbobj_to_nsobj (arg1, &objc_object);
|
1108
|
+
else
|
1109
|
+
rb_raise (rb_eArgError,
|
1110
|
+
"invalid argument (expect "
|
1111
|
+
"(width, height), "
|
1112
|
+
"(format, width, height) or "
|
1113
|
+
"(cg_context, width, height)): %s",
|
1114
|
+
inspect (rb_ary_new3 (3, arg1, arg2, arg3)));
|
1115
|
+
break;
|
1116
|
+
}
|
1117
|
+
|
1118
|
+
rb_width = arg2;
|
1119
|
+
rb_height = arg3;
|
1120
|
+
}
|
1121
|
+
|
1122
|
+
width = NUM2UINT (rb_width);
|
1123
|
+
height = NUM2UINT (rb_height);
|
1124
|
+
|
1125
|
+
if (objc_object == nil)
|
1126
|
+
{
|
1127
|
+
surface = cairo_quartz_surface_create (format, width, height);
|
1128
|
+
}
|
1129
|
+
else
|
1130
|
+
{
|
1131
|
+
context = (CGContextRef)objc_object;
|
1132
|
+
surface =
|
1133
|
+
cairo_quartz_surface_create_for_cg_context (context, width, height);
|
1134
|
+
}
|
1135
|
+
|
1136
|
+
cr_surface_check_status (surface);
|
1137
|
+
DATA_PTR (self) = surface;
|
1138
|
+
if (rb_block_given_p ())
|
1139
|
+
yield_and_finish (self);
|
1140
|
+
return Qnil;
|
1141
|
+
}
|
1142
|
+
|
1143
|
+
static VALUE
|
1144
|
+
cr_quartz_surface_get_cg_context (VALUE self)
|
1145
|
+
{
|
1146
|
+
CGContextRef context;
|
1147
|
+
id objc_object;
|
1148
|
+
|
1149
|
+
context = cairo_quartz_surface_get_cg_context (_SELF);
|
1150
|
+
objc_object = (id)context;
|
1151
|
+
return ocid_to_rbobj (Qnil, objc_object);
|
1152
|
+
}
|
1153
|
+
|
1154
|
+
# if CAIRO_CHECK_VERSION(1, 5, 12)
|
1155
|
+
static VALUE
|
1156
|
+
cr_quartz_image_surface_initialize (VALUE self, VALUE image_surface)
|
1157
|
+
{
|
1158
|
+
cairo_surface_t *surface;
|
1159
|
+
|
1160
|
+
surface = cairo_quartz_image_surface_create (RVAL2CRSURFACE (image_surface));
|
1161
|
+
cr_surface_check_status (surface);
|
1162
|
+
DATA_PTR (self) = surface;
|
1163
|
+
if (rb_block_given_p ())
|
1164
|
+
yield_and_finish (self);
|
1165
|
+
return Qnil;
|
1166
|
+
}
|
1167
|
+
|
1168
|
+
static VALUE
|
1169
|
+
cr_quartz_image_surface_get_image (VALUE self)
|
1170
|
+
{
|
1171
|
+
cairo_surface_t *surface;
|
1172
|
+
|
1173
|
+
surface = cairo_quartz_image_surface_get_image (_SELF);
|
1174
|
+
if (!surface)
|
1175
|
+
return Qnil;
|
1176
|
+
cr_surface_check_status (surface);
|
1177
|
+
return CRSURFACE2RVAL (surface);
|
1178
|
+
}
|
1179
|
+
# endif
|
1180
|
+
#endif
|
1181
|
+
|
1182
|
+
static int
|
1183
|
+
cr_finish_all_guarded_surfaces_at_end_iter (VALUE key, VALUE value, VALUE data)
|
1184
|
+
{
|
1185
|
+
cr_surface_finish (key);
|
1186
|
+
return ST_CONTINUE;
|
1187
|
+
}
|
1188
|
+
|
1189
|
+
static void
|
1190
|
+
cr_finish_all_guarded_surfaces_at_end (VALUE data)
|
1191
|
+
{
|
1192
|
+
rb_hash_foreach (rb_cairo__gc_guarded_objects (rb_cCairo_Surface),
|
1193
|
+
cr_finish_all_guarded_surfaces_at_end_iter,
|
1194
|
+
Qnil);
|
1195
|
+
}
|
1196
|
+
|
1197
|
+
void
|
1198
|
+
Init_cairo_surface (void)
|
1199
|
+
{
|
1200
|
+
cr_id_target = rb_intern ("target");
|
1201
|
+
cr_id_read = rb_intern ("read");
|
1202
|
+
cr_id_write = rb_intern ("write");
|
1203
|
+
cr_id_inspect = rb_intern ("inspect");
|
1204
|
+
cr_id_parse = rb_intern ("parse");
|
1205
|
+
cr_id_size = rb_intern ("size");
|
1206
|
+
cr_id_set_unit = rb_intern ("unit=");
|
1207
|
+
|
1208
|
+
rb_cCairo_Surface =
|
1209
|
+
rb_define_class_under (rb_mCairo, "Surface", rb_cObject);
|
1210
|
+
rb_define_alloc_func (rb_cCairo_Surface, cr_surface_allocate);
|
1211
|
+
|
1212
|
+
rb_cairo__initialize_gc_guard_holder_class (rb_cCairo_Surface);
|
1213
|
+
rb_set_end_proc(cr_finish_all_guarded_surfaces_at_end, Qnil);
|
1214
|
+
|
1215
|
+
|
1216
|
+
rb_define_method (rb_cCairo_Surface, "create_similar",
|
1217
|
+
cr_surface_create_similar, 3);
|
1218
|
+
rb_define_method (rb_cCairo_Surface, "destroy", cr_surface_destroy, 0);
|
1219
|
+
rb_define_method (rb_cCairo_Surface, "finish", cr_surface_finish, 0);
|
1220
|
+
rb_define_method (rb_cCairo_Surface, "content", cr_surface_get_content, 0);
|
1221
|
+
|
1222
|
+
rb_define_method (rb_cCairo_Surface, "font_options",
|
1223
|
+
cr_surface_get_font_options, 0);
|
1224
|
+
rb_define_method (rb_cCairo_Surface, "flush", cr_surface_flush, 0);
|
1225
|
+
rb_define_method (rb_cCairo_Surface, "mark_dirty", cr_surface_mark_dirty, -1);
|
1226
|
+
rb_define_method (rb_cCairo_Surface, "set_device_offset",
|
1227
|
+
cr_surface_set_device_offset, 2);
|
1228
|
+
rb_define_method (rb_cCairo_Surface, "device_offset",
|
1229
|
+
cr_surface_get_device_offset, 0);
|
1230
|
+
rb_define_method (rb_cCairo_Surface, "set_fallback_resolution",
|
1231
|
+
cr_surface_set_fallback_resolution, 2);
|
1232
|
+
#if CAIRO_CHECK_VERSION(1, 7, 2)
|
1233
|
+
rb_define_method (rb_cCairo_Surface, "fallback_resolution",
|
1234
|
+
cr_surface_get_fallback_resolution, 0);
|
1235
|
+
#endif
|
1236
|
+
#if CAIRO_CHECK_VERSION(1, 5, 2)
|
1237
|
+
rb_define_method (rb_cCairo_Surface, "copy_page",
|
1238
|
+
cr_surface_copy_page, 2);
|
1239
|
+
rb_define_method (rb_cCairo_Surface, "show_page",
|
1240
|
+
cr_surface_show_page, 2);
|
1241
|
+
#endif
|
1242
|
+
|
1243
|
+
#ifdef CAIRO_HAS_PNG_FUNCTIONS
|
1244
|
+
rb_define_method (rb_cCairo_Surface, "write_to_png",
|
1245
|
+
cr_surface_write_to_png_generic, 1);
|
1246
|
+
#endif
|
1247
|
+
|
1248
|
+
RB_CAIRO_DEF_SETTERS (rb_cCairo_Surface);
|
1249
|
+
|
1250
|
+
/* Image-surface */
|
1251
|
+
rb_cCairo_ImageSurface =
|
1252
|
+
rb_define_class_under (rb_mCairo, "ImageSurface", rb_cCairo_Surface);
|
1253
|
+
|
1254
|
+
#ifdef CAIRO_HAS_PNG_FUNCTIONS
|
1255
|
+
rb_define_singleton_method (rb_cCairo_ImageSurface, "from_png",
|
1256
|
+
cr_image_surface_create_from_png_generic, 1);
|
1257
|
+
#endif
|
1258
|
+
|
1259
|
+
rb_define_method (rb_cCairo_ImageSurface, "initialize",
|
1260
|
+
cr_image_surface_initialize, -1);
|
1261
|
+
|
1262
|
+
rb_define_method (rb_cCairo_ImageSurface, "data",
|
1263
|
+
cr_image_surface_get_data, 0);
|
1264
|
+
rb_define_method (rb_cCairo_ImageSurface, "format",
|
1265
|
+
cr_image_surface_get_format, 0);
|
1266
|
+
rb_define_method (rb_cCairo_ImageSurface, "width",
|
1267
|
+
cr_image_surface_get_width, 0);
|
1268
|
+
rb_define_method (rb_cCairo_ImageSurface, "height",
|
1269
|
+
cr_image_surface_get_height, 0);
|
1270
|
+
rb_define_method (rb_cCairo_ImageSurface, "stride",
|
1271
|
+
cr_image_surface_get_stride, 0);
|
1272
|
+
|
1273
|
+
#define INIT_SURFACE(type, name) \
|
1274
|
+
rb_cCairo_ ## name ## Surface = \
|
1275
|
+
rb_define_class_under (rb_mCairo, # name "Surface", \
|
1276
|
+
rb_cCairo_Surface); \
|
1277
|
+
\
|
1278
|
+
rb_define_method (rb_cCairo_ ## name ## Surface, "initialize", \
|
1279
|
+
cr_ ## type ## _surface_initialize, -1);
|
1280
|
+
|
1281
|
+
#ifdef CAIRO_HAS_PS_SURFACE
|
1282
|
+
/* PS-surface */
|
1283
|
+
INIT_SURFACE(ps, PS)
|
1284
|
+
|
1285
|
+
rb_define_method (rb_cCairo_PSSurface, "set_size", cr_ps_surface_set_size, -1);
|
1286
|
+
rb_define_method (rb_cCairo_PSSurface, "dsc_comment",
|
1287
|
+
cr_ps_surface_dsc_comment, 1);
|
1288
|
+
rb_define_method (rb_cCairo_PSSurface, "dsc_begin_setup",
|
1289
|
+
cr_ps_surface_dsc_begin_setup, 0);
|
1290
|
+
rb_define_method (rb_cCairo_PSSurface, "dsc_begin_page_setup",
|
1291
|
+
cr_ps_surface_dsc_begin_page_setup, 0);
|
1292
|
+
|
1293
|
+
# if CAIRO_CHECK_VERSION(1, 5, 2)
|
1294
|
+
rb_define_method (rb_cCairo_PSSurface, "restrict_to_level",
|
1295
|
+
cr_ps_surface_restrict_to_level, 1);
|
1296
|
+
rb_define_method (rb_cCairo_PSSurface, "eps?", cr_ps_surface_get_eps, 0);
|
1297
|
+
rb_define_method (rb_cCairo_PSSurface, "set_eps", cr_ps_surface_set_eps, 1);
|
1298
|
+
# endif
|
1299
|
+
|
1300
|
+
RB_CAIRO_DEF_SETTERS (rb_cCairo_PSSurface);
|
1301
|
+
#endif
|
1302
|
+
|
1303
|
+
#ifdef CAIRO_HAS_PDF_SURFACE
|
1304
|
+
/* PDF-surface */
|
1305
|
+
INIT_SURFACE(pdf, PDF)
|
1306
|
+
|
1307
|
+
rb_define_method (rb_cCairo_PDFSurface, "set_size",
|
1308
|
+
cr_pdf_surface_set_size, -1);
|
1309
|
+
|
1310
|
+
RB_CAIRO_DEF_SETTERS (rb_cCairo_PDFSurface);
|
1311
|
+
#endif
|
1312
|
+
|
1313
|
+
#ifdef CAIRO_HAS_SVG_SURFACE
|
1314
|
+
/* SVG-surface */
|
1315
|
+
INIT_SURFACE(svg, SVG)
|
1316
|
+
|
1317
|
+
rb_define_method (rb_cCairo_SVGSurface, "restrict_to_version",
|
1318
|
+
cr_svg_surface_restrict_to_version, 1);
|
1319
|
+
|
1320
|
+
RB_CAIRO_DEF_SETTERS (rb_cCairo_SVGSurface);
|
1321
|
+
#endif
|
1322
|
+
|
1323
|
+
#ifdef CAIRO_HAS_WIN32_SURFACE
|
1324
|
+
/* Win32-surface */
|
1325
|
+
rb_cCairo_Win32Surface =
|
1326
|
+
rb_define_class_under (rb_mCairo, "Win32Surface", rb_cCairo_Surface);
|
1327
|
+
|
1328
|
+
rb_define_method (rb_cCairo_Win32Surface, "initialize",
|
1329
|
+
cr_win32_surface_initialize, -1);
|
1330
|
+
rb_define_method (rb_cCairo_Win32Surface, "hdc",
|
1331
|
+
cr_win32_surface_get_hdc, 0);
|
1332
|
+
# if CAIRO_CHECK_VERSION(1, 4, 0)
|
1333
|
+
rb_define_method (rb_cCairo_Win32Surface, "image",
|
1334
|
+
cr_win32_surface_get_image, 0);
|
1335
|
+
# endif
|
1336
|
+
|
1337
|
+
# if CAIRO_CHECK_VERSION(1, 5, 2)
|
1338
|
+
rb_cCairo_Win32PrintingSurface =
|
1339
|
+
rb_define_class_under (rb_mCairo, "Win32PrintingSurface", rb_cCairo_Surface);
|
1340
|
+
|
1341
|
+
rb_define_method (rb_cCairo_Win32PrintingSurface, "initialize",
|
1342
|
+
cr_win32_printing_surface_initialize, -1);
|
1343
|
+
rb_define_method (rb_cCairo_Win32PrintingSurface, "hdc",
|
1344
|
+
cr_win32_surface_get_hdc, 0);
|
1345
|
+
# endif
|
1346
|
+
|
1347
|
+
#endif
|
1348
|
+
|
1349
|
+
#if defined(CAIRO_HAS_QUARTZ_SURFACE) && defined(HAVE_RUBY_COCOA)
|
1350
|
+
/* Quartz-surface */
|
1351
|
+
|
1352
|
+
rb_cCairo_QuartzSurface =
|
1353
|
+
rb_define_class_under (rb_mCairo, "QuartzSurface", rb_cCairo_Surface);
|
1354
|
+
|
1355
|
+
rb_define_method (rb_cCairo_QuartzSurface, "initialize",
|
1356
|
+
cr_quartz_surface_initialize, -1);
|
1357
|
+
rb_define_method (rb_cCairo_QuartzSurface, "cg_context",
|
1358
|
+
cr_quartz_surface_get_cg_context, 0);
|
1359
|
+
|
1360
|
+
# if CAIRO_CHECK_VERSION(1, 5, 12)
|
1361
|
+
rb_cCairo_QuartzImageSurface =
|
1362
|
+
rb_define_class_under (rb_mCairo, "QuartzImageSurface", rb_cCairo_Surface);
|
1363
|
+
|
1364
|
+
rb_define_method (rb_cCairo_QuartzImageSurface, "initialize",
|
1365
|
+
cr_quartz_image_surface_initialize, 1);
|
1366
|
+
rb_define_method (rb_cCairo_QuartzImageSurface, "image",
|
1367
|
+
cr_quartz_image_surface_get_image, 0);
|
1368
|
+
# endif
|
1369
|
+
|
1370
|
+
#endif
|
1371
|
+
}
|