Hi Ruben,

   I'm fairly certain that getExtentOfChar works properly.  We have a fairly complete test of it in "samples/tests/spec/scripting/text_content.svg" I added some hkern examples to the SVG font that test includes and getExtentOfChar worked correctly in that context.  In looking at that test one thing that occurred to me is the possibility that the coordinate system you are adding the rectangles is slightly different from the texts coordinate system (note that getExtentOfChar returns box in the text element not in the coordinate system of the parent of the text which is likely where you are appending the rect).  You might want to adopt the code that test uses to display it's rectangles for your rectangle display.

   BTW it's expected that the boxes don't overlap that doesn't indicate that the kerning is being ignored.
The extent boxes for horizontal text are adjusted to just touch each other so they can be used for hit detection.  If text selection works correctly for that text then getExtentOfChar should work.

   As for the issue with getting the extent of a single space char I suspect the issue is that we are required to remove
leading and trailing spaces from text elements in the normal case. I think you need to set the "xml:space" attribute
to "preserve".

   I would strong recommend that you try and get the 'getExtentOfChar' approach to work for you as that is a much better solution than dropping support for all the nice text features in SVG.  It also seems to me like if you can't getExtentOfChar to work properly then it likely means you don't really understand your coordinate systems which will likely lead to similar issues down the road with your own solution eventually.

   Thomas

On Nov 7, 2012, at 9:34 AM, rm <ruben.malchow@googlemail.com> wrote:



hi,

i am having font kerning issues. 

what i do is this: i dynamically convert a TTF font to an SVG font. in the SVG font, there's all kinds of kerning hints. then i link to that svg font from my svg as follows:


Element fontface = getSvg().createElementNS(svgNS, SVGConstants.SVG_FONT_FACE_TAG);
fontface.setAttributeNS(null, "font-family", fontname);

Element fontfacesrc = getSvg().createElementNS(svgNS, SVGConstants.SVG_FONT_FACE_SRC_TAG);
Element fontfaceuri = getSvg().createElementNS(svgNS, SVGConstants.SVG_FONT_FACE_URI_TAG);
fontfaceuri.setAttributeNS(svgNS, "xlink:href", uri+"#"+fontname);

Element fontfaceformat = getSvg().createElementNS(svgNS, SVGConstants.SVG_FONT_FACE_FORMAT_TAG);
fontfaceformat.setAttributeNS(svgNS, "string", "svg");

fontfaceuri.appendChild(fontfaceformat);
fontfacesrc.appendChild(fontfaceuri);
fontface.appendChild(fontfacesrc);
defs.appendChild(fontface);


and then i create my textnode like this:


Element text = svg.createElementNS(
svgNS, 
SVG12Constants.SVG_TEXT_TAG);

  svg.getDocumentElement().appendChild(text);

set the font face etc in the style att:

text.setAttributeNS(
null
SVGConstants.SVG_STYLE_ATTRIBUTE
"font-size:"+fontSize+fontUnit+";"+
"font-family:"+fontName+";"+
"font-style:normal;"+
"font-variant:normal;"+
"font-weight:normal;"+
"fill:#000000;"+
"stroke:none"
);


and append the text content:

Node fpText = text.getOwnerDocument().createTextNode(textContent);
text.appendChild(fpText);


now, if i get draw a bounding box for each character:


SVGOMTextElement te = (SVGOMTextElement)text;

for(int i=0;i<textContent.length();i++) {
SVGRect rect = te.getExtentOfChar(i);

Element e = svg.createElement("rect");
e.setAttributeNS(null, "x", rect.getX()+"");
e.setAttributeNS(null, "y", rect.getY()+"");
e.setAttributeNS(null, "width", (rect.getWidth()-6)+"");
e.setAttributeNS(null, "height", rect.getHeight()+"");
e.setAttributeNS(null, "style", "fill:none;fill-opacity:1;stroke:#0000ff;stroke-width:6;stroke-opacity:1;stroke-dasharray:9,9;stroke-dashoffset:0");
svg.appendChild(e);
}


i get a bunch of boxes that have the correct sizes, but don't honour the kerning hints - 
basically, with each box exactly touching the previous one. the glyphs themselves are, however,
laid out including the kerning. in the attachment, this is especially obvious in the AT 
combination. text bounding box and getComputedLength() are also too wide.

it would be ok for me to switch kerning off completely, but setting kerning="0" does not work 
(or i misunderstand it's purpose), and WITH kerning, i cannot correctly calculate the position
and rotation. 

any help, anyone?

thanks!

.rm

 


<Untitled-1.jpg>