mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-26 23:40:46 +00:00
Character sets are limited to GB2312, Shift_JIS, Unicode, and all singlebyte.
Fixed font code points - proper characters display, adding, etc.
This commit is contained in:
@@ -361,12 +361,12 @@ public class DefineFont2Tag extends FontTag {
|
||||
|
||||
@Override
|
||||
public char glyphToChar(int glyphIndex) {
|
||||
return (char) (int) codeTable.get(glyphIndex);
|
||||
return Utf8Helper.codePointToChar(codeTable.get(glyphIndex), getCodesCharset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int charToGlyph(char c) {
|
||||
return codeTable.indexOf((int) c);
|
||||
return codeTable.indexOf(Utf8Helper.charToCodePoint(c, getCodesCharset()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -452,8 +452,13 @@ public class DefineFont2Tag extends FontTag {
|
||||
int fontStyle = getFontStyle();
|
||||
|
||||
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, (int) Math.round(getDivider() * 1024), character);
|
||||
|
||||
int code = (int) character;
|
||||
|
||||
int code = (int) Utf8Helper.charToCodePoint(character, getCodesCharset());
|
||||
|
||||
if (code == -1) { //Fixme - throw exception, etc.
|
||||
code = 0;
|
||||
}
|
||||
|
||||
int pos = -1;
|
||||
boolean exists = false;
|
||||
for (int i = 0; i < codeTable.size(); i++) {
|
||||
@@ -472,7 +477,7 @@ public class DefineFont2Tag extends FontTag {
|
||||
if (!exists) {
|
||||
shiftGlyphIndices(fontID, pos, true);
|
||||
glyphShapeTable.add(pos, shp);
|
||||
codeTable.add(pos, (int) character);
|
||||
codeTable.add(pos, code);
|
||||
} else {
|
||||
glyphShapeTable.set(pos, shp);
|
||||
}
|
||||
@@ -488,25 +493,25 @@ public class DefineFont2Tag extends FontTag {
|
||||
}
|
||||
|
||||
for (int k = 0; k < fontKerningTable.size(); k++) {
|
||||
if (fontKerningTable.get(k).fontKerningCode1 == character
|
||||
|| fontKerningTable.get(k).fontKerningCode2 == character) {
|
||||
if (fontKerningTable.get(k).fontKerningCode1 == code
|
||||
|| fontKerningTable.get(k).fontKerningCode2 == code) {
|
||||
fontKerningTable.remove(k);
|
||||
k--;
|
||||
}
|
||||
}
|
||||
List<FontHelper.KerningPair> kerning = getFontKerningPairs(font, (int) (getDivider() * 1024));
|
||||
for (FontHelper.KerningPair pair : kerning) {
|
||||
if (pair.char1 != character && pair.char2 != character) {
|
||||
if (pair.char1 != code && pair.char2 != code) {
|
||||
continue;
|
||||
}
|
||||
int glyph1 = charToGlyph(pair.char1);
|
||||
if (pair.char1 == character) {
|
||||
if (pair.char1 == code) {
|
||||
|
||||
} else if (glyph1 == -1) {
|
||||
continue;
|
||||
}
|
||||
int glyph2 = charToGlyph(pair.char2);
|
||||
if (pair.char2 == character) {
|
||||
if (pair.char2 == code) {
|
||||
|
||||
} else if (glyph2 == -1) {
|
||||
continue;
|
||||
@@ -596,7 +601,8 @@ public class DefineFont2Tag extends FontTag {
|
||||
public String getCharacters() {
|
||||
StringBuilder ret = new StringBuilder(codeTable.size());
|
||||
for (int i : codeTable) {
|
||||
ret.append((char) i);
|
||||
Character c = Utf8Helper.codePointToChar(i, getCodesCharset());
|
||||
ret.append(c == null ? "?" : c);
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
@@ -616,8 +622,10 @@ public class DefineFont2Tag extends FontTag {
|
||||
@Override
|
||||
public int getCharKerningAdjustment(char c1, char c2) {
|
||||
int kerningAdjustment = 0;
|
||||
int c1Code = Utf8Helper.charToCodePoint(c1, getCodesCharset());
|
||||
int c2Code = Utf8Helper.charToCodePoint(c2, getCodesCharset());
|
||||
for (KERNINGRECORD ker : fontKerningTable) {
|
||||
if (ker.fontKerningCode1 == c1 && ker.fontKerningCode2 == c2) {
|
||||
if (ker.fontKerningCode1 == c1Code && ker.fontKerningCode2 == c2Code) {
|
||||
kerningAdjustment = ker.fontKerningAdjustment;
|
||||
break;
|
||||
}
|
||||
@@ -687,4 +695,12 @@ public class DefineFont2Tag extends FontTag {
|
||||
return hasLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCodesCharset() {
|
||||
if (fontFlagsShiftJIS) {
|
||||
return "Shift_JIS";
|
||||
}
|
||||
return getCharset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -327,12 +327,12 @@ public class DefineFont3Tag extends FontTag {
|
||||
|
||||
@Override
|
||||
public char glyphToChar(int glyphIndex) {
|
||||
return (char) (int) codeTable.get(glyphIndex);
|
||||
return Utf8Helper.codePointToChar(codeTable.get(glyphIndex), getCodesCharset());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int charToGlyph(char c) {
|
||||
return codeTable.indexOf((int) c);
|
||||
return codeTable.indexOf(Utf8Helper.charToCodePoint(c, getCodesCharset()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -444,7 +444,11 @@ public class DefineFont3Tag extends FontTag {
|
||||
}
|
||||
int fontStyle = getFontStyle();
|
||||
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, (int) Math.round(getDivider() * 1024), character);
|
||||
int code = (int) character;
|
||||
int code = (int) Utf8Helper.charToCodePoint(character, getCodesCharset());
|
||||
|
||||
if (code == -1) { //Fixme - throw exception, etc.
|
||||
code = 0;
|
||||
}
|
||||
int pos = -1;
|
||||
boolean exists = false;
|
||||
for (int i = 0; i < codeTable.size(); i++) {
|
||||
@@ -463,7 +467,7 @@ public class DefineFont3Tag extends FontTag {
|
||||
if (!exists) {
|
||||
shiftGlyphIndices(fontID, pos, true);
|
||||
glyphShapeTable.add(pos, shp);
|
||||
codeTable.add(pos, (int) character);
|
||||
codeTable.add(pos, code);
|
||||
} else {
|
||||
glyphShapeTable.set(pos, shp);
|
||||
}
|
||||
@@ -479,25 +483,25 @@ public class DefineFont3Tag extends FontTag {
|
||||
}
|
||||
|
||||
for (int k = 0; k < fontKerningTable.size(); k++) {
|
||||
if (fontKerningTable.get(k).fontKerningCode1 == character
|
||||
|| fontKerningTable.get(k).fontKerningCode2 == character) {
|
||||
if (fontKerningTable.get(k).fontKerningCode1 == code
|
||||
|| fontKerningTable.get(k).fontKerningCode2 == code) {
|
||||
fontKerningTable.remove(k);
|
||||
k--;
|
||||
}
|
||||
}
|
||||
List<FontHelper.KerningPair> kerning = getFontKerningPairs(font, (int) (getDivider() * 1024));
|
||||
for (FontHelper.KerningPair pair : kerning) {
|
||||
if (pair.char1 != character && pair.char2 != character) {
|
||||
if (pair.char1 != code && pair.char2 != code) {
|
||||
continue;
|
||||
}
|
||||
int glyph1 = charToGlyph(pair.char1);
|
||||
if (pair.char1 == character) {
|
||||
if (pair.char1 == code) {
|
||||
|
||||
} else if (glyph1 == -1) {
|
||||
continue;
|
||||
}
|
||||
int glyph2 = charToGlyph(pair.char2);
|
||||
if (pair.char2 == character) {
|
||||
if (pair.char2 == code) {
|
||||
|
||||
} else if (glyph2 == -1) {
|
||||
continue;
|
||||
@@ -599,7 +603,8 @@ public class DefineFont3Tag extends FontTag {
|
||||
public String getCharacters() {
|
||||
StringBuilder ret = new StringBuilder(codeTable.size());
|
||||
for (int i : codeTable) {
|
||||
ret.append((char) i);
|
||||
Character c = Utf8Helper.codePointToChar(i, getCodesCharset());
|
||||
ret.append(c == null ? "?" : c);
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
@@ -629,9 +634,12 @@ public class DefineFont3Tag extends FontTag {
|
||||
|
||||
@Override
|
||||
public int getCharKerningAdjustment(char c1, char c2) {
|
||||
int c1Code = Utf8Helper.charToCodePoint(c1, getCodesCharset());
|
||||
int c2Code = Utf8Helper.charToCodePoint(c2, getCodesCharset());
|
||||
|
||||
int kerningAdjustment = 0;
|
||||
for (KERNINGRECORD ker : fontKerningTable) {
|
||||
if (ker.fontKerningCode1 == c1 && ker.fontKerningCode2 == c2) {
|
||||
if (ker.fontKerningCode1 == c1Code && ker.fontKerningCode2 == c2Code) {
|
||||
kerningAdjustment = ker.fontKerningAdjustment;
|
||||
break;
|
||||
}
|
||||
@@ -701,4 +709,12 @@ public class DefineFont3Tag extends FontTag {
|
||||
public boolean isLeadingEditable() {
|
||||
return hasLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCodesCharset() {
|
||||
if (fontFlagsShiftJIS) {
|
||||
return "Shift_JIS";
|
||||
}
|
||||
return getCharset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,4 +179,14 @@ public class DefineFontInfo2Tag extends FontInfoTag {
|
||||
public void setFontFlagsItalic(boolean value) {
|
||||
fontFlagsItalic = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnsi() {
|
||||
return fontFlagsANSI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShiftJIS() {
|
||||
return fontFlagsShiftJIS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,8 @@ public class DefineFontInfoTag extends FontInfoTag {
|
||||
|
||||
public boolean fontFlagsWideCodes;
|
||||
|
||||
@SWFType(value = BasicType.UI8, alternateValue = BasicType.UI16, alternateCondition = "fontFlagsWideCodes")
|
||||
//@SWFType(value = BasicType.UI8, alternateValue = BasicType.UI16, alternateCondition = "fontFlagsWideCodes")
|
||||
@SWFType(value = BasicType.UI16)
|
||||
public List<Integer> codeTable;
|
||||
|
||||
/**
|
||||
@@ -179,5 +180,15 @@ public class DefineFontInfoTag extends FontInfoTag {
|
||||
@Override
|
||||
public void setFontFlagsItalic(boolean value) {
|
||||
fontFlagsItalic = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShiftJIS() {
|
||||
return fontFlagsShiftJIS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAnsi() {
|
||||
return fontFlagsANSI;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,11 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType;
|
||||
import com.jpexs.decompiler.flash.types.annotations.SWFVersion;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.utf8.Utf8Helper;
|
||||
import java.awt.Font;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -156,7 +158,7 @@ public class DefineFontTag extends FontTag {
|
||||
public char glyphToChar(int glyphIndex) {
|
||||
ensureFontInfo();
|
||||
if (fontInfoTag != null) {
|
||||
return (char) (int) fontInfoTag.getCodeTable().get(glyphIndex);
|
||||
return Utf8Helper.codePointToChar(fontInfoTag.getCodeTable().get(glyphIndex), getCodesCharset());
|
||||
} else {
|
||||
return '?';
|
||||
}
|
||||
@@ -166,7 +168,7 @@ public class DefineFontTag extends FontTag {
|
||||
public int charToGlyph(char c) {
|
||||
ensureFontInfo();
|
||||
if (fontInfoTag != null) {
|
||||
return fontInfoTag.getCodeTable().indexOf((int) c);
|
||||
return fontInfoTag.getCodeTable().indexOf(Utf8Helper.charToCodePoint(c, getCodesCharset()));
|
||||
}
|
||||
return -1;
|
||||
|
||||
@@ -265,11 +267,25 @@ public class DefineFontTag extends FontTag {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCodesCharset() {
|
||||
if (fontInfoTag != null && fontInfoTag.isShiftJIS()) {
|
||||
return "Shift_JIS";
|
||||
}
|
||||
return getCharset();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void addCharacter(char character, Font font) {
|
||||
SHAPE shp = SHAPERECORD.fontCharacterToSHAPE(font, (int) Math.round(getDivider() * 1024), character);
|
||||
ensureFontInfo();
|
||||
int code = (int) character;
|
||||
int code = (int) Utf8Helper.charToCodePoint(character, getCodesCharset());
|
||||
|
||||
if (code == -1) { //Fixme - throw exception, etc.
|
||||
code = 0;
|
||||
}
|
||||
int pos = -1;
|
||||
boolean exists = false;
|
||||
if (fontInfoTag != null) {
|
||||
@@ -296,7 +312,7 @@ public class DefineFontTag extends FontTag {
|
||||
shiftGlyphIndices(fontId, pos, true);
|
||||
glyphShapeTable.add(pos, shp);
|
||||
if (fontInfoTag != null) {
|
||||
fontInfoTag.addFontCharacter(pos, (int) character);
|
||||
fontInfoTag.addFontCharacter(pos, code);
|
||||
}
|
||||
} else {
|
||||
glyphShapeTable.set(pos, shp);
|
||||
@@ -362,8 +378,8 @@ public class DefineFontTag extends FontTag {
|
||||
if (fontInfoTag != null) {
|
||||
List<Integer> codeTable = fontInfoTag.getCodeTable();
|
||||
StringBuilder ret = new StringBuilder(codeTable.size());
|
||||
for (int i : codeTable) {
|
||||
ret.append((char) i);
|
||||
for (int i : codeTable) {
|
||||
ret.append(Utf8Helper.codePointToChar(i, getCodesCharset()));
|
||||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
@@ -62,6 +62,10 @@ public abstract class FontInfoTag extends Tag implements CharacterIdTag {
|
||||
|
||||
public abstract void setFontFlagsItalic(boolean value);
|
||||
|
||||
public abstract boolean isShiftJIS();
|
||||
|
||||
public abstract boolean isAnsi();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " (" + fontID + ")";
|
||||
|
||||
@@ -531,4 +531,6 @@ public abstract class FontTag extends DrawableTag implements AloneTag {
|
||||
return installedFontsByName;
|
||||
}
|
||||
|
||||
public abstract String getCodesCharset();
|
||||
|
||||
}
|
||||
|
||||
@@ -534,4 +534,9 @@ public final class DefineCompactedFont extends FontTag {
|
||||
public RECT getRectWithStrokes() {
|
||||
return getRect();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCodesCharset() {
|
||||
return getCharset();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user