Skip to content

Commit e63211a

Browse files
committed
Default to wuff for WOFF decoding
Signed-off-by: Nico Burns <[email protected]>
1 parent 4c74552 commit e63211a

File tree

5 files changed

+46
-111
lines changed

5 files changed

+46
-111
lines changed

Cargo.lock

Lines changed: 11 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ reqwest = "0.12"
116116
image = { version = "0.25", default-features = false }
117117
woff = { version = "0.6", default-features = false }
118118
woff2 = "0.3"
119+
wuff = "0.2"
119120
html-escape = "0.2.13"
120121
percent-encoding = "2.3.1"
121122
png = "0.17"

packages/blitz-dom/Cargo.toml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,17 @@ rust-version.workspace = true
1414
default = [
1515
"tracing",
1616
"svg",
17-
"woff-c",
17+
"woff-rust",
1818
"accessibility",
1919
"system_fonts",
2020
"file_input",
2121
]
2222
tracing = ["dep:tracing"]
2323
svg = ["dep:usvg"]
2424
# WOFF decoding using the "woff" crate which binds to C libraries
25-
# ("woff" for woff2) and "sfnt2woff" for woff1).
26-
# Both woff1 and woff2 are supported
2725
woff-c = ["dep:woff"]
28-
# WOFF decoding using the "woff2" crate which is pure Rust
29-
# Only woff2 is supported. Does not work correct with all woff2 fonts
30-
woff-rust = ["dep:woff2"]
26+
# WOFF decoding using the "wuff" crate which is pure Rust
27+
woff-rust = ["dep:wuff"]
3128
accessibility = ["accesskit"]
3229
system_fonts = ["parley/system"]
3330
autofocus = []
@@ -72,8 +69,8 @@ fastrand = { workspace = true }
7269
# Media & Decoding
7370
image = { workspace = true }
7471
usvg = { workspace = true, optional = true }
75-
woff = { workspace = true, optional = true, features = ["version2"] }
76-
woff2 = { workspace = true, optional = true }
72+
woff = { workspace = true, optional = true, features = ["version1", "version2"] }
73+
wuff = { workspace = true, optional = true }
7774
html-escape = { workspace = true }
7875
percent-encoding = { workspace = true }
7976

packages/blitz-dom/src/net.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,25 @@ impl NetHandler<Resource> for CssHandler {
171171
struct FontFaceHandler(FontFaceSourceFormatKeyword);
172172
impl NetHandler<Resource> for FontFaceHandler {
173173
fn bytes(mut self: Box<Self>, doc_id: usize, bytes: Bytes, callback: SharedCallback<Resource>) {
174-
if self.0 == FontFaceSourceFormatKeyword::None {
175-
self.0 = match bytes.as_ref() {
174+
if self.0 == FontFaceSourceFormatKeyword::None && bytes.len() >= 4 {
175+
self.0 = match &bytes.as_ref()[0..4] {
176176
// WOFF (v1) files begin with 0x774F4646 ('wOFF' in ascii)
177177
// See: <https://w3c.github.io/woff/woff1/spec/Overview.html#WOFFHeader>
178-
// #[cfg(any(feature = "woff-c"))]
179-
// [b'w', b'O', b'F', b'F', ..] => FontFaceSourceFormatKeyword::Woff,
178+
#[cfg(any(feature = "woff-c", feature = "woff-rust"))]
179+
b"wOFF" => FontFaceSourceFormatKeyword::Woff,
180180
// WOFF2 files begin with 0x774F4632 ('wOF2' in ascii)
181181
// See: <https://w3c.github.io/woff/woff2/#woff20Header>
182182
#[cfg(any(feature = "woff-c", feature = "woff-rust"))]
183-
[b'w', b'O', b'F', b'2', ..] => FontFaceSourceFormatKeyword::Woff2,
183+
b"wOF2" => FontFaceSourceFormatKeyword::Woff2,
184184
// Opentype fonts with CFF data begin with 0x4F54544F ('OTTO' in ascii)
185185
// See: <https://learn.microsoft.com/en-us/typography/opentype/spec/otff#organization-of-an-opentype-font>
186-
[b'O', b'T', b'T', b'O', ..] => FontFaceSourceFormatKeyword::Opentype,
186+
b"OTTO" => FontFaceSourceFormatKeyword::Opentype,
187187
// Opentype fonts truetype outlines begin with 0x00010000
188188
// See: <https://learn.microsoft.com/en-us/typography/opentype/spec/otff#organization-of-an-opentype-font>
189-
[0x00, 0x01, 0x00, 0x00, ..] => FontFaceSourceFormatKeyword::Truetype,
189+
&[0x00, 0x01, 0x00, 0x00] => FontFaceSourceFormatKeyword::Truetype,
190190
// Truetype fonts begin with 0x74727565 ('true' in ascii)
191191
// See: <https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html#ScalerTypeNote>
192-
[b't', b'r', b'u', b'e', ..] => FontFaceSourceFormatKeyword::Truetype,
192+
b"true" => FontFaceSourceFormatKeyword::Truetype,
193193
_ => FontFaceSourceFormatKeyword::None,
194194
}
195195
}
@@ -199,21 +199,26 @@ impl NetHandler<Resource> for FontFaceHandler {
199199
let mut bytes = bytes;
200200

201201
match self.0 {
202-
// #[cfg(feature = "woff-c")]
203-
// FontFaceSourceFormatKeyword::Woff => {
204-
// #[cfg(feature = "tracing")]
205-
// tracing::info!("Decompressing woff1 font");
202+
#[cfg(any(feature = "woff-c", feature = "woff-rust"))]
203+
FontFaceSourceFormatKeyword::Woff => {
204+
#[cfg(feature = "tracing")]
205+
tracing::info!("Decompressing woff1 font");
206206

207-
// // Use woff crate to decompress font
208-
// let decompressed = woff::version1::decompress(&bytes);
207+
// Use woff crate to decompress font
208+
#[cfg(feature = "woff-c")]
209+
let decompressed = woff::version1::decompress(&bytes);
210+
211+
// Use wuff crate to decompress font
212+
#[cfg(feature = "woff-rust")]
213+
let decompressed = wuff::decompress_woff1(&bytes).ok();
209214

210-
// if let Some(decompressed) = decompressed {
211-
// bytes = Bytes::from(decompressed);
212-
// } else {
213-
// #[cfg(feature = "tracing")]
214-
// tracing::warn!("Failed to decompress woff1 font");
215-
// }
216-
// }
215+
if let Some(decompressed) = decompressed {
216+
bytes = Bytes::from(decompressed);
217+
} else {
218+
#[cfg(feature = "tracing")]
219+
tracing::warn!("Failed to decompress woff1 font");
220+
}
221+
}
217222
#[cfg(any(feature = "woff-c", feature = "woff-rust"))]
218223
FontFaceSourceFormatKeyword::Woff2 => {
219224
#[cfg(feature = "tracing")]
@@ -223,9 +228,9 @@ impl NetHandler<Resource> for FontFaceHandler {
223228
#[cfg(feature = "woff-c")]
224229
let decompressed = woff::version2::decompress(&bytes);
225230

226-
// Use woff2 crate to decompress font
231+
// Use wuff crate to decompress font
227232
#[cfg(feature = "woff-rust")]
228-
let decompressed = woff2::decode::convert_woff2_to_ttf(&mut bytes).ok();
233+
let decompressed = wuff::decompress_woff2(&bytes).ok();
229234

230235
if let Some(decompressed) = decompressed {
231236
bytes = Bytes::from(decompressed);

wpt/runner/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ gpu = ["dep:anyrender_vello"]
1111
cpu = ["dep:anyrender_vello_cpu"]
1212

1313
[dependencies]
14-
blitz-dom = { workspace = true, features = ["svg", "woff-c"] }
14+
blitz-dom = { workspace = true, features = ["svg", "woff-rust"] }
1515
blitz-html = {workspace = true }
1616
blitz-traits = { workspace = true }
1717
blitz-paint = { workspace = true, features = ["default"] }

0 commit comments

Comments
 (0)