Back to index

tetex-bin  3.0
t1info.c
Go to the documentation of this file.
00001 /* $XConsortium: t1info.c,v 1.9 92/03/20 16:00:13 eswu Exp $ */
00002 /* Copyright International Business Machines,Corp. 1991
00003  * All Rights Reserved
00004  *
00005  * License, subject to the license given below, to use,
00006  * copy, modify, and distribute this software * and its
00007  * documentation for any purpose and without fee is hereby
00008  * granted, provided that the above copyright notice appear
00009  * in all copies and that both that copyright notice and
00010  * this permission notice appear in supporting documentation,
00011  * and that the name of IBM not be used in advertising or
00012  * publicity pertaining to distribution of the software
00013  * without specific, written prior permission.
00014  *
00015  * IBM PROVIDES THIS SOFTWARE "AS IS", WITHOUT ANY WARRANTIES
00016  * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT
00017  * LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT OF
00019  * THIRD PARTY RIGHTS.  THE ENTIRE RISK AS TO THE QUALITY AND
00020  * PERFORMANCE OF THE SOFTWARE, INCLUDING ANY DUTY TO SUPPORT
00021  * OR MAINTAIN, BELONGS TO THE LICENSEE.  SHOULD ANY PORTION OF
00022  * THE SOFTWARE PROVE DEFECTIVE, THE LICENSEE (NOT IBM) ASSUMES
00023  * THE ENTIRE COST OF ALL SERVICING, REPAIR AND CORRECTION.  IN
00024  * NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
00025  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
00026  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
00027  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
00028  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
00029  * SOFTWARE.
00030  *
00031  * Author: Carol H. Thompson  IBM Almaden Research Center
00032  *   Modeled on spinfo.c by Dave Lemke, Network Computing Devices, Inc
00033  *   which contains the following copyright and permission notices:
00034  *
00035  * Copyright 1990, 1991 Network Computing Devices;
00036  * Portions Copyright 1987 by Digital Equipment Corporation and the
00037  * Massachusetts Institute of Technology
00038  *
00039  * Permission to use, copy, modify, and distribute this protoype software
00040  * and its documentation to Members and Affiliates of the MIT X Consortium
00041  * any purpose and without fee is hereby granted, provided
00042  * that the above copyright notice appear in all copies and that both that
00043  * copyright notice and this permission notice appear in supporting
00044  * documentation, and that the names of Network Computing Devices, Digital or
00045  * MIT not be used in advertising or publicity pertaining to distribution of
00046  * the software without specific, written prior permission.
00047  *
00048  * NETWORK COMPUTING DEVICES, DIGITAL AND MIT DISCLAIM ALL WARRANTIES WITH
00049  * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00050  * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, DIGITAL OR MIT BE
00051  * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00052  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
00053  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00054  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00055  */
00056 
00057 #include "types.h"
00058 #include <stdio.h> 
00059 #include <string.h> 
00060 #include "ffilest.h"
00061 #ifdef XSERVER
00062 #include "FSproto.h"
00063 #endif
00064 #include "ffilest.h"
00065 #include "t1intf.h"
00066 
00067 extern char *Xalloc(int size);
00068 extern void Xfree(void *);
00069 extern int FontComputeInfoAccelerators(FontInfoPtr);
00070 extern long MakeAtom(char *, unsigned int, Bool);
00071 extern int Type1OpenScalable(FontPathElementPtr ev , FontPtr *ppFont ,
00072                           int flags,
00073                           FontEntryPtr entry,
00074                           char *fileName,
00075                           FontScalablePtr vals,
00076                           unsigned long format,
00077                           unsigned long fmask,double efactor,double slant);
00078 extern void Type1CloseFont(struct _Font *pFont);
00079 extern void QueryFontLib(char *env,char *infoName,void *infoValue,int *rcodeP);
00080 
00081 #define DECIPOINTSPERINCH 722.7
00082 #define DEFAULTRES 75
00083 #define DEFAULTPOINTSIZE 120
00084  
00085 enum scaleType {
00086     atom, pixel_size, point_size, resolution_x, resolution_y,
00087     average_width, scaledX, scaledY, unscaled, scaledXoverY,
00088     uncomputed
00089 };
00090  
00091 typedef struct _fontProp {
00092     char       *name;
00093     LONG        atom;
00094     enum scaleType type;
00095 }           fontProp;
00096  
00097 static fontProp fontNamePropTable[] = {  /* Example: */
00098     "FOUNDRY", 0, atom,                  /* adobe */
00099     "FAMILY_NAME", 0, atom,              /* times roman */
00100     "WEIGHT_NAME", 0, atom,              /* bold */
00101     "SLANT", 0, atom,                    /* i */
00102     "SETWIDTH_NAME", 0, atom,            /* normal */
00103     "ADD_STYLE_NAME", 0, atom,           /* */
00104     "PIXEL_SIZE", 0, pixel_size,         /* 18 */
00105     "POINT_SIZE", 0, point_size,         /* 180 */
00106     "RESOLUTION_X", 0, resolution_x,     /* 72 */
00107     "RESOLUTION_Y", 0, resolution_y,     /* 72 */
00108     "SPACING", 0, atom,                  /* p */
00109     "AVERAGE_WIDTH", 0, average_width,   /* 0 */
00110     "CHARSET_REGISTRY", 0, atom,         /* ISO8859 */
00111     "CHARSET_ENCODING", 0, atom,         /* 1 */
00112 };
00113  
00114 static fontProp extraProps[] = {
00115     "FONT", 0, atom,
00116     "COPYRIGHT", 0, atom,
00117 };
00118  
00119 /* this is a bit kludgy */
00120 #define FONTPROP        0
00121 #define COPYRIGHTPROP   1
00122  
00123 #define NNAMEPROPS (sizeof(fontNamePropTable) / sizeof(fontProp))
00124 #define NEXTRAPROPS (sizeof(extraProps) / sizeof(fontProp))
00125  
00126 #define NPROPS  (NNAMEPROPS + NEXTRAPROPS)
00127  
00128 /*ARGSUSED*/
00129 static void
00130 FillHeader(pInfo, Vals)
00131     FontInfoPtr         pInfo;
00132     FontScalablePtr     Vals;
00133 {
00134     /* OpenScalable in T1FUNCS sets the following:
00135     pInfo->firstCol,
00136     pInfo->firstRow,
00137     pInfo->lastCol, and
00138     pInfo->lastRow. */
00139     /* the following are ununsed
00140     pInfo->pad. */
00141  
00142     /* Items we should handle better someday +++ */
00143     pInfo->defaultCh = 0;
00144     pInfo->drawDirection = LeftToRight;
00145     /* our size is based only on Vals->pixel, so we won't
00146        create an anamorphic font (yet) */
00147     pInfo->anamorphic = 0;
00148     pInfo->inkMetrics = 0;  /* no ink metrics here */
00149     pInfo->cachable = 1;    /* no licensing (yet) */
00150 }
00151  
00152 static void
00153 adjust_min_max(minc, maxc, tmp)
00154     xCharInfo  *minc,
00155                *maxc,
00156                *tmp;
00157 {
00158 #define MINMAX(field,ci) \
00159         if (minc->field > (ci)->field) \
00160              minc->field = (ci)->field; \
00161         if (maxc->field < (ci)->field) \
00162             maxc->field = (ci)->field;
00163  
00164     MINMAX(ascent, tmp);
00165     MINMAX(descent, tmp);
00166     MINMAX(leftSideBearing, tmp);
00167     MINMAX(rightSideBearing, tmp);
00168     MINMAX(characterWidth, tmp);
00169  
00170 #undef  MINMAX
00171 }
00172  
00173 static void
00174 ComputeBounds(pInfo, pChars, Vals)
00175     FontInfoPtr         pInfo;
00176     CharInfoPtr         pChars;
00177     FontScalablePtr     Vals;
00178 {
00179     int i;
00180     xCharInfo minchar, maxchar;
00181     LONG width = 0;
00182     int numchars = 0;
00183     int totchars;
00184     int overlap;
00185     int maxlap;
00186  
00187     minchar.ascent = minchar.descent =
00188         minchar.leftSideBearing = minchar.rightSideBearing =
00189         minchar.characterWidth = 32767;
00190     minchar.attributes = 0;  /* What's this for? +++ */
00191     maxchar.ascent = maxchar.descent =
00192         maxchar.leftSideBearing = maxchar.rightSideBearing =
00193         maxchar.characterWidth = -32767;
00194     maxchar.attributes = 0;
00195  
00196     maxlap = -32767;
00197     totchars = pInfo->lastCol - pInfo->firstCol + 1;
00198     pInfo->allExist = 1;
00199     for (i = 0; i < totchars; i++,pChars++) {
00200         xCharInfo *pmetrics = &pChars->metrics;
00201  
00202         if (pmetrics->characterWidth) {
00203             width += pmetrics->characterWidth;
00204             numchars++;
00205             adjust_min_max(&minchar, &maxchar, pmetrics);
00206             overlap = pmetrics->rightSideBearing - pmetrics->characterWidth;
00207             if (overlap > maxlap) maxlap = overlap;
00208         }
00209         else pInfo->allExist = 0;
00210     }
00211 
00212     Vals->width = ((width * 10)+((numchars+1)/2)) / numchars;
00213     /* (We think the above average width value should be put into
00214         the Vals structure.  This may be wrong, and the proper
00215         behavior might be to regard the values in Vals as sacred,
00216         and for us to squirrel the computed number in a static, and
00217         then use that static in ComputeStdProps.) */
00218     pInfo->maxbounds = maxchar;
00219     pInfo->minbounds = minchar;
00220     pInfo->ink_maxbounds = maxchar;
00221     pInfo->ink_minbounds = minchar;
00222     pInfo->maxOverlap = maxlap + -(minchar.leftSideBearing);
00223  
00224     /* Set the pInfo flags */
00225     /* Properties set by FontComputeInfoAccelerators:
00226         pInfo->noOverlap;
00227         pInfo->terminalFont;
00228         pInfo->constantMetrics;
00229         pInfo->constantWidth;
00230         pInfo->inkInside;
00231  
00232     */
00233     FontComputeInfoAccelerators (pInfo);
00234 }
00235  
00236 static void
00237 ComputeProps(pInfo, Vals, Filename)
00238     FontInfoPtr         pInfo;
00239     FontScalablePtr     Vals;
00240     char                *Filename;
00241 {
00242     int infoint;
00243     int infoBBox[4];
00244     int rc;
00245  
00246     QueryFontLib(Filename, "isFixedPitch", &infoint, &rc);
00247     if (!rc) {
00248         pInfo->constantWidth = infoint;
00249     }
00250     QueryFontLib((char *)0, "FontBBox", infoBBox, &rc);
00251     if (!rc) {
00252         pInfo->fontAscent = (infoBBox[3] * Vals->pixel) / 1000;
00253         pInfo->fontDescent = - (infoBBox[1] * Vals->pixel) / 1000;
00254     }
00255 }
00256  
00257 static void
00258 ComputeStdProps(pInfo, Vals, Filename, Fontname)
00259     FontInfoPtr         pInfo;
00260     FontScalablePtr     Vals;
00261     char                *Filename;
00262     char                *Fontname;
00263 {
00264     FontPropPtr pp;
00265     int         i,
00266                 nprops;
00267     fontProp   *fpt;
00268     char       *is_str;
00269     char       *ptr1,
00270                *ptr2;
00271     char *infostrP;
00272     LONG rc;
00273     char      scaledName[MAXFONTNAMELEN];
00274  
00275     strcpy (scaledName, Fontname);
00276 #ifdef WIN32
00277     /* Fill in our copy of the fontname from the Vals structure */
00278     FontParseXLFDName (scaledName, Vals, FONT_XLFD_REPLACE_VALUE);
00279 #endif
00280  
00281     /* This form of the properties is used by the X-client; the X-server
00282        doesn't care what they are. */
00283     nprops = pInfo->nprops = NPROPS;
00284     pInfo->isStringProp = (char *) Xalloc(sizeof(char) * nprops);
00285     pInfo->props = (FontPropPtr) Xalloc(sizeof(FontPropRec) * nprops);
00286     if (!pInfo->isStringProp || !pInfo->props) {
00287         Xfree(pInfo->isStringProp);
00288         pInfo->isStringProp = (char *) 0;
00289         Xfree(pInfo->props);
00290         pInfo->props = (FontPropPtr) 0;
00291         return;
00292     }
00293     (void) memset(pInfo->isStringProp, 0, (sizeof(char) * nprops));
00294  
00295     ptr2 = scaledName;
00296     for (i = NNAMEPROPS, pp = pInfo->props, fpt = fontNamePropTable, is_str = pInfo->isStringProp;
00297             i;
00298             i--, pp++, fpt++, is_str++) {
00299         ptr1 = ptr2 + 1;
00300         if (*ptr1 == '-')
00301             ptr2 = ptr1;
00302         else {
00303             if (i > 1)
00304                 ptr2 = strchr(ptr1 + 1, '-');
00305             else
00306                 ptr2 = strchr(ptr1 + 1, '\0');
00307         }
00308         pp->name = fpt->atom;
00309         switch (fpt->type) {
00310          case atom:  /* Just copy info from scaledName */
00311             *is_str = TRUE;
00312             pp->value = MakeAtom(ptr1, ptr2 - ptr1, TRUE);
00313             break;
00314          case pixel_size:
00315             pp->value = Vals->pixel;
00316             break;
00317          case point_size:
00318             pp->value = Vals->point;
00319             break;
00320          case resolution_x:
00321             pp->value = Vals->x;
00322             break;
00323          case resolution_y:
00324             pp->value = Vals->y;
00325             break;
00326          case average_width:
00327             pp->value = Vals->width;
00328             break;
00329         }
00330     }
00331  
00332     for (i = 0, fpt = extraProps;
00333           i < NEXTRAPROPS;
00334           i++, is_str++, pp++, fpt++) {
00335         pp->name = fpt->atom;
00336         switch (i) {
00337          case FONTPROP:
00338             /* Why do we need this property -- nice for debug anyway */
00339             *is_str = TRUE;
00340             pp->value = MakeAtom(scaledName, strlen(scaledName), TRUE);
00341             break;
00342          case COPYRIGHTPROP:
00343             *is_str = TRUE;
00344             QueryFontLib(Filename, "Notice", &infostrP, &rc);
00345             if (rc || !infostrP) {
00346                 infostrP = "Copyright Notice not available";
00347             }
00348             pp->value = MakeAtom(infostrP, strlen(infostrP), TRUE);
00349             break;
00350         }
00351     }
00352 }
00353  
00354 /*ARGSUSED*/
00355 int
00356 Type1GetInfoScalable(fpe, pInfo, entry, fontName, fileName, Vals)
00357     FontPathElementPtr  fpe;
00358     FontInfoPtr         pInfo;
00359     FontEntryPtr        entry;
00360     FontNamePtr         fontName;
00361     char                *fileName;
00362     FontScalablePtr     Vals;
00363 {
00364     FontPtr pfont;
00365     int flags = 0;
00366     LONG format = 0;  /* It doesn't matter what format for just info */
00367     LONG fmask = 0;
00368     int ret;
00369  
00370     ret = Type1OpenScalable(fpe, &pfont, flags, entry, fileName, Vals, format, fmask, 1.0, 0.0);
00371     if (ret != Successful)
00372        return ret;
00373     *pInfo = pfont->info;
00374 
00375     /* XXX - Set pointers in pfont->info to NULL so they are not freed. */
00376     pfont->info.props = NULL;
00377     pfont->info.isStringProp = NULL;
00378 
00379     Type1CloseFont(pfont);
00380     return Successful;
00381 }
00382  
00383 void
00384 T1FillFontInfo(pFont, Vals, Filename, Fontname)
00385     FontPtr             pFont;
00386     FontScalablePtr     Vals;
00387     char                *Filename;
00388     char                *Fontname;
00389 {
00390     FontInfoPtr         pInfo = &pFont->info;
00391     struct type1font *p = (struct type1font *)pFont->fontPrivate;
00392  
00393     FillHeader(pInfo, Vals);
00394  
00395     ComputeBounds(pInfo, p->glyphs, Vals);
00396  
00397     ComputeProps(pInfo, Vals, Filename);
00398     ComputeStdProps(pInfo, Vals, Filename, Fontname);
00399 }
00400  
00401 /* Called once, at renderer registration time */
00402 void
00403 T1InitStdProps()
00404 {
00405     int         i;
00406     fontProp   *t;
00407  
00408     i = sizeof(fontNamePropTable) / sizeof(fontProp);
00409     for (t = fontNamePropTable; i; i--, t++)
00410         t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
00411     i = sizeof(extraProps) / sizeof(fontProp);
00412     for (t = extraProps; i; i--, t++)
00413         t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
00414 }