SWFOutputStream correct charset handling when saving NetString (font names)

This commit is contained in:
Jindra Petřík
2022-11-12 21:45:57 +01:00
parent b06c8313b1
commit f7b8b855b6
5 changed files with 5 additions and 34 deletions

View File

@@ -198,23 +198,10 @@ public class SWFOutputStream extends OutputStream {
* @throws IOException
*/
public void writeNetString(String value) throws IOException {
byte[] data = value.getBytes();
writeUI8(data.length);
write(data);
}
/**
* Writes netstring (length + string) value to the stream
*
* @param value String value
* @param charset
* @throws IOException
*/
public void writeNetString(String value, Charset charset) throws IOException {
byte[] data = value.getBytes(charset);
writeUI8(data.length);
write(data);
}
}
/**
* Writes UI32 (Unsigned 32bit integer) value to the stream

View File

@@ -256,11 +256,7 @@ public class DefineFont2Tag extends FontTag {
sos.writeUB(1, fontFlagsItalic ? 1 : 0);
sos.writeUB(1, fontFlagsBold ? 1 : 0);
sos.writeLANGCODE(languageCode);
if (swf.version >= 6) {
sos.writeNetString(fontName, Utf8Helper.charset);
} else {
sos.writeNetString(fontName);
}
sos.writeNetString(fontName);
int numGlyphs = glyphShapeTable.size();
sos.writeUI16(numGlyphs);

View File

@@ -253,11 +253,7 @@ public class DefineFont3Tag extends FontTag {
sos.writeUB(1, fontFlagsItalic ? 1 : 0);
sos.writeUB(1, fontFlagsBold ? 1 : 0);
sos.writeLANGCODE(languageCode);
if (swf.version >= 6) {
sos.writeNetString(fontName, Utf8Helper.charset);
} else {
sos.writeNetString(fontName);
}
sos.writeNetString(fontName);
sos.writeUI16(numGlyphs);
for (long offset : offsetTable) {

View File

@@ -118,11 +118,7 @@ public class DefineFontInfo2Tag extends FontInfoTag {
@Override
public void getData(SWFOutputStream sos) throws IOException {
sos.writeUI16(fontID);
if (swf.version >= 6) {
sos.writeNetString(fontName, Utf8Helper.charset);
} else {
sos.writeNetString(fontName);
}
sos.writeNetString(fontName);
sos.writeUB(2, reserved);
sos.writeUB(1, fontFlagsSmallText ? 1 : 0);
sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0);

View File

@@ -116,11 +116,7 @@ public class DefineFontInfoTag extends FontInfoTag {
@Override
public void getData(SWFOutputStream sos) throws IOException {
sos.writeUI16(fontID);
if (swf.version >= 6) {
sos.writeNetString(fontName, Utf8Helper.charset);
} else {
sos.writeNetString(fontName);
}
sos.writeNetString(fontName);
sos.writeUB(2, reserved);
sos.writeUB(1, fontFlagsSmallText ? 1 : 0);
sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0);