Changeset 979
- Timestamp:
- 12/14/09 16:43:16 (2 years ago)
- Location:
- trunk/docx4j/src/main/java/org/docx4j
- Files:
-
- 3 added
- 12 edited
-
convert/out/Converter.java (modified) (2 diffs)
-
convert/out/ModelConverter.java (modified) (3 diffs)
-
convert/out/html/DocX2Html.xslt (modified) (1 diff)
-
convert/out/html/HtmlExporterNG.java (modified) (5 diffs)
-
convert/out/html/HtmlExporterNG2.java (modified) (1 diff)
-
convert/out/html/SymbolWriter.java (added)
-
convert/out/html/docx2xhtmlNG2.xslt (modified) (4 diffs)
-
convert/out/pdf/viaXSLFO/Conversion.java (modified) (3 diffs)
-
convert/out/pdf/viaXSLFO/SymbolWriter.java (added)
-
convert/out/pdf/viaXSLFO/docx2fo.xslt (modified) (3 diffs)
-
model/SymbolModel.java (added)
-
model/images/WordXmlPicture.java (modified) (18 diffs)
-
model/properties/paragraph/NumberingProperty.java (modified) (1 diff)
-
model/properties/run/Font.java (modified) (3 diffs)
-
openpackaging/packages/WordprocessingMLPackage.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/docx4j/src/main/java/org/docx4j/convert/out/Converter.java
r960 r979 31 31 import org.docx4j.XmlUtils; 32 32 import org.docx4j.model.Model; 33 import org.docx4j.model.SymbolModel; 33 34 import org.docx4j.model.TransformState; 34 35 import org.docx4j.model.table.TableModel; … … 85 86 modelClasses = new HashMap<String, Class>(); 86 87 modelClasses.put("w:tbl", TableModel.class); 88 modelClasses.put("w:sym", SymbolModel.class); 87 89 // modelClasses.put("w:p", ParagraphModel.class); 88 90 // modelClasses.put("w:t", TextModel.class); -
trunk/docx4j/src/main/java/org/docx4j/convert/out/ModelConverter.java
r960 r979 27 27 import org.w3c.dom.Node; 28 28 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 */ 29 37 public abstract class ModelConverter { 30 38 … … 32 40 public void setWordMLPackage(WordprocessingMLPackage wordMLPackage) { 33 41 this.wordMLPackage = wordMLPackage; 42 } 43 /** 44 * @return the wordMLPackage 45 */ 46 public WordprocessingMLPackage getWordMLPackage() { 47 return wordMLPackage; 34 48 } 35 49 … … 52 66 public abstract Node toNode(Model m, TransformState state) throws TransformerException; 53 67 68 54 69 } -
trunk/docx4j/src/main/java/org/docx4j/convert/out/html/DocX2Html.xslt
r943 r979 3365 3365 <xsl:variable name="imageData" select="./v:shape/v:imagedata"/> 3366 3366 3367 <xsl:copy-of select="java:org.docx4j.model.images.WordXmlPicture.create ImgE10( $wmlPackage, string($imageDirPath),3367 <xsl:copy-of select="java:org.docx4j.model.images.WordXmlPicture.createHtmlImgE10( $wmlPackage, string($imageDirPath), 3368 3368 $shape, $imageData)" /> 3369 3369 </xsl:when> -
trunk/docx4j/src/main/java/org/docx4j/convert/out/html/HtmlExporterNG.java
r961 r979 2 2 3 3 import java.io.IOException; 4 import java.io.OutputStream;5 import java.math.BigInteger;6 4 import java.util.HashMap; 7 5 import java.util.Iterator; 8 6 import java.util.List; 9 7 import 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 16 9 import javax.xml.bind.Unmarshaller; 17 10 import javax.xml.parsers.DocumentBuilderFactory; 18 import javax.xml.parsers.ParserConfigurationException;19 11 import javax.xml.transform.Source; 20 12 import javax.xml.transform.Templates; … … 22 14 import javax.xml.transform.stream.StreamSource; 23 15 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;29 16 import org.apache.log4j.Logger; 30 17 import org.apache.xml.dtm.ref.DTMNodeProxy; 31 18 import org.docx4j.XmlUtils; 32 19 import 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; 20 import org.docx4j.convert.out.html.SymbolWriter; 37 21 import org.docx4j.fonts.IdentityPlusMapper; 38 import org.docx4j.fonts.PhysicalFont;39 22 import org.docx4j.jaxb.Context; 40 23 import org.docx4j.model.PropertyResolver; 41 24 import org.docx4j.model.TransformState; 42 import org.docx4j.model.listnumbering.Emulator; 43 import org.docx4j.model.listnumbering.Emulator.ResultTriple; 25 import org.docx4j.model.SymbolModel.SymbolModelTransformState; 44 26 import org.docx4j.model.properties.Property; 45 27 import org.docx4j.model.properties.PropertyFactory; … … 47 29 import org.docx4j.openpackaging.exceptions.Docx4JException; 48 30 import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 49 import org.docx4j.relationships.Relationship;50 31 import org.docx4j.wml.CTTblPrBase; 51 32 import org.docx4j.wml.CTTblStylePr; 52 33 import org.docx4j.wml.PPr; 53 import org.docx4j.wml.RFonts;54 34 import org.docx4j.wml.RPr; 55 35 import org.docx4j.wml.Style; 56 import org.docx4j.wml.Tbl;57 import org.docx4j.wml.Tc;58 36 import org.docx4j.wml.TcPr; 59 import org.docx4j.wml.Tr;60 37 import 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;67 38 import org.w3c.dom.Document; 68 39 import org.w3c.dom.DocumentFragment; 69 40 import org.w3c.dom.Element; 70 41 import org.w3c.dom.Node; 71 import org.w3c.dom.NodeList;72 42 import org.w3c.dom.Text; 43 import org.w3c.dom.traversal.NodeIterator; 73 44 74 45 /** … … 144 115 145 116 146 @Deprecated147 117 public void output(javax.xml.transform.Result result) throws Docx4JException { 148 118 … … 247 217 //Converter c = new Converter(); 248 218 Converter.getInstance().registerModelConverter("w:tbl", new TableWriter() ); 219 Converter.getInstance().registerModelConverter("w:sym", new SymbolWriter() ); 249 220 250 221 // By convention, the transform state object is stored by reference to the 251 222 // type of element to which its model applies 252 223 modelStates.put("w:tbl", new TableModelTransformState() ); 224 modelStates.put("w:sym", new SymbolModelTransformState() ); 253 225 254 226 Converter.getInstance().start(wmlPackage); -
trunk/docx4j/src/main/java/org/docx4j/convert/out/html/HtmlExporterNG2.java
r963 r979 578 578 String rStyleVal = rPr.getRStyle().getVal(); 579 579 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 } 584 588 } 585 589 -
trunk/docx4j/src/main/java/org/docx4j/convert/out/html/docx2xhtmlNG2.xslt
r977 r979 271 271 272 272 273 <xsl:template match="w:br[@w:type = 'page']">274 <!-- TODO -->275 </xsl:template>276 273 277 274 <xsl:template match="w:lastRenderedPageBreak" /> 278 275 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>­</xsl:text> 381 </xsl:template> 382 383 <xsl:template match="w:noBreakHyphen"> 384 <xsl:text disable-output-escaping="yes">&#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"> </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 279 458 <!-- 280 459 … … 289 468 --> 290 469 <xsl:template match="w:hyperlink"> 291 <a style="text-decoration:none;">470 <a> 292 471 <xsl:variable name="relId"><xsl:value-of select="string(@r:id)"/></xsl:variable> 293 472 … … 331 510 </a> 332 511 </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 411 512 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 412 523 <xsl:template match="*"> 413 524 <div … … 418 529 </xsl:template> 419 530 420 <xsl:template match="w:proofErr" />421 422 <xsl:template match="w:softHyphen">423 <xsl:text>­</xsl:text>424 </xsl:template>425 426 <xsl:template match="w:noBreakHyphen">427 <xsl:text disable-output-escaping="yes">&#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 447 531 </xsl:stylesheet> -
trunk/docx4j/src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/Conversion.java
r977 r979 32 32 import org.docx4j.model.PropertyResolver; 33 33 import org.docx4j.model.TransformState; 34 import org.docx4j.model.SymbolModel.SymbolModelTransformState; 34 35 import org.docx4j.model.listnumbering.Emulator.ResultTriple; 35 36 import org.docx4j.model.properties.Property; … … 264 265 // Converter c = new Converter(); 265 266 Converter.getInstance().registerModelConverter("w:tbl", new TableWriter() ); 267 Converter.getInstance().registerModelConverter("w:sym", new SymbolWriter() ); 266 268 267 269 // By convention, the transform state object is stored by reference to the 268 270 // type of element to which its model applies 269 271 modelStates.put("w:tbl", new TableModelTransformState() ); 272 modelStates.put("w:sym", new SymbolModelTransformState() ); 270 273 271 274 Converter.getInstance().start(wordMLPackage); … … 632 635 633 636 } 634 637 635 638 } 636 639 -
trunk/docx4j/src/main/java/org/docx4j/convert/out/pdf/viaXSLFO/docx2fo.xslt
r977 r979 450 450 </xsl:template> 451 451 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 466 453 467 454 <xsl:template match="w:lastRenderedPageBreak" /> … … 486 473 487 474 </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 489 495 490 496 <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> … … 561 567 </xsl:when> 562 568 <xsl:otherwise> 563 <fo:block />569 <fo:block white-space-treatment="preserve"> </fo:block> 564 570 </xsl:otherwise> 565 571 </xsl:choose> 566 572 </xsl:template> 567 573 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"> </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> 568 702 569 703 </xsl:stylesheet> -
trunk/docx4j/src/main/java/org/docx4j/model/images/WordXmlPicture.java
r943 r979 4 4 import java.io.IOException; 5 5 import java.io.OutputStream; 6 import java.io.StringReader; 7 import java.util.List; 6 8 import java.util.concurrent.locks.ReadWriteLock; 7 9 import java.util.concurrent.locks.ReentrantReadWriteLock; … … 17 19 import org.apache.commons.vfs.impl.StandardFileSystemManager; 18 20 import org.apache.log4j.Logger; 21 import org.apache.xmlgraphics.image.loader.ImageInfo; 19 22 import org.docx4j.convert.out.ConvertUtils; 23 import org.docx4j.model.structure.DocumentModel; 24 import org.docx4j.model.structure.PageDimensions; 25 import org.docx4j.model.structure.SectionWrapper; 20 26 import org.docx4j.openpackaging.packages.WordprocessingMLPackage; 21 27 import org.docx4j.openpackaging.parts.Part; 22 28 import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart; 29 import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage; 30 import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.CxCy; 23 31 import org.docx4j.relationships.Relationship; 32 import org.docx4j.wml.SectPr; 24 33 import org.w3c.dom.Document; 25 34 import org.w3c.dom.DocumentFragment; 26 35 import org.w3c.dom.Node; 36 import org.w3c.dom.css.CSSPrimitiveValue; 37 import org.w3c.dom.css.CSSStyleDeclaration; 27 38 import org.w3c.dom.traversal.NodeIterator; 28 39 … … 48 59 Node linkElement = null; 49 60 50 /* Extension function to create an HTML <img> element61 /** Extension function to create an HTML <img> element 51 62 * from "E2.0 images" 52 63 * //w:drawing/wp:inline 53 64 * |//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 */ 55 73 public static DocumentFragment createHtmlImgE20(WordprocessingMLPackage wmlPackage, 56 74 String imageDirPath, … … 58 76 NodeIterator picLink, NodeIterator linkData) { 59 77 60 WordXmlPicture picture = createWordXmlPicture ( wmlPackage,78 WordXmlPicture picture = createWordXmlPictureFromE20( wmlPackage, 61 79 imageDirPath, pictureData, picSize, 62 picLink, linkData );80 picLink, linkData, true); 63 81 64 82 Document d = picture.createHtmlImageElement(); … … 70 88 } 71 89 72 /* Extension function to create an XSL FO <fo:external-graphic> element90 /** Extension function to create an XSL FO <fo:external-graphic> element 73 91 * from "E2.0 images" 74 92 * //w:drawing/wp:inline 75 93 * |//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 */ 77 102 public static DocumentFragment createXslFoImgE20(WordprocessingMLPackage wmlPackage, 78 103 String imageDirPath, … … 80 105 NodeIterator picLink, NodeIterator linkData) { 81 106 82 WordXmlPicture picture = createWordXmlPicture ( wmlPackage,107 WordXmlPicture picture = createWordXmlPictureFromE20( wmlPackage, 83 108 imageDirPath, pictureData, picSize, 84 picLink, linkData );109 picLink, linkData, false); 85 110 86 111 Document d = picture.createXslFoImageElement(); … … 101 126 * @return 102 127 */ 103 p ublic static WordXmlPicture createWordXmlPicture(WordprocessingMLPackage wmlPackage,128 private static WordXmlPicture createWordXmlPictureFromE20(WordprocessingMLPackage wmlPackage, 104 129 String imageDirPath, 105 130 NodeIterator pictureData, NodeIterator picSize, 106 NodeIterator picLink, NodeIterator linkData ) {131 NodeIterator picLink, NodeIterator linkData, boolean targetIsHtml) { 107 132 108 133 … … 111 136 112 137 WordXmlPicture picture = new WordXmlPicture(); 113 picture.readStandardAttributes( pictureData.nextNode() );138 picture.readStandardAttributes( pictureData.nextNode(), targetIsHtml ); 114 139 115 140 Node picSizeNode = picSize.nextNode(); … … 155 180 || rel.getTargetMode().equals("Internal")) { 156 181 157 // Get the part 158 Part part = wmlPackage.getMainDocumentPart() 182 BinaryPartAbstractImage part = (BinaryPartAbstractImage)wmlPackage.getMainDocumentPart() 159 183 .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 // } 253 198 254 199 } else { // External … … 266 211 267 212 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; 268 322 } 269 323 … … 347 401 } 348 402 349 /* Extension function to create an <img> element403 /** Extension function to create an <img> element 350 404 * from "E1.0 images" 351 405 * 352 406 * //w:pict 407 * @param wmlPackage 408 * @param imageDirPath 409 * @param shape 410 * @param imageData 411 * @return 353 412 */ 354 public static DocumentFragment create ImgE10(WordprocessingMLPackage wmlPackage,413 public static DocumentFragment createHtmlImgE10(WordprocessingMLPackage wmlPackage, 355 414 String imageDirPath, 356 415 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 358 492 // Sanity check; though XSLT should check these nodes are non null 359 493 // before invoking this extension function. … … 369 503 || imageDataNode ==null ) { 370 504 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; 380 506 } 381 507 // OK 382 508 383 509 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"); 387 514 388 515 if (imgRelId!=null && !imgRelId.equals("")) … … 390 517 Relationship rel = wmlPackage.getMainDocumentPart().getRelationshipsPart().getRelationshipByID(imgRelId); 391 518 392 if (rel.getTargetMode() == null393 || 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 403 519 // if the relationship isn't found, produce a warning 404 520 //if (String.IsNullOrEmpty(picture.Src)) … … 406 522 // this.embeddedPicturesDropped++; 407 523 //} 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 } 415 551 416 } 552 return picture; 553 } 417 554 418 555 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 // } 419 573 420 574 void setAttribute(String name, String value) { … … 509 663 } 510 664 511 p ublicDocument createXslFoImageElement()665 private Document createXslFoImageElement() 512 666 { 513 667 … … 543 697 if (widthSet) 544 698 { 545 setAttribute("content-width", Integer.toString(width) );699 setAttribute("content-width", Integer.toString(width)+units); 546 700 } 547 701 548 702 if (heightSet) 549 703 { 550 setAttribute("content-height", Integer.toString(height) );704 setAttribute("content-height", Integer.toString(height)+units); 551 705 } 552 706 // … … 583 737 } 584 738 739 String units = ""; 740 585 741 /// <id guid="233b126d-66d0-476e-bcd1-ce30bdc3e65b" /> 586 742 /// <owner alias="ROrleth" /> 587 public void readStandardAttributes(Node fromNode )743 public void readStandardAttributes(Node fromNode, boolean targetIsHtml) 588 744 { 589 745 this.id = ConvertUtils.getAttributeValue(fromNode, "id"); … … 591 747 this.alt = ConvertUtils.getAttributeValue(fromNode, "alt"); 592 748 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 594 795 595 796 /// <id guid="048da999-6fbe-41b9-9639-de0e084f3da3" /> -
trunk/docx4j/src/main/java/org/docx4j/model/properties/paragraph/NumberingProperty.java
r977 r979 41 41 @Override 42 42 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"); 44 48 45 49 } -
trunk/docx4j/src/main/java/org/docx4j/model/properties/run/Font.java
r942 r979 86 86 } 87 87 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); 97 89 98 90 } 99 91 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 100 104 @Override 101 105 public void setXslFO(Element foElement) { … … 108 112 109 113 } 114 110 115 111 116 @Override … … 114 119 } 115 120 121 116 122 } -
trunk/docx4j/src/main/java/org/docx4j/openpackaging/packages/WordprocessingMLPackage.java
r967 r979 121 121 int last = getDocumentModel().getSections().size(); 122 122 if (last>0) { 123 // Should always be the case, since we add one, 124 // even if the document contains no sectPr 123 125 return getDocumentModel().getSections().get(last-1).getHeaderFooterPolicy(); 124 126 } else { 127 log.error("Unexpected - zero sections?!"); 125 128 return null; 126 129 }
Note: See TracChangeset
for help on using the changeset viewer.
