xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mistercaste <misterca...@gmail.com>
Subject Re: SVG Symbol Bbox
Date Mon, 22 Feb 2010 11:19:49 GMT

I have solved this trivially using the SVG attributes.
The fields x and y can't be null, so I can always take
them to locate an element. Here is my code:


    private void antiTransformSymbols() {
        final Element symbolsGroup =
canvas.getSVGDocument().getElementById(ID_SYMBOLS_GROUP);

        LinkedList list = new LinkedList();
        recurseLeaves((Node) symbolsGroup, list);// Takes all the leaves of
the symbols group

        while (!list.isEmpty()) {// For every symbol..
            final Node node = (Node) lista.remove();

            // Scale factor
            final double scale = (1 /
canvas.getSVGDocument().getRootElement().getCurrentScale()) *
ANTI_ZOOM_MULTIPLIER_SYMBOLS;

            /*
             * Gets the current element coordinates.
             * The fields x and y can't be null because of SVG definition.
             */
            final float cx = Float.valueOf(((Element)
node).getAttribute("x"));
            final float cy = Float.valueOf(((Element)
node).getAttribute("y"));
            
            canvas.getUpdateManager().getUpdateRunnableQueue().
                    invokeLater(new Runnable() {

                @Override
                public void run() {
                    /*
                     * DOM actions
                     * Translation -> Scale -> Translation because the
element
                     * must be scaled on the center of the reference system.
                     */
                    ((Element) node).setAttributeNS(
                            null,
                            SVG_TRANSFORM_ATTRIBUTE,
                            "translate(" + (cx) + "," + (cy) + ")" +
                            "scale(" + scale + ") " +
                            "translate(" + (-cx) + "," + (-cy) + ")");
                }
            });

        }
    }




Thanks for support.


-- 
View this message in context: http://old.nabble.com/SVG-Symbol-Bbox-tp27622473p27685811.html
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Mime
View raw message