2 * << Haru Free PDF Library >> -- hpdf_encoder.h
4 * URL: http://libharu.org
6 * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
7 * Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
9 * Permission to use, copy, modify, distribute and sell this software
10 * and its documentation for any purpose is hereby granted without fee,
11 * provided that the above copyright notice appear in all copies and
12 * that both that copyright notice and this permission notice appear
13 * in supporting documentation.
14 * It is provided "as is" without express or implied warranty.
18 #ifndef _HPDF_ENCODER_H
19 #define _HPDF_ENCODER_H
21 #include "hpdf_consts.h"
22 #include "hpdf_streams.h"
28 /*-- HPDF_Encoder ---------------------------------------*/
30 #define HPDF_ENCODER_SIG_BYTES 0x454E4344L
32 /*----------------------------------------------------------------------------*/
33 /*------ predefined font encodings -------------------------------------------*/
35 #define HPDF_ENCODING_FONT_SPECIFIC "FontSpecific"
36 #define HPDF_ENCODING_STANDARD "StandardEncoding"
37 #define HPDF_ENCODING_MAC_ROMAN "MacRomanEncoding"
38 #define HPDF_ENCODING_WIN_ANSI "WinAnsiEncoding"
39 #define HPDF_ENCODING_ISO8859_2 "ISO8859-2"
40 #define HPDF_ENCODING_ISO8859_3 "ISO8859-3"
41 #define HPDF_ENCODING_ISO8859_4 "ISO8859-4"
42 #define HPDF_ENCODING_ISO8859_5 "ISO8859-5"
43 #define HPDF_ENCODING_ISO8859_6 "ISO8859-6"
44 #define HPDF_ENCODING_ISO8859_7 "ISO8859-7"
45 #define HPDF_ENCODING_ISO8859_8 "ISO8859-8"
46 #define HPDF_ENCODING_ISO8859_9 "ISO8859-9"
47 #define HPDF_ENCODING_ISO8859_10 "ISO8859-10"
48 #define HPDF_ENCODING_ISO8859_11 "ISO8859-11"
49 #define HPDF_ENCODING_ISO8859_13 "ISO8859-13"
50 #define HPDF_ENCODING_ISO8859_14 "ISO8859-14"
51 #define HPDF_ENCODING_ISO8859_15 "ISO8859-15"
52 #define HPDF_ENCODING_ISO8859_16 "ISO8859-16"
53 #define HPDF_ENCODING_CP1250 "CP1250"
54 #define HPDF_ENCODING_CP1251 "CP1251"
55 #define HPDF_ENCODING_CP1252 "CP1252"
56 #define HPDF_ENCODING_CP1253 "CP1253"
57 #define HPDF_ENCODING_CP1254 "CP1254"
58 #define HPDF_ENCODING_CP1255 "CP1255"
59 #define HPDF_ENCODING_CP1256 "CP1256"
60 #define HPDF_ENCODING_CP1257 "CP1257"
61 #define HPDF_ENCODING_CP1258 "CP1258"
62 #define HPDF_ENCODING_KOI8_R "KOI8-R"
64 /*----------------------------------------------------------------------------*/
65 /*----- definition for font encoding -----------------------------------------*/
67 #define char_NOTDEF ".notdef"
69 typedef enum _HPDF_EncodingType {
70 HPDF_STANDARD_ENCODING = 0,
71 HPDF_MAC_ROMAN_ENCODING,
72 HPDF_WIN_ANSI_ENCODING,
78 typedef struct _HPDF_ParseText_Rec {
79 const HPDF_BYTE *text;
82 HPDF_ByteType byte_type;
86 typedef struct _HPDF_Encoder_Rec *HPDF_Encoder;
89 (*HPDF_Encoder_ByteType_Func) (HPDF_Encoder encoder,
90 HPDF_ParseText_Rec *state);
93 (*HPDF_Encoder_ToUnicode_Func) (HPDF_Encoder encoder,
98 (*HPDF_Encoder_Write_Func) (HPDF_Encoder encoder,
103 (*HPDF_Encoder_Init_Func) (HPDF_Encoder encoder);
107 (*HPDF_Encoder_Free_Func) (HPDF_Encoder encoder);
110 typedef struct _HPDF_Encoder_Rec {
111 HPDF_UINT32 sig_bytes;
112 char name[HPDF_LIMIT_MAX_NAME_LEN + 1];
115 HPDF_EncoderType type;
117 HPDF_Encoder_ByteType_Func byte_type_fn;
118 HPDF_Encoder_ToUnicode_Func to_unicode_fn;
119 HPDF_Encoder_Write_Func write_fn;
120 HPDF_Encoder_Free_Func free_fn;
121 HPDF_Encoder_Init_Func init_fn;
124 char country_code[3];
130 typedef enum _HPDF_BaseEncodings {
131 HPDF_BASE_ENCODING_STANDARD,
132 HPDF_BASE_ENCODING_WIN_ANSI,
133 HPDF_BASE_ENCODING_MAC_ROMAN,
134 HPDF_BASE_ENCODING_FONT_SPECIFIC,
135 HPDF_BASE_ENCODING_EOF
136 } HPDF_BaseEncodings;
139 HPDF_Encoder_Validate (HPDF_Encoder encoder);
142 HPDF_Encoder_SetParseText (HPDF_Encoder encoder,
143 HPDF_ParseText_Rec *state,
144 const HPDF_BYTE *text,
148 HPDF_Encoder_ByteType (HPDF_Encoder encoder,
149 HPDF_ParseText_Rec *state);
154 HPDF_Encoder_ToUnicode (HPDF_Encoder encoder,
159 HPDF_Encoder_Free (HPDF_Encoder encoder);
161 /*-- HPDF_BasicEncoder ----------------------------------*/
164 typedef struct _HPDF_BasicEncoderAttr_Rec *HPDF_BasicEncoderAttr;
166 typedef struct _HPDF_BasicEncoderAttr_Rec {
167 char base_encoding[HPDF_LIMIT_MAX_NAME_LEN + 1];
168 HPDF_BYTE first_char;
170 HPDF_UNICODE unicode_map[256];
171 HPDF_BOOL has_differences;
172 HPDF_BYTE differences[256];
173 } HPDF_BasicEncoderAttr_Rec;
177 HPDF_BasicEncoder_New (HPDF_MMgr mmgr,
178 const char *encoding_name);
182 HPDF_BasicEncoder_Free (HPDF_Encoder encoder);
186 HPDF_BasicEncoder_Write (HPDF_Encoder encoder,
191 HPDF_BasicEncoder_ToUnicode (HPDF_Encoder encoder,
194 /*-- HPDF_CMapEncoder ----------------------------------*/
197 (*HPDF_CMapEncoder_ByteType_Func) (HPDF_Encoder encoder,
200 typedef struct _HPDF_CidRange_Rec {
207 typedef struct _HPDF_UnicodeMap_Rec {
210 } HPDF_UnicodeMap_Rec;
212 typedef struct _HPDF_CMapEncoderAttr_Rec *HPDF_CMapEncoderAttr;
214 typedef struct _HPDF_CMapEncoderAttr_Rec {
215 HPDF_UNICODE unicode_map[256][256];
216 HPDF_UINT16 cid_map[256][256];
217 HPDF_UINT16 jww_line_head[HPDF_MAX_JWW_NUM];
218 HPDF_List cmap_range;
219 HPDF_List notdef_range;
220 HPDF_List code_space_range;
221 HPDF_WritingMode writing_mode;
222 char registry[HPDF_LIMIT_MAX_NAME_LEN + 1];
223 char ordering[HPDF_LIMIT_MAX_NAME_LEN + 1];
225 HPDF_CMapEncoder_ByteType_Func is_lead_byte_fn;
226 HPDF_CMapEncoder_ByteType_Func is_trial_byte_fn;
229 } HPDF_CMapEncoderAttr_Rec;
233 HPDF_CMapEncoder_New (HPDF_MMgr mmgr,
235 HPDF_Encoder_Init_Func init_fn);
239 HPDF_CMapEncoder_InitAttr (HPDF_Encoder encoder);
243 HPDF_CMapEncoder_Free (HPDF_Encoder encoder);
247 HPDF_CMapEncoder_Write (HPDF_Encoder encoder,
252 HPDF_CMapEncoder_ToUnicode (HPDF_Encoder encoder,
256 HPDF_CMapEncoder_ToCID (HPDF_Encoder encoder,
260 HPDF_CMapEncoder_SetParseText (HPDF_Encoder encoder,
261 HPDF_ParseText_Rec *state,
262 const HPDF_BYTE *text,
266 HPDF_CMapEncoder_ByteType (HPDF_Encoder encoder,
267 HPDF_ParseText_Rec *state);
271 HPDF_CMapEncoder_AddCMap (HPDF_Encoder encoder,
272 const HPDF_CidRange_Rec *range);
276 HPDF_CMapEncoder_AddNotDefRange (HPDF_Encoder encoder,
277 HPDF_CidRange_Rec range);
281 HPDF_CMapEncoder_AddCodeSpaceRange (HPDF_Encoder encoder,
282 HPDF_CidRange_Rec range);
286 HPDF_CMapEncoder_SetUnicodeArray (HPDF_Encoder encoder,
287 const HPDF_UnicodeMap_Rec *array1);
291 HPDF_CMapEncoder_AddJWWLineHead (HPDF_Encoder encoder,
292 const HPDF_UINT16 *code);
295 HPDF_Encoder_CheckJWWLineHead (HPDF_Encoder encoder,
296 const HPDF_UINT16 code);
298 /*-- utility functions ----------------------------------*/
301 HPDF_UnicodeToGryphName (HPDF_UNICODE unicode);
305 HPDF_GryphNameToUnicode (const char *gryph_name);
309 #endif /* __cplusplus */
311 #endif /* _HPDF_ENCODER_H */