Hi Mike,

   You aren't setting the viewBox to the right value.
You want to set the viewBox to the box that will "cover"
your content (often although not always the bounding box
of the outermost SVG element).  Also the width/height/viewBox
_attributes_ are in the 'null' (or no) namespace (_elements_
are in the SVG namespace).

   Probably the easiest thing to do would be to subclass the
canvas and override it's calculateViewingTransform call to
be based on the bbox of the root SVG element and the size of
the JSVGComponent.  This would avoid modifying the SVG Document.

Caron, Michael R wrote:

I'm not getting the same results with this code:
// Set the JSVGCanvas listeners.
svgOrig.addSVGDocumentLoaderListener(new
SVGDocumentLoaderAdapter() {
public void documentLoadingStarted(SVGDocumentLoaderEvent e)
{
status.setText("Document Loading...");
System.out.println("Document Loading...");
}
public void documentLoadingCompleted(SVGDocumentLoaderEvent
e) {
svgOrigDocument = e.getSVGDocument();
// here is setting the document height and width
String svgNS = "http://www.w3.org/2000/svg";;
SVGOMSVGElement documentElement = (SVGOMSVGElement)
svgOrigDocument.getDocumentElement();
documentElement.setAttributeNS(svgNS, "viewBox", "0 0 "+ ICON_WIDTH +" "+ ICON_HEIGHT); documentElement.setAttributeNS(svgNS, "width", ""+ICON_WIDTH);
documentElement.setAttributeNS(svgNS, "height", ""+ICON_HEIGHT);
//debug only so I can see results
DOMBuilder b = new DOMBuilder();
Document d = b.build(svgOrigDocument);
XMLOutputter writer = new XMLOutputter();
try {
writer.output(d, new FileOutputStream(new
File("src/xml/out.xml")));
} catch ( IOException x ) {
x.printStackTrace();
} // end debug
status.setText("Document Loaded.");
System.out.println("Document Loaded.");
}
});


An interesting thing is that in the outputted XML document, I get the
following for the root element:
<svg xmlns="http://www.w3.org/2000/svg"; xmlns:xlink="http://www.w3.org/1999/xlink"; contentScriptType="text/ecmascript" zoomAndPan="magnify" width="450"


contentStyleType="text/css" version="1.0" preserveAspectRatio="xMidYMid meet" viewBox="0 0 60 60" height="60">

Notice that the WIDTH was never changed. (why? Is that because of this
preserverAspectRatio thing?)

Back to the drawing board. I think that I will attempt to load the
document before the GUI stuff, then
I'll make the transform, then calculate the size of the canvas that I'll
need and stick in the image. Will that work?


I'm not too familiar with the 2D graphics API and these Affine Transform
deals. I don't know what a ViewBox is and I'm guessing that I'll have to
just start reading about SVG... Yuck. APIs are supposed to take away
these frustrations:

   int HEIGHT = 40;
   int WIDTH = 60;
   JSVGCanvas canvas =
batik.lite.Renderer.openImg("C:/Tmp/MyImage",HEIGHT,WIDTH);
   // bam!
   JFrame f = new Jpanel();
   f.add(canvas);
   f.show();
   // bam!


Dreamy. Mike

________________________________

From: Andres Toussaint [mailto:[EMAIL PROTECTED] Sent: Tuesday, January 25, 2005 8:06 AM
To: Batik Users
Subject: Re: Opening an SVG image to a certain scale



I would suggest the following:


//... svgCanvas.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() { public void documentLoadingStarted(SVGDocumentLoaderEvent e) { //.... }

public void documentLoadingCompleted(SVGDocumentLoaderEvent e) { SVGDocument document = e.getSVGDocument(); SVGOMSVGElement documentElement =
(SVGOMSVGElement)document.getDocumentElement(); String theW = "yourWidthHere"; String theH = "yourHeightHere";


documentElement.setAttributeNS(svgNS, "viewBox", "0 0 "+ theW +" "+
theH); documentElement.setAttributeNS(svgNS, "width", theW ); documentElement.setAttributeNS(svgNS, "height", theH ); } }); //...


I use this on Dynamic JSVGCanvas, and have not tried it on Static
Canvas.


Andres.

On Jan 24, 2005, at 3:38 PM, Caron, Michael R wrote:


Each tile is a separate JSVGCanvas, not loading them as <image>
elements. Output is a JPanel: //... private void init() { addListeners(); setLayout(new BorderLayout()); // status is a JLabel status.setFont(new
Font(PANEL_FONT_NAME,PANEL_FONT_STYLE, PANEL_FONT_SIZE)); status.setText("svg"); status.setHorizontalAlignment(SwingConstants.CENTER); // stick the SVG into an etched pane to make it look
nice JPanel borderedPanel = new JPanel(new
FlowLayout(FlowLayout.CENTER, 0,0));
borderedPanel.setBorder(BorderFactory.createEtchedBorder()); // svgThumbnail is a JSVGCanvas svgThumbnail.setPreferredSize(new Dimension(ICON_HEIGHT,
ICON_WIDTH)); borderedPanel.add(svgThumbnail); // add the SVG add(borderedPanel, BorderLayout.CENTER); // add the status line add(status, BorderLayout.SOUTH); } //... Mike



From: Andres Toussaint [mailto:[EMAIL PROTECTED] Sent: Monday, January 24, 2005 2:34 PM To: Batik Users Subject: Re: Opening an SVG image to a certain scale


Is each of your SVG tiles a separate JSVGCanvas?


Or are you loading your SVG Tiles as <image> elements?



What is your output? A Java Swing window, a raster image, a web
page?





On Jan 24, 2005, at 2:55 PM, Caron, Michael R wrote:



Hi all,



I'd like to open an SVG file to certain dimensions. Essentially,
create a thumbnail, but forget about the original sizes. I've tried to
go with the code example from the Squiggle app, but I can't seem to get
any output. I've looked at the transcoding option, but that doesn't do
what I want. What I want is to load up a bunch of svgs into a grid of
svg tiles no bigger than 40px x 40px. I figured I could do a transform
after the GVTTree was built, but that just gave me some null pointers.



Any ideas?



L

Michael Caron Software Development IR&D - PCES Program


x4889




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to