コード例 #1
0
        private bool ReadData(Stream stream)
        {
            if (stream == null)
            {
                return(false);
            }

            int bytesRead = 0;

            byte[] header = WoffBuffer.ReadBytes(stream, WoffUtils.Woff1DirSize, out bytesRead);

            _tag          = WoffBuffer.ReadUInt32BE(header, 0);
            _offset       = WoffBuffer.ReadUInt32BE(header, 4);
            _compLength   = WoffBuffer.ReadUInt32BE(header, 8);
            _origLength   = WoffBuffer.ReadUInt32BE(header, 12);
            _origChecksum = WoffBuffer.ReadUInt32BE(header, 16);

            if (_origLength > 0)
            {
                _padding = WoffUtils.CalculatePadding(_origLength);
            }

            return(true);
        }
コード例 #2
0
        private bool ReadData(Stream stream, bool isTrueType)
        {
            if (stream == null)
            {
                return(false);
            }
            var tableFlags = WoffTable.TableFlags;

            int bytesRead = 0;

            // UInt8: flags	table type and flags
            _flags = (byte)stream.ReadByte();
            // The interpretation of the flags field is as follows:
            // 1. Bits [0..5] contain an index to the "known tag" table, which represents tags likely to appear in fonts
            int tagIndex = _flags & 0x3F;

            // If the tag is not present in this table, then the value of this bit field is 63.
            if (tagIndex >= 63)
            {
                // UInt32: tag	4-byte tag (optional)
                _tag = WoffBuffer.ReadUInt32BE(WoffBuffer.ReadBytes(stream, 4, out bytesRead), 0);
                var name = WoffBuffer.TagString(_tag);

                for (int i = 0; i < tableFlags.Count; i++)
                {
                    if (string.Equals(name, tableFlags[i], StringComparison.Ordinal))
                    {
                        tagIndex = i;
                        break;
                    }
                }
            }
            else
            {
                _tag = WoffBuffer.TagInt(tableFlags[tagIndex]);
            }

            // 2. Bits 6 and 7 indicate the preprocessing transformation version number (0-3) that was applied to each table.
            int transformVersion = (_flags >> 5) & 0x3;

            // UIntBase128:	origLength	length of original table
            if (!WoffBuffer.ReadUIntBase128(stream, out _origLength))
            {
                return(false);
            }

            // UIntBase128	transformLength	transformed length (if applicable)
            //            _transformLength = _origLength;
            _compLength      = _origLength;
            _transformLength = 0;

            // For all tables in a font, except for 'glyf' and 'loca' tables, transformation version 0
            // indicates the null transform where the original table data is passed directly to the
            // Brotli compressor for inclusion in the compressed data stream.
            if (transformVersion == 0)
            {
                // "glyf" : 10,  "loca" : 11
                if (tagIndex == 10 || tagIndex == 11)
                {
                    if (!WoffBuffer.ReadUIntBase128(stream, out _transformLength))
                    {
                        return(false);
                    }
                    _compLength = _transformLength;
                }
            }
            // The transformation version "1", specified below, is optional and can be applied to
            // eliminate certain redundancies in the hmtx table data.
            if (transformVersion == 1)
            {
                // The transformation version 1 described in this subclause is optional and can only
                // be used when an input font is TrueType-flavored (i.e. has a glyf table)
                // "hmtx" : 3
                if (tagIndex == 3 && isTrueType)
                {
                    if (!WoffBuffer.ReadUIntBase128(stream, out _transformLength))
                    {
                        return(false);
                    }
                    _compLength = _transformLength;
                }
            }

            if (_origLength > 0)
            {
                _padding = WoffUtils.CalculatePadding(_origLength);
            }

            return(true);
        }