View | Details | Raw Unified | Return to bug 54111
Collapse All | Expand All

(-)src/scratchpad/src/org/apache/poi/hslf/model/TextShape.java (-2 / +21 lines)
Lines 42-47 Link Here
42
import org.apache.poi.hslf.record.Record;
42
import org.apache.poi.hslf.record.Record;
43
import org.apache.poi.hslf.record.RecordTypes;
43
import org.apache.poi.hslf.record.RecordTypes;
44
import org.apache.poi.hslf.record.StyleTextPropAtom;
44
import org.apache.poi.hslf.record.StyleTextPropAtom;
45
import org.apache.poi.hslf.record.TextBytesAtom;
45
import org.apache.poi.hslf.record.TextCharsAtom;
46
import org.apache.poi.hslf.record.TextCharsAtom;
46
import org.apache.poi.hslf.record.TextHeaderAtom;
47
import org.apache.poi.hslf.record.TextHeaderAtom;
47
import org.apache.poi.hslf.record.TxInteractiveInfoAtom;
48
import org.apache.poi.hslf.record.TxInteractiveInfoAtom;
Lines 484-491 Link Here
484
    /**
485
    /**
485
      * @return the TextRun object for this text box
486
      * @return the TextRun object for this text box
486
      */
487
      */
487
     public TextRun getTextRun(){
488
    public TextRun getTextRun(){
488
         if(_txtrun == null) initTextRun();
489
        if (null == this._txtrun) initTextRun();
490
        if (null == this._txtrun && null != this._txtbox) {
491
        	TextHeaderAtom    tha = null; 
492
        	TextBytesAtom     tba = null;
493
        	StyleTextPropAtom sta = null;
494
        	Record[] childRecords = this._txtbox.getChildRecords();
495
        	for (Record r : childRecords) {
496
        		if (r instanceof TextHeaderAtom) {
497
        			tha = (TextHeaderAtom) r;
498
				} else if (r instanceof TextBytesAtom) {
499
					tba = (TextBytesAtom) r;
500
				} else if (r instanceof StyleTextPropAtom) {
501
					sta = (StyleTextPropAtom) r;
502
				}
503
        	}
504
        	if (null != tba) {
505
        		this._txtrun = new TextRun(tha, tba, sta);
506
        	}
507
         }
489
         return _txtrun;
508
         return _txtrun;
490
     }
509
     }
491
510
(-)src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestTable.java (+75 lines)
Line 0 Link Here
1
/*
2
 *  ====================================================================
3
 *    Licensed to the Apache Software Foundation (ASF) under one or more
4
 *    contributor license agreements.  See the NOTICE file distributed with
5
 *    this work for additional information regarding copyright ownership.
6
 *    The ASF licenses this file to You under the Apache License, Version 2.0
7
 *    (the "License"); you may not use this file except in compliance with
8
 *    the License.  You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 * ====================================================================
18
 */
19
20
package org.apache.poi.hslf.usermodel;
21
22
import junit.framework.TestCase;
23
24
import org.apache.poi.hslf.model.Shape;
25
import org.apache.poi.hslf.model.Slide;
26
import org.apache.poi.hslf.model.Table;
27
import org.apache.poi.hslf.model.TextRun;
28
import org.apache.poi.POIDataSamples;
29
30
31
/**
32
 * Test that checks numbered list functionality.
33
 * 
34
 * @author Alex Nikiforov [mailto:anikif@gmail.com]
35
 */
36
public final class TestTable extends TestCase {
37
    private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
38
39
	protected void setUp() throws Exception {
40
	}
41
42
	public void testTable() throws Exception {
43
		SlideShow ppt = new SlideShow(_slTests.openResourceAsStream("table_test.ppt"));
44
		assertTrue("No Exceptions while reading file", true);
45
46
		final Slide[] slides = ppt.getSlides();
47
		assertEquals(1, slides.length);
48
		checkSlide(slides[0]);
49
	}
50
	private void checkSlide(final Slide s) {
51
		TextRun[] textRuns = s.getTextRuns();
52
		assertEquals(2, textRuns.length);
53
54
		RichTextRun textRun = textRuns[0].getRichTextRuns()[0];
55
		assertEquals("Table sample", textRun.getRawText().trim());
56
		assertEquals(1, textRuns[0].getRichTextRuns().length);
57
		assertFalse(textRun.isBullet());
58
59
		assertEquals("Dummy text", textRuns[1].getRawText());
60
		
61
		final Shape[] shapes = s.getShapes();
62
		assertNotNull(shapes);
63
		assertEquals(3, shapes.length);
64
		assertTrue(shapes[2] instanceof Table);
65
		final Table table = (Table) shapes[2];
66
		assertEquals(4, table.getNumberOfColumns());
67
		assertEquals(6, table.getNumberOfRows());
68
		for (int x = 0; x < 4; x ++) {
69
			assertEquals("TH Cell " + (x + 1), table.getCell(0, x).getTextRun().getRawText());
70
			for (int y = 1; y < 6; y++) {
71
				assertEquals("Row " + y + ", Cell " + (x + 1), table.getCell(y, x).getText());
72
			}
73
		}
74
	}
75
}

Return to bug 54111