Package org.apache.poi.hslf.model

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


  /**
   * Test the stuff about getting/setting bold
   *  on a rich text run
   */
  public void testBoldRich() {
    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() {

    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

  }

  public void testSetParagraphStyles() throws Exception {
    SlideShow ppt = new SlideShow();

    Slide slide = ppt.createSlide();

    TextBox shape = new TextBox();
    RichTextRun rt = shape.getTextRun().getRichTextRuns()[0];
    shape.setText(
        "Hello, World!\r" +
        "This should be\r" +
        "Multiline text");
    rt.setFontSize(42);
    rt.setBullet(true);
    rt.setTextOffset(50);
    rt.setBulletOffset(0);
    rt.setBulletChar('\u263A');
    slide.addShape(shape);

    assertEquals(42, rt.getFontSize());
    assertEquals(true, rt.isBullet());
    assertEquals(50, rt.getTextOffset());
    assertEquals(0, rt.getBulletOffset());
    assertEquals('\u263A', rt.getBulletChar());

    shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300));
    slide.addShape(shape);

    //serialize and read again
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ppt.write(out);
    out.close();

    ppt = new SlideShow(new ByteArrayInputStream(out.toByteArray()));
    slide = ppt.getSlides()[0];
    shape = (TextBox)slide.getShapes()[0];
    rt = shape.getTextRun().getRichTextRuns()[0];
    assertEquals(42, rt.getFontSize());
    assertEquals(true, rt.isBullet());
    assertEquals(50, rt.getTextOffset());
    assertEquals(0, rt.getBulletOffset());
View Full Code Here

      String coordenador = "";
     
      // Caso n�o existam itens a serem exibidos,
      // O slide � exibido apenas com a informa��o de que nenhum item foi encontrado.
      if (root.getElementsByTagName("semItens").getLength() > 0) {
        Slide s = ppt.createSlide();
        adicionaTitulo(request, root, s, ppt, caminhoImagens);
        TextBox semItens = adicionaTextBox(s, "Nenhum item foi encontrado para os par�metros deste relat�rio.",
            null, 5, 102, 600, 20, 0);
        formataFonte(semItens, 14, "Arial", true, false, false, Color.blue, TextBox.AlignLeft);
        adicionaRodape(root, s);
        ppt.write(out);
          exibePPT(request, response, out, caminhoCompleto);       
      }
    
      NodeList itens = root.getElementsByTagName("item");
           
      ArrayList slides = new ArrayList();
     
      Slide s1;
      int quantidadeSlides = 0;
      int posicaoYQuebraSlide = 548;
      int incrementoParaOutroParecer = 0;
      int desceEtapas = 0;
         
      for (int i = 0; i < itens.getLength(); i++) {
          Node item = itens.item(i);
          NodeList filhosItemCorrente = item.getChildNodes();
          Node nd = null;
          NamedNodeMap map = item.getAttributes();
          nd = map.getNamedItem("nomeItem");
         
         
          if (!nd.getNodeValue().equals("")) {
            nomeItem = nd.getNodeValue();
          }
                 
          // Obtendo a tag ocorrencias do item corrente
          // Obtendo os pareceres do item corrente
          Node noOcorrenciaCorrente = null;
          Node noParecerCorrente = null;
          ArrayList pareceres = new ArrayList();
          String nomeNo;
         
          for (int o = 0; o < filhosItemCorrente.getLength(); o++) {
            nomeNo = filhosItemCorrente.item(o).getNodeName();
            if (nomeNo.equals("ocorrencias")) {
              noOcorrenciaCorrente = filhosItemCorrente.item(o);             
            } else if (nomeNo.equals("parecer")) {
              noParecerCorrente = filhosItemCorrente.item(o);
              pareceres.add(noParecerCorrente);
              desceEtapas++;
            }
          }
         
          // Se a tag item corrente tem o atributo nomeItem != "", cria-se um novo slide
          if (!nd.getNodeValue().equals("")) {           
             // Criando o slide
            s1 = null;
            incrementoParaOutroParecer = 0;
            slides.add(quantidadeSlides, ppt.createSlide());
            s1 = (Slide)slides.get(quantidadeSlides);
            quantidadeSlides++; 
          // Caso contr�rio, continuamos a escrever no mesmo slide
          } else
            s1 = (ppt.getSlides()[ppt.getSlides().length - 1]);           
          }
         
          // ************** Montagem do T�tulo ****************** //        
         
          adicionaTitulo(request, root, s1, ppt, caminhoImagens);
             
          // ************** Montagem do �rgao ****************** //
        
          // Obtendo o �rg�o no XML
          nd = map.getNamedItem("orgaoItem");
     
          String orgao = nd.getNodeValue();//pegarAtributo(doc, "item", "orgao");      
       
          // Obtendo o Respons�vel T�cnico no XML                  
          nd = map.getNamedItem("labelRespTecnicoIett");
          if (!nd.getNodeValue().trim().equals("")) {
            coordenador = nd.getNodeValue();
            nd = map.getNamedItem("valorRespTecnicoIett");
            coordenador += "" + nd.getNodeValue();
          }
        
          //Texto do label DR1 - N�mero de Ocorrencias (label)         
          nd = map.getNamedItem("labelDR1");
          String labelDR1 = nd.getNodeValue() + ":";
        
          //Texto do valor DR1 - N�mero de Ocorrencias (valor)
          nd = map.getNamedItem("valorDR1");
          String valorDR1 = nd.getNodeValue();
         
          adicionaOrgao (s1, orgao, nomeItem, coordenador);
         
          if (valorDR1 != "") {         
            //montagem do label DR1
            TextBox ctLabelDR1 = adicionaTextBox(s1, labelDR1, null, 0, 156, 198, 16, 1);
            ctLabelDR1.setVerticalAlignment(1);
            formataFonte(ctLabelDR1, 12, "Arial", true, false, false, Color.black, TextBox.AlignLeft);
           
            //montagem do valor DR1
            TextBox ctValorDR1 = adicionaTextBox(s1, valorDR1, null, 160, 155, 198, 16, 1);
            ctValorDR1.setVerticalAlignment(1);
            formataFonte(ctValorDR1, 12, "Arial", false, false, false, Color.black, TextBox.AlignLeft);
          }
         
          // ************** Pareceres (Situa��o) **************** //
         
          Iterator pareceresItem = pareceres.iterator();
         
          while(pareceresItem.hasNext()) {
         
            noParecerCorrente = (Node)pareceresItem.next();
           
            // adicionando novo slide caso o parecer corrente n�o caiba no slide atual:
              if ((174 + incrementoParaOutroParecer) >= posicaoYQuebraSlide) {
               
                adicionaRodape(root, s1);
               
                incrementoParaOutroParecer = 0;
               
                // criando o novo slide
                s1 = ppt.createSlide();
                slides.add(quantidadeSlides, s1);
                quantidadeSlides++;
               
                // a partir daqui estamos escrevendo num novo slide               
                adicionaTitulo(request, root, s1, ppt, caminhoImagens);
                adicionaOrgao (s1, orgao, nomeItem, coordenador);
              }
                         
            //montagem do label situa��o
            TextBox ctSituacao = adicionaTextBox(s1, "Situa��o:", null, 0, 174 + incrementoParaOutroParecer, 99, 17, 1);
            ctSituacao.setVerticalAlignment (1);
            formataFonte(ctSituacao, 12, "Arial", true, false, false, Color.black, TextBox.AlignLeft);
 
            //Texto da situa��o
            String situacao = noParecerCorrente.getAttributes().getNamedItem("situacaoParecer").getNodeValue().toString();
            //Deve-se remover as quebras de linha das strings exibidas para que n�o percam a formata��o de fonte.
            situacao = situacao.replace("\n", " ");
           
            //montagem do valor Situa��o
            TextBox ctValorSituacao = adicionaTextBox(s1, situacao, null, 58, 174 + incrementoParaOutroParecer, 99, 17, 1);
            ctValorSituacao.setVerticalAlignment(1);
            formataFonte(ctValorSituacao, 12, "Arial", false, false, false, Color.black, TextBox.AlignLeft);
          
            String pathImagemParecer = "";
            //imagem da situa��o
            try {
              pathImagemParecer = noParecerCorrente.getAttributes().getNamedItem("caminhoImagem").getNodeValue().toString();
              int beginIndex = pathImagemParecer.lastIndexOf("/");
              pathImagemParecer = caminhoImagens + pathImagemParecer.substring(beginIndex, pathImagemParecer.length());
              int idImagemParecer = ppt.addPicture(new File(pathImagemParecer), Picture.PNG);
              Picture imagemParecer = new Picture(idImagemParecer);
              imagemParecer.setAnchor(new java.awt.Rectangle(12, 190 + incrementoParaOutroParecer, 21,21));         
              s1.addShape(imagemParecer);
            } catch (Exception e) {
              System.out.println("Imagem n�o econtrada:" + pathImagemParecer);
            }
          
            //Texto do Label Parecer
View Full Code Here

            if (notesPos != null) notes = _notes[notesPos.intValue()];
            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

      // 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);
      // 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();
      slideRecord.setSheetId(sp.getRefID());
      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();
        record.writeOut(out);
       
        // 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();
      }
     
    // 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);

    // Last view is now of the slide
      usr.setLastViewType((short)UserEditAtom.LAST_VIEW_SLIDE_VIEW);
     
      // All done and added
      slide.setSlideShow(this);
      return slide;
  }
View Full Code Here

            if (notesPos != null) notes = _notes[notesPos.intValue()];
            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

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.