bitsource.c revision 7f7f5e4e
1/* $Xorg: bitsource.c,v 1.4 2001/02/09 02:04:03 xorgcvs Exp $ */ 2 3/* 4 5Copyright 1991, 1998 The Open Group 6 7Permission to use, copy, modify, distribute, and sell this software and its 8documentation for any purpose is hereby granted without fee, provided that 9the above copyright notice appear in all copies and that both that 10copyright notice and this permission notice appear in supporting 11documentation. 12 13The above copyright notice and this permission notice shall be included in 14all copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of The Open Group shall not be 24used in advertising or otherwise to promote the sale, use or other dealings 25in this Software without prior written authorization from The Open Group. 26 27*/ 28/* $XFree86: xc/lib/font/fontfile/bitsource.c,v 1.3 2001/01/17 19:43:29 dawes Exp $ */ 29 30/* 31 * Author: Keith Packard, MIT X Consortium 32 */ 33 34#ifdef HAVE_CONFIG_H 35#include <config.h> 36#endif 37#include <X11/fonts/fntfilst.h> 38 39BitmapSourcesRec FontFileBitmapSources; 40 41Bool 42FontFileRegisterBitmapSource (FontPathElementPtr fpe) 43{ 44 FontPathElementPtr *new; 45 int i; 46 int newsize; 47 48 for (i = 0; i < FontFileBitmapSources.count; i++) 49 if (FontFileBitmapSources.fpe[i] == fpe) 50 return TRUE; 51 if (FontFileBitmapSources.count == FontFileBitmapSources.size) 52 { 53 newsize = FontFileBitmapSources.size + 4; 54 new = realloc (FontFileBitmapSources.fpe, newsize * sizeof *new); 55 if (!new) 56 return FALSE; 57 FontFileBitmapSources.size = newsize; 58 FontFileBitmapSources.fpe = new; 59 } 60 FontFileBitmapSources.fpe[FontFileBitmapSources.count++] = fpe; 61 return TRUE; 62} 63 64void 65FontFileUnregisterBitmapSource (FontPathElementPtr fpe) 66{ 67 int i; 68 69 for (i = 0; i < FontFileBitmapSources.count; i++) 70 if (FontFileBitmapSources.fpe[i] == fpe) 71 { 72 FontFileBitmapSources.count--; 73 if (FontFileBitmapSources.count == 0) 74 { 75 FontFileBitmapSources.size = 0; 76 free (FontFileBitmapSources.fpe); 77 FontFileBitmapSources.fpe = 0; 78 } 79 else 80 { 81 for (; i < FontFileBitmapSources.count; i++) 82 FontFileBitmapSources.fpe[i] = FontFileBitmapSources.fpe[i+1]; 83 } 84 break; 85 } 86} 87 88/* 89 * Our set_path_hook: unregister all bitmap sources. 90 * This is necessary because already open fonts will keep their FPEs 91 * allocated, but they may not be on the new font path. 92 * The bitmap sources in the new path will be registered by the init_func. 93 */ 94void 95FontFileEmptyBitmapSource(void) 96{ 97 if (FontFileBitmapSources.count == 0) 98 return; 99 100 FontFileBitmapSources.count = 0; 101 FontFileBitmapSources.size = 0; 102 free (FontFileBitmapSources.fpe); 103 FontFileBitmapSources.fpe = 0; 104} 105 106int 107FontFileMatchBitmapSource (FontPathElementPtr fpe, 108 FontPtr *pFont, 109 int flags, 110 FontEntryPtr entry, 111 FontNamePtr zeroPat, 112 FontScalablePtr vals, 113 fsBitmapFormat format, 114 fsBitmapFormatMask fmask, 115 Bool noSpecificSize) 116{ 117 int source; 118 FontEntryPtr zero; 119 FontBitmapEntryPtr bitmap; 120 int ret; 121 FontDirectoryPtr dir; 122 FontScaledPtr scaled; 123 124 /* 125 * Look through all the registered bitmap sources for 126 * the same zero name as ours; entries along that one 127 * can be scaled as desired. 128 */ 129 ret = BadFontName; 130 for (source = 0; source < FontFileBitmapSources.count; source++) 131 { 132 if (FontFileBitmapSources.fpe[source] == fpe) 133 continue; 134 dir = (FontDirectoryPtr) FontFileBitmapSources.fpe[source]->private; 135 zero = FontFileFindNameInDir (&dir->scalable, zeroPat); 136 if (!zero) 137 continue; 138 scaled = FontFileFindScaledInstance (zero, vals, noSpecificSize); 139 if (scaled) 140 { 141 if (scaled->pFont) 142 { 143 *pFont = scaled->pFont; 144 (*pFont)->fpe = FontFileBitmapSources.fpe[source]; 145 ret = Successful; 146 } 147 else if (scaled->bitmap) 148 { 149 entry = scaled->bitmap; 150 bitmap = &entry->u.bitmap; 151 if (bitmap->pFont) 152 { 153 *pFont = bitmap->pFont; 154 (*pFont)->fpe = FontFileBitmapSources.fpe[source]; 155 ret = Successful; 156 } 157 else 158 { 159 ret = FontFileOpenBitmap ( 160 FontFileBitmapSources.fpe[source], 161 pFont, flags, entry, format, fmask); 162 if (ret == Successful && *pFont) 163 (*pFont)->fpe = FontFileBitmapSources.fpe[source]; 164 } 165 } 166 else /* "cannot" happen */ 167 { 168 ret = BadFontName; 169 } 170 break; 171 } 172 } 173 return ret; 174} 175