Skip to content

Commit

Permalink
generated .notdef glyph should be left unmapped
Browse files Browse the repository at this point in the history
https://learn.microsoft.com/en-us/typography/opentype/spec/cmap#overview

'Regardless of the encoding scheme, character codes that do not correspond to any glyph in the font should be mapped to glyph index 0. The glyph at this location must be a special glyph representing a missing character, commonly known as .notdef.'
  • Loading branch information
anthrotype committed Sep 5, 2023
1 parent da4fd2a commit 2dba808
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions fontc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,6 @@ mod tests {
.collect();
assert_eq!(
vec![
(0x0000, 0),
(0x002C, 2),
(0x002E, 1),
(0x0030, 3),
Expand Down Expand Up @@ -1288,10 +1287,12 @@ mod tests {
let buf = fs::read(font_file).unwrap();
let font = FontRef::new(&buf).unwrap();

assert_eq!(
GlyphId::new(0),
font.cmap().unwrap().map_codepoint(0u32).unwrap()
);
// Character 0x0000 (NULL) != '.notdef' glyph, and neither are any other
// characters actually, because '.notdef' (glyph index 0) means the absence
// of a character-to-glyph mapping:
// https://github.com/googlefonts/fontc/pull/423/files#r1309257127
// https://learn.microsoft.com/en-us/typography/opentype/spec/cmap#overview
assert_eq!(None, font.cmap().unwrap().map_codepoint(0u32));
}

#[test]
Expand All @@ -1312,13 +1313,12 @@ mod tests {

assert_eq!(
vec![
GlyphId::new(0),
GlyphId::new(1),
GlyphId::new(2),
GlyphId::new(3),
GlyphId::new(6),
],
[0x00, 0x20, 0x21, 0x2d, 0x3d]
[0x20, 0x21, 0x2d, 0x3d]
.iter()
.map(|cp| font.cmap().unwrap().map_codepoint(*cp as u32).unwrap())
.collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion fontir/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ impl GlyphBuilder {

Self {
name: GlyphName::NOTDEF.clone(),
codepoints: HashSet::from([0]),
codepoints: HashSet::new(),
sources: HashMap::from([(
default_location,
GlyphInstance {
Expand Down

0 comments on commit 2dba808

Please sign in to comment.