Package org.apache.poi.hwpf.model

Examples of org.apache.poi.hwpf.model.PicturesTable


  /**
   * Test that compressed image data is correctly returned.
   */
  public void testCompressedImageData() {
    HWPFDocument docC = HWPFTestDataSamples.openSampleFile(docCFile);
    PicturesTable picC = docC.getPicturesTable();
    List<Picture> picturesC = picC.getAllPictures();

    assertEquals(1, picturesC.size());

    Picture pic = picturesC.get(0);
    assertNotNull(pic);
View Full Code Here


    assertBytesSame(picBytes, pic.getContent());
  }

     public void testMacImages() throws Exception {
        HWPFDocument docC = HWPFTestDataSamples.openSampleFile("53446.doc");
       PicturesTable picturesTable = docC.getPicturesTable();
       List<Picture> pictures = picturesTable.getAllPictures();

       assertEquals(4, pictures.size());

        int[][] expectedSizes = {
            { 185, 42 }// PNG
View Full Code Here

       //   file and an embeded word file, in that order
       HWPFDocument doc = HWPFTestDataSamples.openSampleFile("word_with_embeded.doc");
      
       // Check we don't break loading the pictures
       doc.getPicturesTable().getAllPictures();
       PicturesTable pictureTable = doc.getPicturesTable();
      
       // Check the text, and its embeded images
       Paragraph p;
       Range r = doc.getRange();
       assertEquals(1, r.numSections());
       assertEquals(5, r.numParagraphs());
      
       p = r.getParagraph(0);
       assertEquals(2, p.numCharacterRuns());
       assertEquals("I have lots of embedded files in me\r", p.text());
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(0)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(1)));
      
       p = r.getParagraph(1);
       assertEquals(5, p.numCharacterRuns());
       assertEquals("\u0013 EMBED Excel.Sheet.8  \u0014\u0001\u0015\r", p.text());
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(0)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(1)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(2)));
       assertEquals(true,  pictureTable.hasPicture(p.getCharacterRun(3)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(4)));
      
       p = r.getParagraph(2);
       assertEquals(6, p.numCharacterRuns());
       assertEquals("\u0013 EMBED Excel.Sheet.8  \u0014\u0001\u0015\r", p.text());
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(0)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(1)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(2)));
       assertEquals(true,  pictureTable.hasPicture(p.getCharacterRun(3)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(4)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(5)));
      
       p = r.getParagraph(3);
       assertEquals(6, p.numCharacterRuns());
       assertEquals("\u0013 EMBED PowerPoint.Show.8  \u0014\u0001\u0015\r", p.text());
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(0)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(1)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(2)));
       assertEquals(true,  pictureTable.hasPicture(p.getCharacterRun(3)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(4)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(5)));
      
       p = r.getParagraph(4);
       assertEquals(6, p.numCharacterRuns());
       assertEquals("\u0013 EMBED Word.Document.8 \\s \u0014\u0001\u0015\r", p.text());
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(0)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(1)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(2)));
       assertEquals(true,  pictureTable.hasPicture(p.getCharacterRun(3)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(4)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(5)));

       // Look at the pictures table
       List<Picture> pictures = pictureTable.getAllPictures();
       assertEquals(4, pictures.size());

        Picture picture = pictures.get( 0 );
        assertEquals( "emf", picture.suggestFileExtension() );
        assertEquals( "0.emf", picture.suggestFullFileName() );
View Full Code Here

    }

    public void testEquation()
    {
        HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "equation.doc" );
        PicturesTable pictures = doc.getPicturesTable();

        final List<Picture> allPictures = pictures.getAllPictures();
        assertEquals( 1, allPictures.size() );

        Picture picture = allPictures.get( 0 );
        assertNotNull( picture );
        assertEquals( PictureType.EMF, picture.suggestPictureType() );
View Full Code Here

     *  \u0001 which has the offset. More than one can
     *  reference the same \u0001
     */
    public void testFloatingPictures() throws Exception {
       HWPFDocument doc = HWPFTestDataSamples.openSampleFile("FloatingPictures.doc");
       PicturesTable pictures = doc.getPicturesTable();
      
       // There are 19 images in the picture, but some are
       //  duplicate floating ones
       assertEquals(17, pictures.getAllPictures().size());
      
       int plain8s = 0;
       int escher8s = 0;
       int image1s = 0;
      
       Range r = doc.getRange();
       for(int np=0; np < r.numParagraphs(); np++) {
          Paragraph p = r.getParagraph(np);
          for(int nc=0; nc < p.numCharacterRuns(); nc++) {
             CharacterRun cr = p.getCharacterRun(nc);
             if(pictures.hasPicture(cr)) {
                image1s++;
             } else if(pictures.hasEscherPicture(cr)) {
                escher8s++;
             } else if(cr.text().startsWith("\u0008")) {
                plain8s++;
             }
          }
View Full Code Here

        assertEquals(0, pic2.getDyaCropBottom());
    }

    public void testPictureDetectionWithPNG() throws Exception {
        HWPFDocument document = HWPFTestDataSamples.openSampleFile("PngPicture.doc");
        PicturesTable pictureTable = document.getPicturesTable();
       
        assertEquals(1, pictureTable.getAllPictures().size());
       
        Picture p = pictureTable.getAllPictures().get(0);
        assertEquals(PictureType.PNG, p.suggestPictureType());
        assertEquals("png", p.suggestFileExtension());
    }
View Full Code Here

        assertEquals("png", p.suggestFileExtension());
    }
   
    public void testPictureWithAlternativeText() throws Exception {
        HWPFDocument document = HWPFTestDataSamples.openSampleFile("Picture_Alternative_Text.doc");
        PicturesTable pictureTable = document.getPicturesTable();
        Picture picture = pictureTable.getAllPictures().get(0);

        assertEquals("This is the alternative text for the picture.", picture.getDescription());
    }
View Full Code Here

       //   file and an embeded word file, in that order
       HWPFDocument doc = HWPFTestDataSamples.openSampleFile("word_with_embeded.doc");
      
       // Check we don't break loading the pictures
       doc.getPicturesTable().getAllPictures();
       PicturesTable pictureTable = doc.getPicturesTable();
      
       // Check the text, and its embeded images
       Paragraph p;
       Range r = doc.getRange();
       assertEquals(1, r.numSections());
       assertEquals(5, r.numParagraphs());
      
       p = r.getParagraph(0);
       assertEquals(2, p.numCharacterRuns());
       assertEquals("I have lots of embedded files in me\r", p.text());
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(0)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(1)));
      
       p = r.getParagraph(1);
       assertEquals(5, p.numCharacterRuns());
       assertEquals("\u0013 EMBED Excel.Sheet.8  \u0014\u0001\u0015\r", p.text());
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(0)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(1)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(2)));
       assertEquals(true,  pictureTable.hasPicture(p.getCharacterRun(3)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(4)));
      
       p = r.getParagraph(2);
       assertEquals(6, p.numCharacterRuns());
       assertEquals("\u0013 EMBED Excel.Sheet.8  \u0014\u0001\u0015\r", p.text());
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(0)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(1)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(2)));
       assertEquals(true,  pictureTable.hasPicture(p.getCharacterRun(3)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(4)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(5)));
      
       p = r.getParagraph(3);
       assertEquals(6, p.numCharacterRuns());
       assertEquals("\u0013 EMBED PowerPoint.Show.8  \u0014\u0001\u0015\r", p.text());
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(0)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(1)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(2)));
       assertEquals(true,  pictureTable.hasPicture(p.getCharacterRun(3)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(4)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(5)));
      
       p = r.getParagraph(4);
       assertEquals(6, p.numCharacterRuns());
       assertEquals("\u0013 EMBED Word.Document.8 \\s \u0014\u0001\u0015\r", p.text());
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(0)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(1)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(2)));
       assertEquals(true,  pictureTable.hasPicture(p.getCharacterRun(3)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(4)));
       assertEquals(false, pictureTable.hasPicture(p.getCharacterRun(5)));

       // Look at the pictures table
       List<Picture> pictures = pictureTable.getAllPictures();
       assertEquals(4, pictures.size());
      
       Picture picture = pictures.get(0);
       assertEquals("", picture.suggestFileExtension());
       assertEquals("0", picture.suggestFullFileName());
View Full Code Here

     *  \u0001 which has the offset. More than one can
     *  reference the same \u0001
     */
    public void testFloatingPictures() throws Exception {
       HWPFDocument doc = HWPFTestDataSamples.openSampleFile("FloatingPictures.doc");
       PicturesTable pictures = doc.getPicturesTable();
      
       // There are 19 images in the picture, but some are
       //  duplicate floating ones
       assertEquals(17, pictures.getAllPictures().size());
      
       int plain8s = 0;
       int escher8s = 0;
       int image1s = 0;
      
       Range r = doc.getRange();
       for(int np=0; np < r.numParagraphs(); np++) {
          Paragraph p = r.getParagraph(np);
          for(int nc=0; nc < p.numCharacterRuns(); nc++) {
             CharacterRun cr = p.getCharacterRun(nc);
             if(pictures.hasPicture(cr)) {
                image1s++;
             } else if(pictures.hasEscherPicture(cr)) {
                escher8s++;
             } else if(cr.text().startsWith("\u0008")) {
                plain8s++;
             }
          }
View Full Code Here

    HWPFDocument docB = HWPFTestDataSamples.openSampleFile(docBFile);

    assertNotNull(docA.getPicturesTable());
    assertNotNull(docB.getPicturesTable());

    PicturesTable picA = docA.getPicturesTable();
    PicturesTable picB = docB.getPicturesTable();

    List<Picture> picturesA = picA.getAllPictures();
    List<Picture> picturesB = picB.getAllPictures();

    assertEquals(7, picturesA.size());
    assertEquals(2, picturesB.size());
  }
View Full Code Here

TOP

Related Classes of org.apache.poi.hwpf.model.PicturesTable

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.