compact HTML output of WordToHtmlConverter
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1148269 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1ba8c3e781
commit
92e5199a95
@ -160,6 +160,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
|
||||
public Document getDocument()
|
||||
{
|
||||
htmlDocumentFacade.updateStylesheet();
|
||||
return htmlDocumentFacade.getDocument();
|
||||
}
|
||||
|
||||
@ -182,7 +183,7 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
}
|
||||
if ( characterRun.getFontSize() / 2 != blockProperies.pFontSize )
|
||||
{
|
||||
style.append( "font-size: " + characterRun.getFontSize() / 2 + "; " );
|
||||
style.append( "font-size:" + characterRun.getFontSize() / 2 + "pt;" );
|
||||
}
|
||||
if ( triplet.bold )
|
||||
{
|
||||
@ -195,7 +196,8 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
|
||||
WordToHtmlUtils.addCharactersProperties( characterRun, style );
|
||||
if ( style.length() != 0 )
|
||||
span.setAttribute( "style", style.toString() );
|
||||
span.setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
|
||||
span.getTagName(), "s", style.toString() ) );
|
||||
|
||||
Text textNode = htmlDocumentFacade.createText( text );
|
||||
span.appendChild( textNode );
|
||||
@ -312,22 +314,28 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
float visibleHeight = Math.max( 0, imageHeight - cropTop
|
||||
- cropBottom );
|
||||
|
||||
root = htmlDocumentFacade.document.createElement( "div" );
|
||||
root.setAttribute( "style", "vertical-align:text-bottom;width:"
|
||||
+ visibleWidth + "in;height:" + visibleHeight + "in;" );
|
||||
root = htmlDocumentFacade.createBlock();
|
||||
root.setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
|
||||
root.getTagName(), "d", "vertical-align:text-bottom;width:"
|
||||
+ visibleWidth + "in;height:" + visibleHeight
|
||||
+ "in;" ) );
|
||||
|
||||
// complex
|
||||
Element inner = htmlDocumentFacade.document.createElement( "div" );
|
||||
inner.setAttribute( "style", "position:relative;width:"
|
||||
+ visibleWidth + "in;height:" + visibleHeight
|
||||
+ "in;overflow:hidden;" );
|
||||
Element inner = htmlDocumentFacade.createBlock();
|
||||
inner.setAttribute( "class", htmlDocumentFacade
|
||||
.getOrCreateCssClass( inner.getTagName(), "d",
|
||||
"position:relative;width:" + visibleWidth
|
||||
+ "in;height:" + visibleHeight
|
||||
+ "in;overflow:hidden;" ) );
|
||||
root.appendChild( inner );
|
||||
|
||||
Element image = htmlDocumentFacade.document.createElement( "img" );
|
||||
image.setAttribute( "src", imageSourcePath );
|
||||
image.setAttribute( "style", "position:absolute;left:-" + cropLeft
|
||||
+ ";top:-" + cropTop + ";width:" + imageWidth
|
||||
+ "in;height:" + imageHeight + "in;" );
|
||||
image.setAttribute( "class", htmlDocumentFacade
|
||||
.getOrCreateCssClass( image.getTagName(), "i",
|
||||
"position:absolute;left:-" + cropLeft + ";top:-"
|
||||
+ cropTop + ";width:" + imageWidth
|
||||
+ "in;height:" + imageHeight + "in;" ) );
|
||||
inner.appendChild( image );
|
||||
|
||||
style.append( "overflow:hidden;" );
|
||||
@ -414,7 +422,10 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
}
|
||||
|
||||
if ( style.length() > 0 )
|
||||
pElement.setAttribute( "style", style.toString() );
|
||||
pElement.setAttribute(
|
||||
"class",
|
||||
htmlDocumentFacade.getOrCreateCssClass(
|
||||
pElement.getTagName(), "p", style.toString() ) );
|
||||
|
||||
return;
|
||||
}
|
||||
@ -422,8 +433,9 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
protected void processSection( HWPFDocumentCore wordDocument,
|
||||
Section section, int sectionCounter )
|
||||
{
|
||||
Element div = htmlDocumentFacade.document.createElement( "div" );
|
||||
div.setAttribute( "style", getSectionStyle( section ) );
|
||||
Element div = htmlDocumentFacade.createBlock();
|
||||
div.setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
|
||||
div.getTagName(), "d", getSectionStyle( section ) ) );
|
||||
htmlDocumentFacade.body.appendChild( div );
|
||||
|
||||
processSectionParagraphes( wordDocument, div, section,
|
||||
@ -434,8 +446,9 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
protected void processSingleSection( HWPFDocumentCore wordDocument,
|
||||
Section section )
|
||||
{
|
||||
htmlDocumentFacade.body.setAttribute( "style",
|
||||
getSectionStyle( section ) );
|
||||
htmlDocumentFacade.body
|
||||
.setAttribute( "class", htmlDocumentFacade.getOrCreateCssClass(
|
||||
"body", "b", getSectionStyle( section ) ) );
|
||||
|
||||
processSectionParagraphes( wordDocument, htmlDocumentFacade.body,
|
||||
section, Integer.MIN_VALUE );
|
||||
@ -538,15 +551,19 @@ public class WordToHtmlConverter extends AbstractWordConverter
|
||||
.createParagraph() );
|
||||
}
|
||||
if ( tableCellStyle.length() > 0 )
|
||||
tableCellElement.setAttribute( "style",
|
||||
tableCellStyle.toString() );
|
||||
tableCellElement.setAttribute( "class", htmlDocumentFacade
|
||||
.getOrCreateCssClass(
|
||||
tableCellElement.getTagName(),
|
||||
tableCellElement.getTagName(),
|
||||
tableCellStyle.toString() ) );
|
||||
|
||||
tableRowElement.appendChild( tableCellElement );
|
||||
}
|
||||
|
||||
if ( tableRowStyle.length() > 0 )
|
||||
tableRowElement
|
||||
.setAttribute( "style", tableRowStyle.toString() );
|
||||
tableRowElement.setAttribute( "class", htmlDocumentFacade
|
||||
.getOrCreateCssClass( "tr", "r",
|
||||
tableRowStyle.toString() ) );
|
||||
|
||||
if ( tableRow.isTableHeader() )
|
||||
{
|
||||
|
@ -37,21 +37,21 @@ public class WordToHtmlUtils extends AbstractWordUtils
|
||||
|
||||
if ( isEmpty( where ) )
|
||||
{
|
||||
style.append( "border-style: " + getBorderType( borderCode ) + "; " );
|
||||
style.append( "border-color: " + getColor( borderCode.getColor() )
|
||||
+ "; " );
|
||||
style.append( "border-width: " + getBorderWidth( borderCode )
|
||||
+ "; " );
|
||||
style.append( "border:" );
|
||||
}
|
||||
else
|
||||
{
|
||||
style.append( "border-" + where + "-style: "
|
||||
+ getBorderType( borderCode ) + "; " );
|
||||
style.append( "border-" + where + "-color: "
|
||||
+ getColor( borderCode.getColor() ) + "; " );
|
||||
style.append( "border-" + where + "-width: "
|
||||
+ getBorderWidth( borderCode ) + "; " );
|
||||
style.append( "border-" );
|
||||
style.append( where );
|
||||
}
|
||||
|
||||
style.append( ":" );
|
||||
style.append( getBorderWidth( borderCode ) );
|
||||
style.append( ' ' );
|
||||
style.append( getBorderType( borderCode ) );
|
||||
style.append( ' ' );
|
||||
style.append( getColor( borderCode.getColor() ) );
|
||||
style.append( ';' );
|
||||
}
|
||||
|
||||
public static void addCharactersProperties(
|
||||
|
@ -92,7 +92,7 @@ public class TestWordToHtmlConverter extends TestCase
|
||||
public void testAIOOBTap() throws Exception
|
||||
{
|
||||
String result = getHtmlText( "AIOOB-Tap.doc" );
|
||||
assertContains( result.substring( 0, 2000 ), "<table>" );
|
||||
assertContains( result.substring( 0, 6000 ), "<table>" );
|
||||
}
|
||||
|
||||
public void testBug33519() throws Exception
|
||||
|
Loading…
Reference in New Issue
Block a user