You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by jeffupt <je...@gmail.com> on 2007/07/24 23:53:13 UTC

Is Batik right for me?

My current project requires that I am able to retrieve data from an SVG file. 
I need to be able to calculate the bounding box containing all objects that
aren't in a group called "background", and I need to be able to retrieve a
list of unique colors from the image. In addition to retrieiving unique
colors, I need to be able to replace all instances of a color in the image
with a different color. Are these 'features' easily available in the API? If
so, can anyone point me in the right direction ?
-- 
View this message in context: http://www.nabble.com/Is-Batik-right-for-me--tf4138851.html#a11772590
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: Is Batik right for me?

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

On Tue, 2007-07-24 at 14:53 -0700, jeffupt wrote:
> My current project requires that I am able to retrieve data from an SVG file. 
> I need to be able to calculate the bounding box containing all objects that
> aren't in a group called "background", and I need to be able to retrieve a
> list of unique colors from the image. In addition to retrieiving unique
> colors, I need to be able to replace all instances of a color in the image
> with a different color. Are these 'features' easily available in the API? If
> so, can anyone point me in the right direction ?

Batik is SVG DOM API implementation, so you access everything through
standard SVG DOM interface. Some task is easy and some task is hard but
it is SVG DOM. However, if you are interested you could go down to GVT
API layer, it is more complicated and have its own api design.

Basicly Batik is structure is like this

User/Screen
    |
    |
SVG DOM API <---- this is mostly people interact with Batik
    |
    |
GVT API  <---- this is the Java Vector Graphics Implementation, hardcore
stuff

please check the Batik website on how Batik project structured

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


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


RE: Is Batik right for me?

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
For #1, you have to boot the DOM and CSS:

http://wiki.apache.org/xmlgraphics-batik/BootSvgAndCssDom

Michael Bishop 

-----Original Message-----
From: jeffupt [mailto:jeffupt@gmail.com] 
Sent: Thursday, July 26, 2007 12:19 PM
To: batik-users@xmlgraphics.apache.org
Subject: Re: Is Batik right for me?


Thank you for your very helpful response. I have a few clarification
questions after digging around the API documentation and writing some
test code.

1) SVGPathElement.getBBox() always returns null for me - and I can't
find the class documentation in the API Javadoc. I seem to recall
reading that some SVG functions won't return proper values until
rendering has taken place - is this true?

Here's the code that I'm running:
 SAXSVGDocumentFactory docFactory = new SAXSVGDocumentFactory(
XMLResourceDescriptor.getXMLParserClassName() );
        SVGDocument document = docFactory.createSVGDocument( new File(
"C:\\test.svg" ).toURI().toString() );
        
        
        NodeList nodeList = document.getElementsByTagName( "path" );
        for( int i = 0; i < nodeList.getLength(); ++i ) {
            SVGPathElement pathElement = (SVGPathElement)nodeList.item(
i );
            
            SVGRect bbox = pathElement.getBBox();
            
            if ( bbox != null )
                System.out.println( bbox.getX() );
            else
                System.out.println( "null bbox" );
        }

2) As for colors, the SVG documents are exported from Illustrator,
therefore I don't really have any control over the contents.  I assume
I'll have to walk the XML tree and read in all fill and stroke
attributes? This doesn't seem to be too difficult.

Thanks again for your time.

--
View this message in context:
http://www.nabble.com/Is-Batik-right-for-me--tf4138851.html#a11813899
Sent from the Batik - Users mailing list archive at Nabble.com.


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

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


Re: Is Batik right for me?

Posted by jeffupt <je...@gmail.com>.
Thank you for your very helpful response. I have a few clarification
questions after digging around the API documentation and writing some test
code.

1) SVGPathElement.getBBox() always returns null for me - and I can't find
the class documentation in the API Javadoc. I seem to recall reading that
some SVG functions won't return proper values until rendering has taken
place - is this true?

Here's the code that I'm running:
 SAXSVGDocumentFactory docFactory = new SAXSVGDocumentFactory(
XMLResourceDescriptor.getXMLParserClassName() );
        SVGDocument document = docFactory.createSVGDocument( new File(
"C:\\test.svg" ).toURI().toString() );
        
        
        NodeList nodeList = document.getElementsByTagName( "path" );
        for( int i = 0; i < nodeList.getLength(); ++i ) {
            SVGPathElement pathElement = (SVGPathElement)nodeList.item( i );
            
            SVGRect bbox = pathElement.getBBox();
            
            if ( bbox != null )
                System.out.println( bbox.getX() );
            else
                System.out.println( "null bbox" );
        }

2) As for colors, the SVG documents are exported from Illustrator, therefore
I don't really have any control over the contents.  I assume I'll have to
walk the XML tree and read in all fill and stroke attributes? This doesn't
seem to be too difficult.

Thanks again for your time.

-- 
View this message in context: http://www.nabble.com/Is-Batik-right-for-me--tf4138851.html#a11813899
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: Is Batik right for me?

Posted by th...@kodak.com.
Hi Jeff,

jeffupt <je...@gmail.com> wrote on 07/24/2007 05:53:13 PM:

> My current project requires that I am able to retrieve data from an SVG 
file. 
> I need to be able to calculate the bounding box containing all objects 
that
> aren't in a group called "background",

   This is fairly simple if you use the 'getBBox' call on all the 
element's
outside of the background group.  You may have to combine those yourself
depending on the structure of your document but it's fairly simple.

> and I need to be able to retrieve a list of unique colors from the 
image. 
> In addition to retrieiving unique colors, I need to be able to replace 
> all instances of a color in the image with a different color. 

   If you can control the structure of your document so that the unique
colors are defined using 'solidColor' (a feature of SVG 1.2 that Batik
supports).  Then getting the list and manipulating it becomes quite
simple (getElementsByTagNameNS will find them all for you, and then
'setAttribute' will let you change the color).

   If however you have to support more or less 'arbitrary' SVG
then you will need to poke through all the fill/stroke attributes
in the document.  This is a bit more work but if you use something
like XPath it could make your life easier (although the code to
traverse the document and find the fill/stroke values is
a pretty simple recursive tree walk).

> Are these 'features' easily available in the API? If
> so, can anyone point me in the right direction ?

   They are fairly accessible especially if you have some
control over the document.  Compared to starting from
scratch Batik will be an inconceivably big step up
(getting the bounding boxes right - especially for text 
but also for geometry given transforms, stroking etc
would be a huge amount of work).


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