Package org.apache.poi.hslf.model

Examples of org.apache.poi.hslf.model.Slide


  /**
   * Test the stuff about getting/setting bold
   *  on a non rich text run
   */
  public void testBoldNonRich() throws Exception {
    Slide slideOne = ss.getSlides()[0];
    TextRun[] textRuns = slideOne.getTextRuns();
    RichTextRun rtr = textRuns[0].getRichTextRuns()[0];
   
    assertNull(rtr._getRawCharacterStyle());
    assertNull(rtr._getRawParagraphStyle());
    assertFalse(rtr.isBold());
View Full Code Here


  /**
   * Test the stuff about getting/setting bold
   *  on a rich text run
   */
  public void testBoldRich() throws Exception {
    Slide slideOneR = ssRichA.getSlides()[0];
    TextRun[] textRunsR = slideOneR.getTextRuns();
    RichTextRun[] rtrs = textRunsR[1].getRichTextRuns();
    assertEquals(3, rtrs.length);
   
    assertTrue(rtrs[0].isBold());
    assertFalse(rtrs[1].isBold());
View Full Code Here

   * Tests getting and setting the font size on rich and non
   *  rich text runs
   */
  public void testFontSize() throws Exception {
    SlideMaster master;
        Slide slideOne = ss.getSlides()[0];
    TextRun[] textRuns = slideOne.getTextRuns();
    RichTextRun rtr = textRuns[0].getRichTextRuns()[0];
   
    Slide slideOneR = ssRichB.getSlides()[0];
    TextRun[] textRunsR = slideOneR.getTextRuns();
    RichTextRun rtrRa = textRunsR[0].getRichTextRuns()[0];
    RichTextRun rtrRb = textRunsR[1].getRichTextRuns()[0];
    RichTextRun rtrRc = textRunsR[1].getRichTextRuns()[3];

        String defaultFont = "Arial";
View Full Code Here

    HSLFSlideShow[] h = new HSLFSlideShow[] { hss, hssRichA, hssRichB };
    Slide[] s = new Slide[] { ss.getSlides()[0], ssRichA.getSlides()[0], ssRichB.getSlides()[0] };
   
    for(int i=0; i<h.length; i++) {
      // Change
      Slide slideOne = s[i];
      TextRun[] textRuns = slideOne.getTextRuns();
      RichTextRun rtr = textRuns[0].getRichTextRuns()[0];
     
      rtr.setBold(true);
      rtr.setFontSize(18);
      rtr.setFontName("Courier");
     
      // Check it took those
      assertEquals(true, rtr.isBold());
      assertEquals(18, rtr.getFontSize());
      assertEquals("Courier", rtr.getFontName());
     
      // Write out and back in
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      h[i].write(baos);
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
     
      HSLFSlideShow readHSLF = new HSLFSlideShow(bais);
      SlideShow readS = new SlideShow(readHSLF);
     
      // Tweak existing one again, to ensure really worked
      rtr.setBold(false);
      rtr.setFontSize(17);
      rtr.setFontName("CourierZZ");
     
      // Check it took those changes
      assertEquals(false, rtr.isBold());
      assertEquals(17, rtr.getFontSize());
      assertEquals("CourierZZ", rtr.getFontName());

     
      // Now, look at the one we changed, wrote out, and read back in
      // Ensure it does contain our original modifications
      Slide slideOneRR = readS.getSlides()[0];
      TextRun[] textRunsRR = slideOneRR.getTextRuns();
      RichTextRun rtrRRa = textRunsRR[0].getRichTextRuns()[0];
     
      assertEquals(true, rtrRRa.isBold());
      assertEquals(18, rtrRRa.getFontSize());
      assertEquals("Courier", rtrRRa.getFontName());
View Full Code Here

    // Check we have the right number of sheets
    Slide[] slides = ssRichC.getSlides();
    assertEquals(14, slides.length);
   
    // Check the number of text runs on interesting sheets
    Slide slideThreeC = ssRichC.getSlides()[2];
    Slide slideSevenC = ssRichC.getSlides()[6];
    assertEquals(3, slideThreeC.getTextRuns().length);
    assertEquals(5, slideSevenC.getTextRuns().length);
   
    // On slide three, we should have:
    // TR:
    //   You are an important supplier of various items that I need
    //   .
    // TR:
    //   Source: Internal focus groups
    // TR:
    //   Illustrative Example
    //   .
   
    TextRun[] s3tr = slideThreeC.getTextRuns();
    RichTextRun[] s3rtr0 = s3tr[0].getRichTextRuns();
    RichTextRun[] s3rtr1 = s3tr[1].getRichTextRuns();
    RichTextRun[] s3rtr2 = s3tr[2].getRichTextRuns();
   
    assertEquals(2, s3rtr0.length);
    assertEquals(1, s3rtr1.length);
    assertEquals(2, s3rtr2.length);
   
    assertEquals("You are an important supplier of various items that I need", s3rtr0[0].getText());
    assertEquals("", s3rtr0[1].getText());
    assertEquals("Source: Internal focus groups", s3rtr1[0].getText());
    assertEquals("Illustrative Example", s3rtr2[0].getText());
    assertEquals("", s3rtr2[1].getText());
   
    assertTrue(s3rtr0[0]._isParagraphStyleShared());
    assertTrue(s3rtr0[1]._isParagraphStyleShared());
    assertFalse(s3rtr1[0]._isParagraphStyleShared());
    assertTrue(s3rtr2[0]._isParagraphStyleShared());
    assertTrue(s3rtr2[1]._isParagraphStyleShared());
   
    assertFalse(s3rtr0[0]._isCharacterStyleShared());
    assertFalse(s3rtr0[1]._isCharacterStyleShared());
    assertFalse(s3rtr1[0]._isCharacterStyleShared());
    assertFalse(s3rtr2[0]._isCharacterStyleShared());
    assertFalse(s3rtr2[1]._isCharacterStyleShared());
   
    // On slide seven, we have:
    // TR:
    //  (text)
    // TR:
    //  <ps>(text a)</ps><ps>(text a)(text b)</ps>
    // TR:   
    //  (text)
    TextRun[] s7tr = slideSevenC.getTextRuns();
    RichTextRun[] s7rtr0 = s7tr[0].getRichTextRuns();
    RichTextRun[] s7rtr1 = s7tr[1].getRichTextRuns();
    RichTextRun[] s7rtr2 = s7tr[2].getRichTextRuns();
   
    assertEquals(1, s7rtr0.length);
View Full Code Here

   */
  public void testParagraphStylesShorterTheCharStylesWrite() throws Exception {
    assertMatchesSLTWC(ssRichC);
    assertMatchesFileC(ssRichC);
   
    Slide slideSevenC = ssRichC.getSlides()[6];
    TextRun[] s7tr = slideSevenC.getTextRuns();
    RichTextRun[] s7rtr0 = s7tr[0].getRichTextRuns();
    RichTextRun[] s7rtr1 = s7tr[1].getRichTextRuns();
    RichTextRun[] s7rtr2 = s7tr[2].getRichTextRuns();
   
    String oldText;
View Full Code Here

        else
          logger.log(POILogger.ERROR, "Notes not found for noteId=" + noteId);
      }

      // Now, build our slide
      _slides[i] = new Slide(slidesRecords[i], notes, sas, slideIdentifier, (i + 1));
      _slides[i].setSlideShow(this);
    }
  }
View Full Code Here

    }

    SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
    SlideAtomsSet[] sas = slwt.getSlideAtomsSets();

    Slide removedSlide = null;
    ArrayList<Record> records = new ArrayList<Record>();
    ArrayList<SlideAtomsSet> sa = new ArrayList<SlideAtomsSet>();
    ArrayList<Slide> sl = new ArrayList<Slide>();

    ArrayList<Notes> nt = new ArrayList<Notes>();
    for (Notes notes : getNotes())
      nt.add(notes);

    for (int i = 0, num = 0; i < _slides.length; i++) {
      if (i != index) {
        sl.add(_slides[i]);
        sa.add(sas[i]);
        _slides[i].setSlideNumber(num++);
        records.add(sas[i].getSlidePersistAtom());
        records.addAll(Arrays.asList(sas[i].getSlideRecords()));
      } else {
        removedSlide = _slides[i];
        nt.remove(_slides[i].getNotesSheet());
      }
    }
    if (sa.size() == 0) {
      _documentRecord.removeSlideListWithText(slwt);
    } else {
      slwt.setSlideAtomsSets(sa.toArray(new SlideAtomsSet[sa.size()]));
      slwt.setChildRecord(records.toArray(new Record[records.size()]));
    }
    _slides = sl.toArray(new Slide[sl.size()]);

    // if the removed slide had notes - remove references to them too

    if (removedSlide != null) {
      int notesId = removedSlide.getSlideRecord().getSlideAtom().getNotesID();
      if (notesId != 0) {
        SlideListWithText nslwt = _documentRecord.getNotesSlideListWithText();
        records = new ArrayList<Record>();
        ArrayList<SlideAtomsSet> na = new ArrayList<SlideAtomsSet>();
        for (SlideAtomsSet ns : nslwt.getSlideAtomsSets()) {
View Full Code Here

    // Add this new SlidePersistAtom to the SlideListWithText
    slist.addSlidePersistAtom(sp);

    // Create a new Slide
    Slide slide = new Slide(sp.getSlideIdentifier(), sp.getRefID(), _slides.length + 1);
    slide.setSlideShow(this);
    slide.onCreate();

    // Add in to the list of Slides
    Slide[] s = new Slide[_slides.length + 1];
    System.arraycopy(_slides, 0, s, 0, _slides.length);
    s[_slides.length] = slide;
    _slides = s;
    logger.log(POILogger.INFO, "Added slide " + _slides.length + " with ref " + sp.getRefID()
        + " and identifier " + sp.getSlideIdentifier());

    // Add the core records for this new Slide to the record tree
    org.apache.poi.hslf.record.Slide slideRecord = slide.getSlideRecord();
    int slideRecordPos = _hslfSlideShow.appendRootLevelRecord(slideRecord);
    _records = _hslfSlideShow.getRecords();

    // Add the new Slide into the PersistPtr stuff
    int offset = 0;
    int slideOffset = 0;
    PersistPtrHolder ptr = null;
    UserEditAtom usr = null;
    for (int i = 0; i < _records.length; i++) {
      Record record = _records[i];
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      try {
        record.writeOut(out);
      } catch (IOException e) {
        throw new HSLFException(e);
      }

      // Grab interesting records as they come past
      if (_records[i].getRecordType() == RecordTypes.PersistPtrIncrementalBlock.typeID) {
        ptr = (PersistPtrHolder) _records[i];
      }
      if (_records[i].getRecordType() == RecordTypes.UserEditAtom.typeID) {
        usr = (UserEditAtom) _records[i];
      }

      if (i == slideRecordPos) {
        slideOffset = offset;
      }
      offset += out.size();
    }

    // persist ID is UserEditAtom.maxPersistWritten + 1
    int psrId = usr.getMaxPersistWritten() + 1;
    sp.setRefID(psrId);
    slideRecord.setSheetId(psrId);

    // Last view is now of the slide
    usr.setLastViewType((short) UserEditAtom.LAST_VIEW_SLIDE_VIEW);
    usr.setMaxPersistWritten(psrId); // increment the number of persit
                     // objects

    // Add the new slide into the last PersistPtr
    // (Also need to tell it where it is)
    slideRecord.setLastOnDiskOffset(slideOffset);
    ptr.addSlideLookup(sp.getRefID(), slideOffset);
    logger.log(POILogger.INFO, "New slide ended up at " + slideOffset);

    slide.setMasterSheet(_masters[0]);
    // All done and added
    return slide;
  }
View Full Code Here

  /**
   * Test the stuff about getting/setting bold
   *  on a non rich text run
   */
  public void testBoldNonRich() {
    Slide slideOne = ss.getSlides()[0];
    TextRun[] textRuns = slideOne.getTextRuns();
    RichTextRun rtr = textRuns[0].getRichTextRuns()[0];

    assertNull(rtr._getRawCharacterStyle());
    assertNull(rtr._getRawParagraphStyle());
    assertFalse(rtr.isBold());
View Full Code Here

TOP

Related Classes of org.apache.poi.hslf.model.Slide

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.