public virtual void SvgCssResolverStylesheetTest() { iText.StyledXmlParser.Jsoup.Nodes.Element jsoupLink = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf(SvgConstants.Tags.LINK), ""); Attributes linkAttributes = jsoupLink.Attributes(); linkAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.XMLNS, "http://www.w3.org/1999/xhtml" )); linkAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.REL, SvgConstants.Attributes .STYLESHEET)); linkAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute(SvgConstants.Attributes.HREF, "styleSheetWithLinkStyle.css" )); linkAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("type", "text/css")); JsoupElementNode node = new JsoupElementNode(jsoupLink); SvgConverterProperties scp = new SvgConverterProperties(); scp.SetBaseUri(baseUri); SvgProcessorContext processorContext = new SvgProcessorContext(scp); SvgStyleResolver sr = new SvgStyleResolver(node, processorContext); IDictionary <String, String> attr = sr.ResolveStyles(node, new SvgCssContext()); IDictionary <String, String> expectedAttr = new Dictionary <String, String>(); expectedAttr.Put(SvgConstants.Attributes.XMLNS, "http://www.w3.org/1999/xhtml"); expectedAttr.Put(SvgConstants.Attributes.REL, SvgConstants.Attributes.STYLESHEET); expectedAttr.Put(SvgConstants.Attributes.HREF, "styleSheetWithLinkStyle.css"); expectedAttr.Put("type", "text/css"); // Attribute from external stylesheet expectedAttr.Put(SvgConstants.Attributes.FILL, "black"); NUnit.Framework.Assert.AreEqual(expectedAttr, attr); }
/// <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(); CollectCssDeclarations(rootNode, context.GetResourceResolver()); CollectFonts(); }
public virtual void SvgCssResolverBasicAttributeTest() { iText.StyledXmlParser.Jsoup.Nodes.Element jsoupCircle = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf("circle"), ""); Attributes circleAttributes = jsoupCircle.Attributes(); circleAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("id", "circle1")); circleAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("cx", "95")); circleAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("cy", "95")); circleAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("rx", "53")); circleAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("ry", "53")); circleAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("style", "stroke-width:1.5;stroke:#da0000;" )); AbstractCssContext cssContext = new SvgCssContext(); INode circle = new JsoupElementNode(jsoupCircle); SvgProcessorContext context = new SvgProcessorContext(new SvgConverterProperties()); ICssResolver resolver = new SvgStyleResolver(circle, context); IDictionary <String, String> actual = resolver.ResolveStyles(circle, cssContext); IDictionary <String, String> expected = new Dictionary <String, String>(); expected.Put("id", "circle1"); expected.Put("cx", "95"); expected.Put("cy", "95"); expected.Put("rx", "53"); expected.Put("ry", "53"); expected.Put("stroke-width", "1.5"); expected.Put("stroke", "#da0000"); NUnit.Framework.Assert.AreEqual(expected, actual); }
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(); }
public virtual void FontsResolverTagTest() { iText.StyledXmlParser.Jsoup.Nodes.Element styleTag = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf("style"), ""); TextNode styleContents = new TextNode("\n" + "\t@font-face{\n" + "\t\tfont-family:Courier;\n" + "\t\tsrc:url(#Super Sans);\n" + "\t}\n" + " ", ""); JsoupElementNode jSoupStyle = new JsoupElementNode(styleTag); jSoupStyle.AddChild(new JsoupTextNode(styleContents)); SvgProcessorContext context = new SvgProcessorContext(new SvgConverterProperties()); SvgStyleResolver resolver = new SvgStyleResolver(jSoupStyle, context); IList <CssFontFaceRule> fontFaceRuleList = resolver.GetFonts(); NUnit.Framework.Assert.AreEqual(1, fontFaceRuleList.Count); NUnit.Framework.Assert.AreEqual(2, fontFaceRuleList[0].GetProperties().Count); }
public virtual void SvgCssResolveHashXlinkTest() { iText.StyledXmlParser.Jsoup.Nodes.Element jsoupImage = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf("image"), ""); iText.StyledXmlParser.Jsoup.Nodes.Attributes imageAttributes = jsoupImage.Attributes(); imageAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", "#testid")); JsoupElementNode node = new JsoupElementNode(jsoupImage); SvgConverterProperties scp = new SvgConverterProperties(); scp.SetBaseUri(baseUri); SvgProcessorContext processorContext = new SvgProcessorContext(scp); SvgStyleResolver sr = new SvgStyleResolver(node, processorContext); IDictionary <String, String> attr = sr.ResolveStyles(node, new SvgCssContext()); NUnit.Framework.Assert.AreEqual("#testid", attr.Get("xlink:href")); }
public virtual void SvgCssResolverXlinkTest() { iText.StyledXmlParser.Jsoup.Nodes.Element jsoupImage = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf("image"), ""); iText.StyledXmlParser.Jsoup.Nodes.Attributes imageAttributes = jsoupImage.Attributes(); imageAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", "itis.jpg")); JsoupElementNode node = new JsoupElementNode(jsoupImage); SvgConverterProperties scp = new SvgConverterProperties(); scp.SetBaseUri(baseUri); SvgProcessorContext processorContext = new SvgProcessorContext(scp); SvgStyleResolver sr = new SvgStyleResolver(node, processorContext); IDictionary <String, String> attr = sr.ResolveStyles(node, new SvgCssContext()); String fileName = baseUri + "itis.jpg"; String expectedURL = UrlUtil.ToNormalizedURI(fileName).ToString(); NUnit.Framework.Assert.AreEqual(expectedURL, attr.Get("xlink:href")); }
public virtual void AddFontFaceFontsTest() { iText.StyledXmlParser.Jsoup.Nodes.Element styleTag = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf("style"), ""); TextNode styleContents = new TextNode("\n" + "\t@font-face{\n" + "\t\tfont-family:Courier;\n" + "\t\tsrc:local(Courier);\n" + "\t}\n" + " ", ""); JsoupElementNode jSoupStyle = new JsoupElementNode(styleTag); jSoupStyle.AddChild(new JsoupTextNode(styleContents)); SvgProcessorContext context = new SvgProcessorContext(new SvgConverterProperties()); ICssResolver cssResolver = new SvgStyleResolver(jSoupStyle, context); SvgFontProcessor svgFontProcessor = new SvgFontProcessor(context); svgFontProcessor.AddFontFaceFonts(cssResolver); FontInfo info = (FontInfo)context.GetTempFonts().GetFonts().ToArray()[0]; NUnit.Framework.Assert.AreEqual("Courier", info.GetFontName()); }
public virtual void SvgCssResolverStyleTagTest() { iText.StyledXmlParser.Jsoup.Nodes.Element styleTag = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf("style"), ""); TextNode styleContents = new TextNode("\n" + "\tellipse{\n" + "\t\tstroke-width:1.76388889;\n" + "\t\tstroke:#da0000;\n" + "\t\tstroke-opacity:1;\n" + "\t}\n" + " ", ""); JsoupElementNode jSoupStyle = new JsoupElementNode(styleTag); jSoupStyle.AddChild(new JsoupTextNode(styleContents)); iText.StyledXmlParser.Jsoup.Nodes.Element ellipse = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf("ellipse"), ""); JsoupElementNode jSoupEllipse = new JsoupElementNode(ellipse); SvgProcessorContext context = new SvgProcessorContext(new SvgConverterProperties()); SvgStyleResolver resolver = new SvgStyleResolver(jSoupStyle, context); AbstractCssContext svgContext = new SvgCssContext(); IDictionary <String, String> actual = resolver.ResolveStyles(jSoupEllipse, svgContext); IDictionary <String, String> expected = new Dictionary <String, String>(); expected.Put("stroke-width", "1.76388889"); expected.Put("stroke", "#da0000"); expected.Put("stroke-opacity", "1"); NUnit.Framework.Assert.AreEqual(expected, actual); }
public SvgFontProcessor(SvgProcessorContext context) { this.context = context; }
/// <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(); }