Пример #1
0
        protected FontFileType Identify()
        {
            Debug.Assert(m_fs != null);

            FontFileType fft = FontFileType.INVALID;

            // read the first four bytes in the file
            MBOBuffer buf = ReadPaddedBuffer(0, 4);

            if (buf != null)
            {
                OTTag tag = new OTTag(buf.GetBuffer());

                if (IsValidSfntVersion(tag))
                {
                    fft = FontFileType.SINGLE;
                }
                else if ((string)tag == "ttcf")
                {
                    fft = FontFileType.COLLECTION;
                }
            }

            return(fft);
        }
Пример #2
0
        /// <summary>Read part of filestream into MBOBuffer</summary>
        public MBOBuffer ReadPaddedBuffer(uint filepos, uint length)
        {
            // allocate a buffer to hold the table
            MBOBuffer buf = new MBOBuffer(filepos, length);

            // read the table
            m_fs.Seek(filepos, SeekOrigin.Begin);
            int nBytes = m_fs.Read(buf.GetBuffer(), 0, (int)length);

            if (nBytes != length)
            {
                // check for premature EOF
                if (m_fs.Position == m_fs.Length)
                {
                    // EOF
                }
                else
                {
                    // Read Error
                }

                buf = null;
            }

            return(buf);
        }
Пример #3
0
        public static bool BinaryEqual(MBOBuffer buf1, MBOBuffer buf2)
        {
            bool bEqual = true;

            if (buf1.GetLength() != buf2.GetLength())
            {
                bEqual = false;
            }
            else
            {
                byte [] b1 = buf1.GetBuffer();
                byte [] b2 = buf2.GetBuffer();
                for (int i = 0; i < b1.Length; i++)
                {
                    if (b1[i] != b2[i])
                    {
                        bEqual = false;
                        break;
                    }
                }
            }

            return(bEqual);
        }
Пример #4
0
            protected byte[] GenerateFormat12Subtable(uint [] map)
            {
                bool bFound = false;
                uint CurChar = 0;
                ArrayList arrSegments = new ArrayList();
                segment12 seg = new segment12();

                while (CurChar < map.Length)
                {
                    // find the startCode char in this segment
                    bFound = false;
                    for (uint i=CurChar; i<map.Length; i++)
                    {
                        if (map[i] != 0)
                        {
                            seg.startCharCode = i;
                            bFound = true;
                            break;
                        }
                    }
                    if (bFound)
                    {
                        // find the endCode character in this segment
                        CurChar = seg.startCharCode;
                        if (CurChar < map.Length-2)
                        {
                            while (CurChar < map.Length - 1)
                            {
                                if (map[CurChar]+1 == map[CurChar+1] && 
                                    CurChar != map.Length-2)
                                {
                                    CurChar++;
                                }
                                else
                                {
                                    seg.endCharCode = CurChar;
                                    break;
                                }
                            }
                        }
                        else if (CurChar == map.Length - 1)
                        {
                            seg.endCharCode = CurChar;
                        }
                        else
                        {
                            Debug.Assert(false);
                        }
                        Debug.Assert(seg.startCharCode <= seg.endCharCode);

                        // store the start glyph ID for this segment
                        seg.startGlyphID = map[seg.startCharCode];
                    
                        // add the segment to the array
                        arrSegments.Add(seg);
                        Debug.Assert(arrSegments.Count < map.Length, 
                                     "more segments than characters");
                        CurChar = (uint)(seg.endCharCode + 1);
                        seg = new segment12();
                    }
                    else
                    {
                        break;
                    }
                }

                // allocate a buffer for the subtable

                uint nSize = (uint)(16 + 12 * arrSegments.Count);
                MBOBuffer buf = new MBOBuffer(nSize);

                // set the data
                buf.SetUshort(12,  (uint)Format12.FieldOffsets.format);
                buf.SetUshort(0,   (uint)Format12.FieldOffsets.reserved);
                buf.SetUint(nSize, (uint)Format12.FieldOffsets.length);
                buf.SetUint(0,     (uint)Format12.FieldOffsets.language);
                buf.SetUint((uint)arrSegments.Count, 
                            (uint)Format12.FieldOffsets.nGroups);

                for (int i=0; i<arrSegments.Count; i++)
                {
                    seg = (segment12)arrSegments[i];
                    buf.SetUint(seg.startCharCode, (uint)
                                (Format12.FieldOffsets.firstGroup + i*12));
                    buf.SetUint(seg.endCharCode,   (uint)
                                (Format12.FieldOffsets.firstGroup + i*12 + 4));
                    buf.SetUint(seg.startGlyphID,  (uint)
                                (Format12.FieldOffsets.firstGroup + i*12 + 8));
                }

                return buf.GetBuffer();
            }
Пример #5
0
            protected byte[] GenerateFormat4Subtable(uint [] map)
            {
                bool bFound = false;
                uint CurChar = 0;
                ArrayList arrSegments = new ArrayList();
                segment4 seg = new segment4();

                while (CurChar < map.Length)
                {
                    // find the startCode char in this segment
                    bFound = false;
                    for (uint i=CurChar; i<map.Length; i++)
                    {
                        if (map[i] != 0)
                        {
                            seg.startCode = (ushort)i;
                            bFound = true;
                            break;
                        }
                    }
                    if (bFound)
                    {
                        // count number of chars available for delta 
                        // representation
                        short delta = (short)
                            (map[seg.startCode] - seg.startCode);
                        uint nDelta = 1;
                        for (int i=seg.startCode+1; i<map.Length; i++)
                        {
                            if ((ushort)(i+delta) == (ushort)(map[i]))
                            {
                                nDelta++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        
                        // count number of chars available for rangeoffset 
                        // to glyph id representation
                        uint nRangeGlyph=1;
                        if (nDelta == 1)
                        {
                            for (int i=seg.startCode+1; i<map.Length; i++)
                            {
                                if (map[i] == 0)
                                {
                                    // don't keep the zero if it's followed 
                                    // by another zero
                                    if (i+1 < map.Length)
                                    {
                                        if (map[i+1] == 0)
                                        {
                                            break;
                                        }
                                    }
                                    // don't keep the zero if it's followed by
                                    // a delta segment
                                    if (i+3 < map.Length)
                                    {
                                        if ((ushort)(map[i+1]+1) == 
                                            (ushort)(map[i+2]) &&
                                            (ushort)(map[i+2]+1) == 
                                            (ushort)(map[i+3]))
                                        {
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                else if (i+2 < map.Length)
                                {
                                    // stop if this is the start of a two 
                                    // glyph delta segment
                                    if ((ushort)(map[i  ]+1) == 
                                        (ushort)(map[i+1]) &&
                                        (ushort)(map[i+1]+1) == 
                                        (ushort)(map[i+2]))
                                    {
                                        break;
                                    }
                                }
                                else if (i+1 < map.Length)
                                {
                                    // stop if we're at the end of the map
                                    if ((ushort)(map[i]+1) == 
                                        (ushort)(map[i+1]))
                                    {
                                        break;
                                    }
                                }

                                nRangeGlyph++;
                            }
                        }

                        // choose delta or rangeOffset representation
                        if (nDelta >= nRangeGlyph)
                        {
                            // set the endCode character for this segment
                            CurChar = seg.startCode;
                            if (CurChar < 65535)
                            {
                                seg.endCode = (ushort)
                                    (seg.startCode + nDelta - 1);
                                CurChar = seg.endCode;
                            }
                            else if (CurChar == 65535)
                            {
                                seg.endCode = 65535;
                            }
                            else
                            {
                                Debug.Assert(false);
                            }
                            Debug.Assert(seg.startCode <= seg.endCode);

                            // calculate the id delta
                            seg.idDelta = 
                                (short)(map[seg.startCode] - seg.startCode);
                    
                            // add the segment to the array
                            arrSegments.Add(seg);
                            Debug.Assert(arrSegments.Count < 65536);
                            CurChar = (uint)(seg.endCode + 1);
                            seg = new segment4();
                        }
                        else
                        {
                            // set the endCode character for this segment
                            CurChar = seg.startCode;
                            if (CurChar < 65535)
                            {
                                seg.endCode = 
                                    (ushort)(seg.startCode + nRangeGlyph - 1);
                                CurChar = seg.endCode;

                                Debug.Assert(seg.startCode != seg.endCode);
                            }
                            else if (CurChar == 65535)
                            {
                                seg.endCode = 65535;
                            }
                            else
                            {
                                Debug.Assert(false);
                            }

                            // store each character's glyph value in the 
                            // glyphID array

                            int nCount = seg.endCode-seg.startCode+1;
                            seg.glyphIdArray = new ushort[nCount];
                            for (ushort i=0; i<nCount; i++)
                            {
                                seg.glyphIdArray[i] = 
                                    (ushort)map[seg.startCode+i];
                            }

                            // add the segment to the array
                            arrSegments.Add(seg);
                            Debug.Assert(arrSegments.Count < 65536);
                            CurChar = (uint)(seg.endCode + 1);
                            seg = new segment4();
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                // add a final segment if needed
                bool bNeedFinal = true;
                if (arrSegments.Count != 0)
                {
                    segment4 lastseg = (segment4)
                        arrSegments[arrSegments.Count-1];
                    if (lastseg.endCode == 0xffff)
                    {
                        bNeedFinal = false;
                    }
                }
                if (bNeedFinal)
                {
                    segment4 segFinal = new segment4();
                    segFinal.startCode = 0xffff;
                    segFinal.endCode = 0xffff;
                    segFinal.idDelta = 1;
                    arrSegments.Add(segFinal);
                }

                // allocate a buffer for the subtable

                ushort nSize = (ushort)(16 + 8 * arrSegments.Count);
                for (int i=0; i<arrSegments.Count; i++)
                {
                    segment4 s = (segment4)arrSegments[(int)i];
                    if (s.glyphIdArray != null)
                    {
                        nSize += (ushort)(s.glyphIdArray.Length*2);
                    }
                }
                MBOBuffer buf = new MBOBuffer(nSize);

                // set the data

                ushort segCountX2 = (ushort)(arrSegments.Count*2);
                ushort searchRange = (ushort)
                    (2 * util.MaxPower2LE((ushort)(arrSegments.Count)));
                ushort entrySelector = util.Log2((ushort)(searchRange/2));
                ushort rangeShift = (ushort)(segCountX2 - searchRange);

                buf.SetUshort(4,             
                              (uint)Format4.FieldOffsets.format);
                buf.SetUshort(nSize,
                              (uint)Format4.FieldOffsets.length);
                buf.SetUshort(0, 
                              (uint)Format4.FieldOffsets.language);
                buf.SetUshort(segCountX2, 
                              (uint)Format4.FieldOffsets.segCountX2);
                buf.SetUshort(searchRange, 
                              (uint)Format4.FieldOffsets.searchRange);
                buf.SetUshort(entrySelector, 
                              (uint)Format4.FieldOffsets.entrySelector);
                buf.SetUshort(rangeShift,
                              (uint)Format4.FieldOffsets.rangeShift);

                uint endOffset = (uint)Format4.FieldOffsets.endCode;
                uint startOffset = (uint)Format4.FieldOffsets.endCode + 
                    2*(uint)arrSegments.Count + 2;
                uint idDeltaOffset = startOffset + 2*(uint)arrSegments.Count;
                uint idRangeOffset = idDeltaOffset + 2*(uint)arrSegments.Count;

                int nGlyphIdCount = 0;
                for (uint i=0; i<arrSegments.Count; i++)
                {
                    segment4 s = (segment4)arrSegments[(int)i];

                    if (s.glyphIdArray != null)
                    {
                        s.idRangeOffset = (ushort)
                            ((arrSegments.Count - i + nGlyphIdCount)*2);
                        nGlyphIdCount += s.glyphIdArray.Length;
                    }

                    buf.SetUshort(s.endCode, endOffset + i*2);
                    buf.SetUshort(s.startCode, startOffset + i*2);
                    buf.SetShort(s.idDelta, idDeltaOffset + i*2);
                    buf.SetUshort(s.idRangeOffset, idRangeOffset + i*2);

                }
                uint glyphIdPos = idRangeOffset + 2*(uint)arrSegments.Count;
                for (uint i=0; i<arrSegments.Count; i++)
                {
                    segment4 s = (segment4)arrSegments[(int)i];
                    if (s.glyphIdArray != null)
                    {
                        for (uint j=0; j<s.glyphIdArray.Length; j++)
                        {
                            buf.SetUshort(s.glyphIdArray[j], glyphIdPos);
                            glyphIdPos += 2;
                        }
                    }
                }

                
                return buf.GetBuffer();
            }
Пример #6
0
            protected byte[] GenerateFormat0Subtable( uint [] map, 
                                                      ushort language )
            {
                // allocate the buffer
                MBOBuffer buf = new MBOBuffer(262);

                // set the data

                buf.SetUshort(0, (uint)Format0.FieldOffsets.format);
                buf.SetUshort(262, (uint)Format0.FieldOffsets.length);
                buf.SetUshort(language, (uint)Format0.FieldOffsets.language);
                for (int i=0; i<256; i++)
                {
                    buf.SetByte((byte)map[i], 
                                (uint)Format0.FieldOffsets.glyphIDArray + 
                                (uint)i);
                }

                // return the buffer

                return buf.GetBuffer();
            }
Пример #7
0
            // generate a new table from the cached data
            public override OTTable GenerateTable()
            {
                // generate the subtables
                ArrayList arrSubtableBuffers = new ArrayList();
                for (int i=0; i<m_arrSubtables.Count; i++)
                {
                    byte [] buf = null;
                    CachedSubtable st = (CachedSubtable)m_arrSubtables[i];

                    if (st.m_platID == 3 && st.m_encID == 10)
                    {
                        buf = GenerateFormat12Subtable(st.m_CharToGlyphMap);
                    }
                    else if (st.m_platID == 1 && st.m_encID == 0)
                    {
                        buf = GenerateFormat0Subtable(st.m_CharToGlyphMap, 0);
                    }
                    else
                    {
                        buf = GenerateFormat4Subtable(st.m_CharToGlyphMap);
                    }
                    arrSubtableBuffers.Add(buf);
                }


                // calculate the number of bytes required for the cmap table

                uint nBytes = 4; // version and number of subtables
                // encoding table entries
                nBytes += 8 * (uint)m_arrSubtables.Count; 
                for (int i=0; i<m_arrSubtables.Count; i++)
                {
                    byte[] buf = (byte[])arrSubtableBuffers[i];
                    nBytes += (uint)buf.Length;
                }

                // create a buffer for the new cmap table

                MBOBuffer newbuf = new MBOBuffer(nBytes);


                // populate the buffer
                
                // version and number of encoding tables
                newbuf.SetUshort(0, (uint)
                                 Table_cmap.FieldOffsets.TableVersionNumber);
                newbuf.SetUshort((ushort)m_arrSubtables.Count, (uint)
                                 Table_cmap.FieldOffsets.NumberOfEncodingTables
                                 );

                // encoding table entries
                uint SubtableOffset = (uint)(4 + 8*m_arrSubtables.Count);
                for (int i=0; i < m_arrSubtables.Count; i++)
                {
                    CachedSubtable st = (CachedSubtable)m_arrSubtables[i];
                    uint eteOffset = 
                        (uint)Table_cmap.FieldOffsets.EncodingTableEntries + 
                        (uint)i*8;
                    newbuf.SetUshort(st.m_platID, eteOffset);
                    newbuf.SetUshort(st.m_encID,  eteOffset+2);
                    newbuf.SetUint(SubtableOffset, eteOffset+4);
                    byte[] buf = (byte[])arrSubtableBuffers[i];
                    SubtableOffset += (uint)buf.Length;
                }

                // subtables
                byte[] TableBuf = newbuf.GetBuffer();
                SubtableOffset = (uint)(4 + 8*m_arrSubtables.Count);
                for (int i=0; i<m_arrSubtables.Count; i++)
                {
                    byte[] SubtableBuf = (byte[])arrSubtableBuffers[i];
                    System.Buffer.BlockCopy(SubtableBuf, 0, TableBuf, 
                                            (int)SubtableOffset, 
                                            SubtableBuf.Length);
                    SubtableOffset += (uint)SubtableBuf.Length;
                }

                // put the buffer into a Table_cmap object and return it

                Table_cmap cmapTable = new Table_cmap("cmap", newbuf);

                return cmapTable;
            }
Пример #8
0
            private void writeEBDTBuffer( MBOBuffer bufEBDT, uint imageDataOffset, imageCache ic, ushort imageFormat )
            {                
                switch( imageFormat )
                {
                    case 1:
                    {
                        imageCache1 ic1 = (imageCache1)ic;

                        bufEBDT.SetByte( ic1.smallMetrics.height,        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.height );
                        bufEBDT.SetByte( ic1.smallMetrics.width,        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.width );
                        bufEBDT.SetSbyte( ic1.smallMetrics.BearingX,    imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.BearingX );
                        bufEBDT.SetSbyte( ic1.smallMetrics.BearingY,    imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.BearingY );
                        bufEBDT.SetByte( ic1.smallMetrics.Advance,        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.Advance );
                        
                        System.Buffer.BlockCopy( ic1.imageData, 0, bufEBDT.GetBuffer(), (int)(imageDataOffset + Table_EBDT.smallGlyphMetrics.bufSize), ic1.imageData.Length );
                        break;                    
                    }
                    case 2:
                    {
                        imageCache2 ic2 = (imageCache2)ic;

                        bufEBDT.SetByte( ic2.smallMetrics.height,        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.height );
                        bufEBDT.SetByte( ic2.smallMetrics.width,        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.width );
                        bufEBDT.SetSbyte( ic2.smallMetrics.BearingX,    imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.BearingX );
                        bufEBDT.SetSbyte( ic2.smallMetrics.BearingY,    imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.BearingY );
                        bufEBDT.SetByte( ic2.smallMetrics.Advance,        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.Advance );
                        
                        System.Buffer.BlockCopy( ic2.imageData, 0, bufEBDT.GetBuffer(), (int)(imageDataOffset + Table_EBDT.smallGlyphMetrics.bufSize), ic2.imageData.Length );
                        break;
                    }
                    case 5:
                    {
                        imageCache5 ic5 = (imageCache5)ic;
                    
                        System.Buffer.BlockCopy( ic5.imageData, 0, bufEBDT.GetBuffer(), (int)imageDataOffset, ic5.imageData.Length );
                        break;
                    }
                    case 6:
                    {
                        imageCache6 ic6 = (imageCache6)ic;

                        bufEBDT.SetByte( ic6.bigMetrics.height,            imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.height );
                        bufEBDT.SetByte( ic6.bigMetrics.width,            imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.width );
                        bufEBDT.SetSbyte( ic6.bigMetrics.horiBearingX,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.horiBearingX );
                        bufEBDT.SetSbyte( ic6.bigMetrics.horiBearingY,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.horiBearingY );
                        bufEBDT.SetByte( ic6.bigMetrics.horiAdvance,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.horiAdvance );
                        bufEBDT.SetSbyte( ic6.bigMetrics.vertBearingX,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.vertBearingX );
                        bufEBDT.SetSbyte( ic6.bigMetrics.vertBearingY,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.vertBearingY );
                        bufEBDT.SetByte( ic6.bigMetrics.vertAdvance,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.vertAdvance );                        
                        
                        System.Buffer.BlockCopy( ic6.imageData, 0, bufEBDT.GetBuffer(), (int)(imageDataOffset + Table_EBDT.bigGlyphMetrics.bufSize), ic6.imageData.Length );
                        break;
                    }
                    case 7:
                    {
                        imageCache7 ic7 = (imageCache7)ic;

                        bufEBDT.SetByte( ic7.bigMetrics.height,            imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.height );
                        bufEBDT.SetByte( ic7.bigMetrics.width,            imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.width );
                        bufEBDT.SetSbyte( ic7.bigMetrics.horiBearingX,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.horiBearingX );
                        bufEBDT.SetSbyte( ic7.bigMetrics.horiBearingY,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.horiBearingY );
                        bufEBDT.SetByte( ic7.bigMetrics.horiAdvance,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.horiAdvance );
                        bufEBDT.SetSbyte( ic7.bigMetrics.vertBearingX,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.vertBearingX );
                        bufEBDT.SetSbyte( ic7.bigMetrics.vertBearingY,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.vertBearingY );
                        bufEBDT.SetByte( ic7.bigMetrics.vertAdvance,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.vertAdvance );                        
                        
                        System.Buffer.BlockCopy( ic7.imageData, 0, bufEBDT.GetBuffer(), (int)(imageDataOffset + Table_EBDT.bigGlyphMetrics.bufSize), ic7.imageData.Length );
                        break;
                    }
                    case 8:
                    {
                        imageCache8 ic8 = (imageCache8)ic;

                        bufEBDT.SetByte( ic8.smallMetrics.height,        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.height );
                        bufEBDT.SetByte( ic8.smallMetrics.width,        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.width );
                        bufEBDT.SetSbyte( ic8.smallMetrics.BearingX,    imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.BearingX );
                        bufEBDT.SetSbyte( ic8.smallMetrics.BearingY,    imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.BearingY );
                        bufEBDT.SetByte( ic8.smallMetrics.Advance,        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.FieldOffsets.Advance );                    
                        //pad
                        bufEBDT.SetByte( 0,                        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.bufSize );    
                        bufEBDT.SetUshort( ic8.numComponents,    imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.bufSize + 1 );    
                        
                        for( ushort i = 0; i < ic8.numComponents; i++ )
                        {
                            Table_EBDT.ebdtComponent ec = ic8.getComponent( i );
                            bufEBDT.SetUshort( ec.glyphCode,    imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.bufSize + 3 + (uint)(Table_EBDT.ebdtComponent.bufSize * i ));
                            bufEBDT.SetSbyte( ec.xOffset,        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.bufSize + 3 + (uint)(Table_EBDT.ebdtComponent.bufSize * i ) + 2 );
                            bufEBDT.SetSbyte( ec.yOffset,        imageDataOffset + (uint)Table_EBDT.smallGlyphMetrics.bufSize + 3 + (uint)(Table_EBDT.ebdtComponent.bufSize * i ) + 3 );    
                        }
                        break;
                    }
                    case 9:
                    {
                        imageCache9 ic9 = (imageCache9)ic;

                        bufEBDT.SetByte( ic9.bigMetrics.height,            imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.height );
                        bufEBDT.SetByte( ic9.bigMetrics.width,            imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.width );
                        bufEBDT.SetSbyte( ic9.bigMetrics.horiBearingX,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.horiBearingX );
                        bufEBDT.SetSbyte( ic9.bigMetrics.horiBearingY,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.horiBearingY );
                        bufEBDT.SetByte( ic9.bigMetrics.horiAdvance,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.horiAdvance );
                        bufEBDT.SetSbyte( ic9.bigMetrics.vertBearingX,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.vertBearingX );
                        bufEBDT.SetSbyte( ic9.bigMetrics.vertBearingY,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.vertBearingY );
                        bufEBDT.SetByte( ic9.bigMetrics.vertAdvance,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.FieldOffsets.vertAdvance );                            
                        
                        bufEBDT.SetUshort( ic9.numComponents,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.bufSize );    
                        
                        for( ushort i = 0; i < ic9.numComponents; i++ )
                        {
                            Table_EBDT.ebdtComponent ec = ic9.getComponent( i );
                            bufEBDT.SetUshort( ec.glyphCode,    imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.bufSize + 2 + (uint)(Table_EBDT.ebdtComponent.bufSize * i ));
                            bufEBDT.SetSbyte( ec.xOffset,        imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.bufSize + 2 + (uint)(Table_EBDT.ebdtComponent.bufSize * i ) + 2 );
                            bufEBDT.SetSbyte( ec.yOffset,        imageDataOffset + (uint)Table_EBDT.bigGlyphMetrics.bufSize + 2 + (uint)(Table_EBDT.ebdtComponent.bufSize * i ) + 3 );    
                        }
                        break;
                    }
                }                
            }
Пример #9
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);
        }
Пример #10
0
        public new MBOBuffer ReadPaddedBuffer(uint filepos, uint length)
        {
            // allocate a buffer to hold the table
            MBOBuffer buf = new MBOBuffer(filepos, length);

            // read the table
            m_fs.Seek(filepos, SeekOrigin.Begin);
            int nBytes = m_fs.Read(buf.GetBuffer(), 0, (int)length);
            if (nBytes != length)
            {
                // check for premature EOF
                if (m_fs.Position == m_fs.Length)
                {
                    m_Validator.Error(E._GEN_E_EOFError, null);
                }
                else
                {
                    m_Validator.Error(E._GEN_E_ReadError, null);
                }

                buf = null;
            }

            return buf;
        }
Пример #11
0
        public static bool BinaryEqual(MBOBuffer buf1, MBOBuffer buf2)
        {
            bool bEqual = true;

            if (buf1.GetLength() != buf2.GetLength())
            {
                bEqual = false;
            }
            else
            {
                byte [] b1 = buf1.GetBuffer();
                byte [] b2 = buf2.GetBuffer();
                for (int i=0; i<b1.Length; i++)
                {
                    if (b1[i] != b2[i])
                    {
                        bEqual = false;
                        break;
                    }
                }
            }

            return bEqual;
        }