📄 t1funcs.c
字号:
/* $TOG: t1funcs.c /main/23 1997/06/09 14:55:44 barstow $ *//* Copyright International Business Machines,Corp. 1991 * All Rights Reserved * * License, subject to the license given below, to use, * copy, modify, and distribute this software * and its * documentation for any purpose and without fee is hereby * granted, provided that the above copyright notice appear * in all copies and that both that copyright notice and * this permission notice appear in supporting documentation, * and that the name of IBM not be used in advertising or * publicity pertaining to distribution of the software * without specific, written prior permission. * * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF * THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE QUALITY AND * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT * OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY PORTION OF * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION. IN * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. * * Author: Jeffrey B. Lotspiech, IBM Almaden Research Center * Modeled on spfuncs.c by Dave Lemke, Network Computing Devices, Inc * which contains the following copyright and permission notices: * * Copyright 1990, 1991 Network Computing Devices; * Portions Copyright 1987 by Digital Equipment Corporation * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the names of Network Computing Devices * or Digital not be used in advertising or publicity pertaining to * distribution of the software without specific, written prior permission. * Network Computing Devices or Digital make no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *//* $XFree86: xc/lib/font/Type1/t1funcs.c,v 3.4.2.1 1997/07/05 15:55:35 dawes Exp $ *//*Copyright (c) 1987, 1994 X ConsortiumPermission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and/or sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice shall be includedin all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OROTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shallnot be used in advertising or otherwise to promote the sale, use orother dealings in this Software without prior written authorizationfrom the X Consortium.*/ #include <string.h>#ifdef _XOPEN_SOURCE#include <math.h>#else#define _XOPEN_SOURCE /* to get prototype for hypot on some systems */#include <math.h>#undef _XOPEN_SOURCE#endif#include "X11/Xfuncs.h"#include "fntfilst.h"#include "FSproto.h"#include "t1intf.h" #include "objects.h"#include "spaces.h"#include "regions.h"#include "t1stdio.h"#include "util.h"#include "fontfcn.h" int Type1OpenScalable ();static int Type1GetGlyphs();void Type1CloseFont();extern int Type1GetInfoScalable (); static int Type1GetMetrics (); #define minchar(p) ((p).min_char_low + ((p).min_char_high << 8))#define maxchar(p) ((p).max_char_low + ((p).max_char_high << 8))static void fillrun(); extern psfont *FontP;extern psobj *ISOLatin1EncArrayP;extern unsigned long *Xalloc();static void fill(); /*ARGSUSED*/int Type1OpenScalable (fpe, ppFont, flags, entry, fileName, vals, format, fmask, non_cachable_font) FontPathElementPtr fpe; FontPtr *ppFont; int flags; FontEntryPtr entry; char *fileName; FontScalablePtr vals; fsBitmapFormat format; fsBitmapFormatMask fmask; FontPtr non_cachable_font; /* We don't do licensing */{ extern struct XYspace *IDENTITY; extern Bool fontfcnA(); extern struct region *fontfcnB(); FontPtr pFont; int bit, byte, glyph, scan, image; int pad,wordsize; /* scan & image in bits */ unsigned long *pool; /* memory pool for ximager objects */ int size; /* for memory size calculations */ struct XYspace *S; /* coordinate space for character */ struct region *area; CharInfoRec *glyphs; register int i; int len, rc, count = 0; struct type1font *type1; char *p; psobj *fontencoding = NULL; fsRange char_range; psobj *fontmatrix; long x0, total_width = 0, total_raw_width = 0; double x1, y1, t1 = .001, t2 = 0.0, t3 = 0.0, t4 = .001; double sxmult; /* Reject ridiculously small font sizes that will blow up the math */ if (hypot(vals->pixel_matrix[0], vals->pixel_matrix[1]) < 1.0 || hypot(vals->pixel_matrix[2], vals->pixel_matrix[3]) < 1.0) return BadFontName; /* set up default values */ FontDefaultFormat(&bit, &byte, &glyph, &scan); /* get any changes made from above */ rc = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image); if (rc != Successful) return rc; pad = glyph * 8; wordsize = scan * 8; #define PAD(bits, pad) (((bits)+(pad)-1)&-(pad)) pFont = (FontPtr) xalloc(sizeof(FontRec)); if (pFont == NULL) return AllocError; type1 = (struct type1font *)xalloc(sizeof(struct type1font)); if (type1 == NULL) { xfree(pFont); return AllocError; } bzero(type1, sizeof(struct type1font)); /* heuristic for "maximum" size of pool we'll need: */ size = 200000 + 120 * (int)hypot(vals->pixel_matrix[2], vals->pixel_matrix[3]) * sizeof(short); if (size < 0 || NULL == (pool = (unsigned long *) xalloc(size))) { xfree(type1); xfree(pFont); return AllocError; } addmemory(pool, size); glyphs = type1->glyphs; /* load font if not already loaded */ if (!fontfcnA(fileName, &rc)) { delmemory(); xfree(type1); xfree(pFont); xfree(pool); return Type1ReturnCodeToXReturnCode(rc); } fontmatrix = &FontP->fontInfoP[FONTMATRIX].value; if (objPIsArray(fontmatrix) && fontmatrix->len == 6) {#define assign(n,d,f) if (objPIsInteger(fontmatrix->data.arrayP + n)) \ d = fontmatrix->data.arrayP[n].data.integer; \ else if (objPIsReal(fontmatrix->data.arrayP + n)) \ d = fontmatrix->data.arrayP[n].data.real; \ else d = f; assign(0, t1, .001); assign(1, t2, 0.0); assign(2, t3, 0.0); assign(3, t4, .001); } S = (struct XYspace *) t1_Transform(IDENTITY, t1, t2, t3, t4); S = (struct XYspace *) Permanent(t1_Transform(S, vals->pixel_matrix[0], -vals->pixel_matrix[1], vals->pixel_matrix[2], -vals->pixel_matrix[3])); /* multiplier for computation of raw values */ sxmult = hypot(vals->pixel_matrix[0], vals->pixel_matrix[1]); if (sxmult > EPS) sxmult = 1000.0 / sxmult; p = entry->name.name + entry->name.length - 19; if (entry->name.ndashes == 14 && p >= entry->name.name && !strcmp (p, "-adobe-fontspecific")) { fontencoding = FontP->fontInfoP[ENCODING].value.data.arrayP; } if (!fontencoding) fontencoding = ISOLatin1EncArrayP; pFont->info.firstCol = 255; pFont->info.lastCol = FIRSTCOL; for (i=0; i < 256-FIRSTCOL; i++) { long h,w; long paddedW; int j; char *codename; codename = fontencoding[i + FIRSTCOL].data.valueP; len = fontencoding[i + FIRSTCOL].len; if (len == 7 && strcmp(codename,".notdef")==0) continue; /* See if this character is in the list of ranges specified in the XLFD name */ for (j = 0; j < vals->nranges; j++) if (i + FIRSTCOL >= minchar(vals->ranges[j]) && i + FIRSTCOL <= maxchar(vals->ranges[j])) break; /* If not, don't realize it. */ if (vals->nranges && j == vals->nranges) continue; if (pFont->info.firstCol > i + FIRSTCOL) pFont->info.firstCol = i + FIRSTCOL; if (pFont->info.lastCol < i + FIRSTCOL) pFont->info.lastCol = i + FIRSTCOL; rc = 0; area = fontfcnB(S, codename, &len, &rc); if (rc < 0) { rc = Type1ReturnCodeToXReturnCode(rc); break; } else if (rc > 0) continue; if (area == NULL) continue; h = area->ymax - area->ymin; w = area->xmax - area->xmin; paddedW = PAD(w, pad); if (h > 0 && w > 0) { size = h * paddedW / 8; glyphs[i].bits = (char *)xalloc(size); if (glyphs[i].bits == NULL) { rc = AllocError; break; } } else { size = 0; h = w = 0; area->xmin = area->xmax = 0; area->ymax = area->ymax = 0; } glyphs[i].metrics.leftSideBearing = area->xmin; x1 = (double)(x0 = area->ending.x - area->origin.x); y1 = (double)(area->ending.y - area->origin.y); glyphs[i].metrics.characterWidth = (x0 + (x0 > 0 ? FPHALF : -FPHALF)) / (1 << FRACTBITS); if (!glyphs[i].metrics.characterWidth && size == 0) { /* Zero size and zero extents: presumably caused by the choice of transformation. Let's create a small bitmap so we're not mistaken for an undefined character. */ h = w = 1; size = paddedW = PAD(w, pad); glyphs[i].bits = (char *)xalloc(size); if (glyphs[i].bits == NULL) { rc = AllocError; break; } } glyphs[i].metrics.attributes = NEARESTPEL((long)(hypot(x1, y1) * sxmult)); total_width += glyphs[i].metrics.attributes; total_raw_width += abs((int)(INT16)glyphs[i].metrics.attributes); count++; glyphs[i].metrics.rightSideBearing = w + area->xmin; glyphs[i].metrics.descent = area->ymax - NEARESTPEL(area->origin.y); glyphs[i].metrics.ascent = h - glyphs[i].metrics.descent; bzero(glyphs[i].bits, size);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -