예제 #1
0
        internal Typeface Read(BinaryReader reader)
        {
            //WOFF File
            //WOFFHeader        File header with basic font type and version, along with offsets to metadata and private data blocks.
            //TableDirectory    Directory of font tables, indicating the original size, compressed size and location of each table within the WOFF file.
            //FontTables        The font data tables from the input sfnt font, compressed to reduce bandwidth requirements.
            //ExtendedMetadata  An optional block of extended metadata, represented in XML format and compressed for storage in the WOFF file.
            //PrivateData       An optional block of private data for the font designer, foundry, or vendor to use.
            _header = ReadWOFFHeader(reader);
            if (_header == null)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine("can't read ");
#endif
                return(null); //notify user too
            }

            //
            WoffTableDirectory[] woffTableDirs = ReadTableDirectories(reader);
            if (woffTableDirs == null)
            {
                return(null);
            }
            //
            //try read each compressed table
            if (DecompressHandler == null)
            {
                if (WoffDefaultZlibDecompressFunc.DecompressHandler != null)
                {
                    DecompressHandler = WoffDefaultZlibDecompressFunc.DecompressHandler;
                }
                else
                {
#if DEBUG
                    System.Diagnostics.Debug.WriteLine("no Zlib DecompressHandler ");
#endif
                    return(null); //notify user too
                }
            }

            TableEntryCollection tableEntryCollection = CreateTableEntryCollection(woffTableDirs);

            using (MemoryStream decompressStream = new MemoryStream())
            {
                if (Extract(reader, woffTableDirs, decompressStream))
                {
                    using (ByteOrderSwappingBinaryReader reader2 = new ByteOrderSwappingBinaryReader(decompressStream))
                    {
                        decompressStream.Position = 0;
                        OpenFontReader openFontReader = new OpenFontReader();
                        return(openFontReader.ReadTableEntryCollection(tableEntryCollection, reader2));
                    }
                }
            }
            return(null);
        }
예제 #2
0
        static WoffHeader ReadWOFFHeader(BinaryReader reader)
        {
            //WOFFHeader
            //UInt32  signature         0x774F4646 'wOFF'
            //UInt32  flavor            The "sfnt version" of the input font.
            //UInt32  length            Total size of the WOFF file.
            //UInt16  numTables         Number of entries in directory of font tables.
            //UInt16  reserved          Reserved; set to zero.
            //UInt32  totalSfntSize     Total size needed for the uncompressed font data, including the sfnt header, directory, and font tables(including padding).
            //UInt16  majorVersion      Major version of the WOFF file.
            //UInt16  minorVersion      Minor version of the WOFF file.
            //UInt32  metaOffset        Offset to metadata block, from beginning of WOFF file.
            //UInt32  metaLength        Length of compressed metadata block.
            //UInt32  metaOrigLength    Uncompressed size of metadata block.
            //UInt32  privOffset        Offset to private data block, from beginning of WOFF file.
            //UInt32  privLength        Length of private data block.


            //signature
            byte b0 = reader.ReadByte();
            byte b1 = reader.ReadByte();
            byte b2 = reader.ReadByte();
            byte b3 = reader.ReadByte();

            if (!(b0 == 0x77 && b1 == 0x4f && b2 == 0x46 && b3 == 0x46))
            {
                return(null);
            }
            WoffHeader header = new WoffHeader();

            header.flavor    = reader.ReadUInt32();
            header.length    = reader.ReadUInt32();
            header.numTables = reader.ReadUInt16();
            ushort reserved = reader.ReadUInt16();

            header.totalSfntSize = reader.ReadUInt32();

            header.majorVersion = reader.ReadUInt16();
            header.minorVersion = reader.ReadUInt16();

            header.metaOffset         = reader.ReadUInt32();
            header.metaLength         = reader.ReadUInt32();
            header.metaOriginalLength = reader.ReadUInt32();

            header.privOffset = reader.ReadUInt32();
            header.privLength = reader.ReadUInt32();

            return(header);
        }