Skip to content

Commit aa99e79

Browse files
committed
Improve documentation of font file type detection
1 parent 6a02b42 commit aa99e79

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

packages/blitz-dom/src/net.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,24 @@ impl NetHandler for FontFaceHandler {
157157
fn bytes(mut self: Box<Self>, doc_id: usize, bytes: Bytes, callback: SharedCallback<Resource>) {
158158
if self.0 == FontFaceSourceFormatKeyword::None {
159159
self.0 = match bytes.as_ref() {
160-
// https://w3c.github.io/woff/woff2/#woff20Header
161-
#[cfg(feature = "woff")]
162-
[0x77, 0x4F, 0x46, 0x32, ..] => FontFaceSourceFormatKeyword::Woff2,
163-
// https://learn.microsoft.com/en-us/typography/opentype/spec/otff#organization-of-an-opentype-font
164-
[0x4F, 0x54, 0x54, 0x4F, ..] => FontFaceSourceFormatKeyword::Opentype,
165-
// https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html#ScalerTypeNote
166-
[0x00, 0x01, 0x00, 0x00, ..] | [0x74, 0x72, 0x75, 0x65, ..] => {
167-
FontFaceSourceFormatKeyword::Truetype
168-
}
160+
// WOFF (v1) files begin with 0x774F4646 ('wOFF' in ascii)
161+
// See: <https://w3c.github.io/woff/woff1/spec/Overview.html#WOFFHeader>
162+
#[cfg(any(feature = "woff", feature = "woff2"))]
163+
[b'w', b'O', b'F', b'F', ..] => FontFaceSourceFormatKeyword::Woff
164+
[b'w', b'O', b'F', b'F', ..] => FontFaceSourceFormatKeyword::Woff,
165+
// WOFF2 files begin with 0x774F4632 ('wOF2' in ascii)
166+
// See: <https://w3c.github.io/woff/woff2/#woff20Header>
167+
#[cfg(any(feature = "woff", feature = "woff2"))]
168+
[b'w', b'O', b'F', b'2', ..] => FontFaceSourceFormatKeyword::Woff2,
169+
// Opentype fonts with CFF data begin with 0x4F54544F ('OTTO' in ascii)
170+
// See: <https://learn.microsoft.com/en-us/typography/opentype/spec/otff#organization-of-an-opentype-font>
171+
[b'O', b'T', b'T', b'O', ..] => FontFaceSourceFormatKeyword::Opentype,
172+
// Opentype fonts truetype outlines begin with 0x00010000
173+
// See: <https://learn.microsoft.com/en-us/typography/opentype/spec/otff#organization-of-an-opentype-font>
174+
[0x00, 0x01, 0x00, 0x00, ..] => FontFaceSourceFormatKeyword::Truetype,
175+
// Truetype fonts begin with 0x74727565 ('true' in ascii)
176+
// See: <https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html#ScalerTypeNote>
177+
[b't', b'r', b'u', b'e', ..] => FontFaceSourceFormatKeyword::Truetype,
169178
_ => FontFaceSourceFormatKeyword::None,
170179
}
171180
}

0 commit comments

Comments
 (0)