1 /* $XConsortium: bitsource.c,v 1.9 94/04/17 20:16:59 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
36 BitmapSourcesRec FontFileBitmapSources;
39 FontFileRegisterBitmapSource (fpe)
40 FontPathElementPtr fpe;
42 FontPathElementPtr *new;
46 for (i = 0; i < FontFileBitmapSources.count; i++)
47 if (FontFileBitmapSources.fpe[i] == fpe)
49 if (FontFileBitmapSources.count == FontFileBitmapSources.size)
51 newsize = FontFileBitmapSources.size + 4;
52 new = (FontPathElementPtr *) xrealloc (FontFileBitmapSources.fpe, newsize * sizeof *new);
55 FontFileBitmapSources.size = newsize;
56 FontFileBitmapSources.fpe = new;
58 FontFileBitmapSources.fpe[FontFileBitmapSources.count++] = fpe;
63 FontFileUnregisterBitmapSource (fpe)
64 FontPathElementPtr fpe;
68 for (i = 0; i < FontFileBitmapSources.count; i++)
69 if (FontFileBitmapSources.fpe[i] == fpe)
71 FontFileBitmapSources.count--;
72 if (FontFileBitmapSources.count == 0)
74 FontFileBitmapSources.size = 0;
75 xfree (FontFileBitmapSources.fpe);
76 FontFileBitmapSources.fpe = 0;
80 for (; i < FontFileBitmapSources.count; i++)
81 FontFileBitmapSources.fpe[i] = FontFileBitmapSources.fpe[i+1];
88 * Our set_path_hook: unregister all bitmap sources.
89 * This is necessary because already open fonts will keep their FPEs
90 * allocated, but they may not be on the new font path.
91 * The bitmap sources in the new path will be registered by the init_func.
94 FontFileEmptyBitmapSource()
96 if (FontFileBitmapSources.count == 0)
99 FontFileBitmapSources.count = 0;
100 FontFileBitmapSources.size = 0;
101 xfree (FontFileBitmapSources.fpe);
102 FontFileBitmapSources.fpe = 0;
105 FontFileMatchBitmapSource (fpe, pFont, flags, entry, zeroPat, vals, format, fmask, noSpecificSize)
106 FontPathElementPtr fpe;
111 FontScalablePtr vals;
112 fsBitmapFormat format;
113 fsBitmapFormatMask fmask;
118 FontBitmapEntryPtr bitmap;
120 FontDirectoryPtr dir;
121 FontScaledPtr scaled;
124 * Look through all the registered bitmap sources for
125 * the same zero name as ours; entries along that one
126 * can be scaled as desired.
129 for (source = 0; source < FontFileBitmapSources.count; source++)
131 if (FontFileBitmapSources.fpe[source] == fpe)
133 dir = (FontDirectoryPtr) FontFileBitmapSources.fpe[source]->private;
134 zero = FontFileFindNameInDir (&dir->scalable, zeroPat);
137 scaled = FontFileFindScaledInstance (zero, vals, noSpecificSize);
142 *pFont = scaled->pFont;
143 (*pFont)->fpe = FontFileBitmapSources.fpe[source];
146 else if (scaled->bitmap)
148 entry = scaled->bitmap;
149 bitmap = &entry->u.bitmap;
152 *pFont = bitmap->pFont;
153 (*pFont)->fpe = FontFileBitmapSources.fpe[source];
158 ret = FontFileOpenBitmap (
159 FontFileBitmapSources.fpe[source],
160 pFont, flags, entry, format, fmask);
161 if (ret == Successful && *pFont)
162 (*pFont)->fpe = FontFileBitmapSources.fpe[source];
165 else /* "cannot" happen */