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 r d <ba...@hotmail.com> on 2002/01/16 21:59:14 UTC

Crimson parser does not recognize "xlink:href"

Hello Batik team,

I thought I would send you this e-mail that came from Yahoo mailing list:

I think there maybe problem that this gentle person has found......or he 
does not understand xmlnamespaces.......it up to you to decide....I helped 
get his program to run....but you might want to look into it..

http://groups.yahoo.com/group/svg-developers/message/10789

Support for xlink:href in SVG

To Robert A. DiBlasi : Thank you for your response. I did it!

But there are several points that are important to share:

Case 1
------
If you have a SVG file in this format (with a DocType):

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000303 Stylable//EN"
"http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd">
<svg contentScriptType="text/ecmascript" width="100" zoomAndPan="magnify"
contentStyleType="text/css" height="35"
xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid
meet" xmlns="http://www.w3.org/2000/svg" version="1.0">
<defs>
<font-face font-family="SVGDavid">
<font-face-src>
<font-face-uri xlink:href="SVGFonts/SVGDavid.svg#SVGDavid"></font-face-uri>
</font-face-src>
</font-face>
</defs>
<g
style="fill:black;text-anchor:middle;font-size:14;font-weight:300;font-family:SV\
GDavid"
id="TextLayout">
<text x="50" y="22">ABCDE</text>
</g>
</svg>

And you use this program to render a PNG (adapted from the Image Transcoder
Tutorial of Batik):

public class SaveAsPNG
{
public static void main(String [] args) throws Exception
{

// create a PNG transcoder
PNGTranscoder t = new PNGTranscoder();
//t.addTranscodingHint(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE,new
Boolean(true));
// set the transcoding hints
// create the transcoder input
String svgURI = new File(args[0]).toURL().toString();
TranscoderInput input = new TranscoderInput(svgURI);
// create the transcoder output
OutputStream ostream = new FileOutputStream(args[1]);
TranscoderOutput output = new TranscoderOutput(ostream);
// save the image
t.transcode(input, output);
// flush and close the stream then exit
ostream.flush();
ostream.close();
System.exit(0);
}
}

It will work.

Case 2
------
If you have a SVG file in this format (with no DocType, but with
xmlns:xlink="http://www.w3.org/1999/xlink" in the svg tag):

<?xml version="1.0"?>
<svg contentScriptType="text/ecmascript" width="100" zoomAndPan="magnify"
contentStyleType="text/css" height="35"
xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid
meet" xmlns="http://www.w3.org/2000/svg" version="1.0">
<defs>
<font-face font-family="SVGDavid">
<font-face-src>
<font-face-uri xlink:href="SVGFonts/SVGDavid.svg#SVGDavid"></font-face-uri>
</font-face-src>
</font-face>
</defs>
<rect width="100" x="0" height="35" y="0" style="fill:#eeeeee"></rect>
<g style="fill:#cccccc" id="TagBody">
<rect width="100" x="0" height="25" y="10"></rect>
<rect width="70" x="20" height="35" y="0"></rect>
<circle r="40" cx="26" cy="40"></circle>
<circle r="10" cx="90" cy="10"></circle>
</g>
<g
style="fill:black;text-anchor:middle;font-size:14;font-weight:300;font-family:SV\
GDavid"
id="TextLayout">
<text x="50" y="22">ABCDE</text>
</g>
</svg>

And you use the same program to render a PNG, it will work also.

Case 3
------
Step 1
-------
The main problems are when you create a SVG document with the
SVGDOMImplementation.
I have tried to create a document with a DocType (like in case 1), but I
could not do it.
I have looked into the code, and it seems that this option does not exist.

Step 2
------
I have created a SVG document using this program (adapted from the Image
Transcoder Tutorial of Batik):

public class DOMRasterizer {

public Document createDocument()
{
DOMImplementation impl =
SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
Document document =
impl.createDocument(svgNS, "svg", null);
Element root = document.getDocumentElement();
root.setAttributeNS(null, "width", "450");
root.setAttributeNS(null, "height", "500");

//************************************************************
//HERE I ADD THE SUPPORT FOR NAMESPACES
root.setAttributeNS(null, "xmlns:xlink", "http://www.w3.org/1999/xlink");
//**************************************************************

Element e;
e = document.createElementNS(svgNS, "rect");
e.setAttributeNS(null, "x", "10");
e.setAttributeNS(null, "y", "10");
e.setAttributeNS(null, "width", "200");
e.setAttributeNS(null, "height", "300");
e.setAttributeNS(null, "style",
"fill:red;stroke:black;stroke-width:4");
root.appendChild(e);

return document;
}

public void save(Document document) throws Exception
{
PNGTranscoder t = new PNGTranscoder();
TranscoderInput input = new TranscoderInput(document);
OutputStream ostream = new FileOutputStream("out.jpg");
TranscoderOutput output = new TranscoderOutput(ostream);
t.transcode(input, output);
ostream.flush();
ostream.close();
}

public static void main(String [] args) throws Exception {
DOMRasterizer rasterizer = new DOMRasterizer();
Document document = rasterizer.createDocument();
rasterizer.save(document);
System.exit(0);
}
}

And this does not work, I recieve an Exception:

Exception in thread "main" java.lang.NullPointerException
at java.util.Hashtable.get(Hashtable.java:320)
at java.net.URL.getURLStreamHandler(URL.java:884)
at java.net.URL.<init>(URL.java:305)
at java.net.URL.<init>(URL.java:224)
at java.net.URL.<init>(URL.java:243)
at org.apache.batik.util.ParsedURLData.buildURL(Unknown Source)
at org.apache.batik.util.ParsedURLData.openStreamInternal(Unknown
Source
)
at org.apache.batik.util.ParsedURLData.openStream(Unknown Source)
at org.apache.batik.util.ParsedURL.openStream(Unknown Source)
at
org.apache.batik.dom.svg.SAXSVGDocumentFactory.createDocument(Unknown
Source)
at org.apache.batik.bridge.DocumentLoader.loadDocument(Unknown
Source)
at org.apache.batik.bridge.URIResolver.getNode(Unknown Source)
at org.apache.batik.bridge.URIResolver.getElement(Unknown Source)
at
org.apache.batik.bridge.BridgeContext.getReferencedElement(Unknown So
urce)
at org.apache.batik.bridge.SVGFontUtilities.getFontFamily(Unknown
Source
)
at
org.apache.batik.bridge.SVGTextElementBridge.getAttributeMap(Unknown
Source)
at
org.apache.batik.bridge.SVGTextElementBridge.buildAttributedStrings(U
nknown Source)
at
org.apache.batik.bridge.SVGTextElementBridge.buildAttributedString(Un
known Source)
at
org.apache.batik.bridge.SVGTextElementBridge.buildGraphicsNode(Unknow
n Source)
at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown
Source)
at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(Unknown
Source)
at org.apache.batik.bridge.GVTBuilder.buildComposite(Unknown Source)
at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
at
org.apache.batik.transcoder.image.ImageTranscoder.transcode(Unknown S
ource)
at
org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(Unknown S
ource)
at nowSVG.TabGenerator1.save(TabGenerator1.java:141)
at nowSVG.TabGenerator1.main(TabGenerator1.java:152)


Step 3
------
The only solution was:
1.Serialize the Document done as a SVG file (without the DocType, because it
is impossible to add
it, but with the xmlns:xlink= "http://www.w3.org/1999/xlink").

2.Change the method save in DOMRasterizer to:

public void save(String aFileName) throws Exception
{
PNGTranscoder t = new PNGTranscoder();
String svgURI = new File(aFileName).toURL().toString();
TranscoderInput input = new TranscoderInput(svgURI);
// create the transcoder output
OutputStream ostream = new FileOutputStream("out.png");
TranscoderOutput output = new TranscoderOutput(ostream);
// save the image
t.transcode(input, output);
// flush and close the stream then exit
ostream.flush();
ostream.close();
System.exit(0);
}

This worked fine.
Still it is not clear why I recieved an Exception in the original version of
DOMRasterizer

Philip

Long message sorry but may be importaint.....any hints
here is the orginal message:

http://groups.yahoo.com/group/svg-developers/message/10781

We all learn by sharing what we know
Robert A.DiBlasi
http://www.svgnotebook.com




_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


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