xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rm <ruben.malc...@googlemail.com>
Subject fonts & kerning
Date Wed, 07 Nov 2012 14:34:23 GMT


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

 





Mime
View raw message