public virtual void Draw(SvgDrawContext context) { //Set viewport and transformation for pdf-context context.AddViewPort(this.CalculateViewPort(context)); PdfCanvas currentCanvas = context.GetCurrentCanvas(); currentCanvas.ConcatMatrix(this.CalculateTransformation(context)); currentCanvas.WriteLiteral("% svg root\n"); subTreeRoot.Draw(context); }
public virtual void BasicProcessedRendererTest() { iText.StyledXmlParser.Jsoup.Nodes.Element element = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf("processable"), ""); IElementNode tag = new JsoupElementNode(element); ISvgNodeRenderer renderer = fact.CreateSvgNodeRendererForTag(tag, null); NUnit.Framework.Assert.IsTrue(renderer is DummyProcessableSvgNodeRenderer); renderer.Draw(new SvgDrawContext(null, null)); DummyProcessableSvgNodeRenderer processed = (DummyProcessableSvgNodeRenderer)renderer; NUnit.Framework.Assert.IsTrue(processed.IsProcessed()); }
public virtual void NestedProcessedRendererTest() { iText.StyledXmlParser.Jsoup.Nodes.Element parentEl = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf("processable"), ""); iText.StyledXmlParser.Jsoup.Nodes.Element childEl = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf("processable"), ""); IElementNode parentTag = new JsoupElementNode(parentEl); IElementNode childTag = new JsoupElementNode(childEl); ISvgNodeRenderer parentRenderer = fact.CreateSvgNodeRendererForTag(parentTag, null); ISvgNodeRenderer childRenderer = fact.CreateSvgNodeRendererForTag(childTag, parentRenderer); parentRenderer.Draw(new SvgDrawContext(null, null)); DummyProcessableSvgNodeRenderer parentProcessed = (DummyProcessableSvgNodeRenderer)parentRenderer; NUnit.Framework.Assert.IsTrue(parentProcessed.IsProcessed()); DummyProcessableSvgNodeRenderer childProcessed = (DummyProcessableSvgNodeRenderer)childRenderer; // child is not processed unless instructed thus in its parent NUnit.Framework.Assert.IsFalse(childProcessed.IsProcessed()); }
internal static void DrawMarker(SvgDrawContext context, String moveX, String moveY, MarkerVertexType markerToUse , AbstractSvgNodeRenderer parent) { String elementToReUse = parent.attributesAndStyles.Get(markerToUse.ToString()); String normalizedName = SvgTextUtil.FilterReferenceValue(elementToReUse); ISvgNodeRenderer template = context.GetNamedObject(normalizedName); //Clone template ISvgNodeRenderer namedObject = template == null ? null : template.CreateDeepCopy(); if (namedObject is MarkerSvgNodeRenderer && // Having markerWidth or markerHeight with negative or zero value disables rendering of the element . MarkerWidthHeightAreCorrect((MarkerSvgNodeRenderer)namedObject)) { // setting the parent of the referenced element to this instance namedObject.SetParent(parent); namedObject.SetAttribute(SvgConstants.Tags.MARKER, markerToUse.ToString()); namedObject.SetAttribute(SvgConstants.Attributes.X, moveX); namedObject.SetAttribute(SvgConstants.Attributes.Y, moveY); namedObject.Draw(context); // unsetting the parent of the referenced element namedObject.SetParent(null); } }
protected internal override void DoDraw(SvgDrawContext context) { if (this.attributesAndStyles != null) { String elementToReUse = this.attributesAndStyles.Get(SvgConstants.Attributes.XLINK_HREF); if (elementToReUse == null) { elementToReUse = this.attributesAndStyles.Get(SvgConstants.Attributes.HREF); } if (elementToReUse != null && !String.IsNullOrEmpty(elementToReUse) && IsValidHref(elementToReUse)) { String normalizedName = SvgTextUtil.FilterReferenceValue(elementToReUse); if (!context.IsIdUsedByUseTagBefore(normalizedName)) { ISvgNodeRenderer template = context.GetNamedObject(normalizedName); //Clone template ISvgNodeRenderer namedObject = template == null ? null : template.CreateDeepCopy(); //Resolve parent inheritance SvgNodeRendererInheritanceResolver iresolver = new SvgNodeRendererInheritanceResolver(); iresolver.ApplyInheritanceToSubTree(this, namedObject); if (namedObject != null) { if (namedObject is AbstractSvgNodeRenderer) { ((AbstractSvgNodeRenderer)namedObject).SetPartOfClipPath(partOfClipPath); } PdfCanvas currentCanvas = context.GetCurrentCanvas(); float x = 0f; float y = 0f; if (this.attributesAndStyles.ContainsKey(SvgConstants.Attributes.X)) { x = CssUtils.ParseAbsoluteLength(this.attributesAndStyles.Get(SvgConstants.Attributes.X)); } if (this.attributesAndStyles.ContainsKey(SvgConstants.Attributes.Y)) { y = CssUtils.ParseAbsoluteLength(this.attributesAndStyles.Get(SvgConstants.Attributes.Y)); } AffineTransform inverseMatrix = null; if (!CssUtils.CompareFloats(x, 0) || !CssUtils.CompareFloats(y, 0)) { AffineTransform translation = AffineTransform.GetTranslateInstance(x, y); currentCanvas.ConcatMatrix(translation); if (partOfClipPath) { try { inverseMatrix = translation.CreateInverse(); } catch (NoninvertibleTransformException ex) { LogManager.GetLogger(typeof(UseSvgNodeRenderer)).Warn(SvgLogMessageConstant.NONINVERTIBLE_TRANSFORMATION_MATRIX_USED_IN_CLIP_PATH , ex); } } } // setting the parent of the referenced element to this instance namedObject.SetParent(this); namedObject.Draw(context); // unsetting the parent of the referenced element namedObject.SetParent(null); if (inverseMatrix != null) { currentCanvas.ConcatMatrix(inverseMatrix); } } } } } }