?? swftosvg.java
字號(hào):
package SWF2SVG;
// Copyright 1997, 1998,1999 Carmen Delessio (carmen@blackdirt.com)
// Black Dirt Software http://www.blackdirt.com/graphics
// Free for non-commercial use
// revisions:
// May 12,1999 corrected bad URL http://www.w3.org
// Corrected using <desc> as placeholders by embedding in their own <g>
import java.io.*;
import java.util.*;
import java.util.List;
import java.awt.*;
import java.net.*;
import java.applet.Applet;
import java.lang.Math;
import java.lang.String;
import java.awt.image.*;
class swftosvg {
private int i;
private int windowLong;
private short windowInt;
public int inch;
private java.util.Vector MetaRecordVector;
private DataInputStream d;
public WMFHandleTable ht;
byte[] byteData; // Unpacked data: one byte per pixel
byte[] rawData; // the raw unpacked data
int[] intData; // Unpacked data: one int per pixel
public WMFToolkit cvtTool = new WMFToolkit();
private String svgGraphic = new String("");
public short WMFWidth;
public short WMFHeight;
private short htmlWidth = 800;
private short htmlHeight = 600;
public short logExtX;
public short logExtY;
public short logOrgX = 0;
public short logOrgY = 0;
public short devExtX;
public short devExtY;
public int AppletWidth;
public int AppletHeight;
public float d_x;
public float d_y;
public Graphics wmfGraphics;
public Image wmfImageBuffer;
public int fontStyle;
public int fontWeight;
public boolean fontItalic = false;
public int penRed =0;
public int penGreen =0;
public int penBlue =0;
public int textRed =0;
public int textGreen =0;
public int textBlue =0;
String textColor = "000000";
String penColor = "000000";
List ls=new ArrayList();
public boolean styleSet = false;
DataInputStream f;
public swftosvg(InputStream is, PrintStream os,List ls) throws IOException
{
// mRecord = new MetaRecord( windowLong, windowInt, null);
d = new DataInputStream(is);
this.ls=ls;
parseit();
if (styleSet){
svgGraphic += "</g>";
}
svgGraphic += "</svg>\n";
// System.out.println(svgGraphic);
os.println(svgGraphic);
System.out.println("ok is over");
}
// gets all wmf records into a hash table
public synchronized void parseit()throws IOException {
byte[] f_long =new byte[4];
byte[] f_int = new byte[2];
byte[] parmBuffer;
short x;
short y;
short x2;
short y2;
short count = 0;
MetaRecord locMetaRecord;
//begin metafile header
//注意.這里兩個(gè)Byte表示一個(gè)字.看來(lái)圖片還是16位處理器下產(chǎn)生的.
windowLong = readLong(d); //key 4 bytes
if (windowLong == -1698247209){
//檢測(cè)的是頭文件中標(biāo)準(zhǔn)部分.第一個(gè)是雙字,必須為這個(gè)
//如果不是則說(shuō)明頭不存在標(biāo)準(zhǔn)部分.
windowInt = readInt(d); // unused
x2 = readInt(d);
y2 = readInt(d);
x = readInt(d);
y = readInt(d);//這四個(gè)字讀入是bbox,放映了圖片的大小
WMFWidth = (short) Math.abs(x2-x);
WMFHeight = (short) Math.abs(y2-y);
//定義中inch是word型.應(yīng)該是四個(gè)字節(jié).
windowInt = readInt(d); // inch
// System.out.println( windowInt );
inch = windowInt;
// System.out.println( cvtTool.getScreenResolution());
x = (short)(inch/cvtTool.getScreenResolution()); //pixels per inch
if (x < 1){
x =1;
}
// System.out.println("x="+x);
WMFWidth = (short)(WMFWidth /x);
WMFHeight = (short)(WMFHeight/x);
// based on bounded bo x- nnox consideration of map modes
svgGraphic = "<?xml version = \"1.0\" standalone = \"yes\"?>\n";
svgGraphic = svgGraphic + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG April 1999//EN\"\n \"http://www.w3.org/Graphics/SVG/svg-19990412.dtd\">\n";
svgGraphic = svgGraphic + "<svg width = \"" + WMFWidth +"px\" height=\"" + WMFHeight+"px\">\n";
htmlWidth = WMFWidth;
htmlHeight = WMFHeight;
devExtX = htmlWidth;
devExtY = htmlHeight;
x = cvtTool.twip2pixel(x); // add inch stuff here
y = cvtTool.twip2pixel(y);
windowLong = readLong(d); // reserved,沒(méi)有使用,必須為0.
windowInt = readInt(d);// checksum 頭中前十個(gè)字總和.
//metaheader
for ( i = 0; i < 3; i++){
windowInt = readInt(d);
//版本信息,頭文件大小及類(lèi)型全部省略.
}
windowLong = readLong(d);
windowInt = readInt(d);
windowLong = readLong(d);
windowInt = readInt(d);//頭文件全部讀取完畢.
}
else {
// not placeable- no metafile header
// already read long to check for key
windowInt = readInt(d);
windowLong = readLong(d);
windowInt = readInt(d);
windowLong = readLong(d);
windowInt = readInt(d);
//如果沒(méi)有前面的標(biāo)準(zhǔn)頭部,則全部讀完metaheader.
}
MetaRecordVector = new java.util.Vector();
Vector dclist =new Vector();
int index=0;
Stack dcstack=new Stack();
dc olddc=new dc(ls);
while(true){
count++;
System.out.println("*******");
try{
d.readFully(f_long);//讀入記錄大小,以雙字表示
}
catch(EOFException e){ System.out.println("**** eof");break;}
//這里是wmf文件特點(diǎn)?
// if (bytes_read == -1)
// break;
try{ windowLong = flipLong(f_long);
//反轉(zhuǎn)讀取的記錄大小到整形.這里是雙字大小.
windowInt = readInt(d);
//讀取一個(gè)字表示記錄類(lèi)型META_XXX
//記錄類(lèi)型如果為0則為空記錄,跳出.
}
catch(Exception e){
System.out.println("eof");break;
}
if (windowLong >= 3){
windowLong = (windowLong*2) -6;
}//通過(guò)記錄大小來(lái)判斷下面將要讀取的字節(jié)個(gè)數(shù).
// System.out.println(windowLong);
parmBuffer = null;
parmBuffer = new byte[windowLong];
d.readFully(parmBuffer);
locMetaRecord=new MetaRecord( windowLong, windowInt, parmBuffer);
// System.out.println("ok");
MetaRecordVector.addElement(locMetaRecord);
if(windowInt== 0x1E){
// System.out.println("sav"+parmBuffer);
olddc.addlist(MetaRecordVector);
olddc.setsvgGraphic();
// dclist.add(index, olddc);
svgGraphic+=olddc.change();
dcstack.push(olddc);
olddc= new dc(ls);
MetaRecordVector=new java.util.Vector();
}
if(windowInt== 0x127){
// System.out.println("res"+parmBuffer[1]);
olddc=(dc) dcstack.pop();
olddc.addlist(MetaRecordVector);
olddc.setsvgGraphic();
// System.out.println(MetaRecordVector.size());
svgGraphic+=olddc.change();
olddc=(dc) dclist.elementAt(index);
MetaRecordVector=new java.util.Vector();
// olddc=(dc)dclist.get(index-1);
/* if(MetaRecordVector.capacity()!=0)
{
// ht=(WMFHandleTable)dclist.get(index).getht();
olddc.setsvgGraphic();
// int indexrecord=dclist.get(index).getindex();
olddc.setht(ht,indexrecord);
olddc.addlist(MetaRecordVector);
svgGraphic+=olddc.change();
}*/
}
if (windowInt == 0){
System.out.println(index);
olddc.setsvgGraphic();
olddc.addlist(MetaRecordVector);
svgGraphic+=olddc.change();
styleSet =olddc.getstyset();
break;
}
}
}
// interprets each record
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 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 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;
}
public void setls(List ls){
this.ls=ls;
}
public static void main(String args[]) throws IOException{
swftosvg wmf = null;
File source_file;
File dest_file;
FileInputStream source = null;
FileOutputStream destination = null;
PrintStream dataOut = null;
DataInputStream dataIn;
/* if ((args.length == 0) || (args.length >2)){
System.out.println ("Useage: java wmf2svg <source file><destination file>");
System.exit(0);
}*/
// source_file = new File(args[0]);
source_file = new File("e:/dd.wmf");
dest_file = new File("e:/dd.svg");
source = new FileInputStream(source_file);
// source = new FileInputStream("e:/lion.wmf");
destination = new FileOutputStream(dest_file);
// destination = new FileOutputStream("e:/lion.svg");
dataOut = new PrintStream(destination);
dataIn = new DataInputStream(source);
;
poptd po=null;
try{
po= new poptd(dataIn);}
catch(Exception e){
System.out.println("is rong1");
}
// get it to input strream and output stream here
// make the
//?? make is stage WMF2SVG.read
// WMF2SVawrite
List ls=null;
try{
ls=po.getls();
dataIn.close();
source.close();
}
catch(Exception e){
System.out.println("is rong2");
}
DataInputStream dataIn2 = null ;
source = new FileInputStream(source_file);
try{
dataIn2 = new DataInputStream(source);
}
catch(Exception e){
System.out.println("is rong");
}
try{
wmf = new swftosvg(dataIn2,dataOut,ls);}
catch(Exception e){
System.out.println("is rong3");
}
}
} //end parsewmf
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -