home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / g / gs252src.zip / GS252 / ZFONT1.C < prev    next >
C/C++ Source or Header  |  1992-07-10  |  8KB  |  209 lines

  1. /* Copyright (C) 1991, 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* zfont1.c */
  21. /* Type 1 font creation operator for Ghostscript */
  22. #include "ghost.h"
  23. #include "errors.h"
  24. #include "oper.h"
  25. #include "gxfixed.h"
  26. #include "gsmatrix.h"
  27. #include "gxdevice.h"
  28. #include "gschar.h"
  29. #include "gxfont.h"
  30. #include "bfont.h"
  31. #include "dict.h"
  32. #include "dparam.h"
  33. #include "name.h"
  34. #include "store.h"
  35.  
  36. /* Type 1 auxiliary procedures (defined in zchar.c) */
  37. extern int z1_subr_proc(P3(gs_type1_data *, int, const byte **));
  38. extern int z1_pop_proc(P2(gs_type1_data *, fixed *));
  39.  
  40. /* Names of system-known keys in font dictionaries: */
  41. static ref name_PaintType;
  42. extern ref name_UniqueID;        /* in zfont2 */
  43. static ref name_Type1BuildChar;
  44. static ref name_Private;
  45. static ref name_CharStrings;        /* only needed for seac */
  46. /* Names of system-known keys in type 1 font Private dictionary: */
  47. static ref name_BlueFuzz;
  48. static ref name_BlueScale;
  49. static ref name_BlueShift;
  50. static ref name_BlueValues;
  51. static ref name_ExpansionFactor;
  52. static ref name_FamilyBlues;
  53. static ref name_FamilyOtherBlues;
  54. static ref name_ForceBold;
  55. static ref name_LanguageGroup;
  56. static ref name_lenIV;
  57. static ref name_OtherBlues;
  58. static ref name_RndStemUp;
  59. static ref name_StdHW;
  60. static ref name_StdVW;
  61. static ref name_StemSnapH;
  62. static ref name_StemSnapV;
  63. static ref name_Subrs;
  64.  
  65. /* Default value of lenIV */
  66. #define default_lenIV 4
  67.  
  68. /* Initialize the font building operators */
  69. private void
  70. zfont1_init()
  71. {    static const names_def fnd1[] = {
  72.  
  73.     /* Create the names of the standard elements of */
  74.     /* a font dictionary. */
  75.        { "PaintType", &name_PaintType },
  76.        { "Type1BuildChar", &name_Type1BuildChar },
  77.        { "Private", &name_Private },
  78.        { "CharStrings", &name_CharStrings },
  79.  
  80.     /* Create the names of the known entries in */
  81.     /* a type 1 font Private dictionary. */
  82.        { "BlueFuzz", &name_BlueFuzz },
  83.        { "BlueScale", &name_BlueScale },
  84.        { "BlueShift", &name_BlueShift },
  85.        { "BlueValues", &name_BlueValues },
  86.        { "ExpansionFactor", &name_ExpansionFactor },
  87.        { "FamilyBlues", &name_FamilyBlues },
  88.        { "FamilyOtherBlues", &name_FamilyOtherBlues },
  89.        { "ForceBold", &name_ForceBold },
  90.        { "LanguageGroup", &name_LanguageGroup },
  91.        { "lenIV", &name_lenIV },
  92.        { "OtherBlues", &name_OtherBlues },
  93.        { "RndStemUp", &name_RndStemUp },
  94.        { "StdHW", &name_StdHW },
  95.        { "StdVW", &name_StdVW },
  96.        { "StemSnapH", &name_StemSnapH },
  97.        { "StemSnapV", &name_StemSnapV },
  98.        { "Subrs", &name_Subrs },
  99.  
  100.     /* Mark the end of the initalized name list. */
  101.        names_def_end
  102.     };
  103.  
  104.     init_names(fnd1);
  105.  
  106.     /* Make the standard BuildChar procedures executable. */
  107.     r_set_attrs(&name_Type1BuildChar, a_executable);
  108. }
  109.  
  110. /* .buildfont1 */
  111. /* Build a type 1 (Adobe encrypted) font. */
  112. int
  113. zbuildfont1(os_ptr op)
  114. {    gs_type1_data data1;
  115.     ref *psubrs;
  116.     ref *pcharstrings;
  117.     ref *pprivate;
  118.     ref *puniqueid;
  119.     static ref no_subrs;
  120.     gs_font *pfont;
  121.     font_data *pdata;
  122.     int code;
  123.     check_type(*op, t_dictionary);
  124.     code = dict_int_param(op, &name_PaintType, 0, 3, 0, &data1.PaintType);
  125.     if ( code < 0 ) return code;
  126.     if ( dict_find(op, &name_CharStrings, &pcharstrings) <= 0 ||
  127.         !r_has_type(pcharstrings, t_dictionary) ||
  128.         dict_find(op, &name_Private, &pprivate) <= 0 ||
  129.         !r_has_type(pprivate, t_dictionary)
  130.        )
  131.         return e_invalidfont;
  132.     if ( dict_find(pprivate, &name_Subrs, &psubrs) > 0 )
  133.        {    check_array_else(*psubrs, e_invalidfont);
  134.        }
  135.     else
  136.        {    make_tasv(&no_subrs, t_string, 0, 0, bytes, (byte *)0),
  137.         psubrs = &no_subrs;
  138.        }
  139.     /* Get the rest of the information from the Private dictionary. */
  140.     if ( (code = dict_int_param(pprivate, &name_lenIV, 0, 255,
  141.                     default_lenIV, &data1.lenIV)) < 0 ||
  142.          (code = dict_int_param(pprivate, &name_BlueFuzz, 0, 1999, 1,
  143.                     &data1.BlueFuzz)) < 0 ||
  144.          (code = dict_float_param(pprivate, &name_BlueScale, 0.039625,
  145.                       &data1.BlueScale)) < 0 ||
  146.          (code = dict_float_param(pprivate, &name_BlueShift, 7.0,
  147.                     &data1.BlueShift)) < 0 ||
  148.          (code = data1.BlueValues.count = dict_float_array_param(pprivate,
  149.         &name_BlueValues, max_BlueValues * 2,
  150.         &data1.BlueValues.data[0], NULL)) < 0 ||
  151.          (code = dict_float_param(pprivate, &name_ExpansionFactor, 0.06,
  152.                       &data1.ExpansionFactor)) < 0 ||
  153.          (code = data1.FamilyBlues.count = dict_float_array_param(pprivate,
  154.         &name_FamilyBlues, max_FamilyBlues * 2,
  155.         &data1.FamilyBlues.data[0], NULL)) < 0 ||
  156.          (code = data1.FamilyOtherBlues.count = dict_float_array_param(pprivate,
  157.         &name_FamilyOtherBlues, max_FamilyOtherBlues * 2,
  158.         &data1.FamilyOtherBlues.data[0], NULL)) < 0 ||
  159.          (code = dict_bool_param(pprivate, &name_ForceBold, 0,
  160.                      &data1.ForceBold)) < 0 ||
  161.          (code = dict_int_param(pprivate, &name_LanguageGroup, 0, 1, 0,
  162.                     &data1.LanguageGroup)) < 0 ||
  163.          (code = data1.OtherBlues.count = dict_float_array_param(pprivate,
  164.         &name_OtherBlues, max_OtherBlues * 2,
  165.         &data1.OtherBlues.data[0], NULL)) < 0 ||
  166.          (code = dict_bool_param(pprivate, &name_RndStemUp, 0,
  167.                      &data1.RndStemUp)) < 0 ||
  168.          (code = data1.StdHW.count = dict_float_array_param(pprivate,
  169.         &name_StdHW, 1, &data1.StdHW.data[0], NULL)) < 0 ||
  170.          (code = data1.StdVW.count = dict_float_array_param(pprivate,
  171.         &name_StdVW, 1, &data1.StdVW.data[0], NULL)) < 0 ||
  172.          (code = data1.StemSnapH.count = dict_float_array_param(pprivate,
  173.         &name_StemSnapH, max_StemSnap,
  174.         &data1.StemSnapH.data[0], NULL)) < 0 ||
  175.          (code = data1.StemSnapV.count = dict_float_array_param(pprivate,
  176.         &name_StemSnapV, max_StemSnap,
  177.         &data1.StemSnapV.data[0], NULL)) < 0
  178.        )
  179.         return code;
  180.     /* Do the work common to all non-composite font types. */
  181.     code = build_gs_simple_font(op, &pfont, ft_encrypted, &name_Type1BuildChar);
  182.     if ( code != 0 ) return code;
  183.     /* This is a new font, fill it in. */
  184.     pdata = (font_data *)pfont->client_data;
  185.     pfont->data.base.type1_data = data1;
  186.     ref_assign(&pdata->CharStrings, pcharstrings);
  187.     ref_assign(&pdata->Subrs, psubrs);
  188.     pfont->data.base.type1_data.subr_proc = z1_subr_proc;
  189.     pfont->data.base.type1_data.pop_proc = z1_pop_proc;
  190.     pfont->data.base.type1_data.proc_data = (char *)pdata;
  191.     /* Check that the UniqueIDs match.  This is part of the */
  192.     /* Adobe protection scheme, but we may as well emulate it. */
  193.     if ( pfont->data.base.UniqueID >= 0 )
  194.        {    if ( dict_find(pprivate, &name_UniqueID, &puniqueid) <= 0 ||
  195.              !r_has_type(puniqueid, t_integer) ||
  196.              puniqueid->value.intval != pfont->data.base.UniqueID
  197.            )
  198.             pfont->data.base.UniqueID = -1;
  199.        }
  200.     return 0;
  201. }
  202.  
  203. /* ------ Initialization procedure ------ */
  204.  
  205. op_def zfont1_op_defs[] = {
  206.     {"1.buildfont1", zbuildfont1},
  207.     op_def_end(zfont1_init)
  208. };
  209.