java - Reading text from swf with StuartMacKay's transform-swf library -


i need extract texts swf files. i'm using java since have lot of modules developed language. thus, did search through web free java library devoted handle swf files. finally, found library developed stuartmackay. library, named transform-swf, may found on github clicking here.

the question is: once extract glyphindexes textspan, how can convert glyps in characters?

please, provide complete working , tested example. no theoretical answer accepted nor answers "it cannot done", "it ain't possible", etc.

what know , did know glyphindexes built using texttable, constructed recurring integer represente font size , font description provided definefont2 object, when decode definefont2, have 0 length advance.

here follows did.

//creating movie object swf file. movie movie = new movie(); movie.decodefromfile(new file(out));  //saving decoded definefont2 objects. map<integer,definefont2> fonts = new hashmap<>(); (movietag object : list) {   if (object instanceof definefont2) {     definefont2 df2 = (definefont2) object;     fonts.put(df2.getidentifier(), df2);   } }  //now retrieve texts        (movietag object : list) {     if (object instanceof definetext2) {         definetext2 dt2 = (definetext2) object;         (textspan ts : dt2.getspans()) {             integer fontidentifier = ts.getidentifier();             if (fontidentifier != null) {                 int fontsize = ts.getheight();                 // here try create object should                 // reverse process done texttable                 reversetexttable rtt =                    new reversetexttable(fonts.get(fontidentifier), fontsize);                 system.out.println(rtt.charactersfortext(ts.getcharacters()));             }         }     } } 

the class reversetexttable follows here:

public final class reversetexttable {       private final transient map<character, glyphindex> characters;     private final transient map<glyphindex, character> glyphs;      public reversetexttable(final definefont2 font, final int fontsize) {             characters = new linkedhashmap<>();         glyphs = new linkedhashmap<>();          final list<integer> codes = font.getcodes();         final list<integer> advances = font.getadvances();         final float scale = fontsize / emsquare;         final int count = codes.size();          (int = 0; < count; i++) {             characters.put((char) codes.get(i).intvalue(), new glyphindex(i,                     (int) (advances.get(i) * scale)));             glyphs.put(new glyphindex(i,                     (int) (advances.get(i) * scale)), (char) codes.get(i).intvalue());         }     }          //this method should reverse list of glyphindexes string     public string charactersfortext(final list<glyphindex> list) {         string text="";         for(glyphindex gi: list){             text+=glyphs.get(gi);         }         return text;     }         } 

unfortunately, list of advances definefont2 empty, constructor of reversetabletext arrayindexoutofboundexception.

honestly, don't know how in java. i'm not claiming not possible, believe there way that. however, said there lot of libraries that. suggested library, i.e. swftools. so, suggest recurr library extract text flash file. can use runtime.exec() execute command line run library.

personally, prefer apache commons exec rather standard library released jdk. well, let me show how should do. executable file should use "swfstrings.exe". suppose put in "c:\". suppose in same folder can find flash file, e.g. page.swf. then, tried following code (it works fine):

    path pathtoswffile = paths.get("c:\" + file.separator + "page.swf");     commandline commandline = commandline.parse("c:\" + file.separator + "swfstrings.exe");     commandline.addargument("\"" + swffile.tostring() + "\"");     defaultexecutor executor = new defaultexecutor();     executor.setexitvalues(new int[]{0, 1}); //notice swfstrings.exe returns 1 success,                                             //0 file not found, -1 error      bytearrayoutputstream stdout = new bytearrayoutputstream();     pumpstreamhandler psh = new pumpstreamhandler(stdout);     executor.setstreamhandler(psh);     int exitvalue;     try{         exitvalue = executor.execute(commandline);     }catch(org.apache.commons.exec.executeexception ex){         psh.stop();     }     if(!executor.isfailure(exitvalue)){        string out = stdout.tostring("utf-8"); // here have extracted text     } 

i know, not answer requested, works fine.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -