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.1&view=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
          -> ImageConverterGraphics2D2Bitmap
            -> ImageRenderedImage

I hope that clears things up a bit.

> 
> 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.
> 



Jeremias Maerki


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

Reply via email to