Search in sources :

Example 1 with SlideListWithText

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();
}
Also used : SlideListWithText(org.apache.poi.hslf.record.SlideListWithText) Record(org.apache.poi.hslf.record.Record) Document(org.apache.poi.hslf.record.Document) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Example 2 with SlideListWithText

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;
}
Also used : SlideListWithText(org.apache.poi.hslf.record.SlideListWithText) ArrayList(java.util.ArrayList) TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) TextHeaderAtom(org.apache.poi.hslf.record.TextHeaderAtom) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) MasterTextPropAtom(org.apache.poi.hslf.record.MasterTextPropAtom) List(java.util.List) ArrayList(java.util.ArrayList) Record(org.apache.poi.hslf.record.Record) StyleTextPropAtom(org.apache.poi.hslf.record.StyleTextPropAtom) TextRulerAtom(org.apache.poi.hslf.record.TextRulerAtom)

Example 3 with SlideListWithText

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();
}
Also used : SlideListWithText(org.apache.poi.hslf.record.SlideListWithText) SlideAtomsSet(org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) Record(org.apache.poi.hslf.record.Record) Document(org.apache.poi.hslf.record.Document) TextHeaderAtom(org.apache.poi.hslf.record.TextHeaderAtom) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) Test(org.junit.Test)

Example 4 with SlideListWithText

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);
}
Also used : SlideListWithText(org.apache.poi.hslf.record.SlideListWithText) Record(org.apache.poi.hslf.record.Record)

Example 5 with SlideListWithText

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();
}
Also used : SlideListWithText(org.apache.poi.hslf.record.SlideListWithText) Record(org.apache.poi.hslf.record.Record) TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom) StyleTextPropAtom(org.apache.poi.hslf.record.StyleTextPropAtom) HSLFSlideShowImpl(org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)

Aggregations

Record (org.apache.poi.hslf.record.Record)7 SlideListWithText (org.apache.poi.hslf.record.SlideListWithText)7 Document (org.apache.poi.hslf.record.Document)4 HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)4 TextBytesAtom (org.apache.poi.hslf.record.TextBytesAtom)3 TextCharsAtom (org.apache.poi.hslf.record.TextCharsAtom)3 SlidePersistAtom (org.apache.poi.hslf.record.SlidePersistAtom)2 StyleTextPropAtom (org.apache.poi.hslf.record.StyleTextPropAtom)2 TextHeaderAtom (org.apache.poi.hslf.record.TextHeaderAtom)2 DrawPaint (org.apache.poi.sl.draw.DrawPaint)2 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)1 MasterTextPropAtom (org.apache.poi.hslf.record.MasterTextPropAtom)1 Notes (org.apache.poi.hslf.record.Notes)1 NotesAtom (org.apache.poi.hslf.record.NotesAtom)1 PersistPtrHolder (org.apache.poi.hslf.record.PersistPtrHolder)1 PositionDependentRecord (org.apache.poi.hslf.record.PositionDependentRecord)1