#809 autogwow when button is hold, justify align fixes

This commit is contained in:
honfika@gmail.com
2015-02-28 20:35:26 +01:00
parent a9a1e8c5fd
commit ca30321d08
15 changed files with 223 additions and 57 deletions

View File

@@ -2868,9 +2868,9 @@ public class SWFInputStream implements AutoCloseable {
ret.textHeight = readUI16("textHeight");
}
int glyphCount = readUI8("glyphCount");
ret.glyphEntries = new GLYPHENTRY[glyphCount];
ret.glyphEntries = new ArrayList<>(glyphCount);
for (int i = 0; i < glyphCount; i++) {
ret.glyphEntries[i] = readGLYPHENTRY(glyphBits, advanceBits, "glyphEntry");
ret.glyphEntries.add(readGLYPHENTRY(glyphBits, advanceBits, "glyphEntry"));
}
alignByte();
endDumpLevel();

View File

@@ -1471,7 +1471,7 @@ public class SWFOutputStream extends OutputStream {
if (value.styleFlagsHasFont) {
writeUI16(value.textHeight);
}
writeUI8(value.glyphEntries.length);
writeUI8(value.glyphEntries.size());
for (GLYPHENTRY ge : value.glyphEntries) {
writeGLYPHENTRY(ge, glyphBits, advanceBits);
}

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 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.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action;
import com.jpexs.decompiler.flash.DisassemblyListener;
@@ -81,10 +82,9 @@ public class ActionList extends ArrayList<Action> {
}
public Iterator<Action> getReferencesFor(final Action target) {
public Iterator<Action> getReferencesFor(final Action target) {
return new Iterator<Action>() {
private final Iterator<Action> iterator = ActionList.this.iterator();
private Action action = getNext();

View File

@@ -16,7 +16,9 @@
*/
package com.jpexs.decompiler.flash.exporters.swf;
import com.jpexs.decompiler.flash.ApplicationInfo;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.helpers.InternalClass;
import com.jpexs.decompiler.flash.helpers.LazyObject;
import com.jpexs.decompiler.flash.types.annotations.Internal;
import com.jpexs.helpers.ByteArrayRange;
@@ -148,7 +150,12 @@ public class SwfXmlExporter {
((LazyObject) obj).load();
}
String className = obj.getClass().getSimpleName();
Class clazz = obj.getClass();
if (obj instanceof InternalClass) {
clazz = clazz.getSuperclass();
}
String className = clazz.getSimpleName();
List<Field> fields = ReflectionTools.getSwfFields(obj.getClass());
Element objNode = doc.createElement(name);
objNode.setAttribute("type", className);
@@ -156,6 +163,7 @@ public class SwfXmlExporter {
if (level == 0) {
objNode.appendChild(doc.createComment("WARNING: The structure of this XML is not final. In later versions of FFDec it can be changed."));
objNode.appendChild(doc.createComment(ApplicationInfo.applicationVerName));
}
for (Field f : fields) {

View File

@@ -0,0 +1,24 @@
/*
* Copyright (C) 2010-2015 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.helpers;
/**
*
* @author JPEXS
*/
public interface InternalClass {
}

View File

@@ -29,6 +29,7 @@ import com.jpexs.decompiler.flash.tags.base.RenderContext;
import com.jpexs.decompiler.flash.tags.base.TextTag;
import com.jpexs.decompiler.flash.tags.dynamictext.CharacterWithStyle;
import com.jpexs.decompiler.flash.tags.dynamictext.DynamicTextModel;
import com.jpexs.decompiler.flash.tags.dynamictext.GlyphCharacter;
import com.jpexs.decompiler.flash.tags.dynamictext.Paragraph;
import com.jpexs.decompiler.flash.tags.dynamictext.SameStyleTextRecord;
import com.jpexs.decompiler.flash.tags.dynamictext.TextStyle;
@@ -1017,9 +1018,9 @@ public class DefineEditTextTag extends TextTag {
tr2.styleFlagsHasYOffset = true;
tr2.yOffset = yOffset;
}
tr2.glyphEntries = new GLYPHENTRY[tr.glyphEntries.size()];
for (int i = 0; i < tr2.glyphEntries.length; i++) {
tr2.glyphEntries[i] = tr.glyphEntries.get(i).glyphEntry;
tr2.glyphEntries = new ArrayList<>(tr.glyphEntries.size());
for (GlyphCharacter ge : tr.glyphEntries) {
tr2.glyphEntries.add(ge.glyphEntry);
}
allTextRecords.add(tr2);
}

View File

@@ -391,7 +391,7 @@ public class DefineText2Tag extends TextTag {
tr.styleFlagsHasYOffset = true;
y = null;
}
tr.glyphEntries = new GLYPHENTRY[txt.length()];
tr.glyphEntries = new ArrayList<>(txt.length());
for (int i = 0; i < txt.length(); i++) {
char c = txt.charAt(i);
Character nextChar = null;
@@ -399,8 +399,8 @@ public class DefineText2Tag extends TextTag {
nextChar = txt.charAt(i + 1);
}
tr.glyphEntries[i] = new GLYPHENTRY();
tr.glyphEntries[i].glyphIndex = font.charToGlyph(c);
GLYPHENTRY ge = new GLYPHENTRY();
ge.glyphIndex = font.charToGlyph(c);
int advance;
if (font.hasLayout()) {
@@ -408,11 +408,13 @@ public class DefineText2Tag extends TextTag {
if (nextChar != null) {
kerningAdjustment = font.getCharKerningAdjustment(c, nextChar);
}
advance = (int) Math.round(((double) textHeight * (font.getGlyphAdvance(tr.glyphEntries[i].glyphIndex) + kerningAdjustment)) / (font.getDivider() * 1024.0));
advance = (int) Math.round(((double) textHeight * (font.getGlyphAdvance(ge.glyphIndex) + kerningAdjustment)) / (font.getDivider() * 1024.0));
} else {
advance = (int) Math.round(SWF.unitDivisor * FontTag.getSystemFontAdvance(fontName, font.getFontStyle(), (int) (textHeight / SWF.unitDivisor), c, nextChar));
}
tr.glyphEntries[i].glyphAdvance = advance;
ge.glyphAdvance = advance;
tr.glyphEntries.add(ge);
currentX += advance;

View File

@@ -397,7 +397,7 @@ public class DefineTextTag extends TextTag {
tr.styleFlagsHasYOffset = true;
y = null;
}
tr.glyphEntries = new GLYPHENTRY[txt.length()];
tr.glyphEntries = new ArrayList<>(txt.length());
for (int i = 0; i < txt.length(); i++) {
char c = txt.charAt(i);
Character nextChar = null;
@@ -405,8 +405,8 @@ public class DefineTextTag extends TextTag {
nextChar = txt.charAt(i + 1);
}
tr.glyphEntries[i] = new GLYPHENTRY();
tr.glyphEntries[i].glyphIndex = font.charToGlyph(c);
GLYPHENTRY ge = new GLYPHENTRY();
ge.glyphIndex = font.charToGlyph(c);
int advance;
if (font.hasLayout()) {
@@ -414,11 +414,13 @@ public class DefineTextTag extends TextTag {
if (nextChar != null) {
kerningAdjustment = font.getCharKerningAdjustment(c, nextChar);
}
advance = (int) Math.round(((double) textHeight * (font.getGlyphAdvance(tr.glyphEntries[i].glyphIndex) + kerningAdjustment)) / (font.getDivider() * 1024.0));
advance = (int) Math.round(((double) textHeight * (font.getGlyphAdvance(ge.glyphIndex) + kerningAdjustment)) / (font.getDivider() * 1024.0));
} else {
advance = (int) Math.round(SWF.unitDivisor * FontTag.getSystemFontAdvance(fontName, font.getFontStyle(), (int) (textHeight / SWF.unitDivisor), c, nextChar));
}
tr.glyphEntries[i].glyphAdvance = advance;
ge.glyphAdvance = advance;
tr.glyphEntries.add(ge);
currentX += advance;
}

View File

@@ -27,6 +27,7 @@ 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.text.JustifyAlignGlyphEntry;
import com.jpexs.decompiler.flash.tags.text.TextAlign;
import com.jpexs.decompiler.flash.tags.text.TextParseException;
import com.jpexs.decompiler.flash.types.ColorTransform;
@@ -121,6 +122,20 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
}
public static void alignText(SWF swf, List<TEXTRECORD> textRecords, TextAlign textAlign) {
// Remove Justify align entries
for (TEXTRECORD tr : textRecords) {
for (int i = 0; i < tr.glyphEntries.size(); i++) {
GLYPHENTRY ge = tr.glyphEntries.get(i);
if (ge instanceof JustifyAlignGlyphEntry) {
JustifyAlignGlyphEntry jge = (JustifyAlignGlyphEntry) ge;
ge = new GLYPHENTRY();
ge.glyphAdvance = jge.originalAdvance;
ge.glyphIndex = jge.glyphIndex;
tr.glyphEntries.set(i, ge);
}
}
}
int xMin = Integer.MAX_VALUE;
int maxWidth = 0;
for (TEXTRECORD tr : textRecords) {
@@ -146,16 +161,6 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
}
}
/*if (tr.justified) {
// Text record was aligned in Justify mode earier
// restore the advances
for (GLYPHENTRY ge : tr.glyphEntries) {
char ch = font.glyphToChar(ge.glyphIndex);
if (Character.isWhitespace(ch)) {
ge.glyphAdvance = ge.originalAdvance;
}
}
}*/
int width = tr.getTotalAdvance();
switch (textAlign) {
case LEFT:
@@ -205,7 +210,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
}
}
if (spaces > 0) {
if (spaces > 0 && glyphEntries.size() > 0) {
int fix = diff / spaces;
int remaining = diff - fix * spaces;
for (GLYPHENTRY ge : glyphEntries) {
@@ -214,11 +219,13 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
diff2++;
}
//ge.originalAdvance = ge.glyphAdvance;
ge.glyphAdvance += diff2;
JustifyAlignGlyphEntry jge = new JustifyAlignGlyphEntry();
jge.originalAdvance = ge.glyphAdvance;
jge.glyphAdvance = ge.glyphAdvance + diff2;
jge.glyphIndex = ge.glyphIndex;
int idx = tr.glyphEntries.indexOf(ge);
tr.glyphEntries.set(idx, jge);
}
//tr.justified = true;
}
}
}
@@ -295,11 +302,11 @@ public abstract class TextTag extends CharacterTag implements DrawableTag {
firstLine = false;
allLeftMargins.add(currentLeftMargin);
int letterSpacing = 0;
for (int e = 0; e < rec.glyphEntries.length; e++) {
GLYPHENTRY entry = rec.glyphEntries[e];
for (int e = 0; e < rec.glyphEntries.size(); e++) {
GLYPHENTRY entry = rec.glyphEntries.get(e);
GLYPHENTRY nextEntry = null;
if (e < rec.glyphEntries.length - 1) {
nextEntry = rec.glyphEntries[e + 1];
if (e < rec.glyphEntries.size() - 1) {
nextEntry = rec.glyphEntries.get(e + 1);
}
RECT rect = SHAPERECORD.getBounds(glyphs.get(entry.glyphIndex).shapeRecords);
rect.Xmax = (int) Math.round(((double) rect.Xmax * textHeight) / (font.getDivider() * 1024));

View File

@@ -0,0 +1,31 @@
/*
* Copyright (C) 2010-2015 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.tags.text;
import com.jpexs.decompiler.flash.helpers.InternalClass;
import com.jpexs.decompiler.flash.types.GLYPHENTRY;
import com.jpexs.decompiler.flash.types.annotations.Internal;
/**
*
* @author JPEXS
*/
public class JustifyAlignGlyphEntry extends GLYPHENTRY implements InternalClass {
@Internal
public int originalAdvance;
}

View File

@@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.types.annotations.Conditional;
import com.jpexs.decompiler.flash.types.annotations.SWFArray;
import com.jpexs.decompiler.flash.types.annotations.SWFType;
import java.io.Serializable;
import java.util.List;
/**
*
@@ -61,7 +62,7 @@ public class TEXTRECORD implements Serializable {
public int textHeight;
@SWFArray(countField = "glyphCount")
public GLYPHENTRY[] glyphEntries;
public List<GLYPHENTRY> glyphEntries;
public String getText(FontTag font) {
StringBuilder ret = new StringBuilder();