xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From BlueInGreeen <blue_in_gr...@fastwebnet.it>
Subject Re: Need help to fit svg images into fixed diemension JSVGCanvas?
Date Sun, 21 Aug 2005 19:09:32 GMT
Again: thanks to Thomas and also thanks to Dominik (the german guy! ^_^)

I solved my problem in this way:

  public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
                 label.setText("Document Loaded.");

                 SVGDocument d = svgCanvas.getSVGDocument();

                 SVGElement el = d.getRootElement();



         String width = el.getAttributeNS(null,  
SVGConstants.SVG_WIDTH_ATTRIBUTE);
         String height = el.getAttributeNS(null,  
SVGConstants.SVG_HEIGHT_ATTRIBUTE);
         if (width.endsWith("pt"))        //Convertion from pt to px  
(in case pt metric is adopted in the svg file)
             {
             int length = width.length();
             width = width.substring(0, length-2);
             Double dbw = new Double(width);
             double doubleWidth = dbw.doubleValue()*1.333333;
             dbw = new Double(doubleWidth);
             width = dbw.toString();

         }

         if (height.endsWith("pt"))
             {
             int length = height.length();
             height = height.substring(0, length-2);
             Double dbh = new Double(height);
             double doubleHeight = dbh.doubleValue()*1.333333;
             dbh = new Double(doubleHeight);
             height = dbh.toString();
         }

         String widthAndHeight = "0 0 "+width+" "+height;
         el.setAttribute("viewBox", widthAndHeight);

             }
         });


I didn't use UpdateManager beacause this gaves me some problems with  
the InvokeLater method.
I also discovered that my crash problems are related to a bug of the  
JDK 1.5 of Mac Os X Tiger.
It's a problem with the file-choosers.
Let me know if in my solution there's something wrong.
Thank you!!!

Mime
View raw message