Package org.docx4j.fonts.fop.fonts

Examples of org.docx4j.fonts.fop.fonts.CustomFont


   
    // Save to "Temporary Font Files" directory.
        FontResolver fontResolver = FontSetup.createMinimalFontResolver();

    if (log.isDebugEnabled()) {
          CustomFont customFont = null;
          try {
            log.debug("Loading from: " + path);
            String subFontName = null; // TODO set this if its a TTC
            boolean embedded = true;  
            boolean useKerning = true;
              customFont = FontLoader.loadFont("file:" + path,
                  subFontName, embedded, EncodingMode.AUTO, useKerning, fontResolver);
          } catch (Exception e) {
        e.printStackTrace();
          }
          if (customFont!=null) {
            log.info("Successfully reloaded " + customFont.getFontName());
            if (customFont.isEmbeddable()) {
              log.debug("confirmed embeddable");
            } else {
              // Sanity check
              log.error("this embedded font claims it is not embeddable!");           
            }
View Full Code Here


            }
        }


        // try to determine triplet information from font file
        CustomFont customFont = null;
        if (fontUrl.toExternalForm().endsWith(".ttc")) {
            // Get a list of the TTC Font names
            List ttcNames = null; //List<String>
            String fontFileURI = fontUrl.toExternalForm().trim();
            InputStream in = null;
            try {
                in = FontLoader.openFontUri(resolver, fontFileURI);
                TTFFile ttf = new TTFFile();
                FontFileReader reader = new FontFileReader(in);
                ttcNames = ttf.getTTCnames(reader);
            } catch (Exception e) {
                if (this.eventListener != null) {
                    this.eventListener.fontLoadingErrorAtAutoDetection(this, fontFileURI, e);
                }
                return null;
            } finally {
                IOUtils.closeQuietly(in);
            }

            List embedFontInfoList = new java.util.ArrayList(); //List<EmbedFontInfo>

            // For each font name ...
            //for (String fontName : ttcNames) {
            Iterator ttcNamesIterator = ttcNames.iterator();
            while (ttcNamesIterator.hasNext()) {
                String fontName = (String)ttcNamesIterator.next();

                if (log.isDebugEnabled()) {
                    log.debug("Loading " + fontName);
                }
                try {
                    TTFFontLoader ttfLoader = new TTFFontLoader(
                            fontFileURI, fontName, true, EncodingMode.AUTO, true, resolver);
                    customFont = ttfLoader.getFont();
                    if (this.eventListener != null) {
                        customFont.setEventListener(this.eventListener);
                    }
                } catch (Exception e) {
                    if (fontCache != null) {
                        fontCache.registerFailedFont(embedUrl, fileLastModified);
                    }
                    if (this.eventListener != null) {
                        this.eventListener.fontLoadingErrorAtAutoDetection(this, embedUrl, e);
                    }
                    continue;
                }
                EmbedFontInfo fi = getFontInfoFromCustomFont(fontUrl, customFont, fontCache);
                if (fi != null) {
                    embedFontInfoList.add(fi);
                }
            }
            return (EmbedFontInfo[])embedFontInfoList.toArray(
                    new EmbedFontInfo[embedFontInfoList.size()]);
        } else {
            // The normal case
            try {
                customFont = FontLoader.loadFont(fontUrl, null, true, EncodingMode.AUTO, resolver);
                if (this.eventListener != null) {
                    customFont.setEventListener(this.eventListener);
                }
            } catch (Exception e) {
                if (fontCache != null) {
                    fontCache.registerFailedFont(embedUrl, fileLastModified);
                }
View Full Code Here

TOP

Related Classes of org.docx4j.fonts.fop.fonts.CustomFont

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.