Hello,
I create SVG by way of java2D, and then stream it out (a) to a file
(java.io.PrintWriter), or (b) to an HTTP stream
(java.io.OutputStreamWriter). When I embed the SVG output file in a JSP, my
firefox browser gets the font-sizes right (a mix of 10, 12, and 18), just
like I specify in the java2D. But when I stream the SVG output bytes into
the same browser, all the font-sizes are displayed the same (font-size 12)
... which happens to be the default that is specified, for both versions, in
the SVG 'svg' element.
Why are the font-sizes that are specified in the SVG definitions ignored in
the page generated by the byte array stream, but not in the page with the
embedded file, and how do I get them enforced in the byte array stream page?
One difference I see, is that the OutputStreamWriter version always uses
UTF-8:
<?xml version="1.0" encoding="UTF-8"?>
... whether I request that or not:
Writer svgout = new OutputStreamWriter( outstream );
Writer svgout = new OutputStreamWriter( outstream, "UTF-8" );
... so I guess -somebody- is setting the the default character encoding to
UTF-8.
The PrintWriter version claims no encoding:
<?xml version="1.0"?>
And so font-size specification for the OutputStreamWriter:
style="font-size:10;
... differs somewhat from that of the PrintWriter:
font-size="10"
Is this the problem? If so, how do I get no character encoding in the byte
stream ?? And is that an otherwise OK idea?
Thanks!!
-Paul
PS:
This doesn't work:
java.nio.charset.Charset cset = null;
ByteArrayOutputStream outstream = new ByteArrayOutputStream( 4 * 8192 );
Writer svgout = new OutputStreamWriter( outstream, cset );
java.lang.NullPointerException: charset
at java.io.OutputStreamWriter.<init>(OutputStreamWriter.java:114)
PPS:
file & stream versions
DOMImplementation dom = SVGDOMImplementation.getDOMImplementation();
SVGDocument doc = (SVGDocument) dom.createDocument(null, "svg", null);
SVGGraphics2D svggen = new SVGGraphics2D(doc);
file version only
FileWriter file = new FileWriter("filename");
PrintWriter out = new PrintWriter(file);
svggen.stream(out);
out.flush();
out.close();
-----
<embed width="1000" height="800" src="filename" type="image/svg+xml"
/>
stream version only
ByteArrayOutputStream outstream = new ByteArrayOutputStream( 4 * 8192 );
Writer svgout = new OutputStreamWriter( outstream, "UTF-8" );
svggen.stream( svgout, true );
svgout.flush();
svgout.close();
-----
public class SVGStreamServlet extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String contentType = (String)req.getAttribute("contentType");
if (contentType == null || "".equals(contentType))
{
contentType = "image/svg+xml"; // default
}
res.reset();
res.setContentType(contentType);
OutputStream sos = res.getOutputStream();
HttpSession session = req.getSession();
ByteArrayOutputStream baos =
(ByteArrayOutputStream)session.getAttribute("baos");
baos.writeTo(sos);
}
}
PPPS:
- batik-1.7
- Linux 2.6.17-1.2174_FC5 (Fedora Core 5)
- tomcat5-5.5.15-1jpp_6fc
- jdk1.5.0_08
- Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.6)
Gecko/20060808 Fedora/1.5.0.6-2.fc5 Firefox/1.5.0.6 pango-text
--
View this message in context:
http://www.nabble.com/font-size-ignored-for-SVG-stream-to-OutputStreamWriter%2C-but-not-to-PrintWriter-tf3836971.html#a10863884
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]