Exemple #1
0
  /**
   * Create a slide and initialize it from the specified layout.
   *
   * @param layout
   * @return created slide
   */
  @SuppressWarnings("deprecation")
  public XSLFSlide createSlide(XSLFSlideLayout layout) {
    int slideNumber = 256, cnt = 1;
    CTSlideIdList slideList;
    if (!_presentation.isSetSldIdLst()) slideList = _presentation.addNewSldIdLst();
    else {
      slideList = _presentation.getSldIdLst();
      for (CTSlideIdListEntry slideId : slideList.getSldIdArray()) {
        slideNumber = (int) Math.max(slideId.getId() + 1, slideNumber);
        cnt++;
      }
    }

    XSLFSlide slide =
        (XSLFSlide) createRelationship(XSLFRelation.SLIDE, XSLFFactory.getInstance(), cnt);

    CTSlideIdListEntry slideId = slideList.addNewSldId();
    slideId.setId(slideNumber);
    slideId.setId2(slide.getPackageRelationship().getId());

    layout.copyLayout(slide);
    slide.addRelation(layout.getPackageRelationship().getId(), layout);

    PackagePartName ppName = layout.getPackagePart().getPartName();
    slide
        .getPackagePart()
        .addRelationship(
            ppName, TargetMode.INTERNAL, layout.getPackageRelationship().getRelationshipType());

    _slides.add(slide);
    return slide;
  }
  @Test
  public void testCreateShapes() throws Exception {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFSlide slide = ppt.createSlide();

    ppt.setPageSize(new Dimension(792, 612));

    XSLFGroupShape group = slide.createGroup();
    assertEquals(1, slide.getShapes().size());

    Rectangle interior = new Rectangle(-10, -10, 20, 20);
    group.setInteriorAnchor(interior);
    assertEquals(interior, group.getInteriorAnchor());

    Rectangle anchor = new Rectangle(0, 0, 792, 612);
    group.setAnchor(anchor);
    assertEquals(anchor, group.getAnchor());

    assertTrue(group.getShapes().isEmpty());

    XSLFTextBox shape1 = group.createTextBox();
    assertEquals(1, group.getShapes().size());
    assertSame(shape1, group.getShapes().get(0));
    assertEquals(3, shape1.getShapeId());

    XSLFAutoShape shape2 = group.createAutoShape();
    assertEquals(2, group.getShapes().size());
    assertSame(shape1, group.getShapes().get(0));
    assertSame(shape2, group.getShapes().get(1));
    assertEquals(4, shape2.getShapeId());

    XSLFConnectorShape shape3 = group.createConnector();
    assertEquals(3, group.getShapes().size());
    assertSame(shape3, group.getShapes().get(2));
    assertEquals(5, shape3.getShapeId());

    XSLFGroupShape shape4 = group.createGroup();
    assertEquals(4, group.getShapes().size());
    assertSame(shape4, group.getShapes().get(3));
    assertEquals(6, shape4.getShapeId());

    group.removeShape(shape2);
    assertEquals(3, group.getShapes().size());
    assertSame(shape1, group.getShapes().get(0));
    assertSame(shape3, group.getShapes().get(1));
    assertSame(shape4, group.getShapes().get(2));

    group.removeShape(shape3);
    assertEquals(2, group.getShapes().size());
    assertSame(shape1, group.getShapes().get(0));
    assertSame(shape4, group.getShapes().get(1));

    group.removeShape(shape1);
    group.removeShape(shape4);
    assertTrue(group.getShapes().isEmpty());

    ppt.close();
  }
Exemple #3
0
  /** Return notes slide for the specified slide or create new if it does not exist yet. */
  public XSLFNotes getNotesSlide(XSLFSlide slide) {

    XSLFNotes notesSlide = slide.getNotes();
    if (notesSlide == null) {
      notesSlide = createNotesSlide(slide);
    }

    return notesSlide;
  }
Exemple #4
0
  /** Create a blank notes slide. */
  private XSLFNotes createNotesSlide(XSLFSlide slide) {

    if (_notesMaster == null) {
      createNotesMaster();
    }

    Integer slideIndex = XSLFRelation.SLIDE.getFileNameIndex(slide);

    XSLFNotes notesSlide =
        (XSLFNotes) createRelationship(XSLFRelation.NOTES, XSLFFactory.getInstance(), slideIndex);

    notesSlide.addRelation(_notesMaster.getPackageRelationship().getId(), _notesMaster);
    PackagePartName notesMasterPackagePartName = _notesMaster.getPackagePart().getPartName();
    notesSlide
        .getPackagePart()
        .addRelationship(
            notesMasterPackagePartName,
            TargetMode.INTERNAL,
            _notesMaster.getPackageRelationship().getRelationshipType());

    slide.addRelation(notesSlide.getPackageRelationship().getId(), notesSlide);
    PackagePartName notesSlidesPackagePartName = notesSlide.getPackagePart().getPartName();
    slide
        .getPackagePart()
        .addRelationship(
            notesSlidesPackagePartName,
            TargetMode.INTERNAL,
            notesSlide.getPackageRelationship().getRelationshipType());

    notesSlide.addRelation(slide.getPackageRelationship().getId(), slide);
    PackagePartName slidesPackagePartName = slide.getPackagePart().getPartName();
    notesSlide
        .getPackagePart()
        .addRelationship(
            slidesPackagePartName,
            TargetMode.INTERNAL,
            slide.getPackageRelationship().getRelationshipType());

    notesSlide.importContent(_notesMaster);

    return notesSlide;
  }
  public void testSetPath() {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFSlide slide = ppt.createSlide();
    XSLFFreeformShape shape1 = slide.createFreeform();
    // comples path consisting of a rectangle and an ellipse inside it
    GeneralPath path1 = new GeneralPath(new Rectangle(150, 150, 300, 300));
    path1.append(new Ellipse2D.Double(200, 200, 100, 50), false);
    shape1.setPath(path1);

    GeneralPath path2 = shape1.getPath();

    // YK: how to compare the original path1 and the value returned by XSLFFreeformShape.getPath() ?
    // one way is to create another XSLFFreeformShape from path2 and compare the resulting xml
    assertEquals(path1.getBounds2D(), path2.getBounds2D());

    XSLFFreeformShape shape2 = slide.createFreeform();
    shape2.setPath(path2);

    assertEquals(
        shape1.getSpPr().getCustGeom().toString(), shape2.getSpPr().getCustGeom().toString());
  }
Exemple #6
0
  /**
   * Copy placeholders from this layout to the destination slide
   *
   * @param slide destination slide
   */
  public void copyLayout(XSLFSlide slide) {
    for (XSLFShape sh : getShapes()) {
      if (sh instanceof XSLFTextShape) {
        XSLFTextShape tsh = (XSLFTextShape) sh;
        Placeholder ph = tsh.getTextType();
        if (ph == null) continue;

        switch (ph) {
            // these are special and not copied by default
          case DATETIME:
          case SLIDE_NUMBER:
          case FOOTER:
            break;
          default:
            slide.getSpTree().addNewSp().set(tsh.getXmlObject().copy());
        }
      }
    }
  }
  @Test
  public void testRemoveShapes() throws Exception {
    XMLSlideShow ppt = new XMLSlideShow();
    XSLFSlide slide = ppt.createSlide();

    XSLFGroupShape group1 = slide.createGroup();
    group1.createTextBox();
    XSLFGroupShape group2 = slide.createGroup();
    group2.createTextBox();
    XSLFGroupShape group3 = slide.createGroup();
    slide.removeShape(group1);
    slide.removeShape(group2);
    slide.removeShape(group3);

    ppt.close();
  }