try {
// try if the font has been defined.
Document mDocument = ((Document) ((OdfFileDom) mElement.getOwnerDocument()).getDocument());
// find <office:font-face-decls> in content dom
OdfContentDom contentDom = mDocument.getContentDom();
OfficeFontFaceDeclsElement fontfaceDecls = OdfElement.findFirstChildNode(OfficeFontFaceDeclsElement.class,
contentDom.getRootElement());
if (fontfaceDecls == null) {
// find <office:font-face-decls> in style dom
OdfStylesDom styleDom = mDocument.getStylesDom();
fontfaceDecls = OdfElement.findFirstChildNode(OfficeFontFaceDeclsElement.class, styleDom
.getRootElement());
if (fontfaceDecls == null)
fontfaceDecls = contentDom.getRootElement().newOfficeFontFaceDeclsElement();
}
NodeList list = fontfaceDecls.getElementsByTagName("style:font-face");
for (int i = 0; i < list.getLength(); i++) {
StyleFontFaceElement node = (StyleFontFaceElement) list.item(i);
String familyname = node.getSvgFontFamilyAttribute();
String fontName = node.getStyleNameAttribute();
if (aFamilyName.equals(familyname)) {
return fontName;
}
if (aFontName.equals(fontName)) {
duplicated = true;
}
}
// Get a font name
while (duplicated) {
duplicated = false;
aFontName = aFontName + "_1";
for (int i = 0; i < list.getLength(); i++) {
StyleFontFaceElement node = (StyleFontFaceElement) list.item(i);
String fontName = node.getStyleNameAttribute();
if (aFontName.equals(fontName)) {
duplicated = true;
break;
}
}
}
StyleFontFaceElement newfont = fontfaceDecls.newStyleFontFaceElement(aFontName);
newfont.setSvgFontFamilyAttribute(aFamilyName);
return aFontName;
} catch (Exception e) {
Logger.getLogger(TextProperties.class.getName()).log(Level.SEVERE, e.getMessage(), e);
}