Beispiel #1
0
  /**
   * Returns the anchor (the bounding box rectangle) of this shape group. All coordinates are
   * expressed in points (72 dpi).
   *
   * @return the anchor of this shape group
   */
  public Rectangle2D getAnchor2D() {
    EscherContainerRecord spContainer =
        (EscherContainerRecord) _escherContainer.getChildRecords().get(0);
    EscherClientAnchorRecord clientAnchor =
        (EscherClientAnchorRecord) getEscherChild(spContainer, EscherClientAnchorRecord.RECORD_ID);
    Rectangle2D.Float anchor = new Rectangle2D.Float();
    if (clientAnchor == null) {
      logger.log(
          POILogger.INFO,
          "EscherClientAnchorRecord was not found for shape group. Searching for EscherChildAnchorRecord.");
      EscherChildAnchorRecord rec =
          (EscherChildAnchorRecord) getEscherChild(spContainer, EscherChildAnchorRecord.RECORD_ID);
      anchor =
          new Rectangle2D.Float(
              (float) rec.getDx1() * POINT_DPI / MASTER_DPI,
              (float) rec.getDy1() * POINT_DPI / MASTER_DPI,
              (float) (rec.getDx2() - rec.getDx1()) * POINT_DPI / MASTER_DPI,
              (float) (rec.getDy2() - rec.getDy1()) * POINT_DPI / MASTER_DPI);
    } else {
      anchor.x = (float) clientAnchor.getCol1() * POINT_DPI / MASTER_DPI;
      anchor.y = (float) clientAnchor.getFlag() * POINT_DPI / MASTER_DPI;
      anchor.width =
          (float) (clientAnchor.getDx1() - clientAnchor.getCol1()) * POINT_DPI / MASTER_DPI;
      anchor.height =
          (float) (clientAnchor.getRow1() - clientAnchor.getFlag()) * POINT_DPI / MASTER_DPI;
    }

    return anchor;
  }
Beispiel #2
0
  /**
   * Sets the anchor (the bounding box rectangle) of this shape. All coordinates should be expressed
   * in Master units (576 dpi).
   *
   * @param anchor new anchor
   */
  public void setAnchor(java.awt.Rectangle anchor) {

    EscherContainerRecord spContainer =
        (EscherContainerRecord) _escherContainer.getChildRecords().get(0);

    EscherClientAnchorRecord clientAnchor =
        (EscherClientAnchorRecord) getEscherChild(spContainer, EscherClientAnchorRecord.RECORD_ID);
    // hack. internal variable EscherClientAnchorRecord.shortRecord can be
    // initialized only in fillFields(). We need to set shortRecord=false;
    byte[] header = new byte[16];
    LittleEndian.putUShort(header, 0, 0);
    LittleEndian.putUShort(header, 2, 0);
    LittleEndian.putInt(header, 4, 8);
    clientAnchor.fillFields(header, 0, null);

    clientAnchor.setFlag((short) (anchor.y * MASTER_DPI / POINT_DPI));
    clientAnchor.setCol1((short) (anchor.x * MASTER_DPI / POINT_DPI));
    clientAnchor.setDx1((short) ((anchor.width + anchor.x) * MASTER_DPI / POINT_DPI));
    clientAnchor.setRow1((short) ((anchor.height + anchor.y) * MASTER_DPI / POINT_DPI));

    EscherSpgrRecord spgr =
        (EscherSpgrRecord) getEscherChild(spContainer, EscherSpgrRecord.RECORD_ID);

    spgr.setRectX1(anchor.x * MASTER_DPI / POINT_DPI);
    spgr.setRectY1(anchor.y * MASTER_DPI / POINT_DPI);
    spgr.setRectX2((anchor.x + anchor.width) * MASTER_DPI / POINT_DPI);
    spgr.setRectY2((anchor.y + anchor.height) * MASTER_DPI / POINT_DPI);
  }