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 Sudhakar S <ye...@hotmail.com> on 2006/07/05 11:30:03 UTC

Mismatch in Scale value

Hi All,

I am trying to export Zoomed In SVGDocument to JPEG file. But after exported
as JPEG, it doesn?t have same size, which is in SVGCanvas. I am setting
KEY_WIDTH and KEY_HEIGHT transcoding hint values calculated using following
code. 

GraphicsNode gNode = getGraphicsNode();
Rectangle2D viewRect = (Rectangle2D)gNode.getBounds().clone();
AffineTransform vCoordi = getViewBoxTransform();
final Rectangle docSize = vCoordi.createTransformedShape(new Rectangle(0, 0,          
(int)viewRect.getWidth(), (int)viewRect.getHeight())).getBounds();
.
.
.
JPEGTranscoder t = new JPEGTranscoder();
t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1));
t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new
Float((float)docSize.getWidth()));
t.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT, new
Float((float)docSize.getHeight()));

In SVGAbstractTranscoder, while calculating the scale value using following
code, it doesn?t return the same scale value of 
?getSVGDocument().getRootElement().getCurrentScale()?.

float xscale, yscale;
xscale = width/docWidth;
yscale = height/docHeight;
float scale = Math.min(xscale,yscale);

Since there is some difference is scale value, it doesn?t export scaled JPEG
file with exact size. Can anyone please explain how to export JPEG file with
exact zoom in size?

Thanks,
Sudhakar
-- 
View this message in context: http://www.nabble.com/Mismatch-in-Scale-value-tf1893554.html#a5178516
Sent from the Batik - Users forum at Nabble.com.


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


Re: Mismatch in Scale value

Posted by Sudhakar S <ye...@hotmail.com>.
Hi Thomas,

> As I think I mentioned earlier you can modify
> JSVGComponent.calculateViewingTransform (perhaps to > always return the
> identity transform).  

I have changed calculateViewingTransform with identity transform like
following code.

 protected AffineTransform calculateViewingTransform
        (String fragIdent, SVGSVGElement svgElt) {
        return new AffineTransform();
    }

Thanks thomas, after changed to identity transform, its working fine.

Thanks,
Sudhakar

-- 
View this message in context: http://www.nabble.com/Mismatch-in-Scale-value-tf1893554.html#a5287566
Sent from the Batik - Users forum at Nabble.com.


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


Re: Mismatch in Scale value

Posted by th...@kodak.com.
Hi Sudhakar,

Sudhakar S <ye...@hotmail.com> wrote on 07/07/2006 07:07:45 AM:

> Actually i didnt use viewBox attribute in my application. Because if use
> viewBox attribute, SVGCanvas is not showing the exact size of the 
document.
> Total SVG document is zoomed out to smaller size. 

   It is true that an SVG implementation must fit the viewBox to the
available Width/Height.

> But if i use other editors(Internet Explorer) to open exported SVG 
> file. Size is perfect. So could you please explain how to show exact 
> SVG Document with viewBox attribute.

   As I think I mentioned earlier you can modify 
JSVGComponent.calculateViewingTransform (perhaps to always return
the identity transform).  I'm guessing that they don't limit width/height
in any way so the viewBox is generally mapped 1:1 to screen.  Batik
limits width/height to screen size.

> I have used the following code to get zoomed in/zoomed out size of the
> Document. But still i couldn't able to get the exact size. So can you 
please
> give some more information to get proper width and height?

   The code below looks mostly right to me (see comment below). 
So without any more information on how things are failing (how 
far are they off, how you are determining what is right vs 
wrong, etc) I can't help.

> SVGSVGElement el = _document.getRootElement();
>            String viewBoxStr = el.getAttributeNS(null,
> SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);
>            float[] r = ViewBox.parseViewBoxAttribute(el, viewBoxStr);
>            GraphicsNode gn = getGraphicsNode();
>            CanvasGraphicsNode cgn = getCanvasGraphicsNode(gn);
>            if (cgn != null) {
>                AffineTransform vTx = cgn.getViewingTransform();

                        This should probably be canvas.
getViewBoxTransform()

>                final Rectangle docSize = vTx.createTransformedShape(new
> Rectangle((int)r[0], (int)r[1], (int)r[2], (int)r[3])).getBounds();
>                System.out.println("Doc Size::" + docSize);
>            }


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


Re: Mismatch in Scale value

Posted by Sudhakar S <ye...@hotmail.com>.
Hi Thomas,

> This is not necessarily the same as the viewBox rect.  This 
> is the actual bounds of the geometry which can be larger or 
> smaller than the rectangle specified by the viewBox attribute. 

Actually i didnt use viewBox attribute in my application. Because if use
viewBox attribute, SVGCanvas is not showing the exact size of the document.
Total SVG document is zoomed out to smaller size. But if i use other
editors(Internet Explorer) to open exported SVG file. Size is perfect. So
could you please explain how to show exact SVG Document with viewBox
attribute.

<svg contentScriptType="text/ecmascript" width="1019"
     xmlns:xlink="http://www.w3.org/1999/xlink" zoomAndPan="magnify"
     style="cursor:url(#selCursor),crosshair" contentStyleType="text/css"
     height="663" viewBox="0 0 1019 663" preserveAspectRatio="none"
     xmlns="http://www.w3.org/2000/svg" version="1.0">


> The batik.bridge.ViewBox class has a bunch of useful methods for 
> dealing with the viewBox (in particular parseViewBoxAttribute). 

> I would transform the real viewBox with the viewingTransform, 
> this should give you the proper width/height. 

I have used the following code to get zoomed in/zoomed out size of the
Document. But still i couldn't able to get the exact size. So can you please
give some more information to get proper width and height?

SVGSVGElement el = _document.getRootElement();
           String viewBoxStr = el.getAttributeNS(null,
SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);
           float[] r = ViewBox.parseViewBoxAttribute(el, viewBoxStr);
           GraphicsNode gn = getGraphicsNode();
           CanvasGraphicsNode cgn = getCanvasGraphicsNode(gn);
           if (cgn != null) {
               AffineTransform vTx = cgn.getViewingTransform();
               final Rectangle docSize = vTx.createTransformedShape(new
Rectangle((int)r[0], (int)r[1], (int)r[2], (int)r[3])).getBounds();
               System.out.println("Doc Size::" + docSize);
           }


Thanks,
Sudhakar



-- 
View this message in context: http://www.nabble.com/Mismatch-in-Scale-value-tf1893554.html#a5215414
Sent from the Batik - Users forum at Nabble.com.


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


Re: Mismatch in Scale value

Posted by th...@kodak.com.
Hi Sudhakar,

Sudhakar S <ye...@hotmail.com> wrote on 07/05/2006 05:30:03 AM:

> I am trying to export Zoomed In SVGDocument to JPEG file. But after 
exported
> as JPEG, it doesn?t have same size, which is in SVGCanvas. I am setting
> KEY_WIDTH and KEY_HEIGHT transcoding hint values calculated using 
following
> code. 
> 
> GraphicsNode gNode = getGraphicsNode();
> Rectangle2D viewRect = (Rectangle2D)gNode.getBounds().clone();

   This is not necessarily the same as the viewBox rect.  This
is the actual bounds of the geometry which can be larger or
smaller than the rectangle specified by the viewBox attribute.

   The batik.bridge.ViewBox class has a bunch of useful methods for
dealing with the viewBox (in particular parseViewBoxAttribute).

> AffineTransform vCoordi = getViewBoxTransform();

   The viewBoxTransform includes the transform due to viewBox
(the Viewing Transform) along with the transform due to user
pan/zoom (the Rendering Transform).

> In SVGAbstractTranscoder, while calculating the scale value using 
following
> code, it doesn?t return the same scale value of 
> ?getSVGDocument().getRootElement().getCurrentScale()?.

   The value returned by 'getCurrentScale' only considers the 
transform due to user pan/zoom (the rendering transform)
it does not include the viewing transform.

> float xscale, yscale;
> xscale = width/docWidth;
> yscale = height/docHeight;
> float scale = Math.min(xscale,yscale);
> 
> Since there is some difference is scale value, it doesn?t export scaled 
JPEG
> file with exact size. Can anyone please explain how to export JPEG file 
with
> exact zoom in size?

    I would transform the real viewBox with the viewingTransform,
this should give you the proper width/height.


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