home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / fonts / server / MacFS / MacFontInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-29  |  6.0 KB  |  206 lines

  1. /***********************************************************************
  2. Copyright 1991 by Apple Computer, Inc, Cupertino, California
  3.             All Rights Reserved
  4.  
  5. Permission to use, copy, modify, and distribute this software
  6. for any purpose and without fee is hereby granted, provided
  7. that the above copyright notice appear in all copies.
  8.  
  9. APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS,
  10. OR IMPLIED, WITH RESPECT TO THIS SOFTWARE, ITS QUALITY,
  11. PERFORMANCE, MERCHANABILITY, OR FITNESS FOR A PARTICULAR
  12. PURPOSE. AS A RESULT, THIS SOFTWARE IS PROVIDED "AS IS,"
  13. AND YOU THE USER ARE ASSUMING THE ENTIRE RISK AS TO ITS
  14. QUALITY AND PERFORMANCE. IN NO EVENT WILL APPLE BE LIABLE 
  15. FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  16. DAMAGES RESULTING FROM ANY DEFECT IN THE SOFTWARE.
  17.  
  18. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE
  19. AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR
  20. IMPLIED.
  21.  
  22. ***********************************************************************/
  23. /*
  24.  * Copyright 1990, 1991 Network Computing Devices;
  25.  * Portions Copyright 1987 by Digital Equipment Corporation and the
  26.  * Massachusetts Institute of Technology
  27.  *
  28.  * Permission to use, copy, modify, and distribute this protoype software
  29.  * and its documentation to Members and Affiliates of the MIT X Consortium
  30.  * any purpose and without fee is hereby granted, provided
  31.  * that the above copyright notice appear in all copies and that both that
  32.  * copyright notice and this permission notice appear in supporting
  33.  * documentation, and that the names of Network Computing Devices, Digital or
  34.  * MIT not be used in advertising or publicity pertaining to distribution of
  35.  * the software without specific, written prior permission.
  36.  *
  37.  * NETWORK COMPUTING DEVICES, DIGITAL AND MIT DISCLAIM ALL WARRANTIES WITH
  38.  * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  39.  * AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, DIGITAL OR MIT BE
  40.  * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  41.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  42.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  43.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  44.  *
  45.  * Author: Dave Lemke, Network Computing Devices, Inc
  46.  *
  47.  */
  48.  
  49. #include     "MacFont.h"
  50. #include    "fontfilest.h"
  51. #define APPLE    "Apple Computer, Inc."
  52.  
  53. enum scaleType {
  54.     atom, pixel_size, point_size, resolution_x, resolution_y, average_width,
  55.     scaledX, scaledY, unscaled, scaledXoverY, uncomputed,
  56.     weight, x_height, quad_width
  57. };
  58.  
  59. typedef struct _fontProp {
  60.     char       *name;
  61.     long        atom;
  62.     enum scaleType type;
  63. }           fontProp;
  64.  
  65. static fontProp fontNamePropTable[] = {
  66.     "FOUNDRY", 0, atom,
  67.     "FAMILY_NAME", 0, atom,
  68.     "WEIGHT_NAME", 0, atom,
  69.     "SLANT", 0, atom,
  70.     "SETWIDTH_NAME", 0, atom,
  71.     "ADD_STYLE_NAME", 0, atom,
  72.     "PIXEL_SIZE", 0, pixel_size,
  73.     "POINT_SIZE", 0, point_size,
  74.     "RESOLUTION_X", 0, resolution_x,
  75.     "RESOLUTION_Y", 0, resolution_y,
  76.     "SPACING", 0, atom,
  77.     "AVERAGE_WIDTH", 0, average_width,
  78.     "CHARSET_REGISTRY", 0, atom,
  79.     "CHARSET_ENCODING", 0, atom,
  80. };
  81.  
  82. static fontProp extraProps[] = {
  83.     "FONT", 0, atom,
  84.     "COPYRIGHT", 0, atom,
  85.     "WEIGHT", 0, weight,
  86.     "X_HEIGHT", 0, x_height,
  87.     "QUAD_WIDTH", 0, quad_width,
  88. };
  89.  
  90. /* this is a bit kludgy */
  91. #define    FONTPROP    0
  92. #define    COPYRIGHTPROP    1
  93. #define WEIGHTPROP    2
  94. #define X_HEIGHTPROP    3
  95. #define QUAD_WIDTHPROP    4
  96.  
  97. #define NNAMEPROPS (sizeof(fontNamePropTable) / sizeof(fontProp))
  98. #define NEXTRAPROPS (sizeof(extraProps) / sizeof(fontProp))
  99.  
  100. #define    NPROPS    (NNAMEPROPS + NEXTRAPROPS)
  101.  
  102.  
  103. void
  104. MacFontStandardProps()
  105. {
  106.     int         i;
  107.     fontProp   *t;
  108.  
  109.     i = sizeof(fontNamePropTable) / sizeof(fontProp);
  110.     for (t = fontNamePropTable; i; i--, t++)
  111.     t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
  112.     i = sizeof(extraProps) / sizeof(fontProp);
  113.     for (t = extraProps; i; i--, t++)
  114.     t->atom = MakeAtom(t->name, (unsigned) strlen(t->name), TRUE);
  115. }
  116.  
  117.  
  118. void
  119. MacFontComputedProps(fontname, vals, pinfo, pMacPriv)
  120.     char       *fontname;
  121.     FontScalablePtr vals;
  122.     FontInfoPtr pinfo;
  123.     MacBitmapFontRecPtr pMacPriv;
  124. {
  125.     FontPropPtr pp;
  126.     int         i,
  127.                 nprops;
  128.     fontProp   *fpt;
  129.     char       *is_str;
  130.     char       *ptr1,
  131.                *ptr2;
  132.  
  133.     nprops = pinfo->nprops = NPROPS;
  134.     pinfo->isStringProp = (char *) xalloc(sizeof(char) * nprops);
  135.     pinfo->props = (FontPropPtr) xalloc(sizeof(FontPropRec) * nprops);
  136.     if (!pinfo->isStringProp || !pinfo->props) {
  137.     xfree(pinfo->isStringProp);
  138.     pinfo->isStringProp = (char *) 0;
  139.     xfree(pinfo->props);
  140.     pinfo->props = (FontPropPtr) 0;
  141.     return;
  142.     }
  143.     bzero(pinfo->isStringProp, (sizeof(char) * nprops));
  144.  
  145.     ptr2 = fontname;
  146.     for (i = NNAMEPROPS, pp = pinfo->props, fpt = fontNamePropTable,
  147.         is_str = pinfo->isStringProp;
  148.         i;
  149.         i--, pp++, fpt++, is_str++) {
  150.     ptr1 = ptr2 + 1;
  151.     if (*ptr1 == '-')
  152.         ptr2 = ptr1;
  153.     else {
  154.         if (i > 1)
  155.         ptr2 = index(ptr1 + 1, '-');
  156.         else
  157.         ptr2 = index(ptr1 + 1, '\0');
  158.     }
  159.     pp->name = fpt->atom;
  160.     switch (fpt->type) {
  161.     case atom:
  162.         *is_str = TRUE;
  163.         pp->value = MakeAtom(ptr1, ptr2 - ptr1, TRUE);
  164.         break;
  165.     case pixel_size:
  166.         pp->value = vals -> pixel;
  167.         break;
  168.     case point_size:
  169.         pp->value = vals -> point;
  170.         break;
  171.     case resolution_x:
  172.         pp->value = vals -> x;
  173.         break;
  174.     case resolution_y:
  175.         pp->value = vals -> y;
  176.         break;
  177.     case average_width:
  178.         pp->value = pMacPriv -> avgWidth;
  179.         break;
  180.     }
  181.     }
  182.  
  183.     for (i = 0, fpt = extraProps; i < NEXTRAPROPS; i++, is_str++, pp++, fpt++) {
  184.     pp->name = fpt->atom;
  185.     switch (i) {
  186.     case FONTPROP:
  187.         *is_str = TRUE;
  188.         pp->value = MakeAtom(fontname, strlen(fontname), TRUE);
  189.         break;
  190.     case COPYRIGHTPROP:
  191.         *is_str = TRUE;
  192.         pp->value = MakeAtom(APPLE, strlen(APPLE), TRUE);
  193.         break;
  194.     case WEIGHTPROP:
  195.         pp->value = pMacPriv->weight;
  196.         break;
  197.     case X_HEIGHTPROP:
  198.         pp->value = pMacPriv->xHeight;
  199.         break;
  200.     case QUAD_WIDTHPROP:
  201.         pp->value = pMacPriv->quadWidth;
  202.     }
  203.     }
  204. }
  205.  
  206.