From 777d5f286f1ee06b05af2bc39e4046f1f9c2b4be Mon Sep 17 00:00:00 2001 From: Ana Gelez Date: Wed, 17 Apr 2024 14:31:33 +0200 Subject: [PATCH] Introduce UnicodeCmap::new_with_dimension to not break the public API --- src/font.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/font.rs b/src/font.rs index 6d2c961..3b27437 100644 --- a/src/font.rs +++ b/src/font.rs @@ -658,12 +658,22 @@ pub struct UnicodeCmap { mappings: Vec, count: i32, /// Are the glyphs IDs represented using one byte only? - byte_gids: bool, + one_byte_gids: bool, } impl UnicodeCmap { /// Create a new, empty unicode character map. - pub fn new(name: Name, info: SystemInfo, byte_gids: bool) -> Self { + pub fn new(name: Name, info: SystemInfo) -> Self { + Self::new_with_dimension(name, info, false) + } + + /// Create a new, empty unicode character map, that supports either one-byte + /// or two-bytes glyph IDs. + /// + /// Most fonts will use two bytes, but for Type3 fonts (which can only contain + /// up to 256 glyphs) some readers (Adobe Acrobat) will only accept one-byte + /// glyph IDs. + pub fn new_with_dimension(name: Name, info: SystemInfo, one_byte_gids: bool) -> Self { // https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5014.CIDFont_Spec.pdf let mut buf = Vec::new(); @@ -712,14 +722,14 @@ impl UnicodeCmap { // We just cover the whole unicode codespace. buf.extend(b"1 begincodespacerange\n"); - if byte_gids { + if one_byte_gids { buf.extend(b"<00> \n"); } else { buf.extend(b"<0000> \n"); } buf.extend(b"endcodespacerange\n"); - Self { buf, mappings: vec![], count: 0, byte_gids } + Self { buf, mappings: vec![], count: 0, one_byte_gids } } /// Add a mapping from a glyph ID to a codepoint. @@ -734,7 +744,7 @@ impl UnicodeCmap { codepoints: impl IntoIterator, ) { self.mappings.push(b'<'); - if self.byte_gids { + if self.one_byte_gids { self.mappings.push_hex(glyph as u8); } else { self.mappings.push_hex_u16(glyph);