You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Julien Aymé <ju...@gmail.com> on 2010/05/06 13:32:24 UTC

Using custom PSDocumentGraphics2D to use user-defined PS procedures

Greetings,

I am currently trying to generate a Postscript document using a custom
PSDocumentGraphics2D (my class extends PSDocumentGraphics2D),
and the main aim is to use a user-defined Postscript procedure to draw
some simple Polygons which are in huge numbers in the document I have
to produce
(To reduce the size of the Postscript document generated).

The polygons I have to draw are Rectangles, and Arrows, which can be
defined with four points.
I defined a new Interface, SpecializedPolygonGraphics which define
these methods:
    draw(Rectangle2D)
    drawArrow(double, double, double, double, boolean)
and their equivalents fill and fillArrow.

This interface is implemented by the class MyPSDocumentGraphics2D
which extends PSDocumentGraphics2D,
and instead of using the fill/draw(Shape) method, it generates the
corresponding call to my Postscript procedure.

I have struggled quite a bit in order to make it work, so I am
wondering whether my approach is good or not:

- The first problem came when I wanted to write my own Procedure set
in the file header:
My class had to override the PSDocumentGraphics2D#writeFileHeader
method in order to define my procedure set before the END_SETUP
comment.

- When using FOP's NativeTextHandler (to draw text as Plain Text in
the Postscript document), I noticed that the generated Postscript
document was not valid:
The font were used with their alias (F1, F2, ...) but I could not find
any definition for these aliases in the PS setup.
So I had to fix FOP's PSFontUtils to generate another bloc after
writeFontDic which would generate the aliases definitions.
[ by the way, should I submit a patch for this ? Or is this just a
misuse of NativeTextHandler ? ]

- First, I overrode the PSGraphics2D#create() method in order to
return an instance of my class, but it broke the generated Postscript
document:
A new page was generated after each create() call. A notice should be
written in PSGraphics2D that this method should not be overriden.

A hint should be made to duplicate the drawShape method for custom draw methods:
preparePainting, saveState, applyTransform if required, clip,
color/paint, do the custom draw, restoreState.

Anyway, even with the small difficulties, this library helped save a
lot of time in my work, it is awesome ;-)


Should I fill enhancement requests (with patch provided of course) to BugZilla ?
Any comments, tips or thoughts are welcomed and greatly appreciated.

Regards,
Julien Aymé