Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix matcher for woff & woff2 #70

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/matchers/font.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
/// Returns whether a buffer is WOFF font data.
pub fn is_woff(buf: &[u8]) -> bool {
buf.len() > 7
buf.len() > 3
&& buf[0] == 0x77
&& buf[1] == 0x4F
&& buf[2] == 0x46
&& buf[3] == 0x46
&& buf[4] == 0x00
&& buf[5] == 0x01
&& buf[6] == 0x00
&& buf[7] == 0x00
}

/// Returns whether a buffer is WOFF2 font data.
pub fn is_woff2(buf: &[u8]) -> bool {
buf.len() > 7
buf.len() > 3
&& buf[0] == 0x77
&& buf[1] == 0x4F
&& buf[2] == 0x46
&& buf[3] == 0x32
&& buf[4] == 0x00
&& buf[5] == 0x01
&& buf[6] == 0x00
&& buf[7] == 0x00
Copy link

@yisibl yisibl Jul 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be the difference between TrueType(0x00010000) and OTF(OTTO, 0x4F54544F)

https://github.com/junmer/is-woff/blob/f66b0846497788bbb6d8f78e2d07106919232089/index.js#L9-L27

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec: https://www.w3.org/TR/WOFF/#WOFFHeader

The flavor field corresponds to the "sfnt version" field found at the beginning of an sfnt file, indicating the type of font data contained. Although only fonts of type 0x00010000 (the version number 1.0 as a 16.16 fixed-point value, indicating TrueType glyph data) and 0x4F54544F (the tag 'OTTO', indicating CFF glyph data) are widely supported at present, it is not an error in the WOFF file if the flavor field contains a different value, indicating a WOFF-packaged version of a different sfnt flavor. (The value 0x74727565 'true' has been used for some TrueType-flavored fonts on Mac OS, for example.) Whether client software will actually support other types of sfnt font data is outside the scope of the WOFF specification, which simply describes how the sfnt is repackaged for Web use.

}

/// Returns whether a buffer is TTF font data.
Expand Down