Package org.docx4j.fonts

Examples of org.docx4j.fonts.PhysicalFont


      JAXBContext blgh = org.docx4j.jaxb.Context.jc;
        long contextStartupTime = System.currentTimeMillis() - contextStartTime;
      System.out.println( contextStartupTime + " ms to initialise JAXB context");
       

    PhysicalFont font
        = PhysicalFonts.getPhysicalFonts().get("Comic Sans MS");
    fontMapper.put("Calibri", font);
     
    // OK, initial overhead done; let's start the test
   
View Full Code Here


   */
  protected static void declareFonts(Mapper fontMapper, Set<String> fontsInUse, StringBuilder result) {
   
    for (String fontName : fontsInUse) {       
       
        PhysicalFont pf = fontMapper.get(fontName);
       
        if (pf==null) {
          log.error("Document font " + fontName + " is not mapped to a physical font!");
          continue;
        }
       
        String subFontAtt = "";
        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);
        if (pfVariation==null) {
          log.debug(fontName + " no bold form");
        } else {
          result.append("<font embed-url=\"" +pfVariation.getEmbeddedFile() + "\""+ subFontAtt +">" );
          addFontTriplet(result, pf.getName(), "normal", "bold");
          result.append("</font>" );
        }
        pfVariation = PhysicalFonts.getBoldItalicForm(pf);
        if (pfVariation==null) {
          log.debug(fontName + " no bold italic form");
        } else {
          result.append("<font embed-url=\"" +pfVariation.getEmbeddedFile() + "\""+ subFontAtt +">" );
          addFontTriplet(result, pf.getName(), "italic", "bold");
          result.append("</font>" );
        }
        pfVariation = PhysicalFonts.getItalicForm(pf);
        if (pfVariation==null) {
          log.debug(fontName + " no italic form");
        } else {
          result.append("<font embed-url=\"" +pfVariation.getEmbeddedFile() + "\""+ subFontAtt +">" );
          addFontTriplet(result, pf.getName(), "italic", "normal");
          result.append("</font>" );
        }
         
    }
View Full Code Here

   
    // .. example of mapping font Times New Roman which doesn't have certain Arabic glyphs
    // eg Glyph "ي" (0x64a, afii57450) not available in font "TimesNewRomanPS-ItalicMT".
    // eg Glyph "ج" (0x62c, afii57420) not available in font "TimesNewRomanPS-ItalicMT".
    // to a font which does
    PhysicalFont font
        = PhysicalFonts.get("Arial Unicode MS");
      // make sure this is in your regex (if any)!!!
    if (font!=null) {
      fontMapper.put("Times New Roman", font);
      fontMapper.put("Arial", font);
View Full Code Here

              pairs = (Map.Entry)fontMappingsIterator.next();
            }
           
            String fontName = (String)pairs.getKey();       
           
            PhysicalFont pf = wordMLPackage.getFontMapper().getFontMappings().get(fontName);
           
            if (pf==null) {
              log.error("Document font " + fontName + " is not mapped to a physical font!");
              continue;
            }

            BaseFont bf = BaseFont.createFont(pf.getEmbeddedFile(),
                BaseFont.IDENTITY_H,
            BaseFont.NOT_EMBEDDED);
            baseFonts.put(fontName, bf);
           
            // bold, italic etc
            PhysicalFont pfVariation = PhysicalFonts.getBoldForm(pf);
            if (pfVariation!=null) {
                bf = BaseFont.createFont(pfVariation.getEmbeddedFile(),
                    BaseFont.IDENTITY_H,
                BaseFont.NOT_EMBEDDED);
                baseFonts.put(fontName+BOLD, bf);
            }
            pfVariation = PhysicalFonts.getBoldItalicForm(pf);
            if (pfVariation!=null) {
                bf = BaseFont.createFont(pfVariation.getEmbeddedFile(),
                    BaseFont.IDENTITY_H,
                BaseFont.NOT_EMBEDDED);
                baseFonts.put(fontName+BOLD_ITALIC, bf);
            }
            pfVariation = PhysicalFonts.getItalicForm(pf);
            if (pfVariation!=null) {
                bf = BaseFont.createFont(pfVariation.getEmbeddedFile(),
                    BaseFont.IDENTITY_H,
                BaseFont.NOT_EMBEDDED);
                baseFonts.put(fontName+ITALIC, bf);
            }             
        }
View Full Code Here

          Map.Entry pairs = (Map.Entry)physicalFontMapIterator.next();
          if(pairs.getKey()==null) {
            pairs = (Map.Entry)physicalFontMapIterator.next();
          }
          String fontName = (String)pairs.getKey();
          PhysicalFont pf = (PhysicalFont)pairs.getValue();
         
          System.out.println("Added paragraph for " + fontName);
          addObject(wordDocumentPart, sampleText, fontName );
 
          // bold, italic etc
          PhysicalFont pfVariation = PhysicalFonts.getBoldForm(pf);
          if (pfVariation!=null) {
            addObject(wordDocumentPart, sampleTextBold, pfVariation.getName() );
          }
          pfVariation = PhysicalFonts.getBoldItalicForm(pf);
          if (pfVariation!=null) {
            addObject(wordDocumentPart, sampleTextBoldItalic, pfVariation.getName() );
          }
          pfVariation = PhysicalFonts.getItalicForm(pf);
          if (pfVariation!=null) {
            addObject(wordDocumentPart, sampleTextItalic, pfVariation.getName() );
          }
         
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

            pairs = (Map.Entry)fontMappingsIterator.next();
          }
         
          String fontName = (String)pairs.getKey();
         
          PhysicalFont pf = wordMLPackage.getFontMapper().getFontMappings().get(fontName);
         
          if (pf==null) {
            log.error("Document font " + fontName + " is not mapped to a physical font!");
            continue;
          }
         
          embed(renderer, pf);         
          // For any font we embed, also embed the bold, italic, and bold italic substitute
          // .. at present, we can't tell which of these forms are actually used, so add them all
          // bold, italic etc
          PhysicalFont pfVariation = PhysicalFonts.getBoldForm(pf);
          if (pfVariation!=null) {
            embed(renderer, pfVariation);         
          }
          pfVariation = PhysicalFonts.getBoldItalicForm(pf);
          if (pfVariation!=null) {
View Full Code Here

    Text theChar = doc.createTextNode( new String(hexStringToByteArray(value) ) );
   
  DocumentFragment docfrag = doc.createDocumentFragment();
 
  String fontName = modelData.getFont();
  PhysicalFont pf = context.getWmlPackage().getFontMapper().get(fontName);

  if (pf==null) {
    log.warn("No physical font present for:" + fontName);   
      docfrag.appendChild( theChar );
   
  } else {
   
      Element span = doc.createElement("span");
      docfrag.appendChild(span);
   
      span.setAttribute("style", "font-family: '" + pf.getName() + "'" );
      span.appendChild( theChar );
  }
   
    return docfrag;
  }
View Full Code Here

      Node modelContent, TransformState state, Document doc)
      throws TransformerException {
    R.Sym modelData = (R.Sym)unmarshalledNode;
    String fontName = modelData.getFont();
    String textValue =  modelData.getChar();
    PhysicalFont pf = context.getWmlPackage().getFontMapper().get(fontName);
    char chValue = '\0';
    Typeface typeface = null;
   
      if (pf != null) {
        typeface = pf.getTypeface();
       
          if (typeface != null) {
            if (textValue.length() > 1) {
              try {
                chValue = (char)Integer.parseInt(textValue, 16);
              }
              catch (NumberFormatException nfe) {
                chValue = '\0';
              }
            }
            else {
              chValue = textValue.charAt(0);
            }
           
            if (chValue != '\0') {
              if (chValue > 0xf000) { //let's check first the character in the lower ascii (Pre-process according to ECMA-376 2.3.3.29)
                chValue -= 0xf000;
              }
              if (typeface.mapChar(chValue) == 0) {
                chValue += 0xf000;
                if (typeface.mapChar(chValue) == 0) {
                  chValue = '\0';
                }
              }
              if (chValue != '\0') {//character was found
                textValue = Character.toString(chValue);
              }
            }
          }
      }
     
      Text theChar = doc.createTextNode(textValue);
    DocumentFragment docfrag = doc.createDocumentFragment();
 
    if (pf==null) {
      log.warn("No physical font present for:" + fontName);   
        docfrag.appendChild( theChar );
     
    } else {
     
        Element foInline = doc.createElementNS("http://www.w3.org/1999/XSL/Format", "fo:inline");
        docfrag.appendChild(foInline);
     
        foInline.setAttribute("font-family", pf.getName() );
        foInline.appendChild(theChar);
    }
     
      return docfrag;
  }
View Full Code Here

          Map.Entry pairs = (Map.Entry)physicalFontMapIterator.next();
          if(pairs.getKey()==null) {
            pairs = (Map.Entry)physicalFontMapIterator.next();
          }
          String fontName = (String)pairs.getKey();
          PhysicalFont pf = (PhysicalFont)pairs.getValue();
         
          System.out.println("Added paragraph for " + fontName);
          addObject(wordDocumentPart, sampleText, fontName );
 
          // bold, italic etc
          PhysicalFont pfVariation = PhysicalFonts.getBoldForm(pf);
          if (pfVariation!=null) {
            addObject(wordDocumentPart, sampleTextBold, pfVariation.getName() );
          }
          pfVariation = PhysicalFonts.getBoldItalicForm(pf);
          if (pfVariation!=null) {
            addObject(wordDocumentPart, sampleTextBoldItalic, pfVariation.getName() );
          }
          pfVariation = PhysicalFonts.getItalicForm(pf);
          if (pfVariation!=null) {
            addObject(wordDocumentPart, sampleTextItalic, pfVariation.getName() );
          }
         
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.docx4j.fonts.PhysicalFont

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.