Search in sources :

Example 11 with HSLFException

use of org.apache.poi.hslf.exceptions.HSLFException in project poi by apache.

the class PICT method getData.

@Override
public byte[] getData() {
    byte[] rawdata = getRawData();
    try {
        byte[] macheader = new byte[512];
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        out.write(macheader);
        int pos = CHECKSUM_SIZE * getUIDInstanceCount();
        byte[] pict = read(rawdata, pos);
        out.write(pict);
        return out.toByteArray();
    } catch (IOException e) {
        throw new HSLFException(e);
    }
}
Also used : HSLFException(org.apache.poi.hslf.exceptions.HSLFException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 12 with HSLFException

use of org.apache.poi.hslf.exceptions.HSLFException in project poi by apache.

the class EMF method getData.

@Override
public byte[] getData() {
    try {
        byte[] rawdata = getRawData();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        InputStream is = new ByteArrayInputStream(rawdata);
        Header header = new Header();
        header.read(rawdata, CHECKSUM_SIZE);
        long len = is.skip(header.getSize() + (long) CHECKSUM_SIZE);
        assert (len == header.getSize() + CHECKSUM_SIZE);
        InflaterInputStream inflater = new InflaterInputStream(is);
        byte[] chunk = new byte[4096];
        int count;
        while ((count = inflater.read(chunk)) >= 0) {
            out.write(chunk, 0, count);
        }
        inflater.close();
        return out.toByteArray();
    } catch (IOException e) {
        throw new HSLFException(e);
    }
}
Also used : HSLFException(org.apache.poi.hslf.exceptions.HSLFException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 13 with HSLFException

use of org.apache.poi.hslf.exceptions.HSLFException in project poi by apache.

the class TxMasterStyleAtom method updateStyles.

/**
     * Updates the rawdata from the modified paragraph/character styles
     * 
     * @since POI 3.14-beta1
     */
public void updateStyles() {
    int type = getTextType();
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        LittleEndianOutputStream leos = new LittleEndianOutputStream(bos);
        int levels = paragraphStyles.size();
        leos.writeShort(levels);
        TextPropCollection prdummy = new TextPropCollection(0, TextPropType.paragraph);
        TextPropCollection chdummy = new TextPropCollection(0, TextPropType.character);
        for (int i = 0; i < levels; i++) {
            prdummy.copy(paragraphStyles.get(i));
            chdummy.copy(charStyles.get(i));
            if (type >= TextHeaderAtom.CENTRE_BODY_TYPE) {
                leos.writeShort(prdummy.getIndentLevel());
            }
            // Indent level is not written for master styles
            prdummy.setIndentLevel((short) -1);
            prdummy.writeOut(bos, true);
            chdummy.writeOut(bos, true);
        }
        _data = bos.toByteArray();
        leos.close();
        LittleEndian.putInt(_header, 4, _data.length);
    } catch (IOException e) {
        throw new HSLFException("error in updating master style properties", e);
    }
}
Also used : HSLFException(org.apache.poi.hslf.exceptions.HSLFException) LittleEndianOutputStream(org.apache.poi.util.LittleEndianOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TextPropCollection(org.apache.poi.hslf.model.textproperties.TextPropCollection)

Example 14 with HSLFException

use of org.apache.poi.hslf.exceptions.HSLFException in project poi by apache.

the class HSLFSimpleShape method getAdjustValue.

@Override
public Guide getAdjustValue(String name) {
    if (name == null || !name.matches("adj([1-9]|10)?")) {
        LOG.log(POILogger.INFO, "Adjust value '" + name + "' not supported. Using default value.");
        return null;
    }
    name = name.replace("adj", "");
    if ("".equals(name)) {
        name = "1";
    }
    short escherProp;
    switch(Integer.parseInt(name)) {
        case 1:
            escherProp = EscherProperties.GEOMETRY__ADJUSTVALUE;
            break;
        case 2:
            escherProp = EscherProperties.GEOMETRY__ADJUST2VALUE;
            break;
        case 3:
            escherProp = EscherProperties.GEOMETRY__ADJUST3VALUE;
            break;
        case 4:
            escherProp = EscherProperties.GEOMETRY__ADJUST4VALUE;
            break;
        case 5:
            escherProp = EscherProperties.GEOMETRY__ADJUST5VALUE;
            break;
        case 6:
            escherProp = EscherProperties.GEOMETRY__ADJUST6VALUE;
            break;
        case 7:
            escherProp = EscherProperties.GEOMETRY__ADJUST7VALUE;
            break;
        case 8:
            escherProp = EscherProperties.GEOMETRY__ADJUST8VALUE;
            break;
        case 9:
            escherProp = EscherProperties.GEOMETRY__ADJUST9VALUE;
            break;
        case 10:
            escherProp = EscherProperties.GEOMETRY__ADJUST10VALUE;
            break;
        default:
            throw new HSLFException();
    }
    // TODO: the adjust values need to be corrected somehow depending on the shape width/height
    // see https://social.msdn.microsoft.com/Forums/en-US/3f69ebb3-62a0-4fdd-b367-64790dfb2491/presetshapedefinitionsxml-does-not-specify-width-and-height-form-some-autoshapes?forum=os_binaryfile
    // the adjust value can be format dependent, e.g. hexagon has different values,
    // other shape types have the same adjust values in OOXML and native
    int adjval = getEscherProperty(escherProp, -1);
    return (adjval == -1) ? null : new Guide(name, "val " + adjval);
}
Also used : Guide(org.apache.poi.sl.draw.geom.Guide) HSLFException(org.apache.poi.hslf.exceptions.HSLFException) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)

Example 15 with HSLFException

use of org.apache.poi.hslf.exceptions.HSLFException in project poi by apache.

the class HSLFSimpleShape method setPlaceholder.

@Override
public void setPlaceholder(Placeholder placeholder) {
    EscherSpRecord spRecord = getEscherChild(EscherSpRecord.RECORD_ID);
    int flags = spRecord.getFlags();
    if (placeholder == null) {
        flags ^= EscherSpRecord.FLAG_HAVEMASTER;
    } else {
        flags |= EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_HAVEMASTER;
    }
    spRecord.setFlags(flags);
    // Placeholders can't be grouped
    setEscherProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, (placeholder == null ? -1 : 262144));
    HSLFEscherClientDataRecord clientData = getClientData(false);
    if (placeholder == null) {
        if (clientData != null) {
            clientData.removeChild(OEPlaceholderAtom.class);
            clientData.removeChild(RoundTripHFPlaceholder12.class);
            // remove client data if the placeholder was the only child to be carried
            if (clientData.getChildRecords().isEmpty()) {
                getSpContainer().removeChildRecord(clientData);
            }
        }
        return;
    }
    if (clientData == null) {
        clientData = getClientData(true);
    }
    // OEPlaceholderAtom tells powerpoint that this shape is a placeholder
    OEPlaceholderAtom oep = null;
    RoundTripHFPlaceholder12 rtp = null;
    for (Record r : clientData.getHSLFChildRecords()) {
        if (r instanceof OEPlaceholderAtom) {
            oep = (OEPlaceholderAtom) r;
            break;
        }
        if (r instanceof RoundTripHFPlaceholder12) {
            rtp = (RoundTripHFPlaceholder12) r;
            break;
        }
    }
    /**
         * Extract from MSDN:
         *
         * There is a special case when the placeholder does not have a position in the layout.
         * This occurs when the user has moved the placeholder from its original position.
         * In this case the placeholder ID is -1.
         */
    byte phId;
    HSLFSheet sheet = getSheet();
    // TODO: implement/switch NotesMaster
    if (sheet instanceof HSLFSlideMaster) {
        phId = (byte) placeholder.nativeSlideMasterId;
    } else if (sheet instanceof HSLFNotes) {
        phId = (byte) placeholder.nativeNotesId;
    } else {
        phId = (byte) placeholder.nativeSlideId;
    }
    if (phId == -2) {
        throw new HSLFException("Placeholder " + placeholder.name() + " not supported for this sheet type (" + sheet.getClass() + ")");
    }
    switch(placeholder) {
        case HEADER:
        case FOOTER:
            if (rtp == null) {
                rtp = new RoundTripHFPlaceholder12();
                rtp.setPlaceholderId(phId);
                clientData.addChild(rtp);
            }
            if (oep != null) {
                clientData.removeChild(OEPlaceholderAtom.class);
            }
            break;
        default:
            if (rtp != null) {
                clientData.removeChild(RoundTripHFPlaceholder12.class);
            }
            if (oep == null) {
                oep = new OEPlaceholderAtom();
                oep.setPlaceholderSize((byte) OEPlaceholderAtom.PLACEHOLDER_FULLSIZE);
                // TODO: placement id only "SHOULD" be unique ... check other placeholders on sheet for unique id
                oep.setPlacementId(-1);
                oep.setPlaceholderId(phId);
                clientData.addChild(oep);
            }
            break;
    }
}
Also used : RoundTripHFPlaceholder12(org.apache.poi.hslf.record.RoundTripHFPlaceholder12) HSLFException(org.apache.poi.hslf.exceptions.HSLFException) HSLFEscherClientDataRecord(org.apache.poi.hslf.record.HSLFEscherClientDataRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherChildAnchorRecord(org.apache.poi.ddf.EscherChildAnchorRecord) Record(org.apache.poi.hslf.record.Record) AbstractEscherOptRecord(org.apache.poi.ddf.AbstractEscherOptRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherClientAnchorRecord(org.apache.poi.ddf.EscherClientAnchorRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) HSLFEscherClientDataRecord(org.apache.poi.hslf.record.HSLFEscherClientDataRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint) OEPlaceholderAtom(org.apache.poi.hslf.record.OEPlaceholderAtom)

Aggregations

HSLFException (org.apache.poi.hslf.exceptions.HSLFException)20 IOException (java.io.IOException)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 DrawPaint (org.apache.poi.sl.draw.DrawPaint)4 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HashMap (java.util.HashMap)3 TextPropCollection (org.apache.poi.hslf.model.textproperties.TextPropCollection)3 Record (org.apache.poi.hslf.record.Record)3 InputStream (java.io.InputStream)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 InflaterInputStream (java.util.zip.InflaterInputStream)2 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)2 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)2 EscherTextboxWrapper (org.apache.poi.hslf.record.EscherTextboxWrapper)2 TextHeaderAtom (org.apache.poi.hslf.record.TextHeaderAtom)2 Rectangle2D (java.awt.geom.Rectangle2D)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1