diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-09-30 11:22:45 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-09-30 11:23:09 +0200 |
| commit | 7ef6cb31df0fe1ebec99b1077053a586a349f530 (patch) | |
| tree | c4527c31521859bcb9c8ca5eafb14e6efb613bb0 /src/font | |
| parent | 9db89b376da33f99867ca511fe701e067432196d (diff) | |
Bump ttf-parser
Diffstat (limited to 'src/font')
| -rw-r--r-- | src/font/book.rs | 5 | ||||
| -rw-r--r-- | src/font/mod.rs | 31 |
2 files changed, 24 insertions, 12 deletions
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<Item = FontInfo> + '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<Option<MathHeader>>, } @@ -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() |
