xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Palfray <thomas.palf...@gmail.com>
Subject Define String Width with bounding box
Date Wed, 29 Oct 2008 14:59:07 GMT
Hi all,

I'm trying to find the width of a String, but i've a little problem.
in fact, i use getBBox() to find it, and it works ... but not in one case.

I have two test String :

"blabla bla"
"blabla bla "
getBBox() gives me the same length for the two String. It seems that it 
doesn't take the last blankspace.

Here is my method :
    private int getSVGStringWidth(String string, int fontSize){
        Element retourLigne = (Element)docCalcul.createElementNS(svgNS, 
"text");
        retourLigne.setAttributeNS(null,"x", "0");
        retourLigne.setAttributeNS(null,"y", "0");
        retourLigne.setAttributeNS(null,"font-family", "Verdana");
        
retourLigne.setAttributeNS(null,"font-size",String.valueOf(fontSize));
        Text tmpText = docCalcul.createTextNode(string);
        retourLigne.appendChild(tmpText);
        docCalcul.getDocumentElement().appendChild(retourLigne);
        int retour = (int)((SVGLocatable)retourLigne).getBBox().getWidth();
        docCalcul.getDocumentElement().removeChild(retourLigne);

        return retour;           
    }
.
If someone have some advice, it could help me :)
Cheers,
Thomas

---------------------------------------------------------------------
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