From 8b298c8ea3943a17a8aabcb19caad1f75afca498 Mon Sep 17 00:00:00 2001 From: Wesley Moore Date: Wed, 29 May 2024 14:24:50 +1000 Subject: [PATCH] Compatibility with newer Allsorts --- src/bitmaps.rs | 2 +- src/cmap.rs | 8 +------- src/glyph.rs | 10 +++------- src/layout_features.rs | 8 +------- src/shape.rs | 8 +------- src/subset.rs | 10 +++------- src/svg.rs | 8 +------- src/view.rs | 16 +++------------- src/writer.rs | 10 +++++----- 9 files changed, 19 insertions(+), 61 deletions(-) diff --git a/src/bitmaps.rs b/src/bitmaps.rs index 24429ea..d3a216a 100644 --- a/src/bitmaps.rs +++ b/src/bitmaps.rs @@ -20,7 +20,7 @@ pub fn main(opts: BitmapOpts) -> Result { let scope = ReadScope::new(&buffer); let font_file = scope.read::()?; let table_provider = font_file.table_provider(opts.index)?; - let mut font = Font::new(table_provider)?.ok_or("unable to find suitable cmap sub-table")?; + let mut font = Font::new(table_provider)?; let output_path = Path::new(&opts.output); if !output_path.exists() { diff --git a/src/cmap.rs b/src/cmap.rs index 577fcec..1956a2a 100644 --- a/src/cmap.rs +++ b/src/cmap.rs @@ -14,13 +14,7 @@ pub fn main(opts: CmapOpts) -> Result { let scope = ReadScope::new(&buffer); let font_file = scope.read::()?; let table_provider = font_file.table_provider(opts.index)?; - let mut font = match Font::new(Box::new(table_provider))? { - Some(font) => font, - None => { - eprintln!("unable to find suitable cmap subtable"); - return Ok(1); - } - }; + let mut font = Font::new(Box::new(table_provider))?; dump_cmap(&mut font)?; Ok(0) diff --git a/src/glyph.rs b/src/glyph.rs index 847a137..320be29 100644 --- a/src/glyph.rs +++ b/src/glyph.rs @@ -1,5 +1,5 @@ use allsorts::error::ParseError; -use allsorts::gsub::{GlyphOrigin, RawGlyph}; +use allsorts::gsub::{GlyphOrigin, RawGlyph, RawGlyphFlags}; use allsorts::tables::cmap::CmapSubtable; use allsorts::tinyvec::tiny_vec; use allsorts::unicode::VariationSelector; @@ -27,12 +27,8 @@ pub(crate) fn make( glyph_index, liga_component_pos: 0, glyph_origin: GlyphOrigin::Char(ch), - small_caps: false, - multi_subst_dup: false, - is_vert_alt: false, - fake_bold: false, - fake_italic: false, - extra_data: (), + flags: RawGlyphFlags::empty(), variation, + extra_data: (), } } diff --git a/src/layout_features.rs b/src/layout_features.rs index 260e737..fce3c14 100644 --- a/src/layout_features.rs +++ b/src/layout_features.rs @@ -12,13 +12,7 @@ pub fn main(opts: LayoutFeaturesOpts) -> Result { let scope = ReadScope::new(&buffer); let font_file = scope.read::()?; let provider = font_file.table_provider(opts.index)?; - let mut font = match Font::new(provider)? { - Some(font) => font, - None => { - eprintln!("unable to find suitable cmap subtable"); - return Ok(1); - } - }; + let mut font = Font::new(provider)?; if let Some(gsub_cache) = font.gsub_cache()? { println!("Table: GSUB"); diff --git a/src/shape.rs b/src/shape.rs index 604b8fe..d9ff30e 100644 --- a/src/shape.rs +++ b/src/shape.rs @@ -29,13 +29,7 @@ pub fn main(opts: ShapeOpts) -> Result { None => None, }; - let mut font = match Font::new(Box::new(provider))? { - Some(font) => font, - None => { - eprintln!("unable to find suitable cmap subtable"); - return Ok(1); - } - }; + let mut font = Font::new(Box::new(provider))?; let glyphs = font.map_glyphs(&opts.text, script, MatchingPresentation::NotRequired); let infos = font .shape( diff --git a/src/subset.rs b/src/subset.rs index fd5973f..3750eb3 100644 --- a/src/subset.rs +++ b/src/subset.rs @@ -6,7 +6,7 @@ use std::str; use allsorts::binary::read::ReadScope; use allsorts::font::read_cmap_subtable; use allsorts::font_data::FontData; -use allsorts::gsub::{GlyphOrigin, RawGlyph}; +use allsorts::gsub::{GlyphOrigin, RawGlyph, RawGlyphFlags}; use allsorts::tables::cmap::Cmap; use allsorts::tables::{FontTableProvider, MaxpTable}; use allsorts::tinyvec::tiny_vec; @@ -61,13 +61,9 @@ fn subset_text( glyph_index: 0, liga_component_pos: 0, glyph_origin: GlyphOrigin::Direct, - small_caps: false, - multi_subst_dup: false, - is_vert_alt: false, - fake_bold: false, - fake_italic: false, - extra_data: (), + flags: RawGlyphFlags::empty(), variation: None, + extra_data: (), }; glyphs.insert(0, Some(notdef)); diff --git a/src/svg.rs b/src/svg.rs index 960ae4c..cb61171 100644 --- a/src/svg.rs +++ b/src/svg.rs @@ -35,13 +35,7 @@ pub fn main(opts: SvgOpts) -> Result { let provider = font_file.table_provider(0)?; // Map text to glyphs and then apply font shaping - let mut font = match Font::new(provider)? { - Some(font) => font, - None => { - eprintln!("unable to find suitable cmap subtable"); - return Ok(1); - } - }; + let mut font = Font::new(provider)?; let glyphs = font.map_glyphs(&opts.render, script, MatchingPresentation::NotRequired); let infos = font .shape( diff --git a/src/view.rs b/src/view.rs index b558c96..a41d955 100644 --- a/src/view.rs +++ b/src/view.rs @@ -3,7 +3,7 @@ use allsorts::cff::CFF; use allsorts::error::ParseError; use allsorts::font::{Font, GlyphTableFlags, MatchingPresentation}; use allsorts::font_data::FontData; -use allsorts::gsub::{FeatureInfo, FeatureMask, Features, GlyphOrigin, RawGlyph}; +use allsorts::gsub::{FeatureInfo, FeatureMask, Features, GlyphOrigin, RawGlyph, RawGlyphFlags}; use allsorts::pathfinder_geometry::transform2d::Matrix2x2F; use allsorts::pathfinder_geometry::vector::vec2f; use allsorts::post::PostTable; @@ -58,13 +58,7 @@ pub fn main(opts: ViewOpts) -> Result { None => None, }; - let mut font = match Font::new(provider)? { - Some(font) => font, - None => { - eprintln!("unable to find suitable cmap subtable"); - return Ok(1); - } - }; + let mut font = Font::new(provider)?; let glyphs = if let Some(ref text) = opts.text { font.map_glyphs(&text, script, MatchingPresentation::NotRequired) @@ -163,11 +157,7 @@ fn make_raw_glyph(glyph_index: u16) -> RawGlyph<()> { glyph_index, liga_component_pos: 0, glyph_origin: GlyphOrigin::Char('x'), - small_caps: false, - multi_subst_dup: false, - is_vert_alt: false, - fake_bold: false, - fake_italic: false, + flags: RawGlyphFlags::empty(), variation: None, extra_data: (), } diff --git a/src/writer.rs b/src/writer.rs index 2a3a074..14f2511 100644 --- a/src/writer.rs +++ b/src/writer.rs @@ -488,19 +488,19 @@ impl<'info> Symbol<'info> { GlyphOrigin::Direct => String::from("direct"), }, ); - if self.info.glyph.small_caps { + if self.info.glyph.small_caps() { data.insert("data-small-caps", bool_true.clone()); } - if self.info.glyph.multi_subst_dup { + if self.info.glyph.multi_subst_dup() { data.insert("data-multi-subst-dup", bool_true.clone()); } - if self.info.glyph.is_vert_alt { + if self.info.glyph.is_vert_alt() { data.insert("data-is-vert-alt", bool_true.clone()); } - if self.info.glyph.fake_bold { + if self.info.glyph.fake_bold() { data.insert("data-fake-bold", bool_true.clone()); } - if self.info.glyph.fake_italic { + if self.info.glyph.fake_italic() { data.insert("data-fake-italic", bool_true.clone()); } data