1 /* Copyright (C) 2001-2012 Artifex Software, Inc. 2 All Rights Reserved. 3 4 This software is provided AS-IS with no warranty, either express or 5 implied. 6 7 This software is distributed under license and may not be copied, 8 modified or distributed except as expressly authorized under the terms 9 of the license contained in the file LICENSE in this distribution. 10 11 Refer to licensing information at http://www.artifex.com or contact 12 Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, San Rafael, 13 CA 94903, U.S.A., +1(415)492-9861, for further information. 14 */ 15 16 17 /* BaseFont structure and API for pdfwrite */ 18 19 #ifndef gdevpdtb_INCLUDED 20 # define gdevpdtb_INCLUDED 21 22 #include "gdevpdtx.h" 23 24 /* ================ Types and structures ================ */ 25 26 /* 27 * A "base font" pdf_base_font_t contains a stable copy of a gs_font. The 28 * only supported font types are Type 1/2, TrueType / Type 42, CIDFontType 29 * 0, and CIDFontType 2. 30 * 31 * At the time a base font is created, we copy the fixed elements of the 32 * gs_font (that is, everything except the data for individual glyphs) into 33 * stable memory; we then copy individual glyphs as they are used. If 34 * subsetting is not mandatory (that is, if the entire font might be 35 * embedded or its Widths written), we also save a separate copy of the 36 * entire font, since the subsetting decision cannot be made until the font 37 * is written out (normally at the end of the document). 38 * 39 * In an earlier design, we deferred making the complete copy until the font 40 * was about to be freed. We decided that the substantial extra complexity 41 * of this approach did not justify the space that would be saved in the 42 * usual (subsetted) case. 43 * 44 * The term "base font" is used, confusingly, for at least 3 different 45 * concepts in Ghostscript. However, the above meaning is used consistently 46 * within the PDF text code (gdevpdt*.[ch]). 47 */ 48 /* 49 * Font names in PDF files have caused an enormous amount of trouble, so we 50 * document specifically how they are handled in each structure. 51 * 52 * The PDF Reference doesn't place any constraints on the [CID]FontName of 53 * base fonts, although it does say that the BaseFont name in the font 54 * resource is "usually" derived from the [CID]FontName of the base font. 55 * The code in this module allows setting the font name. It initializes 56 * the name to the key_name of the base font, or to the font_name if the 57 * base font has no key_name, minus any XXXXXX+ subset prefix; the 58 * pdf_do_subset_font procedure adds the XXXXXX+ prefix if the font will 59 * be subsetted. 60 */ 61 62 #ifndef pdf_base_font_DEFINED 63 # define pdf_base_font_DEFINED 64 typedef struct pdf_base_font_s pdf_base_font_t; 65 #endif 66 67 /* ================ Procedures ================ */ 68 69 /* 70 * Allocate and initialize a base font structure, making the required 71 * stable copy/ies of the gs_font. Note that this removes any XXXXXX+ 72 * font name prefix from the copy. If complete is true, the copy is 73 * a complete one, and adding glyphs or Encoding entries is not allowed. 74 */ 75 int pdf_base_font_alloc(gx_device_pdf *pdev, pdf_base_font_t **ppbfont, 76 gs_font_base *font, const gs_matrix *orig_matrix, 77 bool is_standard); 78 79 /* 80 * Return a reference to the name of a base font. This name is guaranteed 81 * not to have a XXXXXX+ prefix. The client may change the name at will, 82 * but must not add a XXXXXX+ prefix. 83 */ 84 gs_string *pdf_base_font_name(pdf_base_font_t *pbfont); 85 86 /* 87 * Return the (copied, subset or complete) font associated with a base font. 88 * This procedure probably shouldn't exist.... 89 */ 90 gs_font_base *pdf_base_font_font(const pdf_base_font_t *pbfont, bool complete); 91 92 /* 93 * Check for subset font. 94 */ 95 bool pdf_base_font_is_subset(const pdf_base_font_t *pbfont); 96 97 /* 98 * Drop the copied complete font associated with a base font. 99 */ 100 void pdf_base_font_drop_complete(pdf_base_font_t *pbfont); 101 102 /* 103 * Copy a glyph (presumably one that was just used) into a saved base 104 * font. Note that it is the client's responsibility to determine that 105 * the source font is compatible with the target font. (Normally they 106 * will be the same.) 107 */ 108 int pdf_base_font_copy_glyph(pdf_base_font_t *pbfont, gs_glyph glyph, 109 gs_font_base *font); 110 111 /* 112 * Determine whether a font is a subset font by examining the name. 113 */ 114 bool pdf_has_subset_prefix(const byte *str, uint size); 115 116 /* 117 * Add the XXXXXX+ prefix for a subset font. 118 */ 119 int pdf_add_subset_prefix(const gx_device_pdf *pdev, gs_string *pstr, 120 byte *used, int count); 121 122 /* 123 * Determine whether a copied font should be subsetted. 124 */ 125 bool pdf_do_subset_font(gx_device_pdf *pdev, pdf_base_font_t *pbfont, 126 gs_id rid); 127 128 /* 129 * Write the FontFile entry for an embedded font, /FontFile<n> # # R. 130 */ 131 int pdf_write_FontFile_entry(gx_device_pdf *pdev, pdf_base_font_t *pbfont); 132 133 /* 134 * Write an embedded font, possibly subsetted. 135 */ 136 int pdf_write_embedded_font(gx_device_pdf *pdev, pdf_base_font_t *pbfont, font_type FontType, 137 gs_int_rect *FontBBox, gs_id rid, cos_dict_t **ppcd); 138 139 /* 140 * Write the CharSet data for a subsetted font, as a PDF string. 141 */ 142 int pdf_write_CharSet(gx_device_pdf *pdev, pdf_base_font_t *pbfont); 143 144 /* 145 * Write the CIDSet object for a subsetted CIDFont. 146 */ 147 int pdf_write_CIDSet(gx_device_pdf *pdev, pdf_base_font_t *pbfont, 148 long *pcidset_id); 149 150 /* 151 * Check whether a base font is standard. 152 */ 153 bool pdf_is_standard_font(pdf_base_font_t *bfont); 154 155 void pdf_set_FontFile_object(pdf_base_font_t *bfont, cos_dict_t *pcd); 156 const cos_dict_t * pdf_get_FontFile_object(pdf_base_font_t *bfont); 157 158 const char *pdf_find_base14_name(const byte *str, uint size); 159 160 #endif /* gdevpdtb_INCLUDED */ 161