setting for updateing the test bounds

This commit is contained in:
honfika@gmail.com
2014-12-21 13:23:34 +01:00
parent fdfb143f89
commit edc43f0d18
14 changed files with 198 additions and 24 deletions

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.configuration;
import com.jpexs.decompiler.flash.ApplicationInfo;
import com.jpexs.decompiler.flash.helpers.CodeFormatting;
import com.jpexs.decompiler.flash.importers.TextImportResizeTextBoundsMode;
import com.jpexs.helpers.Helper;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -305,6 +306,9 @@ public class Configuration {
@ConfigurationCategory("export")
public static final ConfigurationItem<String> textExportSingleFileRecordSeparator = null;
@ConfigurationCategory("import")
public static final ConfigurationItem<TextImportResizeTextBoundsMode> textImportResizeTextBoundsMode = null;
@ConfigurationDefaultBoolean(true)
@ConfigurationName("warning.experimental.as12edit")
@ConfigurationCategory("script")

View File

@@ -0,0 +1,26 @@
/*
* 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;
/**
*
* @author JPEXS
*/
public enum TextImportResizeTextBoundsMode {
NO_RESIZE, GROW_ONLY, GROW_AND_SHRINK
}

View File

@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.tags;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.exporters.commonshape.ExportRectangle;
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
import com.jpexs.decompiler.flash.tags.base.BoundedTag;
@@ -794,14 +795,15 @@ public class DefineEditTextTag extends TextTag {
}
private String render(boolean canvas, SerializableImage image, Matrix transformation, ColorTransform colorTransform) {
if (image == null) {
return ""; //TODO: handle Html Canvas conversion
}
if (border) {
// border is always black, fill color is always white?
RGB borderColor = new RGBA(Color.black);
RGB fillColor = new RGBA(Color.white);
drawBorder(swf, image, borderColor, fillColor, getRect(new HashSet<BoundedTag>()), getTextMatrix(), transformation, colorTransform);
if (!canvas) {
drawBorder(swf, image, borderColor, fillColor, getRect(new HashSet<BoundedTag>()), getTextMatrix(), transformation, colorTransform);
} else {
// TODO: draw border
}
}
if (hasText) {
DynamicTextModel textModel = new DynamicTextModel();
@@ -858,7 +860,7 @@ public class DefineEditTextTag extends TextTag {
prevChar = c;
}
textModel.calculateTexWidths();
textModel.calculateTextWidths();
List<List<SameStyleTextRecord>> lines;
if (multiline && wordWrap) {
lines = new ArrayList<>();
@@ -913,7 +915,7 @@ public class DefineEditTextTag extends TextTag {
}
}
textModel.calculateTexWidths();
textModel.calculateTextWidths();
List<TEXTRECORD> allTextRecords = new ArrayList<>();
int yOffset = 0;
@@ -970,9 +972,14 @@ public class DefineEditTextTag extends TextTag {
}
}
staticTextToImage(swf, allTextRecords, 2, image, getTextMatrix(), transformation, colorTransform);
if (canvas) {
return staticTextToHtmlCanvas(1, swf, allTextRecords, 2, getBounds(), getTextMatrix(), colorTransform);
} else {
staticTextToImage(swf, allTextRecords, 2, image, getTextMatrix(), transformation, colorTransform);
}
}
return ""; //TODO: Return HTML Canvas converted
return "";
}
@Override
@@ -980,6 +987,11 @@ public class DefineEditTextTag extends TextTag {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ExportRectangle calculateTextBounds() {
return null;
}
private FontTag getFontTag() {
FontTag font = null;
for (Tag tag : swf.tags) {

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.commonshape.ExportRectangle;
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
import com.jpexs.decompiler.flash.tags.base.BoundedTag;
@@ -431,6 +432,7 @@ public class DefineText2Tag extends TextTag {
throw ex;
}
updateTextBounds(textBounds);
return true;
}
@@ -556,6 +558,11 @@ public class DefineText2Tag extends TextTag {
staticTextToSVG(swf, textRecords, 2, exporter, getRect(new HashSet<BoundedTag>()), getTextMatrix(), colorTransform, zoom);
}
@Override
public ExportRectangle calculateTextBounds() {
return calculateTextBounds(swf, textRecords, getTextMatrix());
}
@Override
public int getNumFrames() {
return 1;

View File

@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.commonshape.ExportRectangle;
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
import com.jpexs.decompiler.flash.tags.base.BoundedTag;
@@ -440,6 +441,7 @@ public class DefineTextTag extends TextTag {
throw ex;
}
updateTextBounds(textBounds);
return true;
}
@@ -575,6 +577,11 @@ public class DefineTextTag extends TextTag {
staticTextToSVG(swf, textRecords, 1, exporter, getRect(new HashSet<BoundedTag>()), getTextMatrix(), colorTransform, zoom);
}
@Override
public ExportRectangle calculateTextBounds() {
return calculateTextBounds(swf, textRecords, getTextMatrix());
}
@Override
public int getNumFrames() {
return 1;

View File

@@ -17,13 +17,16 @@
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.exporters.FontExporter;
import com.jpexs.decompiler.flash.exporters.commonshape.ExportRectangle;
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
import com.jpexs.decompiler.flash.exporters.modes.FontExportMode;
import com.jpexs.decompiler.flash.exporters.shape.BitmapExporter;
import com.jpexs.decompiler.flash.exporters.shape.CanvasShapeExporter;
import com.jpexs.decompiler.flash.exporters.shape.SVGShapeExporter;
import com.jpexs.decompiler.flash.importers.TextImportResizeTextBoundsMode;
import com.jpexs.decompiler.flash.tags.Tag;
import com.jpexs.decompiler.flash.tags.text.TextParseException;
import com.jpexs.decompiler.flash.timeline.DepthState;
@@ -90,6 +93,8 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
public abstract void setBounds(RECT r);
public abstract ExportRectangle calculateTextBounds();
private static void updateRect(RECT ret, int x, int y) {
if (x < ret.Xmin) {
ret.Xmin = x;
@@ -317,6 +322,77 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
}
}
public static ExportRectangle calculateTextBounds(SWF swf, List<TEXTRECORD> textRecords, MATRIX textMatrix) {
FontTag font = null;
int textHeight = 12;
int x = 0;
int y = 0;
List<SHAPE> glyphs = new ArrayList<>();
ExportRectangle result = null;
for (TEXTRECORD rec : textRecords) {
if (rec.styleFlagsHasFont) {
font = (FontTag) swf.characters.get(rec.fontId);
glyphs = font == null ? null : font.getGlyphShapeTable();
textHeight = rec.textHeight;
}
if (rec.styleFlagsHasXOffset) {
x = rec.xOffset;
}
if (rec.styleFlagsHasYOffset) {
y = rec.yOffset;
}
double rat = textHeight / 1024.0 / (font == null ? 1 : font.getDivider());
for (GLYPHENTRY entry : rec.glyphEntries) {
Matrix mat = new Matrix();
mat = mat.concatenate(new Matrix(textMatrix));
Matrix matTr = Matrix.getTranslateInstance(x, y);
mat = mat.concatenate(matTr);
mat = mat.concatenate(Matrix.getScaleInstance(rat));
if (entry.glyphIndex != -1 && glyphs != null) {
// shapeNum: 1
SHAPE shape = glyphs.get(entry.glyphIndex);
RECT glyphBounds = shape.getBounds();
ExportRectangle rect = mat.transform(new ExportRectangle(glyphBounds));
if (result == null) {
result = rect;
} else {
result.xMin = Math.min(result.xMin, rect.xMin);
result.yMin = Math.min(result.yMin, rect.yMin);
result.xMax = Math.max(result.xMax, rect.xMax);
result.yMax = Math.max(result.yMax, rect.yMax);
}
x += entry.glyphAdvance;
}
}
}
return result;
}
public void updateTextBounds(RECT textBounds) {
TextImportResizeTextBoundsMode resizeMode = Configuration.textImportResizeTextBoundsMode.get();
if (resizeMode.equals(TextImportResizeTextBoundsMode.GROW_ONLY) || resizeMode.equals(TextImportResizeTextBoundsMode.GROW_AND_SHRINK)) {
ExportRectangle newBounds = calculateTextBounds();
int xMin = (int) Math.floor(newBounds.xMin);
int yMin = (int) Math.floor(newBounds.yMin);
int xMax = (int) Math.ceil(newBounds.xMax);
int yMax = (int) Math.ceil(newBounds.yMax);
if (resizeMode.equals(TextImportResizeTextBoundsMode.GROW_ONLY)) {
textBounds.Xmin = Math.min(xMin, textBounds.Xmin);
textBounds.Ymin = Math.min(yMin, textBounds.Ymin);
textBounds.Xmax = Math.max(xMax, textBounds.Xmax);
textBounds.Ymax = Math.max(yMax, textBounds.Ymax);
} else if (resizeMode.equals(TextImportResizeTextBoundsMode.GROW_AND_SHRINK)) {
textBounds.Xmin = xMin;
textBounds.Ymin = yMin;
textBounds.Xmax = xMax;
textBounds.Ymax = yMax;
}
}
}
public static String staticTextToHtmlCanvas(double unitDivisor, SWF swf, List<TEXTRECORD> textRecords, int numText, RECT bounds, MATRIX textMatrix, ColorTransform colorTransform) {
int textColor = 0;
String ret = "";

View File

@@ -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.tags.dynamictext;
import com.jpexs.decompiler.flash.types.GLYPHENTRY;
@@ -64,11 +65,11 @@ public class DynamicTextModel {
}
}
public int calculateTextWidths() {
int width = 0;
for (Paragraph p : paragraphs) {
for (Paragraph p : paragraphs) {
width += p.calculateTextWidths();
}
this.width = width;
return width;

View File

@@ -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.tags.dynamictext;
import com.jpexs.decompiler.flash.types.GLYPHENTRY;
@@ -58,11 +59,11 @@ public class Paragraph {
}
}
public int calculateTextWidths() {
int width = 0;
for (Word w : words) {
for (Word w : words) {
width += w.calculateTextWidths();
}
this.width = width;
return width;

View File

@@ -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.tags.dynamictext;
import java.util.ArrayList;
@@ -33,7 +34,7 @@ public class SameStyleTextRecord {
public List<GlyphCharacter> glyphEntries = new ArrayList<>();
public int calculateTextWidths() {
int width = 0;
for (GlyphCharacter gc : glyphEntries) {

View File

@@ -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.tags.dynamictext;
import com.jpexs.decompiler.flash.types.GLYPHENTRY;
@@ -51,11 +52,11 @@ public class Word {
record = null;
}
public int calculateTextWidths() {
int width = 0;
for (SameStyleTextRecord r : records) {
for (SameStyleTextRecord r : records) {
width += r.calculateTextWidths();
}
this.width = width;
return width;

View File

@@ -33,6 +33,7 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -40,6 +41,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
@@ -192,7 +194,6 @@ public class AdvancedSettingsDialog extends AppDialog implements ActionListener
val = "";
}
if (itemType == Calendar.class) {
tf.setText(new SimpleDateFormat().format(((Calendar) item.get()).getTime()));
} else {
tf.setText(val.toString());
@@ -200,12 +201,32 @@ public class AdvancedSettingsDialog extends AppDialog implements ActionListener
tf.setToolTipText(description);
tf.setMaximumSize(new Dimension(Integer.MAX_VALUE, tf.getPreferredSize().height));
c = tf;
}
if (itemType == Boolean.class) {
} else if (itemType == Boolean.class) {
JCheckBox cb = new JCheckBox();
cb.setSelected((Boolean) item.get());
cb.setToolTipText(description);
c = cb;
} else if (itemType.isEnum()) {
JComboBox<String> cb = new JComboBox<>();
@SuppressWarnings("unchecked")
EnumSet enumValues = EnumSet.allOf(itemType);
String stringValue = null;
for (Object enumValue : enumValues) {
String enumValueStr = enumValue.toString();
if (stringValue == null) {
stringValue = enumValueStr;
}
cb.addItem(enumValueStr);
}
if (item.get() != null) {
stringValue = item.get().toString();
}
cb.setToolTipText(description);
cb.setSelectedItem(stringValue);
cb.setMaximumSize(new Dimension(Integer.MAX_VALUE, cb.getPreferredSize().height));
c = cb;
} else {
throw new UnsupportedOperationException("Configuration ttem type '" + itemType.getName() + "' is not supported");
}
componentsMap.put(name, c);
l.setLabelFor(c);
@@ -223,7 +244,7 @@ public class AdvancedSettingsDialog extends AppDialog implements ActionListener
tabs.put(cat, new JScrollPane(configPanel));
}
String catOrder[] = new String[]{"ui", "display", "decompilation", "script", "format", "export", "limit", "update", "debug", "other"};
String catOrder[] = new String[]{"ui", "display", "decompilation", "script", "format", "export", "import", "limit", "update", "debug", "other"};
for (String cat : catOrder) {
if (!tabs.containsKey(cat)) {
@@ -291,6 +312,11 @@ public class AdvancedSettingsDialog extends AppDialog implements ActionListener
}
value = cal;
}
if (itemType.isEnum()) {
String stringValue = (String) ((JComboBox<String>) c).getSelectedItem();
value = Enum.valueOf(itemType, stringValue);
}
try {
if (itemType == Integer.class) {

View File

@@ -60,7 +60,7 @@ public class ErrorLogFrame extends AppFrame {
private static ErrorLogFrame instance;
private final JPanel logView = new JPanel();
private JPanel logViewInner = new JPanel();
private final JPanel logViewInner = new JPanel();
private final Handler handler;
private final ImageIcon expandIcon;
private final ImageIcon collapseIcon;

View File

@@ -299,3 +299,9 @@ config.description.overrideTextExportFileName = You can customite the filename o
config.name.showOldTextDuringTextEditing = Show old text during text editing
config.description.showOldTextDuringTextEditing = Shows the original text of the text tag with gray color in the preview area.
config.group.name.import = Import
config.group.description.import = Configuration of imports
config.name.textImportResizeTextBoundsMode = Text bounds resize mode
config.description.textImportResizeTextBoundsMode = Text bounds resize mode after text editing.

View File

@@ -299,3 +299,9 @@ config.description.overrideTextExportFileName = Szem\u00e9lyre szabhatod a nev\u
config.name.showOldTextDuringTextEditing = R\u00e9gi sz\u00f6veg mutat\u00e1sa sz\u00f6veg szerkeszt\u00e9sekor
config.description.showOldTextDuringTextEditing = Mutatja az eredeti sz\u00f6veget sz\u00fcrke sz\u00ednnel az el\u0151n\u00e9zeti ablakban szerkeszt\u00e9s k\u00f6zben.
config.group.name.import = Import\u00e1l\u00e1s
config.group.description.import = Import\u00e1l\u00e1s be\u00e1ll\u00edt\u00e1sai
config.name.textImportResizeTextBoundsMode = Sz\u00f6veg hat\u00e1r \u00e1tm\u00e9retez\u00e9se
config.description.textImportResizeTextBoundsMode = Sz\u00f6veg hat\u00e1r \u00e1tm\u00e9retez\u00e9se sz\u00f6veg m\u00f3dos\u00edt\u00e1sa ut\u00e1n.