Skip to content

Commit

Permalink
Compatibility with newer Allsorts
Browse files Browse the repository at this point in the history
  • Loading branch information
wezm committed Jun 6, 2024
1 parent 3197942 commit 8b298c8
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/bitmaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn main(opts: BitmapOpts) -> Result<i32, BoxError> {
let scope = ReadScope::new(&buffer);
let font_file = scope.read::<FontData>()?;
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() {
Expand Down
8 changes: 1 addition & 7 deletions src/cmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ pub fn main(opts: CmapOpts) -> Result<i32, BoxError> {
let scope = ReadScope::new(&buffer);
let font_file = scope.read::<FontData>()?;
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)
Expand Down
10 changes: 3 additions & 7 deletions src/glyph.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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: (),
}
}
8 changes: 1 addition & 7 deletions src/layout_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,7 @@ pub fn main(opts: LayoutFeaturesOpts) -> Result<i32, BoxError> {
let scope = ReadScope::new(&buffer);
let font_file = scope.read::<FontData>()?;
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");
Expand Down
8 changes: 1 addition & 7 deletions src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ pub fn main(opts: ShapeOpts) -> Result<i32, BoxError> {
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(
Expand Down
10 changes: 3 additions & 7 deletions src/subset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,13 +61,9 @@ fn subset_text<F: FontTableProvider>(
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));

Expand Down
8 changes: 1 addition & 7 deletions src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,7 @@ pub fn main(opts: SvgOpts) -> Result<i32, BoxError> {
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(
Expand Down
16 changes: 3 additions & 13 deletions src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,13 +58,7 @@ pub fn main(opts: ViewOpts) -> Result<i32, BoxError> {
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)
Expand Down Expand Up @@ -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: (),
}
Expand Down
10 changes: 5 additions & 5 deletions src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b298c8

Please sign in to comment.