📄 fontfile.c
字号:
/* $TOG: fontfile.c /main/29 1997/05/23 16:36:56 barstow $ *//*Copyright (c) 1991 X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.*//* $XFree86: xc/lib/font/fontfile/fontfile.c,v 3.3.4.2 1997/07/05 15:55:36 dawes Exp $ *//* * Author: Keith Packard, MIT X Consortium *//* $NCDId: @(#)fontfile.c,v 1.6 1991/07/02 17:00:46 lemke Exp $ */#include "fntfilst.h"/* * Map FPE functions to renderer functions */intFontFileNameCheck (name) char *name;{#ifndef NCD#ifdef __EMX__ /* OS/2 uses D:/... as a path name for fonts, so accept this as a valid * path if it starts with a letter and a colon */ if (isalpha(*name) && name[1]==':') return TRUE;#endif return *name == '/';#else return ((strcmp(name, "built-ins") == 0) || (*name == '/'));#endif}intFontFileInitFPE (fpe) FontPathElementPtr fpe;{ int status; FontDirectoryPtr dir; status = FontFileReadDirectory (fpe->name, &dir); if (status == Successful) { if (dir->nonScalable.used > 0) if (!FontFileRegisterBitmapSource (fpe)) { FontFileFreeFPE (fpe); return AllocError; } fpe->private = (pointer) dir; } return status;}/* ARGSUSED */intFontFileResetFPE (fpe) FontPathElementPtr fpe;{ FontDirectoryPtr dir; dir = (FontDirectoryPtr) fpe->private; /* * The reset must fail for bitmap fonts because they get cleared when * the path is set. */ if (FontFileDirectoryChanged (dir)) { /* can't do it, so tell the caller to close and re-open */ return FPEResetFailed; } else { if (dir->nonScalable.used > 0) if (!FontFileRegisterBitmapSource (fpe)) { return FPEResetFailed; } return Successful; }}intFontFileFreeFPE (fpe) FontPathElementPtr fpe;{ FontFileUnregisterBitmapSource (fpe); FontFileFreeDir ((FontDirectoryPtr) fpe->private); return Successful;}static inttransfer_values_to_alias(entryname, entrynamelength, resolvedname, aliasName, vals) char *entryname; int entrynamelength; char *resolvedname; char **aliasName; FontScalablePtr vals;{ static char aliasname[MAXFONTNAMELEN]; int nameok = 1, len; char lowerName[MAXFONTNAMELEN]; *aliasName = resolvedname; if ((len = strlen(*aliasName)) <= MAXFONTNAMELEN && FontFileCountDashes (*aliasName, len) == 14) { FontScalableRec tmpVals; FontScalableRec tmpVals2; tmpVals2 = *vals; /* If we're aliasing a scalable name, transfer values from the name into the destination alias, multiplying by matrices that appear in the alias. */ CopyISOLatin1Lowered (lowerName, entryname, entrynamelength); lowerName[entrynamelength] = '\0'; if (FontParseXLFDName(lowerName, &tmpVals, FONT_XLFD_REPLACE_NONE) && !tmpVals.values_supplied && FontParseXLFDName(*aliasName, &tmpVals, FONT_XLFD_REPLACE_NONE)) { double *matrix = 0, tempmatrix[4]; /* Use a matrix iff exactly one is defined */ if ((tmpVals.values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY && !(tmpVals.values_supplied & POINTSIZE_MASK)) matrix = tmpVals.pixel_matrix; else if ((tmpVals.values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY && !(tmpVals.values_supplied & PIXELSIZE_MASK)) matrix = tmpVals.point_matrix; /* If matrix given in the alias, compute new point and/or pixel matrices */ if (matrix) { /* Complete the XLFD name to avoid potential gotchas */ if (FontFileCompleteXLFD(&tmpVals2, &tmpVals2)) { double hypot(); tempmatrix[0] = matrix[0] * tmpVals2.point_matrix[0] + matrix[1] * tmpVals2.point_matrix[2]; tempmatrix[1] = matrix[0] * tmpVals2.point_matrix[1] + matrix[1] * tmpVals2.point_matrix[3]; tempmatrix[2] = matrix[2] * tmpVals2.point_matrix[0] + matrix[3] * tmpVals2.point_matrix[2]; tempmatrix[3] = matrix[2] * tmpVals2.point_matrix[1] + matrix[3] * tmpVals2.point_matrix[3]; tmpVals2.point_matrix[0] = tempmatrix[0]; tmpVals2.point_matrix[1] = tempmatrix[1]; tmpVals2.point_matrix[2] = tempmatrix[2]; tmpVals2.point_matrix[3] = tempmatrix[3]; tempmatrix[0] = matrix[0] * tmpVals2.pixel_matrix[0] + matrix[1] * tmpVals2.pixel_matrix[2]; tempmatrix[1] = matrix[0] * tmpVals2.pixel_matrix[1] + matrix[1] * tmpVals2.pixel_matrix[3]; tempmatrix[2] = matrix[2] * tmpVals2.pixel_matrix[0] + matrix[3] * tmpVals2.pixel_matrix[2]; tempmatrix[3] = matrix[2] * tmpVals2.pixel_matrix[1] + matrix[3] * tmpVals2.pixel_matrix[3]; tmpVals2.pixel_matrix[0] = tempmatrix[0]; tmpVals2.pixel_matrix[1] = tempmatrix[1]; tmpVals2.pixel_matrix[2] = tempmatrix[2]; tmpVals2.pixel_matrix[3] = tempmatrix[3]; tmpVals2.values_supplied = (tmpVals2.values_supplied & ~(PIXELSIZE_MASK | POINTSIZE_MASK)) | PIXELSIZE_ARRAY | POINTSIZE_ARRAY; } else nameok = 0; } CopyISOLatin1Lowered (aliasname, *aliasName, len + 1); if (nameok && FontParseXLFDName(aliasname, &tmpVals2, FONT_XLFD_REPLACE_VALUE)) /* Return a version of the aliasname that has had the vals stuffed into it. To avoid memory leak, this alias name lives in a static buffer. The caller needs to be done with this buffer before this procedure is called again to avoid reentrancy problems. */ *aliasName = aliasname; } } return nameok;}/* ARGSUSED */intFontFileOpenFont (client, fpe, flags, name, namelen, format, fmask, id, pFont, aliasName, non_cachable_font) pointer client; FontPathElementPtr fpe; int flags; char *name; int namelen; fsBitmapFormat format; fsBitmapFormatMask fmask; XID id; FontPtr *pFont; char **aliasName; FontPtr non_cachable_font;{ FontDirectoryPtr dir; char lowerName[MAXFONTNAMELEN]; char fileName[MAXFONTFILENAMELEN*2 + 1]; FontNameRec tmpName; FontEntryPtr entry; FontScalableRec vals; FontScalableEntryPtr scalable; FontScaledPtr scaled; FontBitmapEntryPtr bitmap; FontBCEntryPtr bc; int ret; Bool noSpecificSize; int nranges; fsRange *ranges; if (namelen >= MAXFONTNAMELEN) return AllocError; dir = (FontDirectoryPtr) fpe->private; /* Match non-scalable pattern */ CopyISOLatin1Lowered (lowerName, name, namelen); lowerName[namelen] = '\0'; ranges = FontParseRanges(lowerName, &nranges); tmpName.name = lowerName; tmpName.length = namelen; tmpName.ndashes = FontFileCountDashes (lowerName, namelen); if (!FontParseXLFDName(lowerName, &vals, FONT_XLFD_REPLACE_NONE)) bzero(&vals, sizeof(vals)); if (!(entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName)) && tmpName.ndashes == 14 && FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO)) { tmpName.length = strlen(lowerName); entry = FontFileFindNameInDir (&dir->nonScalable, &tmpName); } if (entry) { int len; switch (entry->type) { case FONT_ENTRY_BITMAP: bitmap = &entry->u.bitmap; if (bitmap->pFont) { *pFont = bitmap->pFont; (*pFont)->fpe = fpe; ret = Successful; } else { ret = FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask, non_cachable_font); if (ret == Successful && *pFont) (*pFont)->fpe = fpe; } break; case FONT_ENTRY_ALIAS: vals.nranges = nranges; vals.ranges = ranges; transfer_values_to_alias(entry->name.name, entry->name.length, entry->u.alias.resolved, aliasName, &vals); ret = FontNameAlias; break;#ifdef NOTYET case FONT_ENTRY_BC: bc = &entry->u.bc; entry = bc->entry; ret = (*scalable->renderer->OpenScalable) (fpe, pFont, flags, entry, &bc->vals, format, fmask, non_cachable_font); if (ret == Successful && *pFont) (*pFont)->fpe = fpe; break;#endif default: ret = BadFontName; } } else { ret = BadFontName; } if (ret != BadFontName) { if (ranges) xfree(ranges); return ret; } /* Match XLFD patterns */ CopyISOLatin1Lowered (lowerName, name, namelen); lowerName[namelen] = '\0'; tmpName.name = lowerName; tmpName.length = namelen; tmpName.ndashes = FontFileCountDashes (lowerName, namelen); if (!FontParseXLFDName (lowerName, &vals, FONT_XLFD_REPLACE_ZERO) || !(tmpName.length = strlen (lowerName), entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals))) { CopyISOLatin1Lowered (lowerName, name, namelen); lowerName[namelen] = '\0'; tmpName.name = lowerName; tmpName.length = namelen; tmpName.ndashes = FontFileCountDashes (lowerName, namelen); entry = FontFileFindNameInScalableDir (&dir->scalable, &tmpName, &vals); if (entry) { strcpy(lowerName, entry->name.name); tmpName.name = lowerName; tmpName.length = entry->name.length; tmpName.ndashes = entry->name.ndashes; } } if (entry) { noSpecificSize = FALSE; /* TRUE breaks XLFD enhancements */ if (entry->type == FONT_ENTRY_SCALABLE && FontFileCompleteXLFD (&vals, &entry->u.scalable.extra->defaults)) { scalable = &entry->u.scalable; if ((vals.values_supplied & PIXELSIZE_MASK) == PIXELSIZE_ARRAY || (vals.values_supplied & POINTSIZE_MASK) == POINTSIZE_ARRAY || (vals.values_supplied & ~SIZE_SPECIFY_MASK & ~CHARSUBSET_SPECIFIED)) scaled = 0; else scaled = FontFileFindScaledInstance (entry, &vals, noSpecificSize); /* * A scaled instance can occur one of two ways: * * Either the font has been scaled to this * size already, in which case scaled->pFont * will point at that font. * * Or a bitmap instance in this size exists, * which is handled as if we got a pattern * matching the bitmap font name. */ if (scaled) { if (scaled->pFont) { *pFont = scaled->pFont; (*pFont)->fpe = fpe; ret = Successful; } else if (scaled->bitmap) { entry = scaled->bitmap; bitmap = &entry->u.bitmap; if (bitmap->pFont) { *pFont = bitmap->pFont; (*pFont)->fpe = fpe; ret = Successful; } else { ret = FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask, non_cachable_font); if (ret == Successful && *pFont) (*pFont)->fpe = fpe; } } else /* "cannot" happen */ { ret = BadFontName; } } else { ret = FontFileMatchBitmapSource (fpe, pFont, flags, entry, &tmpName, &vals, format, fmask, noSpecificSize); if (ret != Successful) { char origName[MAXFONTNAMELEN]; CopyISOLatin1Lowered (origName, name, namelen); origName[namelen] = '\0'; /* Pass the original XLFD name in the vals structure; the rasterizer is free to examine it for hidden meanings. This information will not be saved in the scaled-instances table. */ vals.xlfdName = origName; vals.ranges = ranges; vals.nranges = nranges; strcpy (fileName, dir->directory); strcat (fileName, scalable->fileName); ret = (*scalable->renderer->OpenScalable) (fpe, pFont, flags, entry, fileName, &vals, format, fmask, non_cachable_font); /* In case rasterizer does something bad because of charset subsetting... */ if (ret == Successful && ((*pFont)->info.firstCol > (*pFont)->info.lastCol || (*pFont)->info.firstRow > (*pFont)->info.lastRow)) { (*(*pFont)->unload_font)(*pFont); ret = BadFontName; } /* Save the instance */ if (ret == Successful) { if (FontFileAddScaledInstance (entry, &vals, *pFont, (char *) 0)) ranges = 0; else (*pFont)->fpePrivate = (pointer) 0; (*pFont)->fpe = fpe; } } } } } else ret = BadFontName; if (ranges) xfree(ranges); return ret;}/* ARGSUSED */FontFileCloseFont (fpe, pFont) FontPathElementPtr fpe; FontPtr pFont;{ FontEntryPtr entry; if (entry = (FontEntryPtr) pFont->fpePrivate) { switch (entry->type) { case FONT_ENTRY_SCALABLE: FontFileRemoveScaledInstance (entry, pFont); break; case FONT_ENTRY_BITMAP: entry->u.bitmap.pFont = 0; break; default: /* "cannot" happen */ break; } pFont->fpePrivate = 0; } (*pFont->unload_font) (pFont);}intFontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask, non_cachable_font) FontPathElementPtr fpe; int flags; FontEntryPtr entry; FontPtr *pFont; FontPtr non_cachable_font;{ FontBitmapEntryPtr bitmap; char fileName[MAXFONTFILENAMELEN*2+1]; int ret; FontDirectoryPtr dir; dir = (FontDirectoryPtr) fpe->private; bitmap = &entry->u.bitmap; strcpy (fileName, dir->directory); strcat (fileName, bitmap->fileName); ret = (*bitmap->renderer->OpenBitmap) (fpe, pFont, flags, entry, fileName, format, fmask, non_cachable_font); if (ret == Successful) { bitmap->pFont = *pFont; (*pFont)->fpePrivate = (pointer) entry; } return ret;}intFontFileOpenBitmap (fpe, pFont, flags, entry, format, fmask) FontPathElementPtr fpe; int flags; FontEntryPtr entry; FontPtr *pFont;{ return FontFileOpenBitmapNCF (fpe, pFont, flags, entry, format, fmask, (FontPtr)0);}FontFileGetInfoBitmap (fpe, pFontInfo, entry) FontPathElementPtr fpe; FontInfoPtr pFontInfo; FontEntryPtr entry;{ FontBitmapEntryPtr bitmap; char fileName[MAXFONTFILENAMELEN*2+1]; int ret; FontDirectoryPtr dir; dir = (FontDirectoryPtr) fpe->private; bitmap = &entry->u.bitmap; strcpy (fileName, dir->directory); strcat (fileName, bitmap->fileName); ret = (*bitmap->renderer->GetInfoBitmap) (fpe, pFontInfo, entry, fileName); return ret;}static void_FontFileAddScalableNames(names, scaleNames, nameptr, zeroChars, vals, ranges, nranges, max) FontNamesPtr names; FontNamesPtr scaleNames; FontNamePtr *nameptr; char *zeroChars;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -