Search in sources :

Example 41 with EscherRecord

use of org.apache.poi.ddf.EscherRecord in project poi by apache.

the class PPDrawing method findEscherChildren.

/**
	 * Tree walking way of finding Escher Child Records
	 */
private void findEscherChildren(DefaultEscherRecordFactory erf, byte[] source, int startPos, int lenToGo, List<EscherRecord> found) {
    int escherBytes = LittleEndian.getInt(source, startPos + 4) + 8;
    // Find the record
    EscherRecord r = erf.createRecord(source, startPos);
    // Fill it in
    r.fillFields(source, startPos, erf);
    // Save it
    found.add(r);
    // Wind on
    int size = r.getRecordSize();
    if (size < 8) {
        logger.log(POILogger.WARN, "Hit short DDF record at " + startPos + " - " + size);
    }
    /**
		 * Sanity check. Always advance the cursor by the correct value.
		 *
		 * getRecordSize() must return exactly the same number of bytes that was written in fillFields.
		 * Sometimes it is not so, see an example in bug #44770. Most likely reason is that one of ddf records calculates wrong size.
		 */
    if (size != escherBytes) {
        logger.log(POILogger.WARN, "Record length=" + escherBytes + " but getRecordSize() returned " + r.getRecordSize() + "; record: " + r.getClass());
        size = escherBytes;
    }
    startPos += size;
    lenToGo -= size;
    if (lenToGo >= 8) {
        findEscherChildren(erf, source, startPos, lenToGo, found);
    }
}
Also used : EscherRecord(org.apache.poi.ddf.EscherRecord)

Example 42 with EscherRecord

use of org.apache.poi.ddf.EscherRecord in project poi by apache.

the class PPDrawing method writeOut.

/**
	 * Write the contents of the record back, so it can be written
	 *  to disk
	 * Walks the escher layer to get the contents
	 */
public void writeOut(OutputStream out) throws IOException {
    // Ensure the escher layer reflects the text changes
    for (EscherTextboxWrapper w : textboxWrappers) {
        w.writeOut(null);
    }
    // Find the new size of the escher children;
    int newSize = 0;
    for (EscherRecord er : childRecords) {
        newSize += er.getRecordSize();
    }
    // Update the size (header bytes 5-8)
    LittleEndian.putInt(_header, 4, newSize);
    // Write out our header
    out.write(_header);
    // Now grab the children's data
    byte[] b = new byte[newSize];
    int done = 0;
    for (EscherRecord r : childRecords) {
        done += r.serialize(done, b);
    }
    // Finally, write out the children
    out.write(b);
}
Also used : EscherRecord(org.apache.poi.ddf.EscherRecord)

Aggregations

EscherRecord (org.apache.poi.ddf.EscherRecord)42 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)20 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)10 DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)9 ArrayList (java.util.ArrayList)7 EscherRecordFactory (org.apache.poi.ddf.EscherRecordFactory)6 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)6 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)6 DrawingGroupRecord (org.apache.poi.hssf.record.DrawingGroupRecord)5 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)4 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)4 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)4 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)4 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)4 Document (org.apache.poi.hslf.record.Document)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)3 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)3 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)3 EscherProperty (org.apache.poi.ddf.EscherProperty)2