create a JSVGCanvas from an inputstream

2009-12-30 Thread dao
hello, I am stucked in the process of creating a JSVGCanvas from a SVG XML
content coming from an input stream.

What is the best practice?

Here is the way I do that:

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

String xmlDocument = remoteEngine.getSvgDocument();

System.out.println(xmlDocument);

InputStream inStream = new ByteArrayInputStream(xmlDocument.getBytes());

return builder.parse(inStream);


I get into a ClassCastEexception when batik tries to narrow the document to
a SVG document (I suppose so...)

-- 
Dao Hodac


Re: create a JSVGCanvas from an inputstream

2009-12-30 Thread jonathan wood
Hi Dao,

Here are a couple of load routines I use frequently ..  Hope they help you
narrow your problem.

Load from a file on the classpath (templated)

InputStream templateStream =
Canvas.class.getResourceAsStream(template.svg);
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
SVGDocument doc = null;

try {
doc = f.createSVGDocument(null, templateStream);
} catch (IOException ex) {
}

   myCanvas.setSVGDocument(doc);


Load from a byte array version:

Element a = null;
ByteArrayInputStream bais = new
ByteArrayInputStream(myByteArray);
String parser =
XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);

try {
a = f.createDocument(null, bais).getDocumentElement();
} catch (IOException ex) {
}

a = (Element) document.importNode(a, true);




On Wed, Dec 30, 2009 at 12:47 PM, dao dao.ho...@gmail.com wrote:

 hello, I am stucked in the process of creating a JSVGCanvas from a SVG XML
 content coming from an input stream.

 What is the best practice?

 Here is the way I do that:

  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

 DocumentBuilder builder = factory.newDocumentBuilder();

 String xmlDocument = remoteEngine.getSvgDocument();

 System.out.println(xmlDocument);

 InputStream inStream = new ByteArrayInputStream(xmlDocument.getBytes());

 return builder.parse(inStream);


 I get into a ClassCastEexception when batik tries to narrow the document to
 a SVG document (I suppose so...)

 --
 Dao Hodac



Re: create a JSVGCanvas from an inputstream

2009-12-30 Thread dao
Thank you, it works fine! I will keep those routine somewhere

On Wed, Dec 30, 2009 at 7:16 PM, jonathan wood
jonathanshaww...@gmail.comwrote:

 Hi Dao,

 Here are a couple of load routines I use frequently ..  Hope they help you
 narrow your problem.

 Load from a file on the classpath (templated)

 InputStream templateStream =
 Canvas.class.getResourceAsStream(template.svg);
 String parser = XMLResourceDescriptor.getXMLParserClassName();
 SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
 SVGDocument doc = null;

 try {
 doc = f.createSVGDocument(null, templateStream);
 } catch (IOException ex) {
 }

myCanvas.setSVGDocument(doc);


 Load from a byte array version:

 Element a = null;
 ByteArrayInputStream bais = new
 ByteArrayInputStream(myByteArray);
 String parser =
 XMLResourceDescriptor.getXMLParserClassName();
 SAXSVGDocumentFactory f = new
 SAXSVGDocumentFactory(parser);

 try {
 a = f.createDocument(null, bais).getDocumentElement();
 } catch (IOException ex) {
 }

 a = (Element) document.importNode(a, true);





 On Wed, Dec 30, 2009 at 12:47 PM, dao dao.ho...@gmail.com wrote:

 hello, I am stucked in the process of creating a JSVGCanvas from a SVG XML
 content coming from an input stream.

 What is the best practice?

 Here is the way I do that:

  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

 DocumentBuilder builder = factory.newDocumentBuilder();

 String xmlDocument = remoteEngine.getSvgDocument();

 System.out.println(xmlDocument);

 InputStream inStream = new ByteArrayInputStream(xmlDocument.getBytes());

 return builder.parse(inStream);


 I get into a ClassCastEexception when batik tries to narrow the document
 to a SVG document (I suppose so...)

 --
 Dao Hodac





-- 
Dao Hodac


Re: create a JSVGCanvas from an inputstream

2009-12-30 Thread Helder Magalhães
Hi everyone,


Response inline...


(jonathan wood)
 Here are a couple of load routines I use frequently ..  Hope they help you
 narrow your problem.

(dao)
 Thank you, it works fine! I will keep those routine somewhere

In the wiki [1], perhaps...? ;-)

The how-to section [2] seemed appropriate, but for shorter, useful
code snippets, a dedicated page (UsefulSnippets?) would also be
great! :-)

BTW: if one decides to go with it, including a taken from
[link_to_mailing_list_thread here] would be great so that one can
crawl for background information if is curious enough.


Cheers,
 Helder


[1] http://wiki.apache.org/xmlgraphics-batik/
[2] http://wiki.apache.org/xmlgraphics-batik/HowTo

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



Re: background for text

2009-12-30 Thread Helder Magalhães
Hi Dao,


Response inline...


 interesting, I never think filter oriented... but if I want to highlight a
 filled shape, the yellow never appears, isn't it?

FWIW, I never saw a way to highlight shapes which works well in all
situations. For example, popular ways to highlight objects are:
 1. Use a particular stroke/fill color. How will you highlight a shape
which by coincidence is in that particular color?
 2. Revert colors (a.k.a. XOR mode). How will you highlight a shape
which is mid-tone gray?
 3. Use the shape's bounding box. If the shape is very large and you
are zooming in, for example, you won't have a clue that the shape is
selected. Also, this is not quite a highlight...

I'd advise you to take a look at existing vector graphics editors,
such as Inkscape (which seems to use approach 3) and Sketsa (which
seems to use approach 1; as a matter of curiosity, it's based in
Batik), in order to figure out general approaches to the problem.
Also, Batik Squiggle also has a shape highlighting feature (which
seems to use approach 2): checkout Tools/DOM Viewer.../Click to
enable highlight of selected node. Note that the shape highlight
doesn't seem to be working well with complex SVG files, but you may
use a very simple SVG [1] just to have a feeling: I've just reported
bug 48468 to track it down... ;-)


Hope this helps,
 Helder


[1] 
http://heldermagalhaes.com/stuff/svg/demos/SVGObject-HTMLCanvasInteractors/sample.svg
[2] https://issues.apache.org/bugzilla/show_bug.cgi?id=48468

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



Re: Welcome to Helder Magalhães as a committer

2009-12-30 Thread G. Wade Johnson
On Wed, 30 Dec 2009 12:35:46 +1100
Cameron McCormack c...@mcc.id.au wrote:

 Hello all,
 
 I’d just like to congratulate Helder Magalhães on being voted in as a
 committer for the Apache Batik project!  Helder has been doing great
 work recently answering questions on the mailing list and keeping
 newly filed bugs from going unanswered.

Way to go, Helder.

G. Wade
-- 
Sufficiently encapsulated magic is technology.-- Michael Schwern

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



Re: A repainting issue

2009-12-30 Thread thomas . deweese
Hi Cameron,

Cameron McCormack c...@mcc.id.au wrote on 12/29/2009 10:07:07 PM:

 In the Swing thread, I?m getting the GraphicsNode of one of the elements
 in my document and painting it on a different component.  (It?s a
 thumbnail view of the diagram.)  I think this painting is happening at
 the same time as updating/painting is happening on the JSVGCanvas.

   Yes, this could easily be your problem.

 So my question now becomes: when is it safe for me to grab the GVT node
 and paint it somewhere?  In an UpdateManager Runnable?

The only threading mechanism currently employed in Batik is the
RunnableQueue.  I've considered adding a mutex to the root GVT node
that the UpdateManager would grab before running runnables.

 Otherwise, I guess I will have to paint it to a buffer 
 and then paint that buffer to my thumbnail component in the Swing EDT.

   Yes, I think this is the best route to go.