From a1ff899122b4873a8e33750815e337bed0df065c Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 1 Sep 2014 22:57:48 +0200 Subject: [PATCH] TextTag fixes --- .../flash/tags/DefineEditTextTag.java | 26 ++++++++++++------- .../decompiler/flash/tags/base/TextTag.java | 5 ++-- .../decompiler/flash/xfl/XFLConverter.java | 15 ++++++++--- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java index 7c562e21f..281565166 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java @@ -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; import com.jpexs.decompiler.flash.SWF; @@ -259,7 +260,7 @@ public class DefineEditTextTag extends TextTag { char firstChar = size.charAt(0); if (firstChar != '+' && firstChar != '-') { int fontSize = Integer.parseInt(size); - style.fontHeight = fontSize * style.font.getDivider(); + style.fontHeight = fontSize * (style.font == null ? 1 : style.font.getDivider()); style.fontLeading = leading; } else { // todo: parse relative sizes @@ -340,7 +341,13 @@ public class DefineEditTextTag extends TextTag { public String getFormattedText() { String ret = ""; ret += "["; - String[] alignValues = {"left", "right", "center", "justify"}; + String[] alignNames = {"left", "right", "center", "justify"}; + String alignment; + if (align < alignNames.length) { + alignment = alignNames[align]; + } else { + alignment = "unknown"; + } ret += "\r\nxmin " + bounds.Xmin + "\r\nymin " + bounds.Ymin + "\r\nxmax " + bounds.Xmax + "\r\nymax " + bounds.Ymax + "\r\n"; ret += (wordWrap ? "wordwrap 1\r\n" : "") + (multiline ? "multiline 1\r\n" : "") + (password ? "password 1\r\n" : "") + (readOnly ? "readonly 1\r\n" : "") @@ -349,7 +356,7 @@ public class DefineEditTextTag extends TextTag { + (html ? "html 1\r\n" : "") + (useOutlines ? "useoutlines 1\r\n" : "") + (hasFont ? "font " + fontId + "\r\n" + "height " + fontHeight + "\r\n" : "") + (hasTextColor ? "color " + textColor.toHexARGB() + "\r\n" : "") + (hasFontClass ? "fontclass " + fontClass + "\r\n" : "") + (hasMaxLength ? "maxlength " + maxLength + "\r\n" : "") - + "align " + alignValues[align] + "\r\n" + + "align " + alignment + "\r\n" + (hasLayout ? "leftmargin " + leftMargin + "\r\nrightmargin " + rightMargin + "\r\nindent " + indent + "\r\nleading " + leading + "\r\n" : "") + (!variableName.isEmpty() ? "variablename " + variableName + "\r\n" : ""); ret += "]"; @@ -737,7 +744,7 @@ public class DefineEditTextTag extends TextTag { maxLength = sis.readUI16("maxLength"); } if (hasLayout) { - align = sis.readUI8("align"); //0 left,1 right, 2 center, 3 justify + align = sis.readUI8("align"); //0 left, 1 right, 2 center, 3 justify leftMargin = sis.readUI16("leftMargin"); rightMargin = sis.readUI16("rightMargin"); indent = sis.readUI16("indent"); @@ -810,8 +817,8 @@ public class DefineEditTextTag extends TextTag { int advance; FontTag font = lastStyle.font; GLYPHENTRY ge = new GLYPHENTRY(); - ge.glyphIndex = font.charToGlyph(c); - if (font.hasLayout()) { + ge.glyphIndex = font == null ? -1 : font.charToGlyph(c); + if (font != null && font.hasLayout()) { int kerningAdjustment = 0; if (nextChar != null) { kerningAdjustment = font.getGlyphKerningAdjustment(ge.glyphIndex, font.charToGlyph(nextChar)); @@ -820,7 +827,8 @@ public class DefineEditTextTag extends TextTag { advance = (int) Math.round(font.getDivider() * Math.round((double) lastStyle.fontHeight * (font.getGlyphAdvance(ge.glyphIndex) + kerningAdjustment) / (font.getDivider() * 1024.0))); } else { String fontName = FontTag.defaultFontName; - advance = (int) Math.round(SWF.unitDivisor * FontTag.getSystemFontAdvance(fontName, font.getFontStyle(), (int) (lastStyle.fontHeight / SWF.unitDivisor), c, nextChar)); + int fontStyle = font == null ? 0 : font.getFontStyle(); + advance = (int) Math.round(SWF.unitDivisor * FontTag.getSystemFontAdvance(fontName, fontStyle, (int) (lastStyle.fontHeight / SWF.unitDivisor), c, nextChar)); } ge.glyphAdvance = advance; textModel.addGlyph(c, ge); @@ -927,7 +935,7 @@ public class DefineEditTextTag extends TextTag { } for (SameStyleTextRecord tr : line) { TEXTRECORD tr2 = new TEXTRECORD(); - tr2.styleFlagsHasFont = true; + tr2.styleFlagsHasFont = fontId != 0; tr2.fontId = fontId; tr2.textHeight = tr.style.fontHeight; if (tr.style.textColor != null) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java index 0e3c1617b..d0760fb9e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -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.base; import com.jpexs.decompiler.flash.SWF; @@ -297,7 +298,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag { y = rec.yOffset; } - double rat = textHeight / 1024.0 / font.getDivider(); + double rat = textHeight / 1024.0 / (font == null ? 1 : font.getDivider()); for (GLYPHENTRY entry : rec.glyphEntries) { Matrix mat = transformation.clone(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index 2f93546d7..e1d36d03c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -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.xfl; import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler; @@ -2616,7 +2617,11 @@ public class XFLConverter { indent = det.indent; lineSpacing = det.leading; String[] alignNames = {"left", "right", "center", "justify"}; - alignment = alignNames[det.align]; + if (det.align < alignNames.length) { + alignment = alignNames[det.align]; + } else { + alignment = "unknown"; + } } ret += ""; ret += "