// 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;
            }
示例#2
0
        public virtual OTTable CreateTableObject(OTTag tag, MBOBuffer buf)
        {
            OTTable table = null;

            string sName = GetUnaliasedTableName(tag);

            switch (sName)
            {
                case "BASE": table = new Table_BASE(tag, buf); break;
                case "CFF ": table = new Table_CFF(tag, buf); break;
                case "cmap": table = new Table_cmap(tag, buf); break;
                case "cvt ": table = new Table_cvt(tag, buf); break;
                case "DSIG": table = new Table_DSIG(tag, buf); break;
                case "EBDT": table = new Table_EBDT(tag, buf); break;
                case "EBLC": table = new Table_EBLC(tag, buf); break;
                case "EBSC": table = new Table_EBSC(tag, buf); break;
                case "fpgm": table = new Table_fpgm(tag, buf); break;
                case "gasp": table = new Table_gasp(tag, buf); break;
                case "GDEF": table = new Table_GDEF(tag, buf); break;
                case "glyf": table = new Table_glyf(tag, buf); break;
                case "GPOS": table = new Table_GPOS(tag, buf); break;
                case "GSUB": table = new Table_GSUB(tag, buf); break;
                case "hdmx": table = new Table_hdmx(tag, buf); break;
                case "head": table = new Table_head(tag, buf); break;
                case "hhea": table = new Table_hhea(tag, buf); break;
                case "hmtx": table = new Table_hmtx(tag, buf); break;
                case "JSTF": table = new Table_JSTF(tag, buf); break;
                case "kern": table = new Table_kern(tag, buf); break;
                case "loca": table = new Table_loca(tag, buf); break;
                case "LTSH": table = new Table_LTSH(tag, buf); break;
                case "maxp": table = new Table_maxp(tag, buf); break;
                case "name": table = new Table_name(tag, buf); break;
                case "OS/2": table = new Table_OS2(tag, buf); break;
                case "PCLT": table = new Table_PCLT(tag, buf); break;
                case "post": table = new Table_post(tag, buf); break;
                case "prep": table = new Table_prep(tag, buf); break;
                case "VDMX": table = new Table_VDMX(tag, buf); break;
                case "vhea": table = new Table_vhea(tag, buf); break;
                case "vmtx": table = new Table_vmtx(tag, buf); break;
                case "VORG": table = new Table_VORG(tag, buf); break;
                //case "Zapf": table = new Table_Zapf(tag, buf); break;
                default: table = new Table__Unknown(tag, buf); break;
            }

            return table;
        }
            // constructor

            public cmap_cache(Table_cmap OwnerTable)
            {
                m_arrSubtables = new SubtableArray();

                for ( uint iSubtable=0; 
                      iSubtable < OwnerTable.NumberOfEncodingTables; 
                      iSubtable++ ) {
                    EncodingTableEntry ete = 
                        OwnerTable.GetEncodingTableEntry(iSubtable);
                    Subtable st = OwnerTable.GetSubtable(ete);

                    CachedSubtable cst = new 
                        CachedSubtable(ete.platformID, ete.encodingID);
                    cst.m_CharToGlyphMap = st.GetMap();

                    m_arrSubtables.Add(cst);
                    
                    if (cst.m_platID == 3 && cst.m_encID == 10)
                    {
                        m_DefaultSubtable = cst;
                    }
                    
                    if ( cst.m_platID == 3 && cst.m_encID == 1 && 
                         m_DefaultSubtable == null)
                    {
                        m_DefaultSubtable = cst;
                    }
                }
            }