1 4 5 9 10 package org.openlaszlo.sc; 11 12 import org.openlaszlo.utils.FileUtils; 13 import org.openlaszlo.utils.StringUtils; 14 import org.openlaszlo.compiler.FontInfo; 15 import org.openlaszlo.iv.flash.api.*; 16 import org.openlaszlo.iv.flash.api.action.*; 17 import org.openlaszlo.iv.flash.api.image.*; 18 import org.openlaszlo.iv.flash.api.sound.*; 19 import org.openlaszlo.iv.flash.api.text.*; 20 import org.openlaszlo.iv.flash.util.*; 21 import org.openlaszlo.iv.flash.cache.*; 22 import org.apache.log4j.*; 23 24 import java.io.*; 25 import java.util.*; 26 27 30 31 public class CompressFlashFile { 32 private static Logger mLogger = Logger.getLogger(CompressFlashFile.class); 33 34 static public void main (String args[]) { 35 if (args.length != 2) { 36 System.out.println("usage: compressFlashFile infile outfile"); 37 System.exit(1); 38 } 39 compressFile(args[0], args[1]); 40 } 41 42 static public void compressFile (String infile, String outfile) { 43 try { 44 FlashFile f = FlashFile.parse(infile); 45 OutputStream out = new FileOutputStream(outfile); 46 FontsCollector fc = new FontsCollector(); 47 HashMap fontsTable = new HashMap(); 48 49 java.util.Enumeration defs = f.definitions(); 50 while(defs.hasMoreElements()) { 51 FlashDef def = (FlashDef)defs.nextElement(); 52 if (def instanceof FontDef) { 53 FontDef fontDef = (FontDef)def; 54 Font font = fontDef.getFont(); 55 String bold = ((font.BOLD & font.flags) > 0 ? "bold" : ""); 56 String italic = ((font.ITALIC & font.flags) > 0 ? 57 "italic" : ""); 58 FontDef fdef = fc.addFont(font, null); 61 fdef.setWriteAllChars(true); 62 fdef.setWriteLayout(true); 63 fontsTable.put(font.getFontName() + "::"+bold+italic, font); 64 } 65 } 66 f.setCompressed(true); 68 writeFlashFile(f, fc, out); 69 } catch (Exception e) { 70 mLogger.error("exception in CompressFlashFile.compressFile", e); 71 } 72 } 73 74 static void writeFlashFile(FlashFile f, FontsCollector fc, OutputStream out) { 75 try { 76 InputStream input; 77 input = f.generate(fc, null, false).getInputStream(); 78 FileUtils.send(input, out); 79 input.close(); 80 out.close(); 81 } catch (Exception e) { 82 mLogger.error("exception in CompressFlashFile.writeFlashFile", e); 83 } 84 } 85 86 } 87 | Popular Tags |