int[] missingGlyphCode = new int[1];
missingGlyphCode[0] = commonSizeFont.getMissingGlyphCode();
GlyphVector gv;
gv = commonSizeFont.createGlyphVector(localFRC, 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, String.valueOf( 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, String.valueOf( gm.getAdvance() ) );
// set the ascent and descent attributes
LineMetrics lm = commonSizeFont.getLineMetrics("By", localFRC);
fontFace.setAttributeNS(null, SVG_ASCENT_ATTRIBUTE, String.valueOf( lm.getAscent() ) );
fontFace.setAttributeNS(null, SVG_DESCENT_ATTRIBUTE, String.valueOf( lm.getDescent() ) );
//
// Font ID
//
fontDef.setAttributeNS(null, SVG_ID_ATTRIBUTE, generatorContext.idGenerator.generateID(ID_PREFIX_FONT));
}
//
// add any new glyphs to the fontDef here
//
String textUsingFont = clh.getNewChars();
clh.clearNewChars();
// 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);
String searchStr = String.valueOf( c );
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( searchStr )) {
foundGlyph = true;
break;
}
}
}
if (!foundGlyph) {
// need to create one
Element glyphElement
= domFactory.createElementNS(SVG_NAMESPACE_URI,
SVG_GLYPH_TAG);
GlyphVector gv;
gv = commonSizeFont.createGlyphVector(localFRC, ""+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, String.valueOf( gm.getAdvance() ) );
glyphElement.setAttributeNS(null, SVG_UNICODE_ATTRIBUTE, String.valueOf( c ) );
fontDef.appendChild(glyphElement);
} else {
// have reached the chars in textUsingFont that already