/// <summary>Creates a SvgStyleResolver.</summary> /// <remarks> /// Creates a SvgStyleResolver. This constructor will instantiate its internal style sheet and it /// will collect the css declarations from the provided node. /// </remarks> /// <param name="rootNode">node to collect css from</param> /// <param name="context">the processor context</param> public SvgStyleResolver(INode rootNode, SvgProcessorContext context) { // TODO DEVSIX-2060. Fetch default styles first. this.deviceDescription = context.GetDeviceDescription(); this.resourceResolver = context.GetResourceResolver(); CollectCssDeclarations(rootNode, context.GetResourceResolver()); CollectFonts(); }
public virtual void ResourceResolverInstanceTest() { DummySvgConverterProperties properties = new DummySvgConverterProperties(); SvgProcessorContext context = new SvgProcessorContext(properties); ResourceResolver initialResolver = context.GetResourceResolver(); SvgProcessorResult svgProcessorResult = new SvgProcessorResult(new Dictionary <String, ISvgNodeRenderer>(), new SvgTagSvgNodeRenderer(), context); ResourceResolver currentResolver = SvgConverter.GetResourceResolver(svgProcessorResult, properties); NUnit.Framework.Assert.AreEqual(initialResolver, currentResolver); }
/// <summary> /// Creates a /// <see cref="SvgStyleResolver"/>. /// </summary> /// <param name="context">the processor context</param> public SvgStyleResolver(SvgProcessorContext context) { try { using (Stream defaultCss = ResourceUtil.GetResourceStream(DEFAULT_CSS_PATH)) { this.css = CssStyleSheetParser.Parse(defaultCss); } } catch (System.IO.IOException e) { ILog logger = LogManager.GetLogger(this.GetType()); logger.Warn(SvgLogMessageConstant.ERROR_INITIALIZING_DEFAULT_CSS, e); this.css = new CssStyleSheet(); } this.resourceResolver = context.GetResourceResolver(); }
/// <summary>Creates a font and adds it to the context.</summary> /// <param name="fontFamily">the font family</param> /// <param name="src">the source of the font</param> /// <returns>true, if successful</returns> private bool CreateFont(String fontFamily, FontFace.FontFaceSrc src) { if (!SupportedFontFormat(src.format)) { return(false); } else { if (src.isLocal) { // to method with lazy initialization ICollection <FontInfo> fonts = context.GetFontProvider().GetFontSet().Get(src.src); if (fonts.Count > 0) { foreach (FontInfo fi in fonts) { context.AddTemporaryFont(fi, fontFamily); } // return(true); } else { return(false); } } else { try { // Cache at resource resolver level only, at font level we will create font in any case. // The instance of fontProgram will be collected by GC if the is no need in it. byte[] bytes = context.GetResourceResolver().RetrieveBytesFromResource(src.src); if (bytes != null) { FontProgram fp = FontProgramFactory.CreateFont(bytes, false); context.AddTemporaryFont(fp, PdfEncodings.IDENTITY_H, fontFamily); return(true); } } catch (Exception) { } return(false); } } }
/// <summary> /// Creates a /// <see cref="SvgStyleResolver"/> /// with a given default CSS. /// </summary> /// <param name="defaultCssStream">the default CSS</param> /// <param name="context">the processor context</param> public SvgStyleResolver(Stream defaultCssStream, SvgProcessorContext context) { this.css = CssStyleSheetParser.Parse(defaultCssStream); this.resourceResolver = context.GetResourceResolver(); }