Exemplo n.º 1
0
 /**
  * Create a new shape object used to create the escher records.
  *
  * @param hssfShape The simple shape this is based on.
  */
 public static AbstractShape createShape(HSSFShape hssfShape, int shapeId) {
   AbstractShape shape;
   if (hssfShape instanceof HSSFComment) {
     shape = new CommentShape((HSSFComment) hssfShape, shapeId);
   } else if (hssfShape instanceof HSSFTextbox) {
     shape = new TextboxShape((HSSFTextbox) hssfShape, shapeId);
   } else if (hssfShape instanceof HSSFPolygon) {
     shape = new PolygonShape((HSSFPolygon) hssfShape, shapeId);
   } else if (hssfShape instanceof HSSFSimpleShape) {
     HSSFSimpleShape simpleShape = (HSSFSimpleShape) hssfShape;
     switch (simpleShape.getShapeType()) {
       case HSSFSimpleShape.OBJECT_TYPE_PICTURE:
         shape = new PictureShape(simpleShape, shapeId);
         break;
       case HSSFSimpleShape.OBJECT_TYPE_LINE:
         shape = new LineShape(simpleShape, shapeId);
         break;
       case HSSFSimpleShape.OBJECT_TYPE_OVAL:
       case HSSFSimpleShape.OBJECT_TYPE_RECTANGLE:
         shape = new SimpleFilledShape(simpleShape, shapeId);
         break;
       default:
         throw new IllegalArgumentException("Do not know how to handle this type of shape");
     }
   } else {
     throw new IllegalArgumentException("Unknown shape type");
   }
   EscherSpRecord sp = shape.getSpContainer().getChildById(EscherSpRecord.RECORD_ID);
   if (hssfShape.getParent() != null) sp.setFlags(sp.getFlags() | EscherSpRecord.FLAG_CHILD);
   return shape;
 }
Exemplo n.º 2
0
 /**
  * Add standard properties to the opt record. These properties effect all records.
  *
  * @param shape The user model shape.
  * @param opt The opt record to add the properties to.
  * @return The number of options added.
  */
 protected int addStandardOptions(HSSFShape shape, EscherOptRecord opt) {
   opt.addEscherProperty(
       new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x080000));
   //        opt.addEscherProperty( new EscherBoolProperty(
   // EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 0x080008 ) );
   if (shape.isNoFill()) {
     // Wonderful... none of the spec's give any clue as to what these constants mean.
     opt.addEscherProperty(
         new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 0x00110000));
   } else {
     opt.addEscherProperty(
         new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, 0x00010000));
   }
   opt.addEscherProperty(
       new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, shape.getFillColor()));
   opt.addEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000));
   opt.addEscherProperty(
       new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, shape.getLineStyleColor()));
   int options = 5;
   if (shape.getLineWidth() != HSSFShape.LINEWIDTH_DEFAULT) {
     opt.addEscherProperty(
         new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, shape.getLineWidth()));
     options++;
   }
   if (shape.getLineStyle() != HSSFShape.LINESTYLE_SOLID) {
     opt.addEscherProperty(
         new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEDASHING, shape.getLineStyle()));
     opt.addEscherProperty(
         new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEENDCAPSTYLE, 0));
     if (shape.getLineStyle() == HSSFShape.LINESTYLE_NONE)
       opt.addEscherProperty(
           new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080000));
     else
       opt.addEscherProperty(
           new EscherBoolProperty(EscherProperties.LINESTYLE__NOLINEDRAWDASH, 0x00080008));
     options += 3;
   }
   opt.sortProperties();
   return options; // # options added
 }
Exemplo n.º 3
0
  private void checkWorkbookBack(HSSFWorkbook wb) {
    HSSFWorkbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
    assertNotNull(wbBack);

    HSSFSheet sheetBack = wbBack.getSheetAt(0);
    assertNotNull(sheetBack);

    HSSFPatriarch patriarchBack = sheetBack.getDrawingPatriarch();
    assertNotNull(patriarchBack);

    List<HSSFShape> children = patriarchBack.getChildren();
    assertEquals(4, children.size());
    HSSFShape hssfShape = children.get(0);
    assertTrue(hssfShape instanceof HSSFSimpleShape);
    HSSFAnchor anchor = hssfShape.getAnchor();
    assertTrue(anchor instanceof HSSFClientAnchor);
    assertEquals(0, anchor.getDx1());
    assertEquals(512, anchor.getDx2());
    assertEquals(0, anchor.getDy1());
    assertEquals(100, anchor.getDy2());
    HSSFClientAnchor cAnchor = (HSSFClientAnchor) anchor;
    assertEquals(1, cAnchor.getCol1());
    assertEquals(1, cAnchor.getCol2());
    assertEquals(1, cAnchor.getRow1());
    assertEquals(1, cAnchor.getRow2());

    hssfShape = children.get(1);
    assertTrue(hssfShape instanceof HSSFSimpleShape);
    anchor = hssfShape.getAnchor();
    assertTrue(anchor instanceof HSSFClientAnchor);
    assertEquals(512, anchor.getDx1());
    assertEquals(1024, anchor.getDx2());
    assertEquals(0, anchor.getDy1());
    assertEquals(100, anchor.getDy2());
    cAnchor = (HSSFClientAnchor) anchor;
    assertEquals(1, cAnchor.getCol1());
    assertEquals(1, cAnchor.getCol2());
    assertEquals(1, cAnchor.getRow1());
    assertEquals(1, cAnchor.getRow2());

    hssfShape = children.get(2);
    assertTrue(hssfShape instanceof HSSFSimpleShape);
    anchor = hssfShape.getAnchor();
    assertTrue(anchor instanceof HSSFClientAnchor);
    assertEquals(0, anchor.getDx1());
    assertEquals(512, anchor.getDx2());
    assertEquals(0, anchor.getDy1());
    assertEquals(100, anchor.getDy2());
    cAnchor = (HSSFClientAnchor) anchor;
    assertEquals(2, cAnchor.getCol1());
    assertEquals(2, cAnchor.getCol2());
    assertEquals(2, cAnchor.getRow1());
    assertEquals(2, cAnchor.getRow2());

    hssfShape = children.get(3);
    assertTrue(hssfShape instanceof HSSFSimpleShape);
    anchor = hssfShape.getAnchor();
    assertTrue(anchor instanceof HSSFClientAnchor);
    assertEquals(0, anchor.getDx1());
    assertEquals(512, anchor.getDx2());
    assertEquals(100, anchor.getDy1());
    assertEquals(200, anchor.getDy2());
    cAnchor = (HSSFClientAnchor) anchor;
    assertEquals(2, cAnchor.getCol1());
    assertEquals(2, cAnchor.getCol2());
    assertEquals(2, cAnchor.getRow1());
    assertEquals(2, cAnchor.getRow2());
  }