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:
 
 http://old.nabble.com/how-to-extend-the-rendering-part

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