Package org.odftoolkit.odfdom.dom.element.office

Examples of org.odftoolkit.odfdom.dom.element.office.OfficeFontFaceDeclsElement


    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)
        return null;

      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 (aFontName.equals(fontName)) {
View Full Code Here


    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);
    }
View Full Code Here

TOP

Related Classes of org.odftoolkit.odfdom.dom.element.office.OfficeFontFaceDeclsElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.