1 /* $XConsortium: bitmap.c,v 1.5 94/04/17 20:17:11 gildea Exp $ */
5 Copyright (c) 1991 X Consortium
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
31 * Author: Keith Packard, MIT X Consortium
37 int bitmapGetGlyphs(), bitmapGetMetrics();
38 int bitmapGetBitmaps(), bitmapGetExtents();
39 void bitmapComputeFontBounds ();
40 void bitmapComputeFontInkBounds ();
43 bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
46 register unsigned char *chars;
47 FontEncoding charEncoding;
48 unsigned long *glyphCount; /* RETURN */
49 CharInfoPtr *glyphs; /* RETURN */
51 BitmapFontPtr bitmapFont;
52 unsigned int firstCol;
53 register unsigned int numCols;
54 unsigned int firstRow;
56 CharInfoPtr *glyphsBase;
57 register unsigned int c;
58 register CharInfoPtr pci;
60 CharInfoPtr *encoding;
63 bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
64 encoding = bitmapFont->encoding;
65 pDefault = bitmapFont->pDefault;
66 firstCol = pFont->info.firstCol;
67 numCols = pFont->info.lastCol - firstCol + 1;
69 switch (charEncoding) {
73 if (pFont->info.firstRow > 0)
75 if (pFont->info.allExist && pDefault) {
77 c = (*chars++) - firstCol;
79 *glyphs++ = encoding[c];
85 c = (*chars++) - firstCol;
86 if (c < numCols && (pci = encoding[c]))
94 if (pFont->info.allExist && pDefault) {
97 c = (c | *chars++) - firstCol;
99 *glyphs++ = encoding[c];
101 *glyphs++ = pDefault;
106 c = (c | *chars++) - firstCol;
107 if (c < numCols && (pci = encoding[c]))
110 *glyphs++ = pDefault;
116 firstRow = pFont->info.firstRow;
117 numRows = pFont->info.lastRow - firstRow + 1;
119 r = (*chars++) - firstRow;
120 c = (*chars++) - firstCol;
121 if (r < numRows && c < numCols &&
122 (pci = encoding[r * numCols + c]))
125 *glyphs++ = pDefault;
129 *glyphCount = glyphs - glyphsBase;
133 static CharInfoRec nonExistantChar;
136 bitmapGetMetrics(pFont, count, chars, charEncoding, glyphCount, glyphs)
139 register unsigned char *chars;
140 FontEncoding charEncoding;
141 unsigned long *glyphCount; /* RETURN */
142 xCharInfo **glyphs; /* RETURN */
145 xCharInfo *ink_metrics;
147 BitmapFontPtr bitmapFont;
148 CharInfoPtr oldDefault;
151 bitmapFont = (BitmapFontPtr) pFont->fontPrivate;
152 oldDefault = bitmapFont->pDefault;
153 bitmapFont->pDefault = &nonExistantChar;
154 ret = bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, (CharInfoPtr *) glyphs);
155 if (ret == Successful) {
156 if (bitmapFont->ink_metrics) {
157 metrics = bitmapFont->metrics;
158 ink_metrics = bitmapFont->ink_metrics;
159 for (i = 0; i < *glyphCount; i++) {
160 if (glyphs[i] != (xCharInfo *) & nonExistantChar)
161 glyphs[i] = ink_metrics + (((CharInfoPtr) glyphs[i]) - metrics);
165 bitmapFont->pDefault = oldDefault;