xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thomas.dewe...@kodak.com
Subject Re: Modifying internal CSS in SVG document - partial solution - need help with batik re-draw/update
Date Wed, 02 Apr 2008 10:14:16 GMT
Hi Rob,

Rob Davis-5 <tech@robertjdavis.co.uk> wrote on 03/25/2008 10:08:03 AM:

> Please find below some code I've written to modify the internal CSS
within an
> SVG document.
>
> What I need:
> I need help with telling batik to update/redraw the drawing following the
> modification.
>
> Detail:
> I am not using Swing or any associated batik libraries and do not wish
to.
> What I want is for the GVTBuilder/GraphicsNode/Bridge or whatever to be
> updated to take into account my CSS modification so that I can then do my
> processing of the drawing. The resultant text SVG XML that I output
should
> also reflect all the changes.

   For changes in the DOM to be reflected in the Graphics tree you
need to make sure you set the BridgeContext to be dynamic.

> My solution manipulates the batik CSS objects. I have to say, the
> documentation is very minimal in this area! But with the help of print
outs,
> debugging and Eclipse I achieved my solution.

   So you are going deep into the internals of our CSS implementation.
The interface you should be using (because it will be stable rather
than changed as needed) is the CSS DOM (see later).

> Batik is not very defensive at all with this. When I process it, the
> exception I get originates from non-batik code in the awt, when it tries
to
> render a negative stroke width of a font - here's that excerpt from the
> exception call stack again

   Batik should catch the negative font size in the Text Bridge and
signal an error there (rather than having the render fail).  The fact
that it doesn't is a bug in Batik.  In any case that wouldn't help you
much, since you want it to render something (although you don't seem
to have  clear idea of _what_ you want it to render :).

> What is does is seek out the offending negative font size CSS style, make
it
> positive. Then it finds the SVG elements that use the style. At this
point I
> want to tell batik to update them but don't know how. See also my
comments
> after the code.

   So I would suggest that all you really need to do is find all the text
elements (getElementsByTagNameNS). Then check the font-size property on
that element (SVGSVGElement.getComputedStyle).  If it is negative you can
set the font-size property on that element (SVGElement.getStyle(), and
CSSStyleDeclaration.setProperty).

   This won't 'fix' the style sheets but will fix every problem Text
Element.
It will also do so in a way that will be reflected when you write the
document back out.

> However, the batik system is not completely updated - because when I then
go
> on to process the drawing - I still get the same exception.
>
> So my question is - how to update the entire batik system?

   How are you trying to draw the document after your modifications?
If you are trying to pass the DOM to the transcoder's that won't work
well because the transcoders will rebuild the CSS engine and graphics
tree (effectively disposing of your changes).  If you use 'setProperty'
as I suggest above I think it would work (because setPropery updates the
'style' attribute on the element).

   The more efficient way to draw the document would be to bypass
the transcoders and call the underlying code directly (the biggest
thing you lose is the 'auto sizing' stuff from the transcoders
but that is more complex in the transcoders do to generality).
Take a look at ImageTranscoder mostly (the auto size stuff is
mostly in SVGAbstractTranscoder).

Mime
View raw message