Enhanced OpenType for web use: the WebOTF format ================================================ August 6, 2009 Jonathan Kew, Mozilla Corp. Tal Leming, Type Supply Erik van Blokland, LettError This is a proposal for a simple compressed format for fonts, designed primarily for use on the web. A feature of this format is that clients can decompress individual tables as needed, and thus can access specific parts of the font data without the need to decompress the entire font. In resource-constrained environments such as mobile devices, this allows the user agent to examine, for example, the OS/2 and cmap tables quite cheaply; or a client that knows it is doing horizontal layout could skip decompressing a vertical metrics table. It would even be possible for the UA to use byte-range requests to avoid even downloading the entire compressed file, by first downloading the header, to determine the number of tables, and then the table directory. At this point, the UA can issue a request to get the compressed version of any individual font table, and thus it can minimize the RAM footprint of pages that may link to numerous fonts, at the cost of doing more separate network requests. This format does not provide for individual decompression of single glyphs; it is expected that sites using linked fonts for CJK languages, or using large-character-inventory fonts like Arial Unicode, Code2000, Lucida Grande, etc. (subject to proper licensing), will subset the fonts appropriately before applying WebOTF compression/packaging. The extension ".webotf" is suggested for files using this format. Overall file structure ====================== All values in the WebOTF file are stored in big-endian format, like TrueType and OpenType. The WebOTF file consists of a 44-byte header, followed by a variable-size table directory, a number of OpenType fonts tables, an optional block of extended metadata, and an optional block of private data: WebOTFFile: WebOTFHeader TableDirectory[] OpenType Tables[] Extended Metadata Private Data The main body of the file consists of the same collection of tables as the original uncompressed OpenType font, with one exception; each table is separately compressed (see below), and the OpenType table directory is replaced by the WebOTF table directory. The exception mentioned above is that any DSIG table, if present, is removed from the font. This is because the process of compression and subsequent decompression will invalidate the signature, as the reconstituted font will (normally) not be binary-identical to the original. If digital signature support is required, it would be possible to specify a new signature table for the compressed font, along the same lines as DSIG in OpenType; existing tools could easily be extended to support this, as the two formats are so similar in overall structure. Header ====== The header includes an identifying signature and indicates the kind of OpenType data included in the file; it also has a font version number, offsets to additional data chunks, and the number of entries in the following table directory: WebOTFHeader: UInt32 signature 0x774F5446 ('wOTF') UInt32 flavor The "sfnt version" of the original file (i.e., 0x00010000 or 'OTTO') UInt16 majorVersion Version of the WebOTF font UInt16 minorVersion UInt32 length Total size of the WebOTF file UInt32 metaOffset Offset to metadata block, from beginning of WebOTF UInt32 metaLength Length of compressed metadata block UInt32 metaOrigLength Uncompressed size of metadata block UInt32 privOffset Offset to private data block UInt32 privLength Length of private data block UInt32 numTables Number of entries in directory of OpenType tables UInt32 totalSize Total size of the uncompressed OpenType tables Table directory =============== The table directory follows immediately after the file header. Each entry in the table directory is 20 bytes. The entries must be sorted in ascending order by tag, to permit binary search. TableDirEntry: UInt32 tag 4-byte table identifier (see OT spec) UInt32 offset Offset to the data, from beginning of WebOTF file UInt32 compLength Length of the compressed data (see note below) UInt32 origLength Length of the uncompressed table (from OT table dir) UInt32 origChecksum Checksum of the uncompressed table (see OT spec) NOTE: It is possible that some tables, particularly small ones, may not be worth compressing. It is permissible to store the original table, uncompressed, in the WebOTF file. This is indicated by compLength >= origLength in the table directory. Therefore, a tool creating WebOTF fonts MUST check that the compressed data for each table is smaller than the original uncompressed data. If this is not the case, it MUST store the table in uncompressed form. (NB: it is possible for compLength to be larger than origLength in this case, because the uncompressed table may have up to 3 bytes of padding at the end which are not included in the origLength count.) OpenType Tables =============== The OpenType tables in the WebOTF file are exactly the same as the tables in the original OpenType file, except that each table may have been compressed by the compress2() function of zlib. Tables may be stored in any order. There is no requirement for any specific alignment of tables or padding between tables, except that when a table is stored uncompressed (see above), it MUST begin on a 4-byte boundary and be padded with zeros if necessary so that its length is a multiple of 4. The "compLength" field in the table directory will record the complete (padded) length of the table data, and may therefore be up to 3 bytes larger than the "origLength". Metadata Block ============== The WebOTF font file may optionally include a block of extended metadata, allowing the inclusion of more extensive metadata than is present directly in the OpenType font. The metadata block consists of XML data compressed by zlib; the file header specifies both the size of the actual compressed and the original uncompressed size in order to facilitate memory allocation. The metadata (if present) is always compressed, never stored in uncompressed form. If no extended metadata is present, the offset and lengths in the WebOTF header should be set to zero. If the extended metadata is invalid (for example, the offset/length indicate a range outside of the actual WebOTF file, or the data cannot be decompressed, or it is not well-formed XML), the WebOTF processor should proceed as if the metadata block is absent; the font itself can still be used (provided its OpenType data is valid). WebOTF processors are not required to interpret the extended metadata, which has no influence on the usability of the embedded OpenType font data. However, if they provide a means for users to view information about fonts (such as a "Font Information" panel) then they are encouraged to treat the metadata block as the primary source, falling back on the font's 'name' table entries when extended metadata elements are not present. The specific format of the XML metadata is still to be determined, in consultation with interested parties. An outline of a possible format is included in Appendix A below. Private Data Block ================== The WebOTF font file may optionally include a block of arbitrary data, allowing font creators to include whatever information they wish. WebOTF processors should make no assumptions about the content of any private block; it may (for example) contain ASCII or Unicode text, or some vendor-defined binary data, and it may be compressed and/or encrypted, but as far as WebOTF is concerned it is simply an array of bytes. Only the font developer or vendor responsible for the private block is expected to understand its contents. If no private data is present, the offset and length in the WebOTF header should be set to zero. However, as a conforming WebOTF processor does not interpret or even need to access the private data in any way, it will simply ignore these fields. Only a private vendor-specific tool would use them. APPENDIX A: Draft of Extended Metadata ====================================== A member of the Demo font family. This font is a humanist sans serif style designed for optimal legibility in low-resolution environments. It can be obtained from fontvendor.com. A license goes here. Un permis va ici. Copyright ©2009 Font Vendor" 저작권 ©2009 Font Vendor" Demo Font is a trademark of Font Vendor Demo Font est une marque déposée de Font Vendor Demo Font ist ein eingetragenes Warenzeichen der Font Vendor Demo Font はである Font Vendor のの商標