Example #1
0
  /**
   * Create a new ShapeGroup and create an instance of <code>EscherSpgrContainer</code> which
   * represents a group of shapes
   */
  protected EscherContainerRecord createSpContainer(boolean isChild) {
    EscherContainerRecord spgr = new EscherContainerRecord();
    spgr.setRecordId(EscherContainerRecord.SPGR_CONTAINER);
    spgr.setOptions((short) 15);

    // The group itself is a shape, and always appears as the first EscherSpContainer in the group
    // container.
    EscherContainerRecord spcont = new EscherContainerRecord();
    spcont.setRecordId(EscherContainerRecord.SP_CONTAINER);
    spcont.setOptions((short) 15);

    EscherSpgrRecord spg = new EscherSpgrRecord();
    spg.setOptions((short) 1);
    spcont.addChildRecord(spg);

    EscherSpRecord sp = new EscherSpRecord();
    short type = (ShapeTypes.NotPrimitive << 4) + 2;
    sp.setOptions(type);
    sp.setFlags(EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_GROUP);
    spcont.addChildRecord(sp);

    EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
    spcont.addChildRecord(anchor);

    spgr.addChildRecord(spcont);
    return spgr;
  }
Example #2
0
  @Override
  public HSLFPictureData addPicture(byte[] data, PictureType format) throws IOException {
    if (format == null || format.nativeId == -1) {
      throw new IllegalArgumentException("Unsupported picture format: " + format);
    }

    byte[] uid = HSLFPictureData.getChecksum(data);

    for (HSLFPictureData pd : getPictureData()) {
      if (Arrays.equals(pd.getUID(), uid)) {
        return pd;
      }
    }

    EscherContainerRecord bstore;

    EscherContainerRecord dggContainer = _documentRecord.getPPDrawingGroup().getDggContainer();
    bstore =
        (EscherContainerRecord)
            HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
    if (bstore == null) {
      bstore = new EscherContainerRecord();
      bstore.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);

      dggContainer.addChildBefore(bstore, EscherOptRecord.RECORD_ID);
    }

    HSLFPictureData pict = HSLFPictureData.create(format);
    pict.setData(data);

    int offset = _hslfSlideShow.addPicture(pict);

    EscherBSERecord bse = new EscherBSERecord();
    bse.setRecordId(EscherBSERecord.RECORD_ID);
    bse.setOptions((short) (0x0002 | (format.nativeId << 4)));
    bse.setSize(pict.getRawData().length + 8);
    bse.setUid(uid);

    bse.setBlipTypeMacOS((byte) format.nativeId);
    bse.setBlipTypeWin32((byte) format.nativeId);

    if (format == PictureType.EMF) {
      bse.setBlipTypeMacOS((byte) PictureType.PICT.nativeId);
    } else if (format == PictureType.WMF) {
      bse.setBlipTypeMacOS((byte) PictureType.PICT.nativeId);
    } else if (format == PictureType.PICT) {
      bse.setBlipTypeWin32((byte) PictureType.WMF.nativeId);
    }

    bse.setRef(0);
    bse.setOffset(offset);
    bse.setRemainingData(new byte[0]);

    bstore.addChildRecord(bse);
    int count = bstore.getChildRecords().size();
    bstore.setOptions((short) ((count << 4) | 0xF));

    return pict;
  }