From: Sergey Vladimirov Date: Mon, 25 Jul 2011 09:02:01 +0000 (+0000) Subject: do not use block-inline property compactization in FO (result is a target to automate... X-Git-Tag: REL_3_8_BETA4~83 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ef5deef488b5b042768d54e5b2c9af8babdd4102;p=poi.git do not use block-inline property compactization in FO (result is a target to automate processing anyway) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1150596 13f79535-47bb-0310-9956-ffa450edef68 --- 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 d2aa9e5308..08bdcdaebf 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import java.util.Stack; import java.util.concurrent.atomic.AtomicInteger; import javax.xml.parsers.DocumentBuilderFactory; @@ -57,28 +56,6 @@ import org.w3c.dom.Text; public class WordToFoConverter extends AbstractWordConverter { - /** - * Holds properties values, applied to current fo:block element. - * Those properties shall not be doubled in children fo:inline - * elements. - */ - private static class BlockProperies - { - final boolean pBold; - final String pFontName; - final int pFontSize; - final boolean pItalic; - - public BlockProperies( String pFontName, int pFontSize, boolean pBold, - boolean pItalic ) - { - this.pFontName = pFontName; - this.pFontSize = pFontSize; - this.pBold = pBold; - this.pItalic = pItalic; - } - } - private static final POILogger logger = POILogFactory .getLogger( WordToFoConverter.class ); @@ -133,8 +110,6 @@ public class WordToFoConverter extends AbstractWordConverter return wordToFoConverter.getDocument(); } - private final Stack blocksProperies = new Stack(); - private List endnotes = new ArrayList( 0 ); protected final FoDocumentFacade foDocumentFacade; @@ -228,29 +203,15 @@ public class WordToFoConverter extends AbstractWordConverter protected void outputCharacters( Element block, CharacterRun characterRun, String text ) { - BlockProperies blockProperies = this.blocksProperies.peek(); Element inline = foDocumentFacade.createInline(); Triplet triplet = getCharacterRunTriplet( characterRun ); - if ( triplet.bold != blockProperies.pBold ) - { - WordToFoUtils.setBold( inline, triplet.bold ); - } - if ( triplet.italic != blockProperies.pItalic ) - { - WordToFoUtils.setItalic( inline, triplet.italic ); - } - if ( WordToFoUtils.isNotEmpty( triplet.fontName ) - && !WordToFoUtils.equals( triplet.fontName, - blockProperies.pFontName ) ) - { + if ( WordToFoUtils.isNotEmpty( triplet.fontName ) ) WordToFoUtils.setFontFamily( inline, characterRun.getFontName() ); - } - if ( characterRun.getFontSize() / 2 != blockProperies.pFontSize ) - { - WordToFoUtils.setFontSize( inline, characterRun.getFontSize() / 2 ); - } + WordToFoUtils.setBold( inline, triplet.bold ); + WordToFoUtils.setItalic( inline, triplet.italic ); + WordToFoUtils.setFontSize( inline, characterRun.getFontSize() / 2 ); WordToFoUtils.setCharactersProperties( characterRun, inline ); block.appendChild( inline ); @@ -323,16 +284,7 @@ public class WordToFoConverter extends AbstractWordConverter setId( backwardLink, forwardLinkName ); endnote.appendChild( backwardLink ); - blocksProperies.push( new BlockProperies( "", -1, false, false ) ); - try - { - processCharacters( doc, Integer.MIN_VALUE, endnoteTextRange, - endnote ); - } - finally - { - blocksProperies.pop(); - } + processCharacters( doc, Integer.MIN_VALUE, endnoteTextRange, endnote ); WordToFoUtils.compactInlines( endnote ); this.endnotes.add( endnote ); @@ -368,16 +320,8 @@ public class WordToFoConverter extends AbstractWordConverter footnoteBody.appendChild( footnoteBlock ); footNote.appendChild( footnoteBody ); - blocksProperies.push( new BlockProperies( "", -1, false, false ) ); - try - { - processCharacters( doc, Integer.MIN_VALUE, footnoteTextRange, - footnoteBlock ); - } - finally - { - blocksProperies.pop(); - } + processCharacters( doc, Integer.MIN_VALUE, footnoteTextRange, + footnoteBlock ); WordToFoUtils.compactInlines( footnoteBlock ); } @@ -458,46 +402,26 @@ public class WordToFoConverter extends AbstractWordConverter return; } - { - CharacterRun characterRun = paragraph.getCharacterRun( 0 ); - int pFontSize = characterRun.getFontSize() / 2; - Triplet triplet = getCharacterRunTriplet( characterRun ); - - WordToFoUtils.setFontFamily( block, triplet.fontName ); - WordToFoUtils.setFontSize( block, pFontSize ); - WordToFoUtils.setBold( block, triplet.bold ); - WordToFoUtils.setItalic( block, triplet.italic ); + boolean haveAnyText = false; - blocksProperies.push( new BlockProperies( triplet.fontName, - pFontSize, triplet.bold, triplet.italic ) ); - } - try + if ( WordToFoUtils.isNotEmpty( bulletText ) ) { - boolean haveAnyText = false; + Element inline = foDocumentFacade.createInline(); + block.appendChild( inline ); - if ( WordToFoUtils.isNotEmpty( bulletText ) ) - { - Element inline = foDocumentFacade.createInline(); - block.appendChild( inline ); + Text textNode = foDocumentFacade.createText( bulletText ); + inline.appendChild( textNode ); - Text textNode = foDocumentFacade.createText( bulletText ); - inline.appendChild( textNode ); - - haveAnyText |= bulletText.trim().length() != 0; - } + haveAnyText |= bulletText.trim().length() != 0; + } - haveAnyText = processCharacters( hwpfDocument, currentTableLevel, - paragraph, block ); + haveAnyText = processCharacters( hwpfDocument, currentTableLevel, + paragraph, block ); - if ( !haveAnyText ) - { - Element leader = foDocumentFacade.createLeader(); - block.appendChild( leader ); - } - } - finally + if ( !haveAnyText ) { - blocksProperies.pop(); + Element leader = foDocumentFacade.createLeader(); + block.appendChild( leader ); } WordToFoUtils.compactInlines( block );