iTextSharp.text.FontFactoryImp.GetFont C# (CSharp) Метод

GetFont() публичный Метод

Constructs a Font-object.
public GetFont ( string fontname, string encoding, bool embedded, float size, int style, BaseColor color, bool cached ) : Font
fontname string the name of the font
encoding string the encoding of the font
embedded bool true if the font is to be embedded in the PDF
size float the size of this font
style int the style of this font
color BaseColor the BaseColor of this font
cached bool true if the font comes from the cache or is added to the cache if new, false if the font is always created new
Результат Font
        public virtual Font GetFont(string fontname, string encoding, bool embedded, float size, int style, BaseColor color, bool cached)
        {
            if (fontname == null) return new Font(Font.FontFamily.UNDEFINED, size, style, color);
            string lowercasefontname = fontname.ToLower(CultureInfo.InvariantCulture);
            List<string> tmp;
            fontFamilies.TryGetValue(lowercasefontname, out tmp);
            if (tmp != null) {
                // some bugs were fixed here by Daniel Marczisovszky
                int fs = Font.NORMAL;
                bool found = false;
                int s = style == Font.UNDEFINED ? Font.NORMAL : style;
                foreach (string f in tmp) {
                    string lcf = f.ToLower(CultureInfo.InvariantCulture);
                    fs = Font.NORMAL;
                    if (lcf.ToLower(CultureInfo.InvariantCulture).IndexOf("bold") != -1) fs |= Font.BOLD;
                    if (lcf.ToLower(CultureInfo.InvariantCulture).IndexOf("italic") != -1 || lcf.ToLower(CultureInfo.InvariantCulture).IndexOf("oblique") != -1) fs |= Font.ITALIC;
                    if ((s & Font.BOLDITALIC) == fs) {
                        fontname = f;
                        found = true;
                        break;
                    }
                }
                if (style != Font.UNDEFINED && found) {
                    style &= ~fs;
                }
            }
            BaseFont basefont = null;
            try {
                try {
                    // the font is a type 1 font or CJK font
                    basefont = BaseFont.CreateFont(fontname, encoding, embedded, cached, null, null, true);
                }
                catch (DocumentException) {
                }
                if (basefont == null) {
                    // the font is a true type font or an unknown font
                    trueTypeFonts.TryGetValue(fontname.ToLower(CultureInfo.InvariantCulture), out fontname);
                    // the font is not registered as truetype font
                    if (fontname == null) return new Font(Font.FontFamily.UNDEFINED, size, style, color);
                    // the font is registered as truetype font
                    basefont = BaseFont.CreateFont(fontname, encoding, embedded, cached, null, null);
                }
            }
            catch (DocumentException de) {
                // this shouldn't happen
                throw de;
            }
            catch (System.IO.IOException) {
                // the font is registered as a true type font, but the path was wrong
                return new Font(Font.FontFamily.UNDEFINED, size, style, color);
            }
            catch {
                // null was entered as fontname and/or encoding
                return new Font(Font.FontFamily.UNDEFINED, size, style, color);
            }
            return new Font(basefont, size, style, color);
        }

Same methods

FontFactoryImp::GetFont ( string fontname ) : Font
FontFactoryImp::GetFont ( string fontname, float size ) : Font
FontFactoryImp::GetFont ( string fontname, float size, BaseColor color ) : Font
FontFactoryImp::GetFont ( string fontname, float size, int style ) : Font
FontFactoryImp::GetFont ( string fontname, float size, int style, BaseColor color ) : Font
FontFactoryImp::GetFont ( string fontname, string encoding ) : Font
FontFactoryImp::GetFont ( string fontname, string encoding, bool embedded ) : Font
FontFactoryImp::GetFont ( string fontname, string encoding, bool embedded, float size ) : Font
FontFactoryImp::GetFont ( string fontname, string encoding, bool embedded, float size, int style ) : Font
FontFactoryImp::GetFont ( string fontname, string encoding, bool embedded, float size, int style, BaseColor color ) : Font
FontFactoryImp::GetFont ( string fontname, string encoding, float size ) : Font
FontFactoryImp::GetFont ( string fontname, string encoding, float size, int style ) : Font
FontFactoryImp::GetFont ( string fontname, string encoding, float size, int style, BaseColor color ) : Font

Usage Example

Пример #1
0
 /// <summary>
 /// Constructs a Font-object.
 /// </summary>
 /// <param name="fontname">the name of the font</param>
 /// <param name="encoding">the encoding of the font</param>
 /// <param name="embedded">true if the font is to be embedded in the PDF</param>
 /// <param name="size">the size of this font</param>
 /// <param name="style">the style of this font</param>
 /// <param name="color">the BaseColor of this font</param>
 /// <returns>a Font object</returns>
 public static Font GetFont(string fontname, string encoding, bool embedded, float size, int style, BaseColor color)
 {
     return(fontImp.GetFont(fontname, encoding, embedded, size, style, color));
 }