示例#1
0
 /// <summary>
 /// Get from cache or create a new instance of
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </summary>
 /// <param name="fontInfo">
 /// font info, to create
 /// <see cref="iText.IO.Font.FontProgram"/>
 /// and
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </param>
 /// <param name="tempFonts">Set of temporary fonts.</param>
 /// <returns>
 /// cached or new instance of
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </returns>
 public virtual PdfFont GetPdfFont(FontInfo fontInfo, FontSet tempFonts)
 {
     if (pdfFonts.ContainsKey(fontInfo))
     {
         return(pdfFonts.Get(fontInfo));
     }
     else
     {
         FontProgram fontProgram = null;
         if (tempFonts != null)
         {
             fontProgram = tempFonts.GetFontProgram(fontInfo);
         }
         if (fontProgram == null)
         {
             fontProgram = fontSet.GetFontProgram(fontInfo);
         }
         PdfFont pdfFont;
         try {
             if (fontProgram == null)
             {
                 if (fontInfo.GetFontData() != null)
                 {
                     fontProgram = FontProgramFactory.CreateFont(fontInfo.GetFontData(), GetDefaultCacheFlag());
                 }
                 else
                 {
                     fontProgram = FontProgramFactory.CreateFont(fontInfo.GetFontName(), GetDefaultCacheFlag());
                 }
             }
             String encoding = fontInfo.GetEncoding();
             if (encoding == null || encoding.Length == 0)
             {
                 encoding = GetDefaultEncoding(fontProgram);
             }
             pdfFont = PdfFontFactory.CreateFont(fontProgram, encoding, GetDefaultEmbeddingFlag());
         }
         catch (System.IO.IOException e) {
             // Converting checked exceptions to unchecked RuntimeException (java-specific comment).
             //
             // FontProvider is usually used in highlevel API, which requests fonts in deep underlying logic.
             // IOException would mean that font is chosen and it is supposed to exist, however it cannot be read.
             // Using fallbacks in such situations would make FontProvider less intuitive.
             //
             // Even though softening of checked exceptions can be handled at higher levels in order to let
             // the caller of this method know that font creation failed, we prefer to avoid bloating highlevel API
             // and avoid making higher level code depend on low-level code because of the exceptions handling.
             throw new PdfException(PdfException.IoExceptionWhileCreatingFont, e);
         }
         pdfFonts.Put(fontInfo, pdfFont);
         return(pdfFont);
     }
 }
 /// <summary>
 /// Get from cache or create a new instance of
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </summary>
 /// <param name="fontInfo">
 /// font info, to create
 /// <see cref="iText.IO.Font.FontProgram"/>
 /// and
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </param>
 /// <param name="tempFonts">Set of temporary fonts.</param>
 /// <returns>
 /// cached or new instance of
 /// <see cref="iText.Kernel.Font.PdfFont"/>
 /// .
 /// </returns>
 public virtual PdfFont GetPdfFont(FontInfo fontInfo, FontSet tempFonts)
 {
     if (pdfFonts.ContainsKey(fontInfo))
     {
         return(pdfFonts.Get(fontInfo));
     }
     else
     {
         FontProgram fontProgram = null;
         if (tempFonts != null)
         {
             fontProgram = tempFonts.GetFontProgram(fontInfo);
         }
         if (fontProgram == null)
         {
             fontProgram = fontSet.GetFontProgram(fontInfo);
         }
         PdfFont pdfFont;
         try {
             if (fontProgram == null)
             {
                 if (fontInfo.GetFontData() != null)
                 {
                     fontProgram = FontProgramFactory.CreateFont(fontInfo.GetFontData(), GetDefaultCacheFlag());
                 }
                 else
                 {
                     fontProgram = FontProgramFactory.CreateFont(fontInfo.GetFontName(), GetDefaultCacheFlag());
                 }
             }
             String encoding = fontInfo.GetEncoding();
             if (encoding == null || encoding.Length == 0)
             {
                 encoding = GetDefaultEncoding(fontProgram);
             }
             pdfFont = PdfFontFactory.CreateFont(fontProgram, encoding, GetDefaultEmbeddingFlag());
         }
         catch (System.IO.IOException e) {
             throw new PdfException(PdfException.IoExceptionWhileCreatingFont, e);
         }
         pdfFonts.Put(fontInfo, pdfFont);
         return(pdfFont);
     }
 }