Commit changes in common_sl - need to update trunk ...

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/common_sl@1678832 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-05-11 22:07:40 +00:00
parent 28d7a023e9
commit d2e7cd51c3
19 changed files with 345 additions and 368 deletions

View File

@ -17,9 +17,10 @@
package org.apache.poi.hslf.examples; package org.apache.poi.hslf.examples;
import org.apache.poi.hslf.usermodel.*;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.util.List;
import org.apache.poi.hslf.usermodel.*;
/** /**
* Demonstrates how to read hyperlinks from a presentation * Demonstrates how to read hyperlinks from a presentation
@ -34,44 +35,37 @@ public final class Hyperlinks {
HSLFSlideShow ppt = new HSLFSlideShow(is); HSLFSlideShow ppt = new HSLFSlideShow(is);
is.close(); is.close();
HSLFSlide[] slide = ppt.getSlides(); for (HSLFSlide slide : ppt.getSlides()) {
for (int j = 0; j < slide.length; j++) { System.out.println("\nslide " + slide.getSlideNumber());
System.out.println("slide " + slide[j].getSlideNumber());
//read hyperlinks from the slide's text runs // read hyperlinks from the slide's text runs
System.out.println("reading hyperlinks from the text runs"); System.out.println("- reading hyperlinks from the text runs");
HSLFTextParagraph[] txt = slide[j].getTextParagraphs(); for (List<HSLFTextParagraph> txtParas : slide.getTextParagraphs()) {
for (int k = 0; k < txt.length; k++) { List<HSLFHyperlink> links = HSLFHyperlink.find(txtParas);
String text = txt[k].getRawText(); String text = HSLFTextParagraph.getRawText(txtParas);
HSLFHyperlink[] links = txt[k].getHyperlinks();
if(links != null) for (int l = 0; l < links.length; l++) { for (HSLFHyperlink link : links) {
HSLFHyperlink link = links[l]; System.out.println(toStr(link, text));
String title = link.getTitle();
String address = link.getAddress();
System.out.println(" " + title);
System.out.println(" " + address);
String substring = text.substring(link.getStartIndex(), link.getEndIndex()-1);//in ppt end index is inclusive
System.out.println(" " + substring);
} }
} }
//in PowerPoint you can assign a hyperlink to a shape without text, // in PowerPoint you can assign a hyperlink to a shape without text,
//for example to a Line object. The code below demonstrates how to // for example to a Line object. The code below demonstrates how to
//read such hyperlinks // read such hyperlinks
System.out.println(" reading hyperlinks from the slide's shapes"); System.out.println("- reading hyperlinks from the slide's shapes");
HSLFShape[] sh = slide[j].getShapes(); for (HSLFShape sh : slide.getShapes()) {
for (int k = 0; k < sh.length; k++) { HSLFHyperlink link = HSLFHyperlink.find(sh);
HSLFHyperlink link = sh[k].getHyperlink(); if (link == null) continue;
if(link != null) { System.out.println(toStr(link, null));
String title = link.getTitle();
String address = link.getAddress();
System.out.println(" " + title);
System.out.println(" " + address);
}
} }
} }
} }
} }
static String toStr(HSLFHyperlink link, String rawText) {
//in ppt end index is inclusive
String formatStr = "title: %1$s, address: %2$s" + (rawText == null ? "" : ", start: %3$s, end: %4$s, substring: %5$s");
String substring = (rawText == null) ? "" : rawText.substring(link.getStartIndex(), link.getEndIndex()-1);
return String.format(formatStr, link.getTitle(), link.getAddress(), link.getStartIndex(), link.getEndIndex(), substring);
}
} }

View File

@ -17,16 +17,16 @@
package org.apache.poi.hslf.examples; package org.apache.poi.hslf.examples;
import org.apache.poi.hslf.usermodel.*; import java.awt.*;
import org.apache.poi.hslf.model.*; import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.io.FileOutputStream; import org.apache.poi.hslf.usermodel.HSLFSlide;
import java.io.FileInputStream; import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.geom.Rectangle2D;
/** /**
* Demonstrates how you can use HSLF to convert each slide into a PNG image * Demonstrates how you can use HSLF to convert each slide into a PNG image
@ -70,12 +70,11 @@ public final class PPT2PNG {
int width = (int)(pgsize.width*scale); int width = (int)(pgsize.width*scale);
int height = (int)(pgsize.height*scale); int height = (int)(pgsize.height*scale);
HSLFSlide[] slide = ppt.getSlides(); for (HSLFSlide slide : ppt.getSlides()) {
for (int i = 0; i < slide.length; i++) { if (slidenum != -1 && slidenum != slide.getSlideNumber()) continue;
if (slidenum != -1 && slidenum != (i+1)) continue;
String title = slide[i].getTitle(); String title = slide.getTitle();
System.out.println("Rendering slide "+slide[i].getSlideNumber() + (title == null ? "" : ": " + title)); System.out.println("Rendering slide "+slide.getSlideNumber() + (title == null ? "" : ": " + title));
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = img.createGraphics(); Graphics2D graphics = img.createGraphics();
@ -89,9 +88,9 @@ public final class PPT2PNG {
graphics.scale((double)width/pgsize.width, (double)height/pgsize.height); graphics.scale((double)width/pgsize.width, (double)height/pgsize.height);
slide[i].draw(graphics); slide.draw(graphics);
String fname = file.replaceAll("\\.ppt", "-" + (i+1) + ".png"); String fname = file.replaceAll("\\.ppt", "-" + slide.getSlideNumber() + ".png");
FileOutputStream out = new FileOutputStream(fname); FileOutputStream out = new FileOutputStream(fname);
ImageIO.write(img, "png", out); ImageIO.write(img, "png", out);
out.close(); out.close();

View File

@ -15,17 +15,14 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hslf.examples; package org.apache.poi.hslf.examples;
import org.apache.poi.ddf.*;
import org.apache.poi.hslf.model.*;
import org.apache.poi.hslf.record.InteractiveInfo;
import org.apache.poi.hslf.record.InteractiveInfoAtom;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.usermodel.*;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.apache.poi.ddf.*;
import org.apache.poi.hslf.record.*;
import org.apache.poi.hslf.usermodel.*;
/** /**
* For each slide iterate over shapes and found associated sound data. * For each slide iterate over shapes and found associated sound data.
* *
@ -36,16 +33,15 @@ public class SoundFinder {
HSLFSlideShow ppt = new HSLFSlideShow(new FileInputStream(args[0])); HSLFSlideShow ppt = new HSLFSlideShow(new FileInputStream(args[0]));
HSLFSoundData[] sounds = ppt.getSoundData(); HSLFSoundData[] sounds = ppt.getSoundData();
HSLFSlide[] slide = ppt.getSlides(); for (HSLFSlide slide : ppt.getSlides()) {
for (int i = 0; i < slide.length; i++) { for (HSLFShape shape : slide.getShapes()) {
HSLFShape[] shape = slide[i].getShapes(); int soundRef = getSoundReference(shape);
for (int j = 0; j < shape.length; j++) { if(soundRef == -1) continue;
int soundRef = getSoundReference(shape[j]);
if(soundRef != -1) {
System.out.println("Slide["+i+"], shape["+j+"], soundRef: "+soundRef); System.out.println("Slide["+slide.getSlideNumber()+"], shape["+shape.getShapeId()+"], soundRef: "+soundRef);
System.out.println(" " + sounds[soundRef].getSoundName()); System.out.println(" " + sounds[soundRef].getSoundName());
System.out.println(" " + sounds[soundRef].getSoundType()); System.out.println(" " + sounds[soundRef].getSoundType());
}
} }
} }
} }

View File

@ -19,6 +19,8 @@ package org.apache.poi.hslf.examples;
import org.apache.poi.hslf.usermodel.*; import org.apache.poi.hslf.usermodel.*;
import org.apache.poi.hslf.model.*; import org.apache.poi.hslf.model.*;
import org.apache.poi.sl.usermodel.TextParagraph.TextAlign;
import org.apache.poi.sl.usermodel.VerticalAlignment;
import java.awt.*; import java.awt.*;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -51,8 +53,7 @@ public final class TableDemo {
for (int i = 0; i < txt1.length; i++) { for (int i = 0; i < txt1.length; i++) {
for (int j = 0; j < txt1[i].length; j++) { for (int j = 0; j < txt1[i].length; j++) {
TableCell cell = table1.getCell(i, j); TableCell cell = table1.getCell(i, j);
cell.setText(txt1[i][j]); HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
HSLFTextRun rt = cell.getTextParagraphs().getTextRuns()[0];
rt.setFontName("Arial"); rt.setFontName("Arial");
rt.setFontSize(10); rt.setFontSize(10);
if(i == 0){ if(i == 0){
@ -60,8 +61,9 @@ public final class TableDemo {
} else { } else {
rt.setBold(true); rt.setBold(true);
} }
cell.setVerticalAlignment(HSLFTextBox.AnchorMiddle); cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
cell.setHorizontalAlignment(HSLFTextBox.AlignCenter); cell.setHorizontalCentered(true);
cell.setText(txt1[i][j]);
} }
} }
@ -90,8 +92,7 @@ public final class TableDemo {
for (int i = 0; i < txt2.length; i++) { for (int i = 0; i < txt2.length; i++) {
for (int j = 0; j < txt2[i].length; j++) { for (int j = 0; j < txt2[i].length; j++) {
TableCell cell = table2.getCell(i, j); TableCell cell = table2.getCell(i, j);
cell.setText(txt2[i][j]); HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
HSLFTextRun rt = cell.getTextParagraphs().getTextRuns()[0];
rt.setFontSize(10); rt.setFontSize(10);
rt.setFontName("Arial"); rt.setFontName("Arial");
if(i == 0){ if(i == 0){
@ -99,13 +100,15 @@ public final class TableDemo {
rt.setFontColor(Color.white); rt.setFontColor(Color.white);
rt.setBold(true); rt.setBold(true);
rt.setFontSize(14); rt.setFontSize(14);
cell.setHorizontalAlignment(HSLFTextBox.AlignCenter); cell.setHorizontalCentered(true);
} else { } else {
rt.setBullet(true); rt.getTextParagraph().setBullet(true);
rt.setFontSize(12); rt.setFontSize(12);
cell.setHorizontalAlignment(HSLFTextBox.AlignLeft); rt.getTextParagraph().setAlignment(TextAlign.LEFT);
cell.setHorizontalCentered(false);
} }
cell.setVerticalAlignment(HSLFTextBox.AnchorMiddle); cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
cell.setText(txt2[i][j]);
} }
} }
table2.setColumnWidth(0, 300); table2.setColumnWidth(0, 300);

View File

@ -67,7 +67,7 @@ public class PieChartDemo {
String chartTitle = modelReader.readLine(); // first line is chart title String chartTitle = modelReader.readLine(); // first line is chart title
XMLSlideShow pptx = new XMLSlideShow(new FileInputStream(args[0])); XMLSlideShow pptx = new XMLSlideShow(new FileInputStream(args[0]));
XSLFSlide slide = pptx.getSlides()[0]; XSLFSlide slide = pptx.getSlides().get(0);
// find chart in the slide // find chart in the slide
XSLFChart chart = null; XSLFChart chart = null;

View File

@ -37,7 +37,7 @@ public class Tutorial1 {
/*XSLFSlide blankSlide =*/ ppt.createSlide(); /*XSLFSlide blankSlide =*/ ppt.createSlide();
XSLFSlideMaster master = ppt.getSlideMasters()[0]; XSLFSlideMaster master = ppt.getSlideMasters().get(0);
XSLFSlideLayout layout1 = master.getLayout(SlideLayout.TITLE); XSLFSlideLayout layout1 = master.getLayout(SlideLayout.TITLE);
XSLFSlide slide1 = ppt.createSlide(layout1) ; XSLFSlide slide1 = ppt.createSlide(layout1) ;

View File

@ -49,7 +49,7 @@ public class Step2 {
// blank slide // blank slide
/*XSLFSlide blankSlide =*/ ppt.createSlide(); /*XSLFSlide blankSlide =*/ ppt.createSlide();
XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[0]; XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
// title slide // title slide
XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE); XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);

View File

@ -146,50 +146,31 @@ public final class HSLFHyperlink {
* @param shape <code>TextRun</code> to lookup hyperlinks in * @param shape <code>TextRun</code> to lookup hyperlinks in
* @return found hyperlinks or <code>null</code> if not found * @return found hyperlinks or <code>null</code> if not found
*/ */
public static HSLFHyperlink[] find(HSLFTextShape shape){ public static List<HSLFHyperlink> find(HSLFTextShape shape){
List<HSLFHyperlink> lst = new ArrayList<HSLFHyperlink>(); return find(shape.getTextParagraphs());
HSLFSlideShow ppt = shape.getSheet().getSlideShow();
//document-level container which stores info about all links in a presentation
ExObjList exobj = ppt.getDocumentRecord().getExObjList();
if (exobj == null) {
return null;
}
Record[] records = shape.getClientRecords();
find(records, exobj, lst);
HSLFHyperlink[] links = null;
if (lst.size() > 0){
links = new HSLFHyperlink[lst.size()];
lst.toArray(links);
}
return links;
} }
/** /**
* Find hyperlinks in a text paragraph * Find hyperlinks in a text paragraph
* *
* @param paragraph <code>TextParagraph</code> to lookup hyperlinks in * @param paragraphs List of <code>TextParagraph</code> to lookup hyperlinks
* @return found hyperlinks or <code>null</code> if not found * @return found hyperlinks
*/ */
public static HSLFHyperlink[] find(HSLFTextParagraph paragraph){ public static List<HSLFHyperlink> find(List<HSLFTextParagraph> paragraphs){
List<HSLFHyperlink> lst = new ArrayList<HSLFHyperlink>(); List<HSLFHyperlink> lst = new ArrayList<HSLFHyperlink>();
HSLFSlideShow ppt = paragraph.getSheet().getSlideShow(); if (paragraphs == null || paragraphs.isEmpty()) return lst;
HSLFTextParagraph firstPara = paragraphs.get(0);
HSLFSlideShow ppt = firstPara.getSheet().getSlideShow();
//document-level container which stores info about all links in a presentation //document-level container which stores info about all links in a presentation
ExObjList exobj = ppt.getDocumentRecord().getExObjList(); ExObjList exobj = ppt.getDocumentRecord().getExObjList();
if (exobj == null) { if (exobj == null) return lst;
return null;
}
Record[] records = paragraph.getRecords(); Record[] records = firstPara.getRecords();
find(records, exobj, lst); find(records, exobj, lst);
HSLFHyperlink[] links = null; return lst;
if (lst.size() > 0){
links = new HSLFHyperlink[lst.size()];
lst.toArray(links);
}
return links;
} }
/** /**
@ -224,24 +205,24 @@ public final class HSLFHyperlink {
if (records == null) return; if (records == null) return;
for (int i = 0; i < records.length; i++) { for (int i = 0; i < records.length; i++) {
//see if we have InteractiveInfo in the textrun's records //see if we have InteractiveInfo in the textrun's records
if( records[i] instanceof InteractiveInfo){ if(!(records[i] instanceof InteractiveInfo)) continue;
InteractiveInfo hldr = (InteractiveInfo)records[i];
InteractiveInfoAtom info = hldr.getInteractiveInfoAtom(); InteractiveInfo hldr = (InteractiveInfo)records[i];
int id = info.getHyperlinkID(); InteractiveInfoAtom info = hldr.getInteractiveInfoAtom();
ExHyperlink linkRecord = exobj.get(id); int id = info.getHyperlinkID();
if (linkRecord != null){ ExHyperlink linkRecord = exobj.get(id);
HSLFHyperlink link = new HSLFHyperlink(); if (linkRecord == null) continue;
link.title = linkRecord.getLinkTitle();
link.address = linkRecord.getLinkURL(); HSLFHyperlink link = new HSLFHyperlink();
link.type = info.getAction(); link.title = linkRecord.getLinkTitle();
link.address = linkRecord.getLinkURL();
link.type = info.getAction();
out.add(link);
if (++i < records.length && records[i] instanceof TxInteractiveInfoAtom){ if (i+1 < records.length && records[i+1] instanceof TxInteractiveInfoAtom){
TxInteractiveInfoAtom txinfo = (TxInteractiveInfoAtom)records[i]; TxInteractiveInfoAtom txinfo = (TxInteractiveInfoAtom)records[++i];
link.startIndex = txinfo.getStartIndex(); link.startIndex = txinfo.getStartIndex();
link.endIndex = txinfo.getEndIndex(); link.endIndex = txinfo.getEndIndex();
}
out.add(link);
}
} }
} }
} }

View File

@ -62,8 +62,8 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSl
// Build up TextRuns from pairs of TextHeaderAtom and // Build up TextRuns from pairs of TextHeaderAtom and
// one of TextBytesAtom or TextCharsAtom // one of TextBytesAtom or TextCharsAtom
if (_atomSet != null && _atomSet.getSlideRecords().length > 0) { if (_atomSet != null && _atomSet.getSlideRecords().length > 0) {
List<List<HSLFTextParagraph>> llhtp = HSLFTextParagraph.findTextParagraphs(_atomSet.getSlideRecords()); // Grab text from SlideListWithTexts entries
_paragraphs.addAll(llhtp); _paragraphs.addAll(HSLFTextParagraph.findTextParagraphs(_atomSet.getSlideRecords()));
if (_paragraphs.isEmpty()) { if (_paragraphs.isEmpty()) {
throw new RuntimeException("No text records found for slide"); throw new RuntimeException("No text records found for slide");
} }
@ -71,23 +71,14 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSl
// No text on the slide, must just be pictures // No text on the slide, must just be pictures
} }
// Grab text from SlideListWithTexts entries // Grab text from slide's PPDrawing
for(List<HSLFTextParagraph> ltp : _paragraphs) { _paragraphs.addAll(HSLFTextParagraph.findTextParagraphs(getPPDrawing()));
for (HSLFTextParagraph tp : ltp) {
tp.supplySheet(this);
}
}
// Grab the TextRuns from the PPDrawing for(List<HSLFTextParagraph> ltp : _paragraphs) {
List<List<HSLFTextParagraph>> llOtherRuns = HSLFTextParagraph.findTextParagraphs(getPPDrawing()); for (HSLFTextParagraph tp : ltp) {
for (List<HSLFTextParagraph> otherRuns : llOtherRuns) { tp.supplySheet(this);
// Grab text from slide's PPDrawing }
for(HSLFTextParagraph tp : otherRuns) { }
tp.supplySheet(this);
tp.setIndex(-1); // runs found in PPDrawing are not linked with SlideListWithTexts
}
}
_paragraphs.addAll(llOtherRuns);
} }
/** /**
@ -449,19 +440,19 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSl
public void setHidden(boolean hidden) { public void setHidden(boolean hidden) {
org.apache.poi.hslf.record.Slide cont = getSlideRecord(); org.apache.poi.hslf.record.Slide cont = getSlideRecord();
SSSlideInfoAtom slideInfo = SSSlideInfoAtom slideInfo =
(SSSlideInfoAtom)cont.findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID); (SSSlideInfoAtom)cont.findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID);
if (slideInfo == null) { if (slideInfo == null) {
slideInfo = new SSSlideInfoAtom(); slideInfo = new SSSlideInfoAtom();
cont.addChildAfter(slideInfo, cont.findFirstOfType(RecordTypes.SlideAtom.typeID)); cont.addChildAfter(slideInfo, cont.findFirstOfType(RecordTypes.SlideAtom.typeID));
} }
slideInfo.setEffectTransitionFlagByBit(SSSlideInfoAtom.HIDDEN_BIT, hidden); slideInfo.setEffectTransitionFlagByBit(SSSlideInfoAtom.HIDDEN_BIT, hidden);
} }
public boolean getHidden() { public boolean getHidden() {
SSSlideInfoAtom slideInfo = SSSlideInfoAtom slideInfo =
(SSSlideInfoAtom)getSlideRecord().findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID); (SSSlideInfoAtom)getSlideRecord().findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID);
return (slideInfo == null) return (slideInfo == null)
? false ? false
@ -475,6 +466,6 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSl
public void setFollowMasterColourScheme(boolean follow) { public void setFollowMasterColourScheme(boolean follow) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
} }

View File

@ -613,7 +613,7 @@ public final class HSLFSlideShow implements SlideShow {
SlideAtomsSet[] sas = slwt.getSlideAtomsSets(); SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
List<Record> records = new ArrayList<Record>(); List<Record> records = new ArrayList<Record>();
List<SlideAtomsSet> sa = Arrays.asList(sas); List<SlideAtomsSet> sa = new ArrayList<SlideAtomsSet>(Arrays.asList(sas));
HSLFSlide removedSlide = _slides.remove(index); HSLFSlide removedSlide = _slides.remove(index);
_notes.remove(removedSlide.getNotes()); _notes.remove(removedSlide.getNotes());

View File

@ -668,11 +668,33 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
prop.setSubValue(value,index); prop.setSubValue(value,index);
} }
/**
* Check and add linebreaks to text runs leading other paragraphs
*
* @param paragraphs
*/
protected static void fixLineEndings(List<HSLFTextParagraph> paragraphs) {
HSLFTextRun lastRun = null;
for (HSLFTextParagraph p : paragraphs) {
if (lastRun != null && !lastRun.getRawText().endsWith("\r")) {
lastRun.setText(lastRun.getRawText()+"\r");
}
List<HSLFTextRun> ltr = p.getTextRuns();
if (ltr.isEmpty()) {
throw new RuntimeException("paragraph without textruns found");
}
lastRun = ltr.get(ltr.size()-1);
assert(lastRun.getRawText() != null);
}
}
/** /**
* Saves the modified paragraphs/textrun to the records. * Saves the modified paragraphs/textrun to the records.
* Also updates the styles to the correct text length. * Also updates the styles to the correct text length.
*/ */
protected static void storeText(List<HSLFTextParagraph> paragraphs) { protected static void storeText(List<HSLFTextParagraph> paragraphs) {
fixLineEndings(paragraphs);
String rawText = toInternalString(getRawText(paragraphs)); String rawText = toInternalString(getRawText(paragraphs));
// Will it fit in a 8 bit atom? // Will it fit in a 8 bit atom?
@ -738,16 +760,16 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
styleAtom.clearStyles(); styleAtom.clearStyles();
TextPropCollection lastPTPC = null, lastRTPC = null; TextPropCollection lastPTPC = null, lastRTPC = null, ptpc = null, rtpc = null;
for (HSLFTextParagraph para : paragraphs) { for (HSLFTextParagraph para : paragraphs) {
TextPropCollection ptpc = para.getParagraphStyle(); ptpc = para.getParagraphStyle();
ptpc.updateTextSize(0); ptpc.updateTextSize(0);
if (!ptpc.equals(lastPTPC)) { if (!ptpc.equals(lastPTPC)) {
lastPTPC = styleAtom.addParagraphTextPropCollection(0); lastPTPC = styleAtom.addParagraphTextPropCollection(0);
lastPTPC.copy(ptpc); lastPTPC.copy(ptpc);
} }
for (HSLFTextRun tr : para.getTextRuns()) { for (HSLFTextRun tr : para.getTextRuns()) {
TextPropCollection rtpc = tr.getCharacterStyle(); rtpc = tr.getCharacterStyle();
rtpc.updateTextSize(0); rtpc.updateTextSize(0);
if (!rtpc.equals(lastRTPC)) { if (!rtpc.equals(lastRTPC)) {
lastRTPC = styleAtom.addCharacterTextPropCollection(0); lastRTPC = styleAtom.addCharacterTextPropCollection(0);
@ -761,7 +783,9 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
} }
} }
assert(lastPTPC != null && lastRTPC != null); assert(lastPTPC != null && lastRTPC != null && ptpc != null && rtpc != null);
ptpc.updateTextSize(ptpc.getCharactersCovered()+1);
rtpc.updateTextSize(rtpc.getCharactersCovered()+1);
lastPTPC.updateTextSize(lastPTPC.getCharactersCovered()+1); lastPTPC.updateTextSize(lastPTPC.getCharactersCovered()+1);
lastRTPC.updateTextSize(lastRTPC.getCharactersCovered()+1); lastRTPC.updateTextSize(lastRTPC.getCharactersCovered()+1);
@ -817,6 +841,8 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
} }
htr.setText(rawText); htr.setText(rawText);
} }
storeText(paragraphs);
return htr; return htr;
} }
@ -909,16 +935,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
public static List<List<HSLFTextParagraph>> findTextParagraphs(PPDrawing ppdrawing) { public static List<List<HSLFTextParagraph>> findTextParagraphs(PPDrawing ppdrawing) {
List<List<HSLFTextParagraph>> runsV = new ArrayList<List<HSLFTextParagraph>>(); List<List<HSLFTextParagraph>> runsV = new ArrayList<List<HSLFTextParagraph>>();
for (EscherTextboxWrapper wrapper : ppdrawing.getTextboxWrappers()) { for (EscherTextboxWrapper wrapper : ppdrawing.getTextboxWrappers()) {
// propagate parents to parent-aware records runsV.addAll(findTextParagraphs(wrapper));
RecordContainer.handleParentAwareRecords(wrapper);
int shapeId = wrapper.getShapeId();
List<List<HSLFTextParagraph>> rv = findTextParagraphs(wrapper);
for (List<HSLFTextParagraph> htpList : rv) {
for (HSLFTextParagraph htp : htpList) {
htp.setShapeId(shapeId);
}
}
runsV.addAll(rv);
} }
return runsV; return runsV;
} }
@ -940,8 +957,17 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
* *
* @param wrapper an EscherTextboxWrapper * @param wrapper an EscherTextboxWrapper
*/ */
protected static List<List<HSLFTextParagraph>> findTextParagraphs(final EscherTextboxWrapper wrapper) { protected static List<List<HSLFTextParagraph>> findTextParagraphs(EscherTextboxWrapper wrapper) {
return findTextParagraphs(wrapper.getChildRecords(), wrapper.getStyleTextProp9Atom()); // propagate parents to parent-aware records
RecordContainer.handleParentAwareRecords(wrapper);
int shapeId = wrapper.getShapeId();
List<List<HSLFTextParagraph>> rv = findTextParagraphs(wrapper.getChildRecords(), wrapper.getStyleTextProp9Atom());
for (List<HSLFTextParagraph> htpList : rv) {
for (HSLFTextParagraph htp : htpList) {
htp.setShapeId(shapeId);
}
}
return rv;
} }
/** /**
@ -999,7 +1025,8 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
} }
assert(header != null); assert(header != null);
if (header.getIndex() == -1) { if (header.getParentRecord() instanceof SlideListWithText) {
// runs found in PPDrawing are not linked with SlideListWithTexts
header.setIndex(slwtIndex); header.setIndex(slwtIndex);
} }

View File

@ -383,6 +383,10 @@ public final class HSLFTextRun implements TextRun {
prop.setSubValue(value, index); prop.setSubValue(value, index);
} }
public HSLFTextParagraph getTextParagraph() {
return parentParagraph;
}
public TextCap getTextCap() { public TextCap getTextCap() {
return TextCap.NONE; return TextCap.NONE;
} }

View File

@ -750,7 +750,7 @@ public abstract class HSLFTextShape extends HSLFSimpleShape implements TextShape
* @return the array of all hyperlinks in this text run or <code>null</code> * @return the array of all hyperlinks in this text run or <code>null</code>
* if not found. * if not found.
*/ */
public HSLFHyperlink[] getHyperlinks() { public List<HSLFHyperlink> getHyperlinks() {
return HSLFHyperlink.find(this); return HSLFHyperlink.find(this);
} }

View File

@ -53,17 +53,17 @@ public final class TestHyperlink {
"In addition, its notes has one link"; "In addition, its notes has one link";
assertEquals(expected, rawText); assertEquals(expected, rawText);
HSLFHyperlink[] links = HSLFHyperlink.find(para.get(1)); List<HSLFHyperlink> links = HSLFHyperlink.find(para);
assertNotNull(links); assertNotNull(links);
assertEquals(2, links.length); assertEquals(2, links.size());
assertEquals("http://jakarta.apache.org/poi/", links[0].getTitle()); assertEquals("http://jakarta.apache.org/poi/", links.get(0).getTitle());
assertEquals("http://jakarta.apache.org/poi/", links[0].getAddress()); assertEquals("http://jakarta.apache.org/poi/", links.get(0).getAddress());
assertEquals("http://jakarta.apache.org/poi/", rawText.substring(links[0].getStartIndex(), links[0].getEndIndex()-1)); assertEquals("http://jakarta.apache.org/poi/", rawText.substring(links.get(0).getStartIndex(), links.get(0).getEndIndex()-1));
assertEquals("http://slashdot.org/", links[1].getTitle()); assertEquals("http://slashdot.org/", links.get(1).getTitle());
assertEquals("http://slashdot.org/", links[1].getAddress()); assertEquals("http://slashdot.org/", links.get(1).getAddress());
assertEquals("http://slashdot.org/", rawText.substring(links[1].getStartIndex(), links[1].getEndIndex()-1)); assertEquals("http://slashdot.org/", rawText.substring(links.get(1).getStartIndex(), links.get(1).getEndIndex()-1));
slide = ppt.getSlides().get(1); slide = ppt.getSlides().get(1);
para = slide.getTextParagraphs().get(1); para = slide.getTextParagraphs().get(1);
@ -73,12 +73,12 @@ public final class TestHyperlink {
"Jakarta HSSF"; "Jakarta HSSF";
assertEquals(expected, rawText); assertEquals(expected, rawText);
links = HSLFHyperlink.find(para.get(1)); links = HSLFHyperlink.find(para);
assertNotNull(links); assertNotNull(links);
assertEquals(1, links.length); assertEquals(1, links.size());
assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getTitle()); assertEquals("http://jakarta.apache.org/poi/hssf/", links.get(0).getTitle());
assertEquals("http://jakarta.apache.org/poi/hssf/", links[0].getAddress()); assertEquals("http://jakarta.apache.org/poi/hssf/", links.get(0).getAddress());
assertEquals("Jakarta HSSF", rawText.substring(links[0].getStartIndex(), links[0].getEndIndex()-1)); assertEquals("Jakarta HSSF", rawText.substring(links.get(0).getStartIndex(), links.get(0).getEndIndex()-1));
} }
} }

View File

@ -143,8 +143,9 @@ public class TestDocumentEncryption {
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs); HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
HSLFSlideShow ss = new HSLFSlideShow(hss); HSLFSlideShow ss = new HSLFSlideShow(hss);
HSLFSlide slide = ss.getSlides()[0]; HSLFSlide slide = ss.getSlides().get(0);
assertEquals("Dominic Salemno", slide.getTextParagraphs()[0].getRawText()); String rawText = HSLFTextParagraph.getRawText(slide.getTextParagraphs().get(0));
assertEquals("Dominic Salemno", rawText);
String picCmp[][] = { String picCmp[][] = {
{"0","nKsDTKqxTCR8LFkVVWlP9GSTvZ0="}, {"0","nKsDTKqxTCR8LFkVVWlP9GSTvZ0="},

View File

@ -85,8 +85,8 @@ public final class TestSlideAtom extends TestCase {
ss.write(bos); ss.write(bos);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ss = new HSLFSlideShow(bis); ss = new HSLFSlideShow(bis);
slide1 = ss.getSlides()[0]; slide1 = ss.getSlides().get(0);
slide2 = ss.getSlides()[1]; slide2 = ss.getSlides().get(1);
assertFalse(slide1.getHidden()); assertFalse(slide1.getHidden());
assertTrue(slide2.getHidden()); assertTrue(slide2.getHidden());
} }

View File

@ -21,13 +21,11 @@ import static org.junit.Assert.assertArrayEquals;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList; import java.util.List;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp; import org.apache.poi.hslf.model.textproperties.*;
import org.apache.poi.hslf.model.textproperties.TextProp;
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
import org.apache.poi.util.HexDump; import org.apache.poi.util.HexDump;
/** /**
@ -188,7 +186,7 @@ public final class TestStyleTextPropAtom extends TestCase {
stpb.setParentTextSize(data_b_text_len); stpb.setParentTextSize(data_b_text_len);
// 54 chars, 21 + 17 + 16 // 54 chars, 21 + 17 + 16
LinkedList<TextPropCollection> a_ch_l = stpa.getCharacterStyles(); List<TextPropCollection> a_ch_l = stpa.getCharacterStyles();
TextPropCollection a_ch_1 = a_ch_l.get(0); TextPropCollection a_ch_1 = a_ch_l.get(0);
TextPropCollection a_ch_2 = a_ch_l.get(1); TextPropCollection a_ch_2 = a_ch_l.get(1);
TextPropCollection a_ch_3 = a_ch_l.get(2); TextPropCollection a_ch_3 = a_ch_l.get(2);
@ -197,7 +195,7 @@ public final class TestStyleTextPropAtom extends TestCase {
assertEquals(16, a_ch_3.getCharactersCovered()); assertEquals(16, a_ch_3.getCharactersCovered());
// 179 chars, 30 + 28 + 25 // 179 chars, 30 + 28 + 25
LinkedList<TextPropCollection> b_ch_l = stpb.getCharacterStyles(); List<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
TextPropCollection b_ch_1 = b_ch_l.get(0); TextPropCollection b_ch_1 = b_ch_l.get(0);
TextPropCollection b_ch_2 = b_ch_l.get(1); TextPropCollection b_ch_2 = b_ch_l.get(1);
TextPropCollection b_ch_3 = b_ch_l.get(2); TextPropCollection b_ch_3 = b_ch_l.get(2);
@ -213,7 +211,7 @@ public final class TestStyleTextPropAtom extends TestCase {
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
stpb.setParentTextSize(data_b_text_len); stpb.setParentTextSize(data_b_text_len);
LinkedList<TextPropCollection> b_ch_l = stpb.getCharacterStyles(); List<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
TextPropCollection b_ch_1 = b_ch_l.get(0); TextPropCollection b_ch_1 = b_ch_l.get(0);
TextPropCollection b_ch_2 = b_ch_l.get(1); TextPropCollection b_ch_2 = b_ch_l.get(1);
TextPropCollection b_ch_3 = b_ch_l.get(2); TextPropCollection b_ch_3 = b_ch_l.get(2);
@ -260,7 +258,7 @@ public final class TestStyleTextPropAtom extends TestCase {
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
stpb.setParentTextSize(data_b_text_len); stpb.setParentTextSize(data_b_text_len);
LinkedList<TextPropCollection> b_p_l = stpb.getParagraphStyles(); List<TextPropCollection> b_p_l = stpb.getParagraphStyles();
TextPropCollection b_p_1 = b_p_l.get(0); TextPropCollection b_p_1 = b_p_l.get(0);
TextPropCollection b_p_2 = b_p_l.get(1); TextPropCollection b_p_2 = b_p_l.get(1);
TextPropCollection b_p_3 = b_p_l.get(2); TextPropCollection b_p_3 = b_p_l.get(2);
@ -304,7 +302,7 @@ public final class TestStyleTextPropAtom extends TestCase {
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
stpb.setParentTextSize(data_b_text_len); stpb.setParentTextSize(data_b_text_len);
LinkedList<TextPropCollection> b_ch_l = stpb.getCharacterStyles(); List<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
TextPropCollection b_ch_1 = b_ch_l.get(0); TextPropCollection b_ch_1 = b_ch_l.get(0);
TextPropCollection b_ch_2 = b_ch_l.get(1); TextPropCollection b_ch_2 = b_ch_l.get(1);
TextPropCollection b_ch_3 = b_ch_l.get(2); TextPropCollection b_ch_3 = b_ch_l.get(2);
@ -375,13 +373,13 @@ public final class TestStyleTextPropAtom extends TestCase {
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
stpb.setParentTextSize(data_b_text_len); stpb.setParentTextSize(data_b_text_len);
LinkedList<TextPropCollection> b_p_l = stpb.getParagraphStyles(); List<TextPropCollection> b_p_l = stpb.getParagraphStyles();
TextPropCollection b_p_1 = b_p_l.get(0); TextPropCollection b_p_1 = b_p_l.get(0);
TextPropCollection b_p_2 = b_p_l.get(1); TextPropCollection b_p_2 = b_p_l.get(1);
TextPropCollection b_p_3 = b_p_l.get(2); TextPropCollection b_p_3 = b_p_l.get(2);
TextPropCollection b_p_4 = b_p_l.get(3); TextPropCollection b_p_4 = b_p_l.get(3);
LinkedList<TextPropCollection> b_ch_l = stpb.getCharacterStyles(); List<TextPropCollection> b_ch_l = stpb.getCharacterStyles();
TextPropCollection b_ch_1 = b_ch_l.get(0); TextPropCollection b_ch_1 = b_ch_l.get(0);
TextPropCollection b_ch_2 = b_ch_l.get(1); TextPropCollection b_ch_2 = b_ch_l.get(1);
TextPropCollection b_ch_3 = b_ch_l.get(2); TextPropCollection b_ch_3 = b_ch_l.get(2);
@ -431,7 +429,7 @@ public final class TestStyleTextPropAtom extends TestCase {
// Don't need to touch the paragraph styles // Don't need to touch the paragraph styles
// Add two more character styles // Add two more character styles
LinkedList<TextPropCollection> cs = stpa.getCharacterStyles(); List<TextPropCollection> cs = stpa.getCharacterStyles();
// First char style is boring, and 21 long // First char style is boring, and 21 long
TextPropCollection tpca = cs.get(0); TextPropCollection tpca = cs.get(0);
@ -468,7 +466,7 @@ public final class TestStyleTextPropAtom extends TestCase {
// Need 4 paragraph styles // Need 4 paragraph styles
LinkedList<TextPropCollection> ps = stpa.getParagraphStyles(); List<TextPropCollection> ps = stpa.getParagraphStyles();
// First is 30 long, left aligned, normal spacing // First is 30 long, left aligned, normal spacing
TextPropCollection tppa = ps.get(0); TextPropCollection tppa = ps.get(0);
@ -503,7 +501,7 @@ public final class TestStyleTextPropAtom extends TestCase {
// Now do 4 character styles // Now do 4 character styles
LinkedList<TextPropCollection> cs = stpa.getCharacterStyles(); List<TextPropCollection> cs = stpa.getCharacterStyles();
// First is 30 long, bold and font size // First is 30 long, bold and font size
TextPropCollection tpca = cs.get(0); TextPropCollection tpca = cs.get(0);
@ -568,16 +566,16 @@ public final class TestStyleTextPropAtom extends TestCase {
// Compare in detail to b // Compare in detail to b
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
stpb.setParentTextSize(data_b_text_len); stpb.setParentTextSize(data_b_text_len);
LinkedList<TextPropCollection> psb = stpb.getParagraphStyles(); List<TextPropCollection> psb = stpb.getParagraphStyles();
LinkedList<TextPropCollection> csb = stpb.getCharacterStyles(); List<TextPropCollection> csb = stpb.getCharacterStyles();
assertEquals(psb.size(), ps.size()); assertEquals(psb.size(), ps.size());
assertEquals(csb.size(), cs.size()); assertEquals(csb.size(), cs.size());
// Ensure Paragraph Character styles match // Ensure Paragraph Character styles match
for(int z=0; z<2; z++) { for(int z=0; z<2; z++) {
LinkedList<TextPropCollection> lla = cs; List<TextPropCollection> lla = cs;
LinkedList<TextPropCollection> llb = csb; List<TextPropCollection> llb = csb;
int upto = 5; int upto = 5;
if(z == 1) { if(z == 1) {
lla = ps; lla = ps;
@ -605,8 +603,8 @@ public final class TestStyleTextPropAtom extends TestCase {
ByteArrayOutputStream ba = new ByteArrayOutputStream(); ByteArrayOutputStream ba = new ByteArrayOutputStream();
ByteArrayOutputStream bb = new ByteArrayOutputStream(); ByteArrayOutputStream bb = new ByteArrayOutputStream();
ca.writeOut(ba); ca.writeOut(ba, StyleTextPropAtom.characterTextPropTypes);
cb.writeOut(bb); cb.writeOut(bb, StyleTextPropAtom.characterTextPropTypes);
byte[] cab = ba.toByteArray(); byte[] cab = ba.toByteArray();
byte[] cbb = bb.toByteArray(); byte[] cbb = bb.toByteArray();
@ -695,12 +693,12 @@ public final class TestStyleTextPropAtom extends TestCase {
StyleTextPropAtom atom = new StyleTextPropAtom(data_d, 0, data_d.length); StyleTextPropAtom atom = new StyleTextPropAtom(data_d, 0, data_d.length);
atom.setParentTextSize(data_d_text_len); atom.setParentTextSize(data_d_text_len);
TextPropCollection prprops = atom.getParagraphStyles().getFirst(); TextPropCollection prprops = atom.getParagraphStyles().get(0);
assertEquals(data_d_text_len+1, prprops.getCharactersCovered()); assertEquals(data_d_text_len+1, prprops.getCharactersCovered());
assertEquals(1, prprops.getTextPropList().size()); //1 property found assertEquals(1, prprops.getTextPropList().size()); //1 property found
assertEquals(1, prprops.findByName("alignment").getValue()); assertEquals(1, prprops.findByName("alignment").getValue());
TextPropCollection chprops = atom.getCharacterStyles().getFirst(); TextPropCollection chprops = atom.getCharacterStyles().get(0);
assertEquals(data_d_text_len+1, chprops.getCharactersCovered()); assertEquals(data_d_text_len+1, chprops.getCharactersCovered());
assertEquals(5, chprops.getTextPropList().size()); //5 properties found assertEquals(5, chprops.getTextPropList().size()); //5 properties found
assertEquals(1, chprops.findByName("char_flags").getValue()); assertEquals(1, chprops.findByName("char_flags").getValue());

View File

@ -20,16 +20,12 @@ package org.apache.poi.hslf.usermodel;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.List;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hslf.*;
import org.apache.poi.hslf.record.Record;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.record.UserEditAtom;
import org.apache.poi.hslf.record.Document;
import org.apache.poi.hslf.model.*;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.hslf.record.*;
/** /**
* Tests that SlideShow adds additional sheets properly * Tests that SlideShow adds additional sheets properly
@ -70,7 +66,7 @@ public final class TestAddingSlides extends TestCase {
*/ */
public void testAddSlideToEmpty() throws Exception { public void testAddSlideToEmpty() throws Exception {
// Doesn't have any slides // Doesn't have any slides
assertEquals(0, ss_empty.getSlides().length); assertEquals(0, ss_empty.getSlides().size());
// Should only have a master SLWT // Should only have a master SLWT
assertEquals(1, ss_empty.getDocumentRecord().getSlideListWithTexts().length); assertEquals(1, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
@ -88,7 +84,7 @@ public final class TestAddingSlides extends TestCase {
// Add one // Add one
HSLFSlide slide = ss_empty.createSlide(); HSLFSlide slide = ss_empty.createSlide();
assertEquals(1, ss_empty.getSlides().length); assertEquals(1, ss_empty.getSlides().size());
assertEquals(256, slide._getSheetNumber()); assertEquals(256, slide._getSheetNumber());
assertEquals(3, slide._getSheetRefId()); assertEquals(3, slide._getSheetRefId());
assertEquals(1, slide.getSlideNumber()); assertEquals(1, slide.getSlideNumber());
@ -103,13 +99,13 @@ public final class TestAddingSlides extends TestCase {
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read); HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
// Check it now has a slide // Check it now has a slide
assertEquals(1, ss_read.getSlides().length); assertEquals(1, ss_read.getSlides().size());
// Check it now has two SLWTs // Check it now has two SLWTs
assertEquals(2, ss_empty.getDocumentRecord().getSlideListWithTexts().length); assertEquals(2, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
// And check it's as expected // And check it's as expected
slide = ss_read.getSlides()[0]; slide = ss_read.getSlides().get(0);
assertEquals(256, slide._getSheetNumber()); assertEquals(256, slide._getSheetNumber());
assertEquals(3, slide._getSheetRefId()); assertEquals(3, slide._getSheetRefId());
assertEquals(1, slide.getSlideNumber()); assertEquals(1, slide.getSlideNumber());
@ -120,8 +116,8 @@ public final class TestAddingSlides extends TestCase {
*/ */
public void testAddSlideToExisting() throws Exception { public void testAddSlideToExisting() throws Exception {
// Has one slide // Has one slide
assertEquals(1, ss_one.getSlides().length); assertEquals(1, ss_one.getSlides().size());
HSLFSlide s1 = ss_one.getSlides()[0]; HSLFSlide s1 = ss_one.getSlides().get(0);
// Should have two SLTWs // Should have two SLTWs
assertEquals(2, ss_one.getDocumentRecord().getSlideListWithTexts().length); assertEquals(2, ss_one.getDocumentRecord().getSlideListWithTexts().length);
@ -133,7 +129,7 @@ public final class TestAddingSlides extends TestCase {
// Add a second one // Add a second one
HSLFSlide s2 = ss_one.createSlide(); HSLFSlide s2 = ss_one.createSlide();
assertEquals(2, ss_one.getSlides().length); assertEquals(2, ss_one.getSlides().size());
assertEquals(257, s2._getSheetNumber()); assertEquals(257, s2._getSheetNumber());
assertEquals(4, s2._getSheetRefId()); assertEquals(4, s2._getSheetRefId());
assertEquals(2, s2.getSlideNumber()); assertEquals(2, s2.getSlideNumber());
@ -147,14 +143,14 @@ public final class TestAddingSlides extends TestCase {
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read); HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
// Check it now has two slides // Check it now has two slides
assertEquals(2, ss_read.getSlides().length); assertEquals(2, ss_read.getSlides().size());
// Should still have two SLTWs // Should still have two SLTWs
assertEquals(2, ss_read.getDocumentRecord().getSlideListWithTexts().length); assertEquals(2, ss_read.getDocumentRecord().getSlideListWithTexts().length);
// And check it's as expected // And check it's as expected
s1 = ss_read.getSlides()[0]; s1 = ss_read.getSlides().get(0);
s2 = ss_read.getSlides()[1]; s2 = ss_read.getSlides().get(1);
assertEquals(256, s1._getSheetNumber()); assertEquals(256, s1._getSheetNumber());
assertEquals(3, s1._getSheetRefId()); assertEquals(3, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber()); assertEquals(1, s1.getSlideNumber());
@ -167,7 +163,8 @@ public final class TestAddingSlides extends TestCase {
* Test adding a slide to an existing slideshow, * Test adding a slide to an existing slideshow,
* with two slides already * with two slides already
*/ */
public void testAddSlideToExisting2() throws Exception { @SuppressWarnings("unused")
public void testAddSlideToExisting2() throws Exception {
//grab UserEditAtom //grab UserEditAtom
UserEditAtom usredit = null; UserEditAtom usredit = null;
Record[] _records = hss_two.getRecords(); Record[] _records = hss_two.getRecords();
@ -180,9 +177,9 @@ public final class TestAddingSlides extends TestCase {
assertNotNull(usredit); assertNotNull(usredit);
// Has two slides // Has two slides
assertEquals(2, ss_two.getSlides().length); assertEquals(2, ss_two.getSlides().size());
HSLFSlide s1 = ss_two.getSlides()[0]; HSLFSlide s1 = ss_two.getSlides().get(0);
HSLFSlide s2 = ss_two.getSlides()[1]; HSLFSlide s2 = ss_two.getSlides().get(1);
// Check slide 1 is as expected // Check slide 1 is as expected
assertEquals(256, s1._getSheetNumber()); assertEquals(256, s1._getSheetNumber());
@ -195,7 +192,7 @@ public final class TestAddingSlides extends TestCase {
// Add a third one // Add a third one
HSLFSlide s3 = ss_two.createSlide(); HSLFSlide s3 = ss_two.createSlide();
assertEquals(3, ss_two.getSlides().length); assertEquals(3, ss_two.getSlides().size());
assertEquals(258, s3._getSheetNumber()); assertEquals(258, s3._getSheetNumber());
assertEquals(8, s3._getSheetRefId()); // lots of notes before us assertEquals(8, s3._getSheetRefId()); // lots of notes before us
assertEquals(3, s3.getSlideNumber()); assertEquals(3, s3.getSlideNumber());
@ -210,12 +207,12 @@ public final class TestAddingSlides extends TestCase {
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read); HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
// Check it now has three slides // Check it now has three slides
assertEquals(3, ss_read.getSlides().length); assertEquals(3, ss_read.getSlides().size());
// And check it's as expected // And check it's as expected
s1 = ss_read.getSlides()[0]; s1 = ss_read.getSlides().get(0);
s2 = ss_read.getSlides()[1]; s2 = ss_read.getSlides().get(1);
s3 = ss_read.getSlides()[2]; s3 = ss_read.getSlides().get(2);
assertEquals(256, s1._getSheetNumber()); assertEquals(256, s1._getSheetNumber());
assertEquals(4, s1._getSheetRefId()); assertEquals(4, s1._getSheetRefId());
assertEquals(1, s1.getSlideNumber()); assertEquals(1, s1.getSlideNumber());
@ -235,8 +232,8 @@ public final class TestAddingSlides extends TestCase {
HSLFSlide slide1 = ppt.createSlide(); HSLFSlide slide1 = ppt.createSlide();
HSLFSlide slide2 = ppt.createSlide(); HSLFSlide slide2 = ppt.createSlide();
HSLFSlide[] s1 = ppt.getSlides(); List<HSLFSlide> s1 = ppt.getSlides();
assertEquals(2, s1.length); assertEquals(2, s1.size());
try { try {
ppt.removeSlide(-1); ppt.removeSlide(-1);
fail("expected exception"); fail("expected exception");
@ -254,10 +251,10 @@ public final class TestAddingSlides extends TestCase {
assertEquals(1, slide1.getSlideNumber()); assertEquals(1, slide1.getSlideNumber());
HSLFSlide removedSlide = ppt.removeSlide(0); HSLFSlide removedSlide = ppt.removeSlide(0);
HSLFSlide[] s2 = ppt.getSlides(); List<HSLFSlide> s2 = ppt.getSlides();
assertEquals(1, s2.length); assertEquals(1, s2.size());
assertSame(slide1, removedSlide); assertSame(slide1, removedSlide);
assertSame(slide2, s2[0]); assertSame(slide2, s2.get(0));
assertEquals(0, slide2.getSlideNumber()); assertEquals(0, slide2.getSlideNumber());
@ -266,29 +263,29 @@ public final class TestAddingSlides extends TestCase {
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray())); ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
HSLFSlide[] s3 = ppt.getSlides(); List<HSLFSlide> s3 = ppt.getSlides();
assertEquals(1, s3.length); assertEquals(1, s3.size());
} }
public void test47261() throws Exception { public void test47261() throws Exception {
POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("47261.ppt")); HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("47261.ppt"));
HSLFSlide[] slides = ppt.getSlides(); List<HSLFSlide> slides = ppt.getSlides();
Document doc = ppt.getDocumentRecord(); Document doc = ppt.getDocumentRecord();
assertNotNull(doc.getSlideSlideListWithText()); assertNotNull(doc.getSlideSlideListWithText());
assertEquals(14, ppt.getSlides().length); assertEquals(14, ppt.getSlides().size());
int notesId = slides[0].getSlideRecord().getSlideAtom().getNotesID(); int notesId = slides.get(0).getSlideRecord().getSlideAtom().getNotesID();
assertTrue(notesId > 0); assertTrue(notesId > 0);
assertNotNull(doc.getNotesSlideListWithText()); assertNotNull(doc.getNotesSlideListWithText());
assertEquals(14, doc.getNotesSlideListWithText().getSlideAtomsSets().length); assertEquals(14, doc.getNotesSlideListWithText().getSlideAtomsSets().length);
//remove all slides, corresponding notes should be removed too //remove all slides, corresponding notes should be removed too
for (int i = 0; i < slides.length; i++) { for (int i = 0; i < slides.size(); i++) {
ppt.removeSlide(0); ppt.removeSlide(0);
} }
assertEquals(0, ppt.getSlides().length); assertEquals(0, ppt.getSlides().size());
assertEquals(0, ppt.getNotes().length); assertEquals(0, ppt.getNotes().size());
assertNull(doc.getSlideSlideListWithText()); assertNull(doc.getSlideSlideListWithText());
assertNull(doc.getNotesSlideListWithText()); assertNull(doc.getNotesSlideListWithText());

View File

@ -17,7 +17,7 @@
package org.apache.poi.hslf.usermodel; package org.apache.poi.hslf.usermodel;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -73,7 +73,7 @@ public final class TestBugs {
HSLFSlideShow ppt = new HSLFSlideShow(hslf); HSLFSlideShow ppt = new HSLFSlideShow(hslf);
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
assertEquals(1, ppt.getSlides().length); assertEquals(1, ppt.getSlides().size());
HSLFPictureData[] pict = ppt.getPictureData(); HSLFPictureData[] pict = ppt.getPictureData();
assertEquals(2, pict.length); assertEquals(2, pict.length);
@ -91,23 +91,23 @@ public final class TestBugs {
HSLFSlideShow ppt = new HSLFSlideShow(hslf); HSLFSlideShow ppt = new HSLFSlideShow(hslf);
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
assertEquals(2, ppt.getSlides().length); assertEquals(2, ppt.getSlides().size());
HSLFTextParagraph txrun; List<HSLFTextParagraph> txrun;
HSLFNotes notes; HSLFNotes notes;
notes = ppt.getSlides()[0].getNotesSheet(); notes = ppt.getSlides().get(0).getNotes();
assertNotNull(notes); assertNotNull(notes);
txrun = notes.getTextParagraphs()[0]; txrun = notes.getTextParagraphs().get(0);
assertEquals("Notes-1", txrun.getRawText()); assertEquals("Notes-1", HSLFTextParagraph.getRawText(txrun));
assertEquals(false, txrun.getTextRuns()[0].isBold()); assertEquals(false, txrun.get(0).getTextRuns().get(0).isBold());
//notes for the second slide are in bold //notes for the second slide are in bold
notes = ppt.getSlides()[1].getNotesSheet(); notes = ppt.getSlides().get(1).getNotes();
assertNotNull(notes); assertNotNull(notes);
txrun = notes.getTextParagraphs()[0]; txrun = notes.getTextParagraphs().get(0);
assertEquals("Notes-2", txrun.getRawText()); assertEquals("Notes-2", HSLFTextParagraph.getRawText(txrun));
assertEquals(true, txrun.getTextRuns()[0].isBold()); assertEquals(true, txrun.get(0).getTextRuns().get(0).isBold());
} }
@ -128,13 +128,12 @@ public final class TestBugs {
notesMap.put(Integer.valueOf(7), "Although multiply and square root are easier"); notesMap.put(Integer.valueOf(7), "Although multiply and square root are easier");
notesMap.put(Integer.valueOf(8), "The bus Z is split into Z_H and Z_L"); notesMap.put(Integer.valueOf(8), "The bus Z is split into Z_H and Z_L");
HSLFSlide[] slide = ppt.getSlides(); for (HSLFSlide slide : ppt.getSlides()) {
for (int i = 0; i < slide.length; i++) { Integer slideNumber = Integer.valueOf(slide.getSlideNumber());
Integer slideNumber = Integer.valueOf(slide[i].getSlideNumber()); HSLFNotes notes = slide.getNotes();
HSLFNotes notes = slide[i].getNotesSheet();
if (notesMap.containsKey(slideNumber)){ if (notesMap.containsKey(slideNumber)){
assertNotNull(notes); assertNotNull(notes);
String text = notes.getTextParagraphs()[0].getRawText(); String text = HSLFTextParagraph.getRawText(notes.getTextParagraphs().get(0));
String startingPhrase = notesMap.get(slideNumber); String startingPhrase = notesMap.get(slideNumber);
assertTrue("Notes for slide " + slideNumber + " must start with " + assertTrue("Notes for slide " + slideNumber + " must start with " +
startingPhrase , text.startsWith(startingPhrase)); startingPhrase , text.startsWith(startingPhrase));
@ -150,14 +149,12 @@ public final class TestBugs {
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt")); HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
HSLFSlideShow ppt = new HSLFSlideShow(hslf); HSLFSlideShow ppt = new HSLFSlideShow(hslf);
HSLFShape[] shape = ppt.getSlides()[0].getShapes(); for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
for (int i = 0; i < shape.length; i++) { if(shape instanceof HSLFGroupShape){
if(shape[i] instanceof HSLFGroupShape){ HSLFGroupShape group = (HSLFGroupShape)shape;
HSLFGroupShape group = (HSLFGroupShape)shape[i]; for (HSLFShape sh : group.getShapes()) {
HSLFShape[] sh = group.getShapes(); if(sh instanceof HSLFTextBox){
for (int j = 0; j < sh.length; j++) { HSLFTextBox txt = (HSLFTextBox)sh;
if( sh[j] instanceof HSLFTextBox){
HSLFTextBox txt = (HSLFTextBox)sh[j];
assertNotNull(txt.getTextParagraphs()); assertNotNull(txt.getTextParagraphs());
} }
} }
@ -173,14 +170,12 @@ public final class TestBugs {
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt")); HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
HSLFSlideShow ppt = new HSLFSlideShow(hslf); HSLFSlideShow ppt = new HSLFSlideShow(hslf);
HSLFShape[] shape = ppt.getSlides()[0].getShapes(); for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
for (int i = 0; i < shape.length; i++) { if(shape instanceof HSLFGroupShape){
if(shape[i] instanceof HSLFGroupShape){ HSLFGroupShape group = (HSLFGroupShape)shape;
HSLFGroupShape group = (HSLFGroupShape)shape[i];
assertNotNull(group.getAnchor()); assertNotNull(group.getAnchor());
HSLFShape[] sh = group.getShapes(); for (HSLFShape sh : group.getShapes()) {
for (int j = 0; j < sh.length; j++) { assertNotNull(sh.getAnchor());
assertNotNull(sh[j].getAnchor());
} }
} }
} }
@ -197,28 +192,28 @@ public final class TestBugs {
HSLFSlideShow ppt = new HSLFSlideShow(hslf); HSLFSlideShow ppt = new HSLFSlideShow(hslf);
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
assertEquals(1, ppt.getSlidesMasters().length); assertEquals(1, ppt.getSlideMasters().size());
assertEquals(1, ppt.getTitleMasters().length); assertEquals(1, ppt.getTitleMasters().size());
HSLFSlide[] slide = ppt.getSlides(); boolean isFirst = true;
for (int i = 0; i < slide.length; i++) { for (HSLFSlide slide : ppt.getSlides()) {
HSLFMasterSheet master = slide[i].getMasterSheet(); HSLFMasterSheet master = slide.getMasterSheet();
if (i == 0) assertTrue(master instanceof HSLFTitleMaster); //the first slide follows TitleMaster // the first slide follows TitleMaster
else assertTrue(master instanceof HSLFSlideMaster); assertTrue(isFirst ? master instanceof HSLFTitleMaster : master instanceof HSLFSlideMaster);
isFirst = false;
} }
} }
/** /**
* Bug 42486: Failure parsing a seemingly valid PPT * Bug 42486: Failure parsing a seemingly valid PPT
*/ */
@SuppressWarnings("unused")
@Test @Test
public void bug42486 () throws Exception { public void bug42486 () throws Exception {
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt")); HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt"));
HSLFSlideShow ppt = new HSLFSlideShow(hslf); HSLFSlideShow ppt = new HSLFSlideShow(hslf);
HSLFSlide[] slide = ppt.getSlides(); for (HSLFSlide slide : ppt.getSlides()) {
for (int i = 0; i < slide.length; i++) { List<HSLFShape> shape = slide.getShapes();
@SuppressWarnings("unused")
HSLFShape[] shape = slide[i].getShapes();
} }
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
@ -233,16 +228,13 @@ public final class TestBugs {
HSLFSlideShow ppt = new HSLFSlideShow(hslf); HSLFSlideShow ppt = new HSLFSlideShow(hslf);
//walk down the tree and see if there were no errors while reading //walk down the tree and see if there were no errors while reading
HSLFSlide[] slide = ppt.getSlides(); for (HSLFSlide slide : ppt.getSlides()) {
for (int i = 0; i < slide.length; i++) { for (HSLFShape shape : slide.getShapes()) {
HSLFShape[] shape = slide[i].getShapes(); assertNotNull(shape.getShapeName());
for (int j = 0; j < shape.length; j++) { if (shape instanceof HSLFGroupShape){
assertNotNull(shape[j].getShapeName()); HSLFGroupShape group = (HSLFGroupShape)shape;
if (shape[j] instanceof HSLFGroupShape){ for (HSLFShape comps : group.getShapes()) {
HSLFGroupShape group = (HSLFGroupShape)shape[j]; assertNotNull(comps.getShapeName());
HSLFShape[] comps = group.getShapes();
for (int k = 0; k < comps.length; k++) {
assertNotNull(comps[k].getShapeName());
} }
} }
} }
@ -255,6 +247,7 @@ public final class TestBugs {
/** /**
* Bug 42520: NPE in Picture.getPictureData() * Bug 42520: NPE in Picture.getPictureData()
*/ */
@SuppressWarnings("unused")
@Test @Test
public void bug42520 () throws Exception { public void bug42520 () throws Exception {
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42520.ppt")); HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42520.ppt"));
@ -262,22 +255,17 @@ public final class TestBugs {
HSLFSlideShow ppt = new HSLFSlideShow(hslf); HSLFSlideShow ppt = new HSLFSlideShow(hslf);
//test case from the bug report //test case from the bug report
HSLFGroupShape shapeGroup = (HSLFGroupShape)ppt.getSlides()[11].getShapes()[10]; HSLFGroupShape shapeGroup = (HSLFGroupShape)ppt.getSlides().get(11).getShapes().get(10);
HSLFPictureShape picture = (HSLFPictureShape)shapeGroup.getShapes()[0]; HSLFPictureShape picture = (HSLFPictureShape)shapeGroup.getShapes().get(0);
picture.getPictureData(); picture.getPictureData();
//walk down the tree and see if there were no errors while reading //walk down the tree and see if there were no errors while reading
HSLFSlide[] slide = ppt.getSlides(); for (HSLFSlide slide : ppt.getSlides()) {
for (int i = 0; i < slide.length; i++) { for (HSLFShape shape : slide.getShapes()) {
HSLFShape[] shape = slide[i].getShapes(); if (shape instanceof HSLFGroupShape){
for (int j = 0; j < shape.length; j++) { HSLFGroupShape group = (HSLFGroupShape)shape;
if (shape[j] instanceof HSLFGroupShape){ for (HSLFShape comp : group.getShapes()) {
HSLFGroupShape group = (HSLFGroupShape)shape[j];
HSLFShape[] comps = group.getShapes();
for (int k = 0; k < comps.length; k++) {
HSLFShape comp = comps[k];
if (comp instanceof HSLFPictureShape){ if (comp instanceof HSLFPictureShape){
@SuppressWarnings("unused")
HSLFPictureData pict = ((HSLFPictureShape)comp).getPictureData(); HSLFPictureData pict = ((HSLFPictureShape)comp).getPictureData();
} }
} }
@ -299,10 +287,10 @@ public final class TestBugs {
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
HSLFSlide[] slide = ppt.getSlides(); List<HSLFSlide> slide = ppt.getSlides();
assertEquals(1, slide.length); assertEquals(1, slide.size());
HSLFTextParagraph[] runs = slide[0].getTextParagraphs(); List<List<HSLFTextParagraph>> paras = slide.get(0).getTextParagraphs();
assertEquals(4, runs.length); assertEquals(4, paras.size());
Set<String> txt = new HashSet<String>(); Set<String> txt = new HashSet<String>();
txt.add("\u201CHAPPY BIRTHDAY SCOTT\u201D"); txt.add("\u201CHAPPY BIRTHDAY SCOTT\u201D");
@ -310,8 +298,8 @@ public final class TestBugs {
txt.add("PS Nobody is allowed to hassle Scott TODAY\u2026"); txt.add("PS Nobody is allowed to hassle Scott TODAY\u2026");
txt.add("Drinks will be in the Boardroom at 5pm today to celebrate Scott\u2019s B\u2019Day\u2026 See you all there!"); txt.add("Drinks will be in the Boardroom at 5pm today to celebrate Scott\u2019s B\u2019Day\u2026 See you all there!");
for (int i = 0; i < runs.length; i++) { for (List<HSLFTextParagraph> para : paras) {
String text = runs[i].getRawText(); String text = HSLFTextParagraph.getRawText(para);
assertTrue(text, txt.contains(text)); assertTrue(text, txt.contains(text));
} }
@ -322,39 +310,37 @@ public final class TestBugs {
* ( also fixed followup: getTextRuns() returns no text ) * ( also fixed followup: getTextRuns() returns no text )
*/ */
@Test @Test
public void bug43781 () throws Exception { public void bug43781() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("43781.ppt")); HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("43781.ppt"));
assertTrue("No Exceptions while reading file", true); assertTrue("No Exceptions while reading file", true);
// Check the first slide // Check the first slide
HSLFSlide slide = ppt.getSlides()[0]; HSLFSlide slide = ppt.getSlides().get(0);
HSLFTextParagraph[] slTr = slide.getTextParagraphs(); List<List<HSLFTextParagraph>> slTr = slide.getTextParagraphs();
// Has two text runs, one from slide text, one from drawing // Has 3 text paragraphs, two from slide text (empty title / filled body), one from drawing
assertEquals(2, slTr.length); assertEquals(3, slTr.size());
assertEquals(false, slTr[0].isDrawingBased()); assertFalse(slTr.get(0).get(0).isDrawingBased());
assertEquals(true, slTr[1].isDrawingBased()); assertFalse(slTr.get(1).get(0).isDrawingBased());
assertEquals("First run", slTr[0].getRawText()); assertTrue(slTr.get(2).get(0).isDrawingBased());
assertEquals("Second run", slTr[1].getRawText()); assertEquals("", HSLFTextParagraph.getRawText(slTr.get(0)));
assertEquals("First run", HSLFTextParagraph.getRawText(slTr.get(1)));
assertEquals("Second run", HSLFTextParagraph.getRawText(slTr.get(2)));
// Check the shape based text runs // Check the shape based text runs
List<HSLFTextParagraph> lst = new ArrayList<HSLFTextParagraph>(); List<HSLFTextParagraph> lst = new ArrayList<HSLFTextParagraph>();
HSLFShape[] shape = slide.getShapes(); for (HSLFShape shape : slide.getShapes()) {
for (int i = 0; i < shape.length; i++) { if (shape instanceof HSLFTextShape){
if( shape[i] instanceof HSLFTextShape){ List<HSLFTextParagraph> textRun = ((HSLFTextShape)shape).getTextParagraphs();
HSLFTextParagraph textRun = ((HSLFTextShape)shape[i]).getTextParagraphs(); lst.addAll(textRun);
if(textRun != null) {
lst.add(textRun);
}
} }
} }
// There should be only one shape based one found
assertEquals(1, lst.size());
// And it should be the second one // There are two shapes in the ppt
assertEquals("Second run", lst.get(0).getRawText()); assertEquals(2, lst.size());
assertEquals("First runSecond run", HSLFTextParagraph.getRawText(lst));
} }
/** /**
@ -364,7 +350,7 @@ public final class TestBugs {
public void bug44296 () throws Exception { public void bug44296 () throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("44296.ppt")); HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("44296.ppt"));
HSLFSlide slide = ppt.getSlides()[0]; HSLFSlide slide = ppt.getSlides().get(0);
HSLFBackground b = slide.getBackground(); HSLFBackground b = slide.getBackground();
HSLFFill f = b.getFill(); HSLFFill f = b.getFill();
@ -397,16 +383,16 @@ public final class TestBugs {
public void bug41071() throws Exception { public void bug41071() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("41071.ppt")); HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("41071.ppt"));
HSLFSlide slide = ppt.getSlides()[0]; HSLFSlide slide = ppt.getSlides().get(0);
HSLFShape[] sh = slide.getShapes(); List<HSLFShape> sh = slide.getShapes();
assertEquals(1, sh.length); assertEquals(1, sh.size());
assertTrue(sh[0] instanceof HSLFTextShape); assertTrue(sh.get(0) instanceof HSLFTextShape);
HSLFTextShape tx = (HSLFTextShape)sh[0]; HSLFTextShape tx = (HSLFTextShape)sh.get(0);
assertEquals("Fundera, planera och involvera.", tx.getTextParagraphs().getRawText()); assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(tx.getTextParagraphs()));
HSLFTextParagraph[] run = slide.getTextParagraphs(); List<List<HSLFTextParagraph>> run = slide.getTextParagraphs();
assertEquals(1, run.length); assertEquals(3, run.size());
assertEquals("Fundera, planera och involvera.", run[0].getRawText()); assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(run.get(2)));
} }
/** /**
@ -429,10 +415,10 @@ public final class TestBugs {
public void bug49648() throws Exception { public void bug49648() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("49648.ppt")); HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("49648.ppt"));
for(HSLFSlide slide : ppt.getSlides()) { for(HSLFSlide slide : ppt.getSlides()) {
for(HSLFTextParagraph run : slide.getTextParagraphs()) { for(List<HSLFTextParagraph> run : slide.getTextParagraphs()) {
String text = run.getRawText(); String text = HSLFTextParagraph.getRawText(run);
text.replace("{txtTot}", "With \u0123\u1234\u5678 unicode"); text.replace("{txtTot}", "With \u0123\u1234\u5678 unicode");
run.setRawText(text); HSLFTextParagraph.setText(run, text);
} }
} }
} }
@ -487,9 +473,9 @@ public final class TestBugs {
str = str.replace("$$DATE$$", new Date().toString()); str = str.replace("$$DATE$$", new Date().toString());
tb.setText(str); tb.setText(str);
HSLFTextParagraph tr = tb.getTextParagraphs(); List<HSLFTextParagraph> tr = tb.getTextParagraphs();
assertEquals(str.length()+1,tr.getStyleTextPropAtom().getParagraphStyles().getFirst().getCharactersCovered()); assertEquals(str.length()+1,tr.get(0).getParagraphStyle().getCharactersCovered());
assertEquals(str.length()+1,tr.getStyleTextPropAtom().getCharacterStyles().getFirst().getCharactersCovered()); assertEquals(str.length()+1,tr.get(0).getTextRuns().get(0).getCharacterStyle().getCharactersCovered());
} }
} }
} }
@ -500,7 +486,7 @@ public final class TestBugs {
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath()); HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath());
HSLFSlideShow _show = new HSLFSlideShow(ss); HSLFSlideShow _show = new HSLFSlideShow(ss);
HSLFSlide[] _slides = _show.getSlides(); List<HSLFSlide> _slides = _show.getSlides();
/* Iterate over slides and extract text */ /* Iterate over slides and extract text */
for( HSLFSlide slide : _slides ) { for( HSLFSlide slide : _slides ) {
@ -516,8 +502,8 @@ public final class TestBugs {
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath()); HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath());
HSLFSlideShow _show = new HSLFSlideShow(ss); HSLFSlideShow _show = new HSLFSlideShow(ss);
HSLFSlide[] _slides = _show.getSlides(); List<HSLFSlide> _slides = _show.getSlides();
assertEquals(13, _slides.length); assertEquals(13, _slides.size());
// Check the number of TextHeaderAtoms on Slide 1 // Check the number of TextHeaderAtoms on Slide 1
Document dr = _show.getDocumentRecord(); Document dr = _show.getDocumentRecord();
@ -538,8 +524,8 @@ public final class TestBugs {
// Check the number of text runs based on the slide (not textbox) // Check the number of text runs based on the slide (not textbox)
// Will have skipped the empty one // Will have skipped the empty one
int str = 0; int str = 0;
for (HSLFTextParagraph tr : _slides[0].getTextParagraphs()) { for (List<HSLFTextParagraph> tr : _slides.get(0).getTextParagraphs()) {
if (! tr.isDrawingBased()) str++; if (! tr.get(0).isDrawingBased()) str++;
} }
assertEquals(1, str); assertEquals(1, str);
} }
@ -549,11 +535,11 @@ public final class TestBugs {
InputStream inputStream = new FileInputStream(_slTests.getFile("37625.ppt")); InputStream inputStream = new FileInputStream(_slTests.getFile("37625.ppt"));
try { try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
assertEquals(29, slideShow.getSlides().length); assertEquals(29, slideShow.getSlides().size());
HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow); HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
assertNotNull(slideBack); assertNotNull(slideBack);
assertEquals(29, slideBack.getSlides().length); assertEquals(29, slideBack.getSlides().size());
} finally { } finally {
inputStream.close(); inputStream.close();
} }
@ -564,11 +550,11 @@ public final class TestBugs {
InputStream inputStream = new FileInputStream(_slTests.getFile("57272_corrupted_usereditatom.ppt")); InputStream inputStream = new FileInputStream(_slTests.getFile("57272_corrupted_usereditatom.ppt"));
try { try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
assertEquals(6, slideShow.getSlides().length); assertEquals(6, slideShow.getSlides().size());
HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow); HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
assertNotNull(slideBack); assertNotNull(slideBack);
assertEquals(6, slideBack.getSlides().length); assertEquals(6, slideBack.getSlides().size());
} finally { } finally {
inputStream.close(); inputStream.close();
} }
@ -579,9 +565,9 @@ public final class TestBugs {
InputStream inputStream = new FileInputStream(_slTests.getFile("49541_symbol_map.ppt")); InputStream inputStream = new FileInputStream(_slTests.getFile("49541_symbol_map.ppt"));
try { try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
HSLFSlide slide = slideShow.getSlides()[0]; HSLFSlide slide = slideShow.getSlides().get(0);
HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes()[0]; HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes().get(0);
HSLFTextBox tb = (HSLFTextBox)sg.getShapes()[0]; HSLFTextBox tb = (HSLFTextBox)sg.getShapes().get(0);
String text = StringUtil.mapMsCodepointString(tb.getText()); String text = StringUtil.mapMsCodepointString(tb.getText());
assertEquals("\u226575 years", text); assertEquals("\u226575 years", text);
} finally { } finally {
@ -608,7 +594,7 @@ public final class TestBugs {
InputStream inputStream = new FileInputStream(_slTests.getFile("bug56240.ppt")); InputStream inputStream = new FileInputStream(_slTests.getFile("bug56240.ppt"));
try { try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
int slideCnt = slideShow.getSlides().length; int slideCnt = slideShow.getSlides().size();
assertEquals(105, slideCnt); assertEquals(105, slideCnt);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
slideShow.write(bos); slideShow.write(bos);
@ -623,7 +609,7 @@ public final class TestBugs {
InputStream inputStream = new FileInputStream(_slTests.getFile("bug46441.ppt")); InputStream inputStream = new FileInputStream(_slTests.getFile("bug46441.ppt"));
try { try {
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream); HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
HSLFAutoShape as = (HSLFAutoShape)slideShow.getSlides()[0].getShapes()[0]; HSLFAutoShape as = (HSLFAutoShape)slideShow.getSlides().get(0).getShapes().get(0);
EscherOptRecord opt = as.getEscherOptRecord(); EscherOptRecord opt = as.getEscherOptRecord();
EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS); EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
double exp[][] = { double exp[][] = {