diff options
author | Yegor Kozlov <yegor@apache.org> | 2012-11-07 16:02:42 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2012-11-07 16:02:42 +0000 |
commit | bdba0ab57c0f713ca130be2bc969b5237223f3e8 (patch) | |
tree | 3fdef087d2eb5e7f90e48e18d2bd212c83db2225 | |
parent | b85c7f9f30e24e15f849347cb215c87bf6cd7444 (diff) | |
download | poi-bdba0ab57c0f713ca130be2bc969b5237223f3e8.tar.gz poi-bdba0ab57c0f713ca130be2bc969b5237223f3e8.zip |
Bugzilla 54111 - Fixed extracting text from table cells in HSLF
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1406688 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/documentation/content/xdocs/status.xml | 1 | ||||
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java | 23 | ||||
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java | 75 | ||||
-rw-r--r-- | test-data/slideshow/54111.ppt | bin | 0 -> 117248 bytes |
4 files changed, 97 insertions, 2 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index f297c50612..50f9edc544 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ <changes> <release version="3.9-beta1" date="2012-??-??"> + <action dev="poi-developers" type="fix">54111 - Fixed extracting text from table cells in HSLF</action> <action dev="poi-developers" type="add">52583 - add support for drop-down lists in doc to html convertion</action> <action dev="poi-developers" type="add">52863 - add workaround for files with broken CHP SPRMs</action> <action dev="poi-developers" type="fix">53182 - Reading combined character styling and direct formatting of a character run</action> diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java b/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java index 3bf37499c5..67341a2672 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java @@ -42,6 +42,7 @@ import org.apache.poi.hslf.record.PPDrawing; import org.apache.poi.hslf.record.Record; import org.apache.poi.hslf.record.RecordTypes; import org.apache.poi.hslf.record.StyleTextPropAtom; +import org.apache.poi.hslf.record.TextBytesAtom; import org.apache.poi.hslf.record.TextCharsAtom; import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.record.TxInteractiveInfoAtom; @@ -484,8 +485,26 @@ public abstract class TextShape extends SimpleShape { /** * @return the TextRun object for this text box */ - public TextRun getTextRun(){ - if(_txtrun == null) initTextRun(); + public TextRun getTextRun(){ + if (null == this._txtrun) initTextRun(); + if (null == this._txtrun && null != this._txtbox) { + TextHeaderAtom tha = null; + TextBytesAtom tba = null; + StyleTextPropAtom sta = null; + Record[] childRecords = this._txtbox.getChildRecords(); + for (Record r : childRecords) { + if (r instanceof TextHeaderAtom) { + tha = (TextHeaderAtom) r; + } else if (r instanceof TextBytesAtom) { + tba = (TextBytesAtom) r; + } else if (r instanceof StyleTextPropAtom) { + sta = (StyleTextPropAtom) r; + } + } + if (null != tba) { + this._txtrun = new TextRun(tha, tba, sta); + } + } return _txtrun; } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java new file mode 100644 index 0000000000..0851ff4be1 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java @@ -0,0 +1,75 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.apache.poi.hslf.usermodel; + +import junit.framework.TestCase; + +import org.apache.poi.hslf.model.Shape; +import org.apache.poi.hslf.model.Slide; +import org.apache.poi.hslf.model.Table; +import org.apache.poi.hslf.model.TextRun; +import org.apache.poi.POIDataSamples; + + +/** + * Test that checks numbered list functionality. + * + * @author Alex Nikiforov [mailto:anikif@gmail.com] + */ +public final class TestTable extends TestCase { + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); + + protected void setUp() throws Exception { + } + + public void testTable() throws Exception { + SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("54111.ppt")); + assertTrue("No Exceptions while reading file", true); + + final Slide[] slides = ppt.getSlides(); + assertEquals(1, slides.length); + checkSlide(slides[0]); + } + private void checkSlide(final Slide s) { + TextRun[] textRuns = s.getTextRuns(); + assertEquals(2, textRuns.length); + + RichTextRun textRun = textRuns[0].getRichTextRuns()[0]; + assertEquals("Table sample", textRun.getRawText().trim()); + assertEquals(1, textRuns[0].getRichTextRuns().length); + assertFalse(textRun.isBullet()); + + assertEquals("Dummy text", textRuns[1].getRawText()); + + final Shape[] shapes = s.getShapes(); + assertNotNull(shapes); + assertEquals(3, shapes.length); + assertTrue(shapes[2] instanceof Table); + final Table table = (Table) shapes[2]; + assertEquals(4, table.getNumberOfColumns()); + assertEquals(6, table.getNumberOfRows()); + for (int x = 0; x < 4; x ++) { + assertEquals("TH Cell " + (x + 1), table.getCell(0, x).getTextRun().getRawText()); + for (int y = 1; y < 6; y++) { + assertEquals("Row " + y + ", Cell " + (x + 1), table.getCell(y, x).getText()); + } + } + } +} diff --git a/test-data/slideshow/54111.ppt b/test-data/slideshow/54111.ppt Binary files differnew file mode 100644 index 0000000000..048bfb621b --- /dev/null +++ b/test-data/slideshow/54111.ppt |