123a0898aSmrg/* 223a0898aSmrg 323a0898aSmrgCopyright 1991, 1998 The Open Group 423a0898aSmrg 523a0898aSmrgPermission to use, copy, modify, distribute, and sell this software and its 623a0898aSmrgdocumentation for any purpose is hereby granted without fee, provided that 723a0898aSmrgthe above copyright notice appear in all copies and that both that 823a0898aSmrgcopyright notice and this permission notice appear in supporting 923a0898aSmrgdocumentation. 1023a0898aSmrg 1123a0898aSmrgThe above copyright notice and this permission notice shall be included in 1223a0898aSmrgall copies or substantial portions of the Software. 1323a0898aSmrg 1423a0898aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1523a0898aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1623a0898aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1723a0898aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1823a0898aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1923a0898aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2023a0898aSmrg 2123a0898aSmrgExcept as contained in this notice, the name of The Open Group shall not be 2223a0898aSmrgused in advertising or otherwise to promote the sale, use or other dealings 2323a0898aSmrgin this Software without prior written authorization from The Open Group. 2423a0898aSmrg 2523a0898aSmrg*/ 2623a0898aSmrg 2723a0898aSmrg/* 2823a0898aSmrg * Author: Keith Packard, MIT X Consortium 2923a0898aSmrg */ 3023a0898aSmrg 3123a0898aSmrg#ifdef HAVE_CONFIG_H 3223a0898aSmrg#include <config.h> 3323a0898aSmrg#endif 3423a0898aSmrg#include <X11/fonts/fntfilst.h> 3523a0898aSmrg 3623a0898aSmrgBitmapSourcesRec FontFileBitmapSources; 3723a0898aSmrg 3823a0898aSmrgBool 3923a0898aSmrgFontFileRegisterBitmapSource (FontPathElementPtr fpe) 4023a0898aSmrg{ 4123a0898aSmrg FontPathElementPtr *new; 4223a0898aSmrg int i; 4323a0898aSmrg int newsize; 4423a0898aSmrg 4523a0898aSmrg for (i = 0; i < FontFileBitmapSources.count; i++) 4623a0898aSmrg if (FontFileBitmapSources.fpe[i] == fpe) 4723a0898aSmrg return TRUE; 4823a0898aSmrg if (FontFileBitmapSources.count == FontFileBitmapSources.size) 4923a0898aSmrg { 5023a0898aSmrg newsize = FontFileBitmapSources.size + 4; 517f7f5e4eSmrg new = realloc (FontFileBitmapSources.fpe, newsize * sizeof *new); 5223a0898aSmrg if (!new) 5323a0898aSmrg return FALSE; 5423a0898aSmrg FontFileBitmapSources.size = newsize; 5523a0898aSmrg FontFileBitmapSources.fpe = new; 5623a0898aSmrg } 5723a0898aSmrg FontFileBitmapSources.fpe[FontFileBitmapSources.count++] = fpe; 5823a0898aSmrg return TRUE; 5923a0898aSmrg} 6023a0898aSmrg 6123a0898aSmrgvoid 6223a0898aSmrgFontFileUnregisterBitmapSource (FontPathElementPtr fpe) 6323a0898aSmrg{ 6423a0898aSmrg int i; 6523a0898aSmrg 6623a0898aSmrg for (i = 0; i < FontFileBitmapSources.count; i++) 6723a0898aSmrg if (FontFileBitmapSources.fpe[i] == fpe) 6823a0898aSmrg { 6923a0898aSmrg FontFileBitmapSources.count--; 7023a0898aSmrg if (FontFileBitmapSources.count == 0) 7123a0898aSmrg { 7223a0898aSmrg FontFileBitmapSources.size = 0; 737f7f5e4eSmrg free (FontFileBitmapSources.fpe); 7423a0898aSmrg FontFileBitmapSources.fpe = 0; 7523a0898aSmrg } 7623a0898aSmrg else 7723a0898aSmrg { 7823a0898aSmrg for (; i < FontFileBitmapSources.count; i++) 7923a0898aSmrg FontFileBitmapSources.fpe[i] = FontFileBitmapSources.fpe[i+1]; 8023a0898aSmrg } 8123a0898aSmrg break; 8223a0898aSmrg } 8323a0898aSmrg} 8423a0898aSmrg 8523a0898aSmrg/* 8623a0898aSmrg * Our set_path_hook: unregister all bitmap sources. 8723a0898aSmrg * This is necessary because already open fonts will keep their FPEs 8823a0898aSmrg * allocated, but they may not be on the new font path. 8923a0898aSmrg * The bitmap sources in the new path will be registered by the init_func. 9023a0898aSmrg */ 9123a0898aSmrgvoid 9223a0898aSmrgFontFileEmptyBitmapSource(void) 9323a0898aSmrg{ 9423a0898aSmrg if (FontFileBitmapSources.count == 0) 9523a0898aSmrg return; 9623a0898aSmrg 9723a0898aSmrg FontFileBitmapSources.count = 0; 9823a0898aSmrg FontFileBitmapSources.size = 0; 997f7f5e4eSmrg free (FontFileBitmapSources.fpe); 10023a0898aSmrg FontFileBitmapSources.fpe = 0; 10123a0898aSmrg} 10223a0898aSmrg 10323a0898aSmrgint 10441c30155SmrgFontFileMatchBitmapSource (FontPathElementPtr fpe, 10541c30155Smrg FontPtr *pFont, 10641c30155Smrg int flags, 10741c30155Smrg FontEntryPtr entry, 10841c30155Smrg FontNamePtr zeroPat, 10941c30155Smrg FontScalablePtr vals, 11041c30155Smrg fsBitmapFormat format, 11141c30155Smrg fsBitmapFormatMask fmask, 11223a0898aSmrg Bool noSpecificSize) 11323a0898aSmrg{ 11423a0898aSmrg int source; 11523a0898aSmrg FontEntryPtr zero; 11623a0898aSmrg FontBitmapEntryPtr bitmap; 11723a0898aSmrg int ret; 11823a0898aSmrg FontDirectoryPtr dir; 11923a0898aSmrg FontScaledPtr scaled; 12023a0898aSmrg 12123a0898aSmrg /* 12223a0898aSmrg * Look through all the registered bitmap sources for 12323a0898aSmrg * the same zero name as ours; entries along that one 12423a0898aSmrg * can be scaled as desired. 12523a0898aSmrg */ 12623a0898aSmrg ret = BadFontName; 12723a0898aSmrg for (source = 0; source < FontFileBitmapSources.count; source++) 12823a0898aSmrg { 12923a0898aSmrg if (FontFileBitmapSources.fpe[source] == fpe) 13023a0898aSmrg continue; 13123a0898aSmrg dir = (FontDirectoryPtr) FontFileBitmapSources.fpe[source]->private; 13223a0898aSmrg zero = FontFileFindNameInDir (&dir->scalable, zeroPat); 13323a0898aSmrg if (!zero) 13423a0898aSmrg continue; 13523a0898aSmrg scaled = FontFileFindScaledInstance (zero, vals, noSpecificSize); 13623a0898aSmrg if (scaled) 13723a0898aSmrg { 13823a0898aSmrg if (scaled->pFont) 13923a0898aSmrg { 14023a0898aSmrg *pFont = scaled->pFont; 14123a0898aSmrg (*pFont)->fpe = FontFileBitmapSources.fpe[source]; 14223a0898aSmrg ret = Successful; 14323a0898aSmrg } 14423a0898aSmrg else if (scaled->bitmap) 14523a0898aSmrg { 14623a0898aSmrg entry = scaled->bitmap; 14723a0898aSmrg bitmap = &entry->u.bitmap; 14823a0898aSmrg if (bitmap->pFont) 14923a0898aSmrg { 15023a0898aSmrg *pFont = bitmap->pFont; 15123a0898aSmrg (*pFont)->fpe = FontFileBitmapSources.fpe[source]; 15223a0898aSmrg ret = Successful; 15323a0898aSmrg } 15423a0898aSmrg else 15523a0898aSmrg { 15623a0898aSmrg ret = FontFileOpenBitmap ( 15723a0898aSmrg FontFileBitmapSources.fpe[source], 15823a0898aSmrg pFont, flags, entry, format, fmask); 15923a0898aSmrg if (ret == Successful && *pFont) 16023a0898aSmrg (*pFont)->fpe = FontFileBitmapSources.fpe[source]; 16123a0898aSmrg } 16223a0898aSmrg } 16323a0898aSmrg else /* "cannot" happen */ 16423a0898aSmrg { 16523a0898aSmrg ret = BadFontName; 16623a0898aSmrg } 16723a0898aSmrg break; 16823a0898aSmrg } 16923a0898aSmrg } 17023a0898aSmrg return ret; 17123a0898aSmrg} 172