Changeset 979


Ignore:
Timestamp:
12/14/09 16:43:16 (2 years ago)
Author:
jharrop
Message:

Basic support in pdf via XSL FO, and HTML NG2, for bookmarks, hyperlink, symbols, w:pict.
Tabs are currently just replaced simple-mindedly with spaces.

Location:
trunk/docx4j/src/main/java/org/docx4j
Files:
3 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/Converter.java

    r960 r979  
    3131import org.docx4j.XmlUtils; 
    3232import org.docx4j.model.Model; 
     33import org.docx4j.model.SymbolModel; 
    3334import org.docx4j.model.TransformState; 
    3435import org.docx4j.model.table.TableModel; 
     
    8586    modelClasses = new HashMap<String, Class>(); 
    8687    modelClasses.put("w:tbl", TableModel.class); 
     88    modelClasses.put("w:sym", SymbolModel.class); 
    8789//    modelClasses.put("w:p", ParagraphModel.class); 
    8890//    modelClasses.put("w:t", TextModel.class); 
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/ModelConverter.java

    r960 r979  
    2727import org.w3c.dom.Node; 
    2828 
     29/** 
     30 * Note that ModelConverter (aka Writers) must be  
     31 * registered with eg viaXSLFO.Conversion; 
     32 * (further, the models themselves must be  
     33 *  put in the modelClasses hashmap in 
     34 *  convert.out.Converter.java, either directly, 
     35 *  or by using Converter.getInstance().registerModelConverter) 
     36 */ 
    2937public abstract class ModelConverter { 
    3038 
     
    3240        public void setWordMLPackage(WordprocessingMLPackage wordMLPackage) { 
    3341                this.wordMLPackage = wordMLPackage; 
     42        } 
     43        /** 
     44         * @return the wordMLPackage 
     45         */ 
     46        public WordprocessingMLPackage getWordMLPackage() { 
     47                return wordMLPackage; 
    3448        } 
    3549 
     
    5266        public abstract Node toNode(Model m, TransformState state) throws TransformerException; 
    5367 
     68 
    5469} 
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/html/DocX2Html.xslt

    r943 r979  
    33653365                        <xsl:variable name="imageData" select="./v:shape/v:imagedata"/> 
    33663366                         
    3367                         <xsl:copy-of select="java:org.docx4j.model.images.WordXmlPicture.createImgE10( $wmlPackage, string($imageDirPath), 
     3367                        <xsl:copy-of select="java:org.docx4j.model.images.WordXmlPicture.createHtmlImgE10( $wmlPackage, string($imageDirPath), 
    33683368                                        $shape, $imageData)" /> 
    33693369                </xsl:when> 
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/html/HtmlExporterNG.java

    r961 r979  
    22 
    33import java.io.IOException; 
    4 import java.io.OutputStream; 
    5 import java.math.BigInteger; 
    64import java.util.HashMap; 
    75import java.util.Iterator; 
    86import java.util.List; 
    97import java.util.Map; 
    10 import java.util.concurrent.locks.ReadWriteLock; 
    11 import java.util.concurrent.locks.ReentrantReadWriteLock; 
    12  
    13 import javax.xml.bind.JAXBContext; 
    14 import javax.xml.bind.JAXBElement; 
    15 import javax.xml.bind.Marshaller; 
     8 
    169import javax.xml.bind.Unmarshaller; 
    1710import javax.xml.parsers.DocumentBuilderFactory; 
    18 import javax.xml.parsers.ParserConfigurationException; 
    1911import javax.xml.transform.Source; 
    2012import javax.xml.transform.Templates; 
     
    2214import javax.xml.transform.stream.StreamSource; 
    2315 
    24 import org.apache.commons.vfs.CacheStrategy; 
    25 import org.apache.commons.vfs.FileObject; 
    26 import org.apache.commons.vfs.FileSystemException; 
    27 import org.apache.commons.vfs.FileSystemManager; 
    28 import org.apache.commons.vfs.impl.StandardFileSystemManager; 
    2916import org.apache.log4j.Logger; 
    3017import org.apache.xml.dtm.ref.DTMNodeProxy; 
    3118import org.docx4j.XmlUtils; 
    3219import org.docx4j.convert.out.Converter; 
    33 import org.docx4j.convert.out.Output; 
    34 import org.docx4j.convert.out.flatOpcXml.FlatOpcXmlCreator; 
    35 import org.docx4j.fonts.Mapper; 
    36 import org.docx4j.fonts.BestMatchingMapper; 
     20import org.docx4j.convert.out.html.SymbolWriter; 
    3721import org.docx4j.fonts.IdentityPlusMapper; 
    38 import org.docx4j.fonts.PhysicalFont; 
    3922import org.docx4j.jaxb.Context; 
    4023import org.docx4j.model.PropertyResolver; 
    4124import org.docx4j.model.TransformState; 
    42 import org.docx4j.model.listnumbering.Emulator; 
    43 import org.docx4j.model.listnumbering.Emulator.ResultTriple; 
     25import org.docx4j.model.SymbolModel.SymbolModelTransformState; 
    4426import org.docx4j.model.properties.Property; 
    4527import org.docx4j.model.properties.PropertyFactory; 
     
    4729import org.docx4j.openpackaging.exceptions.Docx4JException; 
    4830import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 
    49 import org.docx4j.relationships.Relationship; 
    5031import org.docx4j.wml.CTTblPrBase; 
    5132import org.docx4j.wml.CTTblStylePr; 
    5233import org.docx4j.wml.PPr; 
    53 import org.docx4j.wml.RFonts; 
    5434import org.docx4j.wml.RPr; 
    5535import org.docx4j.wml.Style; 
    56 import org.docx4j.wml.Tbl; 
    57 import org.docx4j.wml.Tc; 
    5836import org.docx4j.wml.TcPr; 
    59 import org.docx4j.wml.Tr; 
    6037import org.docx4j.wml.TrPr; 
    61 import org.docx4j.wml.UnderlineEnumeration; 
    62 import org.docx4j.openpackaging.parts.Part; 
    63 import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart; 
    64  
    65 import org.w3c.dom.traversal.NodeIterator; 
    66 import org.w3c.dom.DOMException; 
    6738import org.w3c.dom.Document; 
    6839import org.w3c.dom.DocumentFragment; 
    6940import org.w3c.dom.Element; 
    7041import org.w3c.dom.Node; 
    71 import org.w3c.dom.NodeList; 
    7242import org.w3c.dom.Text; 
     43import org.w3c.dom.traversal.NodeIterator; 
    7344 
    7445/** 
     
    144115         
    145116         
    146         @Deprecated 
    147117        public void output(javax.xml.transform.Result result) throws Docx4JException { 
    148118                 
     
    247217                //Converter c = new Converter(); 
    248218                Converter.getInstance().registerModelConverter("w:tbl", new TableWriter() ); 
     219        Converter.getInstance().registerModelConverter("w:sym", new SymbolWriter() ); 
    249220                 
    250221                // By convention, the transform state object is stored by reference to the  
    251222                // type of element to which its model applies 
    252223                modelStates.put("w:tbl", new TableModelTransformState() ); 
     224                modelStates.put("w:sym", new SymbolModelTransformState() ); 
    253225                 
    254226                Converter.getInstance().start(wmlPackage); 
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/html/HtmlExporterNG2.java

    r963 r979  
    578578                                        String rStyleVal = rPr.getRStyle().getVal(); 
    579579                                        Tree<AugmentedStyle> cTree = styleTree.getCharacterStylesTree();                 
    580                                         org.docx4j.model.styles.Node<AugmentedStyle> asn = cTree.get(rStyleVal);                                                 
    581                                         ((Element)span).setAttribute("class",  
    582                                                         StyleTree.getHtmlClassAttributeValue(cTree, asn)                         
    583                                         );                               
     580                                        org.docx4j.model.styles.Node<AugmentedStyle> asn = cTree.get(rStyleVal); 
     581                                        if (asn==null) { 
     582                                                log.warn("No style node for: " + rStyleVal); 
     583                                        } else { 
     584                                                ((Element)span).setAttribute("class",  
     585                                                                StyleTree.getHtmlClassAttributeValue(cTree, asn)                         
     586                                                );               
     587                                        } 
    584588                                } 
    585589                                 
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/html/docx2xhtmlNG2.xslt

    r977 r979  
    271271 
    272272 
    273   <xsl:template match="w:br[@w:type = 'page']"> 
    274         <!--  TODO --> 
    275   </xsl:template> 
    276273   
    277274  <xsl:template match="w:lastRenderedPageBreak" /> 
    278275   
     276   
     277  <!--  TODO - ignored for now --> 
     278  <xsl:template match="w:sectPr"/> 
     279 
     280  <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
     281  <!--  +++++++++++++++++++ image support +++++++++++++++++++++++ --> 
     282  <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
     283 
     284  <xsl:template match="w:drawing"> 
     285        <xsl:apply-templates select="*"/> 
     286  </xsl:template> 
     287 
     288  <xsl:template match="wp:inline|wp:anchor"> 
     289   
     290        <xsl:variable name="pictureData" select="./a:graphic/a:graphicData/pic:pic/pic:blipFill"/> 
     291        <xsl:variable name="picSize" select="./wp:extent"/> 
     292        <xsl:variable name="picLink" select="./wp:docPr/a:hlinkClick"/> 
     293        <xsl:variable name="linkDataNode" select="./a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip"/> 
     294         
     295        <xsl:copy-of select="java:org.docx4j.model.images.WordXmlPicture.createHtmlImgE20( $wmlPackage, string($imageDirPath), 
     296                        $pictureData, $picSize, $picLink, $linkDataNode)" /> 
     297     
     298  </xsl:template> 
     299   
     300    <!--  E1.0 images  --> 
     301        <xsl:template match="w:pict"> 
     302         
     303                <xsl:choose> 
     304                        <xsl:when test="./v:shape/v:imagedata"> 
     305         
     306                                <xsl:variable name="shape" select="./v:shape"/> 
     307                                <xsl:variable name="imageData" select="./v:shape/v:imagedata"/> 
     308                                 
     309                                <xsl:copy-of select="java:org.docx4j.model.images.WordXmlPicture.createHtmlImgE10( $wmlPackage, string($imageDirPath), 
     310                                                $shape, $imageData)" /> 
     311                        </xsl:when> 
     312                        <xsl:otherwise> 
     313                                <xsl:comment>TODO: handle w:pict containing other than ./v:shape/v:imagedata</xsl:comment> 
     314                        </xsl:otherwise> 
     315                </xsl:choose>                    
     316         
     317        </xsl:template> 
     318   
     319 
     320  <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
     321  <!--  +++++++++++++++++++ table support +++++++++++++++++++++++ --> 
     322  <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
     323 
     324 
     325<!--  
     326                    <w:tbl> 
     327                        <w:tblPr> 
     328                            <w:tblStyle w:val="TableGrid"/> 
     329                            <w:tblW w:type="auto" w:w="0"/> 
     330                            <w:tblLook w:val="04A0"/> 
     331                        </w:tblPr> 
     332                        <w:tblGrid> 
     333                            <w:gridCol w:w="3561"/> 
     334                            <w:gridCol w:w="3561"/> 
     335                            <w:gridCol w:w="3561"/> 
     336                        </w:tblGrid> 
     337                        <w:tr> 
     338                            <w:tc> 
     339                                <w:tcPr> 
     340 
     341 --> 
     342  <xsl:template match="w:tbl"> 
     343                <xsl:call-template name="pretty-print-block"/> 
     344 
     345                <xsl:variable name="tblNode" select="." />                       
     346 
     347                <xsl:variable name="childResults"> 
     348                        <xsl:apply-templates /> <!-- select="*[not(name()='w:tblPr' or name()='w:tblGrid')]" /--> 
     349                </xsl:variable> 
     350 
     351<!-- 
     352                <xsl:comment>debug start</xsl:comment> 
     353                        <xsl:copy-of select="$childResults"/> 
     354                <xsl:comment>debug end</xsl:comment> 
     355  --> 
     356   
     357                <!--  Create the HTML table in Java -->  
     358                <xsl:copy-of select="java:org.docx4j.convert.out.Converter.toNode($tblNode, $childResults, $modelStates)"/> 
     359                                                 
     360  </xsl:template> 
     361 
     362<xsl:template match="w:tblPr"/>   
     363<xsl:template match="w:tblGrid"/>   
     364<xsl:template match="w:tr|w:tc"> 
     365        <xsl:copy> 
     366                <!--xsl:apply-templates select="@*"/-->  
     367                <xsl:apply-templates/> 
     368        </xsl:copy> 
     369</xsl:template>   
     370<xsl:template match="w:tcPr"/> 
     371<xsl:template match="w:trPr"/> 
     372 
     373  <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
     374  <!--  +++++++++++++++++++  other stuff  +++++++++++++++++++++++ --> 
     375  <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
     376 
     377        <xsl:template match="w:proofErr" /> 
     378 
     379        <xsl:template match="w:softHyphen"> 
     380                <xsl:text>&#xAD;</xsl:text> 
     381        </xsl:template> 
     382 
     383        <xsl:template match="w:noBreakHyphen"> 
     384                <xsl:text disable-output-escaping="yes">&amp;#8209;</xsl:text> 
     385        </xsl:template> 
     386 
     387  <xsl:template match="w:br"> 
     388    <br> 
     389      <xsl:attribute name="clear"> 
     390        <xsl:choose> 
     391          <xsl:when test="@w:clear"> 
     392            <xsl:value-of select="@w:clear"/> 
     393          </xsl:when> 
     394          <xsl:otherwise>all</xsl:otherwise> 
     395        </xsl:choose> 
     396      </xsl:attribute> 
     397      <xsl:if test="@w:type = 'page'"> 
     398        <xsl:attribute name="style">page-break-before:always</xsl:attribute> 
     399      </xsl:if> 
     400    </br> 
     401  </xsl:template> 
     402   
     403  <xsl:template match="w:cr"> 
     404        <br clear="all" /> 
     405</xsl:template> 
     406   
     407<!--  <w:sym w:font="Wingdings" w:char="F04A"/> --> 
     408<xsl:template match="w:sym"> 
     409 
     410        <xsl:variable name="childResults"> 
     411                <xsl:apply-templates />  
     412        </xsl:variable> 
     413 
     414        <xsl:variable name="symNode" select="." />                       
     415 
     416     <xsl:copy-of select="java:org.docx4j.convert.out.Converter.toNode($symNode,  
     417                        $childResults, $modelStates)" /> 
     418                                         
     419</xsl:template> 
     420   
     421  <xsl:template name="OutputTlcChar"> <!--  From MS stylesheet --> 
     422    <xsl:param name="count" select="0"/> 
     423    <xsl:param name="tlc" select="' '"/> 
     424    <xsl:value-of select="$tlc"/> 
     425    <xsl:if test="$count > 1"> 
     426      <xsl:call-template name="OutputTlcChar"> 
     427        <xsl:with-param name="count" select="$count - 1"/> 
     428        <xsl:with-param name="tlc" select="$tlc"/> 
     429      </xsl:call-template> 
     430    </xsl:if> 
     431  </xsl:template> 
     432 
     433<!--  
     434 
     435<w:p> 
     436        <w:pPr><w:tabs><w:tab w:val="left" w:pos="4320"/></w:tabs></w:pPr> 
     437        <w:r><w:t xml:space="preserve">Will tab.. </w:t></w:r><w:r> 
     438        <w:tab/> 
     439        <w:t>3 inches</w:t></w:r> 
     440</w:p> 
     441 
     442 --> 
     443<xsl:template match="w:tab">  
     444        <!--  Use this simple-minded approach from MS stylesheet, 
     445              until our document model can do better.   --> 
     446    <xsl:call-template name="OutputTlcChar"> 
     447      <xsl:with-param name="tlc"> 
     448        <xsl:text disable-output-escaping="yes">&#160;</xsl:text> 
     449      </xsl:with-param> 
     450      <xsl:with-param name="count" select="3"/> 
     451    </xsl:call-template> 
     452  </xsl:template> 
     453 
     454<xsl:template match="w:smartTag"> 
     455    <xsl:apply-templates /> 
     456</xsl:template> 
     457 
    279458<!--  
    280459   
     
    289468-->   
    290469  <xsl:template match="w:hyperlink"> 
    291     <a style="text-decoration:none;"> 
     470    <a> 
    292471        <xsl:variable name="relId"><xsl:value-of select="string(@r:id)"/></xsl:variable> 
    293472       
     
    331510    </a> 
    332511  </xsl:template> 
    333    
    334   <!--  TODO - ignored for now --> 
    335   <xsl:template match="w:sectPr"/> 
    336  
    337   <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    338   <!--  +++++++++++++++++++ image support +++++++++++++++++++++++ --> 
    339   <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    340  
    341   <xsl:template match="w:drawing"> 
    342         <xsl:apply-templates select="*"/> 
    343   </xsl:template> 
    344  
    345   <xsl:template match="wp:inline|wp:anchor"> 
    346    
    347         <xsl:variable name="pictureData" select="./a:graphic/a:graphicData/pic:pic/pic:blipFill"/> 
    348         <xsl:variable name="picSize" select="./wp:extent"/> 
    349         <xsl:variable name="picLink" select="./wp:docPr/a:hlinkClick"/> 
    350         <xsl:variable name="linkDataNode" select="./a:graphic/a:graphicData/pic:pic/pic:blipFill/a:blip"/> 
    351          
    352         <xsl:copy-of select="java:org.docx4j.model.images.WordXmlPicture.createHtmlImgE20( $wmlPackage, string($imageDirPath), 
    353                         $pictureData, $picSize, $picLink, $linkDataNode)" /> 
    354      
    355   </xsl:template> 
    356  
    357   <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    358   <!--  +++++++++++++++++++ table support +++++++++++++++++++++++ --> 
    359   <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
    360  
    361  
    362 <!--  
    363                     <w:tbl> 
    364                         <w:tblPr> 
    365                             <w:tblStyle w:val="TableGrid"/> 
    366                             <w:tblW w:type="auto" w:w="0"/> 
    367                             <w:tblLook w:val="04A0"/> 
    368                         </w:tblPr> 
    369                         <w:tblGrid> 
    370                             <w:gridCol w:w="3561"/> 
    371                             <w:gridCol w:w="3561"/> 
    372                             <w:gridCol w:w="3561"/> 
    373                         </w:tblGrid> 
    374                         <w:tr> 
    375                             <w:tc> 
    376                                 <w:tcPr> 
    377  
    378  --> 
    379   <xsl:template match="w:tbl"> 
    380                 <xsl:call-template name="pretty-print-block"/> 
    381  
    382                 <xsl:variable name="tblNode" select="." />                       
    383  
    384                 <xsl:variable name="childResults"> 
    385                         <xsl:apply-templates /> <!-- select="*[not(name()='w:tblPr' or name()='w:tblGrid')]" /--> 
    386                 </xsl:variable> 
    387  
    388 <!-- 
    389                 <xsl:comment>debug start</xsl:comment> 
    390                         <xsl:copy-of select="$childResults"/> 
    391                 <xsl:comment>debug end</xsl:comment> 
    392   --> 
    393    
    394                 <!--  Create the HTML table in Java -->  
    395                 <xsl:copy-of select="java:org.docx4j.convert.out.Converter.toNode($tblNode, $childResults, $modelStates)"/> 
    396                                                  
    397   </xsl:template> 
    398  
    399 <xsl:template match="w:tblPr"/>   
    400 <xsl:template match="w:tblGrid"/>   
    401 <xsl:template match="w:tr|w:tc"> 
    402         <xsl:copy> 
    403                 <!--xsl:apply-templates select="@*"/-->  
    404                 <xsl:apply-templates/> 
    405         </xsl:copy> 
    406 </xsl:template>   
    407 <xsl:template match="w:tcPr"/> 
    408 <xsl:template match="w:trPr"/> 
    409  
    410  
    411512    
     513  <xsl:template match="w:bookmarkStart"> 
     514    <a name="{@w:name}"/> 
     515  </xsl:template> 
     516    
     517<xsl:template match="w:bookmarkEnd" /> 
     518 
     519  <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
     520  <!--  +++++++++++++++++++  no match     +++++++++++++++++++++++ --> 
     521  <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
     522 
    412523  <xsl:template match="*"> 
    413524                      <div 
     
    418529  </xsl:template> 
    419530    
    420         <xsl:template match="w:proofErr" /> 
    421  
    422         <xsl:template match="w:softHyphen"> 
    423                 <xsl:text>&#xAD;</xsl:text> 
    424         </xsl:template> 
    425  
    426         <xsl:template match="w:noBreakHyphen"> 
    427                 <xsl:text disable-output-escaping="yes">&amp;#8209;</xsl:text> 
    428         </xsl:template> 
    429     
    430   <xsl:template match="w:br"> 
    431     <br> 
    432       <xsl:attribute name="clear"> 
    433         <xsl:choose> 
    434           <xsl:when test="@w:clear"> 
    435             <xsl:value-of select="@w:clear"/> 
    436           </xsl:when> 
    437           <xsl:otherwise>all</xsl:otherwise> 
    438         </xsl:choose> 
    439       </xsl:attribute> 
    440       <xsl:if test="@w:type = 'page'"> 
    441         <xsl:attribute name="style">page-break-before:always</xsl:attribute> 
    442       </xsl:if> 
    443     </br> 
    444   </xsl:template> 
    445  
    446     
    447531</xsl:stylesheet> 
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/Conversion.java

    r977 r979  
    3232import org.docx4j.model.PropertyResolver; 
    3333import org.docx4j.model.TransformState; 
     34import org.docx4j.model.SymbolModel.SymbolModelTransformState; 
    3435import org.docx4j.model.listnumbering.Emulator.ResultTriple; 
    3536import org.docx4j.model.properties.Property; 
     
    264265//                      Converter c = new Converter(); 
    265266                Converter.getInstance().registerModelConverter("w:tbl", new TableWriter() ); 
     267                Converter.getInstance().registerModelConverter("w:sym", new SymbolWriter() ); 
    266268                 
    267269                        // By convention, the transform state object is stored by reference to the  
    268270                        // type of element to which its model applies 
    269271                        modelStates.put("w:tbl", new TableModelTransformState() ); 
     272                        modelStates.put("w:sym", new SymbolModelTransformState() ); 
    270273                 
    271274                Converter.getInstance().start(wordMLPackage); 
     
    632635                 
    633636        } 
    634      
     637         
    635638} 
    636639     
  • trunk/docx4j/src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/docx2fo.xslt

    r977 r979  
    450450  </xsl:template> 
    451451 
    452   <xsl:template match="*"> 
    453                       <fo:block font-size="12pt" 
    454                         color="red" 
    455                 font-family="sans-serif" 
    456                 line-height="15pt" 
    457                 space-after.optimum="3pt" 
    458                 text-align="justify"> 
    459         NOT IMPLEMENTED: support for <xsl:value-of select="local-name(.)"/> 
    460       </fo:block>   
    461   </xsl:template> 
    462  
    463   <xsl:template match="w:br[@w:type = 'page']"> 
    464         <fo:block break-before="page"/> 
    465   </xsl:template> 
     452 
    466453   
    467454  <xsl:template match="w:lastRenderedPageBreak" /> 
     
    486473     
    487474  </xsl:template> 
    488  
     475   
     476 
     477<xsl:template match="w:pict"> 
     478 
     479        <xsl:choose> 
     480                <xsl:when test="./v:shape/v:imagedata"> 
     481 
     482                        <xsl:variable name="shape" select="./v:shape"/> 
     483                        <xsl:variable name="imageData" select="./v:shape/v:imagedata"/> 
     484                         
     485                        <xsl:copy-of select="java:org.docx4j.model.images.WordXmlPicture.createXslFoImgE10( $wmlPackage, string($imageDirPath), 
     486                                        $shape, $imageData)" /> 
     487                </xsl:when> 
     488                <xsl:otherwise> 
     489                        <xsl:comment>TODO: handle w:pict containing other than ./v:shape/v:imagedata</xsl:comment> 
     490                </xsl:otherwise> 
     491        </xsl:choose>                    
     492 
     493</xsl:template> 
     494   
    489495   
    490496  <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
     
    561567                        </xsl:when> 
    562568                        <xsl:otherwise> 
    563                                 <fo:block /> 
     569                                <fo:block white-space-treatment="preserve"> </fo:block> 
    564570                        </xsl:otherwise> 
    565571                </xsl:choose> 
    566572        </xsl:template> 
    567573 
     574<xsl:template match="w:cr"> 
     575        <fo:block white-space-treatment="preserve"> </fo:block> 
     576</xsl:template> 
     577 
     578<!--  <w:sym w:font="Wingdings" w:char="F04A"/> --> 
     579<xsl:template match="w:sym"> 
     580 
     581        <xsl:variable name="childResults"> 
     582                <xsl:apply-templates />  
     583        </xsl:variable> 
     584 
     585        <xsl:variable name="symNode" select="." />                       
     586 
     587     <xsl:copy-of select="java:org.docx4j.convert.out.Converter.toNode($symNode,  
     588                        $childResults, $modelStates)" /> 
     589                                         
     590</xsl:template> 
     591 
     592 
     593 
     594  <xsl:template name="OutputTlcChar"> <!--  From MS stylesheet --> 
     595    <xsl:param name="count" select="0"/> 
     596    <xsl:param name="tlc" select="' '"/> 
     597    <xsl:value-of select="$tlc"/> 
     598    <xsl:if test="$count > 1"> 
     599      <xsl:call-template name="OutputTlcChar"> 
     600        <xsl:with-param name="count" select="$count - 1"/> 
     601        <xsl:with-param name="tlc" select="$tlc"/> 
     602      </xsl:call-template> 
     603    </xsl:if> 
     604  </xsl:template> 
     605 
     606<!--  
     607 
     608<w:p> 
     609        <w:pPr><w:tabs><w:tab w:val="left" w:pos="4320"/></w:tabs></w:pPr> 
     610        <w:r><w:t xml:space="preserve">Will tab.. </w:t></w:r><w:r> 
     611        <w:tab/> 
     612        <w:t>3 inches</w:t></w:r> 
     613</w:p> 
     614 
     615 --> 
     616<xsl:template match="w:tab">  
     617        <!--  Use this simple-minded approach from MS stylesheet, 
     618              until our document model can do better.   --> 
     619    <xsl:call-template name="OutputTlcChar"> 
     620      <xsl:with-param name="tlc"> 
     621        <xsl:text disable-output-escaping="yes">&#160;</xsl:text> 
     622      </xsl:with-param> 
     623      <xsl:with-param name="count" select="3"/> 
     624    </xsl:call-template> 
     625</xsl:template> 
     626 
     627 
     628<xsl:template match="w:smartTag"> 
     629    <xsl:apply-templates /> 
     630</xsl:template> 
     631 
     632<!--  
     633   
     634                <w:hyperlink r:id="rId4" w:history="true"> 
     635                        <w:r> 
     636                                <w:rPr> 
     637                                    <w:rStyle w:val="Hyperlink"/> 
     638                                </w:rPr> 
     639                                <w:t>hyperlink</w:t> 
     640                        </w:r> 
     641                </w:hyperlink> 
     642-->   
     643  <xsl:template match="w:hyperlink"> 
     644    <fo:basic-link color="blue" text-decoration="underline" > 
     645        <xsl:variable name="relId"><xsl:value-of select="string(@r:id)"/></xsl:variable> 
     646       
     647        <xsl:variable name="hTemp"  
     648                select="java:org.docx4j.convert.out.html.HtmlExporter.resolveHref( 
     649                             $wmlPackage, $relId )" /> 
     650                                    
     651      <xsl:variable name="href"> 
     652          <xsl:value-of select="$hTemp"/> 
     653        <xsl:choose> 
     654          <xsl:when test="@w:anchor"><xsl:value-of select="@w:anchor"/></xsl:when> 
     655          <xsl:when test="@w:bookmark"><xsl:value-of select="@w:bookmark"/></xsl:when> 
     656          <xsl:when test="@w:arbLocation"><xsl:value-of select="@w:arbLocation"/></xsl:when> 
     657        </xsl:choose> 
     658      </xsl:variable> 
     659       
     660        <xsl:choose> 
     661          <xsl:when test="@w:bookmark"> 
     662            <xsl:attribute name="internal-destination"><xsl:value-of select="$href"/></xsl:attribute> 
     663          </xsl:when> 
     664                <!--  TODO: id for anchor, heading etc? Re headers, I think Word may just insert a bookmark --> 
     665          <xsl:when test="@w:arbLocation"> 
     666            <xsl:attribute name="internal-destination"><xsl:value-of select="$href"/></xsl:attribute> 
     667          </xsl:when> 
     668          <xsl:when test="@w:anchor"> 
     669            <xsl:attribute name="internal-destination"><xsl:value-of select="$href"/></xsl:attribute> 
     670          </xsl:when> 
     671          <xsl:otherwise> 
     672                <!--  TODO file? --> 
     673                <xsl:attribute name="external-destination">url(<xsl:value-of select="$href"/>)</xsl:attribute>           
     674          </xsl:otherwise> 
     675        </xsl:choose> 
     676       
     677                <xsl:apply-templates />       
     678    </fo:basic-link> 
     679  </xsl:template> 
     680 
     681<!-- <w:bookmarkStart w:id="0" w:name="mybm"/>  --> 
     682<xsl:template match="w:bookmarkStart" > 
     683        <fo:inline id="{@w:name}"/> 
     684</xsl:template> 
     685 
     686<xsl:template match="w:bookmarkEnd" /> 
     687 
     688  <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
     689  <!--  +++++++++++++++++++  no match     +++++++++++++++++++++++ --> 
     690  <!--  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> 
     691 
     692  <xsl:template match="*"> 
     693                      <fo:block font-size="12pt" 
     694                        color="red" 
     695                font-family="sans-serif" 
     696                line-height="15pt" 
     697                space-after.optimum="3pt" 
     698                text-align="justify"> 
     699        NOT IMPLEMENTED: support for <xsl:value-of select="local-name(.)"/> 
     700      </fo:block>   
     701  </xsl:template> 
    568702 
    569703</xsl:stylesheet> 
  • trunk/docx4j/src/main/java/org/docx4j/model/images/WordXmlPicture.java

    r943 r979  
    44import java.io.IOException; 
    55import java.io.OutputStream; 
     6import java.io.StringReader; 
     7import java.util.List; 
    68import java.util.concurrent.locks.ReadWriteLock; 
    79import java.util.concurrent.locks.ReentrantReadWriteLock; 
     
    1719import org.apache.commons.vfs.impl.StandardFileSystemManager; 
    1820import org.apache.log4j.Logger; 
     21import org.apache.xmlgraphics.image.loader.ImageInfo; 
    1922import org.docx4j.convert.out.ConvertUtils; 
     23import org.docx4j.model.structure.DocumentModel; 
     24import org.docx4j.model.structure.PageDimensions; 
     25import org.docx4j.model.structure.SectionWrapper; 
    2026import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 
    2127import org.docx4j.openpackaging.parts.Part; 
    2228import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart; 
     29import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage; 
     30import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.CxCy; 
    2331import org.docx4j.relationships.Relationship; 
     32import org.docx4j.wml.SectPr; 
    2433import org.w3c.dom.Document; 
    2534import org.w3c.dom.DocumentFragment; 
    2635import org.w3c.dom.Node; 
     36import org.w3c.dom.css.CSSPrimitiveValue; 
     37import org.w3c.dom.css.CSSStyleDeclaration; 
    2738import org.w3c.dom.traversal.NodeIterator; 
    2839 
     
    4859    Node linkElement = null; 
    4960 
    50     /* Extension function to create an HTML <img> element 
     61    /** Extension function to create an HTML <img> element 
    5162     * from "E2.0 images"  
    5263     *      //w:drawing/wp:inline 
    5364     *     |//w:drawing/wp:anchor 
    54      */     
     65     * @param wmlPackage 
     66     * @param imageDirPath 
     67     * @param pictureData 
     68     * @param picSize 
     69     * @param picLink 
     70     * @param linkData 
     71     * @return 
     72     */ 
    5573    public static DocumentFragment createHtmlImgE20(WordprocessingMLPackage wmlPackage, 
    5674                String imageDirPath, 
     
    5876                NodeIterator picLink, NodeIterator linkData) { 
    5977 
    60         WordXmlPicture picture = createWordXmlPicture( wmlPackage, 
     78        WordXmlPicture picture = createWordXmlPictureFromE20( wmlPackage, 
    6179                         imageDirPath, pictureData,  picSize, 
    62                          picLink,  linkData); 
     80                         picLink,  linkData, true); 
    6381         
    6482        Document d = picture.createHtmlImageElement(); 
     
    7088    } 
    7189 
    72     /* Extension function to create an XSL FO <fo:external-graphic> element 
     90    /** Extension function to create an XSL FO <fo:external-graphic> element 
    7391     * from "E2.0 images"  
    7492     *      //w:drawing/wp:inline 
    7593     *     |//w:drawing/wp:anchor 
    76      */     
     94     * @param wmlPackage 
     95     * @param imageDirPath 
     96     * @param pictureData 
     97     * @param picSize 
     98     * @param picLink 
     99     * @param linkData 
     100     * @return 
     101     */ 
    77102    public static DocumentFragment createXslFoImgE20(WordprocessingMLPackage wmlPackage, 
    78103                String imageDirPath, 
     
    80105                NodeIterator picLink, NodeIterator linkData) { 
    81106 
    82         WordXmlPicture picture = createWordXmlPicture( wmlPackage, 
     107        WordXmlPicture picture = createWordXmlPictureFromE20( wmlPackage, 
    83108                         imageDirPath, pictureData,  picSize, 
    84                          picLink,  linkData); 
     109                         picLink,  linkData, false); 
    85110         
    86111        Document d = picture.createXslFoImageElement(); 
     
    101126     * @return 
    102127     */ 
    103     public static WordXmlPicture createWordXmlPicture(WordprocessingMLPackage wmlPackage, 
     128    private static WordXmlPicture createWordXmlPictureFromE20(WordprocessingMLPackage wmlPackage, 
    104129                String imageDirPath, 
    105130                NodeIterator pictureData, NodeIterator picSize, 
    106                 NodeIterator picLink, NodeIterator linkData) { 
     131                NodeIterator picLink, NodeIterator linkData, boolean targetIsHtml) { 
    107132         
    108133                 
     
    111136                 
    112137        WordXmlPicture picture = new WordXmlPicture(); 
    113         picture.readStandardAttributes( pictureData.nextNode() ); 
     138        picture.readStandardAttributes( pictureData.nextNode(), targetIsHtml ); 
    114139         
    115140        Node picSizeNode = picSize.nextNode(); 
     
    155180                                                || rel.getTargetMode().equals("Internal")) { 
    156181 
    157                                         // Get the part 
    158                                         Part part = wmlPackage.getMainDocumentPart() 
     182                        BinaryPartAbstractImage part = (BinaryPartAbstractImage)wmlPackage.getMainDocumentPart() 
    159183                                                        .getRelationshipsPart().getPart(rel); 
    160                                         try { 
    161  
    162                                                 if (imageDirPath.equals("")) { 
    163  
    164                                                         // <img 
    165                                                         // src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub/ 
    166                                                         // 
    167                                                         // which is nice, except it doesn't work in IE7, 
    168                                                         // and is limited to 32KB in IE8! 
    169  
    170                                                         java.nio.ByteBuffer bb = ((BinaryPart) part) 
    171                                                                         .getBuffer(); 
    172                                                         bb.clear(); 
    173                                                         byte[] bytes = new byte[bb.capacity()]; 
    174                                                         bb.get(bytes, 0, bytes.length); 
    175                                                          
    176                                                         byte[] encoded = Base64.encodeBase64(bytes, true); 
    177  
    178                                                         picture 
    179                                                                         .setSrc("data:" + part.getContentType() 
    180                                                                                         + ";base64," 
    181                                                                                         + (new String(encoded, "UTF-8"))); 
    182  
    183                                                 } else { 
    184                                                         // Need to save the image 
    185  
    186                                                         // To create directory: 
    187                                                         FileObject folder = getFileSystemManager() 
    188                                                                         .resolveFile(imageDirPath); 
    189                                                         if (!folder.exists()) { 
    190                                                                 folder.createFolder(); 
    191                                                         } 
    192  
    193                                                         // Construct a file name from the part name 
    194                                                         String partname = part.getPartName().toString(); 
    195                                                         String filename = partname.substring(partname 
    196                                                                         .lastIndexOf("/") + 1); 
    197                                                         log.debug("image file name: " + filename); 
    198  
    199                                                         FileObject fo = folder.resolveFile(filename); 
    200                                                         if (fo.exists()) { 
    201  
    202                                                                 log.warn("Overwriting (!) existing file!"); 
    203  
    204                                                         } else { 
    205                                                                 fo.createFile(); 
    206                                                         } 
    207                                                         // System.out.println("URL: " + 
    208                                                         // fo.getURL().toExternalForm() ); 
    209                                                         // System.out.println("String: " + fo.toString() ); 
    210  
    211                                                         // Save the file 
    212                                                         OutputStream out = fo.getContent() 
    213                                                                         .getOutputStream(); 
    214                                                         // instance of org.apache.commons.vfs.provider.DefaultFileContent$FileContentOutputStream 
    215                                                         // which extends MonitorOutputStream 
    216                                                     // which in turn extends BufferedOutputStream 
    217                                                     // which in turn extends FilterOutputStream. 
    218                                                          
    219                                                         try { 
    220                                                                 java.nio.ByteBuffer bb = ((BinaryPart) part) 
    221                                                                                 .getBuffer(); 
    222                                                                 bb.clear(); 
    223                                                                 byte[] bytes = new byte[bb.capacity()]; 
    224                                                                 bb.get(bytes, 0, bytes.length); 
    225  
    226                                                                 out.write(bytes); 
    227                                                                  
    228                                                                 // Set the attribute 
    229                                                                 String src = fixImgSrcURL(fo); 
    230                                                                 picture.setSrc(src); 
    231                                                                 log.info("Wrote @src='" + src); 
    232                                                                  
    233                                                         } finally { 
    234                                                                 try { 
    235                                                                         fo.close(); 
    236                                                                         // That Closes this file, and its content. 
    237                                                                         // Closing the content in turn 
    238                                                                         // closes any open stream. 
    239                                                                         // out.flush() is unnecessary, since  
    240                                                                         // FilterOutputStream's close() does do flush() first. 
    241                                                                 } catch (IOException ioe) { 
    242                                                                         ioe.printStackTrace(); 
    243                                                                 } 
    244                                                         } 
    245  
    246  
    247                                                 } 
    248  
    249                                         } catch (Exception e) { 
    250                                                 e.printStackTrace(); 
    251                                                 log.error(e); 
    252                                         } 
     184                                         
     185                                        String uri = handlePart(imageDirPath, picture, part); 
     186                                        // Scale it?  Shouldn't be necessary, since Word should 
     187                                        // be providing the height/width 
     188//                                      try { 
     189//                                              ImageInfo imageInfo = BinaryPartAbstractImage.getImageInfo(uri); 
     190//                                               
     191//                                              List<SectionWrapper> sections = wmlPackage.getDocumentModel().getSections(); 
     192//                                              PageDimensions page = sections.get(sections.size()-1).getPageDimensions(); 
     193//                                               
     194//                                              picture.ensureFitsPage(imageInfo, page ); 
     195//                                      } catch (Exception e) { 
     196//                                              e.printStackTrace(); 
     197//                                      } 
    253198 
    254199                                } else { // External 
     
    266211 
    267212                return picture; 
     213        } 
     214 
     215        /** 
     216         * @param imageDirPath 
     217         * @param picture 
     218         * @param part 
     219         * @return uri for the image we've saved, or null 
     220         */ 
     221        private static String handlePart(String imageDirPath, WordXmlPicture picture, 
     222                        Part part) { 
     223                try { 
     224 
     225                        if (imageDirPath.equals("")) { 
     226                                 
     227                                // TODO: this isn't going to work for XSL FO! 
     228                                // So for XSL FO, you always need an imageDirPath!  
     229 
     230                                // <img 
     231                                // src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub/ 
     232                                // 
     233                                // which is nice, except it doesn't work in IE7, 
     234                                // and is limited to 32KB in IE8! 
     235 
     236                                java.nio.ByteBuffer bb = ((BinaryPart) part) 
     237                                                .getBuffer(); 
     238                                bb.clear(); 
     239                                byte[] bytes = new byte[bb.capacity()]; 
     240                                bb.get(bytes, 0, bytes.length); 
     241                                 
     242                                byte[] encoded = Base64.encodeBase64(bytes, true); 
     243 
     244                                picture 
     245                                                .setSrc("data:" + part.getContentType() 
     246                                                                + ";base64," 
     247                                                                + (new String(encoded, "UTF-8"))); 
     248                                 
     249                                return null; 
     250 
     251                        } else { 
     252                                // Need to save the image 
     253 
     254                                // To create directory: 
     255                                FileObject folder = getFileSystemManager() 
     256                                                .resolveFile(imageDirPath); 
     257                                if (!folder.exists()) { 
     258                                        folder.createFolder(); 
     259                                } 
     260 
     261                                // Construct a file name from the part name 
     262                                String partname = part.getPartName().toString(); 
     263                                String filename = partname.substring(partname 
     264                                                .lastIndexOf("/") + 1); 
     265                                log.debug("image file name: " + filename); 
     266 
     267                                FileObject fo = folder.resolveFile(filename); 
     268                                if (fo.exists()) { 
     269 
     270                                        log.warn("Overwriting (!) existing file!"); 
     271 
     272                                } else { 
     273                                        fo.createFile(); 
     274                                } 
     275                                // System.out.println("URL: " + 
     276                                // fo.getURL().toExternalForm() ); 
     277                                // System.out.println("String: " + fo.toString() ); 
     278 
     279                                // Save the file 
     280                                OutputStream out = fo.getContent() 
     281                                                .getOutputStream(); 
     282                                // instance of org.apache.commons.vfs.provider.DefaultFileContent$FileContentOutputStream 
     283                                // which extends MonitorOutputStream 
     284                            // which in turn extends BufferedOutputStream 
     285                            // which in turn extends FilterOutputStream. 
     286                                 
     287                                String src; 
     288                                try { 
     289                                        java.nio.ByteBuffer bb = ((BinaryPart) part) 
     290                                                        .getBuffer(); 
     291                                        bb.clear(); 
     292                                        byte[] bytes = new byte[bb.capacity()]; 
     293                                        bb.get(bytes, 0, bytes.length); 
     294 
     295                                        out.write(bytes); 
     296                                         
     297                                        // Set the attribute 
     298                                        src = fixImgSrcURL(fo); 
     299                                        picture.setSrc(src); 
     300                                        log.info("Wrote @src='" + src); 
     301                                        return src; 
     302                                } finally { 
     303                                        try { 
     304                                                fo.close(); 
     305                                                // That Closes this file, and its content. 
     306                                                // Closing the content in turn 
     307                                                // closes any open stream. 
     308                                                // out.flush() is unnecessary, since  
     309                                                // FilterOutputStream's close() does do flush() first. 
     310                                        } catch (IOException ioe) { 
     311                                                ioe.printStackTrace(); 
     312                                        }                                        
     313                                } 
     314 
     315                        } 
     316 
     317                } catch (Exception e) { 
     318                        e.printStackTrace(); 
     319                        log.error(e); 
     320                } 
     321                return null; 
    268322        } 
    269323 
     
    347401    } 
    348402     
    349     /* Extension function to create an <img> element 
     403    /** Extension function to create an <img> element 
    350404     * from "E1.0 images" 
    351405     *   
    352406     *      //w:pict 
     407     * @param wmlPackage 
     408     * @param imageDirPath 
     409     * @param shape 
     410     * @param imageData 
     411     * @return 
    353412     */ 
    354     public static DocumentFragment createImgE10(WordprocessingMLPackage wmlPackage, 
     413    public static DocumentFragment createHtmlImgE10(WordprocessingMLPackage wmlPackage, 
    355414                String imageDirPath, 
    356415                NodeIterator shape, NodeIterator imageData) { 
    357  
     416         
     417 
     418        WordXmlPicture picture = createWordXmlPictureFromE10( wmlPackage, 
     419                         imageDirPath, 
     420                         shape,  imageData, true); 
     421         
     422        if (picture==null) { 
     423                 
     424            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
     425            Document d; 
     426                        try { 
     427                                d = factory.newDocumentBuilder().newDocument(); 
     428                        return d.createDocumentFragment(); 
     429                        } catch (ParserConfigurationException e) { 
     430                                log.error(e); 
     431                                return null; 
     432                        }   
     433                         
     434        } else { 
     435         
     436                Document d = picture.createHtmlImageElement(); 
     437         
     438                        DocumentFragment docfrag = d.createDocumentFragment(); 
     439                        docfrag.appendChild(d.getDocumentElement()); 
     440         
     441                        return docfrag; 
     442        }         
     443    } 
     444 
     445    /** Extension function to create an <img> element 
     446     * from "E1.0 images" 
     447     *   
     448     *      //w:pict 
     449     * @param wmlPackage 
     450     * @param imageDirPath 
     451     * @param shape 
     452     * @param imageData 
     453     * @return 
     454     */ 
     455    public static DocumentFragment createXslFoImgE10(WordprocessingMLPackage wmlPackage, 
     456                String imageDirPath, 
     457                NodeIterator shape, NodeIterator imageData) { 
     458         
     459 
     460        WordXmlPicture picture = createWordXmlPictureFromE10( wmlPackage, 
     461                         imageDirPath, 
     462                         shape,  imageData, false); 
     463         
     464        if (picture==null) { 
     465                 
     466            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
     467            Document d; 
     468                        try { 
     469                                d = factory.newDocumentBuilder().newDocument(); 
     470                        return d.createDocumentFragment(); 
     471                        } catch (ParserConfigurationException e) { 
     472                                log.error(e); 
     473                                return null; 
     474                        }   
     475                         
     476        } else { 
     477         
     478                Document d = picture.createXslFoImageElement(); 
     479         
     480                        DocumentFragment docfrag = d.createDocumentFragment(); 
     481                        docfrag.appendChild(d.getDocumentElement()); 
     482         
     483                        return docfrag; 
     484        } 
     485    } 
     486     
     487     
     488    private static WordXmlPicture createWordXmlPictureFromE10(WordprocessingMLPackage wmlPackage, 
     489                String imageDirPath, 
     490                NodeIterator shape, NodeIterator imageData, boolean targetIsHtml) { 
     491         
    358492        // Sanity check; though XSLT should check these nodes are non null 
    359493        // before invoking this extension function. 
     
    369503                        || imageDataNode ==null ) { 
    370504                log.error("w:pict contains something other than an image?"); 
    371             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
    372             Document d; 
    373                         try { 
    374                                 d = factory.newDocumentBuilder().newDocument(); 
    375                         return d.createDocumentFragment(); 
    376                         } catch (ParserConfigurationException e) { 
    377                                 log.error(e); 
    378                                 return null; 
    379                         }                
     505                return null; 
    380506        } 
    381507        // OK 
    382508         
    383509        WordXmlPicture picture = new WordXmlPicture(); 
    384         picture.readStandardAttributes( shapeNode );             
    385  
    386         String imgRelId = ConvertUtils.getAttributeValueNS(imageDataNode, "http://schemas.openxmlformats.org/officeDocument/2006/relationships", "id");  
     510        picture.readStandardAttributes( shapeNode, targetIsHtml );       
     511 
     512        String imgRelId = ConvertUtils.getAttributeValueNS(imageDataNode,  
     513                        "http://schemas.openxmlformats.org/officeDocument/2006/relationships", "id");  
    387514 
    388515        if (imgRelId!=null && !imgRelId.equals("")) 
     
    390517                Relationship rel = wmlPackage.getMainDocumentPart().getRelationshipsPart().getRelationshipByID(imgRelId); 
    391518                 
    392                 if (rel.getTargetMode() == null 
    393                                 || rel.getTargetMode().equals("Internal") ) { 
    394                          
    395                         picture.setSrc("TODO - save object " + rel.getTarget() ); 
    396                          
    397                 } else { 
    398                 picture.setSrc( rel.getTarget() );               
    399                 } 
    400  
    401         } 
    402  
    403519            // if the relationship isn't found, produce a warning 
    404520            //if (String.IsNullOrEmpty(picture.Src)) 
     
    406522            //    this.embeddedPicturesDropped++; 
    407523            //} 
    408          
    409         Document d = picture.createHtmlImageElement(); 
    410  
    411                 DocumentFragment docfrag = d.createDocumentFragment(); 
    412                 docfrag.appendChild(d.getDocumentElement()); 
    413  
    414                 return docfrag; 
     524                 
     525                if (rel.getTargetMode() == null 
     526                                || rel.getTargetMode().equals("Internal") ) { 
     527                         
     528                        BinaryPartAbstractImage part = (BinaryPartAbstractImage)wmlPackage.getMainDocumentPart() 
     529                                        .getRelationshipsPart().getPart(rel); 
     530                                String uri = handlePart(imageDirPath, picture, part); 
     531                                 
     532                                // Scale it?  Shouldn't be necessary, since Word should 
     533                                // be providing the height/width 
     534//                              try { 
     535//                                      ImageInfo imageInfo = BinaryPartAbstractImage.getImageInfo(uri); 
     536//                                       
     537//                                      List<SectionWrapper> sections = wmlPackage.getDocumentModel().getSections(); 
     538//                                      PageDimensions page = sections.get(sections.size()-1).getPageDimensions(); 
     539//                                       
     540//                                      picture.ensureFitsPage(imageInfo, page ); 
     541//                              } catch (Exception e) { 
     542//                                      e.printStackTrace(); 
     543//                              } 
     544                                 
     545                         
     546                } else { 
     547                picture.setSrc( rel.getTarget() );               
     548                } 
     549 
     550        } 
    415551         
    416     } 
     552        return picture; 
     553    }   
    417554     
    418555     
     556//    /** 
     557//     * If the docx does not explicitly size the 
     558//     * image, check that it will fit on the page  
     559//     */ 
     560//    private void ensureFitsPage(ImageInfo imageInfo, PageDimensions page) { 
     561// 
     562//       
     563//      CxCy cxcy = BinaryPartAbstractImage.CxCy.scale(imageInfo, page);     
     564//       
     565//      if (cxcy.isScaled() ) { 
     566//              log.info("Scaled to fit page width"); 
     567//              this.setWidth( Math.round(cxcy.getCx()/extentToPixelConversionFactor) ); 
     568//              this.setHeight( Math.round(cxcy.getCy()/extentToPixelConversionFactor) );     
     569//              // That gives pixels, which is ok for HTML, but for XSL FO, we want pt or mm etc 
     570//      } 
     571//       
     572//    } 
    419573         
    420574        void setAttribute(String name, String value) { 
     
    509663    } 
    510664 
    511         public Document createXslFoImageElement() 
     665        private Document createXslFoImageElement() 
    512666    { 
    513667 
     
    543697            if (widthSet) 
    544698            { 
    545                 setAttribute("content-width",  Integer.toString(width)); 
     699                setAttribute("content-width",  Integer.toString(width)+units); 
    546700            } 
    547701 
    548702            if (heightSet) 
    549703            { 
    550                 setAttribute("content-height", Integer.toString(height)); 
     704                setAttribute("content-height", Integer.toString(height)+units); 
    551705            } 
    552706// 
     
    583737    } 
    584738         
     739        String units = ""; 
     740         
    585741    /// <id guid="233b126d-66d0-476e-bcd1-ce30bdc3e65b" /> 
    586742    /// <owner alias="ROrleth" /> 
    587     public void readStandardAttributes(Node fromNode) 
     743    public void readStandardAttributes(Node fromNode, boolean targetIsHtml) 
    588744    { 
    589745        this.id = ConvertUtils.getAttributeValue(fromNode, "id"); 
     
    591747        this.alt = ConvertUtils.getAttributeValue(fromNode, "alt"); 
    592748        this.style = ConvertUtils.getAttributeValue(fromNode, "style"); 
    593     } 
     749 
     750        // E10: <v:shape style="width:428.25pt;height:321pt" 
     751        // hmm, don't want a whole CSS parser just for this.. 
     752        // But if we did, it would be something like 
     753                // CSSStyleDeclaration cssStyleDeclaration = = cssOMParser.parseStyleDeclaration( 
     754                //                      new org.w3c.css.sac.InputSource(new StringReader(styleVal)) ); 
     755 
     756            if (style.lastIndexOf("width")>=0) { 
     757                setWidth( getStyleVal("width",targetIsHtml)); 
     758            } 
     759            if (style.lastIndexOf("height")>=0) { 
     760                setHeight( getStyleVal("height",targetIsHtml)); 
     761            } 
     762    } 
     763     
     764    private int getStyleVal(String name, boolean targetIsHtml) { 
     765         
     766        // Assumptions: 1, the named attribute is present 
     767        //if (style.lastIndexOf(name)<0) return 0; 
     768         
     769        // Assumptions: 2, the dimension is given in pt  
     770         
     771        // E10: <v:shape style="width:428.25pt;height:321pt" 
     772        log.debug(style); 
     773 
     774        int beginIndex = style.indexOf(name) + name.length()+1; // +1 for the ':' 
     775        int endIndex = style.indexOf("pt", beginIndex); 
     776         
     777        String val = style.substring(beginIndex, endIndex); 
     778         
     779         
     780        float f = Float.parseFloat(val); 
     781         
     782        // 72 points per inch 
     783        // so, assuming 72 pdi, there is 1 point per pixel 
     784        // so no further conversion is necessary 
     785        // All we need to do is set the units for XSL FO 
     786        if (!targetIsHtml) { 
     787                units="pt";      
     788        } 
     789         
     790        return Math.round(f); 
     791         
     792         
     793    } 
     794     
    594795 
    595796    /// <id guid="048da999-6fbe-41b9-9639-de0e084f3da3" /> 
  • trunk/docx4j/src/main/java/org/docx4j/model/properties/paragraph/NumberingProperty.java

    r977 r979  
    4141        @Override 
    4242        public String getCssProperty() { 
    43                 throw new RuntimeException("Not implemented"); 
     43                 
     44                // Currently, numbering in HTML NG2 is handled via an extension function 
     45                // directly from the XSLT.  
     46                return ""; 
     47                //throw new RuntimeException("Not implemented"); 
    4448                 
    4549        } 
  • trunk/docx4j/src/main/java/org/docx4j/model/properties/run/Font.java

    r942 r979  
    8686                } 
    8787                 
    88                  
    89                 PhysicalFont pf = wmlPackage.getFontMapper().getFontMappings().get(font); 
    90                 if (pf!=null) { 
    91                         log.debug("Font '" + font + "' maps to " + pf.getName() ); 
    92                         return pf.getName(); 
    93                 } else { 
    94                         log.warn("Font '" + font + "' is not mapped to a physical font. " );                     
    95                         return null; 
    96                 } 
     88                return getPhysicalFont(wmlPackage, font); 
    9789                 
    9890        } 
    9991 
     92        public static String getPhysicalFont(WordprocessingMLPackage wmlPackage, String fontName) { 
     93 
     94                PhysicalFont pf = wmlPackage.getFontMapper().getFontMappings().get(fontName); 
     95                if (pf!=null) { 
     96                        log.debug("Font '" + fontName + "' maps to " + pf.getName() ); 
     97                        return pf.getName(); 
     98                } else { 
     99                        log.warn("Font '" + fontName + "' is not mapped to a physical font. " );                         
     100                        return null; 
     101                }                
     102        }        
     103         
    100104        @Override 
    101105        public void setXslFO(Element foElement) { 
     
    108112                 
    109113        } 
     114                 
    110115 
    111116        @Override 
     
    114119        } 
    115120         
     121         
    116122} 
  • trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java

    r967 r979  
    121121                int last = getDocumentModel().getSections().size(); 
    122122                if (last>0) { 
     123                        // Should always be the case, since we add one, 
     124                        // even if the document contains no sectPr 
    123125                        return getDocumentModel().getSections().get(last-1).getHeaderFooterPolicy(); 
    124126                } else { 
     127                        log.error("Unexpected - zero sections?!"); 
    125128                        return null; 
    126129                } 
Note: See TracChangeset for help on using the changeset viewer.