Example #1
0
 private void LoadCMaps()
 {
     try {
         fontDesc = allFonts[fontName];
         hMetrics = (IntHashtable)fontDesc["W"];
         vMetrics = (IntHashtable)fontDesc["W2"];
         String registry = (String)fontDesc["Registry"];
         uniMap = "";
         foreach (String name in registryNames[registry + "_Uni"].Keys)
         {
             uniMap = name;
             if (name.EndsWith("V") && vertical)
             {
                 break;
             }
             if (!name.EndsWith("V") && !vertical)
             {
                 break;
             }
         }
         if (cidDirect)
         {
             cidUni = CMapCache.GetCachedCMapCidUni(uniMap);
         }
         else
         {
             uniCid  = CMapCache.GetCachedCMapUniCid(uniMap);
             cidByte = CMapCache.GetCachedCMapCidByte(CMap);
         }
     }
     catch (Exception ex) {
         throw new DocumentException(ex.Message);
     }
 }
Example #2
0
 /// <param name="cmap">CMap name.</param>
 /// <param name="uniMap">CMap to convert Unicode value to CID.</param>
 public CMapEncoding(String cmap, String uniMap)
 {
     this.cmap   = cmap;
     this.uniMap = uniMap;
     if (cmap.Equals(PdfEncodings.IDENTITY_H) || cmap.Equals(PdfEncodings.IDENTITY_V))
     {
         cid2Uni  = FontCache.GetCid2UniCmap(uniMap);
         isDirect = true;
     }
     else
     {
         cid2Code = FontCache.GetCid2Byte(cmap);
         code2Cid = cid2Code.GetReversMap();
     }
 }
Example #3
0
        private void InitializeCidFontProperties(IDictionary <String, Object> fontDesc)
        {
            fontIdentification.SetPanose((String)fontDesc.Get("Panose"));
            fontMetrics.SetItalicAngle(Convert.ToInt32((String)fontDesc.Get("ItalicAngle"), System.Globalization.CultureInfo.InvariantCulture
                                                       ));
            fontMetrics.SetCapHeight(Convert.ToInt32((String)fontDesc.Get("CapHeight"), System.Globalization.CultureInfo.InvariantCulture
                                                     ));
            fontMetrics.SetTypoAscender(Convert.ToInt32((String)fontDesc.Get("Ascent"), System.Globalization.CultureInfo.InvariantCulture
                                                        ));
            fontMetrics.SetTypoDescender(Convert.ToInt32((String)fontDesc.Get("Descent"), System.Globalization.CultureInfo.InvariantCulture
                                                         ));
            fontMetrics.SetStemV(Convert.ToInt32((String)fontDesc.Get("StemV"), System.Globalization.CultureInfo.InvariantCulture
                                                 ));
            pdfFontFlags = Convert.ToInt32((String)fontDesc.Get("Flags"), System.Globalization.CultureInfo.InvariantCulture
                                           );
            String          fontBBox = (String)fontDesc.Get("FontBBox");
            StringTokenizer tk       = new StringTokenizer(fontBBox, " []\r\n\t\f");
            int             llx      = Convert.ToInt32(tk.NextToken(), System.Globalization.CultureInfo.InvariantCulture);
            int             lly      = Convert.ToInt32(tk.NextToken(), System.Globalization.CultureInfo.InvariantCulture);
            int             urx      = Convert.ToInt32(tk.NextToken(), System.Globalization.CultureInfo.InvariantCulture);
            int             ury      = Convert.ToInt32(tk.NextToken(), System.Globalization.CultureInfo.InvariantCulture);

            fontMetrics.UpdateBbox(llx, lly, urx, ury);
            registry = (String)fontDesc.Get("Registry");
            String uniMap = GetCompatibleUniMap(registry);

            if (uniMap != null)
            {
                IntHashtable metrics = (IntHashtable)fontDesc.Get("W");
                CMapCidUni   cid2Uni = FontCache.GetCid2UniCmap(uniMap);
                avgWidth = 0;
                foreach (int cid in cid2Uni.GetCids())
                {
                    int   uni   = cid2Uni.Lookup(cid);
                    int   width = metrics.ContainsKey(cid) ? metrics.Get(cid) : DEFAULT_WIDTH;
                    Glyph glyph = new Glyph(cid, width, uni);
                    avgWidth += glyph.GetWidth();
                    codeToGlyph.Put(cid, glyph);
                    unicodeToGlyph.Put(uni, glyph);
                }
                FixSpaceIssue();
                if (codeToGlyph.Count != 0)
                {
                    avgWidth /= codeToGlyph.Count;
                }
            }
        }
Example #4
0
        private void InitFont()
        {
            ProcessToUnicode();
            //if (toUnicodeCmap == null)
            ProcessUni2Byte();

            spaceWidth = base.GetWidth(' ');
            if (spaceWidth == 0)
            {
                spaceWidth = ComputeAverageWidth();
            }
            if (cjkEncoding != null)
            {
                byteCid = CMapCache.GetCachedCMapByteCid(cjkEncoding);
                cidUni  = CMapCache.GetCachedCMapCidUni(uniMap);
            }
        }
Example #5
0
        /// <summary>Parses CMap with a given name producing it in a form of cid to unicode mapping.</summary>
        /// <param name="uniMap">a CMap name. It is expected that CMap identified by this name defines unicode to cid mapping.
        ///     </param>
        /// <returns>an object for convenient mapping from cid to unicode. If no CMap was found for provided name an exception is thrown.
        ///     </returns>
        public static CMapCidUni GetCid2UniCmap(String uniMap)
        {
            CMapCidUni cidUni = new CMapCidUni();

            return(ParseCmap(uniMap, cidUni));
        }