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 Tonny Kohar <to...@kiyut.com> on 2004/02/04 08:55:45 UTC

Enhancement for OutputManager (SVGTranscoder)

Hi,

I would like to submit enhancement for OutputManager. 
This patch will format the attrib to have new line on the specified
documentWidth and indent the newline according to getTabulationWidth
useful for example to format very long path element d attribute.

I attached the cvs diff -u format in this message and here is the
bug(not a bug just enhancement) id # 26651

btw, there is no Transcoder group on the bugzilla under batik. So I just
put in under utilities group. 


Regards
Tonny Kohar
http://www.kiyut.com

Re: Enhancement for OutputManager (SVGTranscoder)

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

> I would like to submit the DOM to source file transcoder with Pretty
> Printer formating rule.  This time no cvs diff -u because it is
> completely new file. See the attachment. Almost all the code is copy and paste from DOMUtilitis and svg2svg transcoder with modification.
> 
> I put it under the package org.apache.batik.transcoder.dom, because I
> think it is different from org.apache.batik.transcoder.svg2svg (Source
> to Source) and this one is DOM to source.
> 

Last time I send the file got bug, here is the updated version of
DOMPrettyPrinter


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


Re: Enhancement for OutputManager (SVGTranscoder)

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

> > If I am not wrong interpreting your suggestion, then
> > PrettyPrinter/OutputManager need to be rewritten in order to preserve
> > the DOM document in order to check namespace,etc. I think something like
> > DOMUtilities.writeNode() with PrettyPrinter formating rule. What is your
> > idea? any suggestion?
> 
>      Yah, I guess that is what my suggestion would boil down to.
> Looking at the code I really have to wonder a bit at why it wasn't
> written that way to start with (it has it's own XML Parser 'lite'
> built in).  One thing is that with a normal XML Parser you lose
> all information about spaces between the attributes of an element,
> it may be that they want to preserve this from the source document.

I would like to submit the DOM to source file transcoder with Pretty
Printer formating rule.  This time no cvs diff -u because it is
completely new file. See the attachment. Almost all the code is copy and paste from DOMUtilitis and svg2svg transcoder with modification.

I put it under the package org.apache.batik.transcoder.dom, because I
think it is different from org.apache.batik.transcoder.svg2svg (Source
to Source) and this one is DOM to source.

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

Re: Enhancement for OutputManager (SVGTranscoder)

Posted by Thomas DeWeese <Th...@Kodak.com>.
Tonny Kohar wrote:
> hi,
> 
> 
>>>I would like to submit enhancement for OutputManager. 
>>>This patch will format the attrib to have new line on the specified
>>>documentWidth and indent the newline according to getTabulationWidth
>>>useful for example to format very long path element d attribute.
>>
>>    There is a problem here.  You can't just add newlines to all
>>attributes.  For example if you add a newline in the
>>middle of preserveAspectRatio='xMidYMid split' the result is an
>>invalid SVG.
>>
>>    The only solution to this is for the OutputManager to have a
>>list of attributes (namespace qualified) for particular elements
>>(or elements in a particular namespace).
> 
> 
> After look at PrettyPrinter and OutputManager more deeply, there is no
> way to get node/attrib information as in DOM, because the way it works
> is in SVGTranscoder the DOM document is written into text string then
> the result string is passed into PrettyPrinter/OutputManager (DOM
> information is lost here).
> 
> If I am not wrong interpreting your suggestion, then
> PrettyPrinter/OutputManager need to be rewritten in order to preserve
> the DOM document in order to check namespace,etc. I think something like
> DOMUtilities.writeNode() with PrettyPrinter formating rule. What is your
> idea? any suggestion?

Hi Tonny,

     Yah, I guess that is what my suggestion would boil down to.
Looking at the code I really have to wonder a bit at why it wasn't
written that way to start with (it has it's own XML Parser 'lite'
built in).  One thing is that with a normal XML Parser you lose
all information about spaces between the attributes of an element,
it may be that they want to preserve this from the source document.


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


Re: Enhancement for OutputManager (SVGTranscoder)

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

> > I would like to submit enhancement for OutputManager. 
> > This patch will format the attrib to have new line on the specified
> > documentWidth and indent the newline according to getTabulationWidth
> > useful for example to format very long path element d attribute.
> 
>     There is a problem here.  You can't just add newlines to all
> attributes.  For example if you add a newline in the
> middle of preserveAspectRatio='xMidYMid split' the result is an
> invalid SVG.
> 
>     The only solution to this is for the OutputManager to have a
> list of attributes (namespace qualified) for particular elements
> (or elements in a particular namespace).

After look at PrettyPrinter and OutputManager more deeply, there is no
way to get node/attrib information as in DOM, because the way it works
is in SVGTranscoder the DOM document is written into text string then
the result string is passed into PrettyPrinter/OutputManager (DOM
information is lost here).

If I am not wrong interpreting your suggestion, then
PrettyPrinter/OutputManager need to be rewritten in order to preserve
the DOM document in order to check namespace,etc. I think something like
DOMUtilities.writeNode() with PrettyPrinter formating rule. What is your
idea? any suggestion?

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


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


Re: Enhancement for OutputManager (SVGTranscoder)

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

Tonny Kohar wrote:

> I would like to submit enhancement for OutputManager. 
> This patch will format the attrib to have new line on the specified
> documentWidth and indent the newline according to getTabulationWidth
> useful for example to format very long path element d attribute.

    There is a problem here.  You can't just add newlines to all
attributes.  For example if you add a newline in the
middle of preserveAspectRatio='xMidYMid split' the result is an
invalid SVG.

    The only solution to this is for the OutputManager to have a
list of attributes (namespace qualified) for particular elements
(or elements in a particular namespace).

> I attached the cvs diff -u format in this message and here is the
> bug(not a bug just enhancement) id # 26651
> 
> btw, there is no Transcoder group on the bugzilla under batik. So I just
> put in under utilities group. 

     This is fine.  I'll attach the above commentary to the bug
report.

> 
> 
> Regards
> Tonny Kohar
> http://www.kiyut.com
> 
> 
> ------------------------------------------------------------------------
> 
> ? this.diff
> Index: OutputManager.java
> ===================================================================
> RCS file: /home/cvspublic/xml-batik/sources/org/apache/batik/transcoder/svg2svg/OutputManager.java,v
> retrieving revision 1.7
> diff -u -r1.7 OutputManager.java
> --- OutputManager.java	8 Aug 2003 11:39:26 -0000	1.7
> +++ OutputManager.java	4 Feb 2004 07:35:07 -0000
> @@ -468,25 +468,11 @@
>          }
>          printCharacter('<');
>          printCharacters(name);
> +        printCharacter(' ');
>  
>          if (prettyPrinter.getFormat()) {
>              Iterator it = attributes.iterator();
> -            if (it.hasNext()) {
> -                AttributeInfo ai = (AttributeInfo)it.next();
> -
> -                if (ai.isAttribute("xml:space")) {
> -                    xmlSpace.set(0, (ai.value.equals("preserve")
> -                                     ? Boolean.TRUE
> -                                     : Boolean.FALSE));
> -                }
> -                
> -                printCharacter(' ');
> -                printCharacters(ai.name);
> -                printCharacter('=');
> -                printCharacter(ai.delimiter);
> -                printString(ai.value);
> -                printCharacter(ai.delimiter);
> -            }
> +            
>              while (it.hasNext()) {
>                  AttributeInfo ai = (AttributeInfo)it.next();
>  
> @@ -496,22 +482,27 @@
>                                       : Boolean.FALSE));
>                  }
>                  
> -                int len = ai.name.length + ai.value.length() + 4;
> -                if (lineAttributes ||
> -                    len + column > prettyPrinter.getDocumentWidth()) {
> -                    printNewline();
> -                    printString(margin.toString());
> -                    for (int i = 0; i < name.length + 2; i++) {
> -                        printCharacter(' ');
> +                // patch format the attrib to have new line on the specified documentWidth
> +                // and indent the newline according to getTabulationWidth
> +                // useful for example to format very long path element d attribute
> +                // The line break is calculated using StringTokenizer which is using word boundary
> +                // as a token
> +                StringBuffer sb = new StringBuffer();
> +                sb.append(ai.name);
> +                sb.append('=');
> +                sb.append(ai.delimiter + ai.value + ai.delimiter);
> +                java.util.StringTokenizer st = new java.util.StringTokenizer(sb.toString());
> +                while (st.hasMoreTokens()) {
> +                    String str = st.nextToken();
> +                    if (str.length() + column > prettyPrinter.getDocumentWidth()) {
> +                        printNewline();
> +                        printString(margin.toString());
> +                        for(int i=0; i<prettyPrinter.getTabulationWidth(); i++) {
> +                            printCharacter(' ');
> +                        }
>                      }
> -                } else {
> -                    printCharacter(' ');
> +                    printString(str + ' ');
>                  }
> -                printCharacters(ai.name);
> -                printCharacter('=');
> -                printCharacter(ai.delimiter);
> -                printString(ai.value);
> -                printCharacter(ai.delimiter);
>              }
>          } else {
>              Iterator it = attributes.iterator();
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> 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