From 1d3fbf0f16f2e2015e4b4eda27e857ffc4814970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 20 Dec 2024 12:44:05 +0100 Subject: [PATCH] Fixed: #2381 Font color values with alpha allowed in html edittext, but alpha ignored --- CHANGELOG.md | 2 ++ .../flash/tags/DefineEditTextTag.java | 12 +++++++- .../jpexs/decompiler/flash/types/RGBA.java | 29 ++++++++++++++++--- .../decompiler/flash/xfl/XFLConverter.java | 10 +++++-- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9f06ad8d..7425ffae0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. ### Fixed - [#2375] Added limit of simultaneously played sounds - AS1/2 - Push action hilighting, GetProperty, Call action hilighting +- [#2381] Font color values with alpha allowed in html edittext, but alpha ignored ## [22.0.1] - 2024-11-20 ### Added @@ -3680,6 +3681,7 @@ Major version of SWF to XML export changed to 2. [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 [#2375]: https://www.free-decompiler.com/flash/issues/2375 [#2374]: https://www.free-decompiler.com/flash/issues/2374 +[#2381]: https://www.free-decompiler.com/flash/issues/2381 [#2366]: https://www.free-decompiler.com/flash/issues/2366 [#2367]: https://www.free-decompiler.com/flash/issues/2367 [#2372]: https://www.free-decompiler.com/flash/issues/2372 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 bb2acc96b..373fa6514 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 @@ -436,7 +436,17 @@ public class DefineEditTextTag extends TextTag { String color = unescape(attributes.getValue("color")); if (color != null) { if (color.startsWith("#")) { - style.textColor = new RGBA(Color.decode(color)); + try { + if (color.length() == 7) { //#rrggbb + style.textColor = new RGBA(Color.decode(color)); + } else if (color.length() == 9) { //#aarrggbb + style.textColor = RGBA.fromHexARGB(color); + style.textColor.alpha = 255; //no alpha is allowed + } + } catch (NumberFormatException ex) { + //do not change textColor + } + } } String size = unescape(attributes.getValue("size")); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/RGBA.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/RGBA.java index f13298bee..3fb5a8830 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/RGBA.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/RGBA.java @@ -20,6 +20,8 @@ import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.types.annotations.SWFType; import java.awt.Color; import java.io.Serializable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * 32-bit red, green, blue and alpha value. @@ -47,9 +49,9 @@ public class RGBA extends RGB implements Serializable { * @return Hex string in format #AARRGGBB */ public String toHexARGB() { - String ra = Integer.toHexString(alpha); - if (ra.length() < 2) { - ra = "0" + ra; + String ah = Integer.toHexString(alpha); + if (ah.length() < 2) { + ah = "0" + ah; } String rh = Integer.toHexString(red); if (rh.length() < 2) { @@ -63,7 +65,7 @@ public class RGBA extends RGB implements Serializable { if (bh.length() < 2) { bh = "0" + bh; } - return "#" + ra + rh + gh + bh; + return "#" + ah + rh + gh + bh; } /** @@ -108,6 +110,25 @@ public class RGBA extends RGB implements Serializable { alpha = 255; } } + + /** + * Converts hex ARGB to RGBA color + * @param hex Hex color in format #aarrggbb + * @return RGBA color + */ + public static RGBA fromHexARGB(String hex) { + Pattern hexPat = Pattern.compile("^#(?[0-9a-fA-F]{2})(?[0-9a-fA-F]{2})(?[0-9a-fA-F]{2})(?[0-9a-fA-F]{2})$"); + Matcher m = hexPat.matcher(hex); + if (!m.matches()) { + throw new NumberFormatException("Not a valid color code with alpha"); + } + int a = Integer.parseInt(m.group("a"), 16); + int r = Integer.parseInt(m.group("r"), 16); + int g = Integer.parseInt(m.group("g"), 16); + int b = Integer.parseInt(m.group("b"), 16); + + return new RGBA(r, g, b, a); + } /** * Constructor. 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 173c70b40..96b5ea2d3 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 @@ -6393,8 +6393,14 @@ public class XFLConverter { } String c = attributes.getValue("color"); if (c != null) { - color = c; - colorAlpha = 255; + if (c.matches("^#[0-9a-fA-F]{8}$")) { + color = "#" + c.substring(3); + } else if (c.matches("^#[0-9a-fA-F]{6}$")) { + color = c; + colorAlpha = 255; + } else { + //wrong format, do not change color + } } String f = attributes.getValue("face"); if (f != null) {