From bef209f31bf4c54ba53e8b19f1799701a654708d Mon Sep 17 00:00:00 2001 From: Laurenz Stampfl Date: Sun, 19 May 2024 08:38:23 +0200 Subject: [PATCH] Don't write local subroutines --- run.sh | 4 ++-- src/cff/dict/private_dict.rs | 7 +------ src/cff/mod.rs | 14 ++++++++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/run.sh b/run.sh index 63acec99..90f9de1f 100755 --- a/run.sh +++ b/run.sh @@ -1,7 +1,7 @@ FONT="fonts/NotoSansCJKsc-Regular.otf" -GIDS="9987" +GIDS="0,1,2698,3950,4059,8509,14538,38945" -fonttools subset $FONT --drop-tables=GSUB,GPOS,GDEF,FFTM,vhea,vmtx,DSIG,VORG,hdmx \ +fonttools subset $FONT --drop-tables=GSUB,GPOS,GDEF,FFTM,vhea,vmtx,DSIG,VORG,hdmx,cmap \ --gids=$GIDS --glyph-names --desubroutinize --output-file=out_ft.otf \ --notdef-outline --no-prune-unicode-ranges --no-prune-codepage-ranges && fonttools ttx -f -o out_ft.xml out_ft.otf && diff --git a/src/cff/dict/private_dict.rs b/src/cff/dict/private_dict.rs index 39516a9d..6e253c26 100644 --- a/src/cff/dict/private_dict.rs +++ b/src/cff/dict/private_dict.rs @@ -58,12 +58,7 @@ pub fn write_private_dicts( while let Some(operator) = dict_parser.parse_next() { match operator { SUBRS => { - let mut w = Writer::new(); - let offset = font_write_context.lsubrs_offsets.as_i32() - - private_dict_offset as i32; - w.write(IntegerNumber::from_i32_as_int5(offset).as_bytes()); - - write(&w.finish(), SUBRS.as_bytes()); + // We don't have any subroutines } _ => { dict_parser.parse_operands().unwrap(); diff --git a/src/cff/mod.rs b/src/cff/mod.rs index 1dc78a17..ffff8f4d 100644 --- a/src/cff/mod.rs +++ b/src/cff/mod.rs @@ -94,13 +94,13 @@ pub fn subset<'a>(ctx: &mut Context<'a>) -> Result<()> { SubroutineCollection::new(subroutines) }; - let mut fd_remapper = FontDictRemapper::new(); + let mut used_fds = BTreeSet::new(); let sid_remapper = get_sid_remapper(&table); let mut char_strings = vec![]; for old_gid in ctx.mapper.old_gids() { let fd_index = table.cid_metadata.fd_select.font_dict_index(old_gid).unwrap(); - fd_remapper.remap(fd_index); + used_fds.insert(fd_index); let mut decompiler = Decompiler::new( gsubrs.get_handler(), @@ -110,6 +110,12 @@ pub fn subset<'a>(ctx: &mut Context<'a>) -> Result<()> { char_strings.push(decompiler.decompile(charstring)?); } + let mut fd_remapper = FontDictRemapper::new(); + + for fd in used_fds { + fd_remapper.remap(fd); + } + let mut font_write_context = FontWriteContext::new(fd_remapper.len()); let mut subsetted_font = vec![]; @@ -134,7 +140,7 @@ pub fn subset<'a>(ctx: &mut Context<'a>) -> Result<()> { w.extend(&write_sids(&sid_remapper, table.strings).unwrap()); // Global Subr INDEX // Note: We desubroutinized, so no global subroutines and thus empty index. - w.extend(&create_index(vec![vec![]]).unwrap()); + w.extend(&create_index(vec![]).unwrap()); font_write_context.charset_offset = IntegerNumber::from_i32_as_int5(w.len() as i32); @@ -176,7 +182,7 @@ pub fn subset<'a>(ctx: &mut Context<'a>) -> Result<()> { // Again, always empty since we desubroutinize. font_write_context.lsubrs_offsets = IntegerNumber::from_i32_as_int5(w.len() as i32); - w.extend(&create_index(vec![vec![]])?); + w.extend(&create_index(vec![])?); subsetted_font = w.finish(); }