Search in sources :

Example 1 with EscherTextboxRecord

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);
    }
}
Also used : EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) HSLFEscherRecordFactory(org.apache.poi.hslf.record.HSLFEscherRecordFactory) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) DefaultEscherRecordFactory(org.apache.poi.ddf.DefaultEscherRecordFactory)

Example 2 with EscherTextboxRecord

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;
    }
}
Also used : EscherTextboxWrapper(org.apache.poi.hslf.record.EscherTextboxWrapper) Record(org.apache.poi.hslf.record.Record) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) TextCharsAtom(org.apache.poi.hslf.record.TextCharsAtom) StyleTextPropAtom(org.apache.poi.hslf.record.StyleTextPropAtom) TextBytesAtom(org.apache.poi.hslf.record.TextBytesAtom)

Example 3 with EscherTextboxRecord

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);
        }
    }
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) EscherRecord(org.apache.poi.ddf.EscherRecord)

Example 4 with EscherTextboxRecord

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;
}
Also used : PPDrawing(org.apache.poi.hslf.record.PPDrawing) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord) EscherTextboxWrapper(org.apache.poi.hslf.record.EscherTextboxWrapper)

Example 5 with EscherTextboxRecord

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;
}
Also used : EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) ShapeType(org.apache.poi.sl.usermodel.ShapeType) EscherTextboxRecord(org.apache.poi.ddf.EscherTextboxRecord)

Aggregations

EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)8 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)4 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)4 EscherRecord (org.apache.poi.ddf.EscherRecord)3 EscherTextboxWrapper (org.apache.poi.hslf.record.EscherTextboxWrapper)2 LinkedList (java.util.LinkedList)1 DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)1 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)1 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)1 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)1 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)1 EscherShapePathProperty (org.apache.poi.ddf.EscherShapePathProperty)1 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)1 HSLFEscherRecordFactory (org.apache.poi.hslf.record.HSLFEscherRecordFactory)1 PPDrawing (org.apache.poi.hslf.record.PPDrawing)1 Record (org.apache.poi.hslf.record.Record)1 StyleTextPropAtom (org.apache.poi.hslf.record.StyleTextPropAtom)1 TextBytesAtom (org.apache.poi.hslf.record.TextBytesAtom)1 TextCharsAtom (org.apache.poi.hslf.record.TextCharsAtom)1 ShapeType (org.apache.poi.sl.usermodel.ShapeType)1