1 /* ADG - Automatic Drawing Generation
2 * Copyright (C) 2007,2008,2009 Nicola Fontana <ntd at entidi.it>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 * SECTION:adg-primitive
23 * @Section_Id:AdgPrimitive
24 * @title: AdgPrimitive
25 * @short_description: A wrapper for #CpmlPrimitive
27 * AdgPrimitive is a wrapper in #GType syntax of the #CpmlPrimitive struct.
33 * Another name for #CpmlPrimitive: check its documentation for the
34 * fields description and visibility details.
38 #include "adg-primitive.h"
44 adg_primitive_get_type(void)
46 static int primitive_type
= 0;
48 if (G_UNLIKELY(primitive_type
== 0))
49 primitive_type
= g_boxed_type_register_static("AdgPrimitive",
50 (GBoxedCopyFunc
) adg_primitive_dup
,
53 return primitive_type
;
58 * @primitive: an #AdgPrimitive structure
60 * Duplicates @primitive. This function makes a shallow duplication of
61 * @primitives, that is the internal pointers of the resulting primitive
62 * struct refer to the same memory as the original @primitive. Check
63 * out adg_primitive_deep_dup() if it is required also the content
66 * Returns: a shallow duplicate of @primitive: must be freed
67 * with g_free() when no longer needed.
70 adg_primitive_dup(const AdgPrimitive
*primitive
)
72 return g_memdup(primitive
, sizeof(AdgPrimitive
));
76 * adg_primitive_deep_dup:
77 * @primitive: an #AdgPrimitive structure
79 * Duplicates @primitive. This function makes a deep duplication of
80 * @primitive, that is it duplicates also the definition data (both
81 * <structfield>org</structfield> and <structfield>data</structfield>).
82 * The <structfield>segment</structfield> field instead is set to
83 * %NULL as the parent segment is not duplicated.
85 * All the data is allocated in the same chunk of memory so freeing
86 * the returned pointer releases all the occupied memory.
88 * Returns: a deep duplicate of @primitive: must be freed
89 * with g_free() when no longer needed.
92 adg_primitive_deep_dup(const AdgPrimitive
*primitive
)
95 gsize primitive_size
, org_size
, data_size
;
96 cairo_path_data_t
*p_data
;
98 primitive_size
= sizeof(AdgPrimitive
);
99 org_size
= primitive
->org
== NULL
? 0 : sizeof(cairo_path_data_t
);
100 data_size
= primitive
->data
== NULL
?
101 0 : sizeof(cairo_path_data_t
) * primitive
->data
->header
.length
;
102 dest
= (AdgPrimitive
*) g_malloc(primitive_size
+ org_size
+ data_size
);
103 p_data
= (cairo_path_data_t
*) ((gchar
*) dest
+ primitive_size
);
105 dest
->segment
= NULL
;
107 if (primitive
->org
!= NULL
) {
109 memcpy(p_data
, primitive
->org
, org_size
);
116 dest
->data
= memcpy(p_data
, primitive
->data
, data_size
);