コード例 #1
0
ファイル: Attributes.cs プロジェクト: ReaZhuang/itext7-dotnet
 // linked hash map to preserve insertion order.
 // null be default as so many elements have no attributes -- saves a good chunk of memory
 /// <summary>Get an attribute value by key.</summary>
 /// <param name="key">the attribute key</param>
 /// <returns>the attribute value if set; or empty string if not set.</returns>
 /// <seealso cref="HasKey(System.String)"/>
 public virtual String Get(String key)
 {
     Validate.NotEmpty(key);
     if (attributes == null)
     {
         return("");
     }
     iText.StyledXmlParser.Jsoup.Nodes.Attribute attr = attributes.Get(key.ToLowerInvariant());
     return(attr != null ? attr.Value : "");
 }
コード例 #2
0
        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));
            }
        }