FileDocCategorySizeDatePackage
PicturesTable.javaAPI DocApache Poi 3.0.16046Sun Mar 11 12:59:30 GMT 2007org.apache.poi.hwpf.model

PicturesTable

public class PicturesTable extends Object
Holds information about all pictures embedded in Word Document either via "Insert -> Picture -> From File" or via clipboard. Responsible for images extraction and determining whether some document�s piece contains embedded image. Analyzes raw data bytestream �Data� (where Word stores all embedded objects) provided by HWPFDocument. Word stores images as is within so called "Data stream" - the stream within a Word docfile containing various data that hang off of characters in the main stream. For example, binary data describing in-line pictures and/or formfields an also embedded objects-native data. Word picture structures are concatenated one after the other in the data stream if the document contains pictures. Data stream is easily reachable via HWPFDocument._dataStream property. A picture is represented in the document text stream as a special character, an Unicode \u0001 whose CharacterRun.isSpecial() returns true. The file location of the picture in the Word binary file is accessed via CharacterRun.getPicOffset(). The CharacterRun.getPicOffset() is a byte offset into the data stream. Beginning at the position recorded in picOffset, a header data structure, will be stored.
author
Dmitry Romanov

Fields Summary
static final int
TYPE_IMAGE
static final int
TYPE_IMAGE_WORD2000
static final int
TYPE_IMAGE_PASTED_FROM_CLIPBOARD
static final int
TYPE_IMAGE_PASTED_FROM_CLIPBOARD_WORD2000
static final int
TYPE_HORIZONTAL_LINE
static final int
BLOCK_TYPE_OFFSET
static final int
MM_MODE_TYPE_OFFSET
private byte[]
_dataStream
Constructors Summary
public PicturesTable(byte[] _dataStream)

param
_dataStream


      
  /*# Picture lnkPicture; */

       
    
  
    this._dataStream = _dataStream;
  
Methods Summary
public org.apache.poi.hwpf.usermodel.PictureextractPicture(org.apache.poi.hwpf.usermodel.CharacterRun run, boolean fillBytes)
Returns picture object tied to specified CharacterRun

param
run
param
fillBytes if true, Picture will be returned with filled byte array that represent picture's contents. If you don't want to have that byte array in memory but only write picture's contents to stream, pass false and then use Picture.writeImageContent
see
Picture#writeImageContent(java.io.OutputStream)
return
a Picture object if picture exists for specified CharacterRun, null otherwise. PicturesTable.hasPicture is used to determine this.
see
#hasPicture(org.apache.poi.hwpf.usermodel.CharacterRun)

    if (hasPicture(run)) {
      return new Picture(run.getPicOffset(), _dataStream, fillBytes);
    }
    return null;
  
public java.util.ListgetAllPictures()

return
a list of Picture objects found in current document

    ArrayList pictures = new ArrayList();
    
    int pos = 0;
    boolean atEnd = false;
    
    while(pos<_dataStream.length && !atEnd) {
      if (isBlockContainsImage(pos)) {
        pictures.add(new Picture(pos, _dataStream, false));
      }
      
      int skipOn = LittleEndian.getInt(_dataStream, pos);
      if(skipOn <= 0) { atEnd = true; }
      pos += skipOn;
    }
    
    return pictures;
  
private static shortgetBlockType(byte[] dataStream, int pictOffset)

    return LittleEndian.getShort(dataStream, pictOffset + BLOCK_TYPE_OFFSET);
  
private static shortgetMmMode(byte[] dataStream, int pictOffset)

    return LittleEndian.getShort(dataStream, pictOffset + MM_MODE_TYPE_OFFSET);
  
public booleanhasHorizontalLine(org.apache.poi.hwpf.usermodel.CharacterRun run)
determines whether specified CharacterRun contains reference to a picture

param
run

    if (run.isSpecialCharacter() && "\u0001".equals(run.text())) {
      return isBlockContainsHorizontalLine(run.getPicOffset());
    }
    return false;
  
public booleanhasPicture(org.apache.poi.hwpf.usermodel.CharacterRun run)
determines whether specified CharacterRun contains reference to a picture

param
run

    if (run.isSpecialCharacter() && !run.isObj() && !run.isOle2() && !run.isData() && "\u0001".equals(run.text())) {
      return isBlockContainsImage(run.getPicOffset());
    }
    return false;
  
private booleanisBlockContainsHorizontalLine(int i)

    return getBlockType(_dataStream, i)==TYPE_HORIZONTAL_LINE && getMmMode(_dataStream, i)==0x64;
  
private booleanisBlockContainsImage(int i)

    return isPictureRecognized(getBlockType(_dataStream, i), getMmMode(_dataStream, i));
  
private booleanisPictureRecognized(short blockType, short mappingModeOfMETAFILEPICT)

    return (blockType == TYPE_IMAGE || blockType == TYPE_IMAGE_PASTED_FROM_CLIPBOARD || (blockType==TYPE_IMAGE_WORD2000 && mappingModeOfMETAFILEPICT==0x64) || (blockType==TYPE_IMAGE_PASTED_FROM_CLIPBOARD_WORD2000 && mappingModeOfMETAFILEPICT==0x64));