1 4 5 9 10 11 package org.openlaszlo.test; 12 13 import java.io.*; 14 import org.openlaszlo.iv.flash.api.*; 15 import org.openlaszlo.iv.flash.api.text.*; 16 import org.openlaszlo.iv.flash.util.*; 17 import org.openlaszlo.utils.FileUtils; 18 19 20 public class copyswf { 21 static public void main (String args[]) { 22 try { 23 FlashFile f = FlashFile.parse(args[0]); 24 OutputStream out = new FileOutputStream(args[1]); 25 26 java.util.Enumeration defs = f.definitions(); 27 FontsCollector fc = new FontsCollector(); 28 FontsCollector pfc = new FontsCollector(); 29 30 FontsCollector curfc = pfc; 32 33 45 int index = 0; 46 int lastIndex = -1; 47 48 boolean hasPreloader = false; 49 50 while(defs.hasMoreElements()) { 51 FlashDef def = (FlashDef)defs.nextElement(); 52 index++; 53 54 if (index == 1 && !(def instanceof FontDef)) { 57 hasPreloader = true; 58 } 59 60 if (def instanceof FontDef) { 61 if (!hasPreloader) { 64 if (lastIndex == -1) { 66 lastIndex = index; 67 } 68 else { 69 if (index > lastIndex + 1) { 72 hasPreloader = true; 73 curfc = fc; 74 } 75 } 76 } 77 FontDef fontDef = (FontDef)def; 78 Font font = fontDef.getFont(); 79 String bold = ((font.BOLD & font.flags) > 0 ? "bold" : ""); 80 String italic = ((font.ITALIC & font.flags) > 0 ? 81 "italic" : ""); 82 System.out.println("Copying font " + font.getFontName() 83 + bold + italic); 84 FontDef fdef = curfc.addFont(font, null); 85 fdef.setWriteAllChars(true); 86 fdef.setWriteLayout(true); 87 } 88 index++; 89 } 90 InputStream input; 91 92 if (!hasPreloader) { 95 fc = pfc; 96 pfc = null; 97 } 98 input = f.generate(fc, pfc, hasPreloader).getInputStream(); 99 FileUtils.send(input, out); 100 input.close(); 101 out.close(); 102 } catch (Exception e) { 103 e.printStackTrace(); 104 } 105 } 106 } 107 | Popular Tags |