3 Copyright 1990, 1994, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
33 #include <X11/fonts/fntfilst.h>
34 #include <X11/fonts/bitmap.h>
35 #include <X11/fonts/bdfint.h>
38 #define MAXSHORT 32767
42 #define MINSHORT -32768
45 static xCharInfo initMinMetrics = {
46 MAXSHORT, MAXSHORT, MAXSHORT, MAXSHORT, MAXSHORT, 0xFFFF};
47 static xCharInfo initMaxMetrics = {
48 MINSHORT, MINSHORT, MINSHORT, MINSHORT, MINSHORT, 0x0000};
50 #define MINMAX(field,ci) \
51 if (minbounds->field > (ci)->field) \
52 minbounds->field = (ci)->field; \
53 if (maxbounds->field < (ci)->field) \
54 maxbounds->field = (ci)->field;
56 #define COMPUTE_MINMAX(ci) \
57 if ((ci)->ascent || (ci)->descent || \
58 (ci)->leftSideBearing || (ci)->rightSideBearing || \
59 (ci)->characterWidth) \
61 MINMAX(ascent, (ci)); \
62 MINMAX(descent, (ci)); \
63 MINMAX(leftSideBearing, (ci)); \
64 MINMAX(rightSideBearing, (ci)); \
65 MINMAX(characterWidth, (ci)); \
69 bitmapComputeFontBounds(FontPtr pFont)
71 BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
81 int numneg = 0, numpos = 0;
83 if (bitmapFont->bitmapExtra) {
84 minbounds = &bitmapFont->bitmapExtra->info.minbounds;
85 maxbounds = &bitmapFont->bitmapExtra->info.maxbounds;
87 minbounds = &pFont->info.minbounds;
88 maxbounds = &pFont->info.maxbounds;
90 *minbounds = initMinMetrics;
91 *maxbounds = initMaxMetrics;
92 maxOverlap = MINSHORT;
93 nchars = bitmapFont->num_chars;
94 for (i = 0, ci = bitmapFont->metrics; i < nchars; i++, ci++) {
95 COMPUTE_MINMAX(&ci->metrics);
96 if (ci->metrics.characterWidth < 0)
100 minbounds->attributes &= ci->metrics.attributes;
101 maxbounds->attributes |= ci->metrics.attributes;
102 overlap = ci->metrics.rightSideBearing - ci->metrics.characterWidth;
103 if (maxOverlap < overlap)
104 maxOverlap = overlap;
106 if (bitmapFont->bitmapExtra) {
108 bitmapFont->bitmapExtra->info.drawDirection = RightToLeft;
110 bitmapFont->bitmapExtra->info.drawDirection = LeftToRight;
111 bitmapFont->bitmapExtra->info.maxOverlap = maxOverlap;
112 minbounds = &pFont->info.minbounds;
113 maxbounds = &pFont->info.maxbounds;
114 *minbounds = initMinMetrics;
115 *maxbounds = initMaxMetrics;
117 maxOverlap = MINSHORT;
118 for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
119 for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
120 ci = ACCESSENCODING(bitmapFont->encoding, i);
122 COMPUTE_MINMAX(&ci->metrics);
123 if (ci->metrics.characterWidth < 0)
127 minbounds->attributes &= ci->metrics.attributes;
128 maxbounds->attributes |= ci->metrics.attributes;
129 overlap = ci->metrics.rightSideBearing -
130 ci->metrics.characterWidth;
131 if (maxOverlap < overlap)
132 maxOverlap = overlap;
139 pFont->info.drawDirection = RightToLeft;
141 pFont->info.drawDirection = LeftToRight;
142 pFont->info.maxOverlap = maxOverlap;
146 bitmapComputeFontInkBounds(FontPtr pFont)
148 BitmapFontPtr bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
155 xCharInfo *minbounds,
159 if (!bitmapFont->ink_metrics) {
160 if (bitmapFont->bitmapExtra) {
161 bitmapFont->bitmapExtra->info.ink_minbounds = bitmapFont->bitmapExtra->info.minbounds;
162 bitmapFont->bitmapExtra->info.ink_maxbounds = bitmapFont->bitmapExtra->info.maxbounds;
164 pFont->info.ink_minbounds = pFont->info.minbounds;
165 pFont->info.ink_maxbounds = pFont->info.maxbounds;
167 if (bitmapFont->bitmapExtra) {
168 minbounds = &bitmapFont->bitmapExtra->info.ink_minbounds;
169 maxbounds = &bitmapFont->bitmapExtra->info.ink_maxbounds;
171 minbounds = &pFont->info.ink_minbounds;
172 maxbounds = &pFont->info.ink_maxbounds;
174 *minbounds = initMinMetrics;
175 *maxbounds = initMaxMetrics;
176 nchars = bitmapFont->num_chars;
177 for (i = 0, ci = bitmapFont->ink_metrics; i < nchars; i++, ci++) {
179 minbounds->attributes &= ci->attributes;
180 maxbounds->attributes |= ci->attributes;
182 if (bitmapFont->bitmapExtra) {
183 minbounds = &pFont->info.ink_minbounds;
184 maxbounds = &pFont->info.ink_maxbounds;
185 *minbounds = initMinMetrics;
186 *maxbounds = initMaxMetrics;
188 for (r = pFont->info.firstRow; r <= pFont->info.lastRow; r++) {
189 for (c = pFont->info.firstCol; c <= pFont->info.lastCol; c++) {
190 cit = ACCESSENCODING(bitmapFont->encoding, i);
192 offset = cit - bitmapFont->metrics;
193 ci = &bitmapFont->ink_metrics[offset];
195 minbounds->attributes &= ci->attributes;
196 maxbounds->attributes |= ci->attributes;
206 bitmapAddInkMetrics(FontPtr pFont)
208 BitmapFontPtr bitmapFont;
211 bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
212 bitmapFont->ink_metrics = malloc(bitmapFont->num_chars * sizeof(xCharInfo));
213 if (!bitmapFont->ink_metrics) {
214 fprintf(stderr, "Error: Couldn't allocate ink_metrics (%d*%ld)\n",
215 bitmapFont->num_chars, (unsigned long)sizeof(xCharInfo));
218 for (i = 0; i < bitmapFont->num_chars; i++)
219 FontCharInkMetrics(pFont, &bitmapFont->metrics[i], &bitmapFont->ink_metrics[i]);
220 pFont->info.inkMetrics = TRUE;
226 bitmapComputeWeight(FontPtr pFont)