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;