]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/font/bitmap/bitmapfunc.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / lib / font / bitmap / bitmapfunc.c
1 /* $XConsortium: bitmapfunc.c /main/10 1996/11/03 19:31:55 kaleb $ */
2 /* $XFree86: xc/lib/font/bitmap/bitmapfunc.c,v 3.4 1996/12/23 06:01:49 dawes Exp $ */
3
4 /*
5
6 Copyright (c) 1991  X Consortium
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
21 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 Except as contained in this notice, the name of the X Consortium shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings
27 in this Software without prior written authorization from the X Consortium.
28
29 */
30
31 /*
32  * Author:  Keith Packard, MIT X Consortium
33  */
34
35 #include "fntfilst.h"
36 #include "bitmap.h"
37
38 typedef struct _BitmapFileFunctions {
39     int         (*ReadFont) ( /* pFont, file, bit, byte, glyph, scan */ );
40     int         (*ReadInfo) ( /* pFontInfo, file */ );
41 }           BitmapFileFunctionsRec, *BitmapFileFunctionsPtr;
42
43 extern int  pcfReadFont(), pcfReadFontInfo();
44 extern int  snfReadFont(), snfReadFontInfo();
45 extern int  bdfReadFont(), bdfReadFontInfo();
46 extern int  pmfReadFont();
47 int         BitmapOpenBitmap ();
48 extern int  BitmapOpenScalable ();
49 int         BitmapGetInfoBitmap ();
50 extern int  BitmapGetInfoScalable ();
51 int         BitmapGetRenderIndex ();
52
53 /*
54  * these two arrays must be in the same order
55  */
56 static BitmapFileFunctionsRec readers[] = {
57     pcfReadFont, pcfReadFontInfo,
58     pcfReadFont, pcfReadFontInfo,
59 #ifdef X_GZIP_FONT_COMPRESSION
60     pcfReadFont, pcfReadFontInfo,
61 #endif
62 #ifdef __EMX__
63     pcfReadFont, pcfReadFontInfo,
64 #endif
65     snfReadFont, snfReadFontInfo,
66     snfReadFont, snfReadFontInfo,
67 #ifdef X_GZIP_FONT_COMPRESSION
68     snfReadFont, snfReadFontInfo,
69 #endif
70     bdfReadFont, bdfReadFontInfo,
71     bdfReadFont, bdfReadFontInfo,
72 #ifdef X_GZIP_FONT_COMPRESSION
73     bdfReadFont, bdfReadFontInfo,
74 #endif
75     pmfReadFont, pcfReadFontInfo,
76 };
77
78
79 #define CAPABILITIES (CAP_MATRIX | CAP_CHARSUBSETTING)
80
81 static FontRendererRec  renderers[] = {
82     ".pcf", 4,
83     BitmapOpenBitmap, BitmapOpenScalable,
84         BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
85         CAPABILITIES,
86     ".pcf.Z", 6,
87     BitmapOpenBitmap, BitmapOpenScalable,
88         BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
89         CAPABILITIES,
90 #ifdef X_GZIP_FONT_COMPRESSION
91     ".pcf.gz", 7,
92     BitmapOpenBitmap, BitmapOpenScalable,
93         BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
94         CAPABILITIES,
95 #endif
96 #ifdef __EMX__
97     ".pcz", 4,
98     BitmapOpenBitmap, BitmapOpenScalable,
99         BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
100         CAPABILITIES,
101 #endif
102     ".snf", 4,
103     BitmapOpenBitmap, BitmapOpenScalable,
104         BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
105         CAPABILITIES,
106     ".snf.Z", 6,
107     BitmapOpenBitmap, BitmapOpenScalable,
108         BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
109         CAPABILITIES,
110 #ifdef X_GZIP_FONT_COMPRESSION
111     ".snf.gz", 7,
112     BitmapOpenBitmap, BitmapOpenScalable,
113         BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
114         CAPABILITIES,
115 #endif
116     ".bdf", 4,
117     BitmapOpenBitmap, BitmapOpenScalable,
118         BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
119         CAPABILITIES,
120     ".bdf.Z", 6,
121     BitmapOpenBitmap, BitmapOpenScalable,
122         BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
123         CAPABILITIES,
124 #ifdef X_GZIP_FONT_COMPRESSION
125     ".bdf.gz", 7,
126     BitmapOpenBitmap, BitmapOpenScalable,
127         BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
128         CAPABILITIES,
129 #endif
130     ".pmf", 4,
131       BitmapOpenBitmap, BitmapOpenScalable,
132         BitmapGetInfoBitmap, BitmapGetInfoScalable, 0,
133         CAPABILITIES 
134 };
135
136 BitmapOpenBitmap (fpe, ppFont, flags, entry, fileName, format, fmask,
137                   non_cachable_font)
138     FontPathElementPtr  fpe;
139     FontPtr             *ppFont;
140     int                 flags;
141     FontEntryPtr        entry;
142     char                *fileName;
143     fsBitmapFormat      format;
144     fsBitmapFormatMask  fmask;
145     FontPtr             non_cachable_font;      /* We don't do licensing */
146 {
147     FontFilePtr file;
148     FontPtr     pFont;
149     int         i;
150     int         ret;
151     int         bit,
152                 byte,
153                 glyph,
154                 scan,
155                 image;
156
157     i = BitmapGetRenderIndex(entry->u.bitmap.renderer);
158     file = FontFileOpen (fileName);
159     if (!file)
160         return BadFontName;
161     pFont = (FontPtr) xalloc(sizeof(FontRec));
162     if (!pFont) {
163         FontFileClose (file);
164         return AllocError;
165     }
166     /* set up default values */
167     FontDefaultFormat(&bit, &byte, &glyph, &scan);
168     /* get any changes made from above */
169     ret = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
170
171     /* Fill in font record. Data format filled in by reader. */
172     pFont->refcnt = 0;
173     pFont->maxPrivate = -1;
174     pFont->devPrivates = (pointer *) 0;
175
176     ret = (*readers[i].ReadFont) (pFont, file, bit, byte, glyph, scan);
177
178     FontFileClose (file);
179     if (ret != Successful)
180         xfree(pFont);
181     else
182         *ppFont = pFont;
183     return ret;
184 }
185
186 BitmapGetInfoBitmap (fpe, pFontInfo, entry, fileName)
187     FontPathElementPtr  fpe;
188     FontInfoPtr         pFontInfo;
189     FontEntryPtr        entry;
190     char                *fileName;
191 {
192     FontFilePtr file;
193     int         i;
194     int         ret;
195     FontRendererPtr renderer;
196
197     renderer = FontFileMatchRenderer (fileName);
198     if (!renderer)
199         return BadFontName;
200     i = BitmapGetRenderIndex(renderer);
201     file = FontFileOpen (fileName);
202     if (!file)
203         return BadFontName;
204     ret = (*readers[i].ReadInfo) (pFontInfo, file);
205     FontFileClose (file);
206     return ret;
207 }
208
209 #define numRenderers    (sizeof renderers / sizeof renderers[0])
210
211 BitmapRegisterFontFileFunctions ()
212 {
213     int     i;
214
215     for (i = 0; i < numRenderers; i++)
216         FontFileRegisterRenderer (&renderers[i]);
217 }
218
219 /*
220  * compute offset into renderers array - used to find the font reader,
221  * the font info reader, and the bitmap scaling routine.  All users
222  * of this routine must be kept in step with the renderer array.
223  */
224 BitmapGetRenderIndex(renderer)
225     FontRendererPtr renderer;
226 {
227     return renderer - renderers;
228 }