thomas.deweese wrote: > > Hi Thomy, > > Thomy <[email protected]> wrote on 05/26/2009 02:11:45 PM: > >> > If you want to know actual text content positions I would suggest >> > that the text content SVG DOM Api's would be a better choice than >> > getBBox: >> > >> > http://www.w3.org/TR/SVG/text.html#DOMInterfaces >> > >> > Take a look at 'samples/tests/spec/scripting/text_content.svg' >> > in the distribution for an example of using these API's. >> > In particular you can call 'getEndPositionOfChar(index)' for the >> > trailing space to get the location of the end of the space. > >> I tried this solution and it's more accurate, but it's not the > "ultimate" >> solution for my space problem. >> In fact, i compute height and width of each character in a String with > the >> following code : > > This code looks a little weird. It looks to me like you are > calculating the width of each character in isolation.
That's exactly what i'm trying to do. My algorithm evolve since my first message and i need to work on character positions, not on string. But i found why there is a size error : i use integer to store values. If i pass them in float, there is not error anymore. > This is a bad idea because Batik implements kerning which can adjust the > space between characters on a pairwise basis. The example for > pairwise kerning I always use is my last name: DeWeese. With a > lot of fonts the two 'e' glyphs will be kerned in under the > "arms" of the capital 'W', if you don't do that the W can > look disconnected, but the default advance can't be shorter > otherwise tall letters (l, h, t, almost all Caps) would collide > with the top of the 'W'. Good to know, so i will do some tests with your name ;) In fact i compute character size one by one, but when i add text element to my svg, i pass the entire string Then, i made one polygone shape for each character (red polygones). Each x2 positions of polygons are the x1 positions of the next character Here is a snapshoot with your name, it's doesn't seems to be wrong, but maybe it's because of the used font (Verdana ?). http://www.hiboox.fr/go/images/informatique/spaceproblem,536d93528638ed63c070aaed88f63139.png.html > >> Text tmpText = docCalcul.createTextNode(string); >> retourLigne.appendChild(tmpText); >> docCalcul.getDocumentElement().appendChild(retourLigne); >> retour += retourLigne.getEndPositionOfChar(0).getX(); > > See I would expect a loop here for the length of "string" > asking for the end position of each character in the string. > >> It's worked well for all character but the space width isn't exact. >> Can you tell me why ? > > Actually the error looks to start earlier in the string than > the space (note the first 'e' isn't aligned with the red bar like > it normally would be). because of integer, if it can be useful for someone else. -- View this message in context: http://www.nabble.com/Re%3A-Define-String-Width-with-bounding-box-tp23739342p23740555.html Sent from the Batik - Users mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
