Ignore:
Timestamp:
03/20/08 03:55:24 (4 years ago)
Author:
jharrop
Message:

Rework so that we pass iText a 'font family name' (with possible magic appendages Bold Italic or BoldItalic?), rather than a postscript font name.
iText works out the corresponding postscript font itself - too smart for our own good!
Decouple Substituter a bit more from FOP's font stuff, to make it easier to use iText exclusively in the future.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java

    r197 r205  
    3131import org.apache.log4j.Logger; 
    3232import org.docx4j.fonts.Substituter; 
     33import org.docx4j.fonts.FontUtils; 
    3334import org.docx4j.jaxb.Context; 
    3435import org.docx4j.openpackaging.contenttype.ContentType; 
     
    445446                Substituter.FontMapping fm = (Substituter.FontMapping)pairs.getValue(); 
    446447                 
    447                         log.info("Substituting " + fontName + " with " + fm.getPostScriptName() + " from " + fm.getEmbeddedFile() ); 
    448                         if (fm.getEmbeddedFile()!=null) { 
     448                        log.info("Substituting " + fontName + " with " + fm.getPhysicalFont().getFamilyName() + " from " + fm.getPhysicalFont().getEmbeddedFile() ); 
     449                        if (fm.getPhysicalFont()!=null) { 
    449450                                try { 
    450                                         if (fm.getEmbeddedFile().endsWith(".pfb")) { 
     451                                        if (fm.getPhysicalFont().getEmbeddedFile().endsWith(".pfb")) { 
    451452                                                 
    452                                                 String afm = fm.getEmbeddedFile().substring(5, fm.getEmbeddedFile().length()-4 ) + ".afm";  // drop the 'file:' 
     453//                                              String afm = fm.getPhysicalFont().getEmbeddedFile().substring(5, fm.getPhysicalFont().getEmbeddedFile().length()-4 ) + ".afm";  // drop the 'file:' 
     454                                                String afm = FontUtils.pathFromURL(fm.getPhysicalFont().getEmbeddedFile()); 
     455                                                afm = afm.substring(0, afm.length()-4 ) + ".afm";  // drop the 'file:' 
    453456                                                log.info("Looking for: " + afm); 
    454457                                                 
     
    457460                                        if (f.exists()) {                                
    458461                                                log.info("Got it"); 
    459                                                 renderer.getFontResolver().addFont(afm, BaseFont.CP1252, true, fm.getEmbeddedFile().substring(5));  // drop the 'file:'  
     462                                                renderer.getFontResolver().addFont(afm, BaseFont.CP1252, true, FontUtils.pathFromURL(fm.getPhysicalFont().getEmbeddedFile()));  // drop the 'file:'      
    460463                                        } else { 
    461464                                                // Should we be doing afm first, or pfm? 
    462                                                         String pfm = fm.getEmbeddedFile().substring(5, fm.getEmbeddedFile().length()-4 ) + ".pfm";  // drop the 'file:' 
     465                                                        String pfm = FontUtils.pathFromURL(fm.getPhysicalFont().getEmbeddedFile()); 
     466                                                        pfm = pfm.substring(0, pfm.length()-4 ) + ".pfm";  // drop the 'file:' 
    463467                                                        log.info("Looking for: " + pfm); 
    464468                                                        f = new File(pfm); 
    465469                                                if (f.exists()) {                                
    466470                                                        log.info("Got it"); 
    467                                                         renderer.getFontResolver().addFont(pfm, BaseFont.CP1252, true, fm.getEmbeddedFile().substring(5));  // drop the 'file:' 
     471                                                        renderer.getFontResolver().addFont(pfm, BaseFont.CP1252, true, FontUtils.pathFromURL(fm.getPhysicalFont().getEmbeddedFile() ));  // drop the 'file:' 
    468472                                                } else { 
    469473                                                        // Shouldn't happen. 
    470                                                         log.error("Couldn't find afm or pfm corresponding to " + fm.getEmbeddedFile()); 
     474                                                        log.error("Couldn't find afm or pfm corresponding to " + fm.getPhysicalFont().getEmbeddedFile()); 
    471475                                                } 
    472476                                        } 
    473                                         } else {                                 
    474                                                 renderer.getFontResolver().addFont(fm.getEmbeddedFile(), true); 
     477                                        } else { 
     478                                                 
     479                                                renderer.getFontResolver().addFont(FontUtils.pathFromURL(fm.getPhysicalFont().getEmbeddedFile()), true); 
    475480                                        } 
    476481                                } catch (java.io.IOException e) { 
     
    485490                                 */ 
    486491                                        e.printStackTrace(); 
    487                                         log.warn("Shouldn't happen - should have been detected upstream ... " +  e.getMessage() + ": " + fm.getEmbeddedFile());  
     492                                        log.warn("Shouldn't happen - should have been detected upstream ... " +  e.getMessage() + ": " + fm.getPhysicalFont().getEmbeddedFile());  
    488493                                } catch (Exception e) { 
    489494                                        e.printStackTrace(); 
Note: See TracChangeset for help on using the changeset viewer.