zcharx.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* Copyright (C) 1992, 2000 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: zcharx.c,v 1.7 2004/08/04 19:36:13 stefan Exp $ */
  14. /* Level 2 character operators */
  15. #include "ghost.h"
  16. #include "oper.h"
  17. #include "gsmatrix.h" /* for gxfont.h */
  18. #include "gstext.h"
  19. #include "gxfixed.h" /* for gxfont.h */
  20. #include "gxfont.h"
  21. #include "ialloc.h"
  22. #include "ichar.h"
  23. #include "igstate.h"
  24. #include "iname.h"
  25. #include "ibnum.h"
  26. /* Common setup for glyphshow and .glyphwidth. */
  27. private int
  28. glyph_show_setup(i_ctx_t *i_ctx_p, gs_glyph *pglyph)
  29. {
  30. os_ptr op = osp;
  31. switch (gs_currentfont(igs)->FontType) {
  32. case ft_CID_encrypted:
  33. case ft_CID_user_defined:
  34. case ft_CID_TrueType:
  35. case ft_CID_bitmap:
  36. check_int_leu(*op, gs_max_glyph - gs_min_cid_glyph);
  37. *pglyph = (gs_glyph) op->value.intval + gs_min_cid_glyph;
  38. break;
  39. default:
  40. check_type(*op, t_name);
  41. *pglyph = name_index(imemory, op);
  42. }
  43. return op_show_enum_setup(i_ctx_p);
  44. }
  45. /* <charname> glyphshow - */
  46. private int
  47. zglyphshow(i_ctx_t *i_ctx_p)
  48. {
  49. gs_glyph glyph;
  50. gs_text_enum_t *penum;
  51. int code;
  52. if ((code = glyph_show_setup(i_ctx_p, &glyph)) != 0 ||
  53. (code = gs_glyphshow_begin(igs, glyph, imemory, &penum)) < 0)
  54. return code;
  55. if ((code = op_show_finish_setup(i_ctx_p, penum, 1, NULL)) < 0) {
  56. ifree_object(penum, "zglyphshow");
  57. return code;
  58. }
  59. return op_show_continue_pop(i_ctx_p, 1);
  60. }
  61. /* <charname> .glyphwidth <wx> <wy> */
  62. private int
  63. zglyphwidth(i_ctx_t *i_ctx_p)
  64. {
  65. gs_glyph glyph;
  66. gs_text_enum_t *penum;
  67. int code;
  68. if ((code = glyph_show_setup(i_ctx_p, &glyph)) != 0 ||
  69. (code = gs_glyphwidth_begin(igs, glyph, imemory, &penum)) < 0)
  70. return code;
  71. if ((code = op_show_finish_setup(i_ctx_p, penum, 1, finish_stringwidth)) < 0) {
  72. ifree_object(penum, "zglyphwidth");
  73. return code;
  74. }
  75. return op_show_continue_pop(i_ctx_p, 1);
  76. }
  77. /* <string> <numarray|numstring> xshow - */
  78. /* <string> <numarray|numstring> yshow - */
  79. /* <string> <numarray|numstring> xyshow - */
  80. private int
  81. moveshow(i_ctx_t *i_ctx_p, bool have_x, bool have_y)
  82. {
  83. os_ptr op = osp;
  84. gs_text_enum_t *penum;
  85. int code = op_show_setup(i_ctx_p, op - 1);
  86. int format;
  87. uint i, size;
  88. float *values;
  89. if (code != 0)
  90. return code;
  91. format = num_array_format(op);
  92. if (format < 0)
  93. return format;
  94. size = num_array_size(op, format);
  95. values = (float *)ialloc_byte_array(size, sizeof(float), "moveshow");
  96. if (values == 0)
  97. return_error(e_VMerror);
  98. for (i = 0; i < size; ++i) {
  99. ref value;
  100. switch (code = num_array_get(imemory, op, format, i, &value)) {
  101. case t_integer:
  102. values[i] = (float)value.value.intval; break;
  103. case t_real:
  104. values[i] = value.value.realval; break;
  105. case t_null:
  106. code = gs_note_error(e_rangecheck);
  107. /* falls through */
  108. default:
  109. ifree_object(values, "moveshow");
  110. return code;
  111. }
  112. }
  113. if ((code = gs_xyshow_begin(igs, op[-1].value.bytes, r_size(op - 1),
  114. (have_x ? values : (float *)0),
  115. (have_y ? values : (float *)0),
  116. size, imemory, &penum)) < 0 ||
  117. (code = op_show_finish_setup(i_ctx_p, penum, 2, NULL)) < 0) {
  118. ifree_object(values, "moveshow");
  119. return code;
  120. }
  121. pop(2);
  122. return op_show_continue(i_ctx_p);
  123. }
  124. private int
  125. zxshow(i_ctx_t *i_ctx_p)
  126. {
  127. return moveshow(i_ctx_p, true, false);
  128. }
  129. private int
  130. zyshow(i_ctx_t *i_ctx_p)
  131. {
  132. return moveshow(i_ctx_p, false, true);
  133. }
  134. private int
  135. zxyshow(i_ctx_t *i_ctx_p)
  136. {
  137. return moveshow(i_ctx_p, true, true);
  138. }
  139. /* ------ Initialization procedure ------ */
  140. const op_def zcharx_op_defs[] =
  141. {
  142. op_def_begin_level2(),
  143. {"1glyphshow", zglyphshow},
  144. {"1.glyphwidth", zglyphwidth},
  145. {"2xshow", zxshow},
  146. {"2xyshow", zxyshow},
  147. {"2yshow", zyshow},
  148. op_def_end(0)
  149. };