~ubuntu-branches/ubuntu/jaunty/ghostscript/jaunty-updates

« back to all changes in this revision

Viewing changes to src/gxfcmap.h

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2009-01-20 16:40:45 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120164045-lnfhi0n30o5lwhwa
Tags: 8.64.dfsg.1~svn9377-0ubuntu1
* New upstream release (SVN rev 9377)
   o Fixes many bugs concerning PDF rendering, to make the PDF printing
     workflow correctly working.
   o Fixes long-standing bugs in many drivers, like input paper tray and
     duplex options not working for the built-in PCL 4, 5, 5c, 5e, and
     6/XL drivers, PDF input not working for bjc600, bjc800, and cups
     output devices, several options not working and uninitialized
     memory with cups output device.
   o Merged nearly all patches of the Ubuntu and Debian packages upstream.
   o Fixes LP: #317810, LP: #314439, LP: #314018.
* debian/patches/03_libpaper_support.dpatch,
  debian/patches/11_gs-cjk_font_glyph_handling_fix.dpatch,
  debian/patches/12_gs-cjk_vertical_writing_metrics_fix.dpatch,
  debian/patches/13_gs-cjk_cjkps_examples.dpatch,
  debian/patches/20_bbox_segv_fix.dpatch,
  debian/patches/21_brother_7x0_gdi_fix.dpatch,
  debian/patches/22_epsn_margin_workaround.dpatch,
  debian/patches/24_gs_man_fix.dpatch,
  debian/patches/25_toolbin_insecure_tmp_usage_fix.dpatch,
  debian/patches/26_assorted_script_fixes.dpatch,
  debian/patches/29_gs_css_fix.dpatch,
  debian/patches/30_ps2pdf_man_improvement.dpatch,
  debian/patches/31_fix-gc-sigbus.dpatch,
  debian/patches/34_ftbfs-on-hurd-fix.dpatch,
  debian/patches/35_disable_libcairo.dpatch,
  debian/patches/38_pxl-duplex.dpatch,
  debian/patches/39_pxl-resolution.dpatch,
  debian/patches/42_gs-init-ps-delaybind-fix.dpatch,
  debian/patches/45_bjc600-bjc800-pdf-input.dpatch,
  debian/patches/48_cups-output-device-pdf-duplex-uninitialized-memory-fix.dpatch,
  debian/patches/50_lips4-floating-point-exception.dpatch,
  debian/patches/52_cups-device-logging.dpatch,
  debian/patches/55_pcl-input-slot-fix.dpatch,
  debian/patches/57_pxl-input-slot-fix.dpatch,
  debian/patches/60_pxl-cups-driver-pdf.dpatch,
  debian/patches/62_onebitcmyk-pdf.dpatch,
  debian/patches/65_too-big-temp-files-1.dpatch,
  debian/patches/67_too-big-temp-files-2.dpatch,
  debian/patches/70_take-into-account-data-in-stream-buffer-before-refill.dpatch:
  Removed, applied upstream.
* debian/patches/01_docdir_fix_for_debian.dpatch,
  debian/patches/02_gs_man_fix_debian.dpatch,
  debian/patches/01_docdir-fix-for-debian.dpatch,
  debian/patches/02_docdir-fix-for-debian.dpatch: Renamed patches to
  make merging with Debian easier.
* debian/patches/32_improve-handling-of-media-size-changes-from-gv.dpatch, 
  debian/patches/33_bad-params-to-xinitimage-on-large-bitmaps.dpatch:
  regenerated for new source directory structure.
* debian/rules: Corrected paths to remove cidfmap (it is in Resource/Init/
  in GS 8.64) and to install headers (source paths are psi/ and base/ now).
* debian/rules: Remove all fontmaps, as DeFoMa replaces them.
* debian/local/pdftoraster/pdftoraster.c,
  debian/local/pdftoraster/pdftoraster.convs, debian/rules: Removed
  added pdftoraster filter and use the one which comes with Ghostscript.
* debian/ghostscript.links: s/8.63/8.64/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2001-2006 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, modified
8
 
   or distributed except as expressly authorized under the terms of that
9
 
   license.  Refer to licensing information at http://www.artifex.com/
10
 
   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11
 
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
 
*/
13
 
 
14
 
/* $Id: gxfcmap.h 8022 2007-06-05 22:23:38Z giles $ */
15
 
/* Internal CMap structure definitions */
16
 
 
17
 
/* This file should be called gxcmap.h, except that name is already used. */
18
 
 
19
 
#ifndef gxfcmap_INCLUDED
20
 
#  define gxfcmap_INCLUDED
21
 
 
22
 
#include "gsfcmap.h"
23
 
#include "gsuid.h"
24
 
#include "gxcid.h"
25
 
 
26
 
/*
27
 
 * CMaps are the structures that map (possibly variable-length) characters
28
 
 * appearing in a text string to glyph numbers in some font-specific space.
29
 
 * The structure defined here generally follows Adobe's specifications, but
30
 
 * the actual implementation of the code space and the lookup tables is
31
 
 * virtual, so that the same interface can be used for direct access to the
32
 
 * corresponding "cmap" structure in TrueType fonts, rather than having to
33
 
 * convert that structure to the Adobe-based one.
34
 
 */
35
 
 
36
 
/*
37
 
 * A CMap conceptually consists of three parts:
38
 
 *
39
 
 *      - The code space, used for parsing the input string into (possibly
40
 
 *        variable-length) characters.
41
 
 *
42
 
 *      - A 'def' map, which maps defined parsed characters to values.
43
 
 *
44
 
 *      - A 'notdef' map, which maps parsed but undefined characters to
45
 
 *        values.
46
 
 *
47
 
 * The value of a character may be a string, a name, or a CID.  For more
48
 
 * information, see the Adobe documentation.
49
 
 */
50
 
 
51
 
/* ---------------- Code space ranges ---------------- */
52
 
 
53
 
/*
54
 
 * A code space is a non-empty, lexicographically sorted sequence of
55
 
 * code space ranges.  Ranges must not overlap.  In each range,
56
 
 * first[i] <= last[i] for 0 <= i < size.
57
 
 */
58
 
#define MAX_CMAP_CODE_SIZE 4
59
 
typedef struct gx_code_space_range_s {
60
 
    byte first[MAX_CMAP_CODE_SIZE];
61
 
    byte last[MAX_CMAP_CODE_SIZE];
62
 
    int size;                   /* 1 .. MAX_CMAP_CODE_SIZE */
63
 
} gx_code_space_range_t;
64
 
 
65
 
/* ---------------- Lookup tables ---------------- */
66
 
 
67
 
/*
68
 
 * A lookup table is a non-empty sequence of lookup ranges.  Each range has
69
 
 * an associated sorted lookup table, indexed by the num_key_bytes low-order
70
 
 * code bytes.  If key_is_range is true, each key is a range (2 x key_size
71
 
 * bytes); if false, each key is a single code (key_size bytes).
72
 
 *
73
 
 * The only difference between CODE_VALUE_CID and CODE_VALUE_NOTDEF is
74
 
 * that after looking up a CID in a table, for CODE_VALUE_CID the result
75
 
 * is incremented by the difference between the input code and the key
76
 
 * (i.e., a single CODE_VALUE_CID entry actually represents a range of
77
 
 * CIDs), whereas for CODE_VALUE_NOTDEF, the result is not incremented.
78
 
 * The defined-character map for a CMap uses the former behavior; the
79
 
 * notdef map uses the latter.
80
 
 *
81
 
 * CODE_VALUE_GLYPH and CODE_VALUE_CHARS are reserved for
82
 
 * rearranged font CMaps, which are not implemented yet.
83
 
 */
84
 
typedef enum {
85
 
    CODE_VALUE_CID,             /* CIDs */
86
 
    CODE_VALUE_GLYPH,           /* glyphs */
87
 
    CODE_VALUE_CHARS,           /* character(s) */
88
 
    CODE_VALUE_NOTDEF           /* CID - for notdef(char|range) dst */
89
 
#define CODE_VALUE_MAX CODE_VALUE_NOTDEF
90
 
} gx_cmap_code_value_type_t;
91
 
typedef struct gx_cmap_lookup_entry_s {
92
 
    /* Key */
93
 
    byte key[2][MAX_CMAP_CODE_SIZE]; /* [key_is_range + 1][key_size] */
94
 
    int key_size;               /* 0 .. MAX_CMAP_CODE_SIZE */
95
 
    bool key_is_range;
96
 
    /* Value */
97
 
    gx_cmap_code_value_type_t value_type;
98
 
    gs_const_string value;
99
 
    int font_index;             /* for rearranged fonts */
100
 
} gx_cmap_lookup_entry_t;
101
 
 
102
 
/* ---------------- CMaps proper ---------------- */
103
 
 
104
 
/*
105
 
 * Define the elements common to all CMaps.  Currently we include all
106
 
 * elements from the Adobe specification except for the actual code space
107
 
 * ranges and lookup tables.
108
 
 *
109
 
 * CMapType and id are common to all CMapTypes.  We really only support the
110
 
 * single Adobe standard CMap format.  Note that the only documented values
111
 
 * of CMapType in the PLRM are 0 and 1, which are equivalent; however, in
112
 
 * the second PDF Reference, the CMapType for the example ToUnicode CMap is
113
 
 * 2.
114
 
 *
115
 
 * glyph_name and glyph_name_data are only used if the CMap has lookup
116
 
 * entries of type CODE_VALUE_GLYPH.  We deliberately chose to make
117
 
 * glyph_name a function pointer rather than including it in the procs
118
 
 * virtual functions.  The rationale is that the virtual functions are
119
 
 * dependent on the representation of the CMap, so they should be set by the
120
 
 * code that must work with this structure.  However, glyph_name is not
121
 
 * dependent on the representation of the CMap: it does not need to know
122
 
 * anything about how the CMap is stored.  Rather, it is meant to be used by
123
 
 * the client who constructs the CMap, who decides how stored
124
 
 * CODE_VALUE_GLYPH values correspond to printable glyph names.  The same
125
 
 * glyph_name procedure can, in principle, be used with multiple different
126
 
 * subclasses of gs_cmap_t.
127
 
 */
128
 
#ifndef gs_cmap_DEFINED
129
 
#  define gs_cmap_DEFINED
130
 
typedef struct gs_cmap_s gs_cmap_t;
131
 
#endif
132
 
 
133
 
#define GS_CMAP_COMMON\
134
 
    int CMapType;               /* must be first */\
135
 
    gs_id id;                   /* internal ID (no relation to UID) */\
136
 
        /* End of entries common to all CMapTypes */\
137
 
    gs_const_string CMapName;\
138
 
    gs_cid_system_info_t *CIDSystemInfo; /* [num_fonts] */\
139
 
    int num_fonts;\
140
 
    float CMapVersion;\
141
 
    gs_uid uid;                 /* XUID or nothing */\
142
 
    long UIDOffset;\
143
 
    int WMode;\
144
 
    bool from_Unicode;          /* if true, characters are Unicode */\
145
 
    bool ToUnicode;             /* if true, it is a ToUnicode CMap */\
146
 
    gs_glyph_name_proc_t glyph_name;  /* glyph name procedure for printing */\
147
 
    void *glyph_name_data;      /* closure data */\
148
 
    const gs_cmap_procs_t *procs
149
 
 
150
 
extern_st(st_cmap);
151
 
#define public_st_cmap()        /* in gsfcmap.c */\
152
 
  BASIC_PTRS(cmap_ptrs) {\
153
 
    GC_CONST_STRING_ELT(gs_cmap_t, CMapName),\
154
 
    GC_OBJ_ELT3(gs_cmap_t, CIDSystemInfo, uid.xvalues, glyph_name_data)\
155
 
  };\
156
 
  gs_public_st_basic(st_cmap, gs_cmap_t, "gs_cmap_t", cmap_ptrs, cmap_data)
157
 
 
158
 
typedef struct gs_cmap_ranges_enum_s gs_cmap_ranges_enum_t;
159
 
typedef struct gs_cmap_lookups_enum_s gs_cmap_lookups_enum_t;
160
 
 
161
 
typedef struct gs_cmap_procs_s {
162
 
 
163
 
    /*
164
 
     * Decode and map a character from a string using a CMap.
165
 
     * See gsfcmap.h for details.
166
 
     */
167
 
 
168
 
    int (*decode_next)(const gs_cmap_t *pcmap, const gs_const_string *str,
169
 
                       uint *pindex, uint *pfidx,
170
 
                       gs_char *pchr, gs_glyph *pglyph);
171
 
 
172
 
    /*
173
 
     * Initialize an enumeration of code space ranges.  See below.
174
 
     */
175
 
 
176
 
    void (*enum_ranges)(const gs_cmap_t *pcmap,
177
 
                        gs_cmap_ranges_enum_t *penum);
178
 
 
179
 
    /*
180
 
     * Initialize an enumeration of lookups.  See below.
181
 
     */
182
 
 
183
 
    void (*enum_lookups)(const gs_cmap_t *pcmap, int which,
184
 
                         gs_cmap_lookups_enum_t *penum);
185
 
 
186
 
    /*
187
 
     * Check if the cmap is identity.
188
 
     */
189
 
 
190
 
    bool (*is_identity)(const gs_cmap_t *pcmap, int font_index_only);
191
 
 
192
 
} gs_cmap_procs_t;
193
 
 
194
 
struct gs_cmap_s {
195
 
    GS_CMAP_COMMON;
196
 
};
197
 
 
198
 
/* ---------------- Enumerators ---------------- */
199
 
 
200
 
/*
201
 
 * Define enumeration structures for code space ranges and lookup tables.
202
 
 * Since all current and currently envisioned implementations are very
203
 
 * simple, we don't bother to make this fully general, with subclasses
204
 
 * or a "finish" procedure.
205
 
 */
206
 
typedef struct gs_cmap_ranges_enum_procs_s {
207
 
    int (*next_range)(gs_cmap_ranges_enum_t *penum);
208
 
} gs_cmap_ranges_enum_procs_t;
209
 
struct gs_cmap_ranges_enum_s {
210
 
    /*
211
 
     * Return the next code space range here.
212
 
     */
213
 
    gx_code_space_range_t range;
214
 
    /*
215
 
     * The rest of the information is private to the implementation.
216
 
     */
217
 
    const gs_cmap_t *cmap;
218
 
    const gs_cmap_ranges_enum_procs_t *procs;
219
 
    uint index;
220
 
};
221
 
 
222
 
typedef struct gs_cmap_lookups_enum_procs_s {
223
 
    int (*next_lookup)(gs_cmap_lookups_enum_t *penum);
224
 
    int (*next_entry)(gs_cmap_lookups_enum_t *penum);
225
 
} gs_cmap_lookups_enum_procs_t;
226
 
struct gs_cmap_lookups_enum_s {
227
 
    /*
228
 
     * Return the next lookup and entry here.
229
 
     */
230
 
    gx_cmap_lookup_entry_t entry;
231
 
    /*
232
 
     * The rest of the information is private to the implementation.
233
 
     */
234
 
    const gs_cmap_t *cmap;
235
 
    const gs_cmap_lookups_enum_procs_t *procs;
236
 
    uint index[2];
237
 
    byte temp_value[max(sizeof(gs_glyph), sizeof(gs_char))];
238
 
};
239
 
/*
240
 
 * Define a vacuous next_lookup procedure, useful for the notdef lookups
241
 
 * for CMaps that don't have any.
242
 
 */
243
 
extern const gs_cmap_lookups_enum_procs_t gs_cmap_no_lookups_procs;
244
 
 
245
 
/* ---------------- Client procedures ---------------- */
246
 
 
247
 
/*
248
 
 * Initialize the enumeration of the code space ranges, and enumerate
249
 
 * the next range.  enum_next returns 0 if OK, 1 if finished, <0 if error.
250
 
 * The intended usage is:
251
 
 *
252
 
 *      for (gs_cmap_ranges_enum_init(pcmap, &renum);
253
 
 *           (code = gs_cmap_enum_next_range(&renum)) == 0; ) {
254
 
 *          ...
255
 
 *      }
256
 
 *      if (code < 0) <<error>>
257
 
 */
258
 
void gs_cmap_ranges_enum_init(const gs_cmap_t *pcmap,
259
 
                              gs_cmap_ranges_enum_t *penum);
260
 
int gs_cmap_enum_next_range(gs_cmap_ranges_enum_t *penum);
261
 
 
262
 
/*
263
 
 * Initialize the enumeration of the lookups, and enumerate the next
264
 
 * the next lookup or entry.  which = 0 for defined characters,
265
 
 * which = 1 for notdef.  next_xxx returns 0 if OK, 1 if finished,
266
 
 * <0 if error.  The intended usage is:
267
 
 *
268
 
 *      for (gs_cmap_lookups_enum_init(pcmap, which, &lenum);
269
 
 *           (code = gs_cmap_enum_next_lookup(&lenum)) == 0; ) {
270
 
 *          while ((code = gs_cmap_enum_next_entry(&lenum)) == 0) {
271
 
 *              ...
272
 
 *          }
273
 
 *          if (code < 0) <<error>>
274
 
 *      }
275
 
 *      if (code < 0) <<error>>
276
 
 *
277
 
 * Note that next_lookup sets (at least) penum->entry.
278
 
 *      key_size, key_is_range, value_type, font_index
279
 
 * whereas next_entry sets penum->entry.
280
 
 *      key[0][*], key[1][*], value
281
 
 * Clients must not modify any members of the enumerator.
282
 
 * The bytes of the value string may be allocated locally (in the enumerator
283
 
 * itself) and not survive from one call to the next.
284
 
 */
285
 
void gs_cmap_lookups_enum_init(const gs_cmap_t *pcmap, int which,
286
 
                               gs_cmap_lookups_enum_t *penum);
287
 
int gs_cmap_enum_next_lookup(gs_cmap_lookups_enum_t *penum);
288
 
int gs_cmap_enum_next_entry(gs_cmap_lookups_enum_t *penum);
289
 
 
290
 
/* ---------------- Implementation procedures ---------------- */
291
 
 
292
 
/*
293
 
 * Initialize a just-allocated CMap, to ensure that all pointers are clean
294
 
 * for the GC.  Note that this only initializes the common part.
295
 
 */
296
 
void gs_cmap_init(const gs_memory_t *mem, gs_cmap_t *pcmap, int num_fonts);
297
 
 
298
 
/*
299
 
 * Allocate and initialize (the common part of) a CMap.
300
 
 */
301
 
int gs_cmap_alloc(gs_cmap_t **ppcmap, const gs_memory_struct_type_t *pstype,
302
 
                  int wmode, const byte *map_name, uint name_size,
303
 
                  const gs_cid_system_info_t *pcidsi, int num_fonts,
304
 
                  const gs_cmap_procs_t *procs, gs_memory_t *mem);
305
 
 
306
 
/*
307
 
 * Initialize an enumerator with convenient defaults (index = 0).
308
 
 */
309
 
void gs_cmap_ranges_enum_setup(gs_cmap_ranges_enum_t *penum,
310
 
                               const gs_cmap_t *pcmap,
311
 
                               const gs_cmap_ranges_enum_procs_t *procs);
312
 
void gs_cmap_lookups_enum_setup(gs_cmap_lookups_enum_t *penum,
313
 
                                const gs_cmap_t *pcmap,
314
 
                                const gs_cmap_lookups_enum_procs_t *procs);
315
 
 
316
 
/* 
317
 
 * Check for identity CMap. Uses a fast check for special cases.
318
 
 */
319
 
bool gs_cmap_is_identity(const gs_cmap_t *pcmap, int font_index_only);
320
 
 
321
 
/* 
322
 
 * For a random CMap, compute whether it is identity.
323
 
 * It is not applicable to gs_cmap_ToUnicode_t due to
324
 
 * different sizes of domain keys and range values.
325
 
 */
326
 
bool gs_cmap_compute_identity(const gs_cmap_t *pcmap, int font_index_only);
327
 
 
328
 
#endif /* gxfcmap_INCLUDED */