mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-04 17:54:18 +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 {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Cache<K, V> implements Freed {
|
||||
private String name;
|
||||
|
||||
static {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(){
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -50,12 +50,12 @@ public class Cache<K, V> implements Freed {
|
||||
c.free();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public static <K, V> Cache<K, V> getInstance(boolean weak,String name) {
|
||||
Cache<K, V> instance = new Cache<>(weak,name);
|
||||
|
||||
public static <K, V> Cache<K, V> getInstance(boolean weak, String name) {
|
||||
Cache<K, V> instance = new Cache<>(weak, name);
|
||||
instances.add(instance);
|
||||
return instance;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ public class Cache<K, V> implements Freed {
|
||||
Map<K, V> newCache = null;
|
||||
if (thisStorageType == STORAGE_FILES) {
|
||||
try {
|
||||
newCache = new FileHashMap<>(File.createTempFile("ffdec_cache_"+name+"_", ".tmp"));
|
||||
newCache = new FileHashMap<>(File.createTempFile("ffdec_cache_" + name + "_", ".tmp"));
|
||||
} catch (IOException ex) {
|
||||
thisStorageType = STORAGE_MEMORY;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ public class Cache<K, V> implements Freed {
|
||||
this.cache = newCache;
|
||||
}
|
||||
|
||||
private Cache(boolean weak,String name) {
|
||||
private Cache(boolean weak, String name) {
|
||||
this.weak = weak;
|
||||
this.name = name;
|
||||
initCache();
|
||||
@@ -148,8 +148,8 @@ public class Cache<K, V> implements Freed {
|
||||
|
||||
@Override
|
||||
public void free() {
|
||||
if(cache instanceof Freed){
|
||||
((Freed)cache).free();
|
||||
if (cache instanceof Freed) {
|
||||
((Freed) cache).free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,6 @@ public class FileHashMap<K, V> extends AbstractMap<K, V> implements Freed {
|
||||
private int maxGapLen = 0;
|
||||
private boolean deleted = false;
|
||||
|
||||
|
||||
|
||||
private static class Gap implements Comparable<Gap> {
|
||||
|
||||
public long offset;
|
||||
@@ -111,7 +109,7 @@ public class FileHashMap<K, V> extends AbstractMap<K, V> implements Freed {
|
||||
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
if(deleted){
|
||||
if (deleted) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return offsets.containsKey(key);
|
||||
@@ -119,7 +117,7 @@ public class FileHashMap<K, V> extends AbstractMap<K, V> implements Freed {
|
||||
|
||||
@Override
|
||||
public Set<K> keySet() {
|
||||
if(deleted){
|
||||
if (deleted) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return offsets.keySet();
|
||||
@@ -127,7 +125,7 @@ public class FileHashMap<K, V> extends AbstractMap<K, V> implements Freed {
|
||||
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
if(deleted){
|
||||
if (deleted) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
try {
|
||||
@@ -156,7 +154,7 @@ public class FileHashMap<K, V> extends AbstractMap<K, V> implements Freed {
|
||||
|
||||
@Override
|
||||
public synchronized V put(K key, V value) {
|
||||
if(deleted){
|
||||
if (deleted) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
ObjectOutputStream oos = null;
|
||||
@@ -222,11 +220,11 @@ public class FileHashMap<K, V> extends AbstractMap<K, V> implements Freed {
|
||||
|
||||
@Override
|
||||
public V remove(Object objKey) {
|
||||
if(deleted){
|
||||
if (deleted) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
K key=(K)objKey;
|
||||
K key = (K) objKey;
|
||||
if (!containsKey(key)) {
|
||||
return null;
|
||||
}
|
||||
@@ -247,19 +245,19 @@ public class FileHashMap<K, V> extends AbstractMap<K, V> implements Freed {
|
||||
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
if(deleted){
|
||||
if (deleted) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
Set<Entry<K,V>> ret=new HashSet<Entry<K, V>>();
|
||||
for(K key:keySet()){
|
||||
ret.add(new FileEntry<K,V>(this,key));
|
||||
Set<Entry<K, V>> ret = new HashSet<Entry<K, V>>();
|
||||
for (K key : keySet()) {
|
||||
ret.add(new FileEntry<K, V>(this, key));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
if(deleted){
|
||||
if (deleted) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
offsets.clear();
|
||||
@@ -271,10 +269,10 @@ public class FileHashMap<K, V> extends AbstractMap<K, V> implements Freed {
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(FileHashMap.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
if(deleted){
|
||||
if (deleted) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
try {
|
||||
@@ -284,9 +282,9 @@ public class FileHashMap<K, V> extends AbstractMap<K, V> implements Freed {
|
||||
}
|
||||
fileName.delete();
|
||||
deleted = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isFreeing() {
|
||||
return !deleted;
|
||||
@@ -294,7 +292,7 @@ public class FileHashMap<K, V> extends AbstractMap<K, V> implements Freed {
|
||||
|
||||
@Override
|
||||
public void free() {
|
||||
if(!deleted){
|
||||
if (!deleted) {
|
||||
delete();
|
||||
}
|
||||
}
|
||||
@@ -308,6 +306,5 @@ public class FileHashMap<K, V> extends AbstractMap<K, V> implements Freed {
|
||||
public int size() {
|
||||
return offsets.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -412,8 +412,7 @@ public class Helper {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static ByteArrayInputStream getInputStream(byte[]
|
||||
... data) {
|
||||
public static ByteArrayInputStream getInputStream(byte[]... data) {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
@@ -480,8 +479,7 @@ public class Helper {
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeFile(String file, byte[]
|
||||
... data) {
|
||||
public static void writeFile(String file, byte[]... data) {
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
for (byte[] d : data) {
|
||||
fos.write(d);
|
||||
@@ -874,7 +872,7 @@ public class Helper {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static String byteCountStr(long bytes, boolean si) {
|
||||
int unit = si ? 1000 : 1024;
|
||||
if (bytes < unit) {
|
||||
@@ -885,5 +883,4 @@ public class Helper {
|
||||
return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -31,17 +31,14 @@ public interface Searchable {
|
||||
* @param data
|
||||
* @return Map Position=>Input stream
|
||||
*/
|
||||
public Map<Long, InputStream> search(byte[]
|
||||
|
||||
... data);
|
||||
public Map<Long, InputStream> search(byte[]... data);
|
||||
|
||||
/**
|
||||
* Searches for byte sequences with progress listener
|
||||
*
|
||||
* @param progListener Listener
|
||||
* @param data
|
||||
* @return Map Position=>Input stream
|
||||
*/
|
||||
public Map<Long, InputStream> search(ProgressListener progListener, byte[]
|
||||
|
||||
... data);
|
||||
public Map<Long, InputStream> search(ProgressListener progListener, byte[]... data);
|
||||
}
|
||||
|
||||
@@ -36,14 +36,12 @@ public class StreamSearch implements Searchable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, InputStream> search(byte[]
|
||||
... data) {
|
||||
public Map<Long, InputStream> search(byte[]... data) {
|
||||
return search(null, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, InputStream> search(ProgressListener progListener, byte[]
|
||||
... data) {
|
||||
public Map<Long, InputStream> search(ProgressListener progListener, byte[]... data) {
|
||||
Map<Long, InputStream> ret = new HashMap<>();
|
||||
int maxFindLen = 0;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
|
||||
@@ -36,16 +36,14 @@ public class SwfHeaderStreamSearch implements Searchable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, InputStream> search(byte[]
|
||||
... data) {
|
||||
public Map<Long, InputStream> search(byte[]... data) {
|
||||
return search(null, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, InputStream> search(ProgressListener progListener, byte[]
|
||||
... data) {
|
||||
public Map<Long, InputStream> search(ProgressListener progListener, byte[]... data) {
|
||||
// Ignore data parameter, find only FWS, CWS, ZWS, GFX and CFX
|
||||
|
||||
|
||||
Map<Long, InputStream> ret = new HashMap<>();
|
||||
byte[] buf = is.getAllRead();
|
||||
byte byte2 = buf[0], byte3 = buf[1];
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Filters = {};
|
||||
|
||||
var createCanvas = function(width, height) {
|
||||
var createCanvas = function (width, height) {
|
||||
var c = document.createElement("canvas");
|
||||
c.width = width;
|
||||
c.height = height;
|
||||
@@ -15,7 +15,7 @@ var createCanvas = function(width, height) {
|
||||
return c;
|
||||
};
|
||||
|
||||
Filters._premultiply = function(data) {
|
||||
Filters._premultiply = function (data) {
|
||||
var len = data.length;
|
||||
for (var i = 0; i < len; i += 4) {
|
||||
var f = data[i + 3] * 0.003921569;
|
||||
@@ -25,7 +25,7 @@ Filters._premultiply = function(data) {
|
||||
}
|
||||
};
|
||||
|
||||
Filters._unpremultiply = function(data) {
|
||||
Filters._unpremultiply = function (data) {
|
||||
var len = data.length;
|
||||
for (var i = 0; i < len; i += 4) {
|
||||
var a = data[i + 3];
|
||||
@@ -53,7 +53,7 @@ Filters._unpremultiply = function(data) {
|
||||
};
|
||||
|
||||
|
||||
Filters._boxBlurHorizontal = function(pixels, mask, w, h, radius, maskType) {
|
||||
Filters._boxBlurHorizontal = function (pixels, mask, w, h, radius, maskType) {
|
||||
var index = 0;
|
||||
var newColors = [];
|
||||
|
||||
@@ -119,7 +119,7 @@ Filters._boxBlurHorizontal = function(pixels, mask, w, h, radius, maskType) {
|
||||
}
|
||||
};
|
||||
|
||||
Filters._boxBlurVertical = function(pixels, mask, w, h, radius, maskType) {
|
||||
Filters._boxBlurVertical = function (pixels, mask, w, h, radius, maskType) {
|
||||
var newColors = [];
|
||||
var oldPixelOffset = -(radius + 1) * w * 4;
|
||||
var newPixelOffset = (radius) * w * 4;
|
||||
@@ -189,7 +189,7 @@ Filters._boxBlurVertical = function(pixels, mask, w, h, radius, maskType) {
|
||||
};
|
||||
|
||||
|
||||
Filters.blur = function(canvas, ctx, hRadius, vRadius, iterations, mask, maskType) {
|
||||
Filters.blur = function (canvas, ctx, hRadius, vRadius, iterations, mask, maskType) {
|
||||
var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
var data = imgData.data;
|
||||
Filters._premultiply(data);
|
||||
@@ -208,7 +208,7 @@ Filters.blur = function(canvas, ctx, hRadius, vRadius, iterations, mask, maskTyp
|
||||
return retCanvas;
|
||||
}
|
||||
|
||||
Filters._moveRGB = function(width, height, rgb, deltaX, deltaY, fill) {
|
||||
Filters._moveRGB = function (width, height, rgb, deltaX, deltaY, fill) {
|
||||
var img = createCanvas(width, height);
|
||||
|
||||
var ig = img.getContext("2d");
|
||||
@@ -230,7 +230,7 @@ Filters.FULL = 1;
|
||||
Filters.INNER = 2;
|
||||
Filters.OUTER = 3;
|
||||
|
||||
Filters._setRGB = function(ctx, x, y, width, height, data) {
|
||||
Filters._setRGB = function (ctx, x, y, width, height, data) {
|
||||
var id = ctx.createImageData(width, height);
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
id.data[i] = data[i];
|
||||
@@ -238,7 +238,7 @@ Filters._setRGB = function(ctx, x, y, width, height, data) {
|
||||
ctx.putImageData(id, x, y);
|
||||
};
|
||||
|
||||
Filters.gradientGlow = function(srcCanvas, src, blurX, blurY, angle, distance, colors, ratios, type, iterations, strength, knockout) {
|
||||
Filters.gradientGlow = function (srcCanvas, src, blurX, blurY, angle, distance, colors, ratios, type, iterations, strength, knockout) {
|
||||
var width = canvas.width;
|
||||
var height = canvas.height;
|
||||
var retCanvas = createCanvas(width, height);
|
||||
@@ -322,7 +322,7 @@ Filters.gradientGlow = function(srcCanvas, src, blurX, blurY, angle, distance, c
|
||||
|
||||
|
||||
|
||||
Filters.dropShadow = function(canvas, src, blurX, blurY, angle, distance, color, inner, iterations, strength, knockout) {
|
||||
Filters.dropShadow = function (canvas, src, blurX, blurY, angle, distance, color, inner, iterations, strength, knockout) {
|
||||
var width = canvas.width;
|
||||
var height = canvas.height;
|
||||
var srcPixels = src.getImageData(0, 0, width, height).data;
|
||||
@@ -374,7 +374,7 @@ Filters.dropShadow = function(canvas, src, blurX, blurY, angle, distance, color,
|
||||
return retCanvas;
|
||||
};
|
||||
|
||||
Filters._cut = function(a, min, max) {
|
||||
Filters._cut = function (a, min, max) {
|
||||
if (a > max)
|
||||
a = max;
|
||||
if (a < min)
|
||||
@@ -382,7 +382,7 @@ Filters._cut = function(a, min, max) {
|
||||
return a;
|
||||
}
|
||||
|
||||
Filters.gradientBevel = function(canvas, src, colors, ratios, blurX, blurY, strength, type, angle, distance, knockout, iterations) {
|
||||
Filters.gradientBevel = function (canvas, src, colors, ratios, blurX, blurY, strength, type, angle, distance, knockout, iterations) {
|
||||
var width = canvas.width;
|
||||
var height = canvas.height;
|
||||
var retImg = createCanvas(width, height);
|
||||
@@ -497,7 +497,7 @@ Filters.gradientBevel = function(canvas, src, colors, ratios, blurX, blurY, stre
|
||||
}
|
||||
return retImg;
|
||||
}
|
||||
Filters.bevel = function(canvas, src, blurX, blurY, strength, type, highlightColor, shadowColor, angle, distance, knockout, iterations) {
|
||||
Filters.bevel = function (canvas, src, blurX, blurY, strength, type, highlightColor, shadowColor, angle, distance, knockout, iterations) {
|
||||
return Filters.gradientBevel(canvas, src, [
|
||||
shadowColor,
|
||||
[shadowColor[0], shadowColor[1], shadowColor[2], 0],
|
||||
@@ -510,7 +510,7 @@ Filters.bevel = function(canvas, src, blurX, blurY, strength, type, highlightCol
|
||||
|
||||
|
||||
//http://www.html5rocks.com/en/tutorials/canvas/imagefilters/
|
||||
Filters.convolution = function(canvas, ctx, weights, opaque) {
|
||||
Filters.convolution = function (canvas, ctx, weights, opaque) {
|
||||
var pixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
var side = Math.round(Math.sqrt(weights.length));
|
||||
var halfSide = Math.floor(side / 2);
|
||||
@@ -558,7 +558,7 @@ Filters.convolution = function(canvas, ctx, weights, opaque) {
|
||||
return outCanvas;
|
||||
};
|
||||
|
||||
Filters.colorMatrix = function(canvas, ctx, m) {
|
||||
Filters.colorMatrix = function (canvas, ctx, m) {
|
||||
var pixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
|
||||
var data = pixels.data;
|
||||
@@ -586,14 +586,14 @@ Filters.colorMatrix = function(canvas, ctx, m) {
|
||||
};
|
||||
|
||||
|
||||
Filters.glow = function(canvas, src, blurX, blurY, strength, color, inner, knockout, iterations) {
|
||||
Filters.glow = function (canvas, src, blurX, blurY, strength, color, inner, knockout, iterations) {
|
||||
return Filters.dropShadow(canvas, src, blurX, blurY, 45, 0, color, inner, iterations, strength, knockout);
|
||||
};
|
||||
|
||||
|
||||
var BlendModes = {};
|
||||
|
||||
BlendModes._cut = function(v) {
|
||||
BlendModes._cut = function (v) {
|
||||
if (v < 0)
|
||||
v = 0;
|
||||
if (v > 255)
|
||||
@@ -601,7 +601,7 @@ BlendModes._cut = function(v) {
|
||||
return v;
|
||||
};
|
||||
|
||||
BlendModes.normal = function(src, dst, result, pos) {
|
||||
BlendModes.normal = function (src, dst, result, pos) {
|
||||
var am = (255 - src[pos + 3]) / 255;
|
||||
result[pos] = this._cut(src[pos] * src[pos + 3] / 255 + dst[pos] * dst[pos + 3] / 255 * am);
|
||||
result[pos + 1] = this._cut(src[pos + 1] * src[pos + 3] / 255 + dst[pos + 1] * dst[pos + 3] / 255 * am);
|
||||
@@ -609,81 +609,81 @@ BlendModes.normal = function(src, dst, result, pos) {
|
||||
result[pos + 3] = this._cut(src[pos + 3] + dst[pos + 3] * am);
|
||||
};
|
||||
|
||||
BlendModes.layer = function(src, dst, result, pos) {
|
||||
BlendModes.layer = function (src, dst, result, pos) {
|
||||
BlendModes.normal(src, dst, result, pos);
|
||||
};
|
||||
|
||||
BlendModes.multiply = function(src, dst, result, pos) {
|
||||
BlendModes.multiply = function (src, dst, result, pos) {
|
||||
result[pos + 0] = (src[pos + 0] * dst[pos + 0]) >> 8;
|
||||
result[pos + 1] = (src[pos + 1] * dst[pos + 1]) >> 8;
|
||||
result[pos + 2] = (src[pos + 2] * dst[pos + 2]) >> 8;
|
||||
result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255);
|
||||
};
|
||||
|
||||
BlendModes.screen = function(src, dst, result, pos) {
|
||||
BlendModes.screen = function (src, dst, result, pos) {
|
||||
result[pos + 0] = 255 - ((255 - src[pos + 0]) * (255 - dst[pos + 0]) >> 8);
|
||||
result[pos + 1] = 255 - ((255 - src[pos + 1]) * (255 - dst[pos + 1]) >> 8);
|
||||
result[pos + 2] = 255 - ((255 - src[pos + 2]) * (255 - dst[pos + 2]) >> 8);
|
||||
result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255);
|
||||
};
|
||||
|
||||
BlendModes.lighten = function(src, dst, result, pos) {
|
||||
BlendModes.lighten = function (src, dst, result, pos) {
|
||||
result[pos + 0] = Math.max(src[pos + 0], dst[pos + 0]);
|
||||
result[pos + 1] = Math.max(src[pos + 1], dst[pos + 1]);
|
||||
result[pos + 2] = Math.max(src[pos + 2], dst[pos + 2]);
|
||||
result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255);
|
||||
};
|
||||
|
||||
BlendModes.darken = function(src, dst, result, pos) {
|
||||
BlendModes.darken = function (src, dst, result, pos) {
|
||||
result[pos + 0] = Math.min(src[pos + 0], dst[pos + 0]);
|
||||
result[pos + 1] = Math.min(src[pos + 1], dst[pos + 1]);
|
||||
result[pos + 2] = Math.min(src[pos + 2], dst[pos + 2]);
|
||||
result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255);
|
||||
};
|
||||
|
||||
BlendModes.difference = function(src, dst, result, pos) {
|
||||
BlendModes.difference = function (src, dst, result, pos) {
|
||||
result[pos + 0] = Math.abs(dst[pos + 0] - src[pos + 0]);
|
||||
result[pos + 1] = Math.abs(dst[pos + 1] - src[pos + 1]);
|
||||
result[pos + 2] = Math.abs(dst[pos + 2] - src[pos + 2]);
|
||||
result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255);
|
||||
};
|
||||
|
||||
BlendModes.add = function(src, dst, result, pos) {
|
||||
BlendModes.add = function (src, dst, result, pos) {
|
||||
result[pos + 0] = Math.min(255, src[pos + 0] + dst[pos + 0]);
|
||||
result[pos + 1] = Math.min(255, src[pos + 1] + dst[pos + 1]);
|
||||
result[pos + 2] = Math.min(255, src[pos + 2] + dst[pos + 2]);
|
||||
result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3]);
|
||||
};
|
||||
|
||||
BlendModes.subtract = function(src, dst, result, pos) {
|
||||
BlendModes.subtract = function (src, dst, result, pos) {
|
||||
result[pos + 0] = Math.max(0, src[pos + 0] + dst[pos + 0] - 256);
|
||||
result[pos + 1] = Math.max(0, src[pos + 1] + dst[pos + 1] - 256);
|
||||
result[pos + 2] = Math.max(0, src[pos + 2] + dst[pos + 2] - 256);
|
||||
result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255);
|
||||
};
|
||||
|
||||
BlendModes.invert = function(src, dst, result, pos) {
|
||||
BlendModes.invert = function (src, dst, result, pos) {
|
||||
result[pos + 0] = 255 - dst[pos + 0];
|
||||
result[pos + 1] = 255 - dst[pos + 1];
|
||||
result[pos + 2] = 255 - dst[pos + 2];
|
||||
result[pos + 3] = src[pos + 3];
|
||||
};
|
||||
|
||||
BlendModes.alpha = function(src, dst, result, pos) {
|
||||
BlendModes.alpha = function (src, dst, result, pos) {
|
||||
result[pos + 0] = src[pos + 0];
|
||||
result[pos + 1] = src[pos + 1];
|
||||
result[pos + 2] = src[pos + 2];
|
||||
result[pos + 3] = dst[pos + 3]; //?
|
||||
};
|
||||
|
||||
BlendModes.erase = function(src, dst, result, pos) {
|
||||
BlendModes.erase = function (src, dst, result, pos) {
|
||||
result[pos + 0] = src[pos + 0];
|
||||
result[pos + 1] = src[pos + 1];
|
||||
result[pos + 2] = src[pos + 2];
|
||||
result[pos + 3] = 255 - dst[pos + 3]; //?
|
||||
};
|
||||
|
||||
BlendModes.overlay = function(src, dst, result, pos) {
|
||||
BlendModes.overlay = function (src, dst, result, pos) {
|
||||
result[pos + 0] = dst[pos + 0] < 128 ? dst[pos + 0] * src[pos + 0] >> 7
|
||||
: 255 - ((255 - dst[pos + 0]) * (255 - src[pos + 0]) >> 7);
|
||||
result[pos + 1] = dst[pos + 1] < 128 ? dst[pos + 1] * src[pos + 1] >> 7
|
||||
@@ -693,7 +693,7 @@ BlendModes.overlay = function(src, dst, result, pos) {
|
||||
result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255);
|
||||
};
|
||||
|
||||
BlendModes.hardlight = function(src, dst, result, pos) {
|
||||
BlendModes.hardlight = function (src, dst, result, pos) {
|
||||
result[pos + 0] = src[pos + 0] < 128 ? dst[pos + 0] * src[pos + 0] >> 7
|
||||
: 255 - ((255 - src[pos + 0]) * (255 - dst[pos + 0]) >> 7);
|
||||
result[pos + 1] = src[pos + 1] < 128 ? dst[pos + 1] * src[pos + 1] >> 7
|
||||
@@ -721,7 +721,7 @@ BlendModes._list = [
|
||||
BlendModes.hardlight
|
||||
];
|
||||
|
||||
BlendModes.blendData = function(srcPixel, dstPixel, retData, modeIndex) {
|
||||
BlendModes.blendData = function (srcPixel, dstPixel, retData, modeIndex) {
|
||||
var result = [];
|
||||
var retPixel = [];
|
||||
var alpha = 1.0;
|
||||
@@ -741,7 +741,7 @@ BlendModes.blendData = function(srcPixel, dstPixel, retData, modeIndex) {
|
||||
}
|
||||
};
|
||||
|
||||
BlendModes.blendCanvas = function(src, dst, result, modeIndex) {
|
||||
BlendModes.blendCanvas = function (src, dst, result, modeIndex) {
|
||||
var width = src.width;
|
||||
var height = src.height;
|
||||
var rctx = result.getContext("2d");
|
||||
@@ -776,7 +776,7 @@ function concatMatrix(m1, m2) {
|
||||
}
|
||||
|
||||
|
||||
var enhanceContext = function(context) {
|
||||
var enhanceContext = function (context) {
|
||||
var m = [1, 0, 0, 1, 0, 0];
|
||||
context._matrix = m;
|
||||
|
||||
@@ -785,42 +785,42 @@ var enhanceContext = function(context) {
|
||||
|
||||
var super_ = context.__proto__;
|
||||
context.__proto__ = ({
|
||||
save: function() {
|
||||
save: function () {
|
||||
this._savedMatrices.push(this._matrix); //.slice()
|
||||
super_.save.call(this);
|
||||
},
|
||||
//if the stack of matrices we're managing doesn't have a saved matrix,
|
||||
//we won't even call the context's original `restore` method.
|
||||
restore: function() {
|
||||
restore: function () {
|
||||
if (this._savedMatrices.length == 0)
|
||||
return;
|
||||
super_.restore.call(this);
|
||||
this._matrix = this._savedMatrices.pop();
|
||||
},
|
||||
scale: function(x, y) {
|
||||
scale: function (x, y) {
|
||||
super_.scale.call(this, x, y);
|
||||
},
|
||||
rotate: function(theta) {
|
||||
rotate: function (theta) {
|
||||
super_.rotate.call(this, theta);
|
||||
},
|
||||
translate: function(x, y) {
|
||||
translate: function (x, y) {
|
||||
super_.translate.call(this, x, y);
|
||||
},
|
||||
transform: function(a, b, c, d, e, f) {
|
||||
transform: function (a, b, c, d, e, f) {
|
||||
this._matrix = concatMatrix([a, b, c, d, e, f], this._matrix);
|
||||
super_.transform.call(this, a, b, c, d, e, f);
|
||||
},
|
||||
setTransform: function(a, b, c, d, e, f) {
|
||||
setTransform: function (a, b, c, d, e, f) {
|
||||
this._matrix = [a, b, c, d, e, f];
|
||||
super_.setTransform.call(this, a, b, c, d, e, f);
|
||||
},
|
||||
resetTransform: function() {
|
||||
resetTransform: function () {
|
||||
super_.resetTransform.call(this);
|
||||
},
|
||||
applyTransforms: function(m) {
|
||||
applyTransforms: function (m) {
|
||||
this.setTransform(m[0], m[1], m[2], m[3], m[4], m[5])
|
||||
},
|
||||
applyTransformToPoint: function(p) {
|
||||
applyTransformToPoint: function (p) {
|
||||
var ret = {};
|
||||
ret.x = this._matrix[0] * p.x + this._matrix[2] * p.y + this._matrix[4];
|
||||
ret.y = this._matrix[1] * p.x + this._matrix[3] * p.y + this._matrix[5];
|
||||
@@ -831,7 +831,7 @@ var enhanceContext = function(context) {
|
||||
|
||||
return context;
|
||||
};
|
||||
var cxform = function(r_add, g_add, b_add, a_add, r_mult, g_mult, b_mult, a_mult) {
|
||||
var cxform = function (r_add, g_add, b_add, a_add, r_mult, g_mult, b_mult, a_mult) {
|
||||
this.r_add = r_add;
|
||||
this.g_add = g_add;
|
||||
this.b_add = b_add;
|
||||
@@ -840,14 +840,14 @@ var cxform = function(r_add, g_add, b_add, a_add, r_mult, g_mult, b_mult, a_mult
|
||||
this.g_mult = g_mult;
|
||||
this.b_mult = b_mult;
|
||||
this.a_mult = a_mult;
|
||||
this._cut = function(v, min, max) {
|
||||
this._cut = function (v, min, max) {
|
||||
if (v < min)
|
||||
v = min;
|
||||
if (v > max)
|
||||
v = max;
|
||||
return v;
|
||||
};
|
||||
this.apply = function(c) {
|
||||
this.apply = function (c) {
|
||||
var d = c;
|
||||
d[0] = this._cut(Math.round(d[0] * this.r_mult / 255 + this.r_add), 0, 255);
|
||||
d[1] = this._cut(Math.round(d[1] * this.g_mult / 255 + this.g_add), 0, 255);
|
||||
@@ -855,7 +855,7 @@ var cxform = function(r_add, g_add, b_add, a_add, r_mult, g_mult, b_mult, a_mult
|
||||
d[3] = this._cut(Math.round(d[3] * this.a_mult / 255 + this.a_add / 255), 0, 1);
|
||||
return d;
|
||||
};
|
||||
this.applyToImage = function(fimg) {
|
||||
this.applyToImage = function (fimg) {
|
||||
if (this.isEmpty()) {
|
||||
return fimg
|
||||
}
|
||||
@@ -875,15 +875,15 @@ var cxform = function(r_add, g_add, b_add, a_add, r_mult, g_mult, b_mult, a_mult
|
||||
ictx.putImageData(imdata, 0, 0);
|
||||
return icanvas;
|
||||
};
|
||||
this.merge = function(cx) {
|
||||
this.merge = function (cx) {
|
||||
return new cxform(this.r_add + cx.r_add, this.g_add + cx.g_add, this.b_add + cx.b_add, this.a_add + cx.a_add, this.r_mult * cx.r_mult / 255, this.g_mult * cx.g_mult / 255, this.b_mult * cx.b_mult / 255, this.a_mult * cx.a_mult / 255);
|
||||
};
|
||||
this.isEmpty = function() {
|
||||
this.isEmpty = function () {
|
||||
return this.r_add == 0 && this.g_add == 0 && this.b_add == 0 && this.a_add == 0 && this.r_mult == 255 && this.g_mult == 255 && this.b_mult == 255 && this.a_mult == 255;
|
||||
};
|
||||
};
|
||||
|
||||
var place = function(obj, canvas, ctx, matrix, ctrans, blendMode, frame, ratio, time) {
|
||||
var place = function (obj, canvas, ctx, matrix, ctrans, blendMode, frame, ratio, time) {
|
||||
ctx.save();
|
||||
ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
|
||||
if (blendMode > 1) {
|
||||
@@ -904,14 +904,14 @@ var place = function(obj, canvas, ctx, matrix, ctrans, blendMode, frame, ratio,
|
||||
}
|
||||
ctx.restore();
|
||||
}
|
||||
var tocolor = function(c) {
|
||||
var tocolor = function (c) {
|
||||
var r = "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + c[3] + ")";
|
||||
return r;
|
||||
};
|
||||
|
||||
|
||||
|
||||
window.addEventListener('load', function() {
|
||||
window.addEventListener('load', function () {
|
||||
|
||||
var wsize = document.getElementById("width_size");
|
||||
var hsize = document.getElementById("height_size");
|
||||
|
||||
Reference in New Issue
Block a user