Skip to content

Commit

Permalink
Don't write local subroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed May 19, 2024
1 parent 8869b07 commit bef209f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
@@ -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 &&
Expand Down
7 changes: 1 addition & 6 deletions src/cff/dict/private_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 10 additions & 4 deletions src/cff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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![];

Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit bef209f

Please sign in to comment.