1 /* CPML - Cairo Path Manipulation Library
2 * Copyright (C) 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.
23 * @Section_Id:CpmlExtents
25 * @short_description: A rectangular area representing a bounding box
27 * The #CpmlExtents struct groups two pairs representing the area of a
28 * bounding box. The <fieldname>org</fieldname> field holds the lowest
29 * (x, y) coordinates while <fieldname>size</fieldname> holds the x and
30 * y extents of the area. The additional <fieldname>is_defined</fieldname>
31 * boolean flag can be checked to know if #CpmlExtents has been computed
32 * (when equal to %1) or not (when <fieldname>is_defined</fieldname> is %0).
37 * @is_defined: %1 if these extents should be considered, %0 otherwise
38 * @org: the lowest x,y coordinates
39 * @size: the width (x) and height (y) of the extents
41 * A structure defining a bounding box area.
45 #include "cpml-extents.h"
54 * @extents: the destination #CpmlExtents
55 * @src: the source #CpmlExtents
57 * Copies @src in @extents.
59 * Return value: @extents
62 cpml_extents_copy(CpmlExtents
*extents
, const CpmlExtents
*src
)
64 return memcpy(extents
, src
, sizeof(CpmlExtents
));
68 * cpml_extents_from_cairo_text:
69 * @extents: the destination #CpmlExtents
70 * @cairo_extents: the source cairo_text_extents_t struct
72 * Converts @cairo_extents in a #CpmlExtents format and stores the
78 cpml_extents_from_cairo_text(CpmlExtents
*extents
,
79 const cairo_text_extents_t
*cairo_extents
)
81 extents
->is_defined
= 1;
82 extents
->org
.x
= cairo_extents
->x_bearing
;
83 extents
->org
.y
= cairo_extents
->y_bearing
;
84 extents
->size
.x
= cairo_extents
->width
;
85 extents
->size
.y
= cairo_extents
->height
;
92 * @extents: the destination #CpmlExtents
93 * @src: the extents to add
95 * Merges @extents and @src and store the result in @extents.
98 cpml_extents_add(CpmlExtents
*extents
, const CpmlExtents
*src
)
100 if (src
->is_defined
== 0)
103 if (extents
->is_defined
== 0) {
104 cpml_extents_copy(extents
, src
);
108 extents
->is_defined
= 1;
110 if (src
->org
.x
< extents
->org
.x
) {
111 extents
->size
.x
+= extents
->org
.x
- src
->org
.x
;
112 extents
->org
.x
= src
->org
.x
;
115 if (src
->org
.y
< extents
->org
.y
) {
116 extents
->size
.y
+= extents
->org
.y
- src
->org
.y
;
117 extents
->org
.y
= src
->org
.y
;
120 if (src
->org
.x
+ src
->size
.x
> extents
->org
.x
+ extents
->size
.x
)
121 extents
->size
.x
= src
->org
.x
+ src
->size
.x
- extents
->org
.x
;
123 if (src
->org
.y
+ src
->size
.y
> extents
->org
.y
+ extents
->size
.y
)
124 extents
->size
.y
= src
->org
.y
+ src
->size
.y
- extents
->org
.y
;