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

  1. /* Copyright (C) 1989, 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. /* gschar.c */
  21. /* Character writing operators for Ghostscript library */
  22. #include "gx.h"
  23. #include "memory_.h"
  24. #include "string_.h"
  25. #include "gserrors.h"
  26. #include "gxfixed.h"            /* ditto */
  27. #include "gxarith.h"
  28. #include "gxmatrix.h"
  29. #include "gzstate.h"            /* must precede gzdevice */
  30. #include "gzdevice.h"            /* must precede gxchar */
  31. #include "gxdevmem.h"
  32. #include "gxchar.h"
  33. #include "gxcache.h"
  34. #include "gxfont.h"
  35. #include "gspath.h"
  36. #include "gzpath.h"
  37. #include "gzcolor.h"
  38.  
  39. /* Exported size of enumerator */
  40. const uint gs_show_enum_sizeof = sizeof(gs_show_enum);
  41.  
  42. /* Imported procedures */
  43. extern void gx_set_black(P1(gs_state *));
  44.  
  45. /* Forward declarations */
  46. private int continue_kshow(P1(gs_show_enum *));
  47. private int continue_show(P1(gs_show_enum *));
  48. private int continue_show_update(P1(gs_show_enum *));
  49. private int show_setup(P3(gs_show_enum *, gs_state *, const char *));
  50. private int show_ctm_setup(P1(gs_show_enum *));
  51. private int stringwidth_setup(P3(gs_show_enum *, gs_state *, const char *));
  52.  
  53. /* Print the ctm if debugging */
  54. #define print_ctm(s,pgs)\
  55.   dprintf7("[p]%sctm=[%g %g %g %g %g %g]\n", s,\
  56.        pgs->ctm.xx, pgs->ctm.xy, pgs->ctm.yx, pgs->ctm.yy,\
  57.        pgs->ctm.tx, pgs->ctm.ty)
  58.  
  59. /* ------ String writing operators ------ */
  60.  
  61. /* Setup macros for show operators */
  62. #define setup_show_n()\
  63.   penum->size = size
  64. #define setup_a()\
  65.   penum->add = 1, penum->ax = ax, penum->ay = ay,\
  66.   penum->slow_show = 1
  67. #define setup_width()\
  68.   penum->wchr = chr, penum->wcx = cx, penum->wcy = cy,\
  69.   penum->slow_show = 1
  70. #define no_chr ~(char_code)0
  71.  
  72. /* show[_n] */
  73. int
  74. gs_show_n_init(register gs_show_enum *penum,
  75.   gs_state *pgs, const char *str, uint size)
  76. {    setup_show_n();
  77.     penum->slow_show = 0;
  78.     return show_setup(penum, pgs, str);
  79. }
  80. int
  81. gs_show_init(gs_show_enum *penum, gs_state *pgs, const char *str)
  82. {    return gs_show_n_init(penum, pgs, str, strlen(str));
  83. }
  84.  
  85. /* ashow[_n] */
  86. int
  87. gs_ashow_n_init(register gs_show_enum *penum,
  88.   gs_state *pgs, floatp ax, floatp ay, const char *str, uint size)
  89. {    int code;
  90.     setup_show_n();
  91.     code = show_setup(penum, pgs, str);
  92.     setup_a();
  93.     return code;
  94. }
  95. int
  96. gs_ashow_init(gs_show_enum *penum,
  97.   gs_state *pgs, floatp ax, floatp ay, const char *str)
  98. {    return gs_ashow_n_init(penum, pgs, ax, ay, str, strlen(str));
  99. }
  100.  
  101. /* widthshow[_n] */
  102. int
  103. gs_widthshow_n_init(register gs_show_enum *penum,
  104.   gs_state *pgs, floatp cx, floatp cy, char chr, const char *str, uint size)
  105. {    int code;
  106.     setup_show_n();
  107.     code = show_setup(penum, pgs, str);
  108.     setup_width();
  109.     return code;
  110. }
  111. int
  112. gs_widthshow_init(gs_show_enum *penum,
  113.   gs_state *pgs, floatp cx, floatp cy, char chr, const char *str)
  114. {    return gs_widthshow_n_init(penum, pgs, cx, cy, chr, str, strlen(str));
  115. }
  116.  
  117. /* awidthshow[_n] */
  118. int
  119. gs_awidthshow_n_init(register gs_show_enum *penum,
  120.   gs_state *pgs, floatp cx, floatp cy, char chr, floatp ax, floatp ay,
  121.   const char *str, uint size)
  122. {    int code;
  123.     setup_show_n();
  124.     code = show_setup(penum, pgs, str);
  125.     setup_a();
  126.     setup_width();
  127.     return code;
  128. }
  129. int
  130. gs_awidthshow_init(gs_show_enum *penum,
  131.   gs_state *pgs, floatp cx, floatp cy, char chr, floatp ax, floatp ay,
  132.   const char *str)
  133. {    return gs_awidthshow_n_init(penum, pgs, cx, cy, chr, ax, ay,
  134.                     str, strlen(str));
  135. }
  136.  
  137. /* kshow[_n] */
  138. int
  139. gs_kshow_n_init(register gs_show_enum *penum,
  140.   gs_state *pgs, const char *str, uint size)
  141. {    int code;
  142.     if ( pgs->font->FontType == ft_composite)
  143.         return_error(gs_error_invalidfont);
  144.     setup_show_n();
  145.     code = show_setup(penum, pgs, str);
  146.     penum->do_kern = penum->slow_show = 1;
  147.     return code;
  148. }
  149. int
  150. gs_kshow_init(gs_show_enum *penum, gs_state *pgs, const char *str)
  151. {    return gs_kshow_n_init(penum, pgs, str, strlen(str));
  152. }
  153.  
  154. /* ------ Related operators ------ */
  155.  
  156. /* stringwidth[_n] */
  157. int
  158. gs_stringwidth_n_init(gs_show_enum *penum, gs_state *pgs, const char *str, uint size)
  159. {    setup_show_n();
  160.     return stringwidth_setup(penum, pgs, str);
  161. }
  162. int
  163. gs_stringwidth_init(gs_show_enum *penum, gs_state *pgs, const char *str)
  164. {    return gs_stringwidth_n_init(penum, pgs, str, strlen(str));
  165. }
  166.  
  167. /* Common code for stringwidth[_n] */
  168. private int
  169. stringwidth_setup(gs_show_enum *penum, gs_state *pgs, const char *str)
  170. {    int code = (penum->slow_show = 0, show_setup(penum, pgs, str));
  171.     if ( code < 0 ) return_error(code);
  172.     penum->stringwidth_flag = 1;
  173.     /* Do an extra gsave and suppress output */
  174.     if ( (code = gs_gsave(pgs)) < 0 ) return code;
  175.     penum->level = pgs->level;    /* for level check in show_update */
  176.     gx_device_no_output(pgs);
  177.     /* Establish an arbitrary current point. */
  178.     return gx_path_add_point(pgs->path, pgs->ctm.tx_fixed, pgs->ctm.ty_fixed);
  179. }
  180.  
  181. /* charpath[_n] */
  182. int
  183. gs_charpath_n_init(gs_show_enum *penum, gs_state *pgs,
  184.   const char *str, uint size, int bool)
  185. {    int code;
  186.     setup_show_n();
  187.     code = show_setup(penum, pgs, str);
  188.     penum->charpath_flag = (bool ? 2 : 1);
  189.     penum->can_cache = 0;
  190.     return code;
  191. }
  192. int
  193. gs_charpath_init(gs_show_enum *penum, gs_state *pgs,
  194.   const char *str, int bool)
  195. {    return gs_charpath_n_init(penum, pgs, str, strlen(str), bool);
  196. }
  197.  
  198. /* ------ Width/cache operators ------ */
  199.  
  200. /* setcachedevice */
  201. int
  202. gs_setcachedevice(register gs_show_enum *penum, gs_state *pgs,
  203.   floatp wx, floatp wy, floatp llx, floatp lly, floatp urx, floatp ury)
  204. {    int code = gs_setcharwidth(penum, pgs, wx, wy);    /* default is don't cache */
  205.     if ( code < 0 ) return code;
  206.     /* See if we want to cache this character. */
  207.     if ( pgs->in_cachedevice )        /* no recursion! */
  208.         return 0;
  209.     pgs->in_cachedevice = 1;    /* disable color/gray/image operators */
  210.     /* We can only use the cache if ctm is unchanged */
  211.     /* (aside from a possible translation), */
  212.     /* and if the extent of the box is non-negative. */
  213.     if ( !penum->can_cache || !pgs->char_tm_valid ||
  214.          llx > urx || lly > ury
  215.        )
  216.         return 0;
  217.        {    gs_font_dir *dir = pgs->font->dir;
  218.         gs_fixed_point cbox_ll, cbox_ur, cdim;
  219.         long iwidth, iheight;
  220.         cached_char *cc;
  221.         gs_fixed_rect clip_box;
  222.         gs_distance_transform2fixed(&pgs->ctm, llx, lly, &cbox_ll);
  223.         gs_distance_transform2fixed(&pgs->ctm, urx, ury, &cbox_ur);
  224.         cdim.x = cbox_ur.x - cbox_ll.x;
  225.         cdim.y = cbox_ur.y - cbox_ll.y;
  226.         if ( cdim.x < 0 ) cdim.x = -cdim.x;
  227.         if ( cdim.y < 0 ) cdim.y = -cdim.y;
  228. #ifdef DEBUG
  229. if ( gs_debug['k'] )
  230.    {    dprintf4("[k]cbox=[%g %g %g %g]\n",
  231.          fixed2float(cbox_ll.x), fixed2float(cbox_ll.y),
  232.          fixed2float(cbox_ur.x), fixed2float(cbox_ur.y));
  233.     print_ctm("  ", pgs);
  234.    }
  235. #endif
  236.         iwidth = fixed2long(cdim.x) + 2;
  237.         iheight = fixed2long(cdim.y) + 2;
  238.         if (    iwidth != (ushort)iwidth ||
  239.             iheight != (ushort)iheight
  240.            )
  241.           return 0;        /* much too big */
  242.         if ( !penum->dev_cache_set )
  243.            {    /* Set up the memory device for the character cache */
  244.             device *dev = &penum->dev_cache_dev;
  245.             penum->dev_cache_info = mem_mono_device;
  246.             dev->info = (gx_device *)&penum->dev_cache_info;
  247.             dev->is_band_device = 0;
  248.             dev->white = 1;
  249.             dev->black = 1;
  250.             penum->dev_cache_set = 1;
  251.            }
  252.         if ( (cc = gx_alloc_char_bits(dir,
  253.                     (gx_device_memory *)&penum->dev_cache_info,
  254.                     (ushort)iwidth,
  255.                     (ushort)iheight)) == 0 )
  256.           return 0;        /* too big for cache */
  257.         /* The mins handle transposed coordinate systems.... */
  258.         /* Truncate the offsets to avoid artifacts later. */
  259.         cc->offset.x = fixed_ceiling(-min(cbox_ll.x, cbox_ur.x));
  260.         cc->offset.y = fixed_ceiling(-min(cbox_ll.y, cbox_ur.y));
  261. #ifdef DEBUG
  262. if ( gs_debug['k'] )
  263.         dprintf2("[k]offset=[%g %g]\n", fixed2float(cc->offset.x),
  264.              fixed2float(cc->offset.y));
  265. #endif
  266.         if ( !color_is_pure(pgs->dev_color) )    /* can't use cache */
  267.            {    gx_free_cached_char(dir, cc);
  268.             return code;
  269.            }
  270.         if ( (code = gs_gsave(pgs)) < 0 )
  271.            {    gx_free_cached_char(dir, cc);
  272.             return code;
  273.            }
  274.         /* Nothing can go wrong now.... */
  275.         penum->cc = cc;
  276.         cc->code = gs_show_current_char(penum);
  277.         cc->wxy = penum->wxy;
  278.         /* Install the device */
  279.         pgs->device = &penum->dev_cache_dev;
  280.         pgs->device_is_shared = 1;    /* don't deallocate */
  281.         /* Adjust the translation in the graphics context */
  282.         /* so that the character lines up with the cache. */
  283.         gs_translate_to_fixed(pgs, cc->offset.x, cc->offset.y);
  284.         /* Set the initial matrix for the cache device. */
  285.         penum->dev_cache_info.initial_matrix = ctm_only(pgs);
  286.         /* Reset the clipping path to match the metrics. */
  287.         clip_box.p.x = clip_box.p.y = 0;
  288.         clip_box.q.x = int2fixed(iwidth);
  289.         clip_box.q.y = int2fixed(iheight);
  290.         if ( (code = gx_clip_to_rectangle(pgs, &clip_box)) < 0 )
  291.           return code;
  292.         gx_set_black(pgs);    /* Set the color to black. */
  293.        }
  294.     penum->width_status = sws_cache;
  295.     return 0;
  296. }
  297.  
  298. /* setcharwidth */
  299. int
  300. gs_setcharwidth(register gs_show_enum *penum, gs_state *pgs, floatp wx, floatp wy)
  301. {    if ( penum->width_status != sws_none )
  302.         return_error(gs_error_undefined);
  303.     gs_distance_transform2fixed(&pgs->ctm, wx, wy, &penum->wxy);
  304.     penum->width_status = sws_no_cache;
  305.     return 0;
  306. }
  307.  
  308. /* setmetrics */
  309. int
  310. gs_setmetrics(register gs_show_enum *penum, gs_state *pgs,
  311.   const gs_point *psbxy, const gs_point *pwxy)
  312. {    if ( penum->width_status != sws_none )
  313.         return_error(gs_error_undefined);
  314.     if ( psbxy != 0 )
  315.        {    penum->metrics_sb.x = float2fixed(psbxy->x);
  316.         penum->metrics_sb.y = float2fixed(psbxy->y);
  317.         penum->sb_set = 1;
  318.        }
  319.     if ( pwxy != 0 )
  320.        {    penum->metrics_width.x = float2fixed(pwxy->x);
  321.         penum->metrics_width.y = float2fixed(pwxy->y);
  322.         penum->width_set = 1;
  323.        }
  324.     return 0;
  325. }
  326.  
  327. /* ------ Enumerator ------ */
  328.  
  329. /* Do the next step of a show (or stringwidth) operation */
  330. int
  331. gs_show_next(gs_show_enum *penum)
  332. {    return (*penum->continue_proc)(penum);
  333. }
  334.  
  335. /* Continuation procedures */
  336. #define show_fast_move(wxy, pgs)\
  337.   gx_path_add_rel_point_inline(pgs->path, wxy.x, wxy.y)
  338. private int show_update(P1(gs_show_enum *penum));
  339. private int show_move(P1(gs_show_enum *penum));
  340. private int show_proceed(P1(gs_show_enum *penum));
  341. private int show_finish(P1(gs_show_enum *penum));
  342. private int
  343. continue_show_update(register gs_show_enum *penum)
  344. {    int code = show_update(penum);
  345.     if ( code < 0 ) return code;
  346.     code = show_move(penum);
  347.     if ( code != 0 ) return code;
  348.     return show_proceed(penum);
  349. }
  350. private int
  351. continue_show(register gs_show_enum *penum)
  352. {    return show_proceed(penum);
  353. }
  354. /* For kshow, the CTM may have changed, so we have to reestablish */
  355. /* the cached values in the enumerator. */
  356. private int
  357. continue_kshow(register gs_show_enum *penum)
  358. {    int code = show_ctm_setup(penum);
  359.     if ( code < 0 ) return code;
  360.     return show_proceed(penum);
  361. }
  362.  
  363. /* Update position */
  364. private int
  365. show_update(register gs_show_enum *penum)
  366. {    register gs_state *pgs = penum->pgs;
  367.     /* Update position for last character */
  368.     switch ( penum->width_status )
  369.        {
  370.     case sws_none:
  371.         /* Adobe interpreters assume a character width of 0, */
  372.         /* even though the documentation says this is an error.... */
  373.         penum->wxy.x = penum->wxy.y = 0;
  374.         break;
  375.     case sws_cache:
  376.        {    /* Finish installing the cache entry. */
  377.         cached_char *cc = penum->cc;
  378.         int code;
  379.         /* If the BuildChar procedure did a save and a restore, */
  380.         /* it already undid the gsave in setcachedevice. */
  381.         /* We have to check for this by comparing levels. */
  382.         switch ( pgs->level - penum->level )
  383.            {
  384.         default:
  385.             return_error(gs_error_invalidfont);    /* WRONG */
  386.         case 2:
  387.             code = gs_grestore(pgs);
  388.             if ( code < 0 ) return code;
  389.         case 1:
  390.             ;
  391.            }
  392.         gx_add_cached_char(pgs->font->dir, &penum->dev_cache_info,
  393.                    cc, gx_lookup_fm_pair(pgs));
  394.         if ( !penum->stringwidth_flag && !penum->charpath_flag )
  395.           { /* Copy the bits to the real output device. */
  396.             penum->color_loaded = 0;    /* force gx_color_render */
  397.             code = gs_grestore(pgs);
  398.             if ( code < 0 ) return code;
  399.             return gx_image_cached_char(penum, cc);
  400.           }
  401.        }
  402.     case sws_no_cache: ;
  403.        }
  404.     return gs_grestore(pgs);
  405. }
  406.  
  407. /* Move to next character */
  408. private int
  409. show_move(register gs_show_enum *penum)
  410. {    register gs_state *pgs = penum->pgs;
  411.     if ( penum->add )
  412.         gs_rmoveto(pgs, penum->ax, penum->ay);
  413.     if ( penum->str[penum->index - 1] == penum->wchr )
  414.         gs_rmoveto(pgs, penum->wcx, penum->wcy);
  415.     /* wxy is in device coordinates */
  416.        {    int code = show_fast_move(penum->wxy, pgs);
  417.         if ( code < 0 ) return code;
  418.        }
  419.     /* Check for kerning, but not on the last character. */
  420.     if ( penum->do_kern && penum->index < penum->size )
  421.        {    penum->continue_proc = continue_kshow;
  422.         return gs_show_kern;
  423.        }
  424.     return 0;
  425. }
  426. /* Process next character */
  427. private int
  428. show_proceed(register gs_show_enum *penum)
  429. {    register gs_state *pgs = penum->pgs;
  430.     const byte *str = penum->str;
  431.     uint index;
  432.     cached_fm_pair *pair = 0;
  433.     char_code chr;
  434.     int code;
  435.     penum->color_loaded = 0;
  436. more:    /* Proceed to next character */
  437.     if ( penum->can_cache )
  438.        {    /* Loop with cache */
  439.         if ( pair == 0 )
  440.           pair = gx_lookup_fm_pair(pgs);
  441.         if ( penum->stringwidth_flag )
  442.           while ( (index = penum->index++) != penum->size )
  443.             {    cached_char *cc;
  444.             chr = str[index];
  445.             cc = gx_lookup_cached_char(pgs, pair, chr);
  446.             if ( cc == 0 ) goto no_cache;
  447.             /* Character is in cache. */
  448.             code = show_fast_move(cc->wxy, pgs);
  449.             if ( code ) return code;
  450.             }
  451.         else
  452.           while ( (index = penum->index++) != penum->size )
  453.             {    cached_char *cc;
  454.             chr = str[index];
  455.             cc = gx_lookup_cached_char(pgs, pair, chr);
  456.             if ( cc == 0 ) goto no_cache;
  457.             /* Character is in cache. */
  458.             code = gx_image_cached_char(penum, cc);
  459.             if ( code < 0 ) return code;
  460.             else if ( code > 0 ) goto no_cache;
  461.             if ( penum->slow_show )
  462.                {    penum->wxy = cc->wxy;
  463.                 code = show_move(penum);
  464.                }
  465.             else
  466.                 code = show_fast_move(cc->wxy, pgs);
  467.             if ( code ) return code;
  468.             }
  469.         /* All done. */
  470.         return show_finish(penum);
  471.        }
  472.     else
  473.        {    /* Can't use cache */
  474.         if ( (index = penum->index++) == penum->size )
  475.           {    /* All done. */
  476.             return show_finish(penum);
  477.           }
  478.         chr = str[index];
  479.        }
  480. no_cache:
  481.     /* Character is not cached, client must render it. */
  482.     if ( (code = gs_gsave(pgs)) < 0 ) return code;
  483.     /* Reset the in_cachedevice flag, so that a recursive show */
  484.     /* will use the cache properly. */
  485.     pgs->in_cachedevice = 0;
  486.     /* Set the charpath flag in the graphics context if necessary, */
  487.     /* so that fill and stroke will add to the path */
  488.     /* rather than having their usual effect. */
  489.     pgs->in_charpath = penum->charpath_flag;
  490.     pgs->stroke_adjust = 0;        /* per specification */
  491.        {    gs_fixed_point cpt;
  492.         gx_path *ppath = pgs->path;
  493.         if ( (code = gx_path_current_point_inline(ppath, &cpt)) < 0 )
  494.             return code;
  495.         cpt.x -= pgs->ctm.tx_fixed;
  496.         cpt.y -= pgs->ctm.ty_fixed;
  497.         gs_setmatrix(pgs, &pgs->char_tm);
  498.         cpt.x += pgs->ctm.tx_fixed;
  499.         cpt.y += pgs->ctm.ty_fixed;
  500.         if ( !penum->charpath_flag )
  501.           { /* Round the translation in the graphics state. */
  502.             /* This helps prevent rounding artifacts later. */
  503.             cpt.x = fixed_rounded(cpt.x);
  504.             cpt.y = fixed_rounded(cpt.y);
  505.           }
  506.         gs_translate_to_fixed(pgs, cpt.x, cpt.y);
  507.         gs_newpath(pgs);
  508.         gx_path_add_point(ppath, pgs->ctm.tx_fixed,
  509.                   pgs->ctm.ty_fixed);
  510.        }
  511.     penum->width_status = sws_none;
  512.     penum->width_set = penum->sb_set = 0;
  513.     penum->continue_proc = continue_show_update;
  514.     /* Try using the build procedure in the font. */
  515.     /* < 0 means error, 0 means success, 1 means failure. */
  516.        {    gs_font *pfont = pgs->font;
  517.         code = (*pfont->build_char_proc)(penum, pgs, pfont, chr, pfont->build_char_data);
  518.         if ( code < 0 ) return_error(code);
  519.         if ( code == 0 )
  520.            {    code = show_update(penum);
  521.             if ( code < 0 ) return code;
  522.             penum->color_loaded = 0;
  523.             code = show_move(penum);
  524.             if ( code ) return code;
  525.             goto more;
  526.            }
  527.        }
  528.     return gs_show_render;
  529. }
  530.  
  531. /* Finish show or stringwidth */
  532. private int
  533. show_finish(register gs_show_enum *penum)
  534. {    register gs_state *pgs = penum->pgs;
  535.     int code;
  536.     if ( !penum->stringwidth_flag ) return 0;
  537.     /* Save the accumulated width before returning, */
  538.     /* and undo the extra gsave. */
  539.     code = gs_currentpoint(pgs, &penum->width);
  540.     if ( code < 0 ) return code;
  541.     return gs_grestore(pgs);
  542. }
  543.  
  544. /* Return the current character for rendering. */
  545. char_code
  546. gs_show_current_char(gs_show_enum *penum)
  547. {    return penum->str[penum->index - 1];
  548. }
  549.  
  550. /* Return the just-displayed character for kerning. */
  551. char_code
  552. gs_kshow_previous_char(gs_show_enum *penum)
  553. {    return penum->str[penum->index - 1];
  554. }
  555.  
  556. /* Return the about-to-be-displayed character for kerning. */
  557. char_code
  558. gs_kshow_next_char(gs_show_enum *penum)
  559. {    return penum->str[penum->index];
  560. }
  561.  
  562. /* Return the accumulated width for stringwidth. */
  563. void
  564. gs_show_width(gs_show_enum *penum, gs_point *ppt)
  565. {    *ppt = penum->width;
  566. }
  567.  
  568. /* Return the charpath flag. */
  569. int
  570. gs_show_in_charpath(gs_show_enum *penum)
  571. {    return penum->charpath_flag;
  572. }
  573.  
  574. /* ------ Internal routines ------ */
  575.  
  576. /* Initialize a show enumerator. */
  577. private int
  578. show_setup(register gs_show_enum *penum, gs_state *pgs, const char *str)
  579. {    int code;
  580.     gs_font *pfont = pgs->font;
  581.     penum->pgs = pgs;
  582.     penum->level = pgs->level;
  583.     penum->str = (const byte *)str;    /* avoid signed chars */
  584.     penum->wchr = no_chr;
  585.     penum->add = 0;
  586.     penum->do_kern = 0;
  587.     penum->charpath_flag = 0;
  588.     penum->stringwidth_flag = 0;
  589.     penum->dev_cache_set = 0;
  590.     penum->index = 0;
  591.     penum->continue_proc = continue_show;
  592.     if ( (penum->is_composite = pfont->FontType == ft_composite) )
  593.        {    gs_font *rfont = pgs->font;
  594.         penum->fstack[0] = rfont;
  595.         penum->fdepth = 0;
  596.         penum->pfont =
  597.           rfont->data.type0_data.FDepVector[rfont->data.type0_data.Encoding[0]];
  598.        }
  599.     penum->can_cache = 1;        /* show_ctm_setup may reset */
  600.     code = show_ctm_setup(penum);
  601.     if ( code < 0 ) return code;
  602.     return 0;
  603. }
  604.  
  605. /* Initialize the CTM-related parts of a show enumerator. */
  606. /* We do this both when starting the show operation, */
  607. /* and when returning from the kshow callout. */
  608. private int
  609. show_ctm_setup(gs_show_enum *penum)
  610. {    gs_state *pgs = penum->pgs;
  611.     int code;
  612.     if ( !pgs->char_tm_valid )
  613.        {    /* Compute combined transformation */
  614.         gs_make_identity(&pgs->char_tm);    /* make sure type */
  615.                     /* fields are set in char_tm! */
  616.         code = gs_matrix_multiply(&pgs->font->FontMatrix,
  617.                       &ctm_only(pgs), &pgs->char_tm);
  618.         if ( code < 0 ) return code;
  619.         pgs->char_tm_valid = 1;
  620.        }
  621.     if ( penum->can_cache &= /* no skewing or non-rectangular rotation */
  622.         (is_fzero2(pgs->char_tm.xy, pgs->char_tm.yx) ||
  623.          is_fzero2(pgs->char_tm.xx, pgs->char_tm.yy)) )
  624.        {    gs_fixed_rect cbox;
  625.         gx_cpath_box_for_check(pgs->clip_path, &cbox);
  626.         penum->cxmin = fixed2int_var(cbox.p.x);
  627.         penum->cymin = fixed2int_var(cbox.p.y);
  628.         penum->cxmax = fixed2int_var(cbox.q.x);
  629.         penum->cymax = fixed2int_var(cbox.q.y);
  630.         penum->ftx = (int)fixed2long(float2fixed(pgs->char_tm.tx) - pgs->ctm.tx_fixed);
  631.         penum->fty = (int)fixed2long(float2fixed(pgs->char_tm.ty) - pgs->ctm.ty_fixed);
  632.        }
  633.     return 0;
  634. }
  635.