Bump ttf-parser

This commit is contained in:
Laurenz 2022-09-30 11:22:45 +02:00
parent 9db89b376d
commit 7ef6cb31df
9 changed files with 65 additions and 50 deletions

64
Cargo.lock generated
View File

@ -196,12 +196,11 @@ dependencies = [
[[package]] [[package]]
name = "crossbeam-utils" name = "crossbeam-utils"
version = "0.8.11" version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"once_cell",
] ]
[[package]] [[package]]
@ -369,23 +368,22 @@ dependencies = [
[[package]] [[package]]
name = "iana-time-zone" name = "iana-time-zone"
version = "0.1.48" version = "0.1.50"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "237a0714f28b1ee39ccec0770ccb544eb02c9ef2c82bb096230eefcffa6468b0" checksum = "fd911b35d940d2bd0bea0f9100068e5b97b51a1cbe13d13382f132e0365257a0"
dependencies = [ dependencies = [
"android_system_properties", "android_system_properties",
"core-foundation-sys", "core-foundation-sys",
"js-sys", "js-sys",
"once_cell",
"wasm-bindgen", "wasm-bindgen",
"winapi", "winapi",
] ]
[[package]] [[package]]
name = "image" name = "image"
version = "0.24.3" version = "0.24.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e30ca2ecf7666107ff827a8e481de6a132a9b687ed3bb20bb1c144a36c00964" checksum = "bd8e4fb07cf672b1642304e731ef8a6a4c7891d67bb4fd4f5ce58cd6ed86803c"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"byteorder", "byteorder",
@ -503,9 +501,9 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.132" version = "0.2.134"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb"
[[package]] [[package]]
name = "lipsum" name = "lipsum"
@ -628,9 +626,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.14.0" version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
[[package]] [[package]]
name = "pdf-writer" name = "pdf-writer"
@ -652,9 +650,9 @@ checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468"
[[package]] [[package]]
name = "pixglyph" name = "pixglyph"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/typst/pixglyph#f1aae13ae622f4640a1cfac231525f02978fc305" source = "git+https://github.com/typst/pixglyph#131ea492ceada591c7e2d6dd2a5958ae325bd0d4"
dependencies = [ dependencies = [
"ttf-parser", "ttf-parser 0.17.0",
] ]
[[package]] [[package]]
@ -677,9 +675,9 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.43" version = "1.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -787,11 +785,11 @@ dependencies = [
[[package]] [[package]]
name = "rex" name = "rex"
version = "0.1.2" version = "0.1.2"
source = "git+https://github.com/laurmaedje/ReX#6e4bada20d2b1685940e2d752630cb9ad3d797b0" source = "git+https://github.com/laurmaedje/ReX#672c321a947f945e9ba936ae9fbd982c4e043f1c"
dependencies = [ dependencies = [
"itertools", "itertools",
"nom", "nom",
"ttf-parser", "ttf-parser 0.17.0",
"unicode-math", "unicode-math",
] ]
@ -822,7 +820,7 @@ dependencies = [
"bitflags", "bitflags",
"bytemuck", "bytemuck",
"smallvec", "smallvec",
"ttf-parser", "ttf-parser 0.15.2",
"unicode-bidi-mirroring", "unicode-bidi-mirroring",
"unicode-ccc", "unicode-ccc",
"unicode-general-category", "unicode-general-category",
@ -855,18 +853,18 @@ dependencies = [
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.144" version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.144" version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -945,9 +943,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.100" version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e" checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -986,18 +984,18 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.35" version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.35" version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1024,6 +1022,12 @@ version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd" checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd"
[[package]]
name = "ttf-parser"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9146d2aaf37dc5334287712849dfbf6aecfbd97971f2e8d86c5e50ea550d71ae"
[[package]] [[package]]
name = "typed-arena" name = "typed-arena"
version = "2.0.1" version = "2.0.1"
@ -1069,7 +1073,7 @@ dependencies = [
"svg2pdf", "svg2pdf",
"syntect", "syntect",
"tiny-skia", "tiny-skia",
"ttf-parser", "ttf-parser 0.17.0",
"typed-arena", "typed-arena",
"typst-macros", "typst-macros",
"unicode-bidi", "unicode-bidi",

View File

@ -24,7 +24,7 @@ comemo = { git = "https://github.com/typst/comemo" }
# Text and font handling # Text and font handling
hypher = "0.1" hypher = "0.1"
kurbo = "0.8" kurbo = "0.8"
ttf-parser = "0.15" ttf-parser = "0.17"
rustybuzz = "0.5" rustybuzz = "0.5"
unicode-bidi = "0.3.5" unicode-bidi = "0.3.5"
unicode-segmentation = "1" unicode-segmentation = "1"

View File

@ -45,8 +45,9 @@ pub fn write_fonts(ctx: &mut PdfContext) {
// Check for the presence of CFF outlines to select the correct // Check for the presence of CFF outlines to select the correct
// CID-Font subtype. // CID-Font subtype.
let subtype = match ttf let subtype = match ttf
.table_data(Tag::from_bytes(b"CFF ")) .raw_face()
.or(ttf.table_data(Tag::from_bytes(b"CFF2"))) .table(Tag::from_bytes(b"CFF "))
.or(ttf.raw_face().table(Tag::from_bytes(b"CFF2")))
{ {
Some(_) => CidFontType::Type0, Some(_) => CidFontType::Type0,
None => CidFontType::Type2, None => CidFontType::Type2,

View File

@ -173,7 +173,7 @@ impl FontInfo {
pub fn from_data<'a>(data: &'a [u8]) -> impl Iterator<Item = FontInfo> + 'a { pub fn from_data<'a>(data: &'a [u8]) -> impl Iterator<Item = FontInfo> + 'a {
let count = ttf_parser::fonts_in_collection(data).unwrap_or(1); let count = ttf_parser::fonts_in_collection(data).unwrap_or(1);
(0 .. count).filter_map(move |index| { (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) Self::from_ttf(&ttf)
}) })
} }
@ -239,7 +239,8 @@ impl FontInfo {
// Determine whether this is a serif or sans-serif font. // Determine whether this is a serif or sans-serif font.
if let Some(panose) = ttf 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)) .and_then(|os2| os2.get(32 .. 45))
{ {
if matches!(panose, [2, 2 ..= 10, ..]) { if matches!(panose, [2, 2 ..= 10, ..]) {

View File

@ -10,7 +10,7 @@ use std::fmt::{self, Debug, Formatter};
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::sync::Arc; use std::sync::Arc;
use once_cell::sync::OnceCell; use once_cell::unsync::OnceCell;
use rex::font::MathHeader; use rex::font::MathHeader;
use ttf_parser::{GlyphId, Tag}; use ttf_parser::{GlyphId, Tag};
@ -33,8 +33,10 @@ struct Repr {
info: FontInfo, info: FontInfo,
/// The font's metrics. /// The font's metrics.
metrics: FontMetrics, metrics: FontMetrics,
/// The underlying ttf-parser/rustybuzz face. /// The underlying ttf-parser face.
ttf: rustybuzz::Face<'static>, ttf: ttf_parser::Face<'static>,
/// The underlying rustybuzz face.
rusty: rustybuzz::Face<'static>,
/// The parsed ReX math header. /// The parsed ReX math header.
math: OnceCell<Option<MathHeader>>, math: OnceCell<Option<MathHeader>>,
} }
@ -51,7 +53,8 @@ impl Font {
let slice: &'static [u8] = let slice: &'static [u8] =
unsafe { std::slice::from_raw_parts(data.as_ptr(), data.len()) }; 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 metrics = FontMetrics::from_ttf(&ttf);
let info = FontInfo::from_ttf(&ttf)?; let info = FontInfo::from_ttf(&ttf)?;
@ -59,8 +62,9 @@ impl Font {
data, data,
index, index,
info, info,
ttf,
metrics, metrics,
ttf,
rusty,
math: OnceCell::new(), math: OnceCell::new(),
}))) })))
} }
@ -108,19 +112,26 @@ impl Font {
find_name(&self.0.ttf, id) find_name(&self.0.ttf, id)
} }
/// A reference to the underlying `ttf-parser` / `rustybuzz` face. /// A reference to the underlying `ttf-parser` face.
pub fn ttf(&self) -> &rustybuzz::Face<'_> { pub fn ttf(&self) -> &ttf_parser::Face<'_> {
// We can't implement Deref because that would leak the internal 'static // We can't implement Deref because that would leak the
// lifetime. // internal 'static lifetime.
&self.0.ttf &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. /// Access the math header, if any.
pub fn math(&self) -> Option<&MathHeader> { pub fn math(&self) -> Option<&MathHeader> {
self.0 self.0
.math .math
.get_or_init(|| { .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() MathHeader::parse(data).ok()
}) })
.as_ref() .as_ref()

View File

@ -22,7 +22,7 @@ pub use shift::*;
use std::borrow::Cow; use std::borrow::Cow;
use ttf_parser::Tag; use rustybuzz::Tag;
use crate::font::{FontMetrics, FontStretch, FontStyle, FontWeight, VerticalFontMetric}; use crate::font::{FontMetrics, FontStretch, FontStyle, FontWeight, VerticalFontMetric};
use crate::library::prelude::*; use crate::library::prelude::*;

View File

@ -1,7 +1,7 @@
use std::ops::Range; use std::ops::Range;
use std::str::FromStr; use std::str::FromStr;
use rustybuzz::{Feature, UnicodeBuffer}; use rustybuzz::{Feature, Tag, UnicodeBuffer};
use super::*; use super::*;
use crate::font::{Font, FontVariant}; use crate::font::{Font, FontVariant};
@ -407,7 +407,7 @@ fn shape_segment<'a>(
}); });
// Shape! // 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 infos = buffer.glyph_infos();
let pos = buffer.glyph_positions(); let pos = buffer.glyph_positions();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -39,8 +39,6 @@ Hello
fn main() {} fn main() {}
``` ```
$ x + y = z $
- List - List
Paragraph Paragraph