@@ -154,13 +154,12 @@ pub fn write_font(
154
154
155
155
font_descriptor. finish ( ) ;
156
156
157
- let cmap = create_cmap ( & ttf, glyph_set, glyph_remapper) ;
157
+ let cmap =
158
+ create_cmap ( & ttf, glyph_set, glyph_remapper) . ok_or ( SubsetError ( font. id ) ) ?;
158
159
chunk. cmap ( cmap_ref, & cmap. finish ( ) ) ;
159
160
160
161
// Subset and write the font's bytes.
161
- let glyphs: Vec < _ > = glyph_set. keys ( ) . copied ( ) . collect ( ) ;
162
- let data = subset_font ( & font. face_data , font. face_index , & glyphs, font. id ) ?;
163
- let data = subset_font ( & font. face_data , font. face_index , & glyph_remapper) ;
162
+ let data = subset_font ( & font. face_data , font. face_index , glyph_remapper, font. id ) ?;
164
163
165
164
let mut stream = chunk. stream ( data_ref, & data) ;
166
165
stream. filter ( Filter :: FlateDecode ) ;
@@ -173,7 +172,11 @@ pub fn write_font(
173
172
}
174
173
175
174
/// Create a /ToUnicode CMap.
176
- fn create_cmap ( ttf : & Face , glyph_set : & mut BTreeMap < u16 , String > , glyph_remapper : & GlyphRemapper ) -> UnicodeCmap {
175
+ fn create_cmap (
176
+ ttf : & Face ,
177
+ glyph_set : & mut BTreeMap < u16 , String > ,
178
+ glyph_remapper : & GlyphRemapper ,
179
+ ) -> Option < UnicodeCmap > {
177
180
// For glyphs that have codepoints mapping to them in the font's cmap table,
178
181
// we prefer them over pre-existing text mappings from the document. Only
179
182
// things that don't have a corresponding codepoint (or only a private-use
@@ -200,24 +203,24 @@ fn create_cmap(ttf: &Face, glyph_set: &mut BTreeMap<u16, String>, glyph_remapper
200
203
// Produce a reverse mapping from glyphs' CIDs to unicode strings.
201
204
let mut cmap = UnicodeCmap :: new ( CMAP_NAME , SYSTEM_INFO ) ;
202
205
for ( & g, text) in glyph_set. iter ( ) {
203
- let new_gid = glyph_remapper. get ( g) . unwrap ( ) ;
206
+ let new_gid = glyph_remapper. get ( g) ? ;
204
207
if !text. is_empty ( ) {
205
208
cmap. pair_with_multiple ( new_gid, text. chars ( ) ) ;
206
209
}
207
210
}
208
211
209
- cmap
212
+ Some ( cmap)
210
213
}
211
214
212
215
fn subset_font (
213
216
font_data : & [ u8 ] ,
214
217
index : u32 ,
215
- glyphs : & [ u16 ] ,
218
+ glyph_remapper : & GlyphRemapper ,
216
219
id : fontdb:: ID ,
217
220
) -> Result < Vec < u8 > > {
218
- fn subset_font ( font_data : & [ u8 ] , index : u32 , glyph_remapper : & GlyphRemapper ) -> Vec < u8 > {
219
221
let data = font_data;
220
- let subsetted = subsetter:: subset ( data, index, glyph_remapper) . unwrap ( ) ;
222
+ let subsetted =
223
+ subsetter:: subset ( data, index, glyph_remapper) . map_err ( |_| SubsetError ( id) ) ?;
221
224
let mut data = subsetted. as_ref ( ) ;
222
225
223
226
// Extract the standalone CFF font program if applicable.
0 commit comments