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.

Location:
trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages
Files:
2 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(); 
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/wordml2html-2007.xslt

    r204 r205  
    26502650        <xsl:choose> 
    26512651                <xsl:when test="count(../w:b)=1 and count(../w:i)=1"> 
     2652                        <!-- 'BoldItalic' is iText magic string --> 
    26522653                        <xsl:variable name="targetFont"  
    26532654                                select="java:org.docx4j.fonts.Substituter.getSubstituteFontXsltExtension($substituterInstance,  
    2654                                                         string($documentFont), 'bolditalic', boolean($fontFamilyStack))" /> 
     2655                                                        string($documentFont), 'BoldItalic', boolean($fontFamilyStack))" /> 
    26552656                        font-family:'<xsl:value-of select="$targetFont"/>';                                              
    26562657                </xsl:when> 
    26572658                <xsl:when test="count(../w:b)=1"> 
     2659                        <!-- 'Bold' is iText magic string --> 
    26582660                        <xsl:variable name="targetFont"  
    26592661                                select="java:org.docx4j.fonts.Substituter.getSubstituteFontXsltExtension($substituterInstance,  
    2660                                                         string($documentFont), 'bold', boolean($fontFamilyStack))" /> 
     2662                                                        string($documentFont), 'Bold', boolean($fontFamilyStack))" /> 
    26612663                        font-family:'<xsl:value-of select="$targetFont"/>';                                                                      
    26622664                </xsl:when> 
    26632665                <xsl:when test="count(../w:i)=1"> 
     2666                        <!-- 'Italic' is iText magic string --> 
    26642667                        <xsl:variable name="targetFont"  
    26652668                                select="java:org.docx4j.fonts.Substituter.getSubstituteFontXsltExtension($substituterInstance,  
    2666                                                         string($documentFont), 'italic', boolean($fontFamilyStack))" /> 
     2669                                                        string($documentFont), 'Italic', boolean($fontFamilyStack))" /> 
    26672670                        font-family:'<xsl:value-of select="$targetFont"/>';                                                                      
    26682671                </xsl:when> 
Note: See TracChangeset for help on using the changeset viewer.