]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/font/bitmap/bitmap.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / lib / font / bitmap / bitmap.c
1 /* $XConsortium: bitmap.c,v 1.5 94/04/17 20:17:11 gildea Exp $ */
2
3 /*
4
5 Copyright (c) 1991  X Consortium
6
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:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
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.
23
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.
27
28 */
29
30 /*
31  * Author:  Keith Packard, MIT X Consortium
32  */
33
34 #include "fntfilst.h"
35 #include "bitmap.h"
36
37 int         bitmapGetGlyphs(), bitmapGetMetrics();
38 int         bitmapGetBitmaps(), bitmapGetExtents();
39 void        bitmapComputeFontBounds ();
40 void        bitmapComputeFontInkBounds ();
41
42 int
43 bitmapGetGlyphs(pFont, count, chars, charEncoding, glyphCount, glyphs)
44     FontPtr     pFont;
45     unsigned long count;
46     register unsigned char *chars;
47     FontEncoding charEncoding;
48     unsigned long *glyphCount;  /* RETURN */
49     CharInfoPtr *glyphs;        /* RETURN */
50 {
51     BitmapFontPtr  bitmapFont;
52     unsigned int firstCol;
53     register unsigned int numCols;
54     unsigned int firstRow;
55     unsigned int numRows;
56     CharInfoPtr *glyphsBase;
57     register unsigned int c;
58     register CharInfoPtr pci;
59     unsigned int r;
60     CharInfoPtr *encoding;
61     CharInfoPtr pDefault;
62
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;
68     glyphsBase = glyphs;
69     switch (charEncoding) {
70
71     case Linear8Bit:
72     case TwoD8Bit:
73         if (pFont->info.firstRow > 0)
74             break;
75         if (pFont->info.allExist && pDefault) {
76             while (count--) {
77                 c = (*chars++) - firstCol;
78                 if (c < numCols)
79                     *glyphs++ = encoding[c];
80                 else
81                     *glyphs++ = pDefault;
82             }
83         } else {
84             while (count--) {
85                 c = (*chars++) - firstCol;
86                 if (c < numCols && (pci = encoding[c]))
87                     *glyphs++ = pci;
88                 else if (pDefault)
89                     *glyphs++ = pDefault;
90             }
91         }
92         break;
93     case Linear16Bit:
94         if (pFont->info.allExist && pDefault) {
95             while (count--) {
96                 c = *chars++ << 8;
97                 c = (c | *chars++) - firstCol;
98                 if (c < numCols)
99                     *glyphs++ = encoding[c];
100                 else
101                     *glyphs++ = pDefault;
102             }
103         } else {
104             while (count--) {
105                 c = *chars++ << 8;
106                 c = (c | *chars++) - firstCol;
107                 if (c < numCols && (pci = encoding[c]))
108                     *glyphs++ = pci;
109                 else if (pDefault)
110                     *glyphs++ = pDefault;
111             }
112         }
113         break;
114
115     case TwoD16Bit:
116         firstRow = pFont->info.firstRow;
117         numRows = pFont->info.lastRow - firstRow + 1;
118         while (count--) {
119             r = (*chars++) - firstRow;
120             c = (*chars++) - firstCol;
121             if (r < numRows && c < numCols &&
122                     (pci = encoding[r * numCols + c]))
123                 *glyphs++ = pci;
124             else if (pDefault)
125                 *glyphs++ = pDefault;
126         }
127         break;
128     }
129     *glyphCount = glyphs - glyphsBase;
130     return Successful;
131 }
132
133 static CharInfoRec nonExistantChar;
134
135 int
136 bitmapGetMetrics(pFont, count, chars, charEncoding, glyphCount, glyphs)
137     FontPtr     pFont;
138     unsigned long count;
139     register unsigned char *chars;
140     FontEncoding charEncoding;
141     unsigned long *glyphCount;  /* RETURN */
142     xCharInfo **glyphs;         /* RETURN */
143 {
144     int         ret;
145     xCharInfo  *ink_metrics;
146     CharInfoPtr metrics;
147     BitmapFontPtr  bitmapFont;
148     CharInfoPtr oldDefault;
149     int         i;
150
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);
162             }
163         }
164     }
165     bitmapFont->pDefault = oldDefault;
166     return ret;
167 }