blipstoreentry.java

来自「jexcelapi_2_4, JXL的API, JXL是JAVA读取EXCEL的」· Java 代码 · 共 137 行

JAVA
137
字号
/*********************************************************************
*
*      Copyright (C) 2003 Andrew Khan
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/

package jxl.biff.drawing;

import java.io.FileInputStream;
import java.io.IOException;
import common.Assert;
import jxl.biff.IntegerHelper;

class BlipStoreEntry extends EscherAtom
{
  private BlipType type;
  private java.io.File imageFile;
  private byte[] data;
  private int imageFileLength;
  private int referenceCount;

  public BlipStoreEntry(EscherRecordData erd)
  {
    super(erd);
    type = BlipType.getType(getInstance());
    byte[] bytes = getBytes();
    referenceCount =  IntegerHelper.getInt(bytes[24], bytes[25], 
                                           bytes[26], bytes[27]);
  }

  public BlipStoreEntry(Drawing d)
    throws IOException
  {
    super(EscherRecordType.BSE);
    imageFile = d.getImageFile();
    type = BlipType.PNG;
    setVersion(2);
    setInstance(type.getValue());

    imageFileLength = (int) imageFile.length();
    data = new byte[imageFileLength + 61];
    FileInputStream fis = new FileInputStream(imageFile);
    fis.read(data, 61, imageFileLength);
    fis.close(); 
    referenceCount = d.getReferenceCount();
  }

  public BlipType getBlipType()
  {
    return type;
  }

  public byte[] getData()
  {    
    if (imageFile != null)
    {
      // Drawing has been specified by API

    // Type on win32
    data[0] = (byte) type.getValue();

    // Type on MacOs
    data[1] = (byte) type.getValue();

    // The blip identifier
    //    IntegerHelper.getTwoBytes(0xfce1, data, 2);

    // Unused tags - 18 bytes
    //    System.arraycopy(stuff, 0, data, 2, stuff.length);

    // The size of the file
    IntegerHelper.getFourBytes(imageFileLength + 8 + 17, data, 20);

    // The reference count on the blip
    IntegerHelper.getFourBytes(referenceCount, data, 24);

    // Offset in the delay stream
    IntegerHelper.getFourBytes(0, data, 28);

    // Usage byte
    data[32] = (byte) 0;

    // Length of the blip name
    data[33] = (byte) 0;

    // Last two bytes unused
    data[34] = (byte) 0x7e;
    data[35] = (byte) 0x01;

    // The blip itself
    data[36] = (byte) 0;
    data[37] = (byte) 0x6e;
    
    // The blip identifier
    IntegerHelper.getTwoBytes(0xf01e, data, 38);

    // The length of the blip.  This is the length of the image file plus 
    // 16 bytes
    IntegerHelper.getFourBytes(imageFileLength + 17, data, 40);

    // Unknown stuff
    //    System.arraycopy(stuff, 0, data, 44, stuff.length);
    }
    else
    {
      // drawing has been read in
      data = getBytes();
    }
   
    return setHeaderData(data);
  }

  void dereference()
  {
    referenceCount--;
    Assert.verify(referenceCount >= 0);
  }

  int getReferenceCount()
  {
    return referenceCount;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?