zcidtest.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* Copyright (C) 2002 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: zcidtest.c,v 1.3 2003/05/22 15:41:03 igor Exp $ */
  14. /* Operators for testing CIDFont and CMap facilities */
  15. #include "string_.h"
  16. #include "ghost.h"
  17. #include "gxfont.h"
  18. #include "gxfont0c.h"
  19. #include "gdevpsf.h"
  20. #include "stream.h"
  21. #include "spprint.h"
  22. #include "oper.h"
  23. #include "files.h"
  24. #include "idict.h"
  25. #include "ifont.h"
  26. #include "igstate.h"
  27. #include "iname.h"
  28. #include "store.h"
  29. /* - .wrapfont - */
  30. private int
  31. zwrapfont(i_ctx_t *i_ctx_p)
  32. {
  33. gs_font *font = gs_currentfont(igs);
  34. gs_font_type0 *font0;
  35. int wmode = 0;
  36. int code;
  37. switch (font->FontType) {
  38. case ft_TrueType:
  39. code = gs_font_type0_from_type42(&font0, (gs_font_type42 *)font, wmode,
  40. true, font->memory);
  41. if (code < 0)
  42. return code;
  43. /*
  44. * Patch up BuildChar and CIDMap. This isn't necessary for
  45. * TrueType fonts in general, only for Type 42 fonts whose
  46. * BuildChar is implemented in PostScript code.
  47. */
  48. {
  49. font_data *pdata = pfont_data(font);
  50. const char *bgstr = "%Type11BuildGlyph";
  51. ref temp;
  52. make_int(&temp, 0);
  53. ref_assign(&pdata->u.type42.CIDMap, &temp);
  54. code = name_ref((const byte *)bgstr, strlen(bgstr), &temp, 1);
  55. if (code < 0)
  56. return code;
  57. r_set_attrs(&temp, a_executable);
  58. ref_assign(&pdata->BuildGlyph, &temp);
  59. }
  60. break;
  61. case ft_CID_encrypted:
  62. case ft_CID_user_defined:
  63. case ft_CID_TrueType:
  64. code = gs_font_type0_from_cidfont(&font0, font, wmode, NULL,
  65. font->memory);
  66. break;
  67. default:
  68. return_error(e_rangecheck);
  69. }
  70. if (code < 0)
  71. return code;
  72. gs_setfont(igs, (gs_font *)font0);
  73. return 0;
  74. }
  75. /* <file> <cmap> .writecmap - */
  76. private int
  77. zfcmap_put_name_default(stream *s, const byte *str, uint size)
  78. {
  79. stream_putc(s, '/');
  80. stream_write(s, str, size);
  81. return 0;
  82. }
  83. private int
  84. zwritecmap(i_ctx_t *i_ctx_p)
  85. {
  86. os_ptr op = osp;
  87. ref *pcodemap;
  88. gs_cmap_t *pcmap;
  89. int code;
  90. stream *s;
  91. check_type(*op, t_dictionary);
  92. if (dict_find_string(op, "CodeMap", &pcodemap) <= 0 ||
  93. !r_is_struct(pcodemap)
  94. )
  95. return_error(e_typecheck);
  96. check_write_file(s, op - 1);
  97. pcmap = r_ptr(pcodemap, gs_cmap_t);
  98. code = psf_write_cmap(s, pcmap, zfcmap_put_name_default, NULL, -1);
  99. if (code >= 0)
  100. pop(2);
  101. return code;
  102. }
  103. /* <file> <cid9font> .writefont9 - */
  104. private int
  105. zwritefont9(i_ctx_t *i_ctx_p)
  106. {
  107. os_ptr op = osp;
  108. gs_font *pfont;
  109. gs_font_cid0 *pfcid;
  110. int code = font_param(op, &pfont);
  111. stream *s;
  112. if (code < 0)
  113. return code;
  114. if (pfont->FontType != ft_CID_encrypted)
  115. return_error(e_invalidfont);
  116. check_write_file(s, op - 1);
  117. pfcid = (gs_font_cid0 *)pfont;
  118. code = psf_write_cid0_font(s, pfcid,
  119. WRITE_TYPE2_NO_LENIV | WRITE_TYPE2_CHARSTRINGS,
  120. NULL, 0, NULL);
  121. if (code >= 0)
  122. pop(2);
  123. return code;
  124. }
  125. /* ------ Initialization procedure ------ */
  126. const op_def zcidtest_op_defs[] =
  127. {
  128. {"1.wrapfont", zwrapfont},
  129. {"2.writecmap", zwritecmap},
  130. {"2.writefont9", zwritefont9},
  131. op_def_end(0)
  132. };