return null; // Not an SVG element.
// if the referenced element is a glyph
if (refElement.getLocalName().equals(SVG_GLYPH_TAG)) {
Glyph glyph = getGlyph(ctx, uri, altGlyphElement, fontSize, aci);
if (glyph == null) {
// failed to create a glyph for the specified glyph uri
return null;
}
Glyph[] glyphArray = new Glyph[1];
glyphArray[0] = glyph;
return glyphArray;
}
// else should be an altGlyphDef element
if (refElement.getLocalName().equals(SVG_ALT_GLYPH_DEF_TAG)) {
// if not local import the referenced altGlyphDef
// into the current document
SVGOMDocument document
= (SVGOMDocument)altGlyphElement.getOwnerDocument();
SVGOMDocument refDocument
= (SVGOMDocument)refElement.getOwnerDocument();
boolean isLocal = (refDocument == document);
Element localRefElement = (isLocal) ? refElement
: (Element)document.importNode(refElement, true);
if (!isLocal) {
// need to attach the imported element to the document and
// then compute the styles and uris
String base = XMLBaseSupport.getCascadedXMLBase(altGlyphElement);
Element g = document.createElementNS(SVG_NAMESPACE_URI, SVG_G_TAG);
g.appendChild(localRefElement);
g.setAttributeNS(XMLBaseSupport.XML_NAMESPACE_URI,
"xml:base",
base);
CSSUtilities.computeStyleAndURIs(refElement,
localRefElement,
uri);
}
// look for glyphRef children
NodeList altGlyphDefChildren = localRefElement.getChildNodes();
boolean containsGlyphRefNodes = false;
int numAltGlyphDefChildren = altGlyphDefChildren.getLength();
for (int i = 0; i < numAltGlyphDefChildren; i++) {
Node altGlyphChild = altGlyphDefChildren.item(i);
if (altGlyphChild.getNodeType() == Node.ELEMENT_NODE) {
Element agc = (Element)altGlyphChild;
if (SVG_NAMESPACE_URI.equals(agc.getNamespaceURI()) &&
SVG_GLYPH_REF_TAG.equals(agc.getLocalName())) {
containsGlyphRefNodes = true;
break;
}
}
}
if (containsGlyphRefNodes) { // process the glyphRef children
NodeList glyphRefNodes
= localRefElement.getElementsByTagNameNS(SVG_NAMESPACE_URI,
SVG_GLYPH_REF_TAG);
int numGlyphRefNodes = glyphRefNodes.getLength();
Glyph[] glyphArray = new Glyph[numGlyphRefNodes];
for (int i = 0; i < numGlyphRefNodes; i++) {
// get the referenced glyph element
Element glyphRefElement = (Element)glyphRefNodes.item(i);
String glyphUri = XLinkSupport.getXLinkHref(glyphRefElement);
Glyph glyph
= getGlyph(ctx, glyphUri, glyphRefElement, fontSize, aci);
if (glyph == null) {
// failed to create a glyph for the specified glyph uri
return null;
}
glyphArray[i] = glyph;
}
return glyphArray;
} else { // try looking for altGlyphItem children
NodeList altGlyphItemNodes
= localRefElement.getElementsByTagNameNS
(SVG_NAMESPACE_URI, SVG_ALT_GLYPH_ITEM_TAG);
int numAltGlyphItemNodes = altGlyphItemNodes.getLength();
if (numAltGlyphItemNodes > 0) {
boolean foundMatchingGlyph = false;
Glyph[] glyphArray = null;
//look through all altGlyphItem to find the one
//that have all its glyphs available
for (int i = 0; i < numAltGlyphItemNodes && !foundMatchingGlyph ; i++) {
// try to find a resolvable glyphRef
Element altGlyphItemElement = (Element)altGlyphItemNodes.item(i);
NodeList altGlyphRefNodes
= altGlyphItemElement.getElementsByTagNameNS
(SVG_NAMESPACE_URI, SVG_GLYPH_REF_TAG);
int numAltGlyphRefNodes = altGlyphRefNodes.getLength();
glyphArray = new Glyph[numAltGlyphRefNodes];
// consider that all glyphs are available
// and check if they can be found
foundMatchingGlyph = true;
for (int j = 0; j < numAltGlyphRefNodes; j++) {
// get the referenced glyph element
Element glyphRefElement = (Element)altGlyphRefNodes.item(j);
String glyphUri = XLinkSupport.getXLinkHref(glyphRefElement);
Glyph glyph = getGlyph(ctx, glyphUri, glyphRefElement, fontSize, aci);
if (glyph != null) {
// found a matching glyph for this altGlyphItem
glyphArray[j] = glyph;
}
else{