mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-05 12:04:22 +00:00
#676: extended logging for text import, imorpt logic moved to separated class, allow to ignore errors duting import
This commit is contained in:
@@ -289,8 +289,8 @@ public class IdentifiersDeobfuscation {
|
||||
return "\u00A7" + escapeOIdentifier(s) + "\u00A7";
|
||||
}
|
||||
|
||||
private static final Cache<String, String> as3NameCache = Cache.getInstance(false,"as3_ident");
|
||||
private static final Cache<String, String> as2NameCache = Cache.getInstance(false,"as2_ident");
|
||||
private static final Cache<String, String> as3NameCache = Cache.getInstance(false, "as3_ident");
|
||||
private static final Cache<String, String> as2NameCache = Cache.getInstance(false, "as2_ident");
|
||||
|
||||
/**
|
||||
* Ensures identifier is valid and if not, uses paragraph syntax
|
||||
@@ -305,19 +305,18 @@ public class IdentifiersDeobfuscation {
|
||||
if (s.startsWith("\u00A7") && s.endsWith("\u00A7")) { //Assuming already printed - TODO:detect better
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
for (String e : validExceptions) {
|
||||
if (e.equals(s)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
Cache<String, String> nameCache = as3?as3NameCache:as2NameCache;
|
||||
|
||||
|
||||
}
|
||||
Cache<String, String> nameCache = as3 ? as3NameCache : as2NameCache;
|
||||
|
||||
if (nameCache.contains(s)) {
|
||||
return nameCache.get(s);
|
||||
}
|
||||
|
||||
|
||||
if (isValidName(as3, s, validExceptions)) {
|
||||
nameCache.put(s, s);
|
||||
return s;
|
||||
@@ -328,7 +327,7 @@ public class IdentifiersDeobfuscation {
|
||||
}
|
||||
|
||||
public static String printNamespace(boolean as3, String pkg, String... validNameExceptions) {
|
||||
Cache<String, String> nameCache = as3?as3NameCache:as2NameCache;
|
||||
Cache<String, String> nameCache = as3 ? as3NameCache : as2NameCache;
|
||||
if (nameCache.contains(pkg)) {
|
||||
return nameCache.get(pkg);
|
||||
}
|
||||
|
||||
@@ -278,9 +278,9 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
public DumpInfoSwfNode dumpInfo;
|
||||
public DefineBinaryDataTag binaryData;
|
||||
|
||||
private static Cache<String, SerializableImage> frameCache = Cache.getInstance(false,"frame");
|
||||
private final Cache<ASMSource, CachedScript> as2Cache = Cache.getInstance(true,"as2");
|
||||
private final Cache<ScriptPack, CachedDecompilation> as3Cache = Cache.getInstance(true,"as3");
|
||||
private static Cache<String, SerializableImage> frameCache = Cache.getInstance(false, "frame");
|
||||
private final Cache<ASMSource, CachedScript> as2Cache = Cache.getInstance(true, "as2");
|
||||
private final Cache<ScriptPack, CachedDecompilation> as3Cache = Cache.getInstance(true, "as3");
|
||||
|
||||
public void updateCharacters() {
|
||||
characters.clear();
|
||||
@@ -307,10 +307,10 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return jtt;
|
||||
}
|
||||
|
||||
|
||||
public void fixCharactersOrder(boolean checkAll) {
|
||||
Set<Integer> addedCharacterIds = new HashSet<>();
|
||||
Set<CharacterTag> movedTags = new HashSet<>();
|
||||
@@ -326,7 +326,7 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
if (neededCharacter == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (movedTags.contains(neededCharacter)) {
|
||||
logger.log(Level.SEVERE, "Fixing characters order failed, recursion detected.");
|
||||
return;
|
||||
@@ -648,13 +648,13 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
throw new IOException("Invalid SWF file. No known tag found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* preload shape tags
|
||||
for (Tag tag : tags) {
|
||||
if (tag instanceof ShapeTag) {
|
||||
((ShapeTag) tag).getShapes();
|
||||
}
|
||||
}*/
|
||||
for (Tag tag : tags) {
|
||||
if (tag instanceof ShapeTag) {
|
||||
((ShapeTag) tag).getShapes();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -2136,14 +2136,14 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
as2Cache.clear();
|
||||
as3Cache.clear();
|
||||
}
|
||||
|
||||
|
||||
public void clearAllCache() {
|
||||
clearImageCache();
|
||||
clearScriptCache();
|
||||
Cache.clearAll();
|
||||
System.gc();
|
||||
}
|
||||
|
||||
|
||||
public static void uncache(ASMSource src) {
|
||||
if (src != null) {
|
||||
src.getSwf().as2Cache.remove(src);
|
||||
@@ -2169,7 +2169,7 @@ public final class SWF implements SWFContainerItem, Timelined {
|
||||
if (swf.as2Cache.contains(src)) {
|
||||
return swf.as2Cache.get(src);
|
||||
}
|
||||
|
||||
|
||||
if (actions == null) {
|
||||
actions = src.getActions();
|
||||
}
|
||||
|
||||
@@ -2978,7 +2978,7 @@ public final class Flasm3Lexer {
|
||||
zzInput = zzBufferL[zzCurrentPosL++];
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
if (zzNext == -1) {
|
||||
break zzForAction;
|
||||
}
|
||||
|
||||
@@ -1308,7 +1308,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
if (type instanceof UnboundedTypeItem) {
|
||||
return 0;
|
||||
}
|
||||
if((""+type).equals("*")){
|
||||
if (("" + type).equals("*")) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1487,7 +1487,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
int slotScope = subMethod? 0 : 1;
|
||||
int slotScope = subMethod ? 0 : 1;
|
||||
|
||||
for (AssignableAVM2Item an : subvariables) {
|
||||
if (an instanceof NameAVM2Item) {
|
||||
@@ -1777,7 +1777,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
isNs = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((type instanceof TypeItem) && (((TypeItem) type).fullTypeName.equals("Namespace"))) {
|
||||
isNs = true;
|
||||
}
|
||||
@@ -1840,7 +1840,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
|
||||
if (t instanceof TraitSlotConst) {
|
||||
if (((TraitSlotConst) t).isNamespace()) {
|
||||
Namespace ns = a.constants.getNamespace(((TraitSlotConst) t).value_index);
|
||||
return abc.constants.getNamespaceId(new Namespace(ns.kind, abc.constants.getStringId(ns.getName(a.constants, true),true)), 0, true);
|
||||
return abc.constants.getNamespaceId(new Namespace(ns.kind, abc.constants.getStringId(ns.getName(a.constants, true), true)), 0, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1357,7 +1357,7 @@ public final class ActionScriptLexer {
|
||||
zzCurrentPosL += Character.charCount(zzInput);
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
if (zzNext == -1) {
|
||||
break zzForAction;
|
||||
}
|
||||
|
||||
@@ -587,9 +587,9 @@ public class ActionScriptParser {
|
||||
throw new AVM2ParseException("Only one static keyword allowed", lexer.yyline());
|
||||
}
|
||||
isStatic = true;
|
||||
} else if(s.type == SymbolType.NAMESPACE) {
|
||||
} else if (s.type == SymbolType.NAMESPACE) {
|
||||
break;
|
||||
} else if(s.type == SymbolType.NATIVE) {
|
||||
} else if (s.type == SymbolType.NATIVE) {
|
||||
throw new AVM2ParseException("Cannot compile native code", lexer.yyline());
|
||||
} else if (s.group == SymbolGroup.IDENTIFIER) {
|
||||
customAccess = s.value.toString();
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library.
|
||||
* License along with this library.
|
||||
*/
|
||||
package com.jpexs.decompiler.flash.abc.avm2.parser.script;
|
||||
|
||||
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
|
||||
@@ -237,9 +238,9 @@ public class NameAVM2Item extends AssignableAVM2Item {
|
||||
return toSourceMerge(localData, generator,
|
||||
ins(new GetScopeObjectIns(), slotScope),
|
||||
assignedValue, !(("" + assignedValue.returnType()).equals("" + type) && (basicTypes.contains("" + type))) ? generateCoerce(localData, generator, type) : null, needsReturn
|
||||
assignedValue, !(("" + assignedValue.returnType()).equals("" + type) && (basicTypes.contains("" + type))) ? generateCoerce(localData, generator, type) : null, needsReturn
|
||||
? dupSetTemp(localData, generator, ret_temp) : null, generateSetLoc(regNumber), slotNumber > -1
|
||||
? ins(new SetSlotIns(), slotNumber)
|
||||
? dupSetTemp(localData, generator, ret_temp) : null, generateSetLoc(regNumber), slotNumber > -1
|
||||
? ins(new SetSlotIns(), slotNumber)
|
||||
: null,
|
||||
needsReturn ? getTemp(localData, generator, ret_temp) : null,
|
||||
killTemp(localData, generator, Arrays.asList(ret_temp)));
|
||||
} else {
|
||||
|
||||
@@ -258,7 +258,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
|
||||
for (int i = 0; i < openedNamespaces.size(); i++) {
|
||||
int nsindex = openedNamespaces.get(i);
|
||||
int nsKind = abc.constants.constant_namespace.get(openedNamespaces.get(i)).kind;
|
||||
String nsname = abc.constants.constant_namespace.get(openedNamespaces.get(i)).getName(abc.constants, true);
|
||||
String nsname = abc.constants.constant_namespace.get(openedNamespaces.get(i)).getName(abc.constants, true);
|
||||
int name_index = 0;
|
||||
for (int m = 1; m < abc.constants.constant_multiname.size(); m++) {
|
||||
Multiname mname = abc.constants.constant_multiname.get(m);
|
||||
|
||||
@@ -326,7 +326,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
|
||||
impName = impName.substring(impName.lastIndexOf('.') + 1);
|
||||
}
|
||||
if (impName.equals(parts.get(0))) {
|
||||
TypeItem ret = new TypeItem(imp);
|
||||
TypeItem ret = new TypeItem(imp);
|
||||
resolved = ret;
|
||||
for (int i = 1; i < parts.size(); i++) {
|
||||
resolved = new PropertyAVM2Item(resolved, parts.get(i), abc, otherAbcs, openedNamespaces, new ArrayList<MethodBody>());
|
||||
|
||||
@@ -866,7 +866,7 @@ public final class MethodInfoLexer {
|
||||
zzInput = zzBufferL[zzCurrentPosL++];
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
if (zzNext == -1) {
|
||||
break zzForAction;
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ public class MethodInfo {
|
||||
} else {
|
||||
restName = "rest";
|
||||
}
|
||||
|
||||
|
||||
HighlightData pdata = new HighlightData();
|
||||
pdata.declaration = true;
|
||||
pdata.declaredType = "*";
|
||||
|
||||
@@ -867,7 +867,7 @@ public final class FlasmLexer {
|
||||
zzInput = zzBufferL[zzCurrentPosL++];
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
if (zzNext == -1) {
|
||||
break zzForAction;
|
||||
}
|
||||
|
||||
@@ -1546,7 +1546,7 @@ public final class ActionScriptLexer {
|
||||
zzInput = zzBufferL[zzCurrentPosL++];
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
if (zzNext == -1) {
|
||||
break zzForAction;
|
||||
}
|
||||
|
||||
@@ -61,31 +61,29 @@ public class ImageExporter {
|
||||
if (settings.mode == ImageExportMode.JPEG) {
|
||||
fileFormat = "jpg";
|
||||
}
|
||||
|
||||
|
||||
if (settings.mode == ImageExportMode.BMP) {
|
||||
fileFormat = "bmp";
|
||||
}
|
||||
{
|
||||
|
||||
final ImageTag imageTag = (ImageTag) t;
|
||||
final File file = new File(outdir + File.separator + Helper.makeFileName(imageTag.getCharacterExportFileName() + "." + fileFormat));
|
||||
final List<Tag> ttags = tags;
|
||||
final String ffileFormat = fileFormat;
|
||||
|
||||
|
||||
new RetryTask(new RunnableIOEx() {
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
if(ffileFormat.equals("bmp")){
|
||||
BMPFile.saveBitmap(imageTag.getImage().getBufferedImage(), file);
|
||||
}else{
|
||||
ImageIO.write(imageTag.getImage().getBufferedImage(), ffileFormat.toUpperCase(Locale.ENGLISH), file);
|
||||
final ImageTag imageTag = (ImageTag) t;
|
||||
final File file = new File(outdir + File.separator + Helper.makeFileName(imageTag.getCharacterExportFileName() + "." + fileFormat));
|
||||
final String ffileFormat = fileFormat;
|
||||
|
||||
new RetryTask(new RunnableIOEx() {
|
||||
@Override
|
||||
public void run() throws IOException {
|
||||
if (ffileFormat.equals("bmp")) {
|
||||
BMPFile.saveBitmap(imageTag.getImage().getBufferedImage(), file);
|
||||
} else {
|
||||
ImageIO.write(imageTag.getImage().getBufferedImage(), ffileFormat.toUpperCase(Locale.ENGLISH), file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, handler).run();
|
||||
ret.add(file);
|
||||
}, handler).run();
|
||||
ret.add(file);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
@@ -113,9 +113,9 @@ public class ShapeExporter {
|
||||
m.translate(-rect.Xmin, -rect.Ymin);
|
||||
m.scale(settings.zoom);
|
||||
st.toImage(0, 0, 0, null, 0, img, m, new CXFORMWITHALPHA());
|
||||
if(settings.mode==ShapeExportMode.PNG){
|
||||
if (settings.mode == ShapeExportMode.PNG) {
|
||||
ImageIO.write(img.getBufferedImage(), "PNG", new FileOutputStream(file));
|
||||
}else{
|
||||
} else {
|
||||
BMPFile.saveBitmap(img.getBufferedImage(), file);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -288,16 +288,16 @@ public final class Matrix implements Cloneable {
|
||||
public double getTotalScaleY() {
|
||||
return Math.sqrt(rotateSkew1 * rotateSkew1 + scaleY * scaleY);
|
||||
}
|
||||
|
||||
private int fromFloat(double f){
|
||||
return (int)(f * (1 << 16));
|
||||
|
||||
private int fromFloat(double f) {
|
||||
return (int) (f * (1 << 16));
|
||||
}
|
||||
|
||||
public MATRIX toMATRIX(){
|
||||
|
||||
public MATRIX toMATRIX() {
|
||||
MATRIX result = new MATRIX();
|
||||
|
||||
result.translateX = (int)translateX;
|
||||
result.translateY = (int)translateY;
|
||||
|
||||
result.translateX = (int) translateX;
|
||||
result.translateY = (int) translateY;
|
||||
result.hasRotate = true;
|
||||
result.hasScale = true;
|
||||
result.scaleX = fromFloat(scaleX);
|
||||
|
||||
@@ -297,7 +297,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
}
|
||||
fillStyleIdx = e.getFillStyleIdx();
|
||||
pos = PointInt.MAX;
|
||||
try {
|
||||
if (fillStyleIdx - 1 < _fillStyles.size()) {
|
||||
Matrix matrix;
|
||||
Matrix matrixEnd;
|
||||
FILLSTYLE fillStyle = _fillStyles.get(fillStyleIdx - 1);
|
||||
@@ -342,7 +342,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter {
|
||||
);
|
||||
break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} else {
|
||||
// Font shapes define no fillstyles per se, but do reference fillstyle index 1,
|
||||
// which represents the font color. We just report null in this case.
|
||||
beginFill(null, null);
|
||||
|
||||
@@ -236,7 +236,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
}
|
||||
fillStyleIdx = e.getFillStyleIdx();
|
||||
pos = PointInt.MAX;
|
||||
try {
|
||||
if (fillStyleIdx - 1 < _fillStyles.size()) {
|
||||
Matrix matrix;
|
||||
FILLSTYLE fillStyle = _fillStyles.get(fillStyleIdx - 1);
|
||||
switch (fillStyle.fillStyleType) {
|
||||
@@ -273,7 +273,7 @@ public abstract class ShapeExporterBase implements IShapeExporter {
|
||||
);
|
||||
break;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} else {
|
||||
// Font shapes define no fillstyles per se, but do reference fillstyle index 1,
|
||||
// which represents the font color. We just report null in this case.
|
||||
beginFill(null);
|
||||
|
||||
@@ -65,12 +65,12 @@ public class BMPFile extends Component {
|
||||
public static void saveBitmap(Image image, File file) throws IOException {
|
||||
BMPFile b = new BMPFile();
|
||||
b.fo = new FileOutputStream(file);
|
||||
try{
|
||||
try {
|
||||
b.save(image, image.getWidth(null), image.getHeight(null));
|
||||
}finally{
|
||||
try{
|
||||
} finally {
|
||||
try {
|
||||
b.fo.close();
|
||||
}catch(Exception ex){
|
||||
} catch (Exception ex) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.io.Serializable;
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class HighlightData implements Cloneable, Serializable {
|
||||
|
||||
|
||||
public boolean declaration;
|
||||
|
||||
public String declaredType;
|
||||
@@ -37,13 +37,13 @@ public class HighlightData implements Cloneable, Serializable {
|
||||
public long index;
|
||||
|
||||
public long offset;
|
||||
|
||||
|
||||
public boolean isEmpty() {
|
||||
return !declaration && declaredType == null && localName == null &&
|
||||
subtype == null && specialValue == null &&
|
||||
index == 0 && offset == 0;
|
||||
return !declaration && declaredType == null && localName == null
|
||||
&& subtype == null && specialValue == null
|
||||
&& index == 0 && offset == 0;
|
||||
}
|
||||
|
||||
|
||||
public void merge(HighlightData data) {
|
||||
if (data.declaration) {
|
||||
declaration = data.declaration;
|
||||
|
||||
@@ -21,8 +21,8 @@ package com.jpexs.decompiler.flash.helpers.hilight;
|
||||
* @author JPEXS
|
||||
*/
|
||||
public enum HighlightSpecialType {
|
||||
|
||||
PARAM_NAME, PARAM, OPTIONAL, RETURNS,
|
||||
|
||||
PARAM_NAME, PARAM, OPTIONAL, RETURNS,
|
||||
TYPE_NAME, CLASS_NAME, METHOD_NAME,
|
||||
TRAIT_TYPE, TRAIT_NAME, TRAIT_TYPE_NAME, TRAIT_VALUE,
|
||||
SLOT_ID, DISP_ID,
|
||||
|
||||
@@ -112,7 +112,7 @@ public class Highlighting implements Serializable {
|
||||
public static Highlighting searchOffset(List<Highlighting> list, long offset) {
|
||||
return searchOffset(list, offset, -1, -1);
|
||||
}
|
||||
|
||||
|
||||
public static Highlighting searchOffset(List<Highlighting> list, long offset, long from, long to) {
|
||||
looph:
|
||||
for (Highlighting h : list) {
|
||||
@@ -139,7 +139,7 @@ public class Highlighting implements Serializable {
|
||||
public static Highlighting searchIndex(List<Highlighting> list, long index) {
|
||||
return searchIndex(list, index, -1, -1);
|
||||
}
|
||||
|
||||
|
||||
public static Highlighting searchIndex(List<Highlighting> list, long index, long from, long to) {
|
||||
looph:
|
||||
for (Highlighting h : list) {
|
||||
|
||||
@@ -38,27 +38,27 @@ import javax.imageio.ImageIO;
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class ShapeImporter {
|
||||
|
||||
|
||||
public Tag importImage(ShapeTag st, byte[] newData) throws IOException {
|
||||
SWF swf = st.getSwf();
|
||||
|
||||
if(newData[0] == 'B' && newData[1] == 'M'){
|
||||
|
||||
if (newData[0] == 'B' && newData[1] == 'M') {
|
||||
BufferedImage b = ImageIO.read(new ByteArrayInputStream(newData));
|
||||
ByteArrayOutputStream baos=new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(b, "PNG", baos);
|
||||
newData = baos.toByteArray();
|
||||
}
|
||||
|
||||
|
||||
DefineBitsJPEG2Tag jpeg2Tag = new DefineBitsJPEG2Tag(swf, null, swf.getNextCharacterId(), newData);
|
||||
jpeg2Tag.setModified(true);
|
||||
swf.tags.add(jpeg2Tag);
|
||||
swf.updateCharacters();
|
||||
st.setModified(true);
|
||||
SHAPEWITHSTYLE shapes = jpeg2Tag.getShape(st.getRect(new HashSet<BoundedTag>()), true);
|
||||
|
||||
|
||||
if (st instanceof DefineShapeTag) {
|
||||
DefineShapeTag dst = (DefineShapeTag) st;
|
||||
dst.shapes = shapes;
|
||||
dst.shapes = shapes;
|
||||
} else if (st instanceof DefineShape2Tag) {
|
||||
DefineShape2Tag dst = (DefineShape2Tag) st;
|
||||
dst.shapes = shapes;
|
||||
@@ -69,7 +69,7 @@ public class ShapeImporter {
|
||||
DefineShape4Tag dst = (DefineShape4Tag) st;
|
||||
dst.shapes = shapes;
|
||||
}
|
||||
|
||||
|
||||
return (Tag) st;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.importers;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.exporters.TextExporter;
|
||||
import com.jpexs.decompiler.flash.tags.Tag;
|
||||
import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler;
|
||||
import com.jpexs.decompiler.flash.tags.base.TextImportErrorHandler;
|
||||
import com.jpexs.decompiler.flash.tags.base.TextTag;
|
||||
import com.jpexs.decompiler.flash.tags.text.TextParseException;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.Path;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class TextImporter {
|
||||
|
||||
private final MissingCharacterHandler missingCharacterHandler;
|
||||
private final TextImportErrorHandler errorHandler;
|
||||
|
||||
public TextImporter(MissingCharacterHandler missingCharacterHandler, TextImportErrorHandler errorHandler) {
|
||||
this.missingCharacterHandler = missingCharacterHandler;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
private Map<Integer, String[]> splitTextRecords(String texts) {
|
||||
String[] textsArr = texts.split(Helper.newLine + Configuration.textExportSingleFileSeparator.get() + Helper.newLine);
|
||||
String recordSeparator = Helper.newLine + Configuration.textExportSingleFileRecordSeparator.get() + Helper.newLine;
|
||||
Map<Integer, String[]> result = new HashMap<>();
|
||||
for (String text : textsArr) {
|
||||
String[] textArr = text.split(Helper.newLine, 2);
|
||||
String idLine = textArr[0];
|
||||
if (idLine.startsWith("ID:")) {
|
||||
int id = Integer.parseInt(idLine.substring(3).trim());
|
||||
String[] records = textArr[1].split(recordSeparator);
|
||||
result.put(id, records);
|
||||
} else {
|
||||
if (errorHandler.handle()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void importTextsSingleFile(File textsFile, SWF swf) {
|
||||
String texts = Helper.readTextFile(textsFile.getPath());
|
||||
Map<Integer, String[]> records = splitTextRecords(texts);
|
||||
if (records != null) {
|
||||
for (int characterId : records.keySet()) {
|
||||
for (Tag tag : swf.tags) {
|
||||
if (tag instanceof TextTag) {
|
||||
TextTag textTag = (TextTag) tag;
|
||||
if (textTag.getCharacterId() == characterId) {
|
||||
String[] currentRecords = records.get(characterId);
|
||||
String text = textTag.getFormattedText();
|
||||
if (!saveText(textTag, text, currentRecords)) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void importTextsSingleFileFormatted(File textsFile, SWF swf) {
|
||||
String texts = Helper.readTextFile(textsFile.getPath());
|
||||
Map<Integer, String[]> records = splitTextRecords(texts);
|
||||
if (records != null) {
|
||||
for (int characterId : records.keySet()) {
|
||||
for (Tag tag : swf.tags) {
|
||||
if (tag instanceof TextTag) {
|
||||
TextTag textTag = (TextTag) tag;
|
||||
if (textTag.getCharacterId() == characterId) {
|
||||
String[] currentRecords = records.get(characterId);
|
||||
if (!saveText(textTag, currentRecords[0], null)) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void importTextsMultipleFiles(String folder, SWF swf) {
|
||||
File textsFolder = new File(Path.combine(folder, TextExporter.TEXT_EXPORT_FOLDER));
|
||||
String[] files = textsFolder.list(new FilenameFilter() {
|
||||
|
||||
private final Pattern pat = Pattern.compile("\\d+\\.txt", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
|
||||
return pat.matcher(name).matches();
|
||||
}
|
||||
});
|
||||
|
||||
if (files == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String fileName : files) {
|
||||
String texts = Helper.readTextFile(Path.combine(textsFolder.getPath(), fileName));
|
||||
int characterId = Integer.parseInt(fileName.split("\\.")[0]);
|
||||
String recordSeparator = Helper.newLine + Configuration.textExportSingleFileRecordSeparator.get() + Helper.newLine;
|
||||
boolean formatted = !texts.contains(recordSeparator) && texts.startsWith("[" + Helper.newLine);
|
||||
if (!formatted) {
|
||||
String[] records = texts.split(recordSeparator);
|
||||
for (Tag tag : swf.tags) {
|
||||
if (tag instanceof TextTag) {
|
||||
TextTag textTag = (TextTag) tag;
|
||||
if (textTag.getCharacterId() == characterId) {
|
||||
String text = textTag.getFormattedText();
|
||||
if (!saveText(textTag, text, records)) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (Tag tag : swf.tags) {
|
||||
if (tag instanceof TextTag) {
|
||||
TextTag textTag = (TextTag) tag;
|
||||
if (textTag.getCharacterId() == characterId) {
|
||||
if (!saveText(textTag, texts, null)) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the new text to the text tag
|
||||
*
|
||||
* @param textTag
|
||||
* @param formattedText
|
||||
* @param texts
|
||||
* @return If false the processing should be interrupted
|
||||
*/
|
||||
public boolean saveText(TextTag textTag, String formattedText, String[] texts) {
|
||||
try {
|
||||
if (textTag.setFormattedText(missingCharacterHandler, formattedText, texts)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !errorHandler.handle();
|
||||
} catch (TextParseException ex) {
|
||||
return !errorHandler.handle(ex.text, ex.line);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag {
|
||||
public byte[] bitmapAlphaData;
|
||||
|
||||
public static final int ID = 35;
|
||||
|
||||
|
||||
@Override
|
||||
public int getCharacterId() {
|
||||
return characterID;
|
||||
|
||||
@@ -207,7 +207,7 @@ public class DefineButton2Tag extends ButtonTag implements Container {
|
||||
return modified;
|
||||
}
|
||||
|
||||
private static final Cache<DefineButton2Tag, RECT> rectCache = Cache.getInstance(true,"rect_button2");
|
||||
private static final Cache<DefineButton2Tag, RECT> rectCache = Cache.getInstance(true, "rect_button2");
|
||||
|
||||
@Override
|
||||
public RECT getRect(Set<BoundedTag> added) {
|
||||
|
||||
@@ -245,7 +245,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource {
|
||||
return modified;
|
||||
}
|
||||
|
||||
private static final Cache<DefineButtonTag, RECT> rectCache = Cache.getInstance(true,"rect_button");
|
||||
private static final Cache<DefineButtonTag, RECT> rectCache = Cache.getInstance(true, "rect_button");
|
||||
|
||||
@Override
|
||||
public RECT getRect(Set<BoundedTag> added) {
|
||||
|
||||
@@ -406,28 +406,28 @@ public class DefineEditTextTag extends TextTag {
|
||||
try {
|
||||
bounds.Xmin = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid xmin value. Number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid xmin value. Number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "ymin":
|
||||
try {
|
||||
bounds.Ymin = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid ymin value. Number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid ymin value. Number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "xmax":
|
||||
try {
|
||||
bounds.Xmax = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid xmax value. Number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid xmax value. Number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "ymax":
|
||||
try {
|
||||
bounds.Ymax = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid ymax value. Number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid ymax value. Number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "wordwrap":
|
||||
@@ -484,7 +484,7 @@ public class DefineEditTextTag extends TextTag {
|
||||
try {
|
||||
fontId = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException ne) {
|
||||
throw new TextParseException("Invalid font value. Number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid font value. Number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "fontclass":
|
||||
@@ -494,7 +494,7 @@ public class DefineEditTextTag extends TextTag {
|
||||
try {
|
||||
fontHeight = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException ne) {
|
||||
throw new TextParseException("Invalid height value. Number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid height value. Number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "color":
|
||||
@@ -502,14 +502,14 @@ public class DefineEditTextTag extends TextTag {
|
||||
if (m.matches()) {
|
||||
textColor = new RGBA(Integer.parseInt(m.group(2), 16), Integer.parseInt(m.group(3), 16), Integer.parseInt(m.group(4), 16), Integer.parseInt(m.group(1), 16));
|
||||
} else {
|
||||
throw new TextParseException("Invalid color. Valid format is #aarrggbb.", lexer.yyline());
|
||||
throw new TextParseException("Invalid color. Valid format is #aarrggbb. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "maxlength":
|
||||
try {
|
||||
maxLength = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException ne) {
|
||||
throw new TextParseException("Invalid maxLength value. Number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid maxLength value. Number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "align":
|
||||
@@ -527,42 +527,42 @@ public class DefineEditTextTag extends TextTag {
|
||||
align = 3;
|
||||
break;
|
||||
default:
|
||||
throw new TextParseException("Invalid align value. Expected one of: left,right,center or justify.", lexer.yyline());
|
||||
throw new TextParseException("Invalid align value. Expected one of: left,right,center or justify. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "leftmargin":
|
||||
try {
|
||||
leftMargin = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException ne) {
|
||||
throw new TextParseException("Invalid leftmargin value. Number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid leftmargin value. Number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "rightmargin":
|
||||
try {
|
||||
rightMargin = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException ne) {
|
||||
throw new TextParseException("Invalid rightmargin value. Number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid rightmargin value. Number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "indent":
|
||||
try {
|
||||
indent = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException ne) {
|
||||
throw new TextParseException("Invalid indent value. Number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid indent value. Number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "leading":
|
||||
try {
|
||||
leading = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException ne) {
|
||||
throw new TextParseException("Invalid leading value. Number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid leading value. Number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "variablename":
|
||||
variableName = paramValue;
|
||||
break;
|
||||
default:
|
||||
throw new TextParseException("Unrecognized parameter name", lexer.yyline());
|
||||
throw new TextParseException("Unrecognized parameter name: " + paramName, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case TEXT:
|
||||
@@ -571,6 +571,7 @@ public class DefineEditTextTag extends TextTag {
|
||||
}
|
||||
}
|
||||
|
||||
setModified(true);
|
||||
this.bounds = bounds;
|
||||
if (formattedText.length() > 0) {
|
||||
initialText = formattedText;
|
||||
@@ -625,8 +626,8 @@ public class DefineEditTextTag extends TextTag {
|
||||
Logger.getLogger(DefineEditTextTag.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -122,7 +122,7 @@ public class DefineSpriteTag extends CharacterTag implements Container, Drawable
|
||||
return ret;
|
||||
}
|
||||
|
||||
private static final Cache<DefineSpriteTag, RECT> rectCache = Cache.getInstance(true,"rect_sprite");
|
||||
private static final Cache<DefineSpriteTag, RECT> rectCache = Cache.getInstance(true, "rect_sprite");
|
||||
|
||||
@Override
|
||||
public RECT getRect(Set<BoundedTag> added) {
|
||||
|
||||
@@ -179,7 +179,6 @@ public class DefineText2Tag extends TextTag {
|
||||
|
||||
@Override
|
||||
public boolean setFormattedText(MissingCharacterHandler missingCharHandler, String formattedText, String[] texts) throws TextParseException {
|
||||
List<TEXTRECORD> oldTextRecords = textRecords;
|
||||
try {
|
||||
TextLexer lexer = new TextLexer(new StringReader(formattedText));
|
||||
ParsedSymbol s = null;
|
||||
@@ -205,15 +204,15 @@ public class DefineText2Tag extends TextTag {
|
||||
case PARAMETER:
|
||||
String paramName = (String) s.values[0];
|
||||
String paramValue = (String) s.values[1];
|
||||
if (paramName.equals("color")) {
|
||||
Matcher m = Pattern.compile("#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])").matcher(paramValue);
|
||||
if (m.matches()) {
|
||||
colorA = new RGBA(Integer.parseInt(m.group(2), 16), Integer.parseInt(m.group(3), 16), Integer.parseInt(m.group(4), 16), Integer.parseInt(m.group(1), 16));
|
||||
} else {
|
||||
throw new TextParseException("Invalid color. Valid format is #aarrggbb.", lexer.yyline());
|
||||
}
|
||||
}
|
||||
switch (paramName) {
|
||||
case "color":
|
||||
Matcher m = Pattern.compile("#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])").matcher(paramValue);
|
||||
if (m.matches()) {
|
||||
colorA = new RGBA(Integer.parseInt(m.group(2), 16), Integer.parseInt(m.group(3), 16), Integer.parseInt(m.group(4), 16), Integer.parseInt(m.group(1), 16));
|
||||
} else {
|
||||
throw new TextParseException("Invalid color. Valid format is #aarrggbb. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "font":
|
||||
try {
|
||||
fontId = Integer.parseInt(paramValue);
|
||||
@@ -231,14 +230,14 @@ public class DefineText2Tag extends TextTag {
|
||||
throw new TextParseException("Font not found", lexer.yyline());
|
||||
}
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid font id - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid font id - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "height":
|
||||
try {
|
||||
textHeight = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid font height - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid font height - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "x":
|
||||
@@ -246,7 +245,7 @@ public class DefineText2Tag extends TextTag {
|
||||
x = Integer.parseInt(paramValue);
|
||||
currentX = x;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid x position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid x position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "y":
|
||||
@@ -254,35 +253,35 @@ public class DefineText2Tag extends TextTag {
|
||||
y = Integer.parseInt(paramValue);
|
||||
currentY = y;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid y position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid y position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "xmin":
|
||||
try {
|
||||
textBounds.Xmin = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid xmin position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid xmin position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "xmax":
|
||||
try {
|
||||
textBounds.Xmax = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid xmax position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid xmax position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "ymin":
|
||||
try {
|
||||
textBounds.Ymin = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid ymin position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid ymin position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "ymax":
|
||||
try {
|
||||
textBounds.Ymax = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid ymax position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid ymax position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "scalex":
|
||||
@@ -290,7 +289,7 @@ public class DefineText2Tag extends TextTag {
|
||||
textMatrix.scaleX = Integer.parseInt(paramValue);
|
||||
textMatrix.hasScale = true;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid scalex value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid scalex value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "scaley":
|
||||
@@ -298,7 +297,7 @@ public class DefineText2Tag extends TextTag {
|
||||
textMatrix.scaleY = Integer.parseInt(paramValue);
|
||||
textMatrix.hasScale = true;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid scalex value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid scalex value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "rotateskew0":
|
||||
@@ -306,7 +305,7 @@ public class DefineText2Tag extends TextTag {
|
||||
textMatrix.rotateSkew0 = Integer.parseInt(paramValue);
|
||||
textMatrix.hasRotate = true;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid rotateskew0 value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid rotateskew0 value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "rotateskew1":
|
||||
@@ -314,23 +313,25 @@ public class DefineText2Tag extends TextTag {
|
||||
textMatrix.rotateSkew1 = Integer.parseInt(paramValue);
|
||||
textMatrix.hasRotate = true;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid rotateskew1 value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid rotateskew1 value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "translatex":
|
||||
try {
|
||||
textMatrix.translateX = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid translatex value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid translatex value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "translatey":
|
||||
try {
|
||||
textMatrix.translateY = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid translatey value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid translatey value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new TextParseException("Unrecognized parameter name: " + paramName, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case TEXT:
|
||||
@@ -411,17 +412,16 @@ public class DefineText2Tag extends TextTag {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setModified(true);
|
||||
this.textRecords = textRecords;
|
||||
this.textBounds = textBounds;
|
||||
//this.textBounds.Xmin = minX;
|
||||
//this.textBounds.Xmax = maxX;
|
||||
} catch (IOException ex) {
|
||||
textRecords = oldTextRecords;
|
||||
return false;
|
||||
} catch (TextParseException ex) {
|
||||
textRecords = oldTextRecords;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -185,11 +185,10 @@ public class DefineTextTag extends TextTag {
|
||||
|
||||
@Override
|
||||
public boolean setFormattedText(MissingCharacterHandler missingCharHandler, String formattedText, String[] texts) throws TextParseException {
|
||||
List<TEXTRECORD> oldTextRecords = textRecords;
|
||||
try {
|
||||
TextLexer lexer = new TextLexer(new StringReader(formattedText));
|
||||
ParsedSymbol s = null;
|
||||
textRecords = new ArrayList<>();
|
||||
List<TEXTRECORD> textRecords = new ArrayList<>();
|
||||
RGB color = null;
|
||||
int fontId = -1;
|
||||
int textHeight = -1;
|
||||
@@ -217,7 +216,7 @@ public class DefineTextTag extends TextTag {
|
||||
if (m.matches()) {
|
||||
color = new RGB(Integer.parseInt(m.group(1), 16), Integer.parseInt(m.group(2), 16), Integer.parseInt(m.group(3), 16));
|
||||
} else {
|
||||
throw new TextParseException("Invalid color. Valid format is #rrggbb.", lexer.yyline());
|
||||
throw new TextParseException("Invalid color. Valid format is #rrggbb. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "font":
|
||||
@@ -237,14 +236,14 @@ public class DefineTextTag extends TextTag {
|
||||
throw new TextParseException("Font not found", lexer.yyline());
|
||||
}
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid font id - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid font id - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "height":
|
||||
try {
|
||||
textHeight = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid font height - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid font height - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "x":
|
||||
@@ -252,7 +251,7 @@ public class DefineTextTag extends TextTag {
|
||||
x = Integer.parseInt(paramValue);
|
||||
currentX = x;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid x position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid x position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "y":
|
||||
@@ -260,35 +259,35 @@ public class DefineTextTag extends TextTag {
|
||||
y = Integer.parseInt(paramValue);
|
||||
currentY = y;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid y position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid y position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "xmin":
|
||||
try {
|
||||
textBounds.Xmin = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid xmin position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid xmin position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "xmax":
|
||||
try {
|
||||
textBounds.Xmax = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid xmax position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid xmax position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "ymin":
|
||||
try {
|
||||
textBounds.Ymin = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid ymin position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid ymin position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "ymax":
|
||||
try {
|
||||
textBounds.Ymax = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid ymax position - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid ymax position - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "scalex":
|
||||
@@ -296,7 +295,7 @@ public class DefineTextTag extends TextTag {
|
||||
textMatrix.scaleX = Integer.parseInt(paramValue);
|
||||
textMatrix.hasScale = true;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid scalex value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid scalex value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "scaley":
|
||||
@@ -304,7 +303,7 @@ public class DefineTextTag extends TextTag {
|
||||
textMatrix.scaleY = Integer.parseInt(paramValue);
|
||||
textMatrix.hasScale = true;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid scalex value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid scalex value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "rotateskew0":
|
||||
@@ -312,7 +311,7 @@ public class DefineTextTag extends TextTag {
|
||||
textMatrix.rotateSkew0 = Integer.parseInt(paramValue);
|
||||
textMatrix.hasRotate = true;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid rotateskew0 value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid rotateskew0 value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "rotateskew1":
|
||||
@@ -320,23 +319,25 @@ public class DefineTextTag extends TextTag {
|
||||
textMatrix.rotateSkew1 = Integer.parseInt(paramValue);
|
||||
textMatrix.hasRotate = true;
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid rotateskew1 value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid rotateskew1 value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "translatex":
|
||||
try {
|
||||
textMatrix.translateX = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid translatex value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid translatex value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case "translatey":
|
||||
try {
|
||||
textMatrix.translateY = Integer.parseInt(paramValue);
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new TextParseException("Invalid translatey value - number expected.", lexer.yyline());
|
||||
throw new TextParseException("Invalid translatey value - number expected. Found: " + paramValue, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new TextParseException("Unrecognized parameter name: " + paramName, lexer.yyline());
|
||||
}
|
||||
break;
|
||||
case TEXT:
|
||||
@@ -418,17 +419,17 @@ public class DefineTextTag extends TextTag {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setModified(true);
|
||||
this.textRecords = textRecords;
|
||||
this.textMatrix = textMatrix;
|
||||
this.textBounds = textBounds;
|
||||
//this.textBounds.Xmin = minX;
|
||||
//this.textBounds.Xmax = maxX;
|
||||
} catch (IOException ex) {
|
||||
textRecords = oldTextRecords;
|
||||
return false;
|
||||
} catch (TextParseException ex) {
|
||||
textRecords = oldTextRecords;
|
||||
throw ex;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -409,12 +409,12 @@ public class PlaceObject2Tag extends CharacterIdTag implements Container, PlaceO
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeTagWithMatrix(SWFOutputStream sos, MATRIX m) throws IOException {
|
||||
MATRIX old=matrix;
|
||||
MATRIX old = matrix;
|
||||
matrix = m;
|
||||
boolean mod=isModified();
|
||||
boolean mod = isModified();
|
||||
setModified(true);
|
||||
super.writeTag(sos);
|
||||
setModified(mod);
|
||||
|
||||
@@ -538,12 +538,12 @@ public class PlaceObject3Tag extends CharacterIdTag implements Container, PlaceO
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeTagWithMatrix(SWFOutputStream sos, MATRIX m) throws IOException {
|
||||
MATRIX old=matrix;
|
||||
MATRIX old = matrix;
|
||||
matrix = m;
|
||||
boolean mod=isModified();
|
||||
boolean mod = isModified();
|
||||
setModified(true);
|
||||
super.writeTag(sos);
|
||||
setModified(mod);
|
||||
|
||||
@@ -541,12 +541,12 @@ public class PlaceObject4Tag extends CharacterIdTag implements Container, PlaceO
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeTagWithMatrix(SWFOutputStream sos, MATRIX m) throws IOException {
|
||||
MATRIX old=matrix;
|
||||
MATRIX old = matrix;
|
||||
matrix = m;
|
||||
boolean mod=isModified();
|
||||
boolean mod = isModified();
|
||||
setModified(true);
|
||||
super.writeTag(sos);
|
||||
setModified(mod);
|
||||
|
||||
@@ -221,14 +221,13 @@ public class PlaceObjectTag extends CharacterIdTag implements PlaceObjectTypeTag
|
||||
|
||||
@Override
|
||||
public void writeTagWithMatrix(SWFOutputStream sos, MATRIX m) throws IOException {
|
||||
MATRIX old=matrix;
|
||||
MATRIX old = matrix;
|
||||
matrix = m;
|
||||
boolean mod=isModified();
|
||||
boolean mod = isModified();
|
||||
setModified(true);
|
||||
super.writeTag(sos);
|
||||
setModified(mod);
|
||||
matrix = old;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ package com.jpexs.decompiler.flash.tags;
|
||||
* @author JPEXS
|
||||
*/
|
||||
public interface TagChangedListener {
|
||||
|
||||
|
||||
public void handleEvent(Tag tag);
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
|
||||
RECT rect = getRect(new HashSet<BoundedTag>());
|
||||
return getShape(rect, false);
|
||||
}
|
||||
|
||||
|
||||
public SHAPEWITHSTYLE getShape(RECT rect, boolean fill) {
|
||||
boolean translated = rect.Xmin != 0 || rect.Ymin != 0;
|
||||
SHAPEWITHSTYLE shape = new SHAPEWITHSTYLE();
|
||||
@@ -125,7 +125,7 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
|
||||
fillStyle.bitmapId = getCharacterId();
|
||||
MATRIX matrix = new MATRIX();
|
||||
matrix.hasScale = true;
|
||||
if (fill) {
|
||||
if (fill) {
|
||||
RECT imageRect = getRect(new HashSet<BoundedTag>());
|
||||
matrix.scaleX = (int) ((((long) SWF.unitDivisor) << 16) * rect.getWidth() / imageRect.getWidth());
|
||||
matrix.scaleY = (int) ((((long) SWF.unitDivisor) << 16) * rect.getHeight() / imageRect.getHeight());
|
||||
@@ -212,7 +212,7 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag {
|
||||
public Shape getOutline(int frame, int time, int ratio, DepthState stateUnderCursor, int mouseButton, Matrix transformation) {
|
||||
return transformation.toTransform().createTransformedShape(getShape().getOutline());
|
||||
}
|
||||
|
||||
|
||||
public void clearCache() {
|
||||
cachedImage = null;
|
||||
}
|
||||
|
||||
@@ -64,6 +64,6 @@ public interface PlaceObjectTypeTag {
|
||||
public int getRatio();
|
||||
|
||||
public CLIPACTIONS getClipActions();
|
||||
|
||||
public void writeTagWithMatrix(SWFOutputStream sos,MATRIX m) throws IOException;
|
||||
|
||||
public void writeTagWithMatrix(SWFOutputStream sos, MATRIX m) throws IOException;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2014 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.base;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public abstract class TextImportErrorHandler {
|
||||
|
||||
public abstract boolean handle();
|
||||
|
||||
public abstract boolean handle(String message, long line);
|
||||
}
|
||||
@@ -637,7 +637,7 @@ public final class TextLexer {
|
||||
zzInput = zzBufferL[zzCurrentPosL++];
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
if (zzNext == -1) {
|
||||
break zzForAction;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ColorTransform implements Cloneable {
|
||||
r2.inShape3 = r.inShape3;
|
||||
r2.ratio = r.ratio;
|
||||
r2.color = apply(r.color);
|
||||
ret[i] = r2;
|
||||
ret[i] = r2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -107,8 +107,6 @@ public class MATRIX implements Serializable {
|
||||
return "[MATRIX scale:" + getScaleXFloat() + "," + getScaleYFloat() + ", rotate:" + getRotateSkew0Float() + "," + getRotateSkew1Float() + ", translate:" + translateX + "," + translateY + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
private float toFloat(int i) {
|
||||
return ((float) i) / (1 << 16);
|
||||
}
|
||||
@@ -162,7 +160,7 @@ public class MATRIX implements Serializable {
|
||||
public int getScaleY() {
|
||||
return (hasScale ? (scaleY) : (1 << 16));
|
||||
}
|
||||
|
||||
|
||||
public boolean isEmpty() {
|
||||
return (translateX == 0) && (translateY == 0) && (!hasRotate) && (!hasScale);
|
||||
}
|
||||
|
||||
@@ -656,7 +656,7 @@ public final class ConditionLexer {
|
||||
zzInput = zzBufferL[zzCurrentPosL++];
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||
if (zzNext == -1) {
|
||||
break zzForAction;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class EdgeType implements Serializable {
|
||||
public SHAPERECORD toSHAPERECORD() {
|
||||
int multiplier = 1;
|
||||
StraightEdgeRecord ser;
|
||||
CurvedEdgeRecord cer;
|
||||
CurvedEdgeRecord cer;
|
||||
switch (data[0]) {
|
||||
case Edge_HLine:
|
||||
ser = new StraightEdgeRecord();
|
||||
|
||||
@@ -153,7 +153,7 @@ public class XFLConverter {
|
||||
public static final int KEY_MODE_SHAPE_TWEEN = 17922;
|
||||
public static final int KEY_MODE_MOTION_TWEEN = 8195;
|
||||
public static final int KEY_MODE_SHAPE_LAYERS = 8192;
|
||||
|
||||
|
||||
private static final Random random = new Random(123); // predictable random
|
||||
|
||||
private XFLConverter() {
|
||||
@@ -281,9 +281,9 @@ public class XFLConverter {
|
||||
|
||||
public static String convertFillStyle(MATRIX mat, HashMap<Integer, CharacterTag> characters, FILLSTYLE fs, int shapeNum) {
|
||||
/* todo: use matrix
|
||||
if (mat == null) {
|
||||
mat = new MATRIX();
|
||||
}*/
|
||||
if (mat == null) {
|
||||
mat = new MATRIX();
|
||||
}*/
|
||||
StringBuilder ret = new StringBuilder();
|
||||
//ret += "<FillStyle index=\"" + index + "\">";
|
||||
switch (fs.fillStyleType) {
|
||||
@@ -3184,7 +3184,7 @@ public class XFLConverter {
|
||||
}
|
||||
|
||||
return "<AdjustColorFilter brightness=\"" + normBrightness(b) + "\" contrast=\"" + normContrast(c) + "\" saturation=\"" + normSaturation(s) + "\" hue=\"" + normHue(h) + "\"/>";
|
||||
}
|
||||
}
|
||||
|
||||
private static String convertHTMLText(List<Tag> tags, DefineEditTextTag det, String html) {
|
||||
HTMLTextParser tparser = new HTMLTextParser(tags, det);
|
||||
@@ -3215,7 +3215,7 @@ public class XFLConverter {
|
||||
}
|
||||
|
||||
private static double twipToPixel(double tw) {
|
||||
return tw /SWF.unitDivisor;
|
||||
return tw / SWF.unitDivisor;
|
||||
}
|
||||
|
||||
private static class HTMLTextParser extends DefaultHandler {
|
||||
|
||||
Reference in New Issue
Block a user