You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by Thomas DeWeese <Th...@Kodak.com> on 2005/01/03 12:01:00 UTC

Re: Whitespace Handling in Batik vs ASV

Hi Rick,

    You might want to check out current CVS Batik.  I just delivered
an updated version that has "improved" whitespace handling.  I still
don't think the specification is at all clear on what the proper
behavior is, but in your simple case the new behavior should be what
you want.

    I mostly did this because there were places where the old
code would behave in violation of what the SVG specification does
specify, and the new version is _much_ cleaner and easier to follow
(IMHO).  Also it should be easier to bring into conformance with
whatever the SVG-WG decides on.

Rick Bullotta wrote:

> On further exploration, because there are element in a non-SVG namespace
> between the whitespace text nodes, they shouldn't/couldn't be normalized.
> Thus, the issue is that in the case of multiple child text nodes,
> "stripfirst" will only apply to the first text node.  At first glance, this
> would appear to be a bug.  Perhaps the "first" variable should be reset to
> true upon encountering a non-text node or a node not in the SVG namespace.
> 
> We'll experiment a bit and see what happens in this case.
> 
> 
> -----Original Message-----
> From: Rick Bullotta [mailto:rick.bullotta@lighthammer.com] 
> Sent: Monday, December 27, 2004 9:50 AM
> To: batik-dev@xml.apache.org
> Subject: RE: Whitespace Handling in Batik vs ASV
> 
> Looking at the source in SVGTextElementBridge.java, it would appear that
> additional leading whitespace would not be properly stripped when there are
> multiple child text nodes containing only whitespace (I believe this may be
> due to the "first" boolean variable being outside the loop iterating the
> child nodes and therefore incorrectly not setting "stripFirst" for text
> nodes other than the first).
> 
> Assuming for a moment that somewhere in the SAXSVGDocumentFactory
> implementation, DOM normalization is not occurring, two questions come to
> mind, I tried adding an explicit call to doc.normalize(), to no avail.
> 
> Iterating for empty text nodes (and removing them), as Tonny has suggested,
> would be a workaround, but a definite performance hit.
> 
> Open to any other suggestions...
> 
> Rick Bullotta
> CTO
> Lighthammer Software (http://www.lighthammer.com)
> 
> -----Original Message-----
> From: Thomas DeWeese [mailto:Thomas.DeWeese@Kodak.com] 
> Sent: Sunday, December 26, 2004 1:44 PM
> To: batik-dev@xml.apache.org
> Subject: Re: Whitespace Handling in Batik vs ASV
> 
> Rick Bullotta wrote:
> 
> 
>>A bit more information:
>>
>>It appears to be that the various viewers handle the 
>>"xml:space=preserve" attribute.ASV and SharpVectorGraphics seem to 
>>ignore it altogether, and Batik seems to honor it (somewhat), but still 
>>converts linefeeds into spaces when preserve is not enabled.
> 
> 
>     No it drops linefeeds when xml:space is set to "default" the
> question is how child elements of the text element interact with
> white space handling. So in your second case you have:
> 
>   [space 1]<element/>[space 2][text][space 3]
> 
>     So clearly "space 1" and "space 3" are to be eliminated
> the question is what should happen to "space 2"?  Is it
> part of leading space? or is it part of 'text'.  What if
> element is a tspan/tref (even if empty?), what if it's a
> glyphRef (which is always empty).  What if it has a
> separate value for "xml:space"?  This is really quite complex.
> 
>     I don't actually think the specification is sufficiently
> clear on the handling of child elements to properly implement
> this.  One thing that really has me wondering is that is seems
> to strongly imply that xml:space is only used on the root 'text'
> element.  If this is the case then you could take a model where
> all child 'text' is put in the string that is passed to the
> collapsing function.  This would still leave a question of when
> a string of whitespace is collapsed that has content from
> multiple elements how does one style the resultant whitespace?
> As well as how to treat glyphRef which doesn't have any real
> text content associated.
> 
> BTW in the future it is best to post working examples.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-dev-help@xml.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-dev-help@xml.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-dev-help@xml.apache.org
> 


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


Re: [Patch] Whitespace Handling in Batik vs ASV

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

>     I really think what you are trying to do is flawed at a pretty deep
> level. For example you can't even get the "right" result for xml:space
> handling of SVG text elements without knowing about svg:text elements
> (the elimination of WS at the start and end of the text makes
> this impossible).
> 
>     Can you say why you want to do this?  Perhaps I can suggest a less
> problematic way to get what you want.

Thank you for the correction and info.
What I trying to achieve is because Batik produced DOM is produce a lot of empty Text Node, on Level 2 DOM tree between element always have empty Text Node. So I think (I could be wrong) if I can eliminate those empty Text Node correctly, the DOM processing eg: iterating the DOM, looking for certain node, etc could be faster and maybe the DOM memory consumption is better.

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com



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


Re: [Patch] Whitespace Handling in Batik vs ASV

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Tonny,

Tonny Kohar wrote:
>>First I don't think you can do whitespace handling in the parser.
>>It's a little hard to know exactly where Batik fits in the XML scheme
>>of things (it's not 100% clear to me if it is an XML processor or an
>>Application) but my reading of the XML spec indicates that Batik can't
>>strip spaces they must be made available through the DOM.
> 
> 1) Since it is a DOM stuff, not a XML stuff. I am going to rewrite it
> for DOM normalize method, is this approach correct ?

    I don't think so, from the DOM 2 spec:

	Puts all Text nodes in the full depth of the sub-tree
	underneath this Node, including attribute nodes, into a
	"normal" form where only structure (e.g., elements, comments,
	processing instructions, CDATA sections, and entity
	references) separates Text nodes, i.e., there are neither
	adjacent Text nodes nor empty Text nodes.

    Note that it does not mention anything about XML space and
seems to be pretty clear that the _only_ change is the merging
of adjacent Text nodes.

> 2) When digging the Batik DOM for this stuff, I found AbstractParentNode
> provide implementation for normalize() however it does not cater for XML
> space preserve|default. Is this implementation correct?

    It looks correct to me according to the DOM specification.  It is
possible that it should also look to merge CDATA sections.

> 3) Is there something about xml preserve stuff that I should consider
> for? Looking through DOM & XML spec from W3C it doesn't say much
> regarding this matter?

    I used the search feature of the W3C site (XML space - I think)
and got a direct hit.  The important thing is that according to the
W3C spec xml:space should have no effect from the XML processor it
is there for XML applications to use.  As I said it's a little hard
to know if Batik is an XML processor or an XML Application, but I
think that what ever is using Batik is the application and Batik
should play the role of processor as much as possible.

> 4) Since text node could contains entity, what entity I should consider
> for? Do I only need to consider the predefined entity in XML spec which
> is only &amp;, &gt; &lt;, &apos;, &quot; ? How to handle non predefined
> entity?

    I think entities will be expanded by the time you see them (by the
XML parser), but they may generate a separate Text Node.

    I really think what you are trying to do is flawed at a pretty deep
level. For example you can't even get the "right" result for xml:space
handling of SVG text elements without knowing about svg:text elements
(the elimination of WS at the start and end of the text makes
this impossible).

    Can you say why you want to do this?  Perhaps I can suggest a less
problematic way to get what you want.

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


Re: [Patch] Whitespace Handling in Batik vs ASV

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

> First I don't think you can do whitespace handling in the parser.
> It's a little hard to know exactly where Batik fits in the XML scheme
> of things (it's not 100% clear to me if it is an XML processor or an
> Application) but my reading of the XML spec indicates that Batik can't
> strip spaces they must be made available through the DOM.

1) Since it is a DOM stuff, not a XML stuff. I am going to rewrite it
for DOM normalize method, is this approach correct ?

2) When digging the Batik DOM for this stuff, I found AbstractParentNode
provide implementation for normalize() however it does not cater for XML
space preserve|default. Is this implementation correct?

3) Is there something about xml preserve stuff that I should consider
for? Looking through DOM & XML spec from W3C it doesn't say much
regarding this matter?

4) Since text node could contains entity, what entity I should consider
for? Do I only need to consider the predefined entity in XML spec which
is only &amp;, &gt; &lt;, &apos;, &quot; ? How to handle non predefined
entity?

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com



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


Re: [Patch] Whitespace Handling in Batik vs ASV

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

>      Thanks for the patch but I think there are two issues with this.
> First I don't think you can do whitespace handling in the parser.
> It's a little hard to know exactly where Batik fits in the XML scheme
> of things (it's not 100% clear to me if it is an XML processor or an
> Application) but my reading of the XML spec indicates that Batik can't
> strip spaces they must be made available through the DOM.

Thanks for the info. So the spaces handling is for DOM not for XML. If
the XML spec say so, just ignore the patch :) It is better to follow the
spec.

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com



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


Re: [Patch] Whitespace Handling in Batik vs ASV

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Tonny,

Tonny Kohar wrote:

> I would like to submit patch for the initial parsing white space
> handling. The patch is attached to this email.

     Thanks for the patch but I think there are two issues with this.
First I don't think you can do whitespace handling in the parser.
It's a little hard to know exactly where Batik fits in the XML scheme
of things (it's not 100% clear to me if it is an XML processor or an
Application) but my reading of the XML spec indicates that Batik can't
strip spaces they must be made available through the DOM.

> This patch is normalize the document on the parsing stage and it is also
> handle XML space attribute based on return value of
> XMLSupport.getXMLSpace(Element)

    I also don't think this is done quite right in some cases you
will introduce new spaces and in other cases you will remove
spaces that should be kept.

eg:
     <text>foo&amp;bar</text>
	will likely become: "foo & bar" instead of "foo&bar".
     <text>foo <baz:blah/>bar</text>
	Will become: "foo<baz:blah>bar" instead of staying the same.

> Do I need to put this into bugzilla?

    Feel free to but I think there are fundamental issues (like
violation of the XML spec) with trying to handle this in this manner.
It may be fine for your application because you know those spaces are
never important but as a general processing tool Batik can't do it.

    Finally, did the new space handling I checked in a few weeks ago
fix text for you?  Or are you worried about something else?


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


Re: [Patch] Whitespace Handling in Batik vs ASV

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

I would like to submit patch for the initial parsing white space
handling. The patch is attached to this email.

This patch is normalize the document on the parsing stage and it is also
handle XML space attribute based on return value of
XMLSupport.getXMLSpace(Element)

Do I need to put this into bugzilla?

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com


RE: Whitespace Handling in Batik vs ASV

Posted by Rick Bullotta <ri...@lighthammer.com>.
Will do.  We temporarily tweaked the class for our internal testing and it
worked well.  Any rough timeframe on an official next release?  And I
wholeheartedly agree that the spec (or, more properly, "specs", since some
base XML behaviors are involved here) is ambiguous.

Thanks!

- Rick
-----Original Message-----
From: Thomas DeWeese [mailto:Thomas.DeWeese@Kodak.com] 
Sent: Monday, January 03, 2005 6:01 AM
To: batik-dev@xml.apache.org
Subject: Re: Whitespace Handling in Batik vs ASV

Hi Rick,

    You might want to check out current CVS Batik.  I just delivered
an updated version that has "improved" whitespace handling.  I still
don't think the specification is at all clear on what the proper
behavior is, but in your simple case the new behavior should be what
you want.

    I mostly did this because there were places where the old
code would behave in violation of what the SVG specification does
specify, and the new version is _much_ cleaner and easier to follow
(IMHO).  Also it should be easier to bring into conformance with
whatever the SVG-WG decides on.


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