1 /* $XConsortium: bitmaputil.c,v 1.6 94/04/17 20:17:12 gildea Exp $ */
5 Copyright (c) 1990, 1994 X Consortium
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
26 Except as contained in this notice, the name of the X Consortium shall
27 not be used in advertising or otherwise to promote the sale, use or
28 other dealings in this Software without prior written authorization
29 from the X Consortium.
37 #define MAXSHORT 32767
41 #define MINSHORT -32768
44 static xCharInfo initMinMetrics = {
45 MAXSHORT, MAXSHORT, MAXSHORT, MAXSHORT, MAXSHORT, 0xFFFF};
46 static xCharInfo initMaxMetrics = {
47 MINSHORT, MINSHORT, MINSHORT, MINSHORT, MINSHORT, 0x0000};
49 #define MINMAX(field,ci) \
50 if (minbounds->field > (ci)->field) \
51 minbounds->field = (ci)->field; \
52 if (maxbounds->field < (ci)->field) \
53 maxbounds->field = (ci)->field;
55 #define COMPUTE_MINMAX(ci) \
56 if ((ci)->ascent != -(ci)->descent || \
57 (ci)->leftSideBearing != (ci)->rightSideBearing || \
58 (ci)->characterWidth) \
60 MINMAX(ascent, (ci)); \
61 MINMAX(descent, (ci)); \
62 MINMAX(leftSideBearing, (ci)); \
63 MINMAX(rightSideBearing, (ci)); \
64 MINMAX(characterWidth, (ci)); \
68 bitmapComputeFontBounds(pFont)
71 BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
82 int numneg = 0, numpos = 0;
84 if (bitmapFont->bitmapExtra) {
85 minbounds = &bitmapFont->bitmapExtra->info.minbounds;
86 maxbounds = &bitmapFont->bitmapExtra->info.maxbounds;
88 minbounds = &pFont->info.minbounds;
89 maxbounds = &pFont->info.maxbounds;
91 *minbounds = initMinMetrics;
92 *maxbounds = initMaxMetrics;
93 maxOverlap = MINSHORT;
94 nchars = bitmapFont->num_chars;
95 for (i = 0, ci = bitmapFont->metrics; i < nchars; i++, ci++) {
96 COMPUTE_MINMAX(&ci->metrics);
97 if (ci->metrics.characterWidth < 0)
101 minbounds->attributes &= ci->metrics.attributes;
102 maxbounds->attributes |= ci->metrics.attributes;
103 overlap = ci->metrics.rightSideBearing - ci->metrics.characterWidth;
104 if (maxOverlap < overlap)
105 maxOverlap = overlap;
107 if (bitmapFont->bitmapExtra) {
109 bitmapFont->bitmapExtra->info.drawDirection = RightToLeft;
111 bitmapFont->bitmapExtra->info.drawDirection = LeftToRight;
112 bitmapFont->bitmapExtra->info.maxOverlap = maxOverlap;
113 minbounds = &pFont->info.minbounds;
114 maxbounds = &pFont->info.maxbounds;
115 *minbounds = initMinMetrics;
116 *maxbounds = initMaxMetrics;
117 pci = bitmapFont->encoding;
118 maxOverlap = MINSHORT;
119 for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
120 for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
123 COMPUTE_MINMAX(&ci->metrics);
124 if (ci->metrics.characterWidth < 0)
128 minbounds->attributes &= ci->metrics.attributes;
129 maxbounds->attributes |= ci->metrics.attributes;
130 overlap = ci->metrics.rightSideBearing -
131 ci->metrics.characterWidth;
132 if (maxOverlap < overlap)
133 maxOverlap = overlap;
139 pFont->info.drawDirection = RightToLeft;
141 pFont->info.drawDirection = LeftToRight;
142 pFont->info.maxOverlap = maxOverlap;
146 bitmapComputeFontInkBounds(pFont)
149 BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
157 xCharInfo *minbounds,
161 if (!bitmapFont->ink_metrics) {
162 if (bitmapFont->bitmapExtra) {
163 bitmapFont->bitmapExtra->info.ink_minbounds = bitmapFont->bitmapExtra->info.minbounds;
164 bitmapFont->bitmapExtra->info.ink_maxbounds = bitmapFont->bitmapExtra->info.maxbounds;
166 pFont->info.ink_minbounds = pFont->info.minbounds;
167 pFont->info.ink_maxbounds = pFont->info.maxbounds;
169 if (bitmapFont->bitmapExtra) {
170 minbounds = &bitmapFont->bitmapExtra->info.ink_minbounds;
171 maxbounds = &bitmapFont->bitmapExtra->info.ink_maxbounds;
173 minbounds = &pFont->info.ink_minbounds;
174 maxbounds = &pFont->info.ink_maxbounds;
176 *minbounds = initMinMetrics;
177 *maxbounds = initMaxMetrics;
178 nchars = bitmapFont->num_chars;
179 for (i = 0, ci = bitmapFont->ink_metrics; i < nchars; i++, ci++) {
181 minbounds->attributes &= ci->attributes;
182 maxbounds->attributes |= ci->attributes;
184 if (bitmapFont->bitmapExtra) {
185 minbounds = &pFont->info.ink_minbounds;
186 maxbounds = &pFont->info.ink_maxbounds;
187 *minbounds = initMinMetrics;
188 *maxbounds = initMaxMetrics;
189 pci = bitmapFont->encoding;
190 for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
191 for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
194 offset = cit - bitmapFont->metrics;
195 ci = &bitmapFont->ink_metrics[offset];
197 minbounds->attributes &= ci->attributes;
198 maxbounds->attributes |= ci->attributes;
207 bitmapAddInkMetrics(pFont)
210 BitmapFontPtr bitmapFont;
213 bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
214 bitmapFont->ink_metrics = (xCharInfo *) xalloc(bitmapFont->num_chars * sizeof(xCharInfo));
215 if (!bitmapFont->ink_metrics)
217 for (i = 0; i < bitmapFont->num_chars; i++)
218 FontCharInkMetrics(pFont, &bitmapFont->metrics[i], &bitmapFont->ink_metrics[i]);
219 pFont->info.inkMetrics = TRUE;
225 bitmapComputeWeight(pFont)