mirror of https://github.com/apache/poi.git
#60993 - HSLF: Grid and rowspan calculation in table cells is wrong
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1791500 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8fa92c2e6a
commit
19fe559090
|
@ -20,6 +20,10 @@
|
||||||
package org.apache.poi.sl;
|
package org.apache.poi.sl;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assume.assumeFalse;
|
import static org.junit.Assume.assumeFalse;
|
||||||
|
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
@ -30,6 +34,7 @@ import java.io.InputStream;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||||
|
import org.apache.poi.sl.usermodel.Slide;
|
||||||
import org.apache.poi.sl.usermodel.SlideShow;
|
import org.apache.poi.sl.usermodel.SlideShow;
|
||||||
import org.apache.poi.sl.usermodel.SlideShowFactory;
|
import org.apache.poi.sl.usermodel.SlideShowFactory;
|
||||||
import org.apache.poi.sl.usermodel.TableCell;
|
import org.apache.poi.sl.usermodel.TableCell;
|
||||||
|
@ -66,7 +71,7 @@ public class TestTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testColWidthRowHeight() throws IOException {
|
public void colWidthRowHeight() throws IOException {
|
||||||
assumeFalse(xslfOnly);
|
assumeFalse(xslfOnly);
|
||||||
|
|
||||||
// Test of table dimensions of same slideshow saved as ppt/x
|
// Test of table dimensions of same slideshow saved as ppt/x
|
||||||
|
@ -110,7 +115,7 @@ public class TestTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTextDirectionHSLF() throws IOException {
|
public void textDirectionHSLF() throws IOException {
|
||||||
assumeFalse(xslfOnly);
|
assumeFalse(xslfOnly);
|
||||||
SlideShow<?,?> ppt1 = new HSLFSlideShow();
|
SlideShow<?,?> ppt1 = new HSLFSlideShow();
|
||||||
testTextDirection(ppt1);
|
testTextDirection(ppt1);
|
||||||
|
@ -118,7 +123,7 @@ public class TestTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTextDirectionXSLF() throws IOException {
|
public void textDirectionXSLF() throws IOException {
|
||||||
SlideShow<?,?> ppt1 = new XMLSlideShow();
|
SlideShow<?,?> ppt1 = new XMLSlideShow();
|
||||||
testTextDirection(ppt1);
|
testTextDirection(ppt1);
|
||||||
ppt1.close();
|
ppt1.close();
|
||||||
|
@ -160,4 +165,53 @@ public class TestTable {
|
||||||
}
|
}
|
||||||
ppt2.close();
|
ppt2.close();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
|
public void tableSpan() throws IOException {
|
||||||
|
String files[] = (xslfOnly) ? new String[]{ "bug60993.pptx" } : new String[]{ "bug60993.pptx", "bug60993.ppt" };
|
||||||
|
for (String f : files) {
|
||||||
|
SlideShow<?,?> ppt = openSampleSlideshow(f);
|
||||||
|
Slide<?,?> slide = ppt.getSlides().get(0);
|
||||||
|
TableShape<?,?> ts = (TableShape<?,?>)slide.getShapes().get(0);
|
||||||
|
int cols = ts.getNumberOfColumns();
|
||||||
|
int rows = ts.getNumberOfRows();
|
||||||
|
for (int r=0; r<rows; r++) {
|
||||||
|
for (int c=0; c<cols; c++) {
|
||||||
|
TableCell<?,?> tc = ts.getCell(r, c);
|
||||||
|
int rc = r*10+c;
|
||||||
|
String msg = f+" (r"+r+",c"+c+")";
|
||||||
|
switch (rc) {
|
||||||
|
case 22:
|
||||||
|
case 51:
|
||||||
|
if (f.endsWith("ppt")) {
|
||||||
|
assertNull(msg, tc);
|
||||||
|
} else {
|
||||||
|
assertNotNull(msg, tc);
|
||||||
|
assertTrue(msg, tc.isMerged());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 21:
|
||||||
|
assertNotNull(msg, tc);
|
||||||
|
assertEquals(msg, 1, tc.getRowSpan());
|
||||||
|
assertEquals(msg, 2, tc.getGridSpan());
|
||||||
|
assertFalse(msg, tc.isMerged());
|
||||||
|
break;
|
||||||
|
case 41:
|
||||||
|
assertNotNull(msg, tc);
|
||||||
|
assertEquals(msg, 2, tc.getRowSpan());
|
||||||
|
assertEquals(msg, 1, tc.getGridSpan());
|
||||||
|
assertFalse(msg, tc.isMerged());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assertNotNull(msg, tc);
|
||||||
|
assertEquals(msg, 1, tc.getRowSpan());
|
||||||
|
assertEquals(msg, 1, tc.getGridSpan());
|
||||||
|
assertFalse(msg, tc.isMerged());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ppt.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ import java.awt.geom.Rectangle2D;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
@ -218,15 +219,11 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private int calcSpan(List<Double> spaces, double totalSpace, int idx) {
|
private int calcSpan(List<Double> spaces, double totalSpace, int idx) {
|
||||||
if (idx == spaces.size()-1) {
|
int span = 1;
|
||||||
return 1;
|
ListIterator<Double> li = spaces.listIterator(idx);
|
||||||
}
|
double start = li.next();
|
||||||
int span = 0;
|
while (li.hasNext() && li.next()-start < totalSpace) {
|
||||||
double remainingSpace = totalSpace;
|
|
||||||
while (idx+1 < spaces.size() && remainingSpace > 0) {
|
|
||||||
remainingSpace -= spaces.get(idx+1)-spaces.get(idx);
|
|
||||||
span++;
|
span++;
|
||||||
idx++;
|
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue