gdevpdtb.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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: gdevpdtb.h,v 1.11 2005/04/04 08:53:07 igor Exp $ */
  14. /* BaseFont structure and API for pdfwrite */
  15. #ifndef gdevpdtb_INCLUDED
  16. # define gdevpdtb_INCLUDED
  17. #include "gdevpdtx.h"
  18. /* ================ Types and structures ================ */
  19. /*
  20. * A "base font" pdf_base_font_t contains a stable copy of a gs_font. The
  21. * only supported font types are Type 1/2, TrueType / Type 42, CIDFontType
  22. * 0, and CIDFontType 2.
  23. *
  24. * At the time a base font is created, we copy the fixed elements of the
  25. * gs_font (that is, everything except the data for individual glyphs) into
  26. * stable memory; we then copy individual glyphs as they are used. If
  27. * subsetting is not mandatory (that is, if the entire font might be
  28. * embedded or its Widths written), we also save a separate copy of the
  29. * entire font, since the subsetting decision cannot be made until the font
  30. * is written out (normally at the end of the document).
  31. *
  32. * In an earlier design, we deferred making the complete copy until the font
  33. * was about to be freed. We decided that the substantial extra complexity
  34. * of this approach did not justify the space that would be saved in the
  35. * usual (subsetted) case.
  36. *
  37. * The term "base font" is used, confusingly, for at least 3 different
  38. * concepts in Ghostscript. However, the above meaning is used consistently
  39. * within the PDF text code (gdevpdt*.[ch]).
  40. */
  41. /*
  42. * Font names in PDF files have caused an enormous amount of trouble, so we
  43. * document specifically how they are handled in each structure.
  44. *
  45. * The PDF Reference doesn't place any constraints on the [CID]FontName of
  46. * base fonts, although it does say that the BaseFont name in the font
  47. * resource is "usually" derived from the [CID]FontName of the base font.
  48. * The code in this module allows setting the font name. It initializes
  49. * the name to the key_name of the base font, or to the font_name if the
  50. * base font has no key_name, minus any XXXXXX+ subset prefix; the
  51. * pdf_do_subset_font procedure adds the XXXXXX+ prefix if the font will
  52. * be subsetted.
  53. */
  54. #ifndef pdf_base_font_DEFINED
  55. # define pdf_base_font_DEFINED
  56. typedef struct pdf_base_font_s pdf_base_font_t;
  57. #endif
  58. /* ================ Procedures ================ */
  59. /*
  60. * Allocate and initialize a base font structure, making the required
  61. * stable copy/ies of the gs_font. Note that this removes any XXXXXX+
  62. * font name prefix from the copy. If complete is true, the copy is
  63. * a complete one, and adding glyphs or Encoding entries is not allowed.
  64. */
  65. int pdf_base_font_alloc(gx_device_pdf *pdev, pdf_base_font_t **ppbfont,
  66. gs_font_base *font, const gs_matrix *orig_matrix,
  67. bool is_standard, bool orig_name);
  68. /*
  69. * Return a reference to the name of a base font. This name is guaranteed
  70. * not to have a XXXXXX+ prefix. The client may change the name at will,
  71. * but must not add a XXXXXX+ prefix.
  72. */
  73. gs_string *pdf_base_font_name(pdf_base_font_t *pbfont);
  74. /*
  75. * Return the (copied, subset or complete) font associated with a base font.
  76. * This procedure probably shouldn't exist....
  77. */
  78. gs_font_base *pdf_base_font_font(const pdf_base_font_t *pbfont, bool complete);
  79. /*
  80. * Check for subset font.
  81. */
  82. bool pdf_base_font_is_subset(const pdf_base_font_t *pbfont);
  83. /*
  84. * Drop the copied complete font associated with a base font.
  85. */
  86. void pdf_base_font_drop_complete(pdf_base_font_t *pbfont);
  87. /*
  88. * Copy a glyph (presumably one that was just used) into a saved base
  89. * font. Note that it is the client's responsibility to determine that
  90. * the source font is compatible with the target font. (Normally they
  91. * will be the same.)
  92. */
  93. int pdf_base_font_copy_glyph(pdf_base_font_t *pbfont, gs_glyph glyph,
  94. gs_font_base *font);
  95. /*
  96. * Determine whether a font is a subset font by examining the name.
  97. */
  98. bool pdf_has_subset_prefix(const byte *str, uint size);
  99. /*
  100. * Add the XXXXXX+ prefix for a subset font.
  101. */
  102. int pdf_add_subset_prefix(const gx_device_pdf *pdev, gs_string *pstr,
  103. byte *used, int count);
  104. /*
  105. * Determine whether a copied font should be subsetted.
  106. */
  107. bool pdf_do_subset_font(gx_device_pdf *pdev, pdf_base_font_t *pbfont,
  108. gs_id rid);
  109. /*
  110. * Write the FontFile entry for an embedded font, /FontFile<n> # # R.
  111. */
  112. int pdf_write_FontFile_entry(gx_device_pdf *pdev, pdf_base_font_t *pbfont);
  113. /*
  114. * Write an embedded font, possibly subsetted.
  115. */
  116. int pdf_write_embedded_font(gx_device_pdf *pdev, pdf_base_font_t *pbfont,
  117. gs_int_rect *FontBBox, gs_id rid, cos_dict_t **ppcd);
  118. /*
  119. * Write the CharSet data for a subsetted font, as a PDF string.
  120. */
  121. int pdf_write_CharSet(gx_device_pdf *pdev, pdf_base_font_t *pbfont);
  122. /*
  123. * Write the CIDSet object for a subsetted CIDFont.
  124. */
  125. int pdf_write_CIDSet(gx_device_pdf *pdev, pdf_base_font_t *pbfont,
  126. long *pcidset_id);
  127. /*
  128. * Check whether a base font is standard.
  129. */
  130. bool pdf_is_standard_font(pdf_base_font_t *bfont);
  131. void pdf_set_FontFile_object(pdf_base_font_t *bfont, cos_dict_t *pcd);
  132. const cos_dict_t * pdf_get_FontFile_object(pdf_base_font_t *bfont);
  133. #endif /* gdevpdtb_INCLUDED */