]> source.dussan.org Git - poi.git/commitdiff
push boundaries checks down, removing deprecation warnings, remove (unused) cpMin...
authorSergey Vladimirov <sergey@apache.org>
Mon, 11 Jul 2011 08:57:42 +0000 (08:57 +0000)
committerSergey Vladimirov <sergey@apache.org>
Mon, 11 Jul 2011 08:57:42 +0000 (08:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1145075 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
src/scratchpad/src/org/apache/poi/hwpf/converter/HtmlDocumentFacade.java
src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlUtils.java
src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java
src/scratchpad/src/org/apache/poi/hwpf/model/OldCHPBinTable.java
src/scratchpad/src/org/apache/poi/hwpf/model/OldPAPBinTable.java
src/scratchpad/src/org/apache/poi/hwpf/model/PAPBinTable.java
src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java
src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java
src/scratchpad/testcases/org/apache/poi/hwpf/model/TestPAPBinTable.java

index a7090d419e2abc17017029a4368191d47928f8c9..b8a9892f9de5d99d32ce1908dc13794713fe0d38 100644 (file)
@@ -214,15 +214,10 @@ public final class HWPFDocument extends HWPFDocumentCore
     _cft = new ComplexFileTable(_mainStream, _tableStream, _fib.getFcClx(), fcMin);
     _tpt = _cft.getTextPieceTable();
 
-    // Word XP and later all put in a zero filled buffer in
-    //  front of the text. This screws up the system for offsets,
-    //  which assume we always start at zero. This is an adjustment.
-    int cpMin = _tpt.getCpMin();
-
     // Now load the rest of the properties, which need to be adjusted
     //  for where text really begin
     _cbt = new CHPBinTable(_mainStream, _tableStream, _fib.getFcPlcfbteChpx(), _fib.getLcbPlcfbteChpx(), _tpt, true);
-    _pbt = new PAPBinTable(_mainStream, _tableStream, _dataStream, _fib.getFcPlcfbtePapx(), _fib.getLcbPlcfbtePapx(), cpMin, _tpt, true);
+    _pbt = new PAPBinTable(_mainStream, _tableStream, _dataStream, _fib.getFcPlcfbtePapx(), _fib.getLcbPlcfbtePapx(), _tpt, true);
 
     // Read FSPA and Escher information
     _fspa = new FSPATable(_tableStream, _fib.getFcPlcspaMom(), _fib.getLcbPlcspaMom(), getTextTable().getTextPieces());
index 6a57704a952bddae90e2c948108e9a481adc26f5..186f037a5a85a27645b36899c1fd1ade1aa587c0 100644 (file)
@@ -43,6 +43,8 @@ public class HtmlDocumentFacade
 
         html.appendChild( head );
         html.appendChild( body );
+
+        body.setAttribute( "style", "white-space-collapsing: preserve; " );
     }
 
     public void addAuthor( String value )
index a1297015a5eac09f9d24912e5f40466b3a9eba97..80e13a453a845f40d71ebf48ef03fcf088d5290b 100644 (file)
@@ -172,7 +172,8 @@ public class WordToHtmlUtils extends AbstractWordUtils
             style.append( "break-before: page; " );
         }
 
-        style.append( "hyphenate: " + paragraph.isAutoHyphenated() + "; " );
+        style.append( "hyphenate: "
+                + ( paragraph.isAutoHyphenated() ? "auto" : "none" ) + "; " );
 
         if ( paragraph.keepOnPage() )
         {
@@ -183,9 +184,6 @@ public class WordToHtmlUtils extends AbstractWordUtils
         {
             style.append( "keep-with-next.within-page: always; " );
         }
-
-        style.append( "linefeed-treatment: preserve; " );
-        style.append( "white-space-collapse: false; " );
     }
 
     public static void addTableCellProperties( TableRow tableRow,
index ed5dae220b1573e4670d0726e2a6fa9b0fa81bce..714f0e1c1e8b9f7f1e7087d10cec6743fb7aba4b 100644 (file)
@@ -21,6 +21,8 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 
 /**
  * Represents a CHP fkp. The style properties for paragraph and character runs
@@ -40,6 +42,9 @@ import org.apache.poi.util.LittleEndian;
  */
 public final class CHPFormattedDiskPage extends FormattedDiskPage
 {
+    private static final POILogger logger = POILogFactory
+            .getLogger( CHPFormattedDiskPage.class );
+
     private static final int FC_SIZE = 4;
 
     private ArrayList<CHPX> _chpxList = new ArrayList<CHPX>();
@@ -79,11 +84,20 @@ public final class CHPFormattedDiskPage extends FormattedDiskPage
        int startAt = getStart(x);
                int endAt = getEnd(x);
 
-        if (ignoreChpxWithoutTextPieces && !tpt.isIndexInTable( startAt, endAt ) ) {
-            _chpxList.add(null);
-        } else {
+        if (!ignoreChpxWithoutTextPieces || tpt.isIndexInTable( startAt, endAt ) )
+        {
                    _chpxList.add(new CHPX(startAt, endAt, tpt, getGrpprl(x)));
         }
+        else
+        {
+            logger.log( POILogger.WARN, "CHPX [",
+                    Integer.valueOf( startAt ), "; ",
+                    Integer.valueOf( endAt ),
+                    ") (bytes) doesn't have corresponding text pieces "
+                            + "and will be skipped" );
+
+            _chpxList.add(null);
+        }
       }
     }
 
index 3f43c2f1bb6a0d311ef20c5a7558b71d164a8b54..479bb3c95c2e0e7111c2da0fde3c6500bddeb451 100644 (file)
@@ -21,8 +21,6 @@ import java.util.Collections;
 
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
 
 /**
  * This class holds all of the character formatting 
@@ -34,9 +32,6 @@ import org.apache.poi.util.POILogger;
  */
 public final class OldCHPBinTable extends CHPBinTable
 {
-    private static final POILogger logger = POILogFactory
-            .getLogger( OldCHPBinTable.class );
-
   /**
    * Constructor used to read an old-style binTable
    *  in from a Word document.
@@ -67,15 +62,8 @@ public final class OldCHPBinTable extends CHPBinTable
       for (int y = 0; y < fkpSize; y++)
       {
         CHPX chpx = cfkp.getCHPX(y);
-        if (chpx != null && tpt.isIndexInTable( chpx.getStartBytes(), chpx.getEndBytes() )) {
+        if (chpx != null)
             _textRuns.add(chpx);
-        } else {
-                    if ( chpx != null )
-                        logger.log( POILogger.WARN, "CHPX [",
-                                chpx.getStartBytes(), "; ", chpx.getEndBytes(),
-                                ") (bytes) doesn't have corresponding text pieces "
-                                        + "and will be skipped" );
-        }
       }
     }
     Collections.sort( _textRuns, PropertyNode.StartComparator.instance );
index 3cc096455eaa29b3edf2085afc91f3e46ffecd26..9f5a43fe6b6bb16550cd446fb594ec895891c9c5 100644 (file)
@@ -21,8 +21,6 @@ import java.util.Collections;
 
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.util.LittleEndian;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
 
 /**
  * This class holds all of the paragraph formatting 
@@ -34,8 +32,6 @@ import org.apache.poi.util.POILogger;
  */
 public final class OldPAPBinTable extends PAPBinTable
 {
-    private static final POILogger logger = POILogFactory
-            .getLogger( OldPAPBinTable.class );
 
   public OldPAPBinTable(byte[] documentStream, int offset,
                      int size, int fcMin, TextPieceTable tpt)
@@ -51,21 +47,15 @@ public final class OldPAPBinTable extends PAPBinTable
       int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum;
 
       PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(documentStream,
-        documentStream, pageOffset, fcMin, tpt);
+        documentStream, pageOffset, tpt, true);
 
       int fkpSize = pfkp.size();
 
       for (int y = 0; y < fkpSize; y++)
       {
        PAPX papx = pfkp.getPAPX(y);
-        if (papx != null && tpt.isIndexInTable( papx.getStartBytes(), papx.getEndBytes() )) {
+        if (papx != null) {
             _paragraphs.add(papx);
-        } else {
-                    if ( papx != null )
-                        logger.log( POILogger.WARN, "PAPX [",
-                                papx.getStartBytes(), "; ", papx.getEndBytes(),
-                                ") (bytes) doesn't have corresponding text pieces "
-                                        + "and will be skipped" );
         }
       }
     }
index 8dc28a45a863e47caa44a7dfad74ba8f3aca30e6..db55fea4183817083b327422858313dd6fe7bbcd 100644 (file)
@@ -56,13 +56,12 @@ public class PAPBinTable
             byte[] dataStream, int offset, int size, int fcMin,
             TextPieceTable tpt )
     {
-        this( documentStream, tableStream, dataStream, offset, size, fcMin,
-                tpt, true );
+        this( documentStream, tableStream, dataStream, offset, size, tpt, true );
     }
 
     public PAPBinTable( byte[] documentStream, byte[] tableStream,
-            byte[] dataStream, int offset, int size, int fcMin,
-            TextPieceTable tpt, boolean ignorePapxWithoutTextPieces )
+            byte[] dataStream, int offset, int size, TextPieceTable tpt,
+            boolean ignorePapxWithoutTextPieces )
     {
     PlexOfCps binTable = new PlexOfCps(tableStream, offset, size, 4);
     this.tpt = tpt;
@@ -76,7 +75,7 @@ public class PAPBinTable
       int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum;
 
       PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(documentStream,
-        dataStream, pageOffset, fcMin, tpt);
+        dataStream, pageOffset, tpt, ignorePapxWithoutTextPieces);
 
       int fkpSize = pfkp.size();
 
@@ -84,8 +83,7 @@ public class PAPBinTable
       {
        PAPX papx = pfkp.getPAPX(y);
 
-       //we don't need PAPX if they are references nowhere
-       if (!ignorePapxWithoutTextPieces || tpt.isIndexInTable( papx.getStartBytes(), papx.getEndBytes() ))
+       if (papx != null)
            _paragraphs.add(papx);
       }
     }
index 14c677db401cfa06d10830764b686655d9b72aae..1035698b8e672e43c8c054ef59c5a760a67e80ca 100644 (file)
@@ -22,6 +22,8 @@ import java.util.Arrays;
 import java.util.List;
 
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 
 /**
  * Represents a PAP FKP. The style properties for paragraph and character runs
@@ -40,6 +42,8 @@ import org.apache.poi.util.LittleEndian;
  * @author Ryan Ackley
  */
 public final class PAPFormattedDiskPage extends FormattedDiskPage {
+    private static final POILogger logger = POILogFactory
+            .getLogger( PAPFormattedDiskPage.class );
 
     private static final int BX_SIZE = 13;
     private static final int FC_SIZE = 4;
@@ -56,17 +60,45 @@ public final class PAPFormattedDiskPage extends FormattedDiskPage {
 
     /**
      * Creates a PAPFormattedDiskPage from a 512 byte array
+     * 
+     * @deprecated Use
+     *             {@link #PAPFormattedDiskPage(byte[],byte[],int,int,TextPieceTable,boolean)}
+     *             instead
      */
-    public PAPFormattedDiskPage(byte[] documentStream, byte[] dataStream, int offset, int fcMin, TextPieceTable tpt)
+    public PAPFormattedDiskPage( byte[] documentStream, byte[] dataStream,
+            int offset, int fcMin, TextPieceTable tpt )
     {
-      super(documentStream, offset);
-      for (int x = 0; x < _crun; x++) {
-         int startAt = getStart(x);
-         int endAt = getEnd(x);
-         _papxList.add(new PAPX(startAt, endAt, tpt, getGrpprl(x), getParagraphHeight(x), dataStream));
-      }
-      _fkp = null;
-      _dataStream = dataStream;
+        this( documentStream, dataStream, offset, tpt, true );
+    }
+
+    /**
+     * Creates a PAPFormattedDiskPage from a 512 byte array
+     */
+    public PAPFormattedDiskPage( byte[] documentStream, byte[] dataStream,
+            int offset, TextPieceTable tpt, boolean ignorePapxWithoutTextPieces )
+    {
+        super( documentStream, offset );
+        for ( int x = 0; x < _crun; x++ )
+        {
+            int startAt = getStart( x );
+            int endAt = getEnd( x );
+            if ( !ignorePapxWithoutTextPieces
+                    || tpt.isIndexInTable( startAt, endAt ) )
+                _papxList.add( new PAPX( startAt, endAt, tpt, getGrpprl( x ),
+                        getParagraphHeight( x ), dataStream ) );
+            else
+            {
+                logger.log( POILogger.WARN, "PAPX [",
+                        Integer.valueOf( startAt ), "; ",
+                        Integer.valueOf( endAt ),
+                        ") (bytes) doesn't have corresponding text pieces "
+                                + "and will be skipped" );
+
+                _papxList.add( null );
+            }
+        }
+        _fkp = null;
+        _dataStream = dataStream;
     }
 
     /**
index 6c8661431505ccfbd2c1702d4e5ce2cf6d6a42ab..ab9daa51ff38778521d3d47093356d25694d0c36 100644 (file)
@@ -26,6 +26,7 @@ import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
 import junit.framework.TestCase;
+
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hwpf.HWPFDocument;
 
@@ -68,6 +69,13 @@ public class TestWordToHtmlConverter extends TestCase
         assertTrue( result.substring( 0, 2000 ).contains( "<table>" ) );
     }
 
+    public void testBug33519() throws Exception
+    {
+        String result = getHtmlText( "Bug33519.doc" );
+        assertTrue( result.contains( "Планински турове" ) );
+        assertTrue( result.contains( "Явор Асенов" ) );
+    }
+
     public void testBug46610_2() throws Exception
     {
         String result = getHtmlText( "Bug46610_2.doc" );
index 20b2680335cd97c19a8182d11b8a0872aa959f44..8bd102a16c6e9edd9bb2f6f0d494b9692eae1cb2 100644 (file)
@@ -21,6 +21,7 @@ import java.io.ByteArrayOutputStream;
 import java.util.ArrayList;
 
 import junit.framework.TestCase;
+
 import org.apache.poi.hwpf.HWPFDocFixture;
 import org.apache.poi.hwpf.model.io.HWPFFileSystem;
 
@@ -38,9 +39,8 @@ public final class TestPAPBinTable
     FileInformationBlock fib = _hWPFDocFixture._fib;
     byte[] mainStream = _hWPFDocFixture._mainStream;
     byte[] tableStream = _hWPFDocFixture._tableStream;
-    int fcMin = fib.getFcMin();
 
-    _pAPBinTable = new PAPBinTable(mainStream, tableStream, null, fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), fcMin, fakeTPT, false);
+    _pAPBinTable = new PAPBinTable(mainStream, tableStream, null, fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), fakeTPT, false);
 
     HWPFFileSystem fileSys = new HWPFFileSystem();
 
@@ -51,7 +51,7 @@ public final class TestPAPBinTable
     byte[] newTableStream = tableOut.toByteArray();
     byte[] newMainStream = mainOut.toByteArray();
 
-    PAPBinTable newBinTable = new PAPBinTable(newMainStream, newTableStream, null,0, newTableStream.length, 0, fakeTPT, false);
+    PAPBinTable newBinTable = new PAPBinTable(newMainStream, newTableStream, null,0, newTableStream.length, fakeTPT, false);
 
     ArrayList oldTextRuns = _pAPBinTable.getParagraphs();
     ArrayList newTextRuns = newBinTable.getParagraphs();