use of org.apache.poi.hslf.record.SlideListWithText in project poi by apache.
the class SLWTListing method main.
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("Need to give a filename");
System.exit(1);
}
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
// Find the documents, and then their SLWT
Record[] records = ss.getRecords();
for (int i = 0; i < records.length; i++) {
if (records[i] instanceof Document) {
Document doc = (Document) records[i];
SlideListWithText[] slwts = doc.getSlideListWithTexts();
System.out.println("Document at " + i + " had " + slwts.length + " SlideListWithTexts");
if (slwts.length == 0) {
System.err.println("** Warning: Should have had at least 1! **");
}
if (slwts.length > 3) {
System.err.println("** Warning: Shouldn't have more than 3!");
}
// Check the SLWTs contain what we'd expect
for (int j = 0; j < slwts.length; j++) {
SlideListWithText slwt = slwts[j];
Record[] children = slwt.getChildRecords();
System.out.println(" - SLWT at " + j + " had " + children.length + " children:");
// Should only have SlideAtomSets if the second one
int numSAS = slwt.getSlideAtomsSets().length;
if (j == 1) {
if (numSAS == 0) {
System.err.println(" ** 2nd SLWT didn't have any SlideAtomSets!");
} else {
System.out.println(" - Contains " + numSAS + " SlideAtomSets");
}
} else {
if (numSAS > 0) {
System.err.println(" ** SLWT " + j + " had " + numSAS + " SlideAtomSets! (expected 0)");
}
}
// Report the first 5 children, to give a flavour
int upTo = 5;
if (children.length < 5) {
upTo = children.length;
}
for (int k = 0; k < upTo; k++) {
Record r = children[k];
int typeID = (int) r.getRecordType();
String typeName = RecordTypes.forTypeID(typeID).name();
System.out.println(" - " + typeID + " (" + typeName + ")");
}
}
}
}
ss.close();
}
use of org.apache.poi.hslf.record.SlideListWithText in project poi by apache.
the class HSLFTextParagraph method findTextParagraphs.
/**
* Scans through the supplied record array, looking for
* a TextHeaderAtom followed by one of a TextBytesAtom or
* a TextCharsAtom. Builds up TextRuns from these
*
* @param records the records to build from
*/
protected static List<List<HSLFTextParagraph>> findTextParagraphs(Record[] records) {
List<List<HSLFTextParagraph>> paragraphCollection = new ArrayList<List<HSLFTextParagraph>>();
int[] recordIdx = { 0 };
for (int slwtIndex = 0; recordIdx[0] < records.length; slwtIndex++) {
TextHeaderAtom header = null;
TextBytesAtom tbytes = null;
TextCharsAtom tchars = null;
TextRulerAtom ruler = null;
MasterTextPropAtom indents = null;
for (Record r : getRecords(records, recordIdx, null)) {
long rt = r.getRecordType();
if (RecordTypes.TextHeaderAtom.typeID == rt) {
header = (TextHeaderAtom) r;
} else if (RecordTypes.TextBytesAtom.typeID == rt) {
tbytes = (TextBytesAtom) r;
} else if (RecordTypes.TextCharsAtom.typeID == rt) {
tchars = (TextCharsAtom) r;
} else if (RecordTypes.TextRulerAtom.typeID == rt) {
ruler = (TextRulerAtom) r;
} else if (RecordTypes.MasterTextPropAtom.typeID == rt) {
indents = (MasterTextPropAtom) r;
}
// don't search for RecordTypes.StyleTextPropAtom.typeID here ... see findStyleAtomPresent below
}
if (header == null) {
break;
}
if (header.getParentRecord() instanceof SlideListWithText) {
// runs found in PPDrawing are not linked with SlideListWithTexts
header.setIndex(slwtIndex);
}
if (tbytes == null && tchars == null) {
tbytes = new TextBytesAtom();
// don't add record yet - set it in storeText
logger.log(POILogger.INFO, "bytes nor chars atom doesn't exist. Creating dummy record for later saving.");
}
String rawText = (tchars != null) ? tchars.getText() : tbytes.getText();
StyleTextPropAtom styles = findStyleAtomPresent(header, rawText.length());
List<HSLFTextParagraph> paragraphs = new ArrayList<HSLFTextParagraph>();
paragraphCollection.add(paragraphs);
// split, but keep delimiter
for (String para : rawText.split("(?<=\r)")) {
HSLFTextParagraph tpara = new HSLFTextParagraph(header, tbytes, tchars, paragraphs);
paragraphs.add(tpara);
tpara._ruler = ruler;
tpara.getParagraphStyle().updateTextSize(para.length());
HSLFTextRun trun = new HSLFTextRun(tpara);
tpara.addTextRun(trun);
trun.setText(para);
}
applyCharacterStyles(paragraphs, styles.getCharacterStyles());
applyParagraphStyles(paragraphs, styles.getParagraphStyles());
if (indents != null) {
applyParagraphIndents(paragraphs, indents.getIndents());
}
}
if (paragraphCollection.isEmpty()) {
logger.log(POILogger.DEBUG, "No text records found.");
}
return paragraphCollection;
}
use of org.apache.poi.hslf.record.SlideListWithText in project poi by apache.
the class TestBugs method bug56260.
@Test
public void bug56260() throws IOException {
HSLFSlideShow ppt = open("56260.ppt");
List<HSLFSlide> _slides = ppt.getSlides();
assertEquals(13, _slides.size());
// Check the number of TextHeaderAtoms on Slide 1
Document dr = ppt.getDocumentRecord();
SlideListWithText slidesSLWT = dr.getSlideSlideListWithText();
SlideAtomsSet s1 = slidesSLWT.getSlideAtomsSets()[0];
int tha = 0;
for (Record r : s1.getSlideRecords()) {
if (r instanceof TextHeaderAtom) {
tha++;
}
}
assertEquals(2, tha);
// Check to see that we have a pair next to each other
assertEquals(TextHeaderAtom.class, s1.getSlideRecords()[0].getClass());
assertEquals(TextHeaderAtom.class, s1.getSlideRecords()[1].getClass());
// Check the number of text runs based on the slide (not textbox)
// Will have skipped the empty one
int str = 0;
for (List<HSLFTextParagraph> tr : _slides.get(0).getTextParagraphs()) {
if (!tr.get(0).isDrawingBased()) {
str++;
}
}
assertEquals(2, str);
ppt.close();
}
use of org.apache.poi.hslf.record.SlideListWithText in project poi by apache.
the class TestRichTextRun method assertMatchesSLTWC.
/**
* Opens a new copy of SlideShow C, writes the active
* SlideListWithText out, and compares it to the write
* out of the supplied SlideShow. Also compares the
* contents.
* @param s
*/
private void assertMatchesSLTWC(HSLFSlideShow s) throws IOException {
// Grab a new copy of slideshow C
HSLFSlideShow refC = HSLFTestDataSamples.getSlideShow(filenameC);
// Write out the 2nd SLWT in the active document
SlideListWithText refSLWT = refC.getDocumentRecord().getSlideListWithTexts()[1];
byte[] raw_slwt = writeRecord(refSLWT);
// Write out the same for the supplied slideshow
SlideListWithText s_SLWT = s.getDocumentRecord().getSlideListWithTexts()[1];
byte[] s_slwt = writeRecord(s_SLWT);
// Check the records are the same
assertEquals(refSLWT.getChildRecords().length, s_SLWT.getChildRecords().length);
for (int i = 0; i < refSLWT.getChildRecords().length; i++) {
Record ref_r = refSLWT.getChildRecords()[i];
Record s_r = s_SLWT.getChildRecords()[i];
byte[] r_rb = writeRecord(ref_r);
byte[] s_rb = writeRecord(s_r);
assertArrayEquals(r_rb, s_rb);
}
// Check the bytes are the same
assertArrayEquals(raw_slwt, s_slwt);
}
use of org.apache.poi.hslf.record.SlideListWithText in project poi by apache.
the class TextStyleListing method main.
public static void main(String[] args) throws IOException {
if (args.length < 1) {
System.err.println("Need to give a filename");
System.exit(1);
}
HSLFSlideShowImpl ss = new HSLFSlideShowImpl(args[0]);
// Find the documents, and then their SLWT
Record[] records = ss.getRecords();
for (int i = 0; i < records.length; i++) {
if (records[i].getRecordType() == 1000l) {
Record docRecord = records[i];
Record[] docChildren = docRecord.getChildRecords();
for (int j = 0; j < docChildren.length; j++) {
if (docChildren[j] instanceof SlideListWithText) {
Record[] slwtChildren = docChildren[j].getChildRecords();
int lastTextLen = -1;
for (int k = 0; k < slwtChildren.length; k++) {
if (slwtChildren[k] instanceof TextCharsAtom) {
lastTextLen = ((TextCharsAtom) slwtChildren[k]).getText().length();
}
if (slwtChildren[k] instanceof TextBytesAtom) {
lastTextLen = ((TextBytesAtom) slwtChildren[k]).getText().length();
}
if (slwtChildren[k] instanceof StyleTextPropAtom) {
StyleTextPropAtom stpa = (StyleTextPropAtom) slwtChildren[k];
stpa.setParentTextSize(lastTextLen);
showStyleTextPropAtom(stpa);
}
}
}
}
}
}
ss.close();
}
Aggregations