zcharx.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* Copyright (C) 1992, 2000 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: zcharx.c,v 1.3 2000/09/19 19:00:52 lpd Exp $ */
  16. /* Level 2 character operators */
  17. #include "ghost.h"
  18. #include "oper.h"
  19. #include "gsmatrix.h" /* for gxfont.h */
  20. #include "gstext.h"
  21. #include "gxfixed.h" /* for gxfont.h */
  22. #include "gxfont.h"
  23. #include "ialloc.h"
  24. #include "ichar.h"
  25. #include "igstate.h"
  26. #include "iname.h"
  27. #include "ibnum.h"
  28. /* Common setup for glyphshow and .glyphwidth. */
  29. private int
  30. glyph_show_setup(i_ctx_t *i_ctx_p, gs_glyph *pglyph)
  31. {
  32. os_ptr op = osp;
  33. switch (gs_currentfont(igs)->FontType) {
  34. case ft_CID_encrypted:
  35. case ft_CID_user_defined:
  36. case ft_CID_TrueType:
  37. case ft_CID_bitmap:
  38. check_int_leu(*op, gs_max_glyph - gs_min_cid_glyph);
  39. *pglyph = (gs_glyph) op->value.intval + gs_min_cid_glyph;
  40. break;
  41. default:
  42. check_type(*op, t_name);
  43. *pglyph = name_index(op);
  44. }
  45. return op_show_enum_setup(i_ctx_p);
  46. }
  47. /* <charname> glyphshow - */
  48. private int
  49. zglyphshow(i_ctx_t *i_ctx_p)
  50. {
  51. gs_glyph glyph;
  52. gs_text_enum_t *penum;
  53. int code;
  54. if ((code = glyph_show_setup(i_ctx_p, &glyph)) != 0 ||
  55. (code = gs_glyphshow_begin(igs, glyph, imemory, &penum)) < 0)
  56. return code;
  57. if ((code = op_show_finish_setup(i_ctx_p, penum, 1, NULL)) < 0) {
  58. ifree_object(penum, "zglyphshow");
  59. return code;
  60. }
  61. return op_show_continue_pop(i_ctx_p, 1);
  62. }
  63. /* <charname> .glyphwidth <wx> <wy> */
  64. private int
  65. zglyphwidth(i_ctx_t *i_ctx_p)
  66. {
  67. gs_glyph glyph;
  68. gs_text_enum_t *penum;
  69. int code;
  70. if ((code = glyph_show_setup(i_ctx_p, &glyph)) != 0 ||
  71. (code = gs_glyphwidth_begin(igs, glyph, imemory, &penum)) < 0)
  72. return code;
  73. if ((code = op_show_finish_setup(i_ctx_p, penum, 1, finish_stringwidth)) < 0) {
  74. ifree_object(penum, "zglyphwidth");
  75. return code;
  76. }
  77. return op_show_continue_pop(i_ctx_p, 1);
  78. }
  79. /* <string> <numarray|numstring> xshow - */
  80. /* <string> <numarray|numstring> yshow - */
  81. /* <string> <numarray|numstring> xyshow - */
  82. private int
  83. moveshow(i_ctx_t *i_ctx_p, bool have_x, bool have_y)
  84. {
  85. os_ptr op = osp;
  86. gs_text_enum_t *penum;
  87. int code = op_show_setup(i_ctx_p, op - 1);
  88. int format;
  89. uint i, size;
  90. float *values;
  91. if (code != 0)
  92. return code;
  93. format = num_array_format(op);
  94. if (format < 0)
  95. return format;
  96. size = num_array_size(op, format);
  97. values = (float *)ialloc_byte_array(size, sizeof(float), "moveshow");
  98. if (values == 0)
  99. return_error(e_VMerror);
  100. for (i = 0; i < size; ++i) {
  101. ref value;
  102. switch (code = num_array_get(op, format, i, &value)) {
  103. case t_integer:
  104. values[i] = value.value.intval; break;
  105. case t_real:
  106. values[i] = value.value.realval; break;
  107. case t_null:
  108. code = gs_note_error(e_rangecheck);
  109. /* falls through */
  110. default:
  111. ifree_object(values, "moveshow");
  112. return code;
  113. }
  114. }
  115. if ((code = gs_xyshow_begin(igs, op[-1].value.bytes, r_size(op - 1),
  116. (have_x ? values : (float *)0),
  117. (have_y ? values : (float *)0),
  118. size, imemory, &penum)) < 0 ||
  119. (code = op_show_finish_setup(i_ctx_p, penum, 2, NULL)) < 0) {
  120. ifree_object(values, "moveshow");
  121. return code;
  122. }
  123. pop(2);
  124. return op_show_continue(i_ctx_p);
  125. }
  126. private int
  127. zxshow(i_ctx_t *i_ctx_p)
  128. {
  129. return moveshow(i_ctx_p, true, false);
  130. }
  131. private int
  132. zyshow(i_ctx_t *i_ctx_p)
  133. {
  134. return moveshow(i_ctx_p, false, true);
  135. }
  136. private int
  137. zxyshow(i_ctx_t *i_ctx_p)
  138. {
  139. return moveshow(i_ctx_p, true, true);
  140. }
  141. /* ------ Initialization procedure ------ */
  142. const op_def zcharx_op_defs[] =
  143. {
  144. op_def_begin_level2(),
  145. {"1glyphshow", zglyphshow},
  146. {"1.glyphwidth", zglyphwidth},
  147. {"2xshow", zxshow},
  148. {"2xyshow", zxyshow},
  149. {"2yshow", zyshow},
  150. op_def_end(0)
  151. };