int missingGlyphCode[] = new int[1];
missingGlyphCode[0] = commonSizeFont.getMissingGlyphCode();
GlyphVector gv = commonSizeFont.createGlyphVector(frc, missingGlyphCode);
Shape missingGlyphShape = gv.getGlyphOutline(0);
GlyphMetrics gm = gv.getGlyphMetrics(0);
// need to turn the missing glyph upside down to be in the font
// coordinate system (i.e Y axis up)
AffineTransform at = AffineTransform.getScaleInstance(1, -1);
missingGlyphShape = at.createTransformedShape(missingGlyphShape);
missingGlyphElement.setAttributeNS(null, SVG_D_ATTRIBUTE,
SVGPath.toSVGPathData(missingGlyphShape, generatorContext));
missingGlyphElement.setAttributeNS(null, SVG_HORIZ_ADV_X_ATTRIBUTE,
"" + gm.getAdvance());
fontDef.appendChild(missingGlyphElement);
// set the font's default horizontal advance to be the same as
// the missing glyph
fontDef.setAttributeNS(null, SVG_HORIZ_ADV_X_ATTRIBUTE, "" + gm.getAdvance());
// set the ascent and descent attributes
LineMetrics lm = commonSizeFont.getLineMetrics("By", frc);
fontFace.setAttributeNS(null, SVG_ASCENT_ATTRIBUTE, "" + lm.getAscent());
fontFace.setAttributeNS(null, SVG_DESCENT_ATTRIBUTE, "" + lm.getDescent());
//
// Font ID
//
fontDef.setAttributeNS(null, ATTR_ID,
generatorContext.idGenerator.
generateID(ID_PREFIX_FONT));
}
//
// add any new glyphs to the fontDef here
//
// process the characters in textUsingFont backwards since the new chars
// are at the end, can stop when find a char that already has a glyph
for (int i = textUsingFont.length()-1; i >= 0; i--) {
char c = textUsingFont.charAt(i);
boolean foundGlyph = false;
NodeList fontChildren = fontDef.getChildNodes();
for (int j = 0; j < fontChildren.getLength(); j++) {
if (fontChildren.item(j) instanceof Element) {
Element childElement = (Element)fontChildren.item(j);
if (childElement.getAttributeNS(null,
SVG_UNICODE_ATTRIBUTE).equals(""+c)) {
foundGlyph = true;
break;
}
}
}
if (!foundGlyph) {
// need to create one
Element glyphElement
= domFactory.createElementNS(SVG_NAMESPACE_URI,
SVG_GLYPH_TAG);
GlyphVector gv = commonSizeFont.createGlyphVector(frc, ""+c);
Shape glyphShape = gv.getGlyphOutline(0);
GlyphMetrics gm = gv.getGlyphMetrics(0);
// need to turn the glyph upside down to be in the font
// coordinate system (i.e Y axis up)
AffineTransform at = AffineTransform.getScaleInstance(1, -1);
glyphShape = at.createTransformedShape(glyphShape);
glyphElement.setAttributeNS(null, SVG_D_ATTRIBUTE,
SVGPath.toSVGPathData(glyphShape, generatorContext));
glyphElement.setAttributeNS(null, SVG_HORIZ_ADV_X_ATTRIBUTE,
"" + gm.getAdvance());
glyphElement.setAttributeNS(null, SVG_UNICODE_ATTRIBUTE,
"" + c);
fontDef.appendChild(glyphElement);
} else {