Skip to content

Commit

Permalink
Fix the Macintosh encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Feb 1, 2024
1 parent c8eb86b commit 1d50ea8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/tables/names/encoding/macintosh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ pub fn encode(
}
};
for character in value.chars() {
if let Some(value) = mapping.get(&character) {
data.push(*value);
if character as u16 <= 0x7F {
data.push(character as u8);
} else if let Some(value) = mapping.get(&character) {
data.push(*value | 0x80);
} else {
raise!("found an unknown Macintosh character ({character})")
}
Expand Down
17 changes: 17 additions & 0 deletions tests/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ mod open_sans {
#[test]
fn read() {
let table = ok!(Names::read(&mut setup!(OpenSans, "name")));
test(&table);
}

#[test]
fn write() {
let table = ok!(Names::read(&mut setup!(OpenSans, "name")));
let records = table.iter().map(|(ids, value)| (ids, ok!(value)));
let language_tags = table.language_tags().map(Option::unwrap);
let table = ok!(Names::from_iter(
records,
language_tags,
&mut Default::default(),
));
test(&table);
}

fn test(table: &Names) {
let records = table.iter().collect::<Vec<_>>();
let name_ids = records
.iter()
Expand Down

0 comments on commit 1d50ea8

Please sign in to comment.