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:
parent
2aea517704
commit
6520c37b7f
@ -17,9 +17,10 @@
|
||||
|
||||
package org.apache.poi.hslf.examples;
|
||||
|
||||
import org.apache.poi.hslf.usermodel.*;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hslf.usermodel.*;
|
||||
|
||||
/**
|
||||
* Demonstrates how to read hyperlinks from a presentation
|
||||
@ -34,44 +35,37 @@ public final class Hyperlinks {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(is);
|
||||
is.close();
|
||||
|
||||
HSLFSlide[] slide = ppt.getSlides();
|
||||
for (int j = 0; j < slide.length; j++) {
|
||||
System.out.println("slide " + slide[j].getSlideNumber());
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
System.out.println("\nslide " + slide.getSlideNumber());
|
||||
|
||||
//read hyperlinks from the slide's text runs
|
||||
System.out.println("reading hyperlinks from the text runs");
|
||||
HSLFTextParagraph[] txt = slide[j].getTextParagraphs();
|
||||
for (int k = 0; k < txt.length; k++) {
|
||||
String text = txt[k].getRawText();
|
||||
HSLFHyperlink[] links = txt[k].getHyperlinks();
|
||||
if(links != null) for (int l = 0; l < links.length; l++) {
|
||||
HSLFHyperlink link = links[l];
|
||||
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);
|
||||
// read hyperlinks from the slide's text runs
|
||||
System.out.println("- reading hyperlinks from the text runs");
|
||||
for (List<HSLFTextParagraph> txtParas : slide.getTextParagraphs()) {
|
||||
List<HSLFHyperlink> links = HSLFHyperlink.find(txtParas);
|
||||
String text = HSLFTextParagraph.getRawText(txtParas);
|
||||
|
||||
for (HSLFHyperlink link : links) {
|
||||
System.out.println(toStr(link, 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
|
||||
//read such hyperlinks
|
||||
System.out.println(" reading hyperlinks from the slide's shapes");
|
||||
HSLFShape[] sh = slide[j].getShapes();
|
||||
for (int k = 0; k < sh.length; k++) {
|
||||
HSLFHyperlink link = sh[k].getHyperlink();
|
||||
if(link != null) {
|
||||
String title = link.getTitle();
|
||||
String address = link.getAddress();
|
||||
System.out.println(" " + title);
|
||||
System.out.println(" " + address);
|
||||
}
|
||||
// in PowerPoint you can assign a hyperlink to a shape without text,
|
||||
// for example to a Line object. The code below demonstrates how to
|
||||
// read such hyperlinks
|
||||
System.out.println("- reading hyperlinks from the slide's shapes");
|
||||
for (HSLFShape sh : slide.getShapes()) {
|
||||
HSLFHyperlink link = HSLFHyperlink.find(sh);
|
||||
if (link == null) continue;
|
||||
System.out.println(toStr(link, null));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -17,16 +17,16 @@
|
||||
|
||||
package org.apache.poi.hslf.examples;
|
||||
|
||||
import org.apache.poi.hslf.usermodel.*;
|
||||
import org.apache.poi.hslf.model.*;
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlide;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||
|
||||
/**
|
||||
* 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 height = (int)(pgsize.height*scale);
|
||||
|
||||
HSLFSlide[] slide = ppt.getSlides();
|
||||
for (int i = 0; i < slide.length; i++) {
|
||||
if (slidenum != -1 && slidenum != (i+1)) continue;
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
if (slidenum != -1 && slidenum != slide.getSlideNumber()) continue;
|
||||
|
||||
String title = slide[i].getTitle();
|
||||
System.out.println("Rendering slide "+slide[i].getSlideNumber() + (title == null ? "" : ": " + title));
|
||||
String title = slide.getTitle();
|
||||
System.out.println("Rendering slide "+slide.getSlideNumber() + (title == null ? "" : ": " + title));
|
||||
|
||||
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D graphics = img.createGraphics();
|
||||
@ -89,9 +88,9 @@ public final class PPT2PNG {
|
||||
|
||||
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);
|
||||
ImageIO.write(img, "png", out);
|
||||
out.close();
|
||||
|
@ -15,17 +15,14 @@
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
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.util.Iterator;
|
||||
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.
|
||||
*
|
||||
@ -36,16 +33,15 @@ public class SoundFinder {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(new FileInputStream(args[0]));
|
||||
HSLFSoundData[] sounds = ppt.getSoundData();
|
||||
|
||||
HSLFSlide[] slide = ppt.getSlides();
|
||||
for (int i = 0; i < slide.length; i++) {
|
||||
HSLFShape[] shape = slide[i].getShapes();
|
||||
for (int j = 0; j < shape.length; j++) {
|
||||
int soundRef = getSoundReference(shape[j]);
|
||||
if(soundRef != -1) {
|
||||
System.out.println("Slide["+i+"], shape["+j+"], soundRef: "+soundRef);
|
||||
System.out.println(" " + sounds[soundRef].getSoundName());
|
||||
System.out.println(" " + sounds[soundRef].getSoundType());
|
||||
}
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
for (HSLFShape shape : slide.getShapes()) {
|
||||
int soundRef = getSoundReference(shape);
|
||||
if(soundRef == -1) continue;
|
||||
|
||||
|
||||
System.out.println("Slide["+slide.getSlideNumber()+"], shape["+shape.getShapeId()+"], soundRef: "+soundRef);
|
||||
System.out.println(" " + sounds[soundRef].getSoundName());
|
||||
System.out.println(" " + sounds[soundRef].getSoundType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ package org.apache.poi.hslf.examples;
|
||||
|
||||
import org.apache.poi.hslf.usermodel.*;
|
||||
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.io.FileOutputStream;
|
||||
@ -51,8 +53,7 @@ public final class TableDemo {
|
||||
for (int i = 0; i < txt1.length; i++) {
|
||||
for (int j = 0; j < txt1[i].length; j++) {
|
||||
TableCell cell = table1.getCell(i, j);
|
||||
cell.setText(txt1[i][j]);
|
||||
HSLFTextRun rt = cell.getTextParagraphs().getTextRuns()[0];
|
||||
HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||
rt.setFontName("Arial");
|
||||
rt.setFontSize(10);
|
||||
if(i == 0){
|
||||
@ -60,8 +61,9 @@ public final class TableDemo {
|
||||
} else {
|
||||
rt.setBold(true);
|
||||
}
|
||||
cell.setVerticalAlignment(HSLFTextBox.AnchorMiddle);
|
||||
cell.setHorizontalAlignment(HSLFTextBox.AlignCenter);
|
||||
cell.setVerticalAlignment(VerticalAlignment.MIDDLE);
|
||||
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 j = 0; j < txt2[i].length; j++) {
|
||||
TableCell cell = table2.getCell(i, j);
|
||||
cell.setText(txt2[i][j]);
|
||||
HSLFTextRun rt = cell.getTextParagraphs().getTextRuns()[0];
|
||||
HSLFTextRun rt = cell.getTextParagraphs().get(0).getTextRuns().get(0);
|
||||
rt.setFontSize(10);
|
||||
rt.setFontName("Arial");
|
||||
if(i == 0){
|
||||
@ -99,13 +100,15 @@ public final class TableDemo {
|
||||
rt.setFontColor(Color.white);
|
||||
rt.setBold(true);
|
||||
rt.setFontSize(14);
|
||||
cell.setHorizontalAlignment(HSLFTextBox.AlignCenter);
|
||||
cell.setHorizontalCentered(true);
|
||||
} else {
|
||||
rt.setBullet(true);
|
||||
rt.getTextParagraph().setBullet(true);
|
||||
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);
|
||||
|
@ -67,7 +67,7 @@ public class PieChartDemo {
|
||||
String chartTitle = modelReader.readLine(); // first line is chart title
|
||||
|
||||
XMLSlideShow pptx = new XMLSlideShow(new FileInputStream(args[0]));
|
||||
XSLFSlide slide = pptx.getSlides()[0];
|
||||
XSLFSlide slide = pptx.getSlides().get(0);
|
||||
|
||||
// find chart in the slide
|
||||
XSLFChart chart = null;
|
||||
|
@ -37,7 +37,7 @@ public class Tutorial1 {
|
||||
/*XSLFSlide blankSlide =*/ ppt.createSlide();
|
||||
|
||||
|
||||
XSLFSlideMaster master = ppt.getSlideMasters()[0];
|
||||
XSLFSlideMaster master = ppt.getSlideMasters().get(0);
|
||||
|
||||
XSLFSlideLayout layout1 = master.getLayout(SlideLayout.TITLE);
|
||||
XSLFSlide slide1 = ppt.createSlide(layout1) ;
|
||||
|
@ -49,7 +49,7 @@ public class Step2 {
|
||||
// blank slide
|
||||
/*XSLFSlide blankSlide =*/ ppt.createSlide();
|
||||
|
||||
XSLFSlideMaster defaultMaster = ppt.getSlideMasters()[0];
|
||||
XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
|
||||
|
||||
// title slide
|
||||
XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);
|
||||
|
@ -146,50 +146,31 @@ public final class HSLFHyperlink {
|
||||
* @param shape <code>TextRun</code> to lookup hyperlinks in
|
||||
* @return found hyperlinks or <code>null</code> if not found
|
||||
*/
|
||||
public static HSLFHyperlink[] find(HSLFTextShape shape){
|
||||
List<HSLFHyperlink> lst = new ArrayList<HSLFHyperlink>();
|
||||
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;
|
||||
public static List<HSLFHyperlink> find(HSLFTextShape shape){
|
||||
return find(shape.getTextParagraphs());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find hyperlinks in a text paragraph
|
||||
*
|
||||
* @param paragraph <code>TextParagraph</code> to lookup hyperlinks in
|
||||
* @return found hyperlinks or <code>null</code> if not found
|
||||
* @param paragraphs List of <code>TextParagraph</code> to lookup hyperlinks
|
||||
* @return found hyperlinks
|
||||
*/
|
||||
public static HSLFHyperlink[] find(HSLFTextParagraph paragraph){
|
||||
public static List<HSLFHyperlink> find(List<HSLFTextParagraph> paragraphs){
|
||||
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
|
||||
ExObjList exobj = ppt.getDocumentRecord().getExObjList();
|
||||
if (exobj == null) {
|
||||
return null;
|
||||
}
|
||||
if (exobj == null) return lst;
|
||||
|
||||
Record[] records = paragraph.getRecords();
|
||||
Record[] records = firstPara.getRecords();
|
||||
find(records, exobj, lst);
|
||||
|
||||
HSLFHyperlink[] links = null;
|
||||
if (lst.size() > 0){
|
||||
links = new HSLFHyperlink[lst.size()];
|
||||
lst.toArray(links);
|
||||
}
|
||||
return links;
|
||||
return lst;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -224,24 +205,24 @@ public final class HSLFHyperlink {
|
||||
if (records == null) return;
|
||||
for (int i = 0; i < records.length; i++) {
|
||||
//see if we have InteractiveInfo in the textrun's records
|
||||
if( records[i] instanceof InteractiveInfo){
|
||||
InteractiveInfo hldr = (InteractiveInfo)records[i];
|
||||
InteractiveInfoAtom info = hldr.getInteractiveInfoAtom();
|
||||
int id = info.getHyperlinkID();
|
||||
ExHyperlink linkRecord = exobj.get(id);
|
||||
if (linkRecord != null){
|
||||
HSLFHyperlink link = new HSLFHyperlink();
|
||||
link.title = linkRecord.getLinkTitle();
|
||||
link.address = linkRecord.getLinkURL();
|
||||
link.type = info.getAction();
|
||||
if(!(records[i] instanceof InteractiveInfo)) continue;
|
||||
|
||||
InteractiveInfo hldr = (InteractiveInfo)records[i];
|
||||
InteractiveInfoAtom info = hldr.getInteractiveInfoAtom();
|
||||
int id = info.getHyperlinkID();
|
||||
ExHyperlink linkRecord = exobj.get(id);
|
||||
if (linkRecord == null) continue;
|
||||
|
||||
HSLFHyperlink link = new HSLFHyperlink();
|
||||
link.title = linkRecord.getLinkTitle();
|
||||
link.address = linkRecord.getLinkURL();
|
||||
link.type = info.getAction();
|
||||
out.add(link);
|
||||
|
||||
if (++i < records.length && records[i] instanceof TxInteractiveInfoAtom){
|
||||
TxInteractiveInfoAtom txinfo = (TxInteractiveInfoAtom)records[i];
|
||||
link.startIndex = txinfo.getStartIndex();
|
||||
link.endIndex = txinfo.getEndIndex();
|
||||
}
|
||||
out.add(link);
|
||||
}
|
||||
if (i+1 < records.length && records[i+1] instanceof TxInteractiveInfoAtom){
|
||||
TxInteractiveInfoAtom txinfo = (TxInteractiveInfoAtom)records[++i];
|
||||
link.startIndex = txinfo.getStartIndex();
|
||||
link.endIndex = txinfo.getEndIndex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,8 +62,8 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSl
|
||||
// Build up TextRuns from pairs of TextHeaderAtom and
|
||||
// one of TextBytesAtom or TextCharsAtom
|
||||
if (_atomSet != null && _atomSet.getSlideRecords().length > 0) {
|
||||
List<List<HSLFTextParagraph>> llhtp = HSLFTextParagraph.findTextParagraphs(_atomSet.getSlideRecords());
|
||||
_paragraphs.addAll(llhtp);
|
||||
// Grab text from SlideListWithTexts entries
|
||||
_paragraphs.addAll(HSLFTextParagraph.findTextParagraphs(_atomSet.getSlideRecords()));
|
||||
if (_paragraphs.isEmpty()) {
|
||||
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
|
||||
}
|
||||
|
||||
// Grab text from SlideListWithTexts entries
|
||||
for(List<HSLFTextParagraph> ltp : _paragraphs) {
|
||||
for (HSLFTextParagraph tp : ltp) {
|
||||
tp.supplySheet(this);
|
||||
}
|
||||
}
|
||||
// Grab text from slide's PPDrawing
|
||||
_paragraphs.addAll(HSLFTextParagraph.findTextParagraphs(getPPDrawing()));
|
||||
|
||||
// Grab the TextRuns from the PPDrawing
|
||||
List<List<HSLFTextParagraph>> llOtherRuns = HSLFTextParagraph.findTextParagraphs(getPPDrawing());
|
||||
for (List<HSLFTextParagraph> otherRuns : llOtherRuns) {
|
||||
// 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);
|
||||
for(List<HSLFTextParagraph> ltp : _paragraphs) {
|
||||
for (HSLFTextParagraph tp : ltp) {
|
||||
tp.supplySheet(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -449,19 +440,19 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSl
|
||||
|
||||
public void setHidden(boolean hidden) {
|
||||
org.apache.poi.hslf.record.Slide cont = getSlideRecord();
|
||||
|
||||
SSSlideInfoAtom slideInfo =
|
||||
|
||||
SSSlideInfoAtom slideInfo =
|
||||
(SSSlideInfoAtom)cont.findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID);
|
||||
if (slideInfo == null) {
|
||||
slideInfo = new SSSlideInfoAtom();
|
||||
cont.addChildAfter(slideInfo, cont.findFirstOfType(RecordTypes.SlideAtom.typeID));
|
||||
}
|
||||
|
||||
|
||||
slideInfo.setEffectTransitionFlagByBit(SSSlideInfoAtom.HIDDEN_BIT, hidden);
|
||||
}
|
||||
|
||||
|
||||
public boolean getHidden() {
|
||||
SSSlideInfoAtom slideInfo =
|
||||
SSSlideInfoAtom slideInfo =
|
||||
(SSSlideInfoAtom)getSlideRecord().findFirstOfType(RecordTypes.SSSlideInfoAtom.typeID);
|
||||
return (slideInfo == null)
|
||||
? false
|
||||
@ -475,6 +466,6 @@ public final class HSLFSlide extends HSLFSheet implements Slide<HSLFShape,HSLFSl
|
||||
|
||||
public void setFollowMasterColourScheme(boolean follow) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -613,7 +613,7 @@ public final class HSLFSlideShow implements SlideShow {
|
||||
SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
|
||||
|
||||
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);
|
||||
_notes.remove(removedSlide.getNotes());
|
||||
|
@ -668,11 +668,33 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
|
||||
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.
|
||||
* Also updates the styles to the correct text length.
|
||||
*/
|
||||
protected static void storeText(List<HSLFTextParagraph> paragraphs) {
|
||||
fixLineEndings(paragraphs);
|
||||
|
||||
String rawText = toInternalString(getRawText(paragraphs));
|
||||
|
||||
// Will it fit in a 8 bit atom?
|
||||
@ -738,16 +760,16 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
|
||||
|
||||
styleAtom.clearStyles();
|
||||
|
||||
TextPropCollection lastPTPC = null, lastRTPC = null;
|
||||
TextPropCollection lastPTPC = null, lastRTPC = null, ptpc = null, rtpc = null;
|
||||
for (HSLFTextParagraph para : paragraphs) {
|
||||
TextPropCollection ptpc = para.getParagraphStyle();
|
||||
ptpc = para.getParagraphStyle();
|
||||
ptpc.updateTextSize(0);
|
||||
if (!ptpc.equals(lastPTPC)) {
|
||||
lastPTPC = styleAtom.addParagraphTextPropCollection(0);
|
||||
lastPTPC.copy(ptpc);
|
||||
}
|
||||
for (HSLFTextRun tr : para.getTextRuns()) {
|
||||
TextPropCollection rtpc = tr.getCharacterStyle();
|
||||
rtpc = tr.getCharacterStyle();
|
||||
rtpc.updateTextSize(0);
|
||||
if (!rtpc.equals(lastRTPC)) {
|
||||
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);
|
||||
lastRTPC.updateTextSize(lastRTPC.getCharactersCovered()+1);
|
||||
|
||||
@ -817,6 +841,8 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
|
||||
}
|
||||
htr.setText(rawText);
|
||||
}
|
||||
|
||||
storeText(paragraphs);
|
||||
|
||||
return htr;
|
||||
}
|
||||
@ -909,16 +935,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
|
||||
public static List<List<HSLFTextParagraph>> findTextParagraphs(PPDrawing ppdrawing) {
|
||||
List<List<HSLFTextParagraph>> runsV = new ArrayList<List<HSLFTextParagraph>>();
|
||||
for (EscherTextboxWrapper wrapper : ppdrawing.getTextboxWrappers()) {
|
||||
// propagate parents to parent-aware records
|
||||
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);
|
||||
runsV.addAll(findTextParagraphs(wrapper));
|
||||
}
|
||||
return runsV;
|
||||
}
|
||||
@ -940,8 +957,17 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFTextRun> {
|
||||
*
|
||||
* @param wrapper an EscherTextboxWrapper
|
||||
*/
|
||||
protected static List<List<HSLFTextParagraph>> findTextParagraphs(final EscherTextboxWrapper wrapper) {
|
||||
return findTextParagraphs(wrapper.getChildRecords(), wrapper.getStyleTextProp9Atom());
|
||||
protected static List<List<HSLFTextParagraph>> findTextParagraphs(EscherTextboxWrapper wrapper) {
|
||||
// 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);
|
||||
if (header.getIndex() == -1) {
|
||||
if (header.getParentRecord() instanceof SlideListWithText) {
|
||||
// runs found in PPDrawing are not linked with SlideListWithTexts
|
||||
header.setIndex(slwtIndex);
|
||||
}
|
||||
|
||||
|
@ -383,6 +383,10 @@ public final class HSLFTextRun implements TextRun {
|
||||
prop.setSubValue(value, index);
|
||||
}
|
||||
|
||||
public HSLFTextParagraph getTextParagraph() {
|
||||
return parentParagraph;
|
||||
}
|
||||
|
||||
public TextCap getTextCap() {
|
||||
return TextCap.NONE;
|
||||
}
|
||||
|
@ -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>
|
||||
* if not found.
|
||||
*/
|
||||
public HSLFHyperlink[] getHyperlinks() {
|
||||
public List<HSLFHyperlink> getHyperlinks() {
|
||||
return HSLFHyperlink.find(this);
|
||||
}
|
||||
|
||||
|
@ -53,17 +53,17 @@ public final class TestHyperlink {
|
||||
"In addition, its notes has one link";
|
||||
assertEquals(expected, rawText);
|
||||
|
||||
HSLFHyperlink[] links = HSLFHyperlink.find(para.get(1));
|
||||
List<HSLFHyperlink> links = HSLFHyperlink.find(para);
|
||||
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[0].getAddress());
|
||||
assertEquals("http://jakarta.apache.org/poi/", rawText.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));
|
||||
assertEquals("http://jakarta.apache.org/poi/", links.get(0).getTitle());
|
||||
assertEquals("http://jakarta.apache.org/poi/", links.get(0).getAddress());
|
||||
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[1].getAddress());
|
||||
assertEquals("http://slashdot.org/", rawText.substring(links[1].getStartIndex(), links[1].getEndIndex()-1));
|
||||
assertEquals("http://slashdot.org/", links.get(1).getTitle());
|
||||
assertEquals("http://slashdot.org/", links.get(1).getAddress());
|
||||
assertEquals("http://slashdot.org/", rawText.substring(links.get(1).getStartIndex(), links.get(1).getEndIndex()-1));
|
||||
|
||||
slide = ppt.getSlides().get(1);
|
||||
para = slide.getTextParagraphs().get(1);
|
||||
@ -73,12 +73,12 @@ public final class TestHyperlink {
|
||||
"Jakarta HSSF";
|
||||
assertEquals(expected, rawText);
|
||||
|
||||
links = HSLFHyperlink.find(para.get(1));
|
||||
links = HSLFHyperlink.find(para);
|
||||
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[0].getAddress());
|
||||
assertEquals("Jakarta HSSF", rawText.substring(links[0].getStartIndex(), links[0].getEndIndex()-1));
|
||||
assertEquals("http://jakarta.apache.org/poi/hssf/", links.get(0).getTitle());
|
||||
assertEquals("http://jakarta.apache.org/poi/hssf/", links.get(0).getAddress());
|
||||
assertEquals("Jakarta HSSF", rawText.substring(links.get(0).getStartIndex(), links.get(0).getEndIndex()-1));
|
||||
}
|
||||
}
|
||||
|
@ -143,8 +143,9 @@ public class TestDocumentEncryption {
|
||||
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
|
||||
HSLFSlideShow ss = new HSLFSlideShow(hss);
|
||||
|
||||
HSLFSlide slide = ss.getSlides()[0];
|
||||
assertEquals("Dominic Salemno", slide.getTextParagraphs()[0].getRawText());
|
||||
HSLFSlide slide = ss.getSlides().get(0);
|
||||
String rawText = HSLFTextParagraph.getRawText(slide.getTextParagraphs().get(0));
|
||||
assertEquals("Dominic Salemno", rawText);
|
||||
|
||||
String picCmp[][] = {
|
||||
{"0","nKsDTKqxTCR8LFkVVWlP9GSTvZ0="},
|
||||
|
@ -85,8 +85,8 @@ public final class TestSlideAtom extends TestCase {
|
||||
ss.write(bos);
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
|
||||
ss = new HSLFSlideShow(bis);
|
||||
slide1 = ss.getSlides()[0];
|
||||
slide2 = ss.getSlides()[1];
|
||||
slide1 = ss.getSlides().get(0);
|
||||
slide2 = ss.getSlides().get(1);
|
||||
assertFalse(slide1.getHidden());
|
||||
assertTrue(slide2.getHidden());
|
||||
}
|
||||
|
@ -21,13 +21,11 @@ import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.poi.hslf.model.textproperties.CharFlagsTextProp;
|
||||
import org.apache.poi.hslf.model.textproperties.TextProp;
|
||||
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
|
||||
import org.apache.poi.hslf.model.textproperties.*;
|
||||
import org.apache.poi.util.HexDump;
|
||||
|
||||
/**
|
||||
@ -188,7 +186,7 @@ public final class TestStyleTextPropAtom extends TestCase {
|
||||
stpb.setParentTextSize(data_b_text_len);
|
||||
|
||||
// 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_2 = a_ch_l.get(1);
|
||||
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());
|
||||
|
||||
// 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_2 = b_ch_l.get(1);
|
||||
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);
|
||||
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_2 = b_ch_l.get(1);
|
||||
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);
|
||||
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_2 = b_p_l.get(1);
|
||||
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);
|
||||
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_2 = b_ch_l.get(1);
|
||||
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);
|
||||
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_2 = b_p_l.get(1);
|
||||
TextPropCollection b_p_3 = b_p_l.get(2);
|
||||
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_2 = b_ch_l.get(1);
|
||||
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
|
||||
// Add two more character styles
|
||||
LinkedList<TextPropCollection> cs = stpa.getCharacterStyles();
|
||||
List<TextPropCollection> cs = stpa.getCharacterStyles();
|
||||
|
||||
// First char style is boring, and 21 long
|
||||
TextPropCollection tpca = cs.get(0);
|
||||
@ -468,7 +466,7 @@ public final class TestStyleTextPropAtom extends TestCase {
|
||||
|
||||
|
||||
// Need 4 paragraph styles
|
||||
LinkedList<TextPropCollection> ps = stpa.getParagraphStyles();
|
||||
List<TextPropCollection> ps = stpa.getParagraphStyles();
|
||||
|
||||
// First is 30 long, left aligned, normal spacing
|
||||
TextPropCollection tppa = ps.get(0);
|
||||
@ -503,7 +501,7 @@ public final class TestStyleTextPropAtom extends TestCase {
|
||||
|
||||
|
||||
// Now do 4 character styles
|
||||
LinkedList<TextPropCollection> cs = stpa.getCharacterStyles();
|
||||
List<TextPropCollection> cs = stpa.getCharacterStyles();
|
||||
|
||||
// First is 30 long, bold and font size
|
||||
TextPropCollection tpca = cs.get(0);
|
||||
@ -568,16 +566,16 @@ public final class TestStyleTextPropAtom extends TestCase {
|
||||
// Compare in detail to b
|
||||
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
|
||||
stpb.setParentTextSize(data_b_text_len);
|
||||
LinkedList<TextPropCollection> psb = stpb.getParagraphStyles();
|
||||
LinkedList<TextPropCollection> csb = stpb.getCharacterStyles();
|
||||
List<TextPropCollection> psb = stpb.getParagraphStyles();
|
||||
List<TextPropCollection> csb = stpb.getCharacterStyles();
|
||||
|
||||
assertEquals(psb.size(), ps.size());
|
||||
assertEquals(csb.size(), cs.size());
|
||||
|
||||
// Ensure Paragraph Character styles match
|
||||
for(int z=0; z<2; z++) {
|
||||
LinkedList<TextPropCollection> lla = cs;
|
||||
LinkedList<TextPropCollection> llb = csb;
|
||||
List<TextPropCollection> lla = cs;
|
||||
List<TextPropCollection> llb = csb;
|
||||
int upto = 5;
|
||||
if(z == 1) {
|
||||
lla = ps;
|
||||
@ -605,8 +603,8 @@ public final class TestStyleTextPropAtom extends TestCase {
|
||||
ByteArrayOutputStream ba = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream bb = new ByteArrayOutputStream();
|
||||
|
||||
ca.writeOut(ba);
|
||||
cb.writeOut(bb);
|
||||
ca.writeOut(ba, StyleTextPropAtom.characterTextPropTypes);
|
||||
cb.writeOut(bb, StyleTextPropAtom.characterTextPropTypes);
|
||||
byte[] cab = ba.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);
|
||||
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(1, prprops.getTextPropList().size()); //1 property found
|
||||
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(5, chprops.getTextPropList().size()); //5 properties found
|
||||
assertEquals(1, chprops.findByName("char_flags").getValue());
|
||||
|
@ -20,16 +20,12 @@ package org.apache.poi.hslf.usermodel;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.List;
|
||||
|
||||
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.hslf.record.*;
|
||||
|
||||
/**
|
||||
* Tests that SlideShow adds additional sheets properly
|
||||
@ -70,7 +66,7 @@ public final class TestAddingSlides extends TestCase {
|
||||
*/
|
||||
public void testAddSlideToEmpty() throws Exception {
|
||||
// Doesn't have any slides
|
||||
assertEquals(0, ss_empty.getSlides().length);
|
||||
assertEquals(0, ss_empty.getSlides().size());
|
||||
|
||||
// Should only have a master SLWT
|
||||
assertEquals(1, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
|
||||
@ -88,7 +84,7 @@ public final class TestAddingSlides extends TestCase {
|
||||
|
||||
// Add one
|
||||
HSLFSlide slide = ss_empty.createSlide();
|
||||
assertEquals(1, ss_empty.getSlides().length);
|
||||
assertEquals(1, ss_empty.getSlides().size());
|
||||
assertEquals(256, slide._getSheetNumber());
|
||||
assertEquals(3, slide._getSheetRefId());
|
||||
assertEquals(1, slide.getSlideNumber());
|
||||
@ -103,13 +99,13 @@ public final class TestAddingSlides extends TestCase {
|
||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
||||
|
||||
// Check it now has a slide
|
||||
assertEquals(1, ss_read.getSlides().length);
|
||||
assertEquals(1, ss_read.getSlides().size());
|
||||
|
||||
// Check it now has two SLWTs
|
||||
assertEquals(2, ss_empty.getDocumentRecord().getSlideListWithTexts().length);
|
||||
|
||||
// And check it's as expected
|
||||
slide = ss_read.getSlides()[0];
|
||||
slide = ss_read.getSlides().get(0);
|
||||
assertEquals(256, slide._getSheetNumber());
|
||||
assertEquals(3, slide._getSheetRefId());
|
||||
assertEquals(1, slide.getSlideNumber());
|
||||
@ -120,8 +116,8 @@ public final class TestAddingSlides extends TestCase {
|
||||
*/
|
||||
public void testAddSlideToExisting() throws Exception {
|
||||
// Has one slide
|
||||
assertEquals(1, ss_one.getSlides().length);
|
||||
HSLFSlide s1 = ss_one.getSlides()[0];
|
||||
assertEquals(1, ss_one.getSlides().size());
|
||||
HSLFSlide s1 = ss_one.getSlides().get(0);
|
||||
|
||||
// Should have two SLTWs
|
||||
assertEquals(2, ss_one.getDocumentRecord().getSlideListWithTexts().length);
|
||||
@ -133,7 +129,7 @@ public final class TestAddingSlides extends TestCase {
|
||||
|
||||
// Add a second one
|
||||
HSLFSlide s2 = ss_one.createSlide();
|
||||
assertEquals(2, ss_one.getSlides().length);
|
||||
assertEquals(2, ss_one.getSlides().size());
|
||||
assertEquals(257, s2._getSheetNumber());
|
||||
assertEquals(4, s2._getSheetRefId());
|
||||
assertEquals(2, s2.getSlideNumber());
|
||||
@ -147,14 +143,14 @@ public final class TestAddingSlides extends TestCase {
|
||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
||||
|
||||
// Check it now has two slides
|
||||
assertEquals(2, ss_read.getSlides().length);
|
||||
assertEquals(2, ss_read.getSlides().size());
|
||||
|
||||
// Should still have two SLTWs
|
||||
assertEquals(2, ss_read.getDocumentRecord().getSlideListWithTexts().length);
|
||||
|
||||
// And check it's as expected
|
||||
s1 = ss_read.getSlides()[0];
|
||||
s2 = ss_read.getSlides()[1];
|
||||
s1 = ss_read.getSlides().get(0);
|
||||
s2 = ss_read.getSlides().get(1);
|
||||
assertEquals(256, s1._getSheetNumber());
|
||||
assertEquals(3, s1._getSheetRefId());
|
||||
assertEquals(1, s1.getSlideNumber());
|
||||
@ -167,7 +163,8 @@ public final class TestAddingSlides extends TestCase {
|
||||
* Test adding a slide to an existing slideshow,
|
||||
* with two slides already
|
||||
*/
|
||||
public void testAddSlideToExisting2() throws Exception {
|
||||
@SuppressWarnings("unused")
|
||||
public void testAddSlideToExisting2() throws Exception {
|
||||
//grab UserEditAtom
|
||||
UserEditAtom usredit = null;
|
||||
Record[] _records = hss_two.getRecords();
|
||||
@ -180,9 +177,9 @@ public final class TestAddingSlides extends TestCase {
|
||||
assertNotNull(usredit);
|
||||
|
||||
// Has two slides
|
||||
assertEquals(2, ss_two.getSlides().length);
|
||||
HSLFSlide s1 = ss_two.getSlides()[0];
|
||||
HSLFSlide s2 = ss_two.getSlides()[1];
|
||||
assertEquals(2, ss_two.getSlides().size());
|
||||
HSLFSlide s1 = ss_two.getSlides().get(0);
|
||||
HSLFSlide s2 = ss_two.getSlides().get(1);
|
||||
|
||||
// Check slide 1 is as expected
|
||||
assertEquals(256, s1._getSheetNumber());
|
||||
@ -195,7 +192,7 @@ public final class TestAddingSlides extends TestCase {
|
||||
|
||||
// Add a third one
|
||||
HSLFSlide s3 = ss_two.createSlide();
|
||||
assertEquals(3, ss_two.getSlides().length);
|
||||
assertEquals(3, ss_two.getSlides().size());
|
||||
assertEquals(258, s3._getSheetNumber());
|
||||
assertEquals(8, s3._getSheetRefId()); // lots of notes before us
|
||||
assertEquals(3, s3.getSlideNumber());
|
||||
@ -210,12 +207,12 @@ public final class TestAddingSlides extends TestCase {
|
||||
HSLFSlideShow ss_read = new HSLFSlideShow(hss_read);
|
||||
|
||||
// Check it now has three slides
|
||||
assertEquals(3, ss_read.getSlides().length);
|
||||
assertEquals(3, ss_read.getSlides().size());
|
||||
|
||||
// And check it's as expected
|
||||
s1 = ss_read.getSlides()[0];
|
||||
s2 = ss_read.getSlides()[1];
|
||||
s3 = ss_read.getSlides()[2];
|
||||
s1 = ss_read.getSlides().get(0);
|
||||
s2 = ss_read.getSlides().get(1);
|
||||
s3 = ss_read.getSlides().get(2);
|
||||
assertEquals(256, s1._getSheetNumber());
|
||||
assertEquals(4, s1._getSheetRefId());
|
||||
assertEquals(1, s1.getSlideNumber());
|
||||
@ -235,8 +232,8 @@ public final class TestAddingSlides extends TestCase {
|
||||
HSLFSlide slide1 = ppt.createSlide();
|
||||
HSLFSlide slide2 = ppt.createSlide();
|
||||
|
||||
HSLFSlide[] s1 = ppt.getSlides();
|
||||
assertEquals(2, s1.length);
|
||||
List<HSLFSlide> s1 = ppt.getSlides();
|
||||
assertEquals(2, s1.size());
|
||||
try {
|
||||
ppt.removeSlide(-1);
|
||||
fail("expected exception");
|
||||
@ -254,10 +251,10 @@ public final class TestAddingSlides extends TestCase {
|
||||
assertEquals(1, slide1.getSlideNumber());
|
||||
|
||||
HSLFSlide removedSlide = ppt.removeSlide(0);
|
||||
HSLFSlide[] s2 = ppt.getSlides();
|
||||
assertEquals(1, s2.length);
|
||||
List<HSLFSlide> s2 = ppt.getSlides();
|
||||
assertEquals(1, s2.size());
|
||||
assertSame(slide1, removedSlide);
|
||||
assertSame(slide2, s2[0]);
|
||||
assertSame(slide2, s2.get(0));
|
||||
|
||||
assertEquals(0, slide2.getSlideNumber());
|
||||
|
||||
@ -266,29 +263,29 @@ public final class TestAddingSlides extends TestCase {
|
||||
|
||||
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
|
||||
|
||||
HSLFSlide[] s3 = ppt.getSlides();
|
||||
assertEquals(1, s3.length);
|
||||
List<HSLFSlide> s3 = ppt.getSlides();
|
||||
assertEquals(1, s3.size());
|
||||
}
|
||||
|
||||
|
||||
public void test47261() throws Exception {
|
||||
POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(slTests.openResourceAsStream("47261.ppt"));
|
||||
HSLFSlide[] slides = ppt.getSlides();
|
||||
List<HSLFSlide> slides = ppt.getSlides();
|
||||
Document doc = ppt.getDocumentRecord();
|
||||
assertNotNull(doc.getSlideSlideListWithText());
|
||||
assertEquals(14, ppt.getSlides().length);
|
||||
int notesId = slides[0].getSlideRecord().getSlideAtom().getNotesID();
|
||||
assertEquals(14, ppt.getSlides().size());
|
||||
int notesId = slides.get(0).getSlideRecord().getSlideAtom().getNotesID();
|
||||
assertTrue(notesId > 0);
|
||||
assertNotNull(doc.getNotesSlideListWithText());
|
||||
assertEquals(14, doc.getNotesSlideListWithText().getSlideAtomsSets().length);
|
||||
|
||||
//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);
|
||||
}
|
||||
assertEquals(0, ppt.getSlides().length);
|
||||
assertEquals(0, ppt.getNotes().length);
|
||||
assertEquals(0, ppt.getSlides().size());
|
||||
assertEquals(0, ppt.getNotes().size());
|
||||
assertNull(doc.getSlideSlideListWithText());
|
||||
assertNull(doc.getNotesSlideListWithText());
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
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.assertTrue;
|
||||
|
||||
@ -73,7 +73,7 @@ public final class TestBugs {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
||||
assertTrue("No Exceptions while reading file", true);
|
||||
|
||||
assertEquals(1, ppt.getSlides().length);
|
||||
assertEquals(1, ppt.getSlides().size());
|
||||
|
||||
HSLFPictureData[] pict = ppt.getPictureData();
|
||||
assertEquals(2, pict.length);
|
||||
@ -91,23 +91,23 @@ public final class TestBugs {
|
||||
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
||||
assertTrue("No Exceptions while reading file", true);
|
||||
assertEquals(2, ppt.getSlides().length);
|
||||
assertEquals(2, ppt.getSlides().size());
|
||||
|
||||
HSLFTextParagraph txrun;
|
||||
List<HSLFTextParagraph> txrun;
|
||||
HSLFNotes notes;
|
||||
|
||||
notes = ppt.getSlides()[0].getNotesSheet();
|
||||
notes = ppt.getSlides().get(0).getNotes();
|
||||
assertNotNull(notes);
|
||||
txrun = notes.getTextParagraphs()[0];
|
||||
assertEquals("Notes-1", txrun.getRawText());
|
||||
assertEquals(false, txrun.getTextRuns()[0].isBold());
|
||||
txrun = notes.getTextParagraphs().get(0);
|
||||
assertEquals("Notes-1", HSLFTextParagraph.getRawText(txrun));
|
||||
assertEquals(false, txrun.get(0).getTextRuns().get(0).isBold());
|
||||
|
||||
//notes for the second slide are in bold
|
||||
notes = ppt.getSlides()[1].getNotesSheet();
|
||||
notes = ppt.getSlides().get(1).getNotes();
|
||||
assertNotNull(notes);
|
||||
txrun = notes.getTextParagraphs()[0];
|
||||
assertEquals("Notes-2", txrun.getRawText());
|
||||
assertEquals(true, txrun.getTextRuns()[0].isBold());
|
||||
txrun = notes.getTextParagraphs().get(0);
|
||||
assertEquals("Notes-2", HSLFTextParagraph.getRawText(txrun));
|
||||
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(8), "The bus Z is split into Z_H and Z_L");
|
||||
|
||||
HSLFSlide[] slide = ppt.getSlides();
|
||||
for (int i = 0; i < slide.length; i++) {
|
||||
Integer slideNumber = Integer.valueOf(slide[i].getSlideNumber());
|
||||
HSLFNotes notes = slide[i].getNotesSheet();
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
Integer slideNumber = Integer.valueOf(slide.getSlideNumber());
|
||||
HSLFNotes notes = slide.getNotes();
|
||||
if (notesMap.containsKey(slideNumber)){
|
||||
assertNotNull(notes);
|
||||
String text = notes.getTextParagraphs()[0].getRawText();
|
||||
String text = HSLFTextParagraph.getRawText(notes.getTextParagraphs().get(0));
|
||||
String startingPhrase = notesMap.get(slideNumber);
|
||||
assertTrue("Notes for slide " + slideNumber + " must start with " +
|
||||
startingPhrase , text.startsWith(startingPhrase));
|
||||
@ -150,14 +149,12 @@ public final class TestBugs {
|
||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
|
||||
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
||||
HSLFShape[] shape = ppt.getSlides()[0].getShapes();
|
||||
for (int i = 0; i < shape.length; i++) {
|
||||
if(shape[i] instanceof HSLFGroupShape){
|
||||
HSLFGroupShape group = (HSLFGroupShape)shape[i];
|
||||
HSLFShape[] sh = group.getShapes();
|
||||
for (int j = 0; j < sh.length; j++) {
|
||||
if( sh[j] instanceof HSLFTextBox){
|
||||
HSLFTextBox txt = (HSLFTextBox)sh[j];
|
||||
for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
|
||||
if(shape instanceof HSLFGroupShape){
|
||||
HSLFGroupShape group = (HSLFGroupShape)shape;
|
||||
for (HSLFShape sh : group.getShapes()) {
|
||||
if(sh instanceof HSLFTextBox){
|
||||
HSLFTextBox txt = (HSLFTextBox)sh;
|
||||
assertNotNull(txt.getTextParagraphs());
|
||||
}
|
||||
}
|
||||
@ -173,14 +170,12 @@ public final class TestBugs {
|
||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42485.ppt"));
|
||||
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
||||
HSLFShape[] shape = ppt.getSlides()[0].getShapes();
|
||||
for (int i = 0; i < shape.length; i++) {
|
||||
if(shape[i] instanceof HSLFGroupShape){
|
||||
HSLFGroupShape group = (HSLFGroupShape)shape[i];
|
||||
for (HSLFShape shape : ppt.getSlides().get(0).getShapes()) {
|
||||
if(shape instanceof HSLFGroupShape){
|
||||
HSLFGroupShape group = (HSLFGroupShape)shape;
|
||||
assertNotNull(group.getAnchor());
|
||||
HSLFShape[] sh = group.getShapes();
|
||||
for (int j = 0; j < sh.length; j++) {
|
||||
assertNotNull(sh[j].getAnchor());
|
||||
for (HSLFShape sh : group.getShapes()) {
|
||||
assertNotNull(sh.getAnchor());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -197,28 +192,28 @@ public final class TestBugs {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
||||
assertTrue("No Exceptions while reading file", true);
|
||||
|
||||
assertEquals(1, ppt.getSlidesMasters().length);
|
||||
assertEquals(1, ppt.getTitleMasters().length);
|
||||
HSLFSlide[] slide = ppt.getSlides();
|
||||
for (int i = 0; i < slide.length; i++) {
|
||||
HSLFMasterSheet master = slide[i].getMasterSheet();
|
||||
if (i == 0) assertTrue(master instanceof HSLFTitleMaster); //the first slide follows TitleMaster
|
||||
else assertTrue(master instanceof HSLFSlideMaster);
|
||||
assertEquals(1, ppt.getSlideMasters().size());
|
||||
assertEquals(1, ppt.getTitleMasters().size());
|
||||
boolean isFirst = true;
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
HSLFMasterSheet master = slide.getMasterSheet();
|
||||
// the first slide follows TitleMaster
|
||||
assertTrue(isFirst ? master instanceof HSLFTitleMaster : master instanceof HSLFSlideMaster);
|
||||
isFirst = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug 42486: Failure parsing a seemingly valid PPT
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
public void bug42486 () throws Exception {
|
||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42486.ppt"));
|
||||
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
||||
HSLFSlide[] slide = ppt.getSlides();
|
||||
for (int i = 0; i < slide.length; i++) {
|
||||
@SuppressWarnings("unused")
|
||||
HSLFShape[] shape = slide[i].getShapes();
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
List<HSLFShape> shape = slide.getShapes();
|
||||
}
|
||||
assertTrue("No Exceptions while reading file", true);
|
||||
|
||||
@ -233,16 +228,13 @@ public final class TestBugs {
|
||||
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
||||
//walk down the tree and see if there were no errors while reading
|
||||
HSLFSlide[] slide = ppt.getSlides();
|
||||
for (int i = 0; i < slide.length; i++) {
|
||||
HSLFShape[] shape = slide[i].getShapes();
|
||||
for (int j = 0; j < shape.length; j++) {
|
||||
assertNotNull(shape[j].getShapeName());
|
||||
if (shape[j] instanceof HSLFGroupShape){
|
||||
HSLFGroupShape group = (HSLFGroupShape)shape[j];
|
||||
HSLFShape[] comps = group.getShapes();
|
||||
for (int k = 0; k < comps.length; k++) {
|
||||
assertNotNull(comps[k].getShapeName());
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
for (HSLFShape shape : slide.getShapes()) {
|
||||
assertNotNull(shape.getShapeName());
|
||||
if (shape instanceof HSLFGroupShape){
|
||||
HSLFGroupShape group = (HSLFGroupShape)shape;
|
||||
for (HSLFShape comps : group.getShapes()) {
|
||||
assertNotNull(comps.getShapeName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -255,6 +247,7 @@ public final class TestBugs {
|
||||
/**
|
||||
* Bug 42520: NPE in Picture.getPictureData()
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
public void bug42520 () throws Exception {
|
||||
HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(_slTests.openResourceAsStream("42520.ppt"));
|
||||
@ -262,22 +255,17 @@ public final class TestBugs {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(hslf);
|
||||
|
||||
//test case from the bug report
|
||||
HSLFGroupShape shapeGroup = (HSLFGroupShape)ppt.getSlides()[11].getShapes()[10];
|
||||
HSLFPictureShape picture = (HSLFPictureShape)shapeGroup.getShapes()[0];
|
||||
HSLFGroupShape shapeGroup = (HSLFGroupShape)ppt.getSlides().get(11).getShapes().get(10);
|
||||
HSLFPictureShape picture = (HSLFPictureShape)shapeGroup.getShapes().get(0);
|
||||
picture.getPictureData();
|
||||
|
||||
//walk down the tree and see if there were no errors while reading
|
||||
HSLFSlide[] slide = ppt.getSlides();
|
||||
for (int i = 0; i < slide.length; i++) {
|
||||
HSLFShape[] shape = slide[i].getShapes();
|
||||
for (int j = 0; j < shape.length; j++) {
|
||||
if (shape[j] instanceof HSLFGroupShape){
|
||||
HSLFGroupShape group = (HSLFGroupShape)shape[j];
|
||||
HSLFShape[] comps = group.getShapes();
|
||||
for (int k = 0; k < comps.length; k++) {
|
||||
HSLFShape comp = comps[k];
|
||||
for (HSLFSlide slide : ppt.getSlides()) {
|
||||
for (HSLFShape shape : slide.getShapes()) {
|
||||
if (shape instanceof HSLFGroupShape){
|
||||
HSLFGroupShape group = (HSLFGroupShape)shape;
|
||||
for (HSLFShape comp : group.getShapes()) {
|
||||
if (comp instanceof HSLFPictureShape){
|
||||
@SuppressWarnings("unused")
|
||||
HSLFPictureData pict = ((HSLFPictureShape)comp).getPictureData();
|
||||
}
|
||||
}
|
||||
@ -299,10 +287,10 @@ public final class TestBugs {
|
||||
|
||||
assertTrue("No Exceptions while reading file", true);
|
||||
|
||||
HSLFSlide[] slide = ppt.getSlides();
|
||||
assertEquals(1, slide.length);
|
||||
HSLFTextParagraph[] runs = slide[0].getTextParagraphs();
|
||||
assertEquals(4, runs.length);
|
||||
List<HSLFSlide> slide = ppt.getSlides();
|
||||
assertEquals(1, slide.size());
|
||||
List<List<HSLFTextParagraph>> paras = slide.get(0).getTextParagraphs();
|
||||
assertEquals(4, paras.size());
|
||||
|
||||
Set<String> txt = new HashSet<String>();
|
||||
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("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++) {
|
||||
String text = runs[i].getRawText();
|
||||
for (List<HSLFTextParagraph> para : paras) {
|
||||
String text = HSLFTextParagraph.getRawText(para);
|
||||
assertTrue(text, txt.contains(text));
|
||||
}
|
||||
|
||||
@ -322,39 +310,37 @@ public final class TestBugs {
|
||||
* ( also fixed followup: getTextRuns() returns no text )
|
||||
*/
|
||||
@Test
|
||||
public void bug43781 () throws Exception {
|
||||
public void bug43781() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("43781.ppt"));
|
||||
|
||||
assertTrue("No Exceptions while reading file", true);
|
||||
|
||||
// Check the first slide
|
||||
HSLFSlide slide = ppt.getSlides()[0];
|
||||
HSLFTextParagraph[] slTr = slide.getTextParagraphs();
|
||||
HSLFSlide slide = ppt.getSlides().get(0);
|
||||
List<List<HSLFTextParagraph>> slTr = slide.getTextParagraphs();
|
||||
|
||||
// Has two text runs, one from slide text, one from drawing
|
||||
assertEquals(2, slTr.length);
|
||||
assertEquals(false, slTr[0].isDrawingBased());
|
||||
assertEquals(true, slTr[1].isDrawingBased());
|
||||
assertEquals("First run", slTr[0].getRawText());
|
||||
assertEquals("Second run", slTr[1].getRawText());
|
||||
// Has 3 text paragraphs, two from slide text (empty title / filled body), one from drawing
|
||||
assertEquals(3, slTr.size());
|
||||
assertFalse(slTr.get(0).get(0).isDrawingBased());
|
||||
assertFalse(slTr.get(1).get(0).isDrawingBased());
|
||||
assertTrue(slTr.get(2).get(0).isDrawingBased());
|
||||
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
|
||||
List<HSLFTextParagraph> lst = new ArrayList<HSLFTextParagraph>();
|
||||
HSLFShape[] shape = slide.getShapes();
|
||||
for (int i = 0; i < shape.length; i++) {
|
||||
if( shape[i] instanceof HSLFTextShape){
|
||||
HSLFTextParagraph textRun = ((HSLFTextShape)shape[i]).getTextParagraphs();
|
||||
if(textRun != null) {
|
||||
lst.add(textRun);
|
||||
}
|
||||
for (HSLFShape shape : slide.getShapes()) {
|
||||
if (shape instanceof HSLFTextShape){
|
||||
List<HSLFTextParagraph> textRun = ((HSLFTextShape)shape).getTextParagraphs();
|
||||
lst.addAll(textRun);
|
||||
}
|
||||
|
||||
}
|
||||
// There should be only one shape based one found
|
||||
assertEquals(1, lst.size());
|
||||
|
||||
// And it should be the second one
|
||||
assertEquals("Second run", lst.get(0).getRawText());
|
||||
// There are two shapes in the ppt
|
||||
assertEquals(2, lst.size());
|
||||
assertEquals("First runSecond run", HSLFTextParagraph.getRawText(lst));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -364,7 +350,7 @@ public final class TestBugs {
|
||||
public void bug44296 () throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("44296.ppt"));
|
||||
|
||||
HSLFSlide slide = ppt.getSlides()[0];
|
||||
HSLFSlide slide = ppt.getSlides().get(0);
|
||||
|
||||
HSLFBackground b = slide.getBackground();
|
||||
HSLFFill f = b.getFill();
|
||||
@ -397,16 +383,16 @@ public final class TestBugs {
|
||||
public void bug41071() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("41071.ppt"));
|
||||
|
||||
HSLFSlide slide = ppt.getSlides()[0];
|
||||
HSLFShape[] sh = slide.getShapes();
|
||||
assertEquals(1, sh.length);
|
||||
assertTrue(sh[0] instanceof HSLFTextShape);
|
||||
HSLFTextShape tx = (HSLFTextShape)sh[0];
|
||||
assertEquals("Fundera, planera och involvera.", tx.getTextParagraphs().getRawText());
|
||||
HSLFSlide slide = ppt.getSlides().get(0);
|
||||
List<HSLFShape> sh = slide.getShapes();
|
||||
assertEquals(1, sh.size());
|
||||
assertTrue(sh.get(0) instanceof HSLFTextShape);
|
||||
HSLFTextShape tx = (HSLFTextShape)sh.get(0);
|
||||
assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(tx.getTextParagraphs()));
|
||||
|
||||
HSLFTextParagraph[] run = slide.getTextParagraphs();
|
||||
assertEquals(1, run.length);
|
||||
assertEquals("Fundera, planera och involvera.", run[0].getRawText());
|
||||
List<List<HSLFTextParagraph>> run = slide.getTextParagraphs();
|
||||
assertEquals(3, run.size());
|
||||
assertEquals("Fundera, planera och involvera.", HSLFTextParagraph.getRawText(run.get(2)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -429,10 +415,10 @@ public final class TestBugs {
|
||||
public void bug49648() throws Exception {
|
||||
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("49648.ppt"));
|
||||
for(HSLFSlide slide : ppt.getSlides()) {
|
||||
for(HSLFTextParagraph run : slide.getTextParagraphs()) {
|
||||
String text = run.getRawText();
|
||||
for(List<HSLFTextParagraph> run : slide.getTextParagraphs()) {
|
||||
String text = HSLFTextParagraph.getRawText(run);
|
||||
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());
|
||||
tb.setText(str);
|
||||
|
||||
HSLFTextParagraph tr = tb.getTextParagraphs();
|
||||
assertEquals(str.length()+1,tr.getStyleTextPropAtom().getParagraphStyles().getFirst().getCharactersCovered());
|
||||
assertEquals(str.length()+1,tr.getStyleTextPropAtom().getCharacterStyles().getFirst().getCharactersCovered());
|
||||
List<HSLFTextParagraph> tr = tb.getTextParagraphs();
|
||||
assertEquals(str.length()+1,tr.get(0).getParagraphStyle().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());
|
||||
HSLFSlideShow _show = new HSLFSlideShow(ss);
|
||||
HSLFSlide[] _slides = _show.getSlides();
|
||||
List<HSLFSlide> _slides = _show.getSlides();
|
||||
|
||||
/* Iterate over slides and extract text */
|
||||
for( HSLFSlide slide : _slides ) {
|
||||
@ -516,8 +502,8 @@ public final class TestBugs {
|
||||
|
||||
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(file.getAbsolutePath());
|
||||
HSLFSlideShow _show = new HSLFSlideShow(ss);
|
||||
HSLFSlide[] _slides = _show.getSlides();
|
||||
assertEquals(13, _slides.length);
|
||||
List<HSLFSlide> _slides = _show.getSlides();
|
||||
assertEquals(13, _slides.size());
|
||||
|
||||
// Check the number of TextHeaderAtoms on Slide 1
|
||||
Document dr = _show.getDocumentRecord();
|
||||
@ -538,8 +524,8 @@ public final class TestBugs {
|
||||
// Check the number of text runs based on the slide (not textbox)
|
||||
// Will have skipped the empty one
|
||||
int str = 0;
|
||||
for (HSLFTextParagraph tr : _slides[0].getTextParagraphs()) {
|
||||
if (! tr.isDrawingBased()) str++;
|
||||
for (List<HSLFTextParagraph> tr : _slides.get(0).getTextParagraphs()) {
|
||||
if (! tr.get(0).isDrawingBased()) str++;
|
||||
}
|
||||
assertEquals(1, str);
|
||||
}
|
||||
@ -549,11 +535,11 @@ public final class TestBugs {
|
||||
InputStream inputStream = new FileInputStream(_slTests.getFile("37625.ppt"));
|
||||
try {
|
||||
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
|
||||
assertEquals(29, slideShow.getSlides().length);
|
||||
assertEquals(29, slideShow.getSlides().size());
|
||||
|
||||
HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
|
||||
assertNotNull(slideBack);
|
||||
assertEquals(29, slideBack.getSlides().length);
|
||||
assertEquals(29, slideBack.getSlides().size());
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
@ -564,11 +550,11 @@ public final class TestBugs {
|
||||
InputStream inputStream = new FileInputStream(_slTests.getFile("57272_corrupted_usereditatom.ppt"));
|
||||
try {
|
||||
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
|
||||
assertEquals(6, slideShow.getSlides().length);
|
||||
assertEquals(6, slideShow.getSlides().size());
|
||||
|
||||
HSLFSlideShow slideBack = HSLFTestDataSamples.writeOutAndReadBack(slideShow);
|
||||
assertNotNull(slideBack);
|
||||
assertEquals(6, slideBack.getSlides().length);
|
||||
assertEquals(6, slideBack.getSlides().size());
|
||||
} finally {
|
||||
inputStream.close();
|
||||
}
|
||||
@ -579,9 +565,9 @@ public final class TestBugs {
|
||||
InputStream inputStream = new FileInputStream(_slTests.getFile("49541_symbol_map.ppt"));
|
||||
try {
|
||||
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
|
||||
HSLFSlide slide = slideShow.getSlides()[0];
|
||||
HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes()[0];
|
||||
HSLFTextBox tb = (HSLFTextBox)sg.getShapes()[0];
|
||||
HSLFSlide slide = slideShow.getSlides().get(0);
|
||||
HSLFGroupShape sg = (HSLFGroupShape)slide.getShapes().get(0);
|
||||
HSLFTextBox tb = (HSLFTextBox)sg.getShapes().get(0);
|
||||
String text = StringUtil.mapMsCodepointString(tb.getText());
|
||||
assertEquals("\u226575 years", text);
|
||||
} finally {
|
||||
@ -608,7 +594,7 @@ public final class TestBugs {
|
||||
InputStream inputStream = new FileInputStream(_slTests.getFile("bug56240.ppt"));
|
||||
try {
|
||||
HSLFSlideShow slideShow = new HSLFSlideShow(inputStream);
|
||||
int slideCnt = slideShow.getSlides().length;
|
||||
int slideCnt = slideShow.getSlides().size();
|
||||
assertEquals(105, slideCnt);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
slideShow.write(bos);
|
||||
@ -623,7 +609,7 @@ public final class TestBugs {
|
||||
InputStream inputStream = new FileInputStream(_slTests.getFile("bug46441.ppt"));
|
||||
try {
|
||||
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();
|
||||
EscherArrayProperty ep = HSLFShape.getEscherProperty(opt, EscherProperties.FILL__SHADECOLORS);
|
||||
double exp[][] = {
|
||||
|
Loading…
Reference in New Issue
Block a user