gfx dump view fixes, FileAttributeTag fix in dumpview

This commit is contained in:
honfika
2014-08-24 11:07:01 +02:00
parent c91f0b106c
commit 6a2f1027b8
9 changed files with 102 additions and 22 deletions

View File

@@ -264,6 +264,7 @@ import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.ImmediateFuture;
import com.jpexs.helpers.MemoryInputStream;
import com.jpexs.helpers.ProgressListener;
import com.jpexs.helpers.utf8.Utf8Helper;
@@ -1010,9 +1011,6 @@ public class SWFInputStream implements AutoCloseable {
executor = Executors.newFixedThreadPool(Configuration.parallelThreadCount.get());
futureResults = new ArrayList<>();
}
int tagCnt = 0;
int faPos = 0;
FileAttributesTag fileAttributes = null;
List<Tag> tags = new ArrayList<>();
Tag tag;
boolean isAS3 = false;
@@ -1024,7 +1022,6 @@ public class SWFInputStream implements AutoCloseable {
} catch (EOFException | EndOfStreamException ex) {
tag = null;
}
tagCnt++;
DumpInfo di = dumpInfo;
if (di != null && tag != null) {
di.name = tag.getName();
@@ -1048,11 +1045,10 @@ public class SWFInputStream implements AutoCloseable {
} else {
switch (tag.getId()) {
case FileAttributesTag.ID: //FileAttributes
faPos = tagCnt - 1; //should be 0, as it is first tag, but anyway
if (tag instanceof TagStub) {
tag = resolveTag((TagStub) tag, level, parallel, skipUnusualTags);
}
fileAttributes = (FileAttributesTag) tag;
FileAttributesTag fileAttributes = (FileAttributesTag) tag;
if (fileAttributes.actionScript3) {
isAS3 = true;
}
@@ -1091,11 +1087,12 @@ public class SWFInputStream implements AutoCloseable {
}
}
if (parseTags && doParse && tag instanceof TagStub) {
if (parallel) {
Future<Tag> future = executor.submit(new TagResolutionTask((TagStub) tag, di, level, parallel, skipUnusualTags));
futureResults.add(future);
}
if (parseTags && doParse && parallel && tag instanceof TagStub) {
Future<Tag> future = executor.submit(new TagResolutionTask((TagStub) tag, di, level, parallel, skipUnusualTags));
futureResults.add(future);
} else {
Future<Tag> future = new ImmediateFuture(tag);
futureResults.add(future);
}
if (tag.getId() == EndTag.ID) {
@@ -1116,10 +1113,6 @@ public class SWFInputStream implements AutoCloseable {
executor.shutdown();
}
//Workaround to not reading fileattributes twice. TODO:Handle this better
if (parallel && fileAttributes != null) {
tags.add(faPos, fileAttributes);
}
return tags;
}
@@ -3296,7 +3289,9 @@ public class SWFInputStream implements AutoCloseable {
public MemoryInputStream getBaseStream() throws IOException {
int pos = (int) is.getPos();
return new MemoryInputStream(is.getAllRead(), pos, is.available());
MemoryInputStream mis = new MemoryInputStream(is.getAllRead(), 0, pos + is.available());
mis.seek(pos);
return mis;
}
public SWFInputStream getLimitedStream(int limit) throws IOException {

View File

@@ -452,8 +452,10 @@ public class Configuration {
Map<String, String> result = new HashMap<>();
for (String pair : fonts.split("::")) {
String[] splittedPair = pair.split("=");
result.put(splittedPair[0], splittedPair[1]);
if (!pair.isEmpty()) {
String[] splittedPair = pair.split("=");
result.put(splittedPair[0], splittedPair[1]);
}
}
return result;
}

View File

@@ -97,7 +97,11 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag {
MemoryInputStream mis = sis.getBaseStream();
while (mis.available() > 0) {
fonts.add(new FontType(new GFxInputStream(mis)));
GFxInputStream gis = new GFxInputStream(mis);
gis.dumpInfo = sis.dumpInfo;
gis.newDumpLevel("fontType", "FontType");
fonts.add(new FontType(gis));
gis.endDumpLevel();
}
rebuildShapeCache();
}

View File

@@ -104,14 +104,18 @@ public class FontTextureInfo extends Tag {
texGlyphs = new TEXGLYPH[numTexGlyphs];
MemoryInputStream mis = sis.getBaseStream();
for (int i = 0; i < numTexGlyphs; i++) {
texGlyphs[i] = new TEXGLYPH(new GFxInputStream(mis));
GFxInputStream gis = new GFxInputStream(mis);
gis.dumpInfo = sis.dumpInfo;
texGlyphs[i] = new TEXGLYPH(gis);
}
sis.skipBytes(mis.getPos());
int numFonts = sis.readUI16("numFonts");
fonts = new FONTINFO[numFonts];
mis = sis.getBaseStream();
for (int i = 0; i < numFonts; i++) {
fonts[i] = new FONTINFO(new GFxInputStream(sis.getBaseStream()));
GFxInputStream gis = new GFxInputStream(mis);
gis.dumpInfo = sis.dumpInfo;
fonts[i] = new FONTINFO(gis);
}
sis.skipBytes(mis.getPos());
}

View File

@@ -85,7 +85,9 @@ public class ContourType implements Serializable {
edges = new EdgeType[(int) numEdgesRef];
for (int i = 0; i < edges.length; i++) {
sis.newDumpLevel("edgeType", "EdgeType");
edges[i] = new EdgeType(sis);
sis.endDumpLevel();
}
if (isReference) {
sis.setPos(oldPos);

View File

@@ -42,6 +42,7 @@ public class FontType implements Serializable {
public List<KerningPairType> kerning;
public FontType(GFxInputStream sis) throws IOException {
long offset = sis.getPos();
fontName = sis.readString("fontName");
flags = sis.readUI16("flags");
nominalSize = sis.readUI16("nominalSize");
@@ -54,21 +55,27 @@ public class FontType implements Serializable {
sis.read(glyphBytes);
glyphInfo = new ArrayList<>();
for (int i = 0; i < numGlyphs; i++) {
sis.newDumpLevel("glyphInfoType", "GlyphInfoType");
glyphInfo.add(new GlyphInfoType(sis));
sis.endDumpLevel();
}
long kerningTableSize = sis.readUI30("kerningTableSize");
kerning = new ArrayList<>();
for (int i = 0; i < kerningTableSize; i++) {
sis.newDumpLevel("kerningPairType", "KerningPairType");
kerning.add(new KerningPairType(sis));
sis.endDumpLevel();
}
long pos = sis.getPos();
glyphs = new ArrayList<>();
for (int i = 0; i < glyphInfo.size(); i++) {
sis.setPos(glyphInfo.get(i).globalOffset);
sis.setPos(glyphInfo.get(i).globalOffset + offset);
sis.newDumpLevel("glyphType", "GlyphType");
glyphs.add(new GlyphType(sis));
sis.endDumpLevel();
}
sis.setPos(pos);

View File

@@ -93,6 +93,7 @@ public class GFxInputStream {
/**
* Reads one SI16 (Signed 16bit integer) value from the stream
*
* @param name
* @return SI16 value
* @throws IOException
*/
@@ -206,6 +207,7 @@ public class GFxInputStream {
* Reads bytes from the stream
*
* @param count Number of bytes to read
* @param name
* @return Array of read bytes
* @throws IOException
*/
@@ -229,6 +231,7 @@ public class GFxInputStream {
/**
* Reads one string value from the stream
*
* @param name
* @return String value
* @throws IOException
*/

View File

@@ -69,7 +69,9 @@ public class GlyphType implements Serializable {
int numContours = sis.readUI15("numContours");
contours = new ContourType[numContours];
for (int i = 0; i < numContours; i++) {
sis.newDumpLevel("contourType", "ContourType");
contours[i] = new ContourType(sis);
sis.endDumpLevel();
}
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.helpers;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
/**
*
* @author JPEXS
* @param <V>
*/
public class ImmediateFuture<V> implements Future<V> {
private final V value;
public ImmediateFuture(V value) {
this.value = value;
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return true;
}
@Override
public V get() throws InterruptedException, ExecutionException {
return value;
}
@Override
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return value;
}
}