zcfont.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* Copyright (C) 1998, 1999 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: zcfont.c,v 1.2 2000/09/19 19:00:52 lpd Exp $ */
  16. /* Composite font-related character operators */
  17. #include "ghost.h"
  18. #include "oper.h"
  19. #include "gsmatrix.h" /* for gxfont.h */
  20. #include "gxfixed.h" /* for gxfont.h */
  21. #include "gxfont.h"
  22. #include "gxtext.h"
  23. #include "estack.h"
  24. #include "ichar.h"
  25. #include "ifont.h"
  26. #include "igstate.h"
  27. #include "store.h"
  28. /* Forward references */
  29. private int cshow_continue(P1(i_ctx_t *));
  30. private int cshow_restore_font(P1(i_ctx_t *));
  31. /* <proc> <string> cshow - */
  32. private int
  33. zcshow(i_ctx_t *i_ctx_p)
  34. {
  35. os_ptr op = osp;
  36. os_ptr proc_op = op - 1;
  37. os_ptr str_op = op;
  38. gs_text_enum_t *penum;
  39. int code;
  40. /*
  41. * Even though this is not documented anywhere by Adobe,
  42. * some Adobe interpreters apparently allow the string and
  43. * the procedure to be provided in either order!
  44. */
  45. if (r_is_proc(proc_op))
  46. ;
  47. else if (r_is_proc(op)) { /* operands reversed */
  48. proc_op = op;
  49. str_op = op - 1;
  50. } else {
  51. check_op(2);
  52. return_error(e_typecheck);
  53. }
  54. if ((code = op_show_setup(i_ctx_p, str_op)) != 0 ||
  55. (code = gs_cshow_begin(igs, str_op->value.bytes, r_size(str_op),
  56. imemory, &penum)) < 0)
  57. return code;
  58. if ((code = op_show_finish_setup(i_ctx_p, penum, 2, NULL)) < 0) {
  59. ifree_object(penum, "op_show_enum_setup");
  60. return code;
  61. }
  62. sslot = *proc_op; /* save kerning proc */
  63. pop(2);
  64. return cshow_continue(i_ctx_p);
  65. }
  66. private int
  67. cshow_continue(i_ctx_t *i_ctx_p)
  68. {
  69. os_ptr op = osp;
  70. gs_text_enum_t *penum = senum;
  71. int code;
  72. check_estack(4); /* in case we call the procedure */
  73. code = gs_text_process(penum);
  74. if (code != TEXT_PROCESS_INTERVENE) {
  75. code = op_show_continue_dispatch(i_ctx_p, 0, code);
  76. if (code == o_push_estack) /* must be TEXT_PROCESS_RENDER */
  77. make_op_estack(esp - 1, cshow_continue);
  78. return code;
  79. }
  80. /* Push the character code and width, and call the procedure. */
  81. {
  82. ref *pslot = &sslot;
  83. gs_point wpt;
  84. gs_font *font = gs_text_current_font(penum);
  85. gs_font *root_font = gs_rootfont(igs);
  86. gs_font *scaled_font;
  87. uint font_space = r_space(pfont_dict(font));
  88. uint root_font_space = r_space(pfont_dict(root_font));
  89. gs_text_current_width(penum, &wpt);
  90. if (font == root_font)
  91. scaled_font = font;
  92. else {
  93. /* Construct a scaled version of the leaf font. */
  94. uint save_space = idmemory->current_space;
  95. ialloc_set_space(idmemory, font_space);
  96. code = gs_makefont(font->dir, font, &root_font->FontMatrix,
  97. &scaled_font);
  98. ialloc_set_space(idmemory, save_space);
  99. if (code < 0)
  100. return code;
  101. }
  102. push(3);
  103. make_int(op - 2, gs_text_current_char(penum) & 0xff);
  104. make_real(op - 1, wpt.x);
  105. make_real(op, wpt.y);
  106. make_struct(&ssfont, font_space, font);
  107. make_struct(&srfont, root_font_space, root_font);
  108. push_op_estack(cshow_restore_font);
  109. /* cshow does not change rootfont for user procedure */
  110. gs_set_currentfont(igs, scaled_font);
  111. *++esp = *pslot; /* user procedure */
  112. }
  113. return o_push_estack;
  114. }
  115. private int
  116. cshow_restore_font(i_ctx_t *i_ctx_p)
  117. {
  118. /* We must restore both the root font and the current font. */
  119. gs_setfont(igs, r_ptr(&srfont, gs_font));
  120. gs_set_currentfont(igs, r_ptr(&ssfont, gs_font));
  121. return cshow_continue(i_ctx_p);
  122. }
  123. /* - rootfont <font> */
  124. private int
  125. zrootfont(i_ctx_t *i_ctx_p)
  126. {
  127. os_ptr op = osp;
  128. push(1);
  129. *op = *pfont_dict(gs_rootfont(igs));
  130. return 0;
  131. }
  132. /* ------ Initialization procedure ------ */
  133. const op_def zcfont_op_defs[] =
  134. {
  135. {"2cshow", zcshow},
  136. {"0rootfont", zrootfont},
  137. /* Internal operators */
  138. {"0%cshow_continue", cshow_continue},
  139. {"0%cshow_restore_font", cshow_restore_font},
  140. op_def_end(0)
  141. };