Beispiel #1
0
        public static WoffHeader ReadHeader(WoffVersionReader version, BigEndianReader reader)
        {
            uint   flavour       = reader.ReadUInt32();
            uint   length        = reader.ReadUInt32();
            ushort numTables     = reader.ReadUInt16();
            var    reserved      = reader.ReadUInt16();
            var    totalFontSize = reader.ReadUInt32();
            var    major         = reader.ReadUInt16();
            var    minor         = reader.ReadUInt16();

            WoffHeader header = new WoffHeader(version, numTables);


            header.Flavour          = flavour;
            header.Length           = length;
            header.TotalFontSize    = totalFontSize;
            header.WoffInnerVersion = new Version(major, minor);

            header.MetaDataOffset         = reader.ReadUInt32();
            header.MetaDataLength         = reader.ReadUInt32();
            header.MetaDataOriginalLength = reader.ReadUInt32();

            header.PrivateDataOffset = reader.ReadUInt32();
            header.PrivateDataLength = reader.ReadUInt32();

            return(header);
        }
Beispiel #2
0
        public override ITypefaceFont ReadTypefaceAfterVersion(BigEndianReader reader, IFontInfo forReference, string source)
        {
            long startOffset = reader.Position - VersionByteSize;

            WoffHeader            header = WoffHeader.ReadHeader(this, reader);
            List <WoffTableEntry> list   = new List <WoffTableEntry>();



            for (var i = 0; i < header.NumberOfTables; i++)
            {
                WoffTableEntry entry = new WoffTableEntry();
                entry.Read(reader);
                list.Add(entry);
            }

            list.Sort(delegate(WoffTableEntry one, WoffTableEntry two) { return(one.Offset.CompareTo(two.Offset)); });

            var entries = new WoffTableEntryList(list);
            var file    = new WoffFontFile(header, entries);

            var factory = this.GetTableFactory();

            foreach (var entry in entries)
            {
                var tbl = factory.ReadTable(entry.Tag, entries, reader);
                if (null != tbl)
                {
                    entry.SetTable(tbl);
                }
            }

            file.EnsureReferenceMatched(forReference);

            byte[] data = CopyStreamData(reader.BaseStream, startOffset);
            file.SetFileData(data, DataFormat.Woff);


            return(file);
        }
Beispiel #3
0
        public override ITypefaceInfo ReadTypefaceInfoAfterVersion(BigEndianReader reader, string source)
        {
            WoffHeader         header = WoffHeader.ReadHeader(this, reader);
            WoffTableEntryList list   = new WoffTableEntryList();

            bool hasOs2   = false;
            bool hasFHead = false;
            bool hasName  = false;

            for (var i = 0; i < header.NumberOfTables; i++)
            {
                WoffTableEntry entry = new WoffTableEntry();
                entry.Read(reader);
                list.Add(entry);

                if (entry.Tag == TrueTypeTableNames.WindowsMetrics)
                {
                    hasOs2 = true;
                }
                else if (entry.Tag == TrueTypeTableNames.FontHeader)
                {
                    hasFHead = true;
                }
                else if (entry.Tag == TrueTypeTableNames.NamingTable)
                {
                    hasName = true;
                }
            }

            if (!(hasOs2 || hasName) || !hasFHead)
            {
                return(new Utility.UnknownTypefaceInfo(source, "Not all the required tables (head with OS/2 or name) were found in the font file"));
            }

            return(ReadInfoFromTables(list, reader, source, hasOs2));
        }