mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 11:10:56 +00:00
better text tags editing
This commit is contained in:
@@ -86,6 +86,7 @@ import java.awt.CardLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
@@ -104,6 +105,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
@@ -173,6 +175,9 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
|
||||
private JPanel searchPanel;
|
||||
private JCheckBoxMenuItem autoDeobfuscateMenuItem;
|
||||
private JPanel displayWithPreview;
|
||||
private JButton textSaveButton;
|
||||
private JButton textEditButton;
|
||||
private JButton textCancelButton;
|
||||
|
||||
public void setPercent(int percent) {
|
||||
progressBar.setValue(percent);
|
||||
@@ -484,16 +489,37 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
|
||||
List<Object> list2 = new ArrayList<Object>();
|
||||
list2.addAll(swf.tags);
|
||||
parseCharacters(list2);
|
||||
|
||||
|
||||
JPanel textPanel = new JPanel(new BorderLayout());
|
||||
textPanel.add(textValue, BorderLayout.CENTER);
|
||||
JButton textSaveButton = new JButton("Save text", View.getIcon("save16"));
|
||||
textPanel.add(textSaveButton, BorderLayout.EAST);
|
||||
textValue.setEditable(false);
|
||||
|
||||
JPanel buttonsPanel = new JPanel();
|
||||
buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
|
||||
|
||||
|
||||
textSaveButton = new JButton("Save", View.getIcon("save16"));
|
||||
textSaveButton.setMargin(new Insets(3, 3, 3, 10));
|
||||
textSaveButton.setActionCommand("SAVETEXT");
|
||||
textSaveButton.addActionListener(this);
|
||||
|
||||
textEditButton = new JButton("Edit", View.getIcon("edit16"));
|
||||
textEditButton.setMargin(new Insets(3, 3, 3, 10));
|
||||
textEditButton.setActionCommand("EDITTEXT");
|
||||
textEditButton.addActionListener(this);
|
||||
|
||||
textCancelButton = new JButton("Cancel", View.getIcon("cancel16"));
|
||||
textCancelButton.setMargin(new Insets(3, 3, 3, 10));
|
||||
textCancelButton.setActionCommand("CANCELTEXT");
|
||||
textCancelButton.addActionListener(this);
|
||||
|
||||
buttonsPanel.add(textEditButton);
|
||||
buttonsPanel.add(textSaveButton);
|
||||
buttonsPanel.add(textCancelButton);
|
||||
|
||||
textSaveButton.setVisible(false);
|
||||
textCancelButton.setVisible(false);
|
||||
|
||||
textPanel.add(buttonsPanel, BorderLayout.EAST);
|
||||
|
||||
displayWithPreview = new JPanel(new CardLayout());
|
||||
displayWithPreview.add(textPanel, CARDTEXTPANEL);
|
||||
@@ -1063,11 +1089,17 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
|
||||
refreshTree();
|
||||
}
|
||||
}
|
||||
if (e.getActionCommand().equals("EDITTEXT")) {
|
||||
setEditText(true);
|
||||
}
|
||||
if (e.getActionCommand().equals("CANCELTEXT")) {
|
||||
setEditText(false);
|
||||
}
|
||||
if (e.getActionCommand().equals("SAVETEXT")) {
|
||||
if (oldValue instanceof TextTag) {
|
||||
try {
|
||||
((TextTag) oldValue).setFormattedText(swf.tags, textValue.getText());
|
||||
reload(true);
|
||||
setEditText(false);
|
||||
} catch (ParseException ex) {
|
||||
JOptionPane.showMessageDialog(null, "Invalid text: " + ex.text + " on line " + ex.line, "Error", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
@@ -1477,6 +1509,7 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
|
||||
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
setEditText(false);
|
||||
reload(false);
|
||||
}
|
||||
|
||||
@@ -1755,4 +1788,14 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi
|
||||
objs.addAll(swf.tags);
|
||||
tagTree.setModel(new TagTreeModel(createTagList(objs, null), (new File(Main.file)).getName()));
|
||||
}
|
||||
|
||||
public void setEditText(boolean edit) {
|
||||
textValue.setEditable(edit);
|
||||
textSaveButton.setVisible(edit);
|
||||
textEditButton.setVisible(!edit);
|
||||
textCancelButton.setVisible(edit);
|
||||
if (!edit) {
|
||||
reload(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,11 @@ public class DefineFont2Tag extends CharacterTag implements FontTag {
|
||||
public RECT fontBoundsTable[];
|
||||
public KERNINGRECORD fontKerningTable[];
|
||||
|
||||
@Override
|
||||
public int getGlyphWidth(int glyphIndex) {
|
||||
return glyphShapeTable[glyphIndex].getBounds().getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGlyphAdvance(int glyphIndex) {
|
||||
if (fontFlagsHasLayout) {
|
||||
|
||||
@@ -57,6 +57,11 @@ public class DefineFont3Tag extends CharacterTag implements FontTag {
|
||||
public RECT fontBoundsTable[];
|
||||
public KERNINGRECORD fontKerningTable[];
|
||||
|
||||
@Override
|
||||
public int getGlyphWidth(int glyphIndex) {
|
||||
return glyphShapeTable[glyphIndex].getBounds().getWidth() / 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGlyphAdvance(int glyphIndex) {
|
||||
if (fontFlagsHasLayout) {
|
||||
|
||||
@@ -41,6 +41,11 @@ public class DefineFontTag extends CharacterTag implements FontTag {
|
||||
|
||||
@Override
|
||||
public int getGlyphAdvance(int glyphIndex) {
|
||||
return getGlyphWidth(glyphIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGlyphWidth(int glyphIndex) {
|
||||
return glyphShapeTable[glyphIndex].getBounds().getWidth();
|
||||
}
|
||||
|
||||
|
||||
@@ -122,15 +122,19 @@ public class DefineText2Tag extends CharacterTag implements BoundedTag, TextTag
|
||||
try {
|
||||
TextLexer lexer = new TextLexer(new InputStreamReader(new ByteArrayInputStream(text.getBytes("UTF-8")), "UTF-8"));
|
||||
ParsedSymbol s = null;
|
||||
textRecords = new ArrayList<TEXTRECORD>();
|
||||
List<TEXTRECORD> textRecords = new ArrayList<TEXTRECORD>();
|
||||
RGBA colorA = null;
|
||||
int fontId = -1;
|
||||
int textHeight = -1;
|
||||
FontTag font = null;
|
||||
Integer x = null;
|
||||
Integer y = null;
|
||||
glyphBits = 0;
|
||||
advanceBits = 0;
|
||||
int currentX = 0;
|
||||
int currentY = 0;
|
||||
int glyphBits = 0;
|
||||
int advanceBits = 0;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int minX = Integer.MAX_VALUE;
|
||||
while ((s = lexer.yylex()) != null) {
|
||||
switch (s.type) {
|
||||
case COLOR:
|
||||
@@ -153,9 +157,17 @@ public class DefineText2Tag extends CharacterTag implements BoundedTag, TextTag
|
||||
break;
|
||||
case X:
|
||||
x = (Integer) s.values[0];
|
||||
currentX = x;
|
||||
if (currentX < minX) {
|
||||
minX = currentX;
|
||||
}
|
||||
if (currentX > maxX) {
|
||||
maxX = currentX;
|
||||
}
|
||||
break;
|
||||
case Y:
|
||||
y = (Integer) s.values[0];
|
||||
currentY = y;
|
||||
break;
|
||||
case TEXT:
|
||||
if (font == null) {
|
||||
@@ -189,10 +201,20 @@ public class DefineText2Tag extends CharacterTag implements BoundedTag, TextTag
|
||||
char c = txt.charAt(i);
|
||||
tr.glyphEntries[i] = new GLYPHENTRY();
|
||||
tr.glyphEntries[i].glyphIndex = font.charToGlyph(tags, c);
|
||||
|
||||
|
||||
|
||||
if (tr.glyphEntries[i].glyphIndex == -1) {
|
||||
throw new ParseException("Font does not contain glyph for character '" + c + "'", lexer.yyline());
|
||||
}
|
||||
tr.glyphEntries[i].glyphAdvance = textHeight * font.getGlyphAdvance(tr.glyphEntries[i].glyphIndex) / 1024;
|
||||
|
||||
int gw = textHeight * font.getGlyphWidth(tr.glyphEntries[i].glyphIndex) / 1024;
|
||||
if (i == 0) {
|
||||
currentX += gw;
|
||||
} else {
|
||||
currentX += tr.glyphEntries[i].glyphAdvance;
|
||||
}
|
||||
if (SWFOutputStream.getNeededBitsS(tr.glyphEntries[i].glyphIndex) > glyphBits) {
|
||||
glyphBits = SWFOutputStream.getNeededBitsS(tr.glyphEntries[i].glyphIndex);
|
||||
}
|
||||
@@ -202,10 +224,21 @@ public class DefineText2Tag extends CharacterTag implements BoundedTag, TextTag
|
||||
|
||||
}
|
||||
textRecords.add(tr);
|
||||
if (currentX > maxX) {
|
||||
maxX = currentX;
|
||||
}
|
||||
if (currentX < minX) {
|
||||
minX = currentX;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
this.advanceBits = advanceBits;
|
||||
this.glyphBits = glyphBits;
|
||||
this.textRecords = textRecords;
|
||||
this.textBounds.Xmin = minX;
|
||||
this.textBounds.Xmax = maxX;
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException ex) {
|
||||
|
||||
@@ -117,15 +117,19 @@ public class DefineTextTag extends CharacterTag implements BoundedTag, TextTag {
|
||||
try {
|
||||
TextLexer lexer = new TextLexer(new InputStreamReader(new ByteArrayInputStream(text.getBytes("UTF-8")), "UTF-8"));
|
||||
ParsedSymbol s = null;
|
||||
textRecords = new ArrayList<TEXTRECORD>();
|
||||
List<TEXTRECORD> textRecords = new ArrayList<TEXTRECORD>();
|
||||
RGB color = null;
|
||||
int fontId = -1;
|
||||
int textHeight = -1;
|
||||
FontTag font = null;
|
||||
Integer x = null;
|
||||
Integer y = null;
|
||||
glyphBits = 0;
|
||||
advanceBits = 0;
|
||||
int currentX = 0;
|
||||
int currentY = 0;
|
||||
int glyphBits = 0;
|
||||
int advanceBits = 0;
|
||||
int maxX = Integer.MIN_VALUE;
|
||||
int minX = Integer.MAX_VALUE;
|
||||
while ((s = lexer.yylex()) != null) {
|
||||
switch (s.type) {
|
||||
case COLOR:
|
||||
@@ -148,9 +152,17 @@ public class DefineTextTag extends CharacterTag implements BoundedTag, TextTag {
|
||||
break;
|
||||
case X:
|
||||
x = (Integer) s.values[0];
|
||||
currentX = x;
|
||||
if (currentX < minX) {
|
||||
minX = currentX;
|
||||
}
|
||||
if (currentX > maxX) {
|
||||
maxX = currentX;
|
||||
}
|
||||
break;
|
||||
case Y:
|
||||
y = (Integer) s.values[0];
|
||||
currentY = y;
|
||||
break;
|
||||
case TEXT:
|
||||
if (font == null) {
|
||||
@@ -184,10 +196,20 @@ public class DefineTextTag extends CharacterTag implements BoundedTag, TextTag {
|
||||
char c = txt.charAt(i);
|
||||
tr.glyphEntries[i] = new GLYPHENTRY();
|
||||
tr.glyphEntries[i].glyphIndex = font.charToGlyph(tags, c);
|
||||
|
||||
|
||||
|
||||
if (tr.glyphEntries[i].glyphIndex == -1) {
|
||||
throw new ParseException("Font does not contain glyph for character '" + c + "'", lexer.yyline());
|
||||
}
|
||||
tr.glyphEntries[i].glyphAdvance = textHeight * font.getGlyphAdvance(tr.glyphEntries[i].glyphIndex) / 1024;
|
||||
|
||||
int gw = textHeight * font.getGlyphWidth(tr.glyphEntries[i].glyphIndex) / 1024;
|
||||
if (i == 0) {
|
||||
currentX += gw;
|
||||
} else {
|
||||
currentX += tr.glyphEntries[i].glyphAdvance;
|
||||
}
|
||||
if (SWFOutputStream.getNeededBitsS(tr.glyphEntries[i].glyphIndex) > glyphBits) {
|
||||
glyphBits = SWFOutputStream.getNeededBitsS(tr.glyphEntries[i].glyphIndex);
|
||||
}
|
||||
@@ -197,10 +219,21 @@ public class DefineTextTag extends CharacterTag implements BoundedTag, TextTag {
|
||||
|
||||
}
|
||||
textRecords.add(tr);
|
||||
if (currentX > maxX) {
|
||||
maxX = currentX;
|
||||
}
|
||||
if (currentX < minX) {
|
||||
minX = currentX;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
this.advanceBits = advanceBits;
|
||||
this.glyphBits = glyphBits;
|
||||
this.textRecords = textRecords;
|
||||
this.textBounds.Xmin = minX;
|
||||
this.textBounds.Xmax = maxX;
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException ex) {
|
||||
|
||||
@@ -35,4 +35,6 @@ public interface FontTag extends AloneTag {
|
||||
public int charToGlyph(List<Tag> tags, char c);
|
||||
|
||||
public int getGlyphAdvance(int glyphIndex);
|
||||
|
||||
public int getGlyphWidth(int glyphIndex);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -53,7 +53,7 @@ public class RECT {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[RECT x=" + Xmin + "-" + Xmax + ", y=" + Ymin + "-" + Ymax + "]";
|
||||
return "[RECT x=" + Xmin + " to " + Xmax + ", y=" + Ymin + " to " + Ymax + "]";
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
|
||||
Reference in New Issue
Block a user