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 Ernst Müller <er...@gmx.net> on 2006/12/02 20:15:55 UTC
Problem with JSVGCanvas and setRenderingTransform
Hi
I'm new to batik and tried to do use the JSVGCanvas with an SVGGraphics2D object - that basically worked - but than I tried to scale it via an Affine Transformation ... that fails sometimes. It only fails when the area that I paint on with SVGGraphics is bigger than the JSVGCanvas size, but it does not always fail ... sometimes I just run it again it works ...
I am running a Linux (Gentoo) with a 1.5.0_09-b03 Java Version, developing in Eclipse 3.2 and using Batik 1.6.
Here is the sourcecode I use:
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame frame = new JFrame("test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
JSVGCanvas canvas = new JSVGCanvas();
frame.getContentPane().add(canvas);
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
// Get a DOMImplementation
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
Document document = domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator
SVGGraphics2D g = new SVGGraphics2D(document);
//some stupid drawings for testing
g.setColor(Color.green);
g.fillRect(0, 0, 1501, 1501);
g.setColor(Color.black);
g.drawRect(10, 10, 100, 100);
g.setColor(java.awt.Color.red);
g.fillArc(20, 20, 50, 50, 0, 359);
Element root = document.getDocumentElement();
g.getRoot(root);
canvas.setDocument(document);
frame.setVisible(true);
canvas.setRenderingTransform(AffineTransform.getScaleInstance(0.1, 0.1), true);
}
Since I am new ... did I use the batik api wrong or is there somewhere a bug?
cu & thx
ernii
--
"Ein Herz für Kinder" - Ihre Spende hilft! Aktion: www.deutschlandsegelt.de
Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's Cup-Yacht!
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Problem with JSVGCanvas and setRenderingTransform
Posted by th...@kodak.com.
Hi Ernst,
"Ernst Müller" <er...@gmx.net> wrote on 12/02/2006 02:15:55 PM:
> I'm new to batik and tried to do use the JSVGCanvas with an
SVGGraphics2D
> object - that basically worked - but than I tried to scale it via an
Affine
> Transformation ... that fails sometimes. It only fails when the area
that I
> paint on with SVGGraphics is bigger than the JSVGCanvas size, but it
does not
> always fail ... sometimes I just run it again it works ...
The is because setDocument is asynchronous, since it can take
a long time for large documents. Once the document is loaded the
canvas uses 'setRenderingTransform' to set the initial view,
if this happens before your call then your call 'wins', if
this happens after your call then your call 'loses'.
Typically, you want to hold off manipulating the canvas until
after the document is fully rendered. This can be detected by
registering a gvtRenderingTreeListener.
> I am running a Linux (Gentoo) with a 1.5.0_09-b03 Java Version,
developing in
> Eclipse 3.2 and using Batik 1.6.
>
> Here is the sourcecode I use:
>
> public static void main(String[] args) {
> // TODO Auto-generated method stub
> JFrame frame = new JFrame("test");
> frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> frame.setSize(500, 500);
> JSVGCanvas canvas = new JSVGCanvas();
> frame.getContentPane().add(canvas);
> String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> // Get a DOMImplementation
> DOMImplementation domImpl =
> GenericDOMImplementation.getDOMImplementation();
>
> // Create an instance of org.w3c.dom.Document
> Document document = domImpl.createDocument(svgNS, "svg", null);
>
> // Create an instance of the SVG Generator
> SVGGraphics2D g = new SVGGraphics2D(document);
> //some stupid drawings for testing
> g.setColor(Color.green);
> g.fillRect(0, 0, 1501, 1501);
> g.setColor(Color.black);
> g.drawRect(10, 10, 100, 100);
> g.setColor(java.awt.Color.red);
> g.fillArc(20, 20, 50, 50, 0, 359);
>
> Element root = document.getDocumentElement();
> g.getRoot(root);
>
> canvas.setDocument(document);
>
> frame.setVisible(true);
>
> canvas.setRenderingTransform(AffineTransform.getScaleInstance(0.1, 0.1),
true);
> }
>
> Since I am new ... did I use the batik api wrong or is there somewhere a
bug?
>
> cu & thx
> ernii
> --
> "Ein Herz für Kinder" - Ihre Spende hilft! Aktion:
www.deutschlandsegelt.de
> Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's
Cup-Yacht!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org