diff --git a/CHANGELOG.md b/CHANGELOG.md index 45c2e2dc0..d973d0b0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file. - [#2325] AS3 direct editation - allow single quoted attributes in XML - [#2329] AS3 - imports for standalone functions - [#2331] AS1/2 lite - support for fscommand2, `#strict` directive +- [#2332] Imported fonts by class name not available in texts ## [21.1.0] - 2024-09-23 ### Added @@ -3598,6 +3599,7 @@ Major version of SWF to XML export changed to 2. [#2325]: https://www.free-decompiler.com/flash/issues/2325 [#2329]: https://www.free-decompiler.com/flash/issues/2329 [#2331]: https://www.free-decompiler.com/flash/issues/2331 +[#2332]: https://www.free-decompiler.com/flash/issues/2332 [#943]: https://www.free-decompiler.com/flash/issues/943 [#1812]: https://www.free-decompiler.com/flash/issues/1812 [#2287]: https://www.free-decompiler.com/flash/issues/2287 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index f7b610fd1..a2bd3a957 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -1270,13 +1270,11 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { if (fontClass == null) { return null; } - for (Tag t : getTags()) { - if (t instanceof FontTag) { - if (((FontTag) t).getClassNames().contains(fontClass)) { - return (FontTag) t; - } - } + CharacterTag t = getCharacterByClass(fontClass); + if (t instanceof FontTag) { + return (FontTag) t; } + return null; } @@ -1290,7 +1288,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { if (fontName == null) { return null; } - for (Tag t : getTags()) { + for (Tag t : getCharacters(true).values()) { if (t instanceof FontTag) { if (fontName.equals(((FontTag) t).getFontName())) { return (FontTag) t; @@ -1313,7 +1311,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { if (fontName == null) { return null; } - for (Tag t : getTags()) { + for (Tag t : getCharacters(true).values()) { if (t instanceof FontTag) { FontTag ft = (FontTag) t; if (fontName.equals(ft.getFontNameIntag()) && ft.isBold() == bold && ft.isItalic() == italic) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/DualPdfGraphics2D.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/DualPdfGraphics2D.java index f5fc344ae..600d9652c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/DualPdfGraphics2D.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/DualPdfGraphics2D.java @@ -582,7 +582,7 @@ public class DualPdfGraphics2D extends Graphics2D implements BlendModeSetable, G } if (rec.styleFlagsHasFont) { - font = swf.getFont(rec.fontId); + font = rec.getFont(swf); textHeight = rec.textHeight; } if (rec.styleFlagsHasXOffset) { 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 ab5185319..0f98418aa 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 @@ -32,6 +32,7 @@ import com.jpexs.decompiler.flash.tags.base.FontTag; import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler; import com.jpexs.decompiler.flash.tags.base.RenderContext; import com.jpexs.decompiler.flash.tags.base.TextTag; +import com.jpexs.decompiler.flash.tags.dynamictext.AdvancedTextRecord; import com.jpexs.decompiler.flash.tags.dynamictext.CharacterWithStyle; import com.jpexs.decompiler.flash.tags.dynamictext.DynamicTextModel; import com.jpexs.decompiler.flash.tags.dynamictext.GlyphCharacter; @@ -1281,13 +1282,10 @@ public class DefineEditTextTag extends TextTag { tr.xOffset += currentIndent; } for (SameStyleTextRecord tr : line) { - TEXTRECORD tr2 = new TEXTRECORD(); + AdvancedTextRecord tr2 = new AdvancedTextRecord(); int fid = fontId; if (fontClass != null) { - FontTag ft = swf.getFontByClass(fontClass); - if (ft != null) { - fid = swf.getCharacterId(ft); - } + tr2.fontClass = fontClass; } if (tr.style.font != null) { fid = swf.getCharacterId(tr.style.font); 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 dcfec89a8..b901f6d9a 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 @@ -218,7 +218,7 @@ public abstract class TextTag extends DrawableTag { for (TEXTRECORD tr : textRecords) { if (tr.styleFlagsHasFont) { - FontTag font2 = swf.getFont(tr.fontId); + FontTag font2 = tr.getFont(swf); if (font2 != null) { font = font2; } @@ -329,7 +329,7 @@ public abstract class TextTag extends DrawableTag { for (int r = 0; r < list.size(); r++) { TEXTRECORD rec = list.get(r); if (rec.styleFlagsHasFont) { - FontTag font2 = swf.getFont(rec.fontId); + FontTag font2 = rec.getFont(swf); if (font2 != null) { font = font2; } @@ -603,7 +603,7 @@ public abstract class TextTag extends DrawableTag { } } if (rec.styleFlagsHasFont) { - FontTag font2 = swf.getFont(rec.fontId); + FontTag font2 = rec.getFont(swf); if (font2 != null) { font = font2; } @@ -681,7 +681,7 @@ public abstract class TextTag extends DrawableTag { ExportRectangle result = null; for (TEXTRECORD rec : textRecords) { if (rec.styleFlagsHasFont) { - font = swf.getFont(rec.fontId); + font = rec.getFont(swf); glyphs = font == null ? null : font.getGlyphShapeTable(); textHeight = rec.textHeight; } @@ -795,7 +795,7 @@ public abstract class TextTag extends DrawableTag { } } if (rec.styleFlagsHasFont) { - font = swf.getFont(rec.fontId); + font = rec.getFont(swf); fontId = rec.fontId; glyphs = font.getGlyphShapeTable(); textHeight = rec.textHeight; @@ -855,7 +855,7 @@ public abstract class TextTag extends DrawableTag { } } if (rec.styleFlagsHasFont) { - font = swf.getFont(rec.fontId); + font = rec.getFont(swf); glyphs = font.getGlyphShapeTable(); textHeight = rec.textHeight; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/dynamictext/AdvancedTextRecord.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/dynamictext/AdvancedTextRecord.java new file mode 100644 index 000000000..649e8c110 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/dynamictext/AdvancedTextRecord.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2010-2024 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.dynamictext; + +import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.tags.base.FontTag; +import com.jpexs.decompiler.flash.types.TEXTRECORD; + +/** + * + * @author JPEXS + */ +public class AdvancedTextRecord extends TEXTRECORD { + public String fontClass = null; + + @Override + public FontTag getFont(SWF swf) { + if (fontClass != null) { + return swf.getFontByClass(fontClass); + } + return super.getFont(swf); + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/TEXTRECORD.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/TEXTRECORD.java index 594786fa5..349b27cd8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/TEXTRECORD.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/TEXTRECORD.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.types; +import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.tags.DefineText2Tag; import com.jpexs.decompiler.flash.tags.DefineTextTag; import com.jpexs.decompiler.flash.tags.base.FontTag; @@ -122,4 +123,11 @@ public class TEXTRECORD implements Serializable { } return width; } + + public FontTag getFont(SWF swf) { + if (fontId == -1) { + return null; + } + return swf.getFont(fontId); + } } 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 bfd363e80..d4c807abc 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 @@ -4311,7 +4311,7 @@ public class XFLConverter { for (TEXTRECORD rec : textRecords) { if (rec.styleFlagsHasFont) { - FontTag ft = swf.getFont(rec.fontId); + FontTag ft = rec.getFont(swf); if (ft != null && ft.isSmall()) { fontRenderingMode = "bitmap"; break;