📄 wmf2svg.java
字号:
}
}
svgGraphic = svgGraphic + " <g>\n <desc> Java Font definition:" + currentFont + " " + fontWeight + "</desc> \n </g>\n";
break;
case 0x12d: //select object
windowInt = readInt(parmStream);
//记录名称用参数保存
switch(windowInt){
case 0x2fa:
MetaRecord me=(MetaRecord) hs.get(recordIndex);
break;
}
/* mRecord = ht.selectObject(windowInt);//在哈西表中找到该记录对象
WMFlistRecord(mRecord, true);*///需要显示选择的对象
break;
case 0x1f0:
windowInt = readInt(parmStream);
ht.deleteObject(windowInt);
break;
case 0x001E://savedc
dcstack.push( new String( brushColor));
brushset =true;
dcstack.push( new String( penColor ));
penset =true;
dcstack.push( new String( currentFont ));
fontset =true;
dcstack.push(textColor);
textColorset=true;
break;
case 0x127://restordc
textColor=(String)dcstack.pop();
textColorset=false;
currentFont=(String) dcstack.pop();
brushset=false;
penColor=(String) dcstack.pop();
penset=false;
brushColor=(String) dcstack.pop();
fontset=false;
case 0x41b: //rectangle
numRectangles++;
shapeName = "rectangle" + numRectangles;
y2 = readInt(parmStream);
x2 = readInt(parmStream);
y = readInt(parmStream);
x = readInt(parmStream);
x = mapX(x);
x2 = mapX(x2);
y = mapY(y);
y2 = mapY(y2);
w = (short) Math.abs(x2-x);
h = (short) Math.abs(y2-y);
// note I am doing draw-filled on a shape by shape basis,
// SVG is more `like WMF - can do it at assignment time as a
// style, therefore these shapes can just take care of themselves
svgGraphic = svgGraphic + " <rect x = " + "\"" + x + "\"" + " y = " + "\"" + y + "\"" + " width = " + "\"" + w + "\"" + " height = " + "\"" + h + "\""+ "\n";
break;
case 0x418: //Oval
numOvals++;
shapeName = "Oval" + numOvals;
y2 = readInt(parmStream);
x2 = readInt(parmStream);
y = readInt(parmStream);
x = readInt(parmStream);
x = mapX(x);
x2 = mapX(x2);
y = mapY(y);
y2 = mapY(y2);
int major;
int minor;
int angle;
int cx;
int cy;
w = (short) Math.abs(x2-x);
h = (short) Math.abs(y2-y);
if (w>h){
major=w;
minor=h;
angle=0;
}
else{
major=h;
minor=w;
angle = 90;
}
cx = (int)(x+ Math.round(0.5 * w));
cy = (int)(y + Math.round(0.5*h));
svgGraphic = svgGraphic + " <ellipse cx = " + "\"" + cx + "\"" + " cy = " + "\"" + cy + "\"" + " major = " + "\"" + major + "\"" + " minor = " + "\"" + minor + "\"" + " angle = " + "\"" + angle + "\"" + "\n";
// svgGraphic = svgGraphic + " <desc> Oval:" + + x + " " + y + " " + w + " " + h + "</desc> \n";
break;
case 0x325: //polyline
// poly = new Polygon();
numPoints = readInt(parmStream);
// tempBuffer = " <polyline verts = \"";
tempBuffer = " <path d = \"M";
// read 1st point as move to segment
x = readInt(parmStream);
y = readInt(parmStream);
x = mapX(x);
y = mapY(y);
tempBuffer = tempBuffer + " " + x + "," + y ;
for (i = 0; i < numPoints -1; i++){
x = readInt(parmStream);
y = readInt(parmStream);
x = mapX(x);
y = mapY(y);
tempBuffer = tempBuffer + "L" + x + "," + y ;
}
svgGraphic = svgGraphic + tempBuffer + "\"+ \n";
break;
case 0x324: //polygon
// poly = new Polygon();
numPoints = readInt(parmStream);
// tempBuffer = " <polyline verts = \"";
oldx = readInt(parmStream);
oldy = readInt(parmStream);
oldx = mapX(oldx);
oldy = mapY(oldy);
tempBuffer = " <path d = \"M";
tempBuffer = tempBuffer + " " + oldx + "," + oldy ;
for (i = 0; i < numPoints-1; i++){
x = readInt(parmStream);
y = readInt(parmStream);
x = mapX(x);
y = mapY(y);
tempBuffer = tempBuffer + "L" + x + "," + y ;
}
tempBuffer = tempBuffer + "L" + oldx + "," + oldy ;
svgGraphic = svgGraphic + tempBuffer + "\"+ \n";
break;
case 0x538: //polypolygon
int numPolys = readInt(parmStream);
ncount = new int[numPolys];
for (j = 0; j < numPolys ; j++){
ncount[j] = readInt(parmStream);
}
for (j = 0; j < numPolys ; j++){
poly = new Polygon();
numPoints = (short) ncount[j];
tempBuffer = " <polyline verts = \"";
oldx = readInt(parmStream);
oldy = readInt(parmStream);
oldx = mapX(oldx);
oldy = mapY(oldy);
tempBuffer = tempBuffer + " " + oldx + "," + oldy ;
// poly.addPoint( oldx ,oldy );
for (i = 0; i < numPoints-1; i++){
x = readInt(parmStream);
y = readInt(parmStream);
x = mapX(x);
y = mapY(y);
tempBuffer = tempBuffer + " " + x + "," + y ;
}
tempBuffer = tempBuffer + " " + oldx + "," + oldy ;
svgGraphic = svgGraphic + tempBuffer + "\"/> \n";
}
break;
case 0x214: //moveto
oldy = readInt(parmStream);
oldx = readInt(parmStream);
oldx = mapX(oldx);
oldy = mapY(oldy);
svgGraphic = svgGraphic + " <path d = \" M " + oldx + " " + oldy + " \"/> \n";
break;
case 0x213: //lineto
numLines++;
shapeName = "line" + numLines;
y = readInt(parmStream);
x = readInt(parmStream);
x = mapX(x);
y = mapY(y);
svgGraphic = svgGraphic + " <path d = \" L " + x + " " + y + " \"/> \n";
break;
case 0x209://set text color
// save text color
// when writing text, switch to text colors
// when done writing, switch back
selColor = readLong(parmStream);
cvtTool.setColors(selColor);
if(textColorset)
textColor = cvtTool.getRGBColor( selColor);
break;
case 0x201://set BK color
break;
case 0xa32: // exttext...
if (styleSet){
svgGraphic = svgGraphic +"</g> \n";
} else{
styleSet = true;
}
svgGraphic = svgGraphic + "<g style = \"stroke: #" + textColor + "\" > \n";
y = readInt(parmStream);
x = readInt(parmStream);
x = mapX(x);
y = mapY(y);
numChars = readInt(parmStream);
wOptions = readInt(parmStream);
textBuffer = new byte[numChars];
try{
parmStream.read(textBuffer);
}
catch(IOException e){ System.err.println(e);}
tempBuffer = new String(textBuffer,0);
svgGraphic = svgGraphic + " <text x = " + "\"" + x + "\"" + " y = " + "\"" + y + "\" >" + tempBuffer + "</text>\n";
svgGraphic = svgGraphic +"</g> \n";
svgGraphic = svgGraphic + "<g style = \"stroke: #" + penColor + "\" > \n";
break;
case 0x521: // TEXTOUT
if (styleSet){
svgGraphic = svgGraphic +"</g> \n";
} else{
styleSet = true;
}
svgGraphic = svgGraphic + "<g style = \"stroke: #" + textColor + "\" > \n";
numChars = readInt(parmStream);
textBuffer = new byte[numChars+1];
try{
parmStream.read(textBuffer);
}
catch(IOException e){ System.err.println(e);}
tempBuffer = new String(textBuffer,0);
y = readInt(parmStream);
x = readInt(parmStream);
x = mapX(x);
y = mapY(y);
svgGraphic = svgGraphic + " <text x = " + "\"" + x + "\"" + " y = " + "\"" + y + "\" >" + tempBuffer + "</text>\n";
svgGraphic = svgGraphic +"</g> \n";
svgGraphic = svgGraphic + "<g style = \"stroke: #" + penColor + "\" > \n";
break;
case 0xF43: //stretch DIB
svgGraphic = svgGraphic + " <desc> DIB - Device independent Bitmap - will convert to JPEG in next release </desc> \n";
break;
case 0x20B: //set_window_org
logOrgY = readInt(parmStream);
// System.out.println("logOrgY= " +logOrgY);
logOrgX = readInt(parmStream);
break;
case 0x20C: //set_window_ext
logExtY = readInt(parmStream);
logExtX = readInt(parmStream);
break;
default:
} // end switch
try{
parmStream.close();
}
catch(IOException e){ System.err.println(e);}
}
public short mapX(short x){
d_x = (float)devExtX/logExtX;
x = (short)(x - logOrgX);
x = (short) (x*d_x);
return (x);
}
public short mapY(short y){
d_y = (float)devExtY/logExtY;
y = (short)(y - logOrgY);
y = (short) (y*d_y);
return (y);
}
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 static void main(String args[]){
wmf2svg wmf;
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:/ff.wmf");
dest_file = new File("e:/ff.svg");
try{
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);
// get it to input strream and output stream here
// make the
//?? make is stage WMF2SVG.read
// WMF2SVawrite
wmf = new wmf2svg(dataIn,dataOut);
}
catch(IOException e){ System.err.println(e);
}
System.exit(0);
}
} //end parsewmf
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -