use of org.apache.poi.ddf.EscherTextboxRecord in project poi by apache.
the class SlideShowDumper method walkEscherDDF.
/**
* Use the DDF code to walk the Escher records
*/
public void walkEscherDDF(int indent, int pos, int len) {
if (len < 8) {
return;
}
final String ind = (indent == 0) ? "%1$s" : "%1$" + indent + "s";
byte[] contents = new byte[len];
System.arraycopy(docstream, pos, contents, 0, len);
DefaultEscherRecordFactory erf = new HSLFEscherRecordFactory();
EscherRecord record = erf.createRecord(contents, 0);
// For now, try filling in the fields
record.fillFields(contents, 0, erf);
long atomType = LittleEndian.getUShort(contents, 2);
// This lacks the 8 byte header size
long atomLen = LittleEndian.getUShort(contents, 4);
// This (should) include the 8 byte header size
int recordLen = record.getRecordSize();
String fmt = ind + "At position %2$d (%2$04x): type is %3$d (%3$04x), len is %4$d (%4$04x) (%5$d) - record claims %6$d";
out.println(String.format(Locale.ROOT, fmt, "", pos, atomType, atomLen, atomLen + 8, recordLen));
// Check for corrupt / lying ones
if (recordLen != 8 && (recordLen != (atomLen + 8))) {
out.println(String.format(Locale.ROOT, ind + "** Atom length of $2d ($3d) doesn't match record length of %4d", "", atomLen, atomLen + 8, recordLen));
}
// Print the record's details
String recordStr = record.toString().replace("\n", String.format(Locale.ROOT, "\n" + ind, ""));
out.println(String.format(Locale.ROOT, ind + "%2$s", "", recordStr));
if (record instanceof EscherContainerRecord) {
walkEscherDDF((indent + 3), pos + 8, (int) atomLen);
}
// Handle records that seem to lie
if (atomType == 61451L) {
// Normally claims a size of 8
recordLen = (int) atomLen + 8;
}
if (atomType == 61453L) {
// Returns EscherContainerRecord, but really msofbtClientTextbox
recordLen = (int) atomLen + 8;
record.fillFields(contents, 0, erf);
if (!(record instanceof EscherTextboxRecord)) {
out.println(String.format(Locale.ROOT, ind + "%2$s", "", "** Really a msofbtClientTextbox !"));
}
}
// Decide on what to do, based on how the lengths match up
if (recordLen == 8 && atomLen > 8) {
// Assume it has children, rather than being corrupted
walkEscherDDF((indent + 3), pos + 8, (int) atomLen);
// Wind on our length + our header
pos += atomLen;
pos += 8;
len -= atomLen;
len -= 8;
} else {
// No children, wind on our real length
pos += atomLen;
pos += 8;
len -= atomLen;
len -= 8;
}
// Move on to the next one, if we're not at the end yet
if (len >= 8) {
walkEscherDDF(indent, pos, len);
}
}
use of org.apache.poi.ddf.EscherTextboxRecord in project poi by apache.
the class SlideShowRecordDumper method printEscherTextBox.
private void printEscherTextBox(EscherTextboxRecord tbRecord, int indent) {
String ind = tabs.substring(0, indent);
ps.println(ind + "EscherTextboxRecord:");
EscherTextboxWrapper etw = new EscherTextboxWrapper(tbRecord);
Record prevChild = null;
for (Record child : etw.getChildRecords()) {
if (child instanceof StyleTextPropAtom) {
// need preceding Text[Chars|Bytes]Atom to initialize the data structure
String text = null;
if (prevChild instanceof TextCharsAtom) {
text = ((TextCharsAtom) prevChild).getText();
} else if (prevChild instanceof TextBytesAtom) {
text = ((TextBytesAtom) prevChild).getText();
} else {
ps.println(ind + "Error! Couldn't find preceding TextAtom for style");
continue;
}
StyleTextPropAtom tsp = (StyleTextPropAtom) child;
tsp.setParentTextSize(text.length());
}
ps.println(ind + child);
prevChild = child;
}
}
use of org.apache.poi.ddf.EscherTextboxRecord in project poi by apache.
the class PPDrawing method findEscherTextboxRecord.
/**
* Look for EscherTextboxRecords
*/
private void findEscherTextboxRecord(List<EscherRecord> toSearch, List<EscherTextboxWrapper> found) {
EscherSpRecord sp = null;
for (EscherRecord r : toSearch) {
if (r instanceof EscherSpRecord) {
sp = (EscherSpRecord) r;
} else if (r instanceof EscherTextboxRecord) {
EscherTextboxRecord tbr = (EscherTextboxRecord) r;
EscherTextboxWrapper w = new EscherTextboxWrapper(tbr);
if (sp != null) {
w.setShapeId(sp.getShapeId());
}
found.add(w);
} else if (r.isContainerRecord()) {
// If it has children, walk them
List<EscherRecord> children = r.getChildRecords();
findEscherTextboxRecord(children, found);
}
}
}
use of org.apache.poi.ddf.EscherTextboxRecord in project poi by apache.
the class HSLFTextShape method getEscherTextboxWrapper.
protected EscherTextboxWrapper getEscherTextboxWrapper() {
if (_txtbox != null) {
return _txtbox;
}
EscherTextboxRecord textRecord = getEscherChild(EscherTextboxRecord.RECORD_ID);
if (textRecord == null) {
return null;
}
HSLFSheet sheet = getSheet();
if (sheet != null) {
PPDrawing drawing = sheet.getPPDrawing();
if (drawing != null) {
EscherTextboxWrapper[] wrappers = drawing.getTextboxWrappers();
if (wrappers != null) {
for (EscherTextboxWrapper w : wrappers) {
// check for object identity
if (textRecord == w.getEscherRecord()) {
_txtbox = w;
return _txtbox;
}
}
}
}
}
_txtbox = new EscherTextboxWrapper(textRecord);
return _txtbox;
}
use of org.apache.poi.ddf.EscherTextboxRecord in project poi by apache.
the class HSLFShapeFactory method createSimpleShape.
public static HSLFShape createSimpleShape(EscherContainerRecord spContainer, ShapeContainer<HSLFShape, HSLFTextParagraph> parent) {
HSLFShape shape = null;
EscherSpRecord spRecord = spContainer.getChildById(EscherSpRecord.RECORD_ID);
ShapeType type = ShapeType.forId(spRecord.getShapeType(), false);
switch(type) {
case TEXT_BOX:
shape = new HSLFTextBox(spContainer, parent);
break;
case HOST_CONTROL:
case FRAME:
shape = createFrame(spContainer, parent);
break;
case LINE:
shape = new HSLFLine(spContainer, parent);
break;
case NOT_PRIMITIVE:
shape = createNonPrimitive(spContainer, parent);
break;
default:
if (parent instanceof HSLFTable) {
EscherTextboxRecord etr = spContainer.getChildById(EscherTextboxRecord.RECORD_ID);
if (etr == null) {
logger.log(POILogger.WARN, "invalid ppt - add EscherTextboxRecord to cell");
etr = new EscherTextboxRecord();
etr.setRecordId(EscherTextboxRecord.RECORD_ID);
etr.setOptions((short) 15);
spContainer.addChildRecord(etr);
}
shape = new HSLFTableCell(spContainer, (HSLFTable) parent);
} else {
shape = new HSLFAutoShape(spContainer, parent);
}
break;
}
return shape;
}
Aggregations