Skip to content

Commit

Permalink
Improve name handling
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed May 23, 2024
1 parent e169945 commit ca0a993
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/fuzz.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand_distr::Distribution;
use std::ffi::OsStr;
use std::fs;
use std::path::{Path, PathBuf};
use std::path::Path;

use rand::distributions::WeightedIndex;
use rand::prelude::{IteratorRandom, ThreadRng};
Expand Down
8 changes: 4 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FONT="/Users/lstampfl/Desktop/fonts-main/ofl/recursive/Recursive[CASL,CRSV,MONO,slnt,wght].ttf"
GIDS="822"
FONT="/Users/lstampfl/Desktop/fonts-main/ofl/phetsarath/Phetsarath-Regular.ttf"
GIDS="107"

# Run normally

Expand All @@ -11,8 +11,8 @@ fonttools ttx -f -o out_ft.xml out_ft.otf
cargo run -- $FONT out_ss.otf $GIDS &&
fonttools ttx -f -o out_ss.xml out_ss.otf

hb-subset $FONT --desubroutinize --gids=$GIDS --output-file=out_hb.otf &&
fonttools ttx -f -o out_hb.xml out_hb.otf
#hb-subset $FONT --desubroutinize --gids=$GIDS --output-file=out_hb.otf &&
#fonttools ttx -f -o out_hb.xml out_hb.otf

# Bench against hb-subset
#time ./target/release/subsetter $FONT out_ss.otf $GIDS
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,17 @@ fn _subset(mut ctx: Context) -> Result<(Vec<u8>, GlyphRemapper)> {
ctx.process(Tag::CFF)?;
}

println!("reached");

// Required tables.
ctx.process(Tag::HEAD)?;
ctx.process(Tag::HMTX)?;
ctx.process(Tag::MAXP)?;
ctx.process(Tag::NAME)?;
ctx.process(Tag::OS2)?;
ctx.process(Tag::POST)?;
println!("reached2");


Ok(construct(ctx))
}
Expand Down
4 changes: 3 additions & 1 deletion src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ pub fn subset(ctx: &mut Context) -> Result<()> {
sub_post.write(index);
} else {
let index = index - 258;
let name = *names.get(index as usize).ok_or(MalformedFont)?;
// Phetsarath-Regular.ttf from Google Fonts seems to have a wrong name table.
// If name cannot be fetched, use empty name instead.
let name = names.get(index as usize).copied().unwrap_or(&[][..]);
let name_len = u8::try_from(name.len()).map_err(|_| MalformedFont)?;
let index = u16::try_from(string_index + 258).map_err(|_| SubsetError)?;
sub_post.write(index);
Expand Down

0 comments on commit ca0a993

Please sign in to comment.