Re: how to extend the rendering part of fop

2011-01-06 Thread gen1986

I finally worked it out. Ouf.
I had to create a ImageFactoryLoader and a Loader to create my initial Image
from the context. After reading the code I conclude that we can't avoid
creating the Loader and LoaderFacotry.

If you look at the code of
PipelineFactory.determineCandidatePipelines(ImageInfo imageInfo, ImageFlavor
targetFlavor) you can see the call to
registry.getImageLoaderFactories(imageInfo, targetFlavor) and there,
surprise : to find a pipeline you first need to get a compatible
LoaderFactory (it seems finally logic as we need an initial image so we can
convert it).

So now I'm at the state where everything works (the fop part and my
extensions) and now hope that fops implementation of Graphics2D is
compatible with Jfreechart.

At the moment drawing basic forms to the Graphis2D works and it gets
displayed into the pdf, however I have still some problems when I'm drawing
with Jfreechart (but I suppose it's my fault and hope so).

When I'll have something clean and working well I'll share it so other can
benefit of that work.

Thanks for your help.

Eugen


Jeremias Maerki-2 wrote:
 
 On 05.01.2011 16:25:20 gen1986 wrote:
 
 Hi Chris,
 
  Did you add the 
  file named org.apache.xmlgraphics.image.loader.spi.ImageConverter to 
  the JAR containing your code in META-INF\services sub directory as 
  suggested by Jeremias?
 
 Yep (you can see it in the attachment).
 
 the attachment seems to be missing.
 
 I have created a ImageChartPreloader to preload the ImageInfo from
 DOMSource. 
 What I can see is that the originalURI is null. 
 
 Yeah, looks like I gave bad advice here, that the Preloader isn't
 necessary. Obviously, it is.
 
 1) Should I do something at some place to specifiy that uri? (where,
 how...)
 
 No, no URI is involved when fo:insteam-foreign-object is used.
 
 2) However even if the originalURI is null as I can get all the infos
 from
 the source it's ok.
 But what MimeType should I give to the created ImageInfo? (I've tried
 some,
 but I always get the same error : no suitable loader/converter
 combination...etc)
 
 I've used application/x-barcode4j+xml for Barcode4J. Create another
 custom one with application/x-[something]+xml.
 
 3) I've tried to solve my problem with the preloader, but if it's not the
 right way for doing it (ex: maybe
 setting some attributes to the Document is?) tell me.
 
 I think the important thing is to support a DOMSource in the preloader
 for your case. Again, take Barcode4J as a template.
 
 4) Please take à look at the attachment, so you can tell me what is
 missing.
 
 It didn't make it to the list. Try putting everything in a ZIP.
 
 
 
 Eugen
 
 
 cbowditch wrote:
  
  On 05/01/2011 10:52, gen1986 wrote:
  
  Hello,
  Stepan and Eric thanks for the suggestions but the whole thing must be
  done
  in java (the charting is only a part of the app).
  Jeremias solution is close to what I must do.
 
  After following the explanations of Jeremias and reading the sources
 of
  Barcode4J, etc. I manage to get something out, but it still doesn't
 work
  and
  I'm not sure about some points.
 
  1) I don't have to call imageManager.convertImage(image, flavors)
 right ?
  It's the fop framework who will do that. However if it's true,
 something
  is
  going wrong because my converters are not executed.
  
  Right, the Image Loader framework takes care of that. Did you add the 
  file named org.apache.xmlgraphics.image.loader.spi.ImageConverter to 
  the JAR containing your code in META-INF\services sub directory as 
  suggested by Jeremias? This is needed in order for the Image Loader 
  Framework to be made aware of your converter.
  2) When I'm running the transformation I've got an error
  GRAVE: Image not available. URI: (instream-object). Reason:
  org.apache.xmlgraphics.image.loader.ImageException: The file format is
  not
  supported. No ImagePreloader found for null (No context info
 available).
 
  After googling a bit I've found that we have to add the following line
 to
  the fop conf :prefer-renderertrue/prefer-renderer
  That is not the correct solution. The prefer-renderer option forces use 
  of the older renderers. The old Renderers don't benefit from the latest 
  bug fixes and improvements that have been made to the painters.
  
  If I'm doing so I've got another error : No handler defined for my
  namespace...
 
  So instead asking a lot of questions I've uploaded a basic test
 project
  so
  you can see what I'm doing wrong.
  http://old.nabble.com/file/p30594894/Fop-ChartExtension.rar
  Fop-ChartExtension.rar
 
  Thanks for your help!
  
  Thanks,
  
  Chris
  
  Eugen
 
 
 
  snip/
  
  -
  To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
  For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
  
  
  
 
 -- 
 View this message in context:
 http://old.nabble.com/how-to-extend-the-rendering-part-of-fop-tp30579066p30597037.html
 Sent 

Re: how to extend the rendering part of fop

2011-01-05 Thread gen1986

Stepan and Eric thanks for the suggestions but the whole thing must be done
in java (the charting is only a part of the app).
Jeremias solution is close to what I must do.

After following the explanations of Jeremias and reading the sources of
Barcode4J, etc. I manage to get something out, but it still doesn't work and
I'm not sure about some points.

1) I don't have to call imageManager.convertImage(image, flavors) right ?
It's the fop framework who will do that. However if it's true, something is
going wrong because my converters are not executed.

2) When I'm running the transformation I've got an error
GRAVE: Image not available. URI: (instream-object). Reason:
org.apache.xmlgraphics.image.loader.ImageException: The file format is not
supported. No ImagePreloader found for null (No context info available). 

After googling a bit I've found that we have to add the following line to
the fop conf :  prefer-renderertrue/prefer-renderer

If I'm doing so I've got another error : No handler defined for my
namespace...

So instead asking a lot of questions I've uploaded a basic test project so
you can see what I'm doing wrong.
http://old.nabble.com/file/p30594894/Fop-ChartExtension.rar
Fop-ChartExtension.rar 

Thanks for your help!

Eugen



Jeremias Maerki-2 wrote:
 
 On 03.01.2011 20:34:03 gen1986 wrote:
 
 Hi Jeremias,
 
 Thanks for your quick response.
 However I'll give some more informations about what I'm trying to
 achieve.
 
 A sketch of the template :
 
 ... XSL-FO tags ...
 fo:instream-foreign-object...
 
 chart:chart xmlns:c=www...charts..
  c:pie width=.. height=..
  c:title value=Hello Piechart/
  ... some custom tags to retrieve data ...
 /c:pie
 /chart:chart
 
 ... XSL-FO tags ...
 
 My elementMapping extension handles those tags and creates my objects
 describing the chart. 
 
 1) Actually I'm extending FONode, should I rather extend
 InstreamForeignObject?
 
 You basically need a ChartObj extends XMLObj (XMLObj is a subclass of
 FONode) and a ChartElement extends ChartObj. ChartElement represents
 the top-level chart:chart elements and all its child elements can use
 ChartObj, just like I do in Barcode4J. Basically, ChartElement simply
 need to be the container for the XML sub-document and return its
 natural/intrinsic size that is used by the layout engine.
 
 At some point (when the pdf is rendered) I'll use my objects to draw the
 chart to Graphics2D. But I will not create an Image.
 
 Right, not in the sense you're probably thinking.
 
 
 As you mentioned, it looks a lot like what you are doing here :
 [3]
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageConverterBarcode2G2D.java?revision=1.1view=markup
 
 So tell me if I'm wrong :
 I must implement Graphics2DImagePainter and AbstractImageConverter, I'll
 draw there my chart to the given Graphics2D. XMLGraphics will take care
 of
 integrating it into the doc (being created by fop).
 
 That's exactly it.
 
 2) I must also extend AbstractImage, but for the moment I don't really
 understand what code to write there.
 
 Your ChartImage will simply hold whatever objects that represent the
 chart image and that you need to paint the chart. That can be the raw
 XML DOM if you want, or better probably the native object representation
 of the chart you derived from the XML content.
 
 To register the converter programatically : 
 FopFactory factory = FopFactory.newInstance();
  
 factory.getImageManager().getRegistry().registerConverter(myG2DConverter);
 
 That sounds ok. 
 
 You can do it that way, but the better way is to register the plug-ins
 through files in the META-INF/services directory in the JAR you'll
 create for the plug-in set. See here:
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/resources/services/
 
 That way, you don't have to programmatically register them. Instead they
 are automatically discovered if they are in the classpath.
 
 3) But I don't understand how to make the link between my objects and the
 registred converter.
 
 The ChartElementMapping/ChartObj/ChartElement classes are only needed
 for FOP so it can deal with the foreign XML content. I assume that
 you'll interpret the XML and create some plain Java objects that
 describe your chart. You can do that in an ImageConverterChartXML2Chart
 like I did in ImageConverterBarcodeXML2Barcode. It builds the ImageChart
 object that represents your image with all the objects you built from
 the XML. The ImageChart could be cached if it came from an external file,
 so it can be painted multiple times. Probably not what you're doing,
 though.
 
 In ImageConverterChart2G2D, you get the ImageChart from the image loader
 framework again and you build an ImageGraphics2D containing an
 Graphics2DImagePainter.
 
 The image loader framework does all the wiring for you. Let me
 illustrate that:
 1. Your FO contains an fo:i-f-o with 

Re: how to extend the rendering part of fop

2011-01-05 Thread Chris Bowditch

On 05/01/2011 10:52, gen1986 wrote:

Hello,

Stepan and Eric thanks for the suggestions but the whole thing must be done
in java (the charting is only a part of the app).
Jeremias solution is close to what I must do.

After following the explanations of Jeremias and reading the sources of
Barcode4J, etc. I manage to get something out, but it still doesn't work and
I'm not sure about some points.

1) I don't have to call imageManager.convertImage(image, flavors) right ?
It's the fop framework who will do that. However if it's true, something is
going wrong because my converters are not executed.


Right, the Image Loader framework takes care of that. Did you add the 
file named org.apache.xmlgraphics.image.loader.spi.ImageConverter to 
the JAR containing your code in META-INF\services sub directory as 
suggested by Jeremias? This is needed in order for the Image Loader 
Framework to be made aware of your converter.

2) When I'm running the transformation I've got an error
GRAVE: Image not available. URI: (instream-object). Reason:
org.apache.xmlgraphics.image.loader.ImageException: The file format is not
supported. No ImagePreloader found for null (No context info available).

After googling a bit I've found that we have to add the following line to
the fop conf :prefer-renderertrue/prefer-renderer
That is not the correct solution. The prefer-renderer option forces use 
of the older renderers. The old Renderers don't benefit from the latest 
bug fixes and improvements that have been made to the painters.



If I'm doing so I've got another error : No handler defined for my
namespace...

So instead asking a lot of questions I've uploaded a basic test project so
you can see what I'm doing wrong.
http://old.nabble.com/file/p30594894/Fop-ChartExtension.rar
Fop-ChartExtension.rar

Thanks for your help!


Thanks,

Chris


Eugen




snip/

-
To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org



Re: how to extend the rendering part of fop

2011-01-05 Thread gen1986

Hi Chris,

 Did you add the 
 file named org.apache.xmlgraphics.image.loader.spi.ImageConverter to 
 the JAR containing your code in META-INF\services sub directory as 
 suggested by Jeremias?

Yep (you can see it in the attachment).

I have created a ImageChartPreloader to preload the ImageInfo from
DOMSource. 
What I can see is that the originalURI is null. 

1) Should I do something at some place to specifiy that uri? (where, how...)

2) However even if the originalURI is null as I can get all the infos from
the source it's ok.
But what MimeType should I give to the created ImageInfo? (I've tried some,
but I always get the same error : no suitable loader/converter
combination...etc)

3) I've tried to solve my problem with the preloader, but if it's not the
right way for doing it (ex: maybe
setting some attributes to the Document is?) tell me.

4) Please take à look at the attachment, so you can tell me what is missing.



Eugen


cbowditch wrote:
 
 On 05/01/2011 10:52, gen1986 wrote:
 
 Hello,
 Stepan and Eric thanks for the suggestions but the whole thing must be
 done
 in java (the charting is only a part of the app).
 Jeremias solution is close to what I must do.

 After following the explanations of Jeremias and reading the sources of
 Barcode4J, etc. I manage to get something out, but it still doesn't work
 and
 I'm not sure about some points.

 1) I don't have to call imageManager.convertImage(image, flavors) right ?
 It's the fop framework who will do that. However if it's true, something
 is
 going wrong because my converters are not executed.
 
 Right, the Image Loader framework takes care of that. Did you add the 
 file named org.apache.xmlgraphics.image.loader.spi.ImageConverter to 
 the JAR containing your code in META-INF\services sub directory as 
 suggested by Jeremias? This is needed in order for the Image Loader 
 Framework to be made aware of your converter.
 2) When I'm running the transformation I've got an error
 GRAVE: Image not available. URI: (instream-object). Reason:
 org.apache.xmlgraphics.image.loader.ImageException: The file format is
 not
 supported. No ImagePreloader found for null (No context info available).

 After googling a bit I've found that we have to add the following line to
 the fop conf :prefer-renderertrue/prefer-renderer
 That is not the correct solution. The prefer-renderer option forces use 
 of the older renderers. The old Renderers don't benefit from the latest 
 bug fixes and improvements that have been made to the painters.
 
 If I'm doing so I've got another error : No handler defined for my
 namespace...

 So instead asking a lot of questions I've uploaded a basic test project
 so
 you can see what I'm doing wrong.
 http://old.nabble.com/file/p30594894/Fop-ChartExtension.rar
 Fop-ChartExtension.rar

 Thanks for your help!
 
 Thanks,
 
 Chris
 
 Eugen



 snip/
 
 -
 To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
 For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
 
 
 

-- 
View this message in context: 
http://old.nabble.com/how-to-extend-the-rendering-part-of-fop-tp30579066p30597037.html
Sent from the FOP - Users mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org



Re: how to extend the rendering part of fop

2011-01-05 Thread Jeremias Maerki
On 05.01.2011 16:25:20 gen1986 wrote:
 
 Hi Chris,
 
  Did you add the 
  file named org.apache.xmlgraphics.image.loader.spi.ImageConverter to 
  the JAR containing your code in META-INF\services sub directory as 
  suggested by Jeremias?
 
 Yep (you can see it in the attachment).

the attachment seems to be missing.

 I have created a ImageChartPreloader to preload the ImageInfo from
 DOMSource. 
 What I can see is that the originalURI is null. 

Yeah, looks like I gave bad advice here, that the Preloader isn't
necessary. Obviously, it is.

 1) Should I do something at some place to specifiy that uri? (where, how...)

No, no URI is involved when fo:insteam-foreign-object is used.

 2) However even if the originalURI is null as I can get all the infos from
 the source it's ok.
 But what MimeType should I give to the created ImageInfo? (I've tried some,
 but I always get the same error : no suitable loader/converter
 combination...etc)

I've used application/x-barcode4j+xml for Barcode4J. Create another
custom one with application/x-[something]+xml.

 3) I've tried to solve my problem with the preloader, but if it's not the
 right way for doing it (ex: maybe
 setting some attributes to the Document is?) tell me.

I think the important thing is to support a DOMSource in the preloader
for your case. Again, take Barcode4J as a template.

 4) Please take à look at the attachment, so you can tell me what is missing.

It didn't make it to the list. Try putting everything in a ZIP.

 
 
 Eugen
 
 
 cbowditch wrote:
  
  On 05/01/2011 10:52, gen1986 wrote:
  
  Hello,
  Stepan and Eric thanks for the suggestions but the whole thing must be
  done
  in java (the charting is only a part of the app).
  Jeremias solution is close to what I must do.
 
  After following the explanations of Jeremias and reading the sources of
  Barcode4J, etc. I manage to get something out, but it still doesn't work
  and
  I'm not sure about some points.
 
  1) I don't have to call imageManager.convertImage(image, flavors) right ?
  It's the fop framework who will do that. However if it's true, something
  is
  going wrong because my converters are not executed.
  
  Right, the Image Loader framework takes care of that. Did you add the 
  file named org.apache.xmlgraphics.image.loader.spi.ImageConverter to 
  the JAR containing your code in META-INF\services sub directory as 
  suggested by Jeremias? This is needed in order for the Image Loader 
  Framework to be made aware of your converter.
  2) When I'm running the transformation I've got an error
  GRAVE: Image not available. URI: (instream-object). Reason:
  org.apache.xmlgraphics.image.loader.ImageException: The file format is
  not
  supported. No ImagePreloader found for null (No context info available).
 
  After googling a bit I've found that we have to add the following line to
  the fop conf :prefer-renderertrue/prefer-renderer
  That is not the correct solution. The prefer-renderer option forces use 
  of the older renderers. The old Renderers don't benefit from the latest 
  bug fixes and improvements that have been made to the painters.
  
  If I'm doing so I've got another error : No handler defined for my
  namespace...
 
  So instead asking a lot of questions I've uploaded a basic test project
  so
  you can see what I'm doing wrong.
  http://old.nabble.com/file/p30594894/Fop-ChartExtension.rar
  Fop-ChartExtension.rar
 
  Thanks for your help!
  
  Thanks,
  
  Chris
  
  Eugen
 
 
 
  snip/
  
  -
  To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
  For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
  
  
  
 
 -- 
 View this message in context: 
 http://old.nabble.com/how-to-extend-the-rendering-part-of-fop-tp30579066p30597037.html
 Sent from the FOP - Users mailing list archive at Nabble.com.
 
 
 -
 To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
 For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
 




Jeremias Maerki


-
To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org



how to extend the rendering part of fop

2011-01-03 Thread gen1986

Hi,

I'm working on a project where I have to extend FO to support custom tags
for drawing charts.
For doing so I've extended ElementMapping and created my custom
ContentHandlerFactory, etc.
Until here it's ok. I can get all the infos about the chart from the xsl-fo
template.

My problem is that I want now to write the chart as a stream to the PDF, but
I don't know which fop classes to use for doing it the right way. Any help
is welcome.

If my problem isn't clear enough I can give more explanations, just let me
know ;)

Thanks,

Eugen
-- 
View this message in context: 
http://old.nabble.com/how-to-extend-the-rendering-part-of-fop-tp30579066p30579066.html
Sent from the FOP - Users mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org



Re: how to extend the rendering part of fop

2011-01-03 Thread gen1986

Hi Jeremias,

Thanks for your quick response.
However I'll give some more informations about what I'm trying to achieve.

A sketch of the template :

... XSL-FO tags ...
fo:instream-foreign-object...

chart:chart xmlns:c=www...charts..
 c:pie width=.. height=..
 c:title value=Hello Piechart/
 ... some custom tags to retrieve data ...
/c:pie
/chart:chart

... XSL-FO tags ...

My elementMapping extension handles those tags and creates my objects
describing the chart. 

1) Actually I'm extending FONode, should I rather extend
InstreamForeignObject?

At some point (when the pdf is rendered) I'll use my objects to draw the
chart to Graphics2D. But I will not create an Image.


As you mentioned, it looks a lot like what you are doing here :
[3]
http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageConverterBarcode2G2D.java?revision=1.1view=markup

So tell me if I'm wrong :
I must implement Graphics2DImagePainter and AbstractImageConverter, I'll
draw there my chart to the given Graphics2D. XMLGraphics will take care of
integrating it into the doc (being created by fop).

2) I must also extend AbstractImage, but for the moment I don't really
understand what code to write there.

To register the converter programatically : 
FopFactory factory = FopFactory.newInstance();

factory.getImageManager().getRegistry().registerConverter(myG2DConverter);

That sounds ok. 
3) But I don't understand how to make the link between my objects and the
registred converter.


Thanks again.

Eugen



Jeremias Maerki-2 wrote:
 
 Hi Eugen
 
 Assuming you're using Apache FOP 1.0 or later, I would suggest to you to
 write a set of plug-ins for the Apache XML Graphics Commons image loader
 framework. The documentation for that is found here:
 http://xmlgraphics.apache.org/commons/image-loader.html
 
 That's our new infrastructure for handling images. And your charting XML
 is nothing other than an image in XML. A good example of such a set of
 plug-ins can be found in Barcode4J:
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/
 
 You can see multiple ImageConverter implementations there. One converts
 [1] a generic XML document into an ImageBarcode [2]. And you would
 create something like an ImageChart. Furthermore, I'd go the Java2D
 route (Graphics2D), so you'd add an ImageConverter which takes an
 ImageChart and produces an ImageGraphics2D [3] (The code in there
 basically paints your chart against a Graphics2D object). The latter can
 be processed by FOP's PDF support to create high-quality vector graphics
 without you having to learn about PDF specifics. The nice side-effect is
 that it won't only work for PDF, but also for all other output formats
 supported by FOP.
 
 [1]
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageConverterBarcodeXML2Barcode.java?view=markup
 [2]
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageBarcode.java?view=markup
 [3]
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageConverterBarcode2G2D.java?view=markup
 
 If you don't plan to put charts in external files (i.e. you use only
 fo:instream-foreign-object), you can omit the Preloader, LoaderFactory
 and Loader, I think. The image converters should be enough.
 
 If there's something that our PDFGraphics2D can't handle, we can take a
 closer look at this again.
 
 HTH
 
 On 03.01.2011 16:55:32 gen1986 wrote:
 
 Hi,
 
 I'm working on a project where I have to extend FO to support custom tags
 for drawing charts.
 For doing so I've extended ElementMapping and created my custom
 ContentHandlerFactory, etc.
 Until here it's ok. I can get all the infos about the chart from the
 xsl-fo
 template.
 
 My problem is that I want now to write the chart as a stream to the PDF,
 but
 I don't know which fop classes to use for doing it the right way. Any
 help
 is welcome.
 
 If my problem isn't clear enough I can give more explanations, just let
 me
 know ;)
 
 Thanks,
 
 Eugen
 -- 
 View this message in context:
 http://old.nabble.com/how-to-extend-the-rendering-part-of-fop-tp30579066p30579066.html
 Sent from the FOP - Users mailing list archive at Nabble.com.
 
 
 Jeremias Maerki
 
 
 -
 To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org
 For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
 
 
 

-- 
View this message in context: 
http://old.nabble.com/how-to-extend-the-rendering-part-of-fop-tp30579066p30580808.html
Sent from the FOP - Users mailing list archive at Nabble.com.


-
To unsubscribe, 

Re: Re: how to extend the rendering part of fop

2011-01-03 Thread Stepan RYBAR
Hi, Eugen,

try to look for a minute on the XSL-T 2.0 library graph2svg, could be found 
on http://graph2svg.jinak.cz/examples_en.html;. It is pure XSL-T 2.0 from XML 
to SVG (when using two-phase transformation even inline SVG). The source XML 
code of graph2svg looks very similar to Your example code.

Cheers, Stepan

  Původní zpráva 
 Od: gen1986 cepoi.eu...@gmail.com
 Předmět: Re: how to extend the rendering part of fop
 Datum: 03.1.2011 20:34:39
 

 Hi Jeremias,

 Thanks for your quick response.
 However I'll give some more informations about what I'm trying to achieve.

 A sketch of the template :

 ... XSL-FO tags ...
 fo:instream-foreign-object...

 chart:chart xmlns:c=www...charts..
  c:pie width=.. height=..
  c:title value=Hello Piechart/
  ... some custom tags to retrieve data ...
 /c:pie
 /chart:chart

 ... XSL-FO tags ...

 My elementMapping extension handles those tags and creates my objects
 describing the chart.

 1) Actually I'm extending FONode, should I rather extend
 InstreamForeignObject?

 At some point (when the pdf is rendered) I'll use my objects to draw the
 chart to Graphics2D. But I will not create an Image.


 As you mentioned, it looks a lot like what you are doing here :
 [3]
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageConverterBarcode2G2D.java?revision=1.1view=markup

 So tell me if I'm wrong :
 I must implement Graphics2DImagePainter and AbstractImageConverter, I'll
 draw there my chart to the given Graphics2D. XMLGraphics will take care of
 integrating it into the doc (being created by fop).

 2) I must also extend AbstractImage, but for the moment I don't really
 understand what code to write there.

 To register the converter programatically :
 FopFactory factory = FopFactory.newInstance();
   
 factory.getImageManager().getRegistry().registerConverter(myG2DConverter);

 That sounds ok.
 3) But I don't understand how to make the link between my objects and the
 registred converter.


 Thanks again.

 Eugen



 Jeremias Maerki-2 wrote:
 
  Hi Eugen
 
  Assuming you're using Apache FOP 1.0 or later, I would suggest to you to
  write a set of plug-ins for the Apache XML Graphics Commons image loader
  framework. The documentation for that is found here:
  http://xmlgraphics.apache.org/commons/image-loader.html
 
  That's our new infrastructure for handling images. And your charting XML
  is nothing other than an image in XML. A good example of such a set of
  plug-ins can be found in Barcode4J:
 
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/
 
  You can see multiple ImageConverter implementations there. One converts
  [1] a generic XML document into an ImageBarcode [2]. And you would
  create something like an ImageChart. Furthermore, I'd go the Java2D
  route (Graphics2D), so you'd add an ImageConverter which takes an
  ImageChart and produces an ImageGraphics2D [3] (The code in there
  basically paints your chart against a Graphics2D object). The latter can
  be processed by FOP's PDF support to create high-quality vector graphics
  without you having to learn about PDF specifics. The nice side-effect is
  that it won't only work for PDF, but also for all other output formats
  supported by FOP.
 
  [1]
 
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageConverterBarcodeXML2Barcode.java?view=markup
  [2]
 
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageBarcode.java?view=markup
  [3]
 
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageConverterBarcode2G2D.java?view=markup
 
  If you don't plan to put charts in external files (i.e. you use only
  fo:instream-foreign-object), you can omit the Preloader, LoaderFactory
  and Loader, I think. The image converters should be enough.
 
  If there's something that our PDFGraphics2D can't handle, we can take a
  closer look at this again.
 
  HTH
 
  On 03.01.2011 16:55:32 gen1986 wrote:
 
  Hi,
 
  I'm working on a project where I have to extend FO to support custom tags
  for drawing charts.
  For doing so I've extended ElementMapping and created my custom
  ContentHandlerFactory, etc.
  Until here it's ok. I can get all the infos about the chart from the
  xsl-fo
  template.
 
  My problem is that I want now to write the chart as a stream to the PDF,
  but
  I don't know which fop classes to use for doing it the right way. Any
  help
  is welcome.
 
  If my problem isn't clear enough I can give more explanations, just let
  me
  know ;)
 
  Thanks,
 
  Eugen
  --
  View this message in context:
 
 

Re: how to extend the rendering part of fop

2011-01-03 Thread Jeremias Maerki
On 03.01.2011 20:34:03 gen1986 wrote:
 
 Hi Jeremias,
 
 Thanks for your quick response.
 However I'll give some more informations about what I'm trying to achieve.
 
 A sketch of the template :
 
 ... XSL-FO tags ...
 fo:instream-foreign-object...
 
 chart:chart xmlns:c=www...charts..
  c:pie width=.. height=..
  c:title value=Hello Piechart/
  ... some custom tags to retrieve data ...
 /c:pie
 /chart:chart
 
 ... XSL-FO tags ...
 
 My elementMapping extension handles those tags and creates my objects
 describing the chart. 
 
 1) Actually I'm extending FONode, should I rather extend
 InstreamForeignObject?

You basically need a ChartObj extends XMLObj (XMLObj is a subclass of
FONode) and a ChartElement extends ChartObj. ChartElement represents
the top-level chart:chart elements and all its child elements can use
ChartObj, just like I do in Barcode4J. Basically, ChartElement simply
need to be the container for the XML sub-document and return its
natural/intrinsic size that is used by the layout engine.

 At some point (when the pdf is rendered) I'll use my objects to draw the
 chart to Graphics2D. But I will not create an Image.

Right, not in the sense you're probably thinking.

 
 As you mentioned, it looks a lot like what you are doing here :
 [3]
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageConverterBarcode2G2D.java?revision=1.1view=markup
 
 So tell me if I'm wrong :
 I must implement Graphics2DImagePainter and AbstractImageConverter, I'll
 draw there my chart to the given Graphics2D. XMLGraphics will take care of
 integrating it into the doc (being created by fop).

That's exactly it.

 2) I must also extend AbstractImage, but for the moment I don't really
 understand what code to write there.

Your ChartImage will simply hold whatever objects that represent the
chart image and that you need to paint the chart. That can be the raw
XML DOM if you want, or better probably the native object representation
of the chart you derived from the XML content.

 To register the converter programatically : 
 FopFactory factory = FopFactory.newInstance();
   
 factory.getImageManager().getRegistry().registerConverter(myG2DConverter);
 
 That sounds ok. 

You can do it that way, but the better way is to register the plug-ins
through files in the META-INF/services directory in the JAR you'll
create for the plug-in set. See here:
http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xmlgraphics-commons/resources/services/

That way, you don't have to programmatically register them. Instead they
are automatically discovered if they are in the classpath.

 3) But I don't understand how to make the link between my objects and the
 registred converter.

The ChartElementMapping/ChartObj/ChartElement classes are only needed
for FOP so it can deal with the foreign XML content. I assume that
you'll interpret the XML and create some plain Java objects that
describe your chart. You can do that in an ImageConverterChartXML2Chart
like I did in ImageConverterBarcodeXML2Barcode. It builds the ImageChart
object that represents your image with all the objects you built from
the XML. The ImageChart could be cached if it came from an external file,
so it can be painted multiple times. Probably not what you're doing,
though.

In ImageConverterChart2G2D, you get the ImageChart from the image loader
framework again and you build an ImageGraphics2D containing an
Graphics2DImagePainter.

The image loader framework does all the wiring for you. Let me
illustrate that:
1. Your FO contains an fo:i-f-o with foreign XML of your custom
namespace. That is represented in FOP by an InstreamForeignObject node
(with ChartElement/Obj as children) that carries the DOM of the foreign
XML.
2. The PDF renderer/painter gets this DOM and is told to paint it at the
appropriate place on the page. The PDF output supports a distinct set of
Image subclasses represented by ImageFlavor constants. This is
communicated to the image loading framework.
3. The image loading framework now tries to find the best conversion
pipeline to convert the raw DOM (input) into an image flavor supported
by the PDF renderer (output). In your case, the following pipeline will
be selected:

DOM
  - ImageConverterChartXML2Chart
- ImageChart
  -ImageConverterChart2Graphics2D
- ImageGraphics2D

4. Finally, the PDF renderer gets back an ImageGraphics2D object that it
knows how to paint. Internally, it calls the attached
Graphics2DImagePainter (that you supplied). And your image painter gets
the current PDFGraphics2D instance as parameter to draw on.

That's about it.

If you rendered instead to RTF, for example, a different pipeline would
be selected, because our RTF output only supports bitmap images:

DOM
  - ImageConverterChartXML2Chart
- ImageChart
  -ImageConverterChart2Graphics2D
- ImageGraphics2D
  - 

RE: Re: how to extend the rendering part of fop

2011-01-03 Thread Eric Douglas
I was going to suggest SVG, the simplest way to produce a chart, but the OP 
asked about extensions like they already had something more complicated in mind 
with their mind made up about how they want to do it.

http://blog.trivadis.com/blogs/andreasmengel/archive/2008/03/14/generating-svg-pie-charts-in-pdf-documents.aspx
 

-Original Message-
From: Stepan RYBAR [mailto:xryb...@seznam.cz] 
Sent: Monday, January 03, 2011 4:19 PM
To: fop-users@xmlgraphics.apache.org
Subject: Re: Re: how to extend the rendering part of fop

Hi, Eugen, 

try to look for a minute on the XSL-T 2.0 library graph2svg, could be found 
on http://graph2svg.jinak.cz/examples_en.html;. It is pure XSL-T 2.0 from XML 
to SVG (when using two-phase transformation even inline SVG). The source XML 
code of graph2svg looks very similar to Your example code. 

Cheers, Stepan 

  Původní zpráva 
 Od: gen1986 cepoi.eu...@gmail.com
 Předmět: Re: how to extend the rendering part of fop
 Datum: 03.1.2011 20:34:39
 
 
 Hi Jeremias,
 
 Thanks for your quick response.
 However I'll give some more informations about what I'm trying to achieve.
 
 A sketch of the template :
 
 ... XSL-FO tags ...
 fo:instream-foreign-object...
 
 chart:chart xmlns:c=www...charts..  c:pie width=.. height=..  
 c:title value=Hello Piechart/  ... some custom tags to retrieve 
 data ...
 /c:pie
 /chart:chart
 
 ... XSL-FO tags ...
 
 My elementMapping extension handles those tags and creates my objects 
 describing the chart.
 
 1) Actually I'm extending FONode, should I rather extend 
 InstreamForeignObject?
 
 At some point (when the pdf is rendered) I'll use my objects to draw 
 the chart to Graphics2D. But I will not create an Image.
 
 
 As you mentioned, it looks a lot like what you are doing here :
 [3]
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xm
 lgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageConver
 terBarcode2G2D.java?revision=1.1view=markup
 
 So tell me if I'm wrong :
 I must implement Graphics2DImagePainter and AbstractImageConverter, 
 I'll draw there my chart to the given Graphics2D. XMLGraphics will 
 take care of integrating it into the doc (being created by fop).
 
 2) I must also extend AbstractImage, but for the moment I don't really 
 understand what code to write there.
 
 To register the converter programatically : 
 FopFactory factory = FopFactory.newInstance();
   
 factory.getImageManager().getRegistry().registerConverter(myG2DConvert
 er);
 
 That sounds ok. 
 3) But I don't understand how to make the link between my objects and 
 the registred converter.
 
 
 Thanks again.
 
 Eugen
 
 
 
 Jeremias Maerki-2 wrote:
  
  Hi Eugen
  
  Assuming you're using Apache FOP 1.0 or later, I would suggest to 
  you to write a set of plug-ins for the Apache XML Graphics Commons 
  image loader framework. The documentation for that is found here:
  http://xmlgraphics.apache.org/commons/image-loader.html
  
  That's our new infrastructure for handling images. And your charting 
  XML is nothing other than an image in XML. A good example of such a 
  set of plug-ins can be found in Barcode4J:
 
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xm
 lgraphics-commons/
  
  You can see multiple ImageConverter implementations there. One 
  converts [1] a generic XML document into an ImageBarcode [2]. And 
  you would create something like an ImageChart. Furthermore, I'd go 
  the Java2D route (Graphics2D), so you'd add an ImageConverter which 
  takes an ImageChart and produces an ImageGraphics2D [3] (The code in 
  there basically paints your chart against a Graphics2D object). The 
  latter can be processed by FOP's PDF support to create high-quality 
  vector graphics without you having to learn about PDF specifics. The 
  nice side-effect is that it won't only work for PDF, but also for 
  all other output formats supported by FOP.
  
  [1]
 
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xm
 lgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageConver
 terBarcodeXML2Barcode.java?view=markup
  [2]
 
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xm
 lgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageBarcod
 e.java?view=markup
  [3]
 
 http://barcode4j.cvs.sourceforge.net/viewvc/barcode4j/barcode4j/src/xm
 lgraphics-commons/java/org/krysalis/barcode4j/image/loader/ImageConver
 terBarcode2G2D.java?view=markup
  
  If you don't plan to put charts in external files (i.e. you use only 
  fo:instream-foreign-object), you can omit the Preloader, 
  LoaderFactory and Loader, I think. The image converters should be enough.
  
  If there's something that our PDFGraphics2D can't handle, we can 
  take a closer look at this again.
  
  HTH
  
  On 03.01.2011 16:55:32 gen1986 wrote:
  
  Hi,
  
  I'm working on a project where I have to extend FO