gsfont0.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Copyright (C) 1994, 1996, 1997, 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: gsfont0.c,v 1.2 2000/09/19 19:00:28 lpd Exp $ */
  16. /* Composite font operations for Ghostscript library */
  17. #include "memory_.h"
  18. #include "gx.h"
  19. #include "gserrors.h"
  20. #include "gsstruct.h"
  21. #include "gxfixed.h"
  22. #include "gsmatrix.h"
  23. #include "gxdevice.h"
  24. #include "gxdevmem.h"
  25. #include "gxfcache.h" /* gs_font_dir */
  26. #include "gxfont.h"
  27. #include "gxfont0.h"
  28. /* Structure descriptor */
  29. private struct_proc_enum_ptrs(font_type0_enum_ptrs);
  30. private struct_proc_reloc_ptrs(font_type0_reloc_ptrs);
  31. public_st_gs_font_type0();
  32. private
  33. ENUM_PTRS_WITH(font_type0_enum_ptrs, gs_font_type0 *pfont)
  34. ENUM_PREFIX(st_gs_font, gs_type0_data_max_ptrs);
  35. ENUM_PTR(0, gs_font_type0, data.Encoding);
  36. ENUM_PTR(1, gs_font_type0, data.FDepVector);
  37. case 2:
  38. switch (pfont->data.FMapType)
  39. {
  40. case fmap_SubsVector:
  41. ENUM_RETURN_CONST_STRING_PTR(gs_font_type0,
  42. data.SubsVector);
  43. case fmap_CMap:
  44. ENUM_RETURN_PTR(gs_font_type0, data.CMap);
  45. default:
  46. ENUM_RETURN(0);
  47. }
  48. ENUM_PTRS_END
  49. private RELOC_PTRS_WITH(font_type0_reloc_ptrs, gs_font_type0 *pfont)
  50. RELOC_PREFIX(st_gs_font);
  51. RELOC_PTR(gs_font_type0, data.Encoding);
  52. RELOC_PTR(gs_font_type0, data.FDepVector);
  53. switch (pfont->data.FMapType)
  54. {
  55. case fmap_SubsVector:
  56. RELOC_CONST_STRING_PTR(gs_font_type0, data.SubsVector);
  57. break;
  58. case fmap_CMap:
  59. RELOC_PTR(gs_font_type0, data.CMap);
  60. break;
  61. default:
  62. ;
  63. }
  64. RELOC_PTRS_END
  65. /* Adjust a composite font by concatenating a given matrix */
  66. /* to the FontMatrix of all descendant composite fonts. */
  67. private int
  68. gs_type0_adjust_matrix(gs_font_dir * pdir, gs_font_type0 * pfont,
  69. const gs_matrix * pmat)
  70. {
  71. gs_font **pdep = pfont->data.FDepVector;
  72. uint fdep_size = pfont->data.fdep_size;
  73. gs_font **ptdep;
  74. uint i;
  75. /* Check for any descendant composite fonts. */
  76. for (i = 0; i < fdep_size; i++)
  77. if (pdep[i]->FontType == ft_composite)
  78. break;
  79. if (i == fdep_size)
  80. return 0;
  81. ptdep = gs_alloc_struct_array(pfont->memory, fdep_size, gs_font *,
  82. &st_gs_font_ptr_element,
  83. "gs_type0_adjust_font(FDepVector)");
  84. if (ptdep == 0)
  85. return_error(gs_error_VMerror);
  86. memcpy(ptdep, pdep, sizeof(gs_font *) * fdep_size);
  87. for (; i < fdep_size; i++)
  88. if (pdep[i]->FontType == ft_composite) {
  89. int code = gs_makefont(pdir, pdep[i], pmat, &ptdep[i]);
  90. if (code < 0)
  91. return code;
  92. }
  93. pfont->data.FDepVector = ptdep;
  94. return 0;
  95. }
  96. /* Finish defining a composite font, */
  97. /* by adjusting its descendants' FontMatrices. */
  98. int
  99. gs_type0_define_font(gs_font_dir * pdir, gs_font * pfont)
  100. {
  101. const gs_matrix *pmat = &pfont->FontMatrix;
  102. /* Check for the identity matrix, which is common in root fonts. */
  103. if (pmat->xx == 1.0 && pmat->yy == 1.0 &&
  104. pmat->xy == 0.0 && pmat->yx == 0.0 &&
  105. pmat->tx == 0.0 && pmat->ty == 0.0
  106. )
  107. return 0;
  108. return gs_type0_adjust_matrix(pdir, (gs_font_type0 *) pfont, pmat);
  109. }
  110. /* Finish scaling a composite font similarly. */
  111. int
  112. gs_type0_make_font(gs_font_dir * pdir, const gs_font * pfont,
  113. const gs_matrix * pmat, gs_font ** ppfont)
  114. {
  115. return gs_type0_adjust_matrix(pdir, (gs_font_type0 *) * ppfont, pmat);
  116. }