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);
}
}
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);
}
Aggregations