empira / PDFsharp

PDFsharp and MigraDoc Foundation for .NET 6 and .NET Framework
https://docs.pdfsharp.net/
Other
492 stars 114 forks source link

Add initialization of XGraphicsPath from its native counterpart #103

Closed xyznobody2 closed 5 months ago

xyznobody2 commented 5 months ago

I'm working with the WPF version and need to create an XGraphicsPath from a WPF PathGeometry, but the interface of XGraphicsPath makes this very complicated, even if it uses a PathGeometry internally. Would it be possible to add a constructor to XGraphicsPath from a PathGeometry that initializes the path with a clone of the PathGeometry (if there are no other restrictions that I do not know of) or else do the conversion inside that constructor? Maybe it is also an option for the other versions of PDFsharp to add a constructor to XGraphicsPath from the corresponding native path type.

StLange commented 5 months ago

Oh yes, I overlooked that. I think adding a constructor like this

#if WPF
public XGraphicsPath(PathGeometry pathGeometry) => PathGeometry = pathGeometry;
#endif

should help. All other code for rendering a PathGeometry to PDF already exists (see AppendPath(PathGeometry geometry) in XGraphicsPdfRenderer)

I will add this to the Preview 3.

StLange commented 5 months ago

I just add a new constructor and a new member function to XGraphicPath for WPF build:

public XGraphicsPath(PathGeometry geometry)
public void AddGeometry(PathGeometry geometry)

Quadratic Bézier segments are still not yet implemented. Let me know if you have issues with PathGeometry.