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 Christopher Foley <cc...@gmail.com> on 2010/08/09 15:29:45 UTC
SVG generated file not opening correctly in Browser
Hi,
I have created a graph with JFreeChart and used Batik to convert it to
svg format, sample code below;
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
Document document = domImpl.createDocument(null, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
chart.draw(svgGenerator, bounds);
// Write svg file
OutputStream outputStream = new FileOutputStream(svgFile);
Writer out = new OutputStreamWriter(outputStream, "UTF-8");
svgGenerator.stream(out, true /* use css */);
outputStream.flush();
outputStream.close();
So it creates the svg file no problem, but when I open the file with a
browser it doesn't open correctly(have tried
both Firefox and Opera, just done 'File,Open'). I have attached a
snapshot of how the file is displayed in Firefox,
the chart is squashed(exact same in Opera). But when I open it in
InkScape(SVG graphics editor) it opens perfectly.
I have tried editing the SVG doc(setting height, width, viewbox tags)
but with no success. I am new to the graphics
area so apologies if this is a simple problem!
Any info appreciated.
Thanks,
Chris.
Re: Re: SVG generated file not opening correctly in Browser
Posted by cc...@gmail.com.
Hi Helder,
Apologies with using the term 'squashed', I wasn't sure what term to use to
describe
it(lack of graphics knowledge!). But your fix worked and as you say it is a
text/formatting
alignment issue.
Thanks again,
Chris.
On Aug 12, 2010 9:20pm, Helder Magalhães <he...@gmail.com> wrote:
> Hi Chris,
> > [...] but when I open the file with a
> > browser it doesn't open correctly(have tried
> > both Firefox and Opera, just done 'File,Open'). I have attached a
> > snapshot of how the file is displayed in Firefox,
> > the chart is squashed(exact same in Opera). But when I open it in
> > InkScape(SVG graphics editor) it opens perfectly.
> I'm not sure what you mean with "squashed". Can you elaborate a bit
> [1]? Also, you have attached a screenshot of how it displays
> unexpectedly but not a screenshot of how you expected it to be. In the
> absence of the resulting SVG file, this triggers the "guys, guess
> what's happening!" mode. ;-)
> Nevertheless, my quick "guess" is that no particular "squashing" is
> happening: I can only see text overflowing other graphics content. If
> so, then you are simply suffering from a common issue with graphics in
> general which is text formatting/alignment. Note that if you don't
> specify font and font-size property, the implementation will use a
> fallback font family/font size which will then vary and may yield such
> unexpected results. As a quick fix attempt, set a default font
> behavior by setting the "font-family" (remember to include a generic
> font family [2]) and "font-size" attributes in the root "svg" element,
> as in:
> [remaining graphics]
> > Any info appreciated.
> Hope this helps,
> Helder
> [1] http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
> [2] http://www.w3.org/TR/CSS2/fonts.html#generic-font-families
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: SVG generated file not opening correctly in Browser
Posted by Helder Magalhães <he...@gmail.com>.
Hi Chris,
> [...] but when I open the file with a
> browser it doesn't open correctly(have tried
> both Firefox and Opera, just done 'File,Open'). I have attached a
> snapshot of how the file is displayed in Firefox,
> the chart is squashed(exact same in Opera). But when I open it in
> InkScape(SVG graphics editor) it opens perfectly.
I'm not sure what you mean with "squashed". Can you elaborate a bit
[1]? Also, you have attached a screenshot of how it displays
unexpectedly but not a screenshot of how you expected it to be. In the
absence of the resulting SVG file, this triggers the "guys, guess
what's happening!" mode. ;-)
Nevertheless, my quick "guess" is that no particular "squashing" is
happening: I can only see text overflowing other graphics content. If
so, then you are simply suffering from a common issue with graphics in
general which is text formatting/alignment. Note that if you don't
specify font and font-size property, the implementation will use a
fallback font family/font size which will then vary and may yield such
unexpected results. As a quick fix attempt, set a default font
behavior by setting the "font-family" (remember to include a generic
font family [2]) and "font-size" attributes in the root "svg" element,
as in:
<svg [...] font-family="Helvetica, Arial, Tahoma, sans-serif" font-size="11">
[remaining graphics]
</svg>
> Any info appreciated.
Hope this helps,
Helder
[1] http://www.chiark.greenend.org.uk/~sgtatham/bugs.html
[2] http://www.w3.org/TR/CSS2/fonts.html#generic-font-families
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org