Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Export to SVG and PDF not working properly (Read 6878 times)
Ton Trommelen
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 11
Joined: Jun 10th, 2013
Export to SVG and PDF not working properly
Jun 10th, 2013 at 10:14am
Print Post  
Hi,

when I export a diagram to SVG and/or PDF the output is not as it should be;

with SVG the size of the nodes in the diagram is to big and with PDF I loose text information of the nodes.

....see attachments....

What can be causing this and how to fix it?
  

diagram_capture.png (Attachment deleted)
pdf_export.png (Attachment deleted)
svg_export.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to SVG and PDF not working properly
Reply #1 - Jun 10th, 2013 at 11:59am
Print Post  
Hi,

Please attach the diagram saved as XML file.

Stoyan
  
Back to top
 
IP Logged
 
Ton Trommelen
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 11
Joined: Jun 10th, 2013
Re: Export to SVG and PDF not working properly
Reply #2 - Jun 10th, 2013 at 2:44pm
Print Post  
...here is the XML file...

Note that I'm using a custom node class.....can this be the problem?
  

diagram.zip ( 2 KB | 347 Downloads )
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to SVG and PDF not working properly
Reply #3 - Jun 10th, 2013 at 5:11pm
Print Post  
Could you post your drawing code then? Please also implement the XML serialization methods and attach the file again, so that we can try it with your images and texts, for example:

Code
Select All
protected override void SaveToXml(XmlElement xmlElement, XmlPersistContext context)
{
    base.SaveToXml(xmlElement, context);

    context.WriteImage(icon, "Icon", xmlElement);
    context.WriteString(label, "Label", xmlElement);
}

protected override void LoadFromXml(XmlElement xmlElement, XmlPersistContext context)
{
    base.LoadFromXml(xmlElement, context);

    icon = context.ReadImage("Icon", xmlElement);
    label = context.ReadString("Label", xmlElement);
} 



Quote:
Note that I'm using a custom node class.....can this be the problem?


We might have not implemented correctly for SVG/PDF IGraphics method overloads that are not used by standard node types, so perhaps you can get better results by using a different Draw* overload, e.g. DrawImage(RectangleF) instead of DrawImage(x,y).
  
Back to top
 
IP Logged
 
Ton Trommelen
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 11
Joined: Jun 10th, 2013
Re: Export to SVG and PDF not working properly
Reply #4 - Jun 10th, 2013 at 9:31pm
Print Post  
Here is the node class I use....
  

IconNode.zip (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to SVG and PDF not working properly
Reply #5 - Jun 11th, 2013 at 7:13am
Print Post  
This version of Draw should work fine when exporting:

Code
Select All
	Public Overrides Sub Draw(ByVal graphics As IGraphics, ByVal options As RenderOptions)
		Dim iconSizePixels As Rectangle = New Rectangle(0, 0, imgIcon.Width, imgIcon.Height)
		Dim imageSize As RectangleF = MindFusion.Utilities.DeviceToDoc(graphics, iconSizePixels)

		' Draw the icon center at the top
		Dim lPoint As System.Drawing.PointF
		lPoint.X = Bounds.X + Bounds.Width / 2 - imageSize.Width / 2
		lPoint.Y = Bounds.Y

		Dim r As RectangleF
		r = New RectangleF( _
		 Form1.diagView.ClientToDoc(Form1.diagView.DocToClient(lPoint)), imageSize.Size)
		graphics.DrawImage(imgIcon, r)

		'Draw the label at the bottom
		Dim labelBounds As RectangleF = RectangleF.FromLTRB(Bounds.X, Bounds.Y + imageSize.Height, Bounds.Right, Bounds.Bottom)
		labelBounds.Inflate(10, 0)

		graphics.DrawString(title, Font, New System.Drawing.SolidBrush(ColorTranslator.FromHtml(tcolor)), labelBounds, format)
	End Sub
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Ton Trommelen
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 11
Joined: Jun 10th, 2013
Re: Export to SVG and PDF not working properly
Reply #6 - Jun 11th, 2013 at 8:21am
Print Post  
Hi!

....your new code works much better....but it's not quite perfect yet; I still loose the text on the second line. See attachment;

(FTPSupload) should be:

(FTPSupload)
Test upload

...any chance this can be fixed as well?
  

svg.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to SVG and PDF not working properly
Reply #7 - Jun 11th, 2013 at 12:10pm
Print Post  
The text seems to clip to the specified rectangle both in SVG and PDF, so try making the rectangle large enough:

Code
Select All
'Draw the label at the bottom
Dim labelSize = Parent.MeasureString( _
	title, EffectiveFont, Integer.MaxValue, format)
Dim labelBounds As RectangleF = New RectangleF( _
	Bounds.X, Bounds.Y + imageSize.Height, labelSize.Width, labelSize.Height)
labelBounds.Inflate(5, 5)

graphics.DrawString(title, _
	Font, New System.Drawing.SolidBrush(ColorTranslator.FromHtml(tcolor)), labelBounds, format)
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Ton Trommelen
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 11
Joined: Jun 10th, 2013
Re: Export to SVG and PDF not working properly
Reply #8 - Jun 11th, 2013 at 3:01pm
Print Post  
I changed line: labelBounds.Inflate(10, 0)

to: labelBounds.Inflate(5, 5)

That did the trick.

Thanks a lot for the help!!!!
  
Back to top
 
IP Logged
 
Ton Trommelen
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 11
Joined: Jun 10th, 2013
Re: Export to SVG and PDF not working properly
Reply #9 - Jun 11th, 2013 at 3:25pm
Print Post  
I cheered a little to soon; although the diagram and the exports are now ok.....the overview is not! This now contains big icons....see attachments.

????
  

diagram.png (Attachment deleted | 0 Downloads )
overview.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to SVG and PDF not working properly
Reply #10 - Jun 11th, 2013 at 4:07pm
Print Post  
It probably happens because the image size is converted from pixels using DiagramView.DeviceToDoc, which calculates it using a different scale than the one set for the Overview. You could keep your old image drawing code that does not specify size and run it inside an "if typeof (graphics) is GdiGraphics" block, and put the current code in an else statement for SvgGraphics and PdfGraphics.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Ton Trommelen
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 11
Joined: Jun 10th, 2013
Re: Export to SVG and PDF not working properly
Reply #11 - Jun 11th, 2013 at 8:09pm
Print Post  
That did the trick!

Thanks again!!!!
  
Back to top
 
IP Logged
 
Ton Trommelen
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 11
Joined: Jun 10th, 2013
Re: Export to SVG and PDF not working properly
Reply #12 - Jun 12th, 2013 at 5:51pm
Print Post  
Now that I'm more into this Draw() stuff;

the overview is still not as good as it can be I think....see attachments.

Is there any way to improve the overview using my custom class?

Thanks for all your help!
  

diagram_001.png (Attachment deleted)
overview_001.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Export to SVG and PDF not working properly
Reply #13 - Jun 13th, 2013 at 8:45am
Print Post  
The problem is that when converting image size from pixels for centering the image and for finding label offset, you need only its size in millimeters, without considering the scale applied on the graphics, while the code above also applies the scale transform.  Try this version instead:

Code
Select All
Public Overrides Sub Draw(ByVal graphics As IGraphics, ByVal options As RenderOptions)
	Dim iconSizePixels As Rectangle = New Rectangle(0, 0, imgIcon.Width, imgIcon.Height)

	' convert to millimeters without considering scale
	Dim g As GdiGraphics
	g = Parent.CreateMeasureGraphics()
	g.ResetTransform()
	Dim imageSize As RectangleF = Utilities.DeviceToDoc(g, iconSizePixels)

	g.Dispose()

	' Draw the icon center at the top
	Dim lPoint As System.Drawing.PointF
	lPoint.X = Bounds.X + Bounds.Width / 2 - imageSize.Width / 2
	lPoint.Y = Bounds.Y

	Dim r As RectangleF
	r = New RectangleF( _
	 Form1.diagView.ClientToDoc(Form1.diagView.DocToClient(lPoint)), imageSize.Size)
	graphics.DrawImage(imgIcon, r)

	'Draw the label at the bottom
	Dim labelSize = Parent.MeasureString( _
	 title, EffectiveFont, Integer.MaxValue, format)
	Dim labelBounds As RectangleF = New RectangleF( _
	 Bounds.X, Bounds.Y + imageSize.Height, labelSize.Width, labelSize.Height)
	labelBounds.Inflate(5, 5)

	graphics.DrawString(title, _
	 Font, New System.Drawing.SolidBrush(ColorTranslator.FromHtml(tcolor)), labelBounds, format)
End Sub
 



With the size only converted to millimeters, you also don't need a separate case for Svg and PdfGraphics:



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Ton Trommelen
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 11
Joined: Jun 10th, 2013
Re: Export to SVG and PDF not working properly
Reply #14 - Jun 17th, 2013 at 8:52am
Print Post  
Works great! Thanks!!!!!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint