home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / fonts / server / MacFS / MacFontFuncs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-29  |  8.3 KB  |  286 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. #include    "fontfilest.h"
  49. extern Boolean CGetOutlinePreferred();
  50. extern Boolean CGetPreserveGlyph();
  51.  
  52. static int
  53. MacFontOpenBitmap (fpe, ppFont, flags, entry, fileName, format, fmask)
  54.     FontPathElementPtr    fpe;
  55.     FontPtr        *ppFont;
  56.     int            flags;
  57.     FontEntryPtr    entry;
  58.     char        *fileName;
  59.     fsBitmapFormat    format;
  60.     fsBitmapFormatMask    fmask;
  61. {
  62.     FontPtr    pFont;
  63.     FontScalableRec    vals;
  64.     int        ret;
  65.     int        bit, byte, glyph, scan, image;
  66.  
  67.     pFont = (FontPtr) xalloc(sizeof(FontRec));
  68.     if (!pFont) return AllocError;
  69.     pFont->refcnt = 0;
  70.     pFont->maxPrivate = -1;
  71.     pFont->devPrivates = (pointer *) 0;
  72.  
  73.  
  74.     if (!FontParseXLFDName(entry->name.name, &vals, FONT_XLFD_REPLACE_NONE))
  75.     return BadFontName; /* XXX how about non-XLFD names? */
  76.  
  77.     /* set up default values */
  78.     FontDefaultFormat(&bit, &byte, &glyph, &scan);
  79.     /* get any changes made from above */
  80.     ret = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
  81.  
  82.     ret = MacFontRenderFont(pFont, entry, &vals, bit, byte, glyph, scan);
  83.  
  84.     if (ret != Successful)
  85.         xfree(pFont);
  86.     else
  87.         *ppFont = pFont;
  88.     return ret;
  89. }
  90.  
  91. static int
  92. MacFontOpenScalable (fpe, ppFont, flags, entry, fileName, vals, format, fmask)
  93.     FontPathElementPtr    fpe;
  94.     FontPtr        *ppFont;
  95.     int            flags;
  96.     FontEntryPtr    entry;
  97.     char        *fileName;
  98.     FontScalablePtr    vals;
  99.     fsBitmapFormat    format;
  100.     fsBitmapFormatMask    fmask;
  101. {
  102.     FontPtr    pFont;
  103.     int        ret;
  104.     int        bit, byte, glyph, scan, image;
  105.  
  106.     pFont = (FontPtr) xalloc(sizeof(FontRec));
  107.     if (!pFont) return AllocError;
  108.     pFont->refcnt = 0;
  109.     pFont->maxPrivate = -1;
  110.     pFont->devPrivates = (pointer *) 0;
  111.  
  112.  
  113.     /* set up default values */
  114.     FontDefaultFormat(&bit, &byte, &glyph, &scan);
  115.     /* get any changes made from above */
  116.     ret = CheckFSFormat(format, fmask, &bit, &byte, &scan, &glyph, &image);
  117.  
  118.     ret = MacFontRenderFont(pFont, entry, vals, bit, byte, glyph, scan);
  119.  
  120.     if (ret != Successful)
  121.         xfree(pFont);
  122.     else
  123.         *ppFont = pFont;
  124.     return ret;
  125. }
  126.  
  127. static int
  128. MacFontOpenTrueTypeScalable (fpe, ppFont, flags, entry, fileName, vals, format, fmask)
  129.     FontPathElementPtr    fpe;
  130.     FontPtr        *ppFont;
  131.     int            flags;
  132.     FontEntryPtr    entry;
  133.     char        *fileName;
  134.     FontScalablePtr    vals;
  135.     fsBitmapFormat    format;
  136.     fsBitmapFormatMask    fmask;
  137. {
  138.     int ret;
  139.     Boolean    saveOutlinePreferred, savePreserveGlyph;
  140.  
  141.     saveOutlinePreferred = CGetOutlinePreferred();
  142.     CSetOutlinePreferred(true);
  143.     savePreserveGlyph = CGetPreserveGlyph();
  144.     CSetPreserveGlyph(true);
  145.     ret = MacFontOpenScalable (fpe, ppFont, flags, entry, fileName, vals, 
  146.                                format, fmask);
  147.     CSetPreserveGlyph(savePreserveGlyph);
  148.     CSetOutlinePreferred(saveOutlinePreferred);
  149.     return ret;
  150. }
  151.  
  152. static int
  153. MacFontOpenBitmapScalable (fpe, ppFont, flags, entry, fileName, vals, format, 
  154.                            fmask)
  155.     FontPathElementPtr    fpe;
  156.     FontPtr        *ppFont;
  157.     int            flags;
  158.     FontEntryPtr    entry;
  159.     char        *fileName;
  160.     FontScalablePtr    vals;
  161.     fsBitmapFormat    format;
  162.     fsBitmapFormatMask    fmask;
  163. {
  164.     int ret;
  165.     Boolean    saveOutlinePreferred, savePreserveGlyph;
  166.  
  167.     saveOutlinePreferred = CGetOutlinePreferred();
  168.     CSetOutlinePreferred(false);
  169.     savePreserveGlyph = CGetPreserveGlyph();
  170.     CSetPreserveGlyph(false);
  171.     ret = MacFontOpenScalable (fpe, ppFont, flags, entry, fileName, vals, 
  172.                                format, fmask);
  173.     CSetPreserveGlyph(savePreserveGlyph);
  174.     CSetOutlinePreferred(saveOutlinePreferred);
  175.     return ret;
  176. }
  177.  
  178. static int
  179. MacFontBadFontName()
  180. {
  181.     return BadFontName;
  182. }
  183.  
  184. static int
  185. MacFontGetInfoBitmap (fpe, pFontInfo, entry, fontName, fileName, vals)
  186.     FontPathElementPtr  fpe;
  187.     FontInfoPtr         pFontInfo;
  188.     FontEntryPtr        entry;
  189.     FontNamePtr         fontName;
  190.     char                *fileName;
  191.     FontScalablePtr     vals;
  192. {
  193.     FontPtr        pFont;
  194.     int            flags = 0;
  195.     fsBitmapFormat    format = 0;
  196.     fsBitmapFormatMask    fmask = 0;
  197.     int            ret;
  198.  
  199.     ret = MacFontOpenBitmap(fpe, &pFont, flags, entry, fileName, format, fmask);
  200.     if (ret == Successful) {
  201.         *pFontInfo = pFont->info;
  202.         pFont->info.props = 0;
  203.         pFont->info.isStringProp = 0;
  204.         pFont->info.nprops = 0;
  205.         MacFontUnloadFont(pFont);
  206.     }
  207.     return ret;
  208. }
  209.  
  210. static int
  211. MacFontGetInfoBitmapScalable (fpe, pFontInfo, entry, fontName, fileName, vals)
  212.     FontPathElementPtr  fpe;
  213.     FontInfoPtr         pFontInfo;
  214.     FontEntryPtr        entry;
  215.     FontNamePtr         fontName;
  216.     char                *fileName;
  217.     FontScalablePtr     vals;
  218. {
  219.     FontPtr        pFont;
  220.     int            flags = 0;
  221.     fsBitmapFormat    format = 0;
  222.     fsBitmapFormatMask    fmask = 0;
  223.     int            ret;
  224.  
  225.     ret = MacFontOpenBitmapScalable (fpe, &pFont, flags, entry, fileName, vals,
  226.                                      format, fmask);
  227.     if (ret == Successful) {
  228.         *pFontInfo = pFont->info;
  229.         pFont->info.props = 0;
  230.         pFont->info.isStringProp = 0;
  231.         pFont->info.nprops = 0;
  232.         MacFontUnloadFont(pFont);
  233.     }
  234.     return ret;
  235. }
  236.  
  237. static int
  238. MacFontGetInfoTrueTypeScalable (fpe, pFontInfo, entry, fontName, fileName, vals)
  239.     FontPathElementPtr  fpe;
  240.     FontInfoPtr         pFontInfo;
  241.     FontEntryPtr        entry;
  242.     FontNamePtr         fontName;
  243.     char                *fileName;
  244.     FontScalablePtr     vals;
  245. {
  246.     FontPtr        pFont;
  247.     int            flags = 0;
  248.     fsBitmapFormat    format = 0;
  249.     fsBitmapFormatMask    fmask = 0;
  250.     int            ret;
  251.  
  252.     ret = MacFontOpenTrueTypeScalable(fpe, &pFont, flags, entry, fileName, vals,
  253.                                      format, fmask);
  254.     if (ret == Successful) {
  255.         *pFontInfo = pFont->info;
  256.         pFont->info.props = 0;
  257.         pFont->info.isStringProp = 0;
  258.         pFont->info.nprops = 0;
  259.         MacFontUnloadFont(pFont);
  260.     }
  261.     return ret;
  262. }
  263.  
  264. static FontRendererRec renderer[] = {
  265.     ".mac", 4, 
  266.     MacFontOpenBitmap, MacFontOpenBitmapScalable, 
  267.     MacFontGetInfoBitmap, MacFontGetInfoBitmapScalable,  0,
  268.     ".tt",  3, 
  269.     MacFontBadFontName, MacFontOpenTrueTypeScalable, 
  270.     MacFontBadFontName, MacFontGetInfoTrueTypeScalable,  0,
  271. };
  272.  
  273. void MacBlockHandler();
  274. void MacWakeupHandler();
  275.     
  276. MacFontRegisterFontFileFunctions()
  277. {
  278.     MacFontStandardProps();
  279.  
  280.     FontFileRegisterRenderer (&renderer[0]);
  281.     FontFileRegisterRenderer (&renderer[1]);
  282.  
  283.     RegisterBlockAndWakeupHandlers(MacBlockHandler, MacWakeupHandler, 0);
  284.     InitMacWorld(); /* XXX move to osinit.c */
  285. }
  286.