1 /************************************************************
2 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
33 #include "xkbcommon/xkbcommon.h"
34 #include "XKBcommonint.h"
37 _XkbCheckBounds(struct xkb_bounds * bounds, int x, int y)
50 XkbcComputeShapeBounds(struct xkb_shape * shape)
53 struct xkb_outline * outline;
54 struct xkb_point * pt;
56 if ((!shape) || (shape->num_outlines < 1))
59 shape->bounds.x1 = shape->bounds.y1 = SHRT_MAX;
60 shape->bounds.x2 = shape->bounds.y2 = SHRT_MIN;
62 for (outline = shape->outlines, o = 0; o < shape->num_outlines;
65 for (pt = outline->points, p = 0; p < outline->num_points; p++, pt++)
66 _XkbCheckBounds(&shape->bounds, pt->x, pt->y);
67 if (outline->num_points < 2)
68 _XkbCheckBounds(&shape->bounds, 0, 0);
74 XkbcComputeRowBounds(struct xkb_geometry * geom, struct xkb_section * section, struct xkb_row * row)
78 struct xkb_bounds *bounds, *sbounds;
80 if (!geom || !section || !row)
83 bounds = &row->bounds;
84 memset(bounds, 0, sizeof(struct xkb_bounds));
86 for (key = row->keys, pos = k = 0; k < row->num_keys; k++, key++) {
87 sbounds = &XkbKeyShape(geom, key)->bounds;
88 _XkbCheckBounds(bounds, pos, 0);
93 _XkbCheckBounds(bounds, pos, 0);
95 _XkbCheckBounds(bounds, pos + sbounds->x1, sbounds->y1);
96 _XkbCheckBounds(bounds, pos + sbounds->x2, sbounds->y2);
102 _XkbCheckBounds(bounds, 0, pos);
104 _XkbCheckBounds(bounds,pos + sbounds->x1, sbounds->y1);
105 _XkbCheckBounds(bounds,pos + sbounds->x2, sbounds->y2);
114 XkbcComputeSectionBounds(struct xkb_geometry * geom, struct xkb_section * section)
117 struct xkb_shape * shape;
118 struct xkb_row * row;
119 union xkb_doodad * doodad;
120 struct xkb_bounds * bounds, *rbounds = NULL;
122 if (!geom || !section)
125 bounds = §ion->bounds;
126 memset(bounds, 0, sizeof(struct xkb_bounds));
128 for (i = 0, row = section->rows; i < section->num_rows; i++, row++) {
129 if (!XkbcComputeRowBounds(geom, section, row))
131 rbounds = &row->bounds;
132 _XkbCheckBounds(bounds, row->left + rbounds->x1,
133 row->top + rbounds->y1);
134 _XkbCheckBounds(bounds, row->left + rbounds->x2,
135 row->top + rbounds->y2);
138 for (i = 0, doodad = section->doodads; i < section->num_doodads;
141 static struct xkb_bounds tbounds;
143 switch (doodad->any.type) {
144 case XkbOutlineDoodad:
146 shape = XkbShapeDoodadShape(geom, &doodad->shape);
147 rbounds = &shape->bounds;
150 tbounds.x1 = doodad->text.left;
151 tbounds.y1 = doodad->text.top;
152 tbounds.x2 = tbounds.x1 + doodad->text.width;
153 tbounds.y2 = tbounds.y1 + doodad->text.height;
156 case XkbIndicatorDoodad:
157 shape = XkbIndicatorDoodadShape(geom, &doodad->indicator);
158 rbounds = &shape->bounds;
161 shape = XkbLogoDoodadShape(geom, &doodad->logo);
162 rbounds = &shape->bounds;
165 tbounds.x1 = tbounds.x2 = doodad->any.left;
166 tbounds.y1 = tbounds.y2 = doodad->any.top;
171 _XkbCheckBounds(bounds, rbounds->x1, rbounds->y1);
172 _XkbCheckBounds(bounds, rbounds->x2, rbounds->y2);