1
/* cairo - a vector graphics library with display and print output
2
 *
3
 * Copyright © 2010 Red Hat Inc.
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it either under the terms of the GNU Lesser General Public
7
 * License version 2.1 as published by the Free Software Foundation
8
 * (the "LGPL") or, at your option, under the terms of the Mozilla
9
 * Public License Version 1.1 (the "MPL"). If you do not alter this
10
 * notice, a recipient may use your version of this file under either
11
 * the MPL or the LGPL.
12
 *
13
 * You should have received a copy of the LGPL along with this library
14
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
15
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
16
 * You should have received a copy of the MPL along with this library
17
 * in the file COPYING-MPL-1.1
18
 *
19
 * The contents of this file are subject to the Mozilla Public License
20
 * Version 1.1 (the "License"); you may not use this file except in
21
 * compliance with the License. You may obtain a copy of the License at
22
 * http://www.mozilla.org/MPL/
23
 *
24
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
25
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
26
 * the specific language governing rights and limitations.
27
 *
28
 * The Original Code is the cairo graphics library.
29
 *
30
 * The Initial Developer of the Original Code is University of Southern
31
 * California.
32
 *
33
 * Contributor(s):
34
 *	Benjamin Otte <otte@redhat.com>
35
 */
36

            
37
#include "config.h"
38

            
39
#include "cairo-gobject.h"
40

            
41
#define CAIRO_DEFINE_BOXED(Name,underscore_name,copy_func,free_func) \
42
GType \
43
underscore_name ## _get_type (void) \
44
{ \
45
   static gsize type_ret = 0; \
46
   if (g_once_init_enter (&type_ret)) { \
47
      GType type = g_boxed_type_register_static (g_intern_static_string (Name), \
48
                                                 (GBoxedCopyFunc)copy_func, \
49
                                                 (GBoxedFreeFunc)free_func); \
50
      g_once_init_leave (&type_ret, type); \
51
   } \
52
   return type_ret; \
53
}
54

            
55
CAIRO_DEFINE_BOXED ("CairoContext", cairo_gobject_context, 
56
                    cairo_reference, cairo_destroy);
57
CAIRO_DEFINE_BOXED ("CairoDevice", cairo_gobject_device, 
58
                    cairo_device_reference, cairo_device_destroy);
59
CAIRO_DEFINE_BOXED ("CairoPattern", cairo_gobject_pattern, 
60
                    cairo_pattern_reference, cairo_pattern_destroy);
61
CAIRO_DEFINE_BOXED ("CairoSurface", cairo_gobject_surface, 
62
                    cairo_surface_reference, cairo_surface_destroy);
63
CAIRO_DEFINE_BOXED ("CairoScaledFont", cairo_gobject_scaled_font, 
64
                    cairo_scaled_font_reference, cairo_scaled_font_destroy);
65
CAIRO_DEFINE_BOXED ("CairoFontFace", cairo_gobject_font_face, 
66
                    cairo_font_face_reference, cairo_font_face_destroy);
67
CAIRO_DEFINE_BOXED ("CairoFontOptions", cairo_gobject_font_options, 
68
                    cairo_font_options_copy, cairo_font_options_destroy);
69
CAIRO_DEFINE_BOXED ("CairoRegion", cairo_gobject_region, 
70
                    cairo_region_reference, cairo_region_destroy);
71

            
72
#if GLIB_CHECK_VERSION(2, 68, 0)
73
#define COPY_FUNC(name) \
74
static gpointer \
75
cairo_gobject_cairo_ ## name ## _copy (gpointer src) { \
76
  return g_memdup2 (src, sizeof (cairo_ ## name ## _t)); \
77
}
78
#else
79
#define COPY_FUNC(name) \
80
static gpointer \
81
cairo_gobject_cairo_ ## name ## _copy (gpointer src) { \
82
  return g_memdup (src, sizeof (cairo_ ## name ## _t)); \
83
}
84
#endif
85

            
86
COPY_FUNC (matrix)
87
CAIRO_DEFINE_BOXED ("CairoMatrix", cairo_gobject_matrix, 
88
                    cairo_gobject_cairo_matrix_copy, g_free);
89
COPY_FUNC (rectangle)
90
CAIRO_DEFINE_BOXED ("CairoRectangle", cairo_gobject_rectangle, 
91
                    cairo_gobject_cairo_rectangle_copy, g_free);
92
COPY_FUNC (rectangle_int)
93
CAIRO_DEFINE_BOXED ("CairoRectangleInt", cairo_gobject_rectangle_int, 
94
                    cairo_gobject_cairo_rectangle_int_copy, g_free);
95
COPY_FUNC (glyph)
96
CAIRO_DEFINE_BOXED ("CairoGlyph", cairo_gobject_glyph,
97
                    cairo_gobject_cairo_glyph_copy, g_free);
98
COPY_FUNC (text_cluster)
99
CAIRO_DEFINE_BOXED ("CairoTextCluster", cairo_gobject_text_cluster,
100
                    cairo_gobject_cairo_text_cluster_copy, g_free);