xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Peter Armstrong" <armstr...@intalio.com>
Subject RE: problems generating SVG
Date Wed, 11 Apr 2001 19:01:30 GMT
>     I realized as I walked out to my car last night, that while you
> should be able to pass SVGGraphics2D into the paint method on a
> JSVGComponent (hence #1, a bug in SVGGraphics2D), you still won't get
> what you want (which is presumably some semblance of the original
> SVG).  What you will get is one large PNG embedded in the SVG file
> (hence #2, JSVGComponent really isn't meant to be painted with
> SVGGraphics2D). The JSVGComponent does a lot of caching of image data
> under the hood, and so it only ever draws a finished image to the
> Graphics passed to it's paint method.

Actually, after I sent that "thanks it's working perfectly now" email to
you, I did a bit more testing and realized that it wasn't working at all.
Then I looked at the generated SVG and saw the PNG images, and figured out
what you just described above.  I realized it was very naive of me to expect
the SVGGraphics2D to do anything but the default behavior (render a
component the best way it knows) with the JSVGComponent it was rendering.

So I decided that I was a bit out of my depth.  What I thought might be
theoretically possible would be to somehow get the JSVGComponent to paint
itself on my SVGGraphics2D (basically, what you just described in your
email), but I didn't know how to do that.  And even if I *could* do this, I
would need to do this self-painting in the correct location: I have many
JSVGComponents in different locations, and if I just got them to blindly
draw themselves on my JSVGComponent, the location information would be gone
and they'd all end up drawing on top of each other in the top left corner.

Am I making sense, or am I missing something completely obvious again?

>    Hope I haven't completely discouraged you.

No, actually.  Thanks to your help, I actually have a working sub-optimal
solution right now:

The paintComponent method of my JPanel that contains the JSVGComponents does
the following:

1. call super.paintComponent(g)
2. call a public drawSelf(g) method to do all my extra drawing

Then, in my drawSelf method, I check if I'm rendering on an SVGGraphics2D.
If so, I draw rectangles with the bounds of each of the JSVGComponents.  So
then (finally) to produce the SVG preview of my document, I just call my
drawSelf method--not paintComponent.  This way, I don't get any of the PNG
images (which actually give me annoying exceptions when they're being
generated), since the JSVGComponents in the panel get painted in the call to
super.paintComponent()--not in drawSelf().  Of course, when the SVG preview
is scaled big it looks terrible since the JSVGComponents are just
represented by rectangles, but for normal usage it's still very useful since
all the other stuff is drawn fine.  The big benefit, of course, is that I
didn't have to write a bunch of extra code myself to generate my (scalable)

So, I am just going to stick with my sub-optimal solution until either (1)
Batik is modified in a way that lets me try one of the methods you suggested
in your email or (2) the SVGGraphics2D code had a special case added to it
for rendering JSVGComponents as SVG not PNG.

Thank you very much for all your help,
Peter Armstrong

To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org

View raw message