Few refactorings & formatting

This commit is contained in:
Jindra Petk
2013-08-03 16:33:48 +02:00
parent d5c1d81cd8
commit b01ede8cca
15 changed files with 65 additions and 54 deletions

View File

@@ -51,7 +51,6 @@ import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord;
import com.jpexs.decompiler.graph.Graph;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphSourceItemContainer;
import com.jpexs.decompiler.graph.GraphSourceItemPos;
import com.jpexs.decompiler.graph.GraphTargetItem;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

View File

@@ -456,6 +456,15 @@ public class SWFOutputStream extends OutputStream {
}
return nBits;
}
public static int getNeededBitsU(int first, int... params) {
int nBits = 0;
nBits = enlargeBitCountU(nBits, first);
for (int i = 0; i < params.length; i++) {
nBits = enlargeBitCountU(nBits, params[i]);
}
return nBits;
}
private static long getIntPart(double value) {
if (value < 0) {
@@ -491,13 +500,21 @@ public class SWFOutputStream extends OutputStream {
return getNeededBitsS(k) + 16;
}
private static int enlargeBitCountS(int currentBitCount, int value) {
public static int enlargeBitCountS(int currentBitCount, int value) {
int neededNew = getNeededBitsS(value);
if (neededNew > currentBitCount) {
return neededNew;
}
return currentBitCount;
}
public static int enlargeBitCountU(int currentBitCount, int value) {
int neededNew = getNeededBitsU(value);
if (neededNew > currentBitCount) {
return neededNew;
}
return currentBitCount;
}
/**
* Writes MATRIX value to the stream

View File

@@ -23,7 +23,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.DecLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NotCompileTimeAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.SubtractAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;

View File

@@ -23,7 +23,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.DecLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NotCompileTimeAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.SubtractAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;

View File

@@ -23,7 +23,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NotCompileTimeAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.UndefinedAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import java.util.HashMap;

View File

@@ -22,7 +22,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.IncLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NotCompileTimeAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.AddAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;

View File

@@ -22,7 +22,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.IncLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NotCompileTimeAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.AddAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;

View File

@@ -28,7 +28,6 @@ import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NewActivationAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NotCompileTimeAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostDecrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostIncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.SetLocalAVM2Item;

View File

@@ -20,7 +20,6 @@ import com.jpexs.decompiler.flash.DisassemblyListener;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.action.model.CallFunctionActionItem;
import com.jpexs.decompiler.flash.action.model.ConstantPool;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
import com.jpexs.decompiler.flash.action.model.ExtendsActionItem;
@@ -29,7 +28,6 @@ import com.jpexs.decompiler.flash.action.model.GetMemberActionItem;
import com.jpexs.decompiler.flash.action.model.GetPropertyActionItem;
import com.jpexs.decompiler.flash.action.model.GetVariableActionItem;
import com.jpexs.decompiler.flash.action.model.ImplementsOpActionItem;
import com.jpexs.decompiler.flash.action.model.NewMethodActionItem;
import com.jpexs.decompiler.flash.action.model.NewObjectActionItem;
import com.jpexs.decompiler.flash.action.model.SetMemberActionItem;
import com.jpexs.decompiler.flash.action.model.SetPropertyActionItem;

View File

@@ -3026,7 +3026,7 @@ public class MainFrame extends AppRibbonFrame implements ActionListener, TreeSel
rec.add(tr);
mat.translateX = x * width / sloupcu;
mat.translateY = y * height / radku;
sos2.writeTag(new DefineTextTag(null, 999 + f, new RECT(0, width, 0, height), new MATRIX(), SWFOutputStream.getNeededBitsU(countGlyphs - 1), SWFOutputStream.getNeededBitsU(0), rec));
sos2.writeTag(new DefineTextTag(null, 999 + f, new RECT(0, width, 0, height), new MATRIX(), rec));
sos2.writeTag(new PlaceObject2Tag(null, false, false, false, true, false, true, true, false, 1 + f, 999 + f, mat, null, 0, null, 0, null));
x++;
}

View File

@@ -25,12 +25,8 @@ import static com.jpexs.decompiler.flash.gui.AppStrings.translate;
import com.jpexs.decompiler.flash.gui.View;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.awt.BorderLayout;
import java.awt.Font;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import jsyntaxpane.syntaxkits.Flasm3MethodInfoSyntaxKit;
/**

View File

@@ -62,8 +62,6 @@ public class DefineText2Tag extends TextTag implements DrawableTag {
public int characterID;
public RECT textBounds;
public MATRIX textMatrix;
public int glyphBits;
public int advanceBits;
public List<TEXTRECORD> textRecords;
public static final int ID = 33;
@@ -159,10 +157,11 @@ public class DefineText2Tag extends TextTag implements DrawableTag {
@Override
public boolean setFormattedText(MissingCharacterHandler missingCharHandler, List<Tag> tags, String text, String fontName) throws ParseException {
List<TEXTRECORD> oldTextRecords = textRecords;
try {
TextLexer lexer = new TextLexer(new InputStreamReader(new ByteArrayInputStream(text.getBytes("UTF-8")), "UTF-8"));
ParsedSymbol s = null;
List<TEXTRECORD> textRecords = new ArrayList<>();
textRecords = new ArrayList<>();
RGBA colorA = null;
int fontId = -1;
int textHeight = -1;
@@ -171,8 +170,6 @@ public class DefineText2Tag extends TextTag implements DrawableTag {
Integer y = null;
int currentX = 0;
int currentY = 0;
int glyphBits = 0;
int advanceBits = 0;
int maxX = Integer.MIN_VALUE;
int minX = Integer.MAX_VALUE;
MATRIX textMatrix = new MATRIX();
@@ -303,6 +300,7 @@ public class DefineText2Tag extends TextTag implements DrawableTag {
throw new ParseException("Font not defined", lexer.yyline());
}
TEXTRECORD tr = new TEXTRECORD();
textRecords.add(tr);
if (fontId > -1) {
tr.fontId = fontId;
tr.textHeight = textHeight;
@@ -328,12 +326,13 @@ public class DefineText2Tag extends TextTag implements DrawableTag {
tr.glyphEntries = new GLYPHENTRY[txt.length()];
for (int i = 0; i < txt.length(); i++) {
char c = txt.charAt(i);
tr.glyphEntries[i] = new GLYPHENTRY();
if (!font.containsChar(tags, c)) {
if (!missingCharHandler.handle(font, tags, c)) {
return false;
}
}
tr.glyphEntries[i] = new GLYPHENTRY();
tr.glyphEntries[i].glyphIndex = font.charToGlyph(tags, c);
int advance;
@@ -345,15 +344,8 @@ public class DefineText2Tag extends TextTag implements DrawableTag {
tr.glyphEntries[i].glyphAdvance = advance;
currentX += advance;
if (SWFOutputStream.getNeededBitsU(tr.glyphEntries[i].glyphIndex) > glyphBits) {
glyphBits = SWFOutputStream.getNeededBitsU(tr.glyphEntries[i].glyphIndex);
}
if (SWFOutputStream.getNeededBitsS(tr.glyphEntries[i].glyphAdvance) > advanceBits) {
advanceBits = SWFOutputStream.getNeededBitsS(tr.glyphEntries[i].glyphAdvance);
}
}
textRecords.add(tr);
if (currentX > maxX) {
maxX = currentX;
}
@@ -364,8 +356,6 @@ public class DefineText2Tag extends TextTag implements DrawableTag {
}
}
this.advanceBits = advanceBits;
this.glyphBits = glyphBits;
this.textRecords = textRecords;
this.textBounds = textBounds;
//this.textBounds.Xmin = minX;
@@ -373,7 +363,11 @@ public class DefineText2Tag extends TextTag implements DrawableTag {
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(DefineText2Tag.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
textRecords = oldTextRecords;
return false;
} catch (ParseException ex) {
textRecords = oldTextRecords;
throw ex;
}
return true;
}
@@ -403,6 +397,15 @@ public class DefineText2Tag extends TextTag implements DrawableTag {
sos.writeUI16(characterID);
sos.writeRECT(textBounds);
sos.writeMatrix(textMatrix);
int glyphBits = 0;
int advanceBits = 0;
for (TEXTRECORD tr : textRecords) {
for (GLYPHENTRY ge : tr.glyphEntries) {
glyphBits = SWFOutputStream.enlargeBitCountU(glyphBits, ge.glyphIndex);
advanceBits = SWFOutputStream.enlargeBitCountS(advanceBits, ge.glyphAdvance);
}
}
sos.writeUI8(glyphBits);
sos.writeUI8(advanceBits);
for (TEXTRECORD tr : textRecords) {
@@ -429,8 +432,8 @@ public class DefineText2Tag extends TextTag implements DrawableTag {
characterID = sis.readUI16();
textBounds = sis.readRECT();
textMatrix = sis.readMatrix();
glyphBits = sis.readUI8();
advanceBits = sis.readUI8();
int glyphBits = sis.readUI8();
int advanceBits = sis.readUI8();
textRecords = new ArrayList<>();
TEXTRECORD tr;
while ((tr = sis.readTEXTRECORD(true, glyphBits, advanceBits)) != null) {

View File

@@ -62,8 +62,6 @@ public class DefineTextTag extends TextTag implements DrawableTag {
public int characterID;
public RECT textBounds;
public MATRIX textMatrix;
public int glyphBits;
public int advanceBits;
public List<TEXTRECORD> textRecords;
public static final int ID = 11;
@@ -159,10 +157,11 @@ public class DefineTextTag extends TextTag implements DrawableTag {
@Override
public boolean setFormattedText(MissingCharacterHandler missingCharHandler, List<Tag> tags, String text, String fontName) throws ParseException {
List<TEXTRECORD> oldTextRecords = textRecords;
try {
TextLexer lexer = new TextLexer(new InputStreamReader(new ByteArrayInputStream(text.getBytes("UTF-8")), "UTF-8"));
ParsedSymbol s = null;
List<TEXTRECORD> textRecords = new ArrayList<>();
textRecords = new ArrayList<>();
RGB color = null;
int fontId = -1;
int textHeight = -1;
@@ -171,8 +170,6 @@ public class DefineTextTag extends TextTag implements DrawableTag {
Integer y = null;
int currentX = 0;
int currentY = 0;
int glyphBits = 0;
int advanceBits = 0;
int maxX = Integer.MIN_VALUE;
int minX = Integer.MAX_VALUE;
MATRIX textMatrix = new MATRIX();
@@ -302,6 +299,7 @@ public class DefineTextTag extends TextTag implements DrawableTag {
throw new ParseException("Font not defined", lexer.yyline());
}
TEXTRECORD tr = new TEXTRECORD();
textRecords.add(tr);
if (fontId > -1) {
tr.fontId = fontId;
tr.textHeight = textHeight;
@@ -327,12 +325,13 @@ public class DefineTextTag extends TextTag implements DrawableTag {
tr.glyphEntries = new GLYPHENTRY[txt.length()];
for (int i = 0; i < txt.length(); i++) {
char c = txt.charAt(i);
tr.glyphEntries[i] = new GLYPHENTRY();
if (!font.containsChar(tags, c)) {
if (!missingCharHandler.handle(font, tags, c)) {
return false;
}
}
tr.glyphEntries[i] = new GLYPHENTRY();
tr.glyphEntries[i].glyphIndex = font.charToGlyph(tags, c);
int advance;
@@ -344,15 +343,9 @@ public class DefineTextTag extends TextTag implements DrawableTag {
tr.glyphEntries[i].glyphAdvance = advance;
currentX += advance;
if (SWFOutputStream.getNeededBitsU(tr.glyphEntries[i].glyphIndex) > glyphBits) {
glyphBits = SWFOutputStream.getNeededBitsU(tr.glyphEntries[i].glyphIndex);
}
if (SWFOutputStream.getNeededBitsS(tr.glyphEntries[i].glyphAdvance) > advanceBits) {
advanceBits = SWFOutputStream.getNeededBitsS(tr.glyphEntries[i].glyphAdvance);
}
}
textRecords.add(tr);
if (currentX > maxX) {
maxX = currentX;
}
@@ -363,9 +356,6 @@ public class DefineTextTag extends TextTag implements DrawableTag {
}
}
this.advanceBits = advanceBits;
this.glyphBits = glyphBits;
this.textRecords = textRecords;
this.textMatrix = textMatrix;
this.textBounds = textBounds;
//this.textBounds.Xmin = minX;
@@ -373,7 +363,11 @@ public class DefineTextTag extends TextTag implements DrawableTag {
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(DefineTextTag.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
textRecords = oldTextRecords;
return false;
} catch (ParseException ex) {
textRecords = oldTextRecords;
throw ex;
}
return true;
}
@@ -383,13 +377,11 @@ public class DefineTextTag extends TextTag implements DrawableTag {
return characterID;
}
public DefineTextTag(SWF swf, int characterID, RECT textBounds, MATRIX textMatrix, int glyphBits, int advanceBits, List<TEXTRECORD> textRecords) {
public DefineTextTag(SWF swf, int characterID, RECT textBounds, MATRIX textMatrix, List<TEXTRECORD> textRecords) {
super(swf, ID, "DefineText", new byte[0], 0);
this.characterID = characterID;
this.textBounds = textBounds;
this.textMatrix = textMatrix;
this.glyphBits = glyphBits;
this.advanceBits = advanceBits;
this.textRecords = textRecords;
}
@@ -408,6 +400,16 @@ public class DefineTextTag extends TextTag implements DrawableTag {
sos.writeUI16(characterID);
sos.writeRECT(textBounds);
sos.writeMatrix(textMatrix);
int glyphBits = 0;
int advanceBits = 0;
for (TEXTRECORD tr : textRecords) {
for (GLYPHENTRY ge : tr.glyphEntries) {
glyphBits = SWFOutputStream.enlargeBitCountU(glyphBits, ge.glyphIndex);
advanceBits = SWFOutputStream.enlargeBitCountS(advanceBits, ge.glyphAdvance);
}
}
sos.writeUI8(glyphBits);
sos.writeUI8(advanceBits);
for (TEXTRECORD tr : textRecords) {
@@ -434,8 +436,8 @@ public class DefineTextTag extends TextTag implements DrawableTag {
characterID = sis.readUI16();
textBounds = sis.readRECT();
textMatrix = sis.readMatrix();
glyphBits = sis.readUI8();
advanceBits = sis.readUI8();
int glyphBits = sis.readUI8();
int advanceBits = sis.readUI8();
textRecords = new ArrayList<>();
TEXTRECORD tr;
while ((tr = sis.readTEXTRECORD(false, glyphBits, advanceBits)) != null) {

View File

@@ -23,7 +23,6 @@ import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.helpers.Helper;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

View File

@@ -128,6 +128,9 @@ public abstract class FontTag extends CharacterTag implements AloneTag {
continue;
}
for (GLYPHENTRY en : tr.glyphEntries) {
if (en == null) { //Currently edited
continue;
}
if (en.glyphIndex >= startIndex) {
en.glyphIndex++;
}