Package org.docx4j.fonts.fop.fonts

Examples of org.docx4j.fonts.fop.fonts.FontTriplet


        for (Iterator/*<FontSubstitution>*/ subsIt = super.iterator(); subsIt.hasNext();) {
            FontSubstitution substitution = (FontSubstitution)subsIt.next();

            // find the best matching font triplet
            FontQualifier toQualifier = substitution.getToQualifier();
            FontTriplet fontTriplet = toQualifier.bestMatch(fontInfo);
            if (fontTriplet == null) {
                log.error("Unable to match font substitution for destination qualifier "
                        + toQualifier);
                continue;
            }
            String internalFontKey = fontInfo.getInternalFontKey(fontTriplet);

            FontQualifier fromQualifier = substitution.getFromQualifier();
            List/*<FontTriplet>*/ tripletList = fromQualifier.getTriplets();
            for (Iterator tripletit = tripletList.iterator(); tripletit.hasNext();) {
                FontTriplet triplet = (FontTriplet) tripletit.next();
                fontInfo.addFontProperties(internalFontKey, triplet);
            }
        }
    }
View Full Code Here


            Map/*<FontTriplet>*/ triplets = (Map/*<FontTriplet>*/)fontInfo.getFontTriplets();
            if (triplets != null) {
                Set/*<FontTriplet>*/ tripletSet = triplets.keySet();
                for (Iterator/*<FontTriplet>*/ tripletIt = tripletSet.iterator();
                        tripletIt.hasNext();) {
                    FontTriplet triplet = (FontTriplet)tripletIt.next();
                    String fontName = triplet.getName();

                    // matched font family name
                    if (fontFamilyString.toLowerCase().equals(fontName.toLowerCase())) {

                        // try and match font weight
                        boolean weightMatched = false;
                        int fontWeight = triplet.getWeight();
                        for (Iterator weightIt = weightValue.iterator(); weightIt.hasNext();) {
                            Object weightObj = weightIt.next();
                            if (weightObj instanceof FontWeightRange) {
                                FontWeightRange intRange = (FontWeightRange)weightObj;
                                if (intRange.isWithinRange(fontWeight)) {
                                    weightMatched = true;
                                }
                            } else if (weightObj instanceof String) {
                                String fontWeightString = (String)weightObj;
                                int fontWeightValue = FontUtil.parseCSS2FontWeight(
                                        fontWeightString);
                                if (fontWeightValue == fontWeight) {
                                    weightMatched = true;
                                }
                            } else if (weightObj instanceof Integer) {
                                Integer fontWeightInteger = (Integer)weightObj;
                                int fontWeightValue = fontWeightInteger.intValue();
                                if (fontWeightValue == fontWeight) {
                                    weightMatched = true;
                                }
                            }
                        }

                        // try and match font style
                        boolean styleMatched = false;
                        String fontStyleString = triplet.getStyle();
                        for (Iterator styleIt = styleValue.iterator(); styleIt.hasNext();) {
                            String style = (String)styleIt.next();
                            if (fontStyleString.equals(style)) {
                                styleMatched = true;
                            }
View Full Code Here

     * @param fontInfo the font info
     * @return the highest priority matching font triplet
     */
    protected FontTriplet bestMatch(FontInfo fontInfo) {
        List/*<FontTriplet>*/ matchingTriplets = match(fontInfo);
        FontTriplet bestTriplet = null;
        if (matchingTriplets.size() == 1) {
            bestTriplet = (FontTriplet)matchingTriplets.get(0);
        } else {
            for (Iterator iterator = matchingTriplets.iterator(); iterator.hasNext();) {
                FontTriplet triplet = (FontTriplet)iterator.next();
                if (bestTriplet == null) {
                    bestTriplet = triplet;
                } else {
                    int priority = triplet.getPriority();
                    if (priority < bestTriplet.getPriority()) {
                        bestTriplet = triplet;
                    }
                }
            }
View Full Code Here

                    if (weightObj instanceof FontWeightRange) {
                        FontWeightRange fontWeightRange = (FontWeightRange)weightObj;
                        int[] weightRange = fontWeightRange.toArray();
                        for (int i = 0; i < weightRange.length; i++) {
                            triplets.add(new FontTriplet(name, style, weightRange[i]));
                        }
                    } else if (weightObj instanceof String) {
                        String weightString = (String)weightObj;
                        int weight = FontUtil.parseCSS2FontWeight(weightString);
                        triplets.add(new FontTriplet(name, style, weight));
                    } else if (weightObj instanceof Integer) {
                        Integer weightInteger = (Integer)weightObj;
                        int weight = weightInteger.intValue();
                        triplets.add(new FontTriplet(name, style, weight));
                    }
                }
            }
        }
        return triplets;
View Full Code Here

        //Full Name usually includes style/weight info so don't use these traits
        //If we still want to use these traits, we have to make FontInfo.fontLookup() smarter
       
        //System.out.println("fuulName:" + fullName);
        // Full name contains spaces, and is typically Title Case
        triplets.add(new FontTriplet(fullName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL));
        if (!fullName.equals(strippedName)) {
            triplets.add(new FontTriplet(strippedName, Font.STYLE_NORMAL, Font.WEIGHT_NORMAL));
        }
        Set familyNames = customFont.getFamilyNames();
        Iterator iter = familyNames.iterator();
        while (iter.hasNext()) {
            String familyName = stripQuotes((String)iter.next());
            if (!fullName.equals(familyName)) {
                /* Heuristic:
                 *   The more similar the family name to the full font name,
                 *   the higher the priority of its triplet.
                 * (Lower values indicate higher priorities.) */
                int priority = fullName.startsWith(familyName)
                    ? fullName.length() - familyName.length()
                    : fullName.length();
                triplets.add(new FontTriplet(familyName, style, weight, priority));
            }
        }
    }
View Full Code Here

        if (pf.getEmbedFontInfo().getSubFontName()!=null)
          subFontAtt= " sub-font=\"" + pf.getEmbedFontInfo().getSubFontName() + "\"";
       
        result.append("<font embed-url=\"" +pf.getEmbeddedFile() + "\""+ subFontAtt +">" );
          // now add the first font triplet
          FontTriplet fontTriplet = (FontTriplet)pf.getEmbedFontInfo().getFontTriplets().get(0);
          addFontTriplet(result, fontTriplet);
        result.append("</font>" );
       
        // bold, italic etc
        PhysicalFont pfVariation = PhysicalFonts.getBoldForm(pf);
View Full Code Here

      PhysicalFont pf;
     
//      for (Iterator iterIn = fontInfo.getFontTriplets().iterator() ; iterIn.hasNext();) {
//        FontTriplet triplet = (FontTriplet)iterIn.next();
     
        FontTriplet triplet = (FontTriplet)fontInfo.getFontTriplets().get(0);
        // There is one triplet for each of the font family names
        // this font has, and we create a PhysicalFont object
        // for each of them.  For our purposes though, each of
        // these physical font objects contains the same info
         
            String lower = fontInfo.getEmbedFile().toLowerCase();
            log.debug("Processing physical font: " + lower);
        debug.append(".. triplet " + triplet.getName()
            + " (priority " + triplet.getPriority() +"\n" );
                       
            pf = null;
            // xhtmlrenderer's org.xhtmlrenderer.pdf.ITextFontResolver.addFont
            // can handle
            // .otf, .ttf, .ttc, .pfb
            if (lower.endsWith(".otf") || lower.endsWith(".ttf") || lower.endsWith(".ttc") ) {
              pf = new PhysicalFont(triplet.getName(), fontInfo, fontResolver);
            } else if (lower.endsWith(".pfb") ) {
              // See whether we have everything org.xhtmlrenderer.pdf.ITextFontResolver.addFont
              // will need - for a .pfb file, it needs a corresponding .afm or .pfm
          String afm = FontUtils.pathFromURL(lower);
          afm = afm.substring(0, afm.length()-4 ) + ".afm"// drop the 'file:'
          log.debug("Looking for: " + afm);         
          File f = new File(afm);
              if (f.exists()) {
               
                log.debug(".. found");

// Uncomment if you want to use the iText stuff in docx4j-extras               
//                // We're only interested if this font supports UTF-8 encoding
//                // since otherwise iText can't use it (at least on a
//                // UTF8 encoded XHTML document)
//                try {
//                  BaseFont bf = BaseFont.createFont(afm,
//                      BaseFont.IDENTITY_H,
//                  BaseFont.NOT_EMBEDDED);
//            } catch (java.io.UnsupportedEncodingException uee) {
//              log.error(afm + " does not support UTF encoding, so ignoring");
//              continue;
//            } catch (Exception e) {
//              log.error(e.getMessage(), e);
//              continue;
//            }
                pf = new PhysicalFont(triplet.getName(),fontInfo, fontResolver);
               
               
              } else {
                // Should we be doing afm first, or pfm?
            String pfm = FontUtils.pathFromURL(lower);
            pfm = pfm.substring(0, pfm.length()-4 ) + ".pfm"// drop the 'file:'
            log.debug("Looking for: " + pfm);
            f = new File(pfm);
                if (f.exists()) {       
                  log.debug(".. found");

                  // Uncomment if you want to use the iText stuff in docx4j-extras                                 
//                  // We're only interested if this font supports UTF-8 encoding
//                  try {
//                    BaseFont bf = BaseFont.createFont(pfm,
//                        BaseFont.IDENTITY_H,
//                    BaseFont.NOT_EMBEDDED);
//              } catch (java.io.UnsupportedEncodingException uee) {
//                log.error(pfm + " does not support UTF encoding, so ignoring");
//                continue;
//              } catch (Exception e) {
//                log.error(e.getMessage(), e);
//                continue;
//              }
                  pf = new PhysicalFont(triplet.getName(), fontInfo, fontResolver);
                } else {
                log.warn("Skipping " + triplet.getName() + "; couldn't find .afm or .pfm for : " + fontInfo.getEmbedFile());                                                         
                }
              }
            } else {                     
            log.warn("Skipping " + triplet.getName() + "; unsupported type: " + fontInfo.getEmbedFile());                                       
            }
         
           
            if (pf!=null) {
             
View Full Code Here

TOP

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

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.