private FontInfo ResolveFontName(String fontFamily, String fontWeight, String fontStyle, FontProvider provider , FontSet tempFonts) { bool isBold = fontWeight != null && SvgConstants.Attributes.BOLD.EqualsIgnoreCase(fontWeight); bool isItalic = fontStyle != null && SvgConstants.Attributes.ITALIC.EqualsIgnoreCase(fontStyle); FontCharacteristics fontCharacteristics = new FontCharacteristics(); IList <String> stringArrayList = new List <String>(); stringArrayList.Add(fontFamily); fontCharacteristics.SetBoldFlag(isBold); fontCharacteristics.SetItalicFlag(isItalic); return(provider.GetFontSelector(stringArrayList, fontCharacteristics, tempFonts).BestMatch()); }
public virtual void SearchFontAliasWithUnicodeChars() { // фонт1 String cyrillicAlias = "\u0444\u043E\u043D\u04421"; // γραμματοσειρά2 String greekAlias = "\u03B3\u03C1\u03B1\u03BC\u03BC\u03B1\u03C4\u03BF\u03C3\u03B5\u03B9\u03C1\u03AC2"; // フォント3 String japaneseAlias = "\u30D5\u30A9\u30F3\u30C83"; IDictionary <String, String> aliasToFontName = new LinkedDictionary <String, String>(); aliasToFontName.Put(cyrillicAlias, "NotoSans-Regular.ttf"); aliasToFontName.Put(greekAlias, "FreeSans.ttf"); aliasToFontName.Put(japaneseAlias, "Puritan2.otf"); FontProvider provider = new FontProvider(); foreach (KeyValuePair <String, String> e in aliasToFontName) { provider.GetFontSet().AddFont(fontsFolder + e.Value, PdfEncodings.IDENTITY_H, e.Key); } ICollection <String> actualAliases = new HashSet <String>(); foreach (FontInfo fontInfo in provider.GetFontSet().GetFonts()) { actualAliases.Add(fontInfo.GetAlias()); } ICollection <String> expectedAliases = aliasToFontName.Keys; NUnit.Framework.Assert.IsTrue(actualAliases.ContainsAll(expectedAliases) && expectedAliases.ContainsAll(actualAliases )); foreach (String fontAlias in expectedAliases) { PdfFont pdfFont = provider.GetPdfFont(provider.GetFontSelector(JavaCollectionsUtil.SingletonList(fontAlias ), new FontCharacteristics()).BestMatch()); String fontName = pdfFont.GetFontProgram().GetFontNames().GetFontName(); NUnit.Framework.Assert.IsTrue(aliasToFontName.Get(fontAlias).Contains(fontName)); } }