FileDocCategorySizeDatePackage
WMF.javaAPI DocApache Poi 3.0.17570Thu May 31 18:45:28 BST 2007org.apache.poi.hslf.blip

WMF

public class WMF extends Metafile
Represents a WMF (Windows Metafile) picture data.
author
Yegor Kozlov

Fields Summary
Constructors Summary
Methods Summary
public byte[]getData()
Extract compressed WMF data from a ppt

        try {
            byte[] rawdata = getRawData();

            ByteArrayOutputStream out = new ByteArrayOutputStream();
            InputStream is = new ByteArrayInputStream( rawdata );
            Header header = new Header();
            header.read(rawdata, CHECKSUM_SIZE);
            is.skip(header.getSize() + CHECKSUM_SIZE);

            AldusHeader aldus = new AldusHeader();
            aldus.left = header.bounds.x;
            aldus.top = header.bounds.y;
            aldus.right = header.bounds.x + header.bounds.width;
            aldus.bottom = header.bounds.y + header.bounds.height;
            aldus.write(out);

            InflaterInputStream inflater = new InflaterInputStream( is );
            byte[] chunk = new byte[4096];
            int count;
            while ((count = inflater.read(chunk)) >=0 ) {
                out.write(chunk,0,count);
            }
            inflater.close();
            return out.toByteArray();
        } catch (IOException e){
            throw new HSLFException(e);
        }
    
public intgetSignature()
WMF signature is 0x2160

        return 0x2160;
    
public intgetType()
We are of type Picture.WMF

        return Picture.WMF;
    
public voidsetData(byte[] data)

        int pos = 0;
        AldusHeader aldus = new AldusHeader();
        aldus.read(data, pos);
        pos += aldus.getSize();

        byte[] compressed = compress(data, pos, data.length-pos);

        Header header = new Header();
        header.wmfsize = data.length - aldus.getSize();
        header.bounds = new java.awt.Rectangle((short)aldus.left, (short)aldus.top, (short)aldus.right-(short)aldus.left, (short)aldus.bottom-(short)aldus.top);
        //coefficiaent to translate from WMF dpi to 96pdi
        int coeff = 96*Shape.EMU_PER_POINT/aldus.inch;
        header.size = new java.awt.Dimension(header.bounds.width*coeff, header.bounds.height*coeff);
        header.zipsize = compressed.length;

        byte[] checksum = getChecksum(data);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        out.write(checksum);
        header.write(out);
        out.write(compressed);

        setRawData(out.toByteArray());