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. 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'. > 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). > I need an exact size for my compute. Then you will either need to exactly match Batik's layout algorithm (see batik.gvt.text.doExplicitGlyphLayout), or use the text content API for each string. > Here is a snapshot of the result : > Each red rectangle is the bounding rectangle of a character. > http://www.hiboox.fr/go/images/informatique/spaceproblem, > 8595d6a7be900c2c0c63600b7dc0678e.png.html > > You can easily see the problem on the first space. > The more space i have in a string, the biggest the error is !
