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 Mike Favata <mj...@benderson.com> on 2004/04/06 18:15:58 UTC

JSVGCanvas resizing document on initial load

Hello all,

I am having a small problem when my JSVGCanvas first loads a document.  When the document is first loaded it is scaled down and only takes up a small portion of the canvas.  When I move the mouse over the canvas the document scales to best fit the size of the canvas.  What am I doing wrong?  I would like the document to best fit the canvas on first load without having to wait for the user to move the mouse over the canvas.  Has anyone ran into this problem before?  Any help would be appreciated.  Thanks!

-Mike Favata

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


Re: Dynamic modification of the DOM

Posted by Cameron McCormack <ca...@aka.mcc.id.au>.
Archie Cobbs:
> Hmm.. guess I'm confused. So can you explain sections A.2 and A.3 of:
> 
>   http://www.w3.org/TR/REC-xml-names/#sets-no-good

(I hadn't read xml-names in detail before.)

> I interpreted them to mean that unqualified attribute names are
> scoped only to the corresponding element tag (i.e., they're "private"
> to the namespace assoicated with that particular element tag).

Yes, it seems that unprefixed attributes that are designated as part of
the "per-element-type partition" have some sort of association with the
element's expanded name, at least for the purpose of determining
attribute identity.  That's not to say that they are in the namespace of
the element on which they appear, though.  They are still in the empty
namespace, as section 5.2 says that namespace defaulting only happens to
elements, not attributes.

Do other W3C recommendations specify which attributes belong to the two
partitions?  I don't see any text in SVG about it.  I guess it's a small
semantic point that doesn't need worrying about most of the time.

> Which would imply (?) that you can add an attribute with no namespace
> prefix and it should do the right thing.

Yeah, I've always thought that setAttribute(x, y) should be equivalent
to setAttributeNS(null, x, y) in namespace-aware DOMs, but it's not
always the case.

Cameron

-- 
Cameron McCormack
|  Web: http://mcc.id.au/
|  ICQ: 26955922

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


Re: Dynamic modification of the DOM

Posted by Archie Cobbs <ar...@dellroad.org>.
Cameron McCormack wrote:
> > I believe unqualified attributes automatically inherit the namespace
> > of the associated tag.
> 
> No they don't, they are in the empty namespace.  Why the XML people
> decided that attributes don't respect the default namespace is anyone's
> guess.

Hmm.. guess I'm confused. So can you explain sections A.2 and A.3 of:

  http://www.w3.org/TR/REC-xml-names/#sets-no-good

I interpreted them to mean that unqualified attribute names are
scoped only to the corresponding element tag (i.e., they're "private"
to the namespace assoicated with that particular element tag).

Which would imply (?) that you can add an attribute with no namespace
prefix and it should do the right thing.

Thanks,
-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

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


Re: Dynamic modification of the DOM

Posted by Cameron McCormack <ca...@aka.mcc.id.au>.
Archie Cobbs:
> I believe unqualified attributes automatically inherit the namespace
> of the associated tag.

No they don't, they are in the empty namespace.  Why the XML people
decided that attributes don't respect the default namespace is anyone's
guess.

-- 
Cameron McCormack
|  Web: http://mcc.id.au/
|  ICQ: 26955922

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


Re: Dynamic modification of the DOM

Posted by Archie Cobbs <ar...@dellroad.org>.
Jeremy E. Denton wrote:
> That worked. Namespaces are a pain. Do you know why are there namespaces for
> the elements but not the attributes?

I believe unqualified attributes automatically inherit the namespace
of the associated tag.

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

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


RE: Dynamic modification of the DOM

Posted by "Jeremy E. Denton" <jd...@galdosinc.com>.
Thanks Tonny,

That worked. Namespaces are a pain. Do you know why are there namespaces for
the elements but not the attributes?

Cheers,
Jeremy

> -----Original Message-----
> From: Tonny Kohar [mailto:tonny@kiyut.com]
> Sent: Tuesday, 6 April 2004 8:41 PM
> To: batik-users@xml.apache.org
> Subject: Re: Dynamic modification of the DOM
>
>
> Hi,
>
> > 		if (svgDoc != null) {
> > 			if (dirty) {
> > 				Element rect = svgDoc.createElement("rect");
>
> I think above line should be svgDoc.createElementNS(svgNS,"rect");
>
> > 				rect.setAttribute("x", "100");
> > 				rect.setAttribute("y", "100");
> > 				rect.setAttribute("width", "400");
> > 				rect.setAttribute("height", "400");
> > 				rect.setAttribute("fill", "blue");
>
> Same here setAttributeNS(null,"x","100");
> so on
>
> Regards
> Tonny Kohar
> --
> Sketsa
> SVG Graphics Editor
> http://www.kiyut.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>


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


Re: Dynamic modification of the DOM

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

> 		if (svgDoc != null) {
> 			if (dirty) {
> 				Element rect = svgDoc.createElement("rect");

I think above line should be svgDoc.createElementNS(svgNS,"rect");

> 				rect.setAttribute("x", "100");
> 				rect.setAttribute("y", "100");
> 				rect.setAttribute("width", "400");
> 				rect.setAttribute("height", "400");
> 				rect.setAttribute("fill", "blue");

Same here setAttributeNS(null,"x","100");
so on

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com



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


Dynamic modification of the DOM

Posted by "Jeremy E. Denton" <jd...@galdosinc.com>.

Hey all,

I would like to be able to modify the DOM live and propogating the change to
the DOM to the rendered image. I've been experimenting but I've not had any
success. The following is a method that I call when the rendering is done.
The call is made to the "drawRect" and I reset the SVGDocument back to the
canvas. (admittedly this is a brute force method). but it doesn't appear to
actually render anything. Though I do note that the "drawRect" is being
called twice so it does go through the rendering process twice.

I would prefer to modify the DOM directly than use the modified Graphics2D
calls. It gives me better control and better access to the SVG model.

	boolean dirty = true;

	private void drawRect() {

		System.out.println("Draw Rect");

		SVGDocument svgDoc = svgCanvas.getSVGDocument();
		if (svgDoc != null) {
			if (dirty) {
				Element rect = svgDoc.createElement("rect");
				rect.setAttribute("x", "100");
				rect.setAttribute("y", "100");
				rect.setAttribute("width", "400");
				rect.setAttribute("height", "400");
				rect.setAttribute("fill", "blue");

				System.out.println(SVGPicture.xmlToString(svgDoc));
				svgDoc.getRootElement().appendChild(rect);
				svgCanvas.setSVGDocument(svgDoc);

				label.setText("Updating");
				dirty = false;
			}
			label.setText("Draw Rect Done.");

		} else {
			System.out.println("Document Root is null");
		}
	}

Any suggestions?

Cheers,
Jeremy


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


Re: JSVGCanvas resizing document on initial load

Posted by Andres Toussaint <an...@onemileup.com>.
Hi Mike:

That happened to me also, and it turned out that my original SVG file 
was the source of the error. You have to specify the viewport with the 
exact same dimensions as the width height attributes in your SVG 
declaration:

<svg width="1000" height ="500" viewport="0 0 1000 500" ..... >
...
</svg>

Or another solution you could use, in case you have no control over the 
original SVG (i.e. a user is providing it to your app), you can try 
adding a Load listener and set the canvas dimensions from the SVG file:

....
// Set the JSVGCanvas listeners.
         svgCanvas.addSVGDocumentLoaderListener(new 
SVGDocumentLoaderAdapter() {
             public void documentLoadingStarted(SVGDocumentLoaderEvent 
e) {
             }

             public void documentLoadingCompleted(SVGDocumentLoaderEvent 
e) {

                 SVGDocument document = e.getSVGDocument();
                 SVGOMSVGElement  documentElement = 
(SVGOMSVGElement)document.getDocumentElement();

	      //Get the dimensions from the SVG document
                 String theW = documentElement.getAttribute("width");
                 String theH = documentElement.getAttribute("height");

                 Integer WW = new Integer(theW);
                 Integer HH = new Integer(theH);

	      //this is actually where we indicate the JSVGCanvas to modify 
its viewport size
                 svgCanvas.setMySize(new Dimension(WW.intValue(), 
HH.intValue()));
             }
         });

protected JSVGCanvas svgCanvas;


This might work for you. It does for me.
Best regards,

Andres.

On Tuesday, April 6, 2004, at 10:15 AM, Mike Favata wrote:

> Hello all,
>
> I am having a small problem when my JSVGCanvas first loads a document. 
>  When the document is first loaded it is scaled down and only takes up 
> a small portion of the canvas.  When I move the mouse over the canvas 
> the document scales to best fit the size of the canvas.  What am I 
> doing wrong?  I would like the document to best fit the canvas on 
> first load without having to wait for the user to move the mouse over 
> the canvas.  Has anyone ran into this problem before?  Any help would 
> be appreciated.  Thanks!
>
> -Mike Favata
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
>
>



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