/// <summary> /// Method that will set properties to be inherited by this branch renderer's /// children and will iterate over all children in order to draw them. /// </summary> /// <param name="context"> /// the object that knows the place to draw this element and /// maintains its state /// </param> protected internal override void DoDraw(SvgDrawContext context) { if (GetChildren().Count > 0) { // if branch has no children, don't do anything PdfStream stream = new PdfStream(); stream.Put(PdfName.Type, PdfName.XObject); stream.Put(PdfName.Subtype, PdfName.Form); PdfFormXObject xObject = (PdfFormXObject)PdfXObject.MakeXObject(stream); PdfCanvas newCanvas = new PdfCanvas(xObject, context.GetCurrentCanvas().GetDocument()); ApplyViewBox(context); //Bounding box needs to be written after viewbox calculations to account for pdf syntax interaction stream.Put(PdfName.BBox, new PdfArray(context.GetCurrentViewPort())); context.PushCanvas(newCanvas); ApplyViewportClip(context); ApplyViewportTranslationCorrection(context); foreach (ISvgNodeRenderer child in GetChildren()) { newCanvas.SaveState(); child.Draw(context); newCanvas.RestoreState(); } CleanUp(context); context.GetCurrentCanvas().AddXObject(xObject, 0, 0); } }
/// <summary> /// Method that will set properties to be inherited by this branch renderer's /// children and will iterate over all children in order to draw them. /// </summary> /// <param name="context"> /// the object that knows the place to draw this element and /// maintains its state /// </param> protected internal override void DoDraw(SvgDrawContext context) { // if branch has no children, don't do anything if (GetChildren().Count > 0) { PdfStream stream = new PdfStream(); stream.Put(PdfName.Type, PdfName.XObject); stream.Put(PdfName.Subtype, PdfName.Form); PdfFormXObject xObject = (PdfFormXObject)PdfXObject.MakeXObject(stream); PdfCanvas newCanvas = new PdfCanvas(xObject, context.GetCurrentCanvas().GetDocument()); ApplyViewBox(context); bool overflowVisible = IsOverflowVisible(this); // TODO (DEVSIX-3482) Currently overflow logic works only for markers. Update this code after the ticket will be finished. if (this is MarkerSvgNodeRenderer && overflowVisible) { WriteBBoxAccordingToVisibleOverflow(context, stream); } else { Rectangle bbBox = context.GetCurrentViewPort().Clone(); stream.Put(PdfName.BBox, new PdfArray(bbBox)); } if (this is MarkerSvgNodeRenderer) { ((MarkerSvgNodeRenderer)this).ApplyMarkerAttributes(context); } context.PushCanvas(newCanvas); // TODO (DEVSIX-3482) Currently overflow logic works only for markers. Update this code after the ticket will be finished. if (!(this is MarkerSvgNodeRenderer) || !overflowVisible) { ApplyViewportClip(context); } ApplyViewportTranslationCorrection(context); foreach (ISvgNodeRenderer child in GetChildren()) { if (!(child is MarkerSvgNodeRenderer)) { newCanvas.SaveState(); child.Draw(context); newCanvas.RestoreState(); } } CleanUp(context); // transformation already happened in AbstractSvgNodeRenderer, so no need to do a transformation here context.GetCurrentCanvas().AddXObject(xObject, 0, 0); } }