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 Joanie Abalone <pf...@earthlink.net> on 2007/05/30 00:20:03 UTC

font-size ignored for SVG stream to OutputStreamWriter, but not to PrintWriter

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:

  &LT;?xml version="1.0" encoding="UTF-8"?&GT;

... 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:

  &LT;?xml version="1.0"?&GT;

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();
-----
&LT;embed width="1000" height="800" src="filename" type="image/svg+xml"
/&GT;

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: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: font-size ignored for SVG stream to OutputStreamWriter, but not to PrintWriter

Posted by Joanie Abalone <pf...@earthlink.net>.
Hello Thomas!

Finally got a chance to try that ... and it works!

Thanks so much!



Hi Joanie,

I'm not sure about all the stuff you mentioned, but regarding the CSS 
style font size specification (style="font-size:10;") Firefox requires 
you to specify a unit (i.e. style="font-size:10px;"). The reason for 
this is that SVG CSS styles actually violate the CSS spec (CSS always 
requires units for length attributes). My advice to you would be to use 
a customized version of org.apache.batik.svggen.SVGCSSStyler that 
appends "px" to all font-size attribute lengths (at least that's what I do).

Regards, Thomas



-- 
View this message in context: http://www.nabble.com/font-size-ignored-for-SVG-stream-to-OutputStreamWriter%2C-but-not-to-PrintWriter-tf3836971.html#a11001511
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: font-size ignored for SVG stream to OutputStreamWriter, but not to PrintWriter

Posted by Thomas Behr <th...@yworks.com>.
Hi Joanie,

I'm not sure about all the stuff you mentioned, but regarding the CSS 
style font size specification (style="font-size:10;") Firefox requires 
you to specify a unit (i.e. style="font-size:10px;"). The reason for 
this is that SVG CSS styles actually violate the CSS spec (CSS always 
requires units for length attributes). My advice to you would be to use 
a customized version of org.apache.batik.svggen.SVGCSSStyler that 
appends "px" to all font-size attribute lengths (at least that's what I do).

Regards, Thomas


Joanie Abalone wrote:
> 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:
> 
>   &LT;?xml version="1.0" encoding="UTF-8"?&GT;
> 
> ... 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:
> 
>   &LT;?xml version="1.0"?&GT;
> 
> 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();
> -----
> &LT;embed width="1000" height="800" src="filename" type="image/svg+xml"
> /&GT;
> 
> 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
> 
> 
> 
> 

-- 
Thomas Behr
yWorks GmbH
Vor dem Kreuzberg 28
72070 Tuebingen, Germany
Tel.:  +49 7071 9709050
Fax.:  +49 7071 9709051


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