PDFsharp & MigraDoc Foundation

Custom DocumentObject / Renderer
Page 1 of 1

Author:  oleneveu [ Wed Feb 24, 2016 2:02 pm ]
Post subject:  Custom DocumentObject / Renderer


I've been asked recently to add a very specific chart to one of the reports of the software I'm working on.
I could not manage to render this chart using the 'Chart' class from Migradoc, and I could not use the "mix MigraDoc and PdfSharp" technic neither as the chart integrates in an existing complex report (all done using MigraDoc).

So I considered writing my owns DocumentObject/Renderer classes but I quickly discovered that the library does not allow this kind of extensions as many classes/methods/properties are marked as internal. The only workaround is to make a fork of the whole code with all the constraints that it brings.

I've added a static method to the 'Renderer' class that allow to register a new type of renderer for a particular DocumentObject, and removed the internal modifier from some classes.

Could that kind of changes be accepted if I make a pull request on GitHub?

Best regards,

O. Leneveu

Author:  Thomas Hoevel [ Wed Feb 24, 2016 2:15 pm ]
Post subject:  Re: Custom DocumentObject / Renderer


We have to see the changes to decide whether we will include them.

A ZIP with the changed files might be easier for us than a pull request.

Author:  oleneveu [ Wed Feb 24, 2016 3:09 pm ]
Post subject:  Re: Custom DocumentObject / Renderer


Thanks for your answer.
The changed files are attached, based on v1.50 beta3b.

The most important change is in the 'Renderer' class: I've added a callback as a property. This callback is called from the 'Create()' methods to resolve the 'Renderer' type for a custom DocumentObject class.
I did not declared the callback as an 'event' because the delegate has a return value, and as an event can be attached more than once this could lead to unpredictable results.

All other changes consists of changing the 'internal' modifier to 'public' where I needed it.
As I told you, I'm writing a custom chart so I have inherited my custom DocumentObject and Renderer classes from 'Shape' and 'ShapeRenderer', but depending on the base class that someone would like to inherits from some other classes might have to be modified the same way.

Olivier Leneveu

MigraDoc.zip [51.66 KiB]
Downloaded 481 times

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group