Пример #1
0
        private int DecompressTable(MemoryStream output, BigEndianReader reader, WoffTableEntry table, uint length)
        {
            int pos = (int)output.Position;

            using (var streamIn = new MemoryStream(reader.Read((int)table.CompressedLength)))
            {
#if NET6_0
                using (var compress = new System.IO.Compression.ZLibStream(streamIn, System.IO.Compression.CompressionMode.Decompress))
                {
                    compress.CopyTo(output);
                }
#else
                using (InflaterInputStream decompressor = new InflaterInputStream(streamIn))
                {
                    decompressor.CopyTo(output);
                }
#endif
            }

            int len = (int)(output.Position - pos);
            if (len != length)
            {
                return(-1);
            }
            else
            {
                return(len);
            }
        }
Пример #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);
        }
Пример #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));
        }