📄 poptd.java
字号:
package SWF2SVG;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
public class poptd {
DataInputStream f;
List ls=new ArrayList();
public poptd(DataInputStream is) throws IOException{
this.f=is;
presit();
}
private void presit() throws IOException {
byte[] f_long =new byte[4];
byte[] f_int = new byte[2];
byte[] parmBuffer;
int windowLong= readLong(f);
if (windowLong == -1698247209){
//检测的是头文件中标准部分.第一个是双字,必须为这个
//如果不是则说明头不存在标准部分.
int windowInt = readInt(f); // unused
int x2 = readInt(f);
int y2 = readInt(f);
int x = readInt(f);
int y = readInt(f);//这四个字读入是bbox,放映了图片的大小
int WMFWidth = (short) Math.abs(x2-x);
int WMFHeight = (short) Math.abs(y2-y);
//定义中inch是word型.应该是四个字节.
windowInt = readInt(f); // inch
// System.out.println( windowInt );
int inch = windowInt;
windowLong = readLong(f); // reserved,没有使用,必须为0.
windowInt = readInt(f);// checksum 头中前十个字总和.
//metaheader
for (int i = 0; i < 3; i++){
windowInt = readInt(f);
//版本信息,头文件大小及类型全部省略.
}
windowLong = readLong(f);
windowInt = readInt(f);
windowLong = readLong(f);
windowInt = readInt(f);//头文件全部读取完毕.
}
else {
// not placeable- no metafile header
// already read long to check for key
int windowInt = readInt(f);
windowLong = readLong(f);
windowInt = readInt(f);
windowLong = readLong(f);
windowInt = readInt(f);
//如果没有前面的标准头部,则全部读完metaheader.
}
Vector MetaRecordVector = new java.util.Vector();
Vector dclist =new Vector();
int index=0;
int indexrecord=0;
boolean s=true;
while(s){
try{
f.readFully(f_long);//读入记录大小,以双字表示
}
catch(EOFException e){ System.out.println("eof");break;} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
//这里是wmf文件特点?
// if (bytes_read == -1)
// break;
windowLong = flipLong(f_long);
//反转读取的记录大小到整形.这里是双字大小.
short windowInt = readInt(f);
//读取一个字表示记录类型META_XXX
//记录类型如果为0则为空记录,跳出.
if (windowInt==0)
break;
if (windowLong >= 3){
windowLong = (windowLong*2) -6;
}//通过记录大小来判断下面将要读取的字节个数.
parmBuffer = null;
parmBuffer = new byte[windowLong];
f.readFully(parmBuffer);
MetaRecord locMetaRecord = new MetaRecord( windowLong, windowInt, parmBuffer);
ls.add(indexrecord, locMetaRecord);
indexrecord++;
}
System.out.println(indexrecord);
}
public List getls(){
return ls;
}
public int readLong( DataInputStream d){
byte[] longBuf =new byte[4];
try{
d.read(longBuf);
// d.readFully(longBuf);
return flipLong(longBuf);
} catch(IOException e){
System.err.println(e);
return 99;
}
}
public short readInt( DataInputStream d){
byte[] intBuf =new byte[2];
try{
d.read(intBuf);
// d.readFully(intBuf);
return flipInt(intBuf);
} catch(IOException e){
System.err.println(e);
return 99;
}
}
public int flipLong(byte[] byteFlip){
DataInputStream dl;
ByteArrayInputStream b_in;
byte[] bytebuffer;
bytebuffer = new byte[4];
bytebuffer[0] = byteFlip[3];
bytebuffer[1] = byteFlip[2];
bytebuffer[2] = byteFlip[1];
bytebuffer[3] = byteFlip[0];
b_in = new ByteArrayInputStream(bytebuffer);
dl = new DataInputStream(b_in);
try{
return dl.readInt();
}
catch(IOException e){System.err.println(e);}
return 0;
}
public short flipInt( byte[] byteFlip){
DataInputStream d;
ByteArrayOutputStream b_out;
ByteArrayInputStream b_in;
byte[] bytebuffer;
bytebuffer = new byte[2];
bytebuffer[0] = byteFlip[1];
bytebuffer[1] = byteFlip[0];
b_in = new ByteArrayInputStream(bytebuffer);
d = new DataInputStream(b_in);
try{
return d.readShort();
}
catch(IOException e){ System.err.println(e);}
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -