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 / GSTYPE1.C < prev    next >
C/C++ Source or Header  |  1992-09-15  |  20KB  |  649 lines

  1. /* Copyright (C) 1990, 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. /* gstype1.c */
  21. /* Adobe Type 1 font routines for Ghostscript library */
  22. #include "math_.h"
  23. #include "memory_.h"
  24. #include "gx.h"
  25. #include "gserrors.h"
  26. #include "gxarith.h"
  27. #include "gxfixed.h"
  28. #include "gxmatrix.h"
  29. #include "gzstate.h"
  30. #include "gzdevice.h"            /* for gxchar */
  31. #include "gxdevmem.h"            /* ditto */
  32. #include "gzpath.h"
  33. #include "gxchar.h"
  34. #include "gxfont.h"
  35. #include "gxtype1.h"
  36. #include "gxop1.h"
  37.  
  38. /* Define the amount of thickening to be applied to characters. */
  39. /* This is a hack to avoid dropouts when there are no hints. */
  40. #define adjust_with_hints 0.0
  41. #define adjust_without_hints 0.2
  42.  
  43. /* Encrypt a string. */
  44. int
  45. gs_type1_encrypt(byte *dest, const byte *src, uint len, crypt_state *pstate)
  46. {    register crypt_state state = *pstate;
  47.     register const byte *from = src;
  48.     register byte *to = dest;
  49.     register uint count = len;
  50.     while ( count )
  51.        {    encrypt_next(*from, state, *to);
  52.         from++, to++, count--;
  53.        }
  54.     *pstate = state;
  55.     return 0;
  56. }
  57. /* Decrypt a string. */
  58. int
  59. gs_type1_decrypt(byte *dest, const byte *src, uint len, crypt_state *pstate)
  60. {    register crypt_state state = *pstate;
  61.     register const byte *from = src;
  62.     register byte *to = dest;
  63.     register uint count = len;
  64.     while ( count )
  65.        {    /* If from == to, we can't use the obvious */
  66.         /*    decrypt_next(*from, state, *to);    */
  67.         register byte ch = *from++;
  68.         decrypt_next(ch, state, *to);
  69.         to++, count--;
  70.        }
  71.     *pstate = state;
  72.     return 0;
  73. }
  74.  
  75. /* Export the size of the structure */
  76. const uint gs_type1_state_sizeof = sizeof(gs_type1_state);
  77.  
  78. /* Imported procedures */
  79. extern int gx_matrix_to_fixed_coeff(P3(gs_matrix *, fixed_coeff *, int));
  80.  
  81. /* Initialize a Type 1 interpreter. */
  82. /* The caller must supply a string to the first call of gs_type1_interpret. */
  83. int
  84. gs_type1_init(register gs_type1_state *pis, gs_show_enum *penum,
  85.   int charpath_flag, int paint_type, gs_type1_data *pdata)
  86. {    gs_state *pgs = penum->pgs;
  87.     pis->penum = penum;
  88.     pis->pgs = pgs;
  89.     pis->pdata = pdata;
  90.     pis->charpath_flag = charpath_flag;
  91.     pis->paint_type = paint_type;
  92.     pis->os_count = 0;
  93.     pis->ips_count = 1;
  94.     pis->seac_base = -1;
  95.     pis->in_dotsection = 0;
  96.     pis->vstem3_set = 0;
  97.     pis->vs_offset.x = pis->vs_offset.y = 0;
  98.     reset_stem_hints(pis);
  99.     gx_matrix_to_fixed_coeff(&ctm_only(pgs), &pis->fc, max_coeff_bits);
  100.     compute_font_hints(&pis->fh, &pgs->ctm, pdata);
  101.     /* Set the current point of the path to the origin, */
  102.     /* in anticipation of the initial [h]sbw. */
  103.     { gx_path *ppath = pgs->path;
  104.       ppath->position.x = pgs->ctm.tx_fixed;
  105.       ppath->position.y = pgs->ctm.ty_fixed;
  106.     }
  107.     /* Set the flatness to a value that is likely to produce */
  108.     /* reasonably good-looking curves, regardless of its */
  109.     /* current value in the graphics state. */
  110.        {    /* If the character is very small, set the flatness */
  111.         /* to zero, which will produce very accurate curves. */
  112.         float cxx = pgs->ctm.xx, cyy = pgs->ctm.yy;
  113.         if ( cxx < 0 ) cxx = -cxx;
  114.         if ( cyy < 0 ) cyy = -cyy;
  115.         if ( cyy > cxx ) cxx = cyy;
  116.         if ( is_skewed(&pgs->ctm) )
  117.            {    float cxy = pgs->ctm.xy, cyx = pgs->ctm.yx;
  118.             if ( cxy < 0 ) cxy = -cxy;
  119.             if ( cyx < 0 ) cyx = -cyx;
  120.             if ( cxy > cxx ) cxx = cxy;
  121.             if ( cyx > cxx ) cxx = cyx;
  122.            }
  123.         /* Now cxx is approximately one character space unit */
  124.         /* in device pixels. */
  125.         pis->flatness = (cxx >= 0.2 ? cxx : 0.0);
  126.        }
  127.     return 0;
  128. }
  129.  
  130. /* Tracing for type 1 interpreter */
  131. #ifdef DEBUG
  132. #  define dc(str) if ( gs_debug['1'] ) type1_trace(cip, c, str);
  133. private void near
  134. type1_trace(const byte *cip, byte c, const char _ds *str)
  135. {    dprintf3("[1]%lx: %02x %s\n", (ulong)(cip - 1), c, (char *)str);
  136. }
  137. #else
  138. #  define dc(str)
  139. #endif
  140.  
  141. /* Define the state used by operator procedures. */
  142. /* These macros refer to a current instance (s) of gs_op1_state. */
  143. #define sppath s.ppath
  144. #define sfc s.fc
  145. #define ptx s.px
  146. #define pty s.py
  147. #define sctx s.ctx
  148. #define scty s.cty
  149.  
  150. /* Accumulate relative coordinates */
  151. /****** THESE ARE NOT ACCURATE FOR NON-INTEGER DELTAS. ******/
  152. /* This probably doesn't make any difference in practice. */
  153. #define c_fixed(d, c) m_fixed(fixed2int_var(d), c, sfc, max_coeff_bits)
  154. #define accum_x(dx)\
  155.     ptx += c_fixed(dx, xx);\
  156.     if ( sfc.skewed ) pty += c_fixed(dx, xy)
  157. #define accum_y(dy)\
  158.     pty += c_fixed(dy, yy);\
  159.     if ( sfc.skewed ) ptx += c_fixed(dy, yx)
  160. #define accum_xy(dx,dy)\
  161.     accum_xy_proc(&s, dx, dy)
  162.  
  163. #define s (*ps)
  164.  
  165. private void near
  166. accum_xy_proc(register is_ptr ps, fixed dx, fixed dy)
  167. {    int idx, idy;
  168.     idx = fixed2int_var(dx);
  169.     ptx += m_fixed(idx, xx, sfc, max_coeff_bits),
  170.     idy = fixed2int_var(dy);
  171.     pty += m_fixed(idy, yy, sfc, max_coeff_bits);
  172.     if ( sfc.skewed )
  173.         ptx += m_fixed(idy, yx, sfc, max_coeff_bits),
  174.         pty += m_fixed(idx, xy, sfc, max_coeff_bits);
  175. }
  176.  
  177. /* We round all endpoints of lines or curves */
  178. /* to the nearest quarter-pixel, and suppress null lines. */
  179. /* (Rounding to the half-pixel causes too many dropouts.) */
  180. /* This saves a lot of rendering work for small characters. */
  181. #define pixel_rounded(fx)\
  182.   (((fx) + float2fixed(0.125)) & float2fixed(-0.25))
  183. #define must_draw_to(lpx, lpy, px, py)\
  184.   ((lpx = pixel_rounded(px)), (lpy = pixel_rounded(py)),\
  185.    (psub = sppath->current_subpath) == 0 ||\
  186.    (pseg = psub->last)->type == s_line_close ||\
  187.    lpx != pseg->pt.x || lpy != pseg->pt.y)
  188.  
  189. /* ------ Operator procedures ------ */
  190.  
  191. /* We put these before the interpreter to save having to write */
  192. /* prototypes for all of them. */
  193.  
  194. int
  195. gs_op1_closepath(register is_ptr ps)
  196. {    /* Note that this does NOT reset the current point! */
  197.     int code = gx_path_close_subpath(sppath);
  198.     if ( code < 0 ) return code;
  199.     return gx_path_add_point(sppath, ptx, pty);    /* put the point where it was */
  200. }
  201.  
  202. int
  203. gs_op1_sbw(register is_ptr ps, fixed sbx, fixed sby, fixed wx, fixed wy)
  204. {    register gs_type1_state *pis = ps->pis;
  205.     gs_show_enum *penum = pis->penum;
  206.     if ( penum->sb_set )
  207.         pis->lsb = penum->metrics_sb;
  208.     else
  209.         pis->lsb.x = sbx, pis->lsb.y = sby;
  210.     if ( penum->width_set )
  211.         pis->width = penum->metrics_width;
  212.     else
  213.         pis->width.x = wx, pis->width.y = wy;
  214.     if_debug4('1',"[1]sb=(%g,%g) w=(%g,%g)\n",
  215.           fixed2float(pis->lsb.x), fixed2float(pis->lsb.y),
  216.           fixed2float(pis->width.x), fixed2float(pis->width.y));
  217.     accum_xy(pis->lsb.x, pis->lsb.y);
  218.     return 0;
  219. }
  220.  
  221. int
  222. gs_op1_hsbw(register is_ptr ps, fixed sbx, fixed wx)
  223. {    return gs_op1_sbw(ps, sbx, (fixed)0, wx, (fixed)0);
  224. }
  225.  
  226. int
  227. gs_op1_rrcurveto(register is_ptr ps, fixed dx1, fixed dy1,
  228.   fixed dx2, fixed dy2, fixed dx3, fixed dy3)
  229. {    gs_fixed_point pt1, pt2, pt3;
  230.     gs_type1_state *pis = ps->pis;
  231.     fixed ax0 = pixel_rounded(ptx) - ptx;
  232.     fixed ay0 = pixel_rounded(pty) - pty;
  233.     /* Following declarations are only for must_draw_to */
  234.     fixed lpx, lpy;
  235.     subpath *psub;
  236.     segment *pseg;
  237.     accum_xy(dx1, dy1);
  238.     pt1.x = ptx + ax0, pt1.y = pty + ay0;
  239.     accum_xy(dx2, dy2);
  240.     pt2.x = ptx, pt2.y = pty;
  241.     accum_xy(dx3, dy3);
  242.     find_stem_hints(pis, ptx, pty, dx3, dy3, &pt3);
  243.     if ( must_draw_to(lpx, lpy, pt3.x, pt3.y) )
  244.     {    /* Adjust second control point for endpoint hint */
  245.         /* and rounding. */
  246.         pt2.x += lpx - ptx, pt2.y += lpy - pty;
  247.         return gx_path_add_flattened_curve(sppath, pt1.x, pt1.y, pt2.x, pt2.y, lpx, lpy, pis->flatness);
  248.     }
  249.     return 0;
  250. }
  251.  
  252. #undef s
  253.  
  254. /* ------ Main interpreter ------ */
  255.  
  256. /* Continue interpreting a Type 1 CharString. */
  257. /* If str != 0, it is taken as the byte string to interpret. */
  258. /* Return 0 on successful completion, <0 on error, */
  259. /* or >0 when client intervention is required. */
  260. /* The int * argument is where the character is stored for seac, */
  261. /* or the othersubr # for callothersubr. */
  262. private int near type1_endchar(P3(gs_type1_state *, gs_state *, gx_path *));
  263. int
  264. gs_type1_interpret(register gs_type1_state *pis, const byte *str, int *pindex)
  265. {    gs_state *pgs = pis->pgs;
  266.     gs_type1_data *pdata = pis->pdata;
  267.     gs_op1_state s;
  268.     fixed cstack[ostack_size];
  269. #define cs0 cstack[0]
  270. #define ics0 fixed2int_var(cs0)
  271. #define cs1 cstack[1]
  272. #define ics1 fixed2int_var(cs1)
  273. #define cs2 cstack[2]
  274. #define ics2 fixed2int_var(cs2)
  275. #define cs3 cstack[3]
  276. #define ics3 fixed2int_var(cs3)
  277. #define cs4 cstack[4]
  278. #define ics4 fixed2int_var(cs4)
  279. #define cs5 cstack[5]
  280. #define ics5 fixed2int_var(cs5)
  281.     register fixed _ss *csp;
  282. #define clear csp = cstack - 1
  283.     ip_state *ipsp = &pis->ipstack[pis->ips_count - 1];
  284.     register const byte *cip;
  285.     register crypt_state state;
  286.     register int c;
  287.     int code = 0;
  288.     fixed ftx = pgs->ctm.tx_fixed, fty = pgs->ctm.ty_fixed;
  289.     gs_fixed_point hpt;
  290.     /* Following are only for must_draw_to */
  291.     fixed lpx, lpy;
  292.     subpath *psub;
  293.     segment *pseg;
  294.  
  295.     sppath = pgs->path;
  296.     s.pis = pis;
  297.     sfc = pis->fc;
  298.     ptx = sppath->position.x;
  299.     pty = sppath->position.y;
  300.  
  301.     /* Copy the operand stack out of the saved state. */
  302.     if ( pis->os_count == 0 )
  303.        {    clear;
  304.        }
  305.     else
  306.        {    memcpy(cstack, pis->ostack, pis->os_count * sizeof(fixed));
  307.         csp = &cstack[pis->os_count - 1];
  308.        }
  309.  
  310.     if ( str == 0 ) goto cont;
  311.     cip = str;
  312. call:    state = crypt_charstring_seed;
  313.        {    int skip = pdata->lenIV;
  314.         /* Skip initial random bytes */
  315.         for ( ; skip > 0; --skip )
  316.            {    decrypt_skip_next(*cip, state); ++cip;
  317.            }
  318.        }
  319.     goto top;
  320. cont:    cip = ipsp->ip;
  321.     state = ipsp->dstate;
  322. top:    while ( 1 )
  323.      { uint c0;
  324.        c = decrypt_this((c0 = *cip++), state);
  325.        decrypt_skip_next(c0, state);
  326.        switch ( (char_command)c )
  327.        {
  328. #define cnext clear; break
  329.     case c_hstem: dc("hstem")
  330.         type1_hstem(pis, cs0, cs1);
  331.         cnext;
  332.     case c_vstem: dc("vstem")
  333.         type1_vstem(pis, cs0, cs1);
  334.         cnext;
  335.     case c_vmoveto: dc("vmoveto")
  336.         cs1 = cs0;
  337.         cs0 = 0;
  338.         accum_y(cs1);
  339. move:        /* cs0 = dx, cs1 = dy for hint checking. */
  340.         find_stem_hints(pis, ptx, pty, cs0, cs1, &hpt);
  341.         /* Round to the nearest center of a quarter-pixel. */
  342.         if ( must_draw_to(lpx, lpy, hpt.x, hpt.y) )
  343.             code = gx_path_add_point(sppath, lpx, lpy);
  344.         goto cc;
  345.     case c_rlineto: dc("rlineto")
  346.         accum_xy(cs0, cs1);
  347. line:        /* cs0 = dx, cs1 = dy for hint checking. */
  348.         find_stem_hints(pis, ptx, pty, cs0, cs1, &hpt);
  349.         /* Round to the nearest center of a quarter-pixel. */
  350.         if ( must_draw_to(lpx, lpy, hpt.x, hpt.y) )
  351.             code = gx_path_add_line(sppath, lpx, lpy);
  352. cc:        if ( code < 0 ) return code;
  353. pp:        if_debug2('1', "[1]pt=(%g,%g)\n",
  354.               fixed2float(ptx), fixed2float(pty));
  355.         cnext;
  356.     case c_hlineto: dc("hlineto")
  357.         accum_x(cs0);
  358.         cs1 = 0;
  359.         goto line;
  360.     case c_vlineto: dc("vlineto")
  361.         cs1 = cs0;
  362.         cs0 = 0;
  363.         accum_y(cs1);
  364.         goto line;
  365.     case c_rrcurveto: dc("rrcurveto")
  366.         code = gs_op1_rrcurveto(&s, cs0, cs1, cs2, cs3, cs4, cs5);
  367.         goto cc;
  368.     case c_closepath: dc("closepath")
  369.         code = gs_op1_closepath(&s);
  370.         goto cc;
  371.     case c_callsubr: dc("callsubr")
  372.        {    int index = fixed2int_var(*csp);
  373.         const byte *nip;
  374.         code = (*pdata->subr_proc)(pdata, index, &nip);
  375.         if ( code < 0 ) return_error(code);
  376.         --csp;
  377.         ipsp->ip = cip, ipsp->dstate = state;
  378.         ++ipsp;
  379.         cip = nip;
  380.        }
  381.         goto call;
  382.     case c_return: dc("return")
  383.         --ipsp;
  384.         goto cont;
  385.     case c_escape: dc("escape:")
  386.         decrypt_next(*cip, state, c); ++cip;
  387.         switch ( (char_extended_command)c )
  388.            {
  389.         case ce_dotsection: dc("  dotsection")
  390.             pis->in_dotsection = !pis->in_dotsection;
  391.             cnext;
  392.         case ce_vstem3: dc("  vstem3")
  393.             type1_vstem(pis, cs0, cs1);
  394.             type1_vstem(pis, cs2, cs3);
  395.             type1_vstem(pis, cs4, cs5);
  396.             cnext;
  397.         case ce_hstem3: dc("  hstem3")
  398.             type1_hstem(pis, cs0, cs1);
  399.             type1_hstem(pis, cs2, cs3);
  400.             type1_hstem(pis, cs4, cs5);
  401.             cnext;
  402.         case ce_seac: dc("  seac")
  403.             /* Do the accent now.  When it finishes */
  404.             /* (detected in endchar), do the base character. */
  405.             pis->seac_base = ics3;
  406.             /* Adjust the origin of the coordinate system */
  407.             /* for the accent (endchar puts it back). */
  408.             ptx = ftx, pty = fty;
  409.             cs1 -= cs0;     /* subtract off asb */
  410.             accum_xy(cs1, cs2);
  411.             sppath->position.x = ptx;
  412.             sppath->position.y = pty;
  413.             pis->os_count = 0;    /* clear */
  414.             /* Give control back to the caller, who must */
  415.             /* re-invoke the interpreter with the seac string. */
  416.             *pindex = ics4;
  417.             return type1_result_seac;
  418.         case ce_sbw: dc("  sbw")
  419.             code = gs_op1_sbw(&s, cs0, cs1, cs2, cs3);
  420.             goto cc;
  421.         case ce_div: dc("  div")
  422.             csp[-1] = float2fixed((float)csp[-1] / (float)*csp);
  423.             --csp; goto pushed;
  424.         case ce_undoc15: dc("  undoc15")
  425.             /*
  426.              * NOTE: this opcode is not documented by Adobe,
  427.              * but is used in some Adobe fonts.  I have no idea
  428.              * what it is supposed to do.
  429.              */
  430.             cnext;
  431.         case ce_callothersubr: dc("  callothersubr")
  432.            {    int scount = csp - cstack;
  433.             *pindex = fixed2int_var(*csp);
  434.             /* Update path position so it will be right */
  435.             /* when we come back in. */
  436.             sppath->position.x = ptx;
  437.             sppath->position.y = pty;
  438.             /* Exit to caller */
  439.             ipsp->ip = cip, ipsp->dstate = state;
  440.             pis->os_count = scount;
  441.             pis->ips_count = ipsp - &pis->ipstack[0] + 1;
  442.             if ( scount )
  443.                 memcpy(pis->ostack, cstack,
  444.                        scount * sizeof(fixed));
  445.             return type1_result_callothersubr;
  446.            }
  447.         case ce_pop: dc("  pop")
  448.             ++csp;
  449.             code = (*pdata->pop_proc)(pdata, csp);
  450.             if ( code < 0 ) return_error(code);
  451.             goto pushed;
  452.         case ce_setcurrentpoint: dc("  setcurrentpoint")
  453.             ptx = ftx, pty = fty;
  454.             accum_xy(cs0, cs1);
  455.             goto pp;
  456.         default:
  457.             return_error(gs_error_invalidfont);
  458.            }
  459.         break;
  460.     case c_hsbw: dc("hsbw")
  461.         code = gs_op1_hsbw(&s, cs0, cs1);
  462.         goto cc;
  463.     case c_endchar: dc("endchar")
  464.         if ( pis->seac_base >= 0 )
  465.            {    /* We just finished the accent of a seac. */
  466.             /* Do the base character. */
  467.             *pindex = pis->seac_base;
  468.             pis->seac_base = -1;
  469.             /* Restore the coordinate system origin */
  470.             sppath->position.x = ftx;
  471.             sppath->position.y = fty;
  472.             pis->os_count = 0;    /* clear */
  473.             /* Clear the ipstack, in case the accent ended */
  474.             /* inside a subroutine. */
  475.             pis->ips_count = 1;
  476.             /* Give control back to the caller, who must */
  477.             /* re-invoke the interpreter with the */
  478.             /* base character string. */
  479.             return type1_result_seac;
  480.            }
  481.         /* This is a real endchar.  Handle it below. */
  482.         return type1_endchar(pis, pgs, sppath);
  483.     case c_undoc15: dc("  undoc15")
  484.         /*
  485.          * NOTE: this opcode is not documented by Adobe,
  486.          * but is used in some Adobe fonts.  I have no idea
  487.          * what it is supposed to do.
  488.          */
  489.         cnext;
  490.     case c_rmoveto: dc("rmoveto")
  491.         accum_xy(cs0, cs1);
  492.         goto move;
  493.     case c_hmoveto: dc("hmoveto")
  494.         accum_x(cs0);
  495.         cs1 = 0;
  496.         goto move;
  497.     case c_vhcurveto: dc("vhcurveto")
  498.         code = gs_op1_rrcurveto(&s, (fixed)0, cs0, cs1, cs2, cs3, (fixed)0);
  499.         goto cc;
  500.     case c_hvcurveto: dc("hvcurveto")
  501.         code = gs_op1_rrcurveto(&s, cs0, (fixed)0, cs1, cs2, (fixed)0, cs3);
  502.         goto cc;
  503.     /* Fill up the dispatch up to 32. */
  504.     case c_undef0: case c_undef2:
  505.     case c_undef16: case c_undef17: case c_undef18: case c_undef19:
  506.     case c_undef20: case c_undef23:
  507.     case c_undef24: case c_undef25: case c_undef26: case c_undef27:
  508.     case c_undef28: case c_undef29:
  509.         return_error(gs_error_invalidfont);
  510.     /* Fill up the dispatch for 1-byte numbers. */
  511. #define icase(n) case n:
  512. #define ncase(n) case n: *++csp = int2fixed(c_value_num1(n)); goto pushed;
  513. #define icase10(n)\
  514.   icase(n) icase(n+1) icase(n+2) icase(n+3) icase(n+4)\
  515.   icase(n+5) icase(n+6) icase(n+7) icase(n+8) icase(n+9)
  516. #define ncase10(n)\
  517.   ncase(n) ncase(n+1) ncase(n+2) ncase(n+3) ncase(n+4)\
  518.   ncase(n+5) ncase(n+6) ncase(n+7) ncase(n+8) ncase(n+9)
  519.     icase(32) icase(33) icase(34)
  520.     icase(35) icase(36) icase(37) icase(38) icase(39)
  521.     icase10(40)
  522.     icase10(50) icase10(60) icase10(70) icase10(80) icase10(90)
  523.     icase10(100) icase10(110) goto pi; ncase10(120) ncase10(130) ncase10(140)
  524.     ncase10(150) icase10(160) icase10(170) icase10(180) icase10(190)
  525.     icase10(200) icase10(210) icase10(220) icase10(230)
  526.     icase(240) icase(241) icase(242) icase(243) icase(244)
  527.     icase(245) icase(246)
  528. pi:        *++csp = int2fixed(c_value_num1(c));
  529. pushed:        if_debug3('1', "[1]%d: (%d) %f\n",
  530.               (int)(csp - cstack), c, fixed2float(*csp));
  531.         break;
  532.     /* Handle 2-byte positive numbers. */
  533. #define case_num2(n)\
  534.   case c_num2+n: c = c_value_num2(c_num2+n, 0)
  535.     case_num2(0); goto pos2;
  536.     case_num2(1); goto pos2;
  537.     case_num2(2); goto pos2;
  538.     case_num2(3);
  539. #undef case_num2
  540. pos2:       {    c0 = *cip++;
  541.         if_debug2('1', "[1] (%d)+%d\n",
  542.               c, decrypt_this(c0, state));
  543.         *++csp = int2fixed((int)decrypt_this(c0, state) + c);
  544.         decrypt_skip_next(c0, state);
  545.        }    goto pushed;
  546.     /* Handle 2-byte negative numbers. */
  547. #define case_num3(n)\
  548.   case c_num3+n: c = c_value_num3(c_num3+n, 0)
  549.     case_num3(0); goto neg2;
  550.     case_num3(1); goto neg2;
  551.     case_num3(2); goto neg2;
  552.     case_num3(3);
  553. #undef case_num3
  554. neg2:       {    c0 = *cip++;
  555.         if_debug2('1', "[1] (%d)-%d\n",
  556.               c, decrypt_this(c0, state));
  557.         *++csp = int2fixed(c - (int)decrypt_this(c0, state));
  558.         decrypt_skip_next(c0, state);
  559.        }    goto pushed;
  560.     /* Handle 5-byte numbers. */
  561.     case c_num4:
  562.        {    uint c1, c2;
  563.         long lw;
  564.         decrypt_next(*cip, state, c0);
  565.         decrypt_next(cip[1], state, c1);
  566.         decrypt_next(cip[2], state, c2);
  567.         decrypt_next(cip[3], state, lw);
  568.         cip += 4;
  569.         lw += (ulong)c0 << 24;
  570.         lw += (ulong)c1 << 16;
  571.         lw += c2 << 8;
  572.         *++csp = int2fixed(lw);
  573.         if ( lw != fixed2long(*csp) )
  574.             return_error(gs_error_rangecheck);
  575.        }    goto pushed;
  576.        }
  577.      }
  578. }
  579.  
  580. /* Pop a (fixed) number off the internal stack. */
  581. /* The client uses this to get the arguments for an OtherSubr. */
  582. int
  583. gs_type1_pop(gs_type1_state *pis, fixed *pf)
  584. {    *pf = pis->ostack[--(pis->os_count)];
  585.     return 0;
  586. }
  587.  
  588. /* ------ Termination ------ */
  589.  
  590. /* Handle the end of a character.  We break this out into a separate */
  591. /* procedure so as not to overwhelm the optimizing compilers. */
  592. private int near
  593. type1_endchar(gs_type1_state *pis, gs_state *pgs, gx_path *ppath)
  594. {    int use_stroke = pis->paint_type == 1 || pis->paint_type == 2;
  595.     fixed ftx = pgs->ctm.tx_fixed, fty = pgs->ctm.ty_fixed;
  596.     int code;
  597.     /* Set the current point to the character origin: */
  598.     /* the 'show' loop will take care of adding in */
  599.     /* the width we supply to setcharwidth/cachedevice. */
  600.     gx_path_add_point(ppath, ftx, fty);
  601.     if ( pis->charpath_flag )
  602.        {    code = gs_setcharwidth(pis->penum, pgs,
  603.                 fixed2float(pis->width.x),
  604.                 fixed2float(pis->width.y));
  605.         if ( code < 0 ) return code;
  606.         /* Merge the path into its parent */
  607.         return gx_path_add_path(pgs->saved->path, ppath);
  608.        }
  609.        {    gs_rect bbox;
  610.         code = gs_pathbbox(pgs, &bbox);
  611.         if ( code < 0 )        /* must be a null path */
  612.            {    bbox.p.x = bbox.p.y = bbox.q.x = bbox.q.y = 0;
  613.            }
  614.         if_debug4('1', "[1]bbox=(%g,%g),(%g,%g)\n",
  615.               bbox.p.x, bbox.p.y, bbox.q.x, bbox.q.y);
  616.            {    /* Expand the bounding box to encompass */
  617.             /* the width of the stroke (if stroking). */
  618.             /* setcachedevice also adds 1 or 2 pixels, */
  619.             /* so we don't have to worry about rounding. */
  620.             if ( use_stroke )
  621.                {    float adjust = gs_currentlinewidth(pgs);
  622.                 if ( adjust < 1 ) adjust = 1;
  623.                 /****** SHOULD SCALE ******/
  624.                 bbox.p.x -= adjust;
  625.                 bbox.p.y -= adjust;
  626.                 bbox.q.x += adjust;
  627.                 bbox.q.y += adjust;
  628.                }
  629.            }
  630.         code = gs_setcachedevice(pis->penum, pgs,
  631.                 fixed2float(pis->width.x),
  632.                 fixed2float(pis->width.y),
  633.                 bbox.p.x, bbox.p.y,
  634.                 bbox.q.x, bbox.q.y);
  635.         if ( code < 0 ) return code;
  636.        }
  637.     /* We've already constructed the path: */
  638.     /* translate it so it matches the cache device. */
  639.     code = gx_path_translate(pgs->path, pgs->ctm.tx_fixed - ftx,
  640.                  pgs->ctm.ty_fixed - fty);
  641.     if ( code < 0 ) return code;
  642.     gx_color_load(pgs->dev_color, pgs);
  643.     return (use_stroke ? gs_stroke(pgs) :
  644.         gs_fill_adjust(pgs,
  645.                    (pis->fh.use_x_hints | pis->fh.use_y_hints ?
  646.                 float2fixed(adjust_with_hints) :
  647.                 float2fixed(adjust_without_hints))));
  648. }
  649.