Ignore:
Timestamp:
02/29/08 15:07:04 (4 years ago)
Author:
jharrop
Message:

Font replacement in HTML (for PDF output) is now basically working.

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

    r145 r153  
    3232 
    3333import org.apache.log4j.Logger; 
     34import org.docx4j.fonts.Substituter; 
    3435import org.docx4j.jaxb.Context; 
    3536import org.docx4j.openpackaging.Base; 
     
    210211                 
    211212                log.info("wordDocument created for PDF rendering!"); 
    212                  
    213                  
    214                  
     213 
     214/*               
     215 *              We want to use plain old Xalan J, not xsltc 
     216 *  
     217 *              Following is not necessary provided Xalan is on the classpath. 
     218 *                                                                 ================================== 
     219 *  
     220                System.setProperty("javax.xml.transform.TransformerFactory", "FQCN"); 
     221 
     222                examples of FQCN: 
     223                 
     224                  com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl 
     225                  org.apache.xalan.xsltc.trax.TransformerFactoryImpl 
     226                 
     227                         
     228*/               
    215229                // Now transform this into XHTML 
    216230                javax.xml.transform.TransformerFactory tfactory = javax.xml.transform.TransformerFactory.newInstance(); 
     
    228242                // Use the template to create a transformer 
    229243                javax.xml.transform.Transformer xformer = template.newTransformer(); 
    230  
     244                 
     245                log.error(xformer.getClass().getName() ); 
     246                // com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl won't work 
     247                // with our extension function. 
     248 
     249                // Handle fonts - this is platform specific 
     250                // Algorithm - to be implemented: 
     251                // 1.  Get a list of all the fonts in the document 
     252                java.util.Map fontsInUse = this.getMainDocumentPart().fontsInUse(); 
     253                 
     254                // 2.  For each font, find the closest match on the system (use OO's VCL.xcu to do this) 
     255                //     - do this in a general way, since docx4all needs this as well to display fonts 
     256                Substituter s = new Substituter(); 
     257                s.populateFontMappings(fontsInUse); 
     258                 
     259                // 3.  Ensure that the font names in the XHTML have been mapped to these matches 
     260                //     possibly via an extension function in the XSLT 
     261                xformer.setParameter("substituterInstance", s); 
     262                 
     263                 
    231264                //DEBUGGING  
    232265                // use the identity transform if you want to send wordDocument; 
     
    275308                // Now render the XHTML 
    276309                org.xhtmlrenderer.pdf.ITextRenderer renderer = new org.xhtmlrenderer.pdf.ITextRenderer(); 
    277                  
    278                 // TODO: Handle fonts 
    279                 // - this is platform specific 
    280                 // Algorithm - to be implemented: 
    281                 // 1.  Get a list of all the fonts in the document 
    282                 // 2.  For each font, find the closest match on the system (use OO's VCL.xcu to do this) 
    283                 //     - do this in a general way, since docx4all needs this as well to display fonts 
    284                 // 3.  Ensure that the font names in the XHTML have been mapped to these matches 
    285                 //     possibly via an extension function in the XSLT 
     310                                 
    286311                // 4.  Use addFont code like that below as necessary for the fonts 
    287312                 
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/wordml2html-2007.xslt

    r139 r153  
    2525        xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
    2626        xmlns:ext="http://www.xmllab.net/wordml2html/ext" 
     27        xmlns:java="http://xml.apache.org/xalan/java" 
    2728        version="1.0" 
    28         exclude-result-prefixes="msxsl ext w o v WX aml w10"> 
    29  
    30  
     29        exclude-result-prefixes="java msxsl ext w o v WX aml w10">       
     30 
     31        <!--    xmlns:substituterClass= "org.docx4j.fonts.Substituter" 
     32        extension-element-prefixes="substituterClass"    
     33--> 
     34         
    3135<xsl:output method="xml" encoding="utf-8" omit-xml-declaration="no" indent="yes" /> 
    3236        <!-- doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" --> 
    3337 
     38<!-- Used in extension function for mapping fonts -->            
     39<xsl:param name="substituterInstance"/> <!-- select="'passed in'"-->     
     40         
    3441 
    3542<xsl:variable name="paraStyleID_Default">Normal</xsl:variable> 
     
    26232630 
    26242631       Basic support for fonts --> 
     2632 
     2633 
     2634<!--  
    26252635<xsl:template match="w:rFonts" mode="rpr">font-family:<xsl:value-of select="@w:ascii"/>;</xsl:template> 
    2626  
     2636--> 
     2637         
     2638<xsl:template match="w:rFonts" mode="rpr"> 
     2639        <xsl:variable name="documentFont"><xsl:value-of select="string(@w:ascii)"/></xsl:variable> 
     2640        <xsl:variable name="targetFont" select="java:org.docx4j.fonts.Substituter.getPdfSubstituteFont($substituterInstance, string($documentFont))" /> 
     2641        font-family:<xsl:value-of select="$targetFont"/>; 
     2642</xsl:template> 
    26272643 
    26282644 
Note: See TracChangeset for help on using the changeset viewer.