From 7ef6cb31df0fe1ebec99b1077053a586a349f530 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 30 Sep 2022 11:22:45 +0200 Subject: Bump ttf-parser --- src/export/pdf/font.rs | 5 +++-- src/font/book.rs | 5 +++-- src/font/mod.rs | 31 +++++++++++++++++++++---------- src/library/text/mod.rs | 2 +- src/library/text/shaping.rs | 4 ++-- 5 files changed, 30 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/export/pdf/font.rs b/src/export/pdf/font.rs index 446d36bc..3398478a 100644 --- a/src/export/pdf/font.rs +++ b/src/export/pdf/font.rs @@ -45,8 +45,9 @@ pub fn write_fonts(ctx: &mut PdfContext) { // Check for the presence of CFF outlines to select the correct // CID-Font subtype. let subtype = match ttf - .table_data(Tag::from_bytes(b"CFF ")) - .or(ttf.table_data(Tag::from_bytes(b"CFF2"))) + .raw_face() + .table(Tag::from_bytes(b"CFF ")) + .or(ttf.raw_face().table(Tag::from_bytes(b"CFF2"))) { Some(_) => CidFontType::Type0, None => CidFontType::Type2, diff --git a/src/font/book.rs b/src/font/book.rs index 29190516..d900d3c4 100644 --- a/src/font/book.rs +++ b/src/font/book.rs @@ -173,7 +173,7 @@ impl FontInfo { pub fn from_data<'a>(data: &'a [u8]) -> impl Iterator + 'a { let count = ttf_parser::fonts_in_collection(data).unwrap_or(1); (0 .. count).filter_map(move |index| { - let ttf = ttf_parser::Face::from_slice(data, index).ok()?; + let ttf = ttf_parser::Face::parse(data, index).ok()?; Self::from_ttf(&ttf) }) } @@ -239,7 +239,8 @@ impl FontInfo { // Determine whether this is a serif or sans-serif font. if let Some(panose) = ttf - .table_data(Tag::from_bytes(b"OS/2")) + .raw_face() + .table(Tag::from_bytes(b"OS/2")) .and_then(|os2| os2.get(32 .. 45)) { if matches!(panose, [2, 2 ..= 10, ..]) { diff --git a/src/font/mod.rs b/src/font/mod.rs index 2404ad32..7cddf1ea 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -10,7 +10,7 @@ use std::fmt::{self, Debug, Formatter}; use std::hash::{Hash, Hasher}; use std::sync::Arc; -use once_cell::sync::OnceCell; +use once_cell::unsync::OnceCell; use rex::font::MathHeader; use ttf_parser::{GlyphId, Tag}; @@ -33,8 +33,10 @@ struct Repr { info: FontInfo, /// The font's metrics. metrics: FontMetrics, - /// The underlying ttf-parser/rustybuzz face. - ttf: rustybuzz::Face<'static>, + /// The underlying ttf-parser face. + ttf: ttf_parser::Face<'static>, + /// The underlying rustybuzz face. + rusty: rustybuzz::Face<'static>, /// The parsed ReX math header. math: OnceCell>, } @@ -51,7 +53,8 @@ impl Font { let slice: &'static [u8] = unsafe { std::slice::from_raw_parts(data.as_ptr(), data.len()) }; - let ttf = rustybuzz::Face::from_slice(slice, index)?; + let ttf = ttf_parser::Face::parse(slice, index).ok()?; + let rusty = rustybuzz::Face::from_slice(slice, index)?; let metrics = FontMetrics::from_ttf(&ttf); let info = FontInfo::from_ttf(&ttf)?; @@ -59,8 +62,9 @@ impl Font { data, index, info, - ttf, metrics, + ttf, + rusty, math: OnceCell::new(), }))) } @@ -108,19 +112,26 @@ impl Font { find_name(&self.0.ttf, id) } - /// A reference to the underlying `ttf-parser` / `rustybuzz` face. - pub fn ttf(&self) -> &rustybuzz::Face<'_> { - // We can't implement Deref because that would leak the internal 'static - // lifetime. + /// A reference to the underlying `ttf-parser` face. + pub fn ttf(&self) -> &ttf_parser::Face<'_> { + // We can't implement Deref because that would leak the + // internal 'static lifetime. &self.0.ttf } + /// A reference to the underlying `rustybuzz` face. + pub fn rusty(&self) -> &rustybuzz::Face<'_> { + // We can't implement Deref because that would leak the + // internal 'static lifetime. + &self.0.rusty + } + /// Access the math header, if any. pub fn math(&self) -> Option<&MathHeader> { self.0 .math .get_or_init(|| { - let data = self.ttf().table_data(Tag::from_bytes(b"MATH"))?; + let data = self.ttf().raw_face().table(Tag::from_bytes(b"MATH"))?; MathHeader::parse(data).ok() }) .as_ref() diff --git a/src/library/text/mod.rs b/src/library/text/mod.rs index 934f5e15..c9bf2e57 100644 --- a/src/library/text/mod.rs +++ b/src/library/text/mod.rs @@ -22,7 +22,7 @@ pub use shift::*; use std::borrow::Cow; -use ttf_parser::Tag; +use rustybuzz::Tag; use crate::font::{FontMetrics, FontStretch, FontStyle, FontWeight, VerticalFontMetric}; use crate::library::prelude::*; diff --git a/src/library/text/shaping.rs b/src/library/text/shaping.rs index 16989acf..487b9090 100644 --- a/src/library/text/shaping.rs +++ b/src/library/text/shaping.rs @@ -1,7 +1,7 @@ use std::ops::Range; use std::str::FromStr; -use rustybuzz::{Feature, UnicodeBuffer}; +use rustybuzz::{Feature, Tag, UnicodeBuffer}; use super::*; use crate::font::{Font, FontVariant}; @@ -407,7 +407,7 @@ fn shape_segment<'a>( }); // Shape! - let buffer = rustybuzz::shape(font.ttf(), &ctx.tags, buffer); + let buffer = rustybuzz::shape(font.rusty(), &ctx.tags, buffer); let infos = buffer.glyph_infos(); let pos = buffer.glyph_positions(); -- cgit v1.2.3