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 ananth balasubramanyam <ab...@cs.odu.edu> on 2004/06/03 20:13:32 UTC

little help

Hi all,

I am replacing the text of a text element with a new text string and
am trying to shift the text element, either to the left or the right based
on the the difference in old and new widths(so as to maintain the
center alignment). Here is a sample code. I dont
seem to be visually getting the desired results. Could somebody please
help me with this. Am i doing something wrong ?

SVGOMTextElement textElement ......
..................................
oldWidth = textElement.getComputedTextLength();
..................................
change the text context of the textElement
..................................
newWidth = textElement.getComputedTextLength();

SVGMatrix matrix = textElement.getTransform().getBaseVal().consolidate().getMatrix();
oldX = matrix.getE();

if (oldWidth > newWidth) {
 newX = oldX + ((oldWidth - newWidth) / 2);
} else if (oldWidth < newWidth) {
 newX = oldX - ((newWidth - oldWidth) / 2);
}

matrix.setE(newX);

Is something wrong in the above code.
thanks,
Ananth

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


Re: little help

Posted by Cameron McCormack <ca...@aka.mcc.id.au>.
Hi Ananth.

ananth balasubramanyam:
> I am replacing the text of a text element with a new text string and
> am trying to shift the text element, either to the left or the right based
> on the the difference in old and new widths(so as to maintain the
> center alignment). Here is a sample code. I dont
> seem to be visually getting the desired results. Could somebody please
> help me with this. Am i doing something wrong ?

Not addressing your actual problem, but why don't you just set
text-anchor="middle" on your text element so you the centering is done
automatically?

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