diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index b745ff391..b0e905291 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -212,6 +212,7 @@ public final class SWF { public HashMap characters; public List abcList; public JPEGTablesTag jtt; + public Map sourceFontsMap = new HashMap<>(); /** * Gets all tags with specified id diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java index 7d3726a65..4a5bb1142 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.gui; import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.FontTag; import com.jpexs.decompiler.flash.tags.base.TextTag; @@ -32,8 +33,6 @@ import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; -import java.util.HashMap; -import java.util.Map; import java.util.Set; import java.util.TreeSet; import javax.swing.Box; @@ -59,8 +58,6 @@ public class FontPanel extends JPanel implements ActionListener { private MainPanel mainPanel; - public Map sourceFontsMap = new HashMap<>(); - private JLabel fontNameLabel; private JLabel fontIsBoldLabel; private JLabel fontIsItalicLabel; @@ -180,16 +177,17 @@ public class FontPanel extends JPanel implements ActionListener { fontParams1.add(fontAddCharsPanel); JPanel fontSelectionPanel = new JPanel(new FlowLayout()); fontSelectionPanel.add(new JLabel(translate("font.source"))); - fontSelection = new JComboBox<>(FontTag.fontNames.toArray(new String[FontTag.fontNames.size()])); - fontSelection.setSelectedIndex(0); - fontSelection.setSelectedItem("Times New Roman"); - fontSelection.setSelectedItem("Arial"); + fontSelection = new JComboBox<>(FontTag.fontNamesArray); + fontSelection.setSelectedItem(FontTag.defaultFontName); fontSelection.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (mainPanel.oldTag instanceof FontTag) { FontTag f = (FontTag) mainPanel.oldTag; - sourceFontsMap.put(f.getFontId(), (String) fontSelection.getSelectedItem()); + SWF swf = f.getSwf(); + String selectedSystemFont = (String) fontSelection.getSelectedItem(); + swf.sourceFontsMap.put(f.getFontId(), selectedSystemFont); + Configuration.addFontPair(f.getFontName(swf.tags), selectedSystemFont); } } }); @@ -282,8 +280,10 @@ public class FontPanel extends JPanel implements ActionListener { fontLeadingLabel.setText(ft.getLeading() == -1 ? translate("value.unknown") : "" + ft.getLeading()); String chars = ft.getCharacters(swf.tags); fontCharactersTextArea.setText(chars); - if (sourceFontsMap.containsKey(ft.getFontId())) { - fontSelection.setSelectedItem(sourceFontsMap.get(ft.getFontId())); + if (swf.sourceFontsMap.containsKey(ft.getFontId())) { + fontSelection.setSelectedItem(swf.sourceFontsMap.get(ft.getFontId())); + } else if (Configuration.getFontPairs().containsKey(ft.getFontName(swf.tags))) { + fontSelection.setSelectedItem(Configuration.getFontPairs().get(ft.getFontName(swf.tags))); } else { fontSelection.setSelectedItem(FontTag.findInstalledFontName(ft.getFontName(swf.tags))); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java index 59a2014a3..91d2c27aa 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java @@ -35,7 +35,6 @@ import java.util.Timer; import java.util.TimerTask; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JCheckBoxMenuItem; import javax.swing.JOptionPane; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java index db67f5921..bc9f6d628 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -1977,7 +1977,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec if (textTag.setFormattedText(new MissingCharacterHandler() { @Override public boolean handle(FontTag font, List tags, char character) { - String fontName = fontPanel.sourceFontsMap.get(font.getFontId()); + String fontName = font.getSwf().sourceFontsMap.get(font.getFontId()); if (fontName == null) { fontName = font.getFontName(tags); } @@ -1991,7 +1991,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec return true; } - }, textTag.getSwf().tags, text, fontPanel.getSelectedFont())) { + }, textTag.getSwf().tags, text)) { return true; } } catch (ParseException ex) { diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java index 1266db370..4c46964dc 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java @@ -163,7 +163,7 @@ public class DefineEditTextTag extends TextTag { } @Override - public boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text, String fontName) throws ParseException { + public boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text) throws ParseException { try { TextLexer lexer = new TextLexer(new StringReader(text)); ParsedSymbol s = null; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java index 19421cba5..17885dd15 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java @@ -153,7 +153,7 @@ public class DefineText2Tag extends TextTag implements DrawableTag { } @Override - public boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text, String fontName) throws ParseException { + public boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text) throws ParseException { List oldTextRecords = textRecords; try { TextLexer lexer = new TextLexer(new StringReader(text)); @@ -163,6 +163,7 @@ public class DefineText2Tag extends TextTag implements DrawableTag { int fontId = -1; int textHeight = -1; FontTag font = null; + String fontName = null; Integer x = null; Integer y = null; int currentX = 0; @@ -195,6 +196,7 @@ public class DefineText2Tag extends TextTag implements DrawableTag { if (t instanceof FontTag) { if (((FontTag) t).getFontId() == fontId) { font = (FontTag) t; + fontName = font.getSystemFontName(tags); break; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java index df42f2c70..78c6d7674 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java @@ -153,7 +153,7 @@ public class DefineTextTag extends TextTag implements DrawableTag { } @Override - public boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text, String fontName) throws ParseException { + public boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text) throws ParseException { List oldTextRecords = textRecords; try { TextLexer lexer = new TextLexer(new StringReader(text)); @@ -163,6 +163,7 @@ public class DefineTextTag extends TextTag implements DrawableTag { int fontId = -1; int textHeight = -1; FontTag font = null; + String fontName = null; Integer x = null; Integer y = null; int currentX = 0; @@ -195,6 +196,7 @@ public class DefineTextTag extends TextTag implements DrawableTag { if (t instanceof FontTag) { if (((FontTag) t).getFontId() == fontId) { font = (FontTag) t; + fontName = font.getSystemFontName(tags); break; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java index 6a8b63e61..e91b1cc05 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.tags.base; import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.tags.DefineText2Tag; import com.jpexs.decompiler.flash.tags.DefineTextTag; import com.jpexs.decompiler.flash.tags.Tag; @@ -37,6 +38,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Stack; /** @@ -118,6 +120,15 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable return name + " (" + getCharacterId() + nameAppend + ")"; } + public String getSystemFontName(List tags) { + Map fontPairs = Configuration.getFontPairs(); + String name = getFontName(tags); + if (fontPairs.containsKey(name)) { + return fontPairs.get(name); + } + return defaultFontName; + } + public static void shiftGlyphIndices(int fontId, int startIndex, List tags) { List textRecords = new ArrayList<>(); for (Tag t : tags) { @@ -156,7 +167,20 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable GlyphMetrics gm = gv.getGlyphMetrics(0); return gm.getAdvanceX(); } - public static List fontNames = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()); + + public static final String[] fontNamesArray = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); + public static final List fontNames = Arrays.asList(fontNamesArray); + public static final String defaultFontName; + + static { + if (fontNames.contains("Times New Roman")) { + defaultFontName = "Times New Roman"; + } else if (fontNames.contains("Arial")) { + defaultFontName = "Arial"; + } else { + defaultFontName = fontNames.get(0); + } + } public static String isFontInstalled(String fontName) { if (fontNames.contains(fontName)) { @@ -181,15 +205,7 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable return beforeUnderscore; } } - fontName = "Times New Roman"; - if (fontNames.contains(fontName)) { - return fontName; - } - fontName = "Arial"; - if (fontNames.contains(fontName)) { - return fontName; - } - return fontNames.get(0); + return defaultFontName; } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java index f8f18b587..9467e51d9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -56,7 +56,7 @@ public abstract class TextTag extends CharacterTag implements BoundedTag { public abstract String getFormattedText(List tags); - public abstract boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text, String fontName) throws ParseException; + public abstract boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text) throws ParseException; @Override public abstract int getCharacterId();