1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
#include "fitz.h"
#include "mupdf.h"
/*
* Load CMap stream in PDF file
*/
fz_error
pdf_load_embedded_cmap(pdf_cmap **cmapp, pdf_xref *xref, fz_obj *stmobj)
{
fz_error error = fz_okay;
fz_stream *file = NULL;
pdf_cmap *cmap = NULL;
pdf_cmap *usecmap;
fz_obj *wmode;
fz_obj *obj;
if ((*cmapp = pdf_find_item(xref->store, pdf_drop_cmap, stmobj)))
{
pdf_keep_cmap(*cmapp);
return fz_okay;
}
pdf_log_font("load embedded cmap (%d %d R) {\n", fz_to_num(stmobj), fz_to_gen(stmobj));
error = pdf_open_stream(&file, xref, fz_to_num(stmobj), fz_to_gen(stmobj));
if (error)
{
error = fz_rethrow(error, "cannot open cmap stream (%d %d R)", fz_to_num(stmobj), fz_to_gen(stmobj));
goto cleanup;
}
error = pdf_parse_cmap(&cmap, file);
if (error)
{
error = fz_rethrow(error, "cannot parse cmap stream (%d %d R)", fz_to_num(stmobj), fz_to_gen(stmobj));
goto cleanup;
}
fz_close(file);
wmode = fz_dict_gets(stmobj, "WMode");
if (fz_is_int(wmode))
{
pdf_log_font("wmode %d\n", wmode);
pdf_set_wmode(cmap, fz_to_int(wmode));
}
obj = fz_dict_gets(stmobj, "UseCMap");
if (fz_is_name(obj))
{
pdf_log_font("usecmap /%s\n", fz_to_name(obj));
error = pdf_load_system_cmap(&usecmap, fz_to_name(obj));
if (error)
{
error = fz_rethrow(error, "cannot load system usecmap '%s'", fz_to_name(obj));
goto cleanup;
}
pdf_set_usecmap(cmap, usecmap);
pdf_drop_cmap(usecmap);
}
else if (fz_is_indirect(obj))
{
pdf_log_font("usecmap (%d %d R)\n", fz_to_num(obj), fz_to_gen(obj));
error = pdf_load_embedded_cmap(&usecmap, xref, obj);
if (error)
{
error = fz_rethrow(error, "cannot load embedded usecmap (%d %d R)", fz_to_num(obj), fz_to_gen(obj));
goto cleanup;
}
pdf_set_usecmap(cmap, usecmap);
pdf_drop_cmap(usecmap);
}
pdf_log_font("}\n");
pdf_store_item(xref->store, pdf_keep_cmap, pdf_drop_cmap, stmobj, cmap);
*cmapp = cmap;
return fz_okay;
cleanup:
if (file)
fz_close(file);
if (cmap)
pdf_drop_cmap(cmap);
return error; /* already rethrown */
}
/*
* Create an Identity-* CMap (for both 1 and 2-byte encodings)
*/
pdf_cmap *
pdf_new_identity_cmap(int wmode, int bytes)
{
pdf_cmap *cmap = pdf_new_cmap();
sprintf(cmap->cmap_name, "Identity-%c", wmode ? 'V' : 'H');
pdf_add_codespace(cmap, 0x0000, 0xffff, bytes);
pdf_map_range_to_range(cmap, 0x0000, 0xffff, 0);
pdf_sort_cmap(cmap);
pdf_set_wmode(cmap, wmode);
return cmap;
}
/*
* Load predefined CMap from system.
*/
fz_error
pdf_load_system_cmap(pdf_cmap **cmapp, char *cmap_name)
{
fz_error error;
pdf_cmap *usecmap;
pdf_cmap *cmap;
int i;
pdf_log_font("loading system cmap %s\n", cmap_name);
for (i = 0; pdf_cmap_table[i]; i++)
{
if (!strcmp(cmap_name, pdf_cmap_table[i]->cmap_name))
{
cmap = pdf_cmap_table[i];
if (cmap->usecmap_name[0] && !cmap->usecmap)
{
error = pdf_load_system_cmap(&usecmap, cmap->usecmap_name);
if (error)
return fz_rethrow(error, "cannot load usecmap: %s", cmap->usecmap_name);
pdf_set_usecmap(cmap, usecmap);
}
*cmapp = cmap;
return fz_okay;
}
}
return fz_throw("no builtin cmap file: %s", cmap_name);
}
|