Ejemplo n.º 1
0
 internal FontSelectorCache(FontSet defaultFontSet)
 {
     System.Diagnostics.Debug.Assert(defaultFontSet != null);
     this.defaultSelectors = new FontSelectorCache.FontSetSelectors();
     this.defaultSelectors.Update(defaultFontSet);
     this.defaultFontSet = defaultFontSet;
 }
Ejemplo n.º 2
0
 /// <summary>Creates a new instance of FontProvider</summary>
 /// <param name="fontSet">predefined set of fonts, could be null.</param>
 /// <param name="defaultFontFamily">default font family.</param>
 public FontProvider(FontSet fontSet, String defaultFontFamily)
 {
     this.fontSet           = fontSet != null ? fontSet : new FontSet();
     pdfFonts               = new Dictionary <FontInfo, PdfFont>();
     fontSelectorCache      = new FontSelectorCache(this.fontSet);
     this.defaultFontFamily = defaultFontFamily;
 }
 protected internal FontSelectorStrategy(String text, FontProvider provider, FontSet tempFonts)
 {
     this.text      = text;
     this.index     = 0;
     this.provider  = provider;
     this.tempFonts = tempFonts;
 }
Ejemplo n.º 4
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);
     }
 }
Ejemplo n.º 5
0
 internal virtual bool Update(FontSet fontSet)
 {
     System.Diagnostics.Debug.Assert(fontSet != null);
     if (fontSetSize == fontSet.Size())
     {
         return(false);
     }
     else
     {
         map.Clear();
         fontSetSize = fontSet.Size();
         return(true);
     }
 }
Ejemplo n.º 6
0
        private bool Update(FontSelectorCache.FontSetSelectors selectors, FontSet fontSet)
        {
            bool updated = false;

            if (defaultSelectors.Update(defaultFontSet))
            {
                updated = true;
            }
            if (selectors != null && selectors.Update(fontSet))
            {
                updated = true;
            }
            return(updated);
        }
Ejemplo n.º 7
0
 internal virtual void Put(FontSelectorKey key, FontSelector fontSelector, FontSet fontSet)
 {
     if (fontSet == null)
     {
         Put(key, fontSelector);
     }
     else
     {
         FontSelectorCache.FontSetSelectors selectors = caches.Get(fontSet.GetId());
         if (selectors == null)
         {
             caches.Put(fontSet.GetId(), selectors = new FontSelectorCache.FontSetSelectors());
         }
         //update selectors and defaultSelectors to reset counter before pushing if needed.
         Update(selectors, fontSet);
         selectors.map.Put(key, fontSelector);
     }
 }
Ejemplo n.º 8
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) {
             throw new PdfException(PdfException.IoExceptionWhileCreatingFont, e);
         }
         pdfFonts.Put(fontInfo, pdfFont);
         return(pdfFont);
     }
 }
Ejemplo n.º 9
0
 internal virtual FontSelector Get(FontSelectorKey key, FontSet fontSet)
 {
     if (fontSet == null)
     {
         return(Get(key));
     }
     else
     {
         FontSelectorCache.FontSetSelectors selectors = caches.Get(fontSet.GetId());
         if (selectors == null)
         {
             caches.Put(fontSet.GetId(), selectors = new FontSelectorCache.FontSetSelectors());
         }
         if (Update(selectors, fontSet))
         {
             return(null);
         }
         else
         {
             return(selectors.map.Get(key));
         }
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Create
        /// <see cref="FontSelector"/>
        /// or get from cache.
        /// </summary>
        /// <param name="fontFamilies">target font families</param>
        /// <param name="fc">
        /// instance of
        /// <see cref="FontCharacteristics"/>
        /// .
        /// </param>
        /// <param name="tempFonts">set of temporary fonts.</param>
        /// <returns>
        /// an instance of
        /// <see cref="FontSelector"/>
        /// .
        /// </returns>
        /// <seealso cref="CreateFontSelector(System.Collections.Generic.ICollection{E}, System.Collections.Generic.IList{E}, FontCharacteristics)
        ///     ">}</seealso>
        public FontSelector GetFontSelector(IList <String> fontFamilies, FontCharacteristics fc, FontSet tempFonts)
        {
            FontSelectorKey key          = new FontSelectorKey(fontFamilies, fc);
            FontSelector    fontSelector = fontSelectorCache.Get(key, tempFonts);

            if (fontSelector == null)
            {
                fontSelector = CreateFontSelector(fontSet.GetFonts(tempFonts), fontFamilies, fc);
                fontSelectorCache.Put(key, fontSelector, tempFonts);
            }
            return(fontSelector);
        }
Ejemplo n.º 11
0
 public virtual FontSelectorStrategy GetStrategy(String text, IList <String> fontFamilies, FontCharacteristics
                                                 fc, FontSet additonalFonts)
 {
     return(new ComplexFontSelectorStrategy(text, GetFontSelector(fontFamilies, fc, additonalFonts), this, additonalFonts
                                            ));
 }
Ejemplo n.º 12
0
 /// <summary>Creates a new instance of FontProvider</summary>
 /// <param name="fontSet">predefined set of fonts, could be null.</param>
 public FontProvider(FontSet fontSet)
     : this(fontSet, DEFAULT_FONT_FAMILY)
 {
 }
Ejemplo n.º 13
0
 public ComplexFontSelectorStrategy(String text, FontSelector selector, FontProvider provider, FontSet tempFonts
                                    )
     : base(text, provider, tempFonts)
 {
     this.font     = null;
     this.selector = selector;
 }
Ejemplo n.º 14
0
 /// <summary>Creates a new instance of FontProvider</summary>
 /// <param name="fontSet">predefined set of fonts, could be null.</param>
 public FontProvider(FontSet fontSet)
 {
     this.fontSet      = fontSet != null ? fontSet : new FontSet();
     pdfFonts          = new Dictionary <FontInfo, PdfFont>();
     fontSelectorCache = new FontSelectorCache(this.fontSet);
 }