...

Source file src/github.com/gabriel-vasile/mimetype/internal/magic/font.go

Documentation: github.com/gabriel-vasile/mimetype/internal/magic

     1  package magic
     2  
     3  import (
     4  	"bytes"
     5  )
     6  
     7  var (
     8  	// Woff matches a Web Open Font Format file.
     9  	Woff = prefix([]byte("wOFF"))
    10  	// Woff2 matches a Web Open Font Format version 2 file.
    11  	Woff2 = prefix([]byte("wOF2"))
    12  	// Otf matches an OpenType font file.
    13  	Otf = prefix([]byte{0x4F, 0x54, 0x54, 0x4F, 0x00})
    14  )
    15  
    16  // Ttf matches a TrueType font file.
    17  func Ttf(raw []byte, limit uint32) bool {
    18  	if !bytes.HasPrefix(raw, []byte{0x00, 0x01, 0x00, 0x00}) {
    19  		return false
    20  	}
    21  	return !MsAccessAce(raw, limit) && !MsAccessMdb(raw, limit)
    22  }
    23  
    24  // Eot matches an Embedded OpenType font file.
    25  func Eot(raw []byte, limit uint32) bool {
    26  	return len(raw) > 35 &&
    27  		bytes.Equal(raw[34:36], []byte{0x4C, 0x50}) &&
    28  		(bytes.Equal(raw[8:11], []byte{0x02, 0x00, 0x01}) ||
    29  			bytes.Equal(raw[8:11], []byte{0x01, 0x00, 0x00}) ||
    30  			bytes.Equal(raw[8:11], []byte{0x02, 0x00, 0x02}))
    31  }
    32  
    33  // Ttc matches a TrueType Collection font file.
    34  func Ttc(raw []byte, limit uint32) bool {
    35  	return len(raw) > 7 &&
    36  		bytes.HasPrefix(raw, []byte("ttcf")) &&
    37  		(bytes.Equal(raw[4:8], []byte{0x00, 0x01, 0x00, 0x00}) ||
    38  			bytes.Equal(raw[4:8], []byte{0x00, 0x02, 0x00, 0x00}))
    39  }
    40  

View as plain text