/// <summary>Adds @font-face fonts to the FontProvider.</summary> private void AddFontFaceFonts() { //TODO Shall we add getFonts() to ICssResolver? if (cssResolver is DefaultCssResolver) { foreach (CssFontFaceRule fontFace in ((DefaultCssResolver)cssResolver).GetFonts()) { bool findSupportedSrc = false; IList <CssDeclaration> declarations = fontFace.GetProperties(); CssFontFace ff = CssFontFace.Create(declarations); if (ff != null) { foreach (CssFontFace.CssFontFaceSrc src in ff.GetSources()) { if (CreateFont(ff.GetFontFamily(), src, fontFace.ResolveUnicodeRange())) { findSupportedSrc = true; break; } } } if (!findSupportedSrc) { logger.Error(MessageFormatUtil.Format(iText.Html2pdf.LogMessageConstant.UNABLE_TO_RETRIEVE_FONT, fontFace) ); } } } }
/// <summary>Adds @font-face fonts to the FontProvider.</summary> /// <param name="cssResolver">the css styles resolver</param> public virtual void AddFontFaceFonts(ICssResolver cssResolver) { if (cssResolver is SvgStyleResolver) { foreach (CssFontFaceRule fontFace in ((SvgStyleResolver)cssResolver).GetFonts()) { bool findSupportedSrc = false; CssFontFace ff = CssFontFace.Create(fontFace.GetProperties()); if (ff != null) { foreach (CssFontFace.CssFontFaceSrc src in ff.GetSources()) { if (CreateFont(ff.GetFontFamily(), src, fontFace.ResolveUnicodeRange())) { findSupportedSrc = true; break; } } } if (!findSupportedSrc) { LogManager.GetLogger(typeof(iText.Svg.Processors.Impl.Font.SvgFontProcessor)).Error(MessageFormatUtil.Format (iText.StyledXmlParser.LogMessageConstant.UNABLE_TO_RETRIEVE_FONT, fontFace)); } } } }
public virtual void CreateCssFontFaceNullSrcTest() { IList <CssDeclaration> properties = new List <CssDeclaration>(); properties.Add(new CssDeclaration("font-family", "Droid Italic")); properties.Add(new CssDeclaration("src", null)); CssFontFace fontFace = CssFontFace.Create(properties); NUnit.Framework.Assert.IsNull(fontFace); }
public virtual void CreateCssFontFaceNullFontFamilyTest() { IList <CssDeclaration> properties = new List <CssDeclaration>(); properties.Add(new CssDeclaration("font-family", "")); properties.Add(new CssDeclaration("src", "some_directory/droid-serif-italic.ttf")); CssFontFace fontFace = CssFontFace.Create(properties); NUnit.Framework.Assert.IsNull(fontFace); }
public virtual void CreateCssFontFaceTest() { IList <CssDeclaration> properties = new List <CssDeclaration>(); properties.Add(new CssDeclaration("font-family", "Droid Italic")); properties.Add(new CssDeclaration("src", "url(\"web-fonts/droid-serif-italic.ttf\")")); CssFontFace fontFace = CssFontFace.Create(properties); NUnit.Framework.Assert.IsNotNull(fontFace); NUnit.Framework.Assert.AreEqual("droid italic", fontFace.GetFontFamily()); IList <CssFontFace.CssFontFaceSrc> sources = fontFace.GetSources(); NUnit.Framework.Assert.IsNotNull(sources); NUnit.Framework.Assert.AreEqual(1, sources.Count); NUnit.Framework.Assert.AreEqual("web-fonts/droid-serif-italic.ttf", sources[0].GetSrc()); }