-
Notifications
You must be signed in to change notification settings - Fork 1
/
cid_mkmap.c
192 lines (166 loc) · 5.06 KB
/
cid_mkmap.c
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
cid_mkmap.c -- make array of glyph ids from cid
Copyright (C) 1999 Dieter Baron
This file is part of ttftot42, to use TrueType fonts in PostScript.
The author can be contacted at <[email protected]>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote
products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "t42.h"
struct cmap_feature {
TT_UShort sidx, lidx, fidx;
};
struct cmap_state {
int valid;
TT_CharMap cmap;
int nvert, nfeature;
struct cmap_feature *vert, feature;
};
#ifdef HAVE_GSUB
static int get_feature(font *f, struct cid_feature *feature,
struct cmap_feature *feat)
#endif
int
cid_mkmap(struct font *f, struct cid *cid, unsigned short **mapp)
{
struct cmap_state *state;
unsigned short *map;
int valid, v, flags;
int i, j, ncid;
#ifdef HAVE_GSUB
int k;
#endif
unsigned short pl, en;
state = (struct cmap_state *)xmalloc(sizeof(struct cmap_state)*cid->ncmap);
valid = 0;
for (i=0; i<cid->ncmap; i++) {
state[i].valid = 0;
for (j=0; j<f->ncmaps; j++) {
TT_Get_CharMap_ID(f->face, j, &pl, &en);
if ((pl == cid->cmap[i].pid && en == cid->cmap[i].eid)) {
if (TT_Get_CharMap(f->face, i, &state[i].cmap) == TT_Err_Ok)
valid = state[i].valid = 1;
break;
}
}
if (state[i].valid) {
cid_decode_init(cid->cmap[i].code);
#ifdef HAVE_GSUB
if (cid->cmap[i].nvert)
state[i].vert
= (struct cmap_feature *)xmalloc(sizeof(struct
cmap_feature)
* cid->cmap[i].nvert);
else
state[i].vert = NULL;
if (cid->cmap[i].nfeature)
state[i].feature
= (struct cmap_feature *)xmalloc(sizeof(struct
cmap_feature)
* cid->cmap[i].nfeature);
else
state[i].feature = NULL;
state[i].nvert = state[i].nfeature = 0;
for (k=0; k<cid->cmap[i].nvert; k++) {
if (get_feature(f->face,
cid->cmap[i].vert+k,
state[i].vert+state[i].nvert) == 0)
state[i].nvert++;
}
for (k=0; k<cid->cmap[i].nfeature; k++) {
if (get_feature(f->face,
cid->cmap[i].feature+k,
state[i].feature+state[i].nfeature) == 0)
state[i].nfeature++;
}
#endif /* HAVE_GSUB */
}
}
if (valid == 0) {
/* XXX: no suitable charmap found */
return -1;
}
map = (unsigned short *)xmalloc(sizeof(unsigned short)
* cid->supl_ncid[cid->supplement]);
ncid = 0;
for (i=0; i<cid->supl_ncid[cid->supplement]; i++) {
map[i] = 0;
for (j=0; j<cid->ncmap; j++) {
do {
flags = cid_decode(cid->cmap[j].code, &v);
if ((flags & CID_NENC) == 0 && state[j].valid && map[i] == 0) {
if ((v=TT_Char_Index(state[j].cmap, v)) != 0) {
/* XXX: apply vert & feature */
#ifdef HAVE_GSUB
if (flags & CID_VERT) {
v = apply_features(f, state[j].nvert,
state[j].vert, v);
}
v = apply_features(f, state[j].nfeature,
state[j].feature, v);
map[i] = v;
ncid = i;
#else /* HAVE_GSUB */
if (!(flags & CID_VERT)) {
map[i] = v;
ncid = i;
}
#endif
}
}
} while (flags & CID_ALT);
}
}
*mapp = map;
#ifdef HAVE_GSUB
for (i=0; i<cid->ncmap; i++) {
if (state[i].valid) {
free(state[i].vert);
free(state[i].feature);
}
}
#endif HAVE_GSUB
return ncid+1;
}
#ifdef HAVE_GSUB
static int
get_feature(font *f, struct cid_feature *feature, struct cmap_feature *feat)
{
if (TT_GSUB_Select_Script(f->gsub, feature->script, &feat->sidx))
return -1;
if (TT_GSUB_Select_Language(f->gsub, feature->language,
feat->sidx, &feat->lidx))
return -1;
if (TT_GSUB_Select_Feature(f->gsub, feature->feature,
feat->sidx, feat->lidx, &feat->fidx))
return -1;
return 0;
}
static int
apply_features(font *f, int n, struct cmap_feature *feat, int v)
{
/* XXX: FreeType 1.2 doesn't implement TTO_GSUB_Apply */
return v;
}
#endif /* HAVE_GSUB */