Package org.apache.poi.ddf

Examples of org.apache.poi.ddf.EscherContainerRecord$ReadOnlyIterator


    }

    // The top level container ought to have
    //  the DgRecord and the container of one container
    //  per shape group (patriach overall first)
    EscherContainerRecord topContainer = getEscherContainer();
    if(topContainer == null) {
      return;
    }
    topContainer = topContainer.getChildContainers().get(0);

    List tcc = topContainer.getChildContainers();
    if(tcc.size() == 0) {
      throw new IllegalStateException("No child escher containers at the point that should hold the patriach data, and one container per top level shape!");
    }

    // First up, get the patriach position
    // This is in the first EscherSpgrRecord, in
    //  the first container, with a EscherSRecord too
    EscherContainerRecord patriachContainer =
      (EscherContainerRecord)tcc.get(0);
    EscherSpgrRecord spgr = null;
    for(Iterator<EscherRecord> it = patriachContainer.getChildIterator(); it.hasNext();) {
      EscherRecord r = it.next();
      if(r instanceof EscherSpgrRecord) {
        spgr = (EscherSpgrRecord)r;
        break;
      }
    }
    if(spgr != null) {
      patriarch.setCoordinates(
          spgr.getRectX1(), spgr.getRectY1(),
          spgr.getRectX2(), spgr.getRectY2()
      );
    }

    // Now process the containers for each group
    //  and objects
    for(int i=1; i<tcc.size(); i++) {
      EscherContainerRecord shapeContainer =
        (EscherContainerRecord)tcc.get(i);
      //System.err.println("\n\n*****\n\n");
      //System.err.println(shapeContainer);

      // Could be a group, or a base object
      if(shapeContainer.getChildRecords().size() == 1 &&
          shapeContainer.getChildContainers().size() == 1) {
        // Group
        HSSFShapeGroup group =
          new HSSFShapeGroup(null, new HSSFClientAnchor());
        patriarch.getChildren().add(group);

        EscherContainerRecord groupContainer =
          (EscherContainerRecord)shapeContainer.getChild(0);
        convertRecordsToUserModel(groupContainer, group);
      } else if(shapeContainer.hasChildOfType((short)0xF00D)) {
        // TextBox
        HSSFTextbox box =
View Full Code Here


      tailRec.clear();
      clearEscherRecords();
      if ( patriarch.getChildren().size() != 0 )
      {
        convertPatriarch( patriarch );
        EscherContainerRecord dgContainer = (EscherContainerRecord) getEscherRecord( 0 );
        EscherContainerRecord spgrContainer = null;
        Iterator<EscherRecord> iter = dgContainer.getChildIterator();
        while (iter.hasNext()) {
          EscherRecord child = iter.next();
          if (child.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
            spgrContainer = (EscherContainerRecord) child;
View Full Code Here

  }

  private void convertGroup( HSSFShapeGroup shape, EscherContainerRecord escherParent, Map shapeToObj )
  {
    EscherContainerRecord spgrContainer = new EscherContainerRecord();
    EscherContainerRecord spContainer = new EscherContainerRecord();
    EscherSpgrRecord spgr = new EscherSpgrRecord();
    EscherSpRecord sp = new EscherSpRecord();
    EscherOptRecord opt = new EscherOptRecord();
    EscherRecord anchor;
    EscherClientDataRecord clientData = new EscherClientDataRecord();

    spgrContainer.setRecordId( EscherContainerRecord.SPGR_CONTAINER );
    spgrContainer.setOptions( (short) 0x000F );
    spContainer.setRecordId( EscherContainerRecord.SP_CONTAINER );
    spContainer.setOptions( (short) 0x000F );
    spgr.setRecordId( EscherSpgrRecord.RECORD_ID );
    spgr.setOptions( (short) 0x0001 );
    spgr.setRectX1( shape.getX1() );
    spgr.setRectY1( shape.getY1() );
    spgr.setRectX2( shape.getX2() );
    spgr.setRectY2( shape.getY2() );
    sp.setRecordId( EscherSpRecord.RECORD_ID );
    sp.setOptions( (short) 0x0002 );
    int shapeId = drawingManager.allocateShapeId(drawingGroupId);
    sp.setShapeId( shapeId );
    if (shape.getAnchor() instanceof HSSFClientAnchor)
      sp.setFlags( EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR );
    else
      sp.setFlags( EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_HAVEANCHOR | EscherSpRecord.FLAG_CHILD );
    opt.setRecordId( EscherOptRecord.RECORD_ID );
    opt.setOptions( (short) 0x0023 );
    opt.addEscherProperty( new EscherBoolProperty( EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00040004 ) );
    opt.addEscherProperty( new EscherBoolProperty( EscherProperties.GROUPSHAPE__PRINT, 0x00080000 ) );

    anchor = ConvertAnchor.createAnchor( shape.getAnchor() );
//    clientAnchor.setCol1( ( (HSSFClientAnchor) shape.getAnchor() ).getCol1() );
//    clientAnchor.setRow1( (short) ( (HSSFClientAnchor) shape.getAnchor() ).getRow1() );
//    clientAnchor.setDx1( (short) shape.getAnchor().getDx1() );
//    clientAnchor.setDy1( (short) shape.getAnchor().getDy1() );
//    clientAnchor.setCol2( ( (HSSFClientAnchor) shape.getAnchor() ).getCol2() );
//    clientAnchor.setRow2( (short) ( (HSSFClientAnchor) shape.getAnchor() ).getRow2() );
//    clientAnchor.setDx2( (short) shape.getAnchor().getDx2() );
//    clientAnchor.setDy2( (short) shape.getAnchor().getDy2() );
    clientData.setRecordId( EscherClientDataRecord.RECORD_ID );
    clientData.setOptions( (short) 0x0000 );

    spgrContainer.addChildRecord( spContainer );
    spContainer.addChildRecord( spgr );
    spContainer.addChildRecord( sp );
    spContainer.addChildRecord( opt );
    spContainer.addChildRecord( anchor );
    spContainer.addChildRecord( clientData );

    ObjRecord obj = new ObjRecord();
    CommonObjectDataSubRecord cmo = new CommonObjectDataSubRecord();
    cmo.setObjectType( CommonObjectDataSubRecord.OBJECT_TYPE_GROUP );
    cmo.setObjectId( shapeId );
View Full Code Here

    throw new IllegalArgumentException( "Can not find client data record" );
  }

  private void convertPatriarch( HSSFPatriarch patriarch )
  {
    EscherContainerRecord dgContainer = new EscherContainerRecord();
    EscherDgRecord dg;
    EscherContainerRecord spgrContainer = new EscherContainerRecord();
    EscherContainerRecord spContainer1 = new EscherContainerRecord();
    EscherSpgrRecord spgr = new EscherSpgrRecord();
    EscherSpRecord sp1 = new EscherSpRecord();

    dgContainer.setRecordId( EscherContainerRecord.DG_CONTAINER );
    dgContainer.setOptions( (short) 0x000F );
    dg = drawingManager.createDgRecord();
    drawingGroupId = dg.getDrawingGroupId();
//    dg.setOptions( (short) ( drawingId << 4 ) );
//    dg.setNumShapes( getNumberOfShapes( patriarch ) );
//    dg.setLastMSOSPID( 0 );  // populated after all shape id's are assigned.
    spgrContainer.setRecordId( EscherContainerRecord.SPGR_CONTAINER );
    spgrContainer.setOptions( (short) 0x000F );
    spContainer1.setRecordId( EscherContainerRecord.SP_CONTAINER );
    spContainer1.setOptions( (short) 0x000F );
    spgr.setRecordId( EscherSpgrRecord.RECORD_ID );
    spgr.setOptions( (short) 0x0001 )// version
    spgr.setRectX1( patriarch.getX1() );
    spgr.setRectY1( patriarch.getY1() );
    spgr.setRectX2( patriarch.getX2() );
    spgr.setRectY2( patriarch.getY2() );
    sp1.setRecordId( EscherSpRecord.RECORD_ID );
    sp1.setOptions( (short) 0x0002 );
    sp1.setShapeId( drawingManager.allocateShapeId(dg.getDrawingGroupId()) );
    sp1.setFlags( EscherSpRecord.FLAG_GROUP | EscherSpRecord.FLAG_PATRIARCH );

    dgContainer.addChildRecord( dg );
    dgContainer.addChildRecord( spgrContainer );
    spgrContainer.addChildRecord( spContainer1 );
    spContainer1.addChildRecord( spgr );
    spContainer1.addChildRecord( sp1 );

    addEscherRecord( dgContainer );
  }
View Full Code Here

            if(r instanceof DrawingGroupRecord) {
                DrawingGroupRecord dg = (DrawingGroupRecord)r;
                dg.processChildRecords();

                EscherContainerRecord cr =
                    dg.getEscherContainer();
                if(cr == null) {
                    continue;
                }

                EscherDggRecord dgg = null;
                for(Iterator<EscherRecord> it = cr.getChildIterator(); it.hasNext();) {
                    Object er = it.next();
                    if(er instanceof EscherDggRecord) {
                        dgg = (EscherDggRecord)er;
                    }
                }
View Full Code Here

     * Creates a primary drawing group record.  If it already
     *  exists then it's modified.
     */
    public void createDrawingGroup() {
        if (drawingManager == null) {
            EscherContainerRecord dggContainer = new EscherContainerRecord();
            EscherDggRecord dgg = new EscherDggRecord();
            EscherOptRecord opt = new EscherOptRecord();
            EscherSplitMenuColorsRecord splitMenuColors = new EscherSplitMenuColorsRecord();

            dggContainer.setRecordId((short) 0xF000);
            dggContainer.setOptions((short) 0x000F);
            dgg.setRecordId(EscherDggRecord.RECORD_ID);
            dgg.setOptions((short)0x0000);
            dgg.setShapeIdMax(1024);
            dgg.setNumShapesSaved(0);
            dgg.setDrawingsSaved(0);
            dgg.setFileIdClusters(new EscherDggRecord.FileIdCluster[] {} );
            drawingManager = new DrawingManager2(dgg);
            EscherContainerRecord bstoreContainer = null;
            if (escherBSERecords.size() > 0)
            {
                bstoreContainer = new EscherContainerRecord();
                bstoreContainer.setRecordId( EscherContainerRecord.BSTORE_CONTAINER );
                bstoreContainer.setOptions( (short) ( (escherBSERecords.size() << 4) | 0xF ) );
                for ( Iterator iterator = escherBSERecords.iterator(); iterator.hasNext(); )
                {
                    EscherRecord escherRecord = (EscherRecord) iterator.next();
                    bstoreContainer.addChildRecord( escherRecord );
                }
            }
            opt.setRecordId((short) 0xF00B);
            opt.setOptions((short) 0x0033);
            opt.addEscherProperty( new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 524296) );
View Full Code Here

        escherBSERecords.add( e );

        int dgLoc = findFirstRecordLocBySid(DrawingGroupRecord.sid);
        DrawingGroupRecord drawingGroup = (DrawingGroupRecord) getRecords().get( dgLoc );

        EscherContainerRecord dggContainer = (EscherContainerRecord) drawingGroup.getEscherRecord( 0 );
        EscherContainerRecord bstoreContainer;
        if (dggContainer.getChild( 1 ).getRecordId() == EscherContainerRecord.BSTORE_CONTAINER )
        {
            bstoreContainer = (EscherContainerRecord) dggContainer.getChild( 1 );
        }
        else
        {
            bstoreContainer = new EscherContainerRecord();
            bstoreContainer.setRecordId( EscherContainerRecord.BSTORE_CONTAINER );
            List<EscherRecord> childRecords = dggContainer.getChildRecords();
            childRecords.add(1, bstoreContainer);
            dggContainer.setChildRecords(childRecords);
        }
        bstoreContainer.setOptions( (short) ( (escherBSERecords.size() << 4) | 0xF ) );

        bstoreContainer.addChildRecord( e );

        return escherBSERecords.size();
    }
View Full Code Here

        //check if the cloned sheet has drawings
        int aggLoc = sheet.aggregateDrawingRecords(drawingManager, false);
        if(aggLoc != -1) {
            EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
            EscherContainerRecord escherContainer = agg.getEscherContainer();
            if (escherContainer == null) {
                return;
            }

            EscherDggRecord dgg = drawingManager.getDgg();

            //register a new drawing group for the cloned sheet
            int dgId = drawingManager.findNewDrawingGroupId();
            dgg.addCluster( dgId, 0 );
            dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);

            EscherDgRecord dg = null;
            for(Iterator<EscherRecord> it = escherContainer.getChildIterator(); it.hasNext();) {
                EscherRecord er = it.next();
                if(er instanceof EscherDgRecord) {
                    dg = (EscherDgRecord)er;
                    //update id of the drawing in the cloned sheet
                    dg.setOptions( (short) ( dgId << 4 ) );
                } else if (er instanceof EscherContainerRecord){
                    //recursively find shape records and re-generate shapeId
                    List<EscherRecord> spRecords = new ArrayList<EscherRecord>();
                    EscherContainerRecord cp = (EscherContainerRecord)er;
                    cp.getRecordsById(EscherSpRecord.RECORD_ID,  spRecords);
                    for(Iterator<EscherRecord> spIt = spRecords.iterator(); spIt.hasNext();) {
                        EscherSpRecord sp = (EscherSpRecord)spIt.next();
                        int shapeId = drawingManager.allocateShapeId((short)dgId, dg);
                        //allocateShapeId increments the number of shapes. roll back to the previous value
                        dg.setNumShapes(dg.getNumShapes()-1);
View Full Code Here

   * @return the index to this picture (1 based).
   */
  public int addPicture(byte[] data, int format) throws IOException {
    byte[] uid = PictureData.getChecksum(data);

    EscherContainerRecord bstore;

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

      dggContainer.addChildBefore(bstore, EscherOptRecord.RECORD_ID);
    } else {
      Iterator<EscherRecord> iter = bstore.getChildIterator();
      for (int i = 0; iter.hasNext(); i++) {
        EscherBSERecord bse = (EscherBSERecord) iter.next();
        if (Arrays.equals(bse.getUid(), uid)) {
View Full Code Here

     * @return          the index to this picture (1 based).
     */
    public int addPicture(byte[] data, int format) throws IOException {
        byte[] uid = PictureData.getChecksum(data);

        EscherContainerRecord bstore;
        int offset = 0;

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

            List child = dggContainer.getChildRecords();
            for ( int i = 0; i < child.size(); i++ ) {
                EscherRecord rec = (EscherRecord)child.get(i);
                if (rec.getRecordId() == EscherOptRecord.RECORD_ID){
                    child.add(i, bstore);
                    i++;
                }
            }
            dggContainer.setChildRecords(child);
        } else {
            List lst = bstore.getChildRecords();
            for ( int i = 0; i < lst.size(); i++ ) {
                EscherBSERecord bse = (EscherBSERecord) lst.get(i);
                if (Arrays.equals(bse.getUid(), uid)){
View Full Code Here

TOP

Related Classes of org.apache.poi.ddf.EscherContainerRecord$ReadOnlyIterator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.