Exemplo n.º 1
0
        /******************
         * protected methods
         */


        protected static OffsetTable ReadOffsetTable(OTFile file, uint filepos)
        {
            // read the Offset Table from the file

            const int SIZEOF_OFFSETTABLE = 12;

            OffsetTable ot = null;


            // read the offset table

            MBOBuffer buf = file.ReadPaddedBuffer(filepos, SIZEOF_OFFSETTABLE);

            if (buf != null)
            {
                if (OTFile.IsValidSfntVersion(buf.GetUint(0)))
                {
                    ot = new OffsetTable(buf);
                }
            }


            // now read the directory entries

            if (ot != null)
            {
                const int SIZEOF_DIRECTORYENTRY = 16;


                for (int i = 0; i < ot.numTables; i++)
                {
                    uint      dirFilePos = (uint)(filepos + SIZEOF_OFFSETTABLE + i * SIZEOF_DIRECTORYENTRY);
                    MBOBuffer DirEntBuf  = file.ReadPaddedBuffer(dirFilePos, SIZEOF_DIRECTORYENTRY);

                    if (DirEntBuf != null)
                    {
                        DirectoryEntry de = new DirectoryEntry(DirEntBuf);
                        ot.DirectoryEntries.Add(de);
                    }
                    else
                    {
                        Debug.Assert(false);
                        break;
                    }
                }
            }

            return(ot);
        }
Exemplo n.º 2
0
 // Offset relative to subtable start
 // Return value is relative to subtable start
 static public uint MaxOffset( MBOBuffer b, 
                               uint subtableOffset,
                               uint offset )
 {
     uint nRec = b.GetUint( subtableOffset + offset );
     return 
         offset + 4 + ( nRec * UVSMapping.BYTES_PER_RECORD ) - 1;
 }
Exemplo n.º 3
0
 public void Populate( MBOBuffer b, 
                       uint subtableOffset,
                       uint offset )
 {
     uint o = subtableOffset + offset;
     mappings = new List<UVSMapping>();
     numUVSMappings = b.GetUint( o );
     o += 4;
     for ( uint i = 0; i < numUVSMappings; i++ ) {
         UVSMapping r = new UVSMapping();
         r.Populate( b, o );
         mappings.Add( r );
         o += UVSMapping.BYTES_PER_RECORD;
     }
 }
Exemplo n.º 4
0
 // Offset relative to subtable start
 // Return value is relative to subtable start
 static public uint MaxOffset( MBOBuffer b, 
                               uint subtableOffset,
                               uint offset )
 {
     
     uint nRec = b.GetUint( subtableOffset + offset );
     return 
         offset + 4 + 
         ( nRec * UnicodeValueRange.BYTES_PER_RECORD )
         - 1;
 }
Exemplo n.º 5
0
 // Offset is relative to start of subtable
 public void Populate( MBOBuffer b, 
                       uint subtableOffset,
                       uint offset )
 {
     uint o = subtableOffset + offset;
     numUnicodeValueRanges = b.GetUint( o );
     ranges = new List<UnicodeValueRange>();
     o += 4;
     for ( uint i = 0; i < numUnicodeValueRanges; i++ ) {
         UnicodeValueRange r = new UnicodeValueRange();
         r.Populate( b, o );
         ranges.Add( r );
         o += UnicodeValueRange.BYTES_PER_RECORD;
     }
 }
Exemplo n.º 6
0
        /************************
         * public static methods
         */
        public static TTCHeader ReadTTCHeader(OTFile file)
        {
            TTCHeader ttc = null;

            const int SIZEOF_FIRSTTHREEFIELDS = 12;
            const int SIZEOF_UINT             = 4;

            // read the first three fields of the TTC Header
            // starting at the beginning of the file

            MBOBuffer buf = file.ReadPaddedBuffer(0, SIZEOF_FIRSTTHREEFIELDS);

            OTTag tag            = null;
            uint  version        = 0;
            uint  DirectoryCount = 0;

            if (buf != null)
            {
                tag            = new OTTag(buf.GetBuffer());
                version        = buf.GetUint(4);
                DirectoryCount = buf.GetUint(8);
            }


            // if the tag and the version and the dir count seem correct then
            // allocate a TTCHeader object and try to read the rest of the header
            if ((string)tag == "ttcf" &&
                (version == 0x00010000 || version == 0x00020000) &&
                12 + DirectoryCount * SIZEOF_UINT < file.GetFileLength())
            {
                ttc                = new TTCHeader();
                ttc.TTCTag         = tag;
                ttc.version        = version;
                ttc.DirectoryCount = DirectoryCount;

                // Directory offsets
                buf = file.ReadPaddedBuffer(SIZEOF_FIRSTTHREEFIELDS, DirectoryCount * SIZEOF_UINT);
                if (buf != null)
                {
                    for (uint i = 0; i < ttc.DirectoryCount; i++)
                    {
                        uint offset = buf.GetUint(i * SIZEOF_UINT);
                        ttc.DirectoryOffsets.Add(offset);
                    }
                }

                // only read Dsig fields if version 2.0 and last buffer was successfully read
                if ((version == 0x00010000 || version == 0x00020000) && buf != null)
                {
                    uint filepos = SIZEOF_FIRSTTHREEFIELDS + DirectoryCount * SIZEOF_UINT;
                    buf = file.ReadPaddedBuffer(filepos, 3 * SIZEOF_UINT);
                    if (buf != null)
                    {
                        // DsigTag
                        ttc.DsigTag = new OTTag(buf.GetBuffer());
                        if ((version == 0x00010000) && ((string)ttc.DsigTag != "DSIG"))
                        {
                            // failed v1 trial - reset & bail
                            ttc.DsigTag = null;
                            return(ttc);
                        }

                        // DsigLength
                        ttc.DsigLength = buf.GetUint(4);

                        // DsigOffset
                        ttc.DsigOffset = buf.GetUint(8);
                    }
                }
            }

            return(ttc);
        }