1 /*
2 * Copyright 1999 SuSE, Inc.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of SuSE not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. SuSE makes no representations about the
11 * suitability of this software for any purpose. It is provided "as is"
12 * without express or implied warranty.
13 *
14 * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
16 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
18 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 *
21 * Author: Keith Packard, SuSE, Inc.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 #include "libxfontint.h"
28 #include <X11/fonts/fntfilst.h>
29 #include <X11/fonts/fontutil.h>
30 #include <X11/fonts/pcf.h>
31 #include "builtin.h"
32
33 static int
BuiltinOpenBitmap(FontPathElementPtr fpe,FontPtr * ppFont,int flags,FontEntryPtr entry,char * fileName,fsBitmapFormat format,fsBitmapFormatMask fmask,FontPtr unused)34 BuiltinOpenBitmap (FontPathElementPtr fpe, FontPtr *ppFont, int flags,
35 FontEntryPtr entry, char *fileName, fsBitmapFormat format,
36 fsBitmapFormatMask fmask, FontPtr unused)
37 {
38 FontFilePtr file;
39 FontPtr pFont;
40 int ret;
41 int bit,
42 byte,
43 glyph,
44 scan,
45 image;
46
47 file = BuiltinFileOpen (fileName);
48 if (!file)
49 return BadFontName;
50 pFont = malloc(sizeof(FontRec));
51 if (!pFont) {
52 BuiltinFileClose (file, 0);
53 return AllocError;
54 }
55 /* set up default values */
56 FontDefaultFormat(&bit, &byte, &glyph, &scan);
57 /* get any changes made from above */
58 ret = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
59
60 /* Fill in font record. Data format filled in by reader. */
61 pFont->refcnt = 0;
62 pFont->maxPrivate = -1;
63 pFont->devPrivates = (pointer *) 0;
64
65 ret = pcfReadFont (pFont, file, bit, byte, glyph, scan);
66
67 BuiltinFileClose (file, 0);
68 if (ret != Successful)
69 free(pFont);
70 else
71 *ppFont = pFont;
72 return ret;
73 }
74
75 static int
BuiltinGetInfoBitmap(FontPathElementPtr fpe,FontInfoPtr pFontInfo,FontEntryPtr entry,char * fileName)76 BuiltinGetInfoBitmap (FontPathElementPtr fpe, FontInfoPtr pFontInfo,
77 FontEntryPtr entry, char *fileName)
78 {
79 FontFilePtr file;
80 int ret;
81
82 file = BuiltinFileOpen (fileName);
83 if (!file)
84 return BadFontName;
85 ret = pcfReadFontInfo (pFontInfo, file);
86 BuiltinFileClose (file, 0);
87 return ret;
88 }
89
90 static int
BuiltinOpenScalable(FontPathElementPtr fpe,FontPtr * pFont,int flags,FontEntryPtr entry,char * fileName,FontScalablePtr vals,fsBitmapFormat format,fsBitmapFormatMask fmask,FontPtr non_cachable_font)91 BuiltinOpenScalable (FontPathElementPtr fpe,
92 FontPtr *pFont,
93 int flags,
94 FontEntryPtr entry,
95 char *fileName,
96 FontScalablePtr vals,
97 fsBitmapFormat format,
98 fsBitmapFormatMask fmask,
99 FontPtr non_cachable_font) /* We don't do licensing */
100 {
101 return BadFontName;
102 }
103
104 static int
BuiltinGetInfoScalable(FontPathElementPtr fpe,FontInfoPtr pFontInfo,FontEntryPtr entry,FontNamePtr fontName,char * fileName,FontScalablePtr vals)105 BuiltinGetInfoScalable (FontPathElementPtr fpe,
106 FontInfoPtr pFontInfo,
107 FontEntryPtr entry,
108 FontNamePtr fontName,
109 char *fileName,
110 FontScalablePtr vals)
111 {
112 return BadFontName;
113 }
114
115 static FontRendererRec renderers[] = {
116 { ".builtin", 8,
117 BuiltinOpenBitmap,
118 BuiltinOpenScalable,
119 BuiltinGetInfoBitmap,
120 BuiltinGetInfoScalable,
121 0 }
122 };
123
124 #define numRenderers (sizeof renderers / sizeof renderers[0])
125
126 void
BuiltinRegisterFontFileFunctions(void)127 BuiltinRegisterFontFileFunctions(void)
128 {
129 int i;
130 for (i = 0; i < numRenderers; i++)
131 FontFileRegisterRenderer ((FontRendererRec *) &renderers[i]);
132 }
133
134