Esempio n. 1
0
        /*****************
         * private methods
         */

        private bool TestFileType()
        {
            m_FontFileType = Identify();

            switch (m_FontFileType)
            {
            case FontFileType.INVALID:
                close();
                return(false);

            case FontFileType.SINGLE:
                m_ttch   = null;
                m_nFonts = 1;
                return(true);

            case FontFileType.COLLECTION:
                m_ttch = TTCHeader.ReadTTCHeader(this);
                if (m_ttch != null)
                {
                    m_nFonts = m_ttch.DirectoryCount;
                }
                else
                {
                    m_nFonts = 0;
                }
                return(true);

            default:
                close();
                return(false);
            }
        }
Esempio n. 2
0
        /***************
         * constructors
         */
        /// <summary>Construct empty object except for <c>TableManager</c>
        /// </summary>
        public OTFile()
        {
            m_TableManager = new TableManager(this);

            m_FontFileType = FontFileType.INVALID;
            m_nFonts = 0;
            m_ttch = null;
        }
Esempio n. 3
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;
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        /*****************
        * private methods
        */
        private bool TestFileType()
        {
            m_FontFileType = Identify();

            switch (m_FontFileType)
            {
                case FontFileType.INVALID:
                    close();
                    return false;

                case FontFileType.SINGLE:
                    m_ttch = null;
                    m_nFonts = 1;
                    return true;

                case FontFileType.COLLECTION:
                    m_ttch = TTCHeader.ReadTTCHeader(this);
                    if (m_ttch != null)
                    {
                        m_nFonts = m_ttch.DirectoryCount;
                    }
                    else
                    {
                        m_nFonts = 0;
                    }
                    return true;
                default:
                    close();
                    return false;
            }
        }
Esempio n. 6
0
 /// <summary>Close filestream and set type to file type to 
 /// invalid.</summary>
 public void close()
 {
     if (m_fs != null)
     {
         m_fs.Close();
         m_fs = null;
     }
     m_TableManager = new TableManager(this); // JJF: Why?
     m_FontFileType = FontFileType.INVALID;
     m_ttch = null;
     m_nFonts = 0;
 }