diff --git a/CHANGELOG.md b/CHANGELOG.md index 3975c0d1b..328c44fd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ All notable changes to this project will be documented in this file. - [#2471] Clipping - multiple clips handling, in display and also SVG export - [#2471] SVG Export - exporting with font-face - text tags with multiple texts, fix invalid family names, incorrect text size +- Replacing existing characters in a font which has character codes unsorted ## [23.0.1] - 2025-05-16 ### Fixed diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java index a1de88e28..0df8323e4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java @@ -481,15 +481,14 @@ public class DefineFont2Tag extends FontTag { code = 0; } - int pos = -1; - boolean exists = false; - for (int i = 0; i < codeTable.size(); i++) { - if (codeTable.get(i) >= code) { - if (codeTable.get(i) == code) { - exists = true; + int pos = codeTable.indexOf(code); + boolean exists = pos != -1; + if (!exists) { + for (int i = 0; i < codeTable.size(); i++) { + if (codeTable.get(i) > code) { + pos = i; + break; } - pos = i; - break; } } if (pos == -1) { @@ -551,18 +550,7 @@ public class DefineFont2Tag extends FontTag { @Override public synchronized boolean removeCharacter(char character) { int code = (int) character; - int pos = -1; - for (int i = 0; i < codeTable.size(); i++) { - if (codeTable.get(i) >= code) { - if (codeTable.get(i) == code) { - pos = i; - break; - } - - return false; - } - } - + int pos = codeTable.indexOf(code); if (pos == -1) { return false; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java index e41dfad3d..84a6d9dac 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java @@ -472,15 +472,14 @@ public class DefineFont3Tag extends FontTag { if (code == -1) { //Fixme - throw exception, etc. code = 0; } - int pos = -1; - boolean exists = false; - for (int i = 0; i < codeTable.size(); i++) { - if (codeTable.get(i) >= code) { - if (codeTable.get(i) == code) { - exists = true; + int pos = codeTable.indexOf(code); + boolean exists = pos != -1; + if (!exists) { + for (int i = 0; i < codeTable.size(); i++) { + if (codeTable.get(i) > code) { + pos = i; + break; } - pos = i; - break; } } if (pos == -1) { @@ -555,17 +554,7 @@ public class DefineFont3Tag extends FontTag { } int code = (int) character; - int pos = -1; - for (int i = 0; i < codeTable.size(); i++) { - if (codeTable.get(i) >= code) { - if (codeTable.get(i) == code) { - pos = i; - break; - } - - return false; - } - } + int pos = codeTable.indexOf(code); if (pos == -1) { return false; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java index 924df1c84..b7158590e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java @@ -305,20 +305,20 @@ public class DefineFontTag extends FontTag { boolean exists = false; if (fontInfoTag != null) { List codeTable = fontInfoTag.getCodeTable(); - for (int i = 0; i < codeTable.size(); i++) { - if (codeTable.get(i) >= code) { - if (codeTable.get(i) == code) { - exists = true; + + pos = codeTable.indexOf(code); + exists = pos != -1; + if (!exists) { + for (int i = 0; i < codeTable.size(); i++) { + if (codeTable.get(i) > code) { + pos = i; + break; } - - pos = i; - break; } } - if (pos == -1) { pos = codeTable.size(); - } + } } else { pos = 0; } @@ -372,17 +372,8 @@ public class DefineFontTag extends FontTag { int code = (int) character; int pos = -1; List codeTable = fontInfoTag.getCodeTable(); - for (int i = 0; i < codeTable.size(); i++) { - if (codeTable.get(i) >= code) { - if (codeTable.get(i) == code) { - pos = i; - break; - } - - return false; - } - } - + pos = codeTable.indexOf(code); + if (pos == -1) { return false; }