1 /* $TOG: t1info.c /main/20 1997/06/09 11:21:53 barstow $ */
2 /* Copyright International Business Machines,Corp. 1991
5 * License, subject to the license given below, to use,
6 * copy, modify, and distribute this software * and its
7 * documentation for any purpose and without fee is hereby
8 * granted, provided that the above copyright notice appear
9 * in all copies and that both that copyright notice and
10 * this permission notice appear in supporting documentation,
11 * and that the name of IBM not be used in advertising or
12 * publicity pertaining to distribution of the software
13 * without specific, written prior permission.
15 * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
16 * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
17 * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
19 * THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE QUALITY AND
20 * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
21 * OR MAINTAIN, BELONGS TO THE LICENSEE. SHOULD ANY PORTION OF
22 * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
23 * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION. IN
24 * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
25 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
26 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
27 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
28 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
31 * Author: Carol H. Thompson IBM Almaden Research Center
32 * Modeled on spinfo.c by Dave Lemke, Network Computing Devices, Inc
33 * which contains the following copyright and permission notices:
35 * Copyright 1990, 1991 Network Computing Devices;
36 * Portions Copyright 1987 by Digital Equipment Corporation
38 * Permission to use, copy, modify, distribute, and sell this software and its
39 * documentation for any purpose is hereby granted without fee, provided that
40 * the above copyright notice appear in all copies and that both that
41 * copyright notice and this permission notice appear in supporting
42 * documentation, and that the names of Network Computing Devices or Digital
43 * not be used in advertising or publicity pertaining to distribution of the
44 * software without specific, written prior permission. Network Computing
45 * Devices and Digital make no representations about the suitability of this
46 * software for any purpose. It is provided "as is" without express or
49 * NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
50 * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
51 * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES OR DIGITAL BE
52 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
53 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
54 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
55 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
60 Copyright (c) 1987 X Consortium
62 Permission is hereby granted, free of charge, to any person obtaining
63 a copy of this software and associated documentation files (the
64 "Software"), to deal in the Software without restriction, including
65 without limitation the rights to use, copy, modify, merge, publish,
66 distribute, sublicense, and/or sell copies of the Software, and to
67 permit persons to whom the Software is furnished to do so, subject to
68 the following conditions:
70 The above copyright notice and this permission notice shall be included
71 in all copies or substantial portions of the Software.
73 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
74 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
75 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
76 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
77 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
78 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
79 OTHER DEALINGS IN THE SOFTWARE.
81 Except as contained in this notice, the name of the X Consortium shall
82 not be used in advertising or otherwise to promote the sale, use or
83 other dealings in this Software without prior written authorization
84 from the X Consortium.
94 #define DECIPOINTSPERINCH 722.7
96 #define DEFAULTPOINTSIZE 120
99 atom, truncate_atom, pixel_size, point_size, resolution_x,
100 resolution_y, average_width
103 typedef struct _fontProp {
109 static fontProp fontNamePropTable[] = { /* Example: */
110 "FOUNDRY", 0, atom, /* adobe */
111 "FAMILY_NAME", 0, atom, /* times roman */
112 "WEIGHT_NAME", 0, atom, /* bold */
113 "SLANT", 0, atom, /* i */
114 "SETWIDTH_NAME", 0, atom, /* normal */
115 "ADD_STYLE_NAME", 0, atom, /* */
116 "PIXEL_SIZE", 0, pixel_size, /* 18 */
117 "POINT_SIZE", 0, point_size, /* 180 */
118 "RESOLUTION_X", 0, resolution_x, /* 72 */
119 "RESOLUTION_Y", 0, resolution_y, /* 72 */
120 "SPACING", 0, atom, /* p */
121 "AVERAGE_WIDTH", 0, average_width, /* 0 */
122 "CHARSET_REGISTRY", 0, atom, /* ISO8859 */
123 "CHARSET_ENCODING", 0, truncate_atom, /* 1 */
126 /* NOTICE: Following array is closely related to the sequence of defines
128 static fontProp extraProps[] = {
131 "RAW_PIXEL_SIZE", 0, 0,
132 "RAW_POINT_SIZE", 0, 0,
135 "RAW_AVERAGE_WIDTH", 0, 0,
139 /* this is a bit kludgy */
141 #define COPYRIGHTPROP 1
142 #define RAWPIXELPROP 2
143 #define RAWPOINTPROP 3
144 #define RAWASCENTPROP 4
145 #define RAWDESCENTPROP 5
146 #define RAWWIDTHPROP 6
147 #define FACE_NAMEPROP 7
149 #define NNAMEPROPS (sizeof(fontNamePropTable) / sizeof(fontProp))
150 #define NEXTRAPROPS (sizeof(extraProps) / sizeof(fontProp))
152 #define NPROPS (NNAMEPROPS + NEXTRAPROPS)
156 FillHeader(pInfo, Vals)
158 FontScalablePtr Vals;
160 /* OpenScalable in T1FUNCS sets the following:
165 /* the following are ununsed
168 /* Items we should handle better someday +++ */
169 pInfo->defaultCh = 0;
170 pInfo->drawDirection = LeftToRight;
171 if (Vals->point_matrix[0] == Vals->point_matrix[3])
172 pInfo->anamorphic = 0;
174 pInfo->anamorphic = 1;
175 pInfo->inkMetrics = 0; /* no ink metrics here */
176 pInfo->cachable = 1; /* no licensing (yet) */
180 adjust_min_max(minc, maxc, tmp)
185 #define MINMAX(field,ci) \
186 if (minc->field > (ci)->field) \
187 minc->field = (ci)->field; \
188 if (maxc->field < (ci)->field) \
189 maxc->field = (ci)->field;
192 MINMAX(descent, tmp);
193 MINMAX(leftSideBearing, tmp);
194 MINMAX(rightSideBearing, tmp);
195 MINMAX(characterWidth, tmp);
197 /* Do MINMAX for attributes field. Since that field is CARD16,
198 we'll cast to a signed integer */
199 if ((INT16)minc->attributes > (INT16)tmp->attributes)
200 minc->attributes = tmp->attributes;
201 if ((INT16)maxc->attributes < (INT16)tmp->attributes)
202 maxc->attributes = tmp->attributes;
208 ComputeBounds(pInfo, pChars, Vals)
211 FontScalablePtr Vals;
214 xCharInfo minchar, maxchar;
220 minchar.ascent = minchar.descent =
221 minchar.leftSideBearing = minchar.rightSideBearing =
222 minchar.characterWidth = minchar.attributes = 32767;
223 maxchar.ascent = maxchar.descent =
224 maxchar.leftSideBearing = maxchar.rightSideBearing =
225 maxchar.characterWidth = maxchar.attributes = -32767;
228 totchars = pInfo->lastCol - pInfo->firstCol + 1;
229 pChars += pInfo->firstCol - FIRSTCOL;
231 for (i = 0; i < totchars; i++,pChars++) {
232 xCharInfo *pmetrics = &pChars->metrics;
234 if (pmetrics->attributes ||
235 pmetrics->ascent != -pmetrics->descent ||
236 pmetrics->leftSideBearing != pmetrics->rightSideBearing) {
238 adjust_min_max(&minchar, &maxchar, pmetrics);
239 overlap = pmetrics->rightSideBearing - pmetrics->characterWidth;
240 if (overlap > maxlap) maxlap = overlap;
242 else pInfo->allExist = 0;
245 /* If we're monospaced, round the average width field to the
247 if (minchar.characterWidth == maxchar.characterWidth)
248 Vals->width = minchar.characterWidth * 10;
250 pInfo->maxbounds = maxchar;
251 pInfo->minbounds = minchar;
252 pInfo->ink_maxbounds = maxchar;
253 pInfo->ink_minbounds = minchar;
254 pInfo->maxOverlap = maxlap + -(minchar.leftSideBearing);
256 /* Set the pInfo flags */
257 /* Properties set by FontComputeInfoAccelerators:
260 pInfo->constantMetrics;
261 pInfo->constantWidth;
265 FontComputeInfoAccelerators (pInfo);
269 ComputeProps(pInfo, Vals, Filename, sAscent, sDescent)
271 FontScalablePtr Vals;
280 QueryFontLib(Filename, "isFixedPitch", &infoint, &rc);
282 pInfo->constantWidth = infoint;
284 QueryFontLib((char *)0, "FontBBox", infoBBox, &rc);
287 (int)((double)infoBBox[3] * Vals->pixel_matrix[3] +
288 (infoBBox[3] > 0 ? 500 : -500)) / 1000;
290 -(int)((double)infoBBox[1] * Vals->pixel_matrix[3] +
291 (infoBBox[1] > 0 ? 500 : -500)) / 1000;
292 *sAscent = infoBBox[3];
293 *sDescent = -infoBBox[1];
298 ComputeStdProps(pInfo, Vals, Filename, Fontname, sAscent, sDescent, sWidth)
300 FontScalablePtr Vals;
317 char scaledName[MAXFONTNAMELEN];
319 strcpy (scaledName, Fontname);
320 /* Fill in our copy of the fontname from the Vals structure */
321 FontParseXLFDName (scaledName, Vals, FONT_XLFD_REPLACE_VALUE);
323 /* This form of the properties is used by the X-client; the X-server
324 doesn't care what they are. */
325 nprops = pInfo->nprops = NPROPS;
326 pInfo->isStringProp = (char *) xalloc(sizeof(char) * nprops);
327 pInfo->props = (FontPropPtr) xalloc(sizeof(FontPropRec) * nprops);
328 if (!pInfo->isStringProp || !pInfo->props) {
329 xfree(pInfo->isStringProp);
330 pInfo->isStringProp = (char *) 0;
332 pInfo->props = (FontPropPtr) 0;
335 bzero(pInfo->isStringProp, (sizeof(char) * nprops));
338 for (i = NNAMEPROPS, pp = pInfo->props, fpt = fontNamePropTable, is_str = pInfo->isStringProp;
340 i--, pp++, fpt++, is_str++) {
345 if (!(ptr2 = strchr(ptr1, '-'))) ptr2 = strchr(ptr1, '\0');
348 pp->name = fpt->atom;
350 case atom: /* Just copy info from scaledName */
352 pp->value = MakeAtom(ptr1, ptr2 - ptr1, TRUE);
356 for (ptr3 = ptr1; *ptr3; ptr3++)
359 pp->value = MakeAtom(ptr1, ptr3 - ptr1, TRUE);
362 pp->value = (int)(fabs(Vals->pixel_matrix[3]) + .5);
365 pp->value = (int)(fabs(Vals->point_matrix[3]) * 10.0 + .5);
374 pp->value = Vals->width;
379 for (i = 0, fpt = extraProps;
381 i++, is_str++, pp++, fpt++) {
382 pp->name = fpt->atom;
386 pp->value = MakeAtom(scaledName, strlen(scaledName), TRUE);
390 QueryFontLib(Filename, "Notice", &infostrP, &rc);
391 if (rc || !infostrP) {
392 infostrP = "Copyright Notice not available";
394 pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
398 QueryFontLib(Filename, "FontName", &infostrP, &rc);
399 if (rc || !infostrP) {
400 infostrP = "(unknown)";
402 pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
410 pp->value = (long)(72270.0 / (double)Vals->y + .5);
418 pp->value = sDescent;
430 Type1GetInfoScalable(fpe, pInfo, entry, fontName, fileName, Vals)
431 FontPathElementPtr fpe;
434 FontNamePtr fontName;
436 FontScalablePtr Vals;
440 long format = 0; /* It doesn't matter what format for just info */
444 ret = Type1OpenScalable(fpe, &pfont, flags, entry, fileName, Vals, format, fmask);
445 if (ret != Successful)
447 *pInfo = pfont->info;
449 /* XXX - Set pointers in pfont->info to NULL so they are not freed. */
450 pfont->info.props = NULL;
451 pfont->info.isStringProp = NULL;
453 Type1CloseFont(pfont);
458 T1FillFontInfo(pFont, Vals, Filename, Fontname, sWidth)
460 FontScalablePtr Vals;
465 FontInfoPtr pInfo = &pFont->info;
466 struct type1font *p = (struct type1font *)pFont->fontPrivate;
467 long sAscent, sDescent; /* Scalable 1000-pixel values */
469 FillHeader(pInfo, Vals);
471 ComputeBounds(pInfo, p->glyphs, Vals);
473 ComputeProps(pInfo, Vals, Filename, &sAscent, &sDescent);
474 ComputeStdProps(pInfo, Vals, Filename, Fontname, sAscent, sDescent, sWidth);
477 /* Called once, at renderer registration time */
484 i = sizeof(fontNamePropTable) / sizeof(fontProp);
485 for (t = fontNamePropTable; i; i--, t++)
486 t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
487 i = sizeof(extraProps) / sizeof(fontProp);
488 for (t = extraProps; i; i--, t++)
489 t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);