home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / ZFONT1.C < prev    next >
C/C++ Source or Header  |  1994-07-27  |  6KB  |  153 lines

  1. /* Copyright (C) 1991, 1992, 1993 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* zfont1.c */
  20. /* Type 1 font creation operator */
  21. #include "ghost.h"
  22. #include "errors.h"
  23. #include "oper.h"
  24. #include "gxfixed.h"
  25. #include "gsmatrix.h"
  26. #include "gxdevice.h"
  27. #include "gschar.h"
  28. #include "gxfont.h"
  29. #include "gxfont1.h"
  30. #include "bfont.h"
  31. #include "ialloc.h"
  32. #include "idict.h"
  33. #include "idparam.h"
  34. #include "store.h"
  35.  
  36. /* Type 1 auxiliary procedures (defined in zchar1.c) */
  37. extern int z1_subr_proc(P3(gs_type1_data *, int, const byte **));
  38. extern int z1_push_proc(P3(gs_type1_data *, const fixed *, int));
  39. extern int z1_pop_proc(P2(gs_type1_data *, fixed *));
  40.  
  41. /* Default value of lenIV */
  42. #define default_lenIV 4
  43.  
  44. /* <string|name> <font_dict> .buildfont1 <string|name> <font> */
  45. /* Build a type 1 (Adobe encrypted) font. */
  46. int
  47. zbuildfont1(os_ptr op)
  48. {    gs_type1_data data1;
  49.     ref *pothersubrs;
  50.     ref *psubrs;
  51.     ref *pcharstrings;
  52.     ref *pprivate;
  53.     static ref no_subrs;
  54.     gs_font_type1 *pfont;
  55.     font_data *pdata;
  56.     int code;
  57.     check_type(*op, t_dictionary);
  58.     code = dict_int_param(op, "PaintType", 0, 3, 0, &data1.PaintType);
  59.     if ( code < 0 ) return code;
  60.     if ( dict_find_string(op, "CharStrings", &pcharstrings) <= 0 ||
  61.         !r_has_type(pcharstrings, t_dictionary) ||
  62.         dict_find_string(op, "Private", &pprivate) <= 0 ||
  63.         !r_has_type(pprivate, t_dictionary)
  64.        )
  65.         return_error(e_invalidfont);
  66.     make_array(&no_subrs, 0, 0, NULL);
  67.     if ( dict_find_string(pprivate, "OtherSubrs", &pothersubrs) > 0 )
  68.     {    check_array_else(*pothersubrs, e_invalidfont);
  69.     }
  70.     else
  71.         pothersubrs = &no_subrs;
  72.     if ( dict_find_string(pprivate, "Subrs", &psubrs) > 0 )
  73.     {    check_array_else(*psubrs, e_invalidfont);
  74.     }
  75.     else
  76.         psubrs = &no_subrs;
  77.     /* Get the rest of the information from the Private dictionary. */
  78.     if ( (code = dict_int_param(pprivate, "lenIV", 0, 255,
  79.                     default_lenIV, &data1.lenIV)) < 0 ||
  80.          (code = dict_int_param(pprivate, "BlueFuzz", 0, 1999, 1,
  81.                     &data1.BlueFuzz)) < 0 ||
  82.          (code = dict_float_param(pprivate, "BlueScale", 0.039625,
  83.                       &data1.BlueScale)) < 0 ||
  84.          (code = dict_float_param(pprivate, "BlueShift", 7.0,
  85.                     &data1.BlueShift)) < 0 ||
  86.          (code = data1.BlueValues.count = dict_float_array_param(pprivate,
  87.         "BlueValues", max_BlueValues * 2,
  88.         &data1.BlueValues.values[0], NULL)) < 0 ||
  89.          (code = dict_float_param(pprivate, "ExpansionFactor", 0.06,
  90.                       &data1.ExpansionFactor)) < 0 ||
  91.          (code = data1.FamilyBlues.count = dict_float_array_param(pprivate,
  92.         "FamilyBlues", max_FamilyBlues * 2,
  93.         &data1.FamilyBlues.values[0], NULL)) < 0 ||
  94.          (code = data1.FamilyOtherBlues.count = dict_float_array_param(pprivate,
  95.         "FamilyOtherBlues", max_FamilyOtherBlues * 2,
  96.         &data1.FamilyOtherBlues.values[0], NULL)) < 0 ||
  97.          (code = dict_bool_param(pprivate, "ForceBold", false,
  98.                      &data1.ForceBold)) < 0 ||
  99.          (code = dict_int_param(pprivate, "LanguageGroup", 0, 1, 0,
  100.                     &data1.LanguageGroup)) < 0 ||
  101.          (code = data1.OtherBlues.count = dict_float_array_param(pprivate,
  102.         "OtherBlues", max_OtherBlues * 2,
  103.         &data1.OtherBlues.values[0], NULL)) < 0 ||
  104.          (code = dict_bool_param(pprivate, "RndStemUp", false,
  105.                      &data1.RndStemUp)) < 0 ||
  106.          (code = data1.StdHW.count = dict_float_array_param(pprivate,
  107.         "StdHW", 1, &data1.StdHW.values[0], NULL)) < 0 ||
  108.          (code = data1.StdVW.count = dict_float_array_param(pprivate,
  109.         "StdVW", 1, &data1.StdVW.values[0], NULL)) < 0 ||
  110.          (code = data1.StemSnapH.count = dict_float_array_param(pprivate,
  111.         "StemSnapH", max_StemSnap,
  112.         &data1.StemSnapH.values[0], NULL)) < 0 ||
  113.          (code = data1.StemSnapV.count = dict_float_array_param(pprivate,
  114.         "StemSnapV", max_StemSnap,
  115.         &data1.StemSnapV.values[0], NULL)) < 0
  116.        )
  117.         return code;
  118.     /* Do the work common to all non-composite font types. */
  119.     {    build_proc_refs build;
  120.         code = build_proc_name_refs(&build,
  121.             "Type1BuildChar", "Type1BuildGlyph");
  122.         if ( code < 0 ) return code;
  123.         code = build_gs_simple_font(op, (gs_font_base **)&pfont,
  124.                         ft_encrypted,
  125.                         &st_gs_font_type1, &build);
  126.     }
  127.     if ( code != 0 ) return code;
  128.     /* This is a new font, fill it in. */
  129.     pdata = pfont_data(pfont);
  130.     pfont->data = data1;
  131.     ref_assign(&pdata->CharStrings, pcharstrings);
  132.     ref_assign(&pdata->OtherSubrs, pothersubrs);
  133.     ref_assign(&pdata->Subrs, psubrs);
  134.     pfont->data.subr_proc = z1_subr_proc;
  135.     pfont->data.push_proc = z1_push_proc;
  136.     pfont->data.pop_proc = z1_pop_proc;
  137.     pfont->data.proc_data = (char *)pdata;
  138.     /* Check that the UniqueIDs match.  This is part of the */
  139.     /* Adobe protection scheme, but we may as well emulate it. */
  140.     if ( uid_is_valid(&pfont->UID) &&
  141.          !dict_check_uid_param(op, &pfont->UID)
  142.        )
  143.         uid_set_invalid(&pfont->UID);
  144.     return define_gs_font((gs_font *)pfont);
  145. }
  146.  
  147. /* ------ Initialization procedure ------ */
  148.  
  149. op_def zfont1_op_defs[] = {
  150.     {"2.buildfont1", zbuildfont1},
  151.     op_def_end(0)
  152. };
  153.