show some basic tag info

This commit is contained in:
honfika@gmail.com
2015-05-16 15:15:27 +02:00
parent 3632c466e1
commit 7d2c0122f7
11 changed files with 494 additions and 264 deletions

View File

@@ -36,7 +36,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.flash.abc.types.traits.Traits;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.TagInfo;
import com.jpexs.decompiler.flash.tags.TagTypeInfo;
import com.jpexs.decompiler.flash.types.ALPHABITMAPDATA;
import com.jpexs.decompiler.flash.types.ALPHACOLORMAPDATA;
import com.jpexs.decompiler.flash.types.ARGB;
@@ -241,7 +241,7 @@ public class SwfXmlImporter {
private Object createObject(String type, SWF swf, Tag tag) throws NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (swfTags == null) {
Map<String, Class> tags = new HashMap<>();
Map<Integer, TagInfo> knownTags = Tag.getKnownClasses();
Map<Integer, TagTypeInfo> knownTags = Tag.getKnownClasses();
for (Integer key : knownTags.keySet()) {
Class cls = knownTags.get(key).getCls();
if (!ReflectionTools.canInstantiate(cls)) {

View File

@@ -19,6 +19,8 @@ package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.tags.base.BoundedTag;
import com.jpexs.decompiler.flash.tags.base.CharacterIdTag;
import com.jpexs.decompiler.flash.tags.base.Exportable;
import com.jpexs.decompiler.flash.tags.base.NeedsCharacters;
import com.jpexs.decompiler.flash.tags.gfx.DefineCompactedFont;
@@ -32,8 +34,10 @@ import com.jpexs.decompiler.flash.tags.gfx.DefineSubImage;
import com.jpexs.decompiler.flash.tags.gfx.ExporterInfo;
import com.jpexs.decompiler.flash.tags.gfx.FontTextureInfo;
import com.jpexs.decompiler.flash.timeline.Timelined;
import com.jpexs.decompiler.flash.types.RECT;
import com.jpexs.decompiler.flash.types.annotations.Internal;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.Helper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;
@@ -161,9 +165,9 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable {
private volatile static Integer[] knownTagIds;
private volatile static Map<Integer, TagInfo> knownTagInfosById;
private volatile static Map<Integer, TagTypeInfo> knownTagInfosById;
private volatile static Map<String, TagInfo> knownTagInfosByName;
private volatile static Map<String, TagTypeInfo> knownTagInfosByName;
private volatile static List<Integer> requiredTagIds;
@@ -180,12 +184,12 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable {
return knownTagIds;
}
public static Map<Integer, TagInfo> getKnownClasses() {
public static Map<Integer, TagTypeInfo> getKnownClasses() {
if (knownTagInfosById == null) {
synchronized (lockObject) {
if (knownTagInfosById == null) {
Map<Integer, TagInfo> map = new HashMap<>();
Map<String, TagInfo> map2 = new HashMap<>();
Map<Integer, TagTypeInfo> map = new HashMap<>();
Map<String, TagTypeInfo> map2 = new HashMap<>();
addTagInfo(map, map2, CSMTextSettingsTag.ID, CSMTextSettingsTag.class, CSMTextSettingsTag.NAME);
addTagInfo(map, map2, DebugIDTag.ID, DebugIDTag.class, DebugIDTag.NAME);
addTagInfo(map, map2, DefineBinaryDataTag.ID, DefineBinaryDataTag.class, DefineBinaryDataTag.NAME);
@@ -273,7 +277,7 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable {
return knownTagInfosById;
}
public static Map<String, TagInfo> getKnownClassesByName() {
public static Map<String, TagTypeInfo> getKnownClassesByName() {
// map is filled together with knownTagInfosById
if (knownTagInfosByName == null) {
getKnownClasses();
@@ -282,9 +286,9 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable {
return knownTagInfosByName;
}
private static void addTagInfo(Map<Integer, TagInfo> map, Map<String, TagInfo> map2, int id, Class cls, String name) {
map.put(id, new TagInfo(id, cls, name));
map2.put(name, new TagInfo(id, cls, name));
private static void addTagInfo(Map<Integer, TagTypeInfo> map, Map<String, TagTypeInfo> map2, int id, Class cls, String name) {
map.put(id, new TagTypeInfo(id, cls, name));
map2.put(name, new TagTypeInfo(id, cls, name));
}
public static List<Integer> getRequiredTags() {
@@ -561,4 +565,37 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable {
}
}
}
public void getTagInfo(TagInfo tagInfo) {
tagInfo.addInfo("general", "tagType", String.format("%s (%d)", tagName, id));
if (this instanceof CharacterIdTag) {
CharacterIdTag characterIdTag = (CharacterIdTag) this;
tagInfo.addInfo("general", "characterId", characterIdTag.getCharacterId());
}
if (originalRange != null) {
int pos = originalRange.getPos();
int length = originalRange.getLength();
tagInfo.addInfo("general", "offset", String.format("%d (0x%x)", pos, pos));
tagInfo.addInfo("general", "length", String.format("%d (0x%x)", length, length));
}
if (this instanceof BoundedTag) {
BoundedTag boundedIdTag = (BoundedTag) this;
RECT bounds = boundedIdTag.getRect();
tagInfo.addInfo("general", "bounds",
String.format("(%.2f, %.2f)[%.2f x %.2f]", bounds.Xmin / SWF.unitDivisor,
bounds.Ymin / SWF.unitDivisor,
bounds.getWidth() / SWF.unitDivisor,
bounds.getHeight() / SWF.unitDivisor));
}
Set<Integer> needed = new LinkedHashSet<>();
getNeededCharactersDeep(needed);
if (needed.size() > 0) {
tagInfo.addInfo("general", "neededCharacters", Helper.joinStrings(needed, ", "));
}
}
}

View File

@@ -16,33 +16,55 @@
*/
package com.jpexs.decompiler.flash.tags;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author JPEXS
*/
public class TagInfo {
private final int id;
private final Map<String, List<TagInfoItem>> infos = new LinkedHashMap<>();
private final Class cls;
public void addInfo(String categoryName, String name, Object value) {
categoryName = "general"; // temporary add everything to general catagory
List<TagInfoItem> category = infos.get(categoryName);
if (category == null) {
category = new ArrayList<>();
infos.put(categoryName, category);
}
private final String name;
public TagInfo(int id, Class cls, String name) {
this.id = id;
this.cls = cls;
this.name = name;
category.add(new TagInfoItem(name, value));
}
public int getId() {
return id;
public Map<String, List<TagInfoItem>> getInfos() {
return infos;
}
public Class getCls() {
return cls;
public boolean isEmpty() {
return infos.isEmpty();
}
public String getName() {
return name;
public class TagInfoItem {
private final String name;
private final Object value;
public TagInfoItem(String name, Object value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}
public Object getValue() {
return value;
}
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.tags;
/**
*
* @author JPEXS
*/
public class TagTypeInfo {
private final int id;
private final Class cls;
private final String name;
public TagTypeInfo(int id, Class cls, String name) {
this.id = id;
this.cls = cls;
this.name = name;
}
public int getId() {
return id;
}
public Class getCls() {
return cls;
}
public String getName() {
return name;
}
}

View File

@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
import com.jpexs.decompiler.flash.exporters.shape.BitmapExporter;
import com.jpexs.decompiler.flash.exporters.shape.CanvasShapeExporter;
import com.jpexs.decompiler.flash.exporters.shape.SVGShapeExporter;
import com.jpexs.decompiler.flash.tags.TagInfo;
import com.jpexs.decompiler.flash.tags.enums.ImageFormat;
import com.jpexs.decompiler.flash.types.BasicType;
import com.jpexs.decompiler.flash.types.ColorTransform;
@@ -264,6 +265,14 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
cachedImage = null;
}
@Override
public void getTagInfo(TagInfo tagInfo) {
super.getTagInfo(tagInfo);
SerializableImage image = getImage();
tagInfo.addInfo("general", "width", image.getWidth());
tagInfo.addInfo("general", "height", image.getHeight());
}
@Override
public int getCharacterId() {
return characterID;