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 "BlackBeetle@foxmail.com" <Bl...@foxmail.com> on 2008/09/12 10:13:43 UTC

Batik

hi~
i'm first use the Batik.

It's java code from apache-batik.

package acom;
import java.awt.Rectangle;
import java.awt.Graphics2D;
import java.awt.Color;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.IOException;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.dom.GenericDOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.DOMImplementation;
public class TestSVGGen {
    public void paint(Graphics2D g2d) {
        g2d.setPaint(Color.red);
        g2d.fill(new Rectangle(10, 10, 100, 100));
        g2d.setPaint(Color.black);
        g2d.fill(new Rectangle(10, 10, 80, 10));
    }
    public static void main(String[] args) throws IOException {
      
        // Get a DOMImplementation.
        DOMImplementation domImpl =
            GenericDOMImplementation.getDOMImplementation();
        // Create an instance of org.w3c.dom.Document.
        String svgNS = "http://www.w3.org/2000/svg";
        Document document = domImpl.createDocument(svgNS, "svg", null);
        // Create an instance of the SVG Generator.
        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
        // Ask the test to render into the SVG Graphics2D implementation.
        TestSVGGen test = new TestSVGGen();
        test.paint(svgGenerator);
        // Finally, stream out SVG to the standard output using
        // UTF-8 encoding.
        boolean useCSS = true; // we want to use CSS style attributes
        Writer out = new OutputStreamWriter(System.out, "UTF-8");
        svgGenerator.stream(out, useCSS);
    }
}


the svg file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg xmlns:xlink="http://www.w3.org/1999/xlink" style="fill-opacity:1; color-rendering:auto; color-interpolation:auto; stroke:black; text-rendering:auto; stroke-linecap:square; stroke-miterlimit:10; stroke-opacity:1; shape-rendering:auto; fill:black; stroke-dasharray:none; font-weight:normal; stroke-width:1; font-family:&apos;Dialog&apos;; font-style:normal; stroke-linejoin:miter; font-size:12; stroke-dashoffset:0; image-rendering:auto;" xmlns="http://www.w3.org/2000/svg"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
  /><g
  ><g style="fill:red; stroke:red;"
    ><rect x="10" width="100" height="100" y="10" style="stroke:none;"
      /><rect x="10" y="10" width="80" style="fill:black; stroke:none;" height="10"
    /></g
  ></g
></svg
>

The svg file can not be shrinked on FireFox3.0.
why?




2008-09-12

Re: Batik

Posted by Helder Magalhães <he...@gmail.com>.
> The svg file can not be shrinked on FireFox3.0.
> why?

Note that Firefox has its own forum [1] for posting SVG-related
questions, where I'd suggest redirecting this thread if there are more
Firefox-specific comments.

The SVG zoom and pan functionality is not as inter-operable as one
might expect. Different implementations have different behavior (key
combinations used, slightly different context menu terminology, etc.)
and some implementations (such Firefox) don't implement it at all
(take a look at the "Zoom, Pan, and Resize" section of [2] for
additional background information). Nevertheless, Firefox has a couple
[2] [3] of plug-ins which aim to provide such functionality, although
they are a bit buggy and somehow outdated.

If you meant "shrink" by adjusting the window size instead of zooming
out, than it may be due to not specifying canvas dimensions
("width"/"height") and/or the "viewbox" attribute [4].


> boolean useCSS = true; // we want to use CSS style attributes

Just a side note: I'd generally suggest using XML attributes instead
of CSS for styling SVG. Although they seem to be equivalent, there are
good reasons [5] for that.


Hope this helps,

 Helder Magalhães

[1] http://groups.google.com/group/mozilla.dev.tech.svg/
[2] http://schepers.cc/grafox/
[3] http://www.treebuilder.de/zoomAndPan/index.htm
[4] http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
[5] http://jwatt.org/svg/authoring/#the-style-attribute

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


Re: Batik

Posted by Gentle Yang <ya...@genomics.org.cn>.
Hi, your svg flile has no problem both by my firefox3 on linux(centos)
and firefox3 on windows 2003 ;

Abd I find no error but some style warnings ; and also I can zoom in or
out on the svg !

So maybe u could check your mouse ? :-)






BlackBeetle@foxmail.com 写道:
> hi~
> i'm first use the Batik.
> It's java code from apache-batik.
> packageacom;
> importjava.awt.Rectangle;
> importjava.awt.Graphics2D;
> importjava.awt.Color;
> importjava.io.Writer;
> importjava.io.OutputStreamWriter;
> importjava.io.IOException;
> importorg.apache.batik.svggen.SVGGraphics2D;
> importorg.apache.batik.dom.GenericDOMImplementation;
> importorg.w3c.dom.Document;
> importorg.w3c.dom.DOMImplementation;
> publicclassTestSVGGen{
> publicvoidpaint(Graphics2Dg2d){
> g2d.setPaint(Color.red);
> g2d.fill(newRectangle(10,10,100,100));
> g2d.setPaint(Color.black);
> g2d.fill(newRectangle(10,10,80,10));
> }
> publicstaticvoidmain(String[]args)throwsIOException{
> //GetaDOMImplementation.
> DOMImplementationdomImpl=
> GenericDOMImplementation.getDOMImplementation();
> //Createaninstanceoforg.w3c.dom.Document.
> StringsvgNS="http://www.w3.org/2000/svg";
> Documentdocument=domImpl.createDocument(svgNS,"svg",null);
> //CreateaninstanceoftheSVGGenerator.
> SVGGraphics2DsvgGenerator=newSVGGraphics2D(document);
> //AskthetesttorenderintotheSVGGraphics2Dimplementation.
> TestSVGGentest=newTestSVGGen();
> test.paint(svgGenerator);
> //Finally,streamoutSVGtothestandardoutputusing
> //UTF-8encoding.
> booleanuseCSS=true;//wewanttouseCSSstyleattributes
> Writerout=newOutputStreamWriter(System.out,"UTF-8");
> svgGenerator.stream(out,useCSS);
> }
> }
> the svg file
> <?xmlversion="1.0"encoding="UTF-8"?>
> <!DOCTYPEsvgPUBLIC'-//W3C//DTDSVG1.0//EN'
> 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
> <svgxmlns:xlink="http://www.w3.org/1999/xlink"style="fill-opacity:1;color-rendering:auto;color-interpolation:auto;stroke:black;text-rendering:auto;stroke-linecap:square;stroke-miterlimit:10;stroke-opacity:1;shape-rendering:auto;fill:black;stroke-dasharray:none;font-weight:normal;stroke-width:1;font-family:&apos;Dialog&apos;;font-style:normal;stroke-linejoin:miter;font-size:12;stroke-dashoffset:0;image-rendering:auto;"xmlns="http://www.w3.org/2000/svg"
> ><!--GeneratedbytheBatikGraphics2DSVGGenerator--><defsid="genericDefs"
> /><g
> ><gstyle="fill:red;stroke:red;"
> ><rectx="10"width="100"height="100"y="10"style="stroke:none;"
> /><rectx="10"y="10"width="80"style="fill:black;stroke:none;"height="10"
> /></g
> ></g
> ></svg
> >
> The svg file can not be *shrinked *on FireFox3.0.
> why?
> ------------------------------------------------------------------------
> 2008-09-12