From 92381ae7d8f4d51eda923fbd540533fa40ffcdf8 Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Tue, 12 Jul 2011 14:40:06 +0000 Subject: [PATCH] add line breaks (0xb) support git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1145609 13f79535-47bb-0310-9956-ffa450edef68 --- .../hwpf/converter/AbstractWordConverter.java | 29 ++++++++++++++++++- .../hwpf/converter/HtmlDocumentFacade.java | 5 ++++ .../poi/hwpf/converter/WordToFoConverter.java | 6 ++++ .../hwpf/converter/WordToHtmlConverter.java | 6 ++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java index 2f740f513..64494a9c8 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java @@ -155,7 +155,31 @@ public abstract class AbstractWordConverter || ( text.charAt( text.length() - 1 ) == BEL_MARK && currentTableLevel != 0 ) ) text = text.substring( 0, text.length() - 1 ); - outputCharacters( block, characterRun, text ); + { + // line breaks + StringBuilder stringBuilder = new StringBuilder(); + for ( char charChar : text.toCharArray() ) + { + if ( charChar == 11 ) + { + if ( stringBuilder.length() > 0 ) + { + outputCharacters( block, characterRun, stringBuilder.toString() ); + stringBuilder.setLength( 0 ); + } + processLineBreak(block, characterRun); + } + else + { + stringBuilder.append( charChar ); + } + } + if ( stringBuilder.length() > 0 ) + { + outputCharacters( block, characterRun, stringBuilder.toString() ); + stringBuilder.setLength( 0 ); + } + } haveAnyText |= text.trim().length() != 0; } @@ -293,6 +317,9 @@ public abstract class AbstractWordConverter protected abstract void processImage( Element currentBlock, boolean inlined, Picture picture ); + protected abstract void processLineBreak( Element block, + CharacterRun characterRun ); + protected abstract void processPageref( HWPFDocumentCore wordDocument, Element currentBlock, Range textRange, int currentTableLevel, String pageref ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java index 186f037a5..d43fd4494 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java @@ -82,6 +82,11 @@ public class HtmlDocumentFacade return basicLink; } + public Element createLineBreak() + { + return document.createElement( "br" ); + } + public Element createListItem() { return document.createElement( "li" ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java index e1f47d738..7d118dbca 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java @@ -294,6 +294,12 @@ public class WordToFoConverter extends AbstractWordConverter + "' can be here" ) ); } + @Override + protected void processLineBreak( Element block, CharacterRun characterRun ) + { + block.appendChild( foDocumentFacade.createBlock() ); + } + protected void processPageref( HWPFDocumentCore hwpfDocument, Element currentBlock, Range textRange, int currentTableLevel, String pageref ) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java index 4c8e03f29..5daf0375b 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java @@ -251,6 +251,12 @@ public class WordToHtmlConverter extends AbstractWordConverter basicLink ); } + @Override + protected void processLineBreak( Element block, CharacterRun characterRun ) + { + block.appendChild( htmlDocumentFacade.createLineBreak() ); + } + /** * This method shall store image bytes in external file and convert it if * necessary. Images shall be stored using PNG format. Other formats may be