Example #1
0
 public virtual IDictionary <int, int[]> GetActiveCmap()
 {
     OpenTypeParser.CmapTable cmaps = fontParser.GetCmapTable();
     if (cmaps.cmapExt != null)
     {
         return(cmaps.cmapExt);
     }
     else
     {
         if (!cmaps.fontSpecific && cmaps.cmap31 != null)
         {
             return(cmaps.cmap31);
         }
         else
         {
             if (cmaps.fontSpecific && cmaps.cmap10 != null)
             {
                 return(cmaps.cmap10);
             }
             else
             {
                 if (cmaps.cmap31 != null)
                 {
                     return(cmaps.cmap31);
                 }
                 else
                 {
                     return(cmaps.cmap10);
                 }
             }
         }
     }
 }
Example #2
0
        /// <summary>Reads the several maps from the table 'cmap'.</summary>
        /// <remarks>
        /// Reads the several maps from the table 'cmap'. The maps of interest are 1.0 for symbolic
        /// fonts and 3.1 for all others. A symbolic font is defined as having the map 3.0.
        /// Depends from
        /// <c>readGlyphWidths()</c>.
        /// </remarks>
        private void ReadCmapTable()
        {
            int[] table_location = tables.Get("cmap");
            if (table_location == null)
            {
                if (fileName != null)
                {
                    throw new iText.IO.IOException(iText.IO.IOException.TableDoesNotExistsIn).SetMessageParams("cmap", fileName
                                                                                                               );
                }
                else
                {
                    throw new iText.IO.IOException(iText.IO.IOException.TableDoesNotExist).SetMessageParams("cmap");
                }
            }
            raf.Seek(table_location[0]);
            raf.SkipBytes(2);
            int num_tables = raf.ReadUnsignedShort();
            int map10      = 0;
            int map31      = 0;
            int map30      = 0;
            int mapExt     = 0;

            cmaps = new OpenTypeParser.CmapTable();
            for (int k = 0; k < num_tables; ++k)
            {
                int platId     = raf.ReadUnsignedShort();
                int platSpecId = raf.ReadUnsignedShort();
                int offset     = raf.ReadInt();
                if (platId == 3 && platSpecId == 0)
                {
                    cmaps.fontSpecific = true;
                    map30 = offset;
                }
                else
                {
                    if (platId == 3 && platSpecId == 1)
                    {
                        map31 = offset;
                    }
                    else
                    {
                        if (platId == 3 && platSpecId == 10)
                        {
                            mapExt = offset;
                        }
                        else
                        {
                            if (platId == 1 && platSpecId == 0)
                            {
                                map10 = offset;
                            }
                        }
                    }
                }
            }
            if (map10 > 0)
            {
                raf.Seek(table_location[0] + map10);
                int format = raf.ReadUnsignedShort();
                switch (format)
                {
                case 0: {
                    cmaps.cmap10 = ReadFormat0();
                    break;
                }

                case 4: {
                    cmaps.cmap10 = ReadFormat4(false);
                    break;
                }

                case 6: {
                    cmaps.cmap10 = ReadFormat6();
                    break;
                }
                }
            }
            if (map31 > 0)
            {
                raf.Seek(table_location[0] + map31);
                int format = raf.ReadUnsignedShort();
                if (format == 4)
                {
                    cmaps.cmap31 = ReadFormat4(false);
                }
            }
            if (map30 > 0)
            {
                raf.Seek(table_location[0] + map30);
                int format = raf.ReadUnsignedShort();
                if (format == 4)
                {
                    cmaps.cmap10 = ReadFormat4(cmaps.fontSpecific);
                }
                else
                {
                    cmaps.fontSpecific = false;
                }
            }
            if (mapExt > 0)
            {
                raf.Seek(table_location[0] + mapExt);
                int format = raf.ReadUnsignedShort();
                switch (format)
                {
                case 0: {
                    cmaps.cmapExt = ReadFormat0();
                    break;
                }

                case 4: {
                    cmaps.cmapExt = ReadFormat4(false);
                    break;
                }

                case 6: {
                    cmaps.cmapExt = ReadFormat6();
                    break;
                }

                case 12: {
                    cmaps.cmapExt = ReadFormat12();
                    break;
                }
                }
            }
        }