Skip to content

Commit

Permalink
Add support for EOT and OTF font types
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-vasile committed Jul 26, 2019
1 parent 34a3ae5 commit 265ccad
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
16 changes: 15 additions & 1 deletion internal/matchers/font.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,19 @@ func Woff(in []byte) bool {

// Woff2 matches a Web Open Font Format version 2 file.
func Woff2(in []byte) bool {
return len(in) > 4 && bytes.Equal(in[:4], []byte("wOF2"))
return bytes.HasPrefix(in, []byte("wOF2"))
}

// Otf matches an OpenType font file.
func Otf(in []byte) bool {
return bytes.HasPrefix(in, []byte{0x4F, 0x54, 0x54, 0x4F, 0x00})
}

// Eot matches an Embedded OpenType font file.
func Eot(in []byte) bool {
return len(in) > 35 &&
bytes.Equal(in[34:36], []byte{0x4C, 0x50}) &&
(bytes.Equal(in[8:11], []byte{0x02, 0x00, 0x01}) ||
bytes.Equal(in[8:11], []byte{0x01, 0x00, 0x00}) ||
bytes.Equal(in[8:11], []byte{0x02, 0x00, 0x02}))
}
2 changes: 2 additions & 0 deletions mime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ var files = map[string]*node{
// fonts
"woff.woff": woff,
"woff2.woff2": woff2,
"otf.otf": otf,
"eot.eot": eot,

// XML and subtypes of XML
"xml.xml": xml,
Expand Down
4 changes: 3 additions & 1 deletion supported_mimes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 112 Supported MIME types
## 114 Supported MIME types
This file is automatically generated when running tests. Do not edit manually.

Extension | MIME type
Expand Down Expand Up @@ -103,6 +103,8 @@ Extension | MIME type
**crx** | application/x-chrome-extension
**woff** | font/woff
**woff2** | font/woff2
**otf** | font/otf
**eot** | application/vnd.ms-fontobject
**wasm** | application/wasm
**shx** | application/octet-stream
**shp** | application/octet-stream
Expand Down
Binary file added testdata/eot.eot
Binary file not shown.
Binary file added testdata/otf.otf
Binary file not shown.
6 changes: 4 additions & 2 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var root = newNode("application/octet-stream", "", matchers.True,
sevenZ, zip, pdf, xls, ppt, doc, ps, psd, ogg, png, jpg, gif, webp, exe, elf,
ar, tar, xar, bz2, fits, tiff, bmp, ico, mp3, flac, midi, ape, musePack, amr,
wav, aiff, au, mpeg, quickTime, mqv, mp4, webM, threeGP, threeG2, avi, flv,
mkv, asf, aac, voc, aMp4, m4a, txt, gzip, class, swf, crx, woff, woff2, wasm,
shx, dbf, dcm, rar, djvu, mobi, lit, bpg, sqlite3, dwg,
mkv, asf, aac, voc, aMp4, m4a, txt, gzip, class, swf, crx, woff, woff2, otf,
eot, wasm, shx, dbf, dcm, rar, djvu, mobi, lit, bpg, sqlite3, dwg,
)

// The list of nodes appended to the root node
Expand Down Expand Up @@ -98,6 +98,8 @@ var (
crx = newNode("application/x-chrome-extension", "crx", matchers.Crx)
woff = newNode("font/woff", "woff", matchers.Woff)
woff2 = newNode("font/woff2", "woff2", matchers.Woff2)
otf = newNode("font/otf", "otf", matchers.Otf)
eot = newNode("application/vnd.ms-fontobject", "eot", matchers.Eot)
wasm = newNode("application/wasm", "wasm", matchers.Wasm)
shp = newNode("application/octet-stream", "shp", matchers.Shp)
shx = newNode("application/octet-stream", "shx", matchers.Shx, shp)
Expand Down

0 comments on commit 265ccad

Please sign in to comment.