Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Elements cropping when exporting SvgNode (Read 757 times)
Dducky
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 14
Joined: Oct 17th, 2022
Elements cropping when exporting SvgNode
Feb 8th, 2023 at 12:22pm
Print Post  
The problem is illustrated within attached code.

Code
Select All
var diagram = new AtsPrintDiagram()
        {
            // Width: 1056, Height: 1600.
            Bounds = atsDiagramControl.Bounds,
        };
        var textItemLocation = new Vector2(550, 800);
        var textItemGeometry = new TextGeometry(textItemLocation)
        {
            Text = "Random text",
        };
        textItemGeometry.SetHeight(100);
        textItemGeometry.SetWidth(400);
        textItemGeometry.FontStyle.FontSize = 48;
        // Text item will override Draw method.
        // It will call diagram.DrawStyledText method.
        // ParentDiagram.DrawStyledText(graphics, coloredText, textAttributes, bounds);
        var textItem = new AtsTextDiagramItem(diagram, textItemGeometry)
        {
            // Here it's will work as expected, because it will be drawn through diagram.
            // RenderTransform = Transform.Identity,
            RotationAngle = 25,
        };
        diagram.Items.Add(textItem);

        // Also, we are always set SvgText.DrawAsPath property to 'false'.
        var svgNodeWithText = new ParentSvgNode(diagram);
        diagram.Items.Add(svgNodeWithText);

        var svgExporter = new SvgExporter()
        {
            // In this test case it doesn't matter, but in the real cases...
            // Text SvgNode drawing incorrect with SetClipPaths = true, if its 'false' it works as expected.
            // But our 'Mask' implementation doesn't work without SetClipPaths = true property.
            SetClipPaths = true,
        };
        var svgStream = new MemoryStream();
        svgExporter.Export(diagram, svgStream);
 



Code
Select All
class ParentSvgNode : SvgNode
    {
        public ParentSvgNode(AtsDiagram diagram)
        {
            Bounds = new System.Windows.Rect(0, 0, 700, 500);
            Transparent = true;

            MindFusion.Svg.SvgText.DrawAsPath = false;

            var exporter = new SvgExporter();
            var ms = new MemoryStream();

            var innerDiagram = new AtsDiagram()
            {
                Bounds = Bounds,
            };

            // Just a location where the item was dropped onto page.
            var textItemLocation = new Vector2(500, 400);
            var textItemGeometry = new TextGeometry(textItemLocation)
            {
                Text = "Exported text as svg",
            };
            textItemGeometry.SetHeight(400);
            textItemGeometry.SetWidth(400);
            textItemGeometry.FontStyle.FontSize = 36;
            // Text item will override Draw method.
            // It will call diagram.DrawStyledText method.
            // ParentDiagram.DrawStyledText(graphics, coloredText, textAttributes, bounds);
            var textItem = new AtsTextDiagramItem(diagram, textItemGeometry)
            {
                // When we apply RenderTransform or Rotation Angle its cut off.
                // Because it's nested element inside SvgNode that exported by exporter and loaded by node.
                // RenderTransform = Transform.Identity,
                // RotationAngle = 25,
            };

            innerDiagram.Items.Add(textItem);

            exporter.Export(innerDiagram, ms);

            this.LoadSvg(ms);
        }
    }
 



AtsTextDiagramItem internally change RenderTransform and RotationAngle properties dependent on our setups, it works as expected when we just add it to the Diagram.Items collection, but when we export this element as Svg (by SvgExporter) and then load content by SvgNode (and append node to the Diagram.Items) collection - it's cut off. As i see, its related with the RenderTransform and RotationAngle.

Attachment 1: ParentSvgNode (in constructor) textItem.RotationAngle is not set (it's 0), i'm not sure maybe RenderTransform is a little changed. It's drawn with a little cutting from top.
Attachment 2: ParentSvgNode (in constructor) textItem.RotationAngle = 25, an element just cut off from the diagram.

Related topic with the mask:
https://mindfusion.eu/Forum/YaBB.pl?num=1675858956/0#0

If we set SetClipPaths to false it will work as expected, also with the SvgNode.
  

Untitled_028.png ( 65 KB | 30 Downloads )
Untitled_028.png
Untitled1.png ( 44 KB | 35 Downloads )
Untitled1.png
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Elements cropping when exporting SvgNode
Reply #1 - Feb 9th, 2023 at 5:04pm
Print Post  
We can't understand that code very well with all the custom classes of yours, and dealing with the intricacies of generating SVG from custom-drawn and masked objects is rather low priority for us overall. Please at least attach a minimal reproducible project our developer could compile and run to investigate.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint