Corrected read only tags handling in GUI (allow edit only after pressing Edit button outside of Editor mode)

Font wideOffsets,wideCodes fixed in DefineFont2/3
This commit is contained in:
Jindra Petřík
2016-01-18 10:48:16 +01:00
parent 97051d183e
commit bbe2c95f0a
5 changed files with 100 additions and 16 deletions

View File

@@ -161,7 +161,7 @@ public class SWFOutputStream extends OutputStream {
*/
public void writeUI8(int value) throws IOException {
if (value > 0xff) {
throw new Error("Value is too large for UI8: " + value);
throw new IllegalArgumentException("Value is too large for UI8: " + value);
}
write(value);
@@ -218,7 +218,7 @@ public class SWFOutputStream extends OutputStream {
*/
public void writeUI32(long value) throws IOException {
if (value > 0xffffffffL) {
throw new Error("Value is too large for UI32: " + value);
throw new IllegalArgumentException("Value is too large for UI32: " + value);
}
write((int) (value & 0xff));
@@ -235,7 +235,7 @@ public class SWFOutputStream extends OutputStream {
*/
public void writeUI16(int value) throws IOException {
if (value > 0xffff) {
throw new Error("Value is too large for UI16: " + value);
throw new IllegalArgumentException("Value is too large for UI16: " + value);
}
write((int) (value & 0xff));
@@ -250,7 +250,7 @@ public class SWFOutputStream extends OutputStream {
*/
public void writeSI32(long value) throws IOException {
if (value > 0x7fffffffL) {
throw new Error("Value is too large for SI32: " + value);
throw new IllegalArgumentException("Value is too large for SI32: " + value);
}
writeUI32(value);
@@ -280,7 +280,7 @@ public class SWFOutputStream extends OutputStream {
*/
public void writeSI8(int value) throws IOException {
if (value > 0x7ff) {
throw new Error("Value is too large for SI8: " + value);
throw new IllegalArgumentException("Value is too large for SI8: " + value);
}
writeUI8(value);

View File

@@ -195,6 +195,48 @@ public class DefineFont2Tag extends FontTag {
}
}
private void checkWideParameters() {
int numGlyphs = glyphShapeTable.size();
if (!fontFlagsWideOffsets) {
ByteArrayOutputStream baosGlyphShapes = new ByteArrayOutputStream();
SWFOutputStream sos3 = new SWFOutputStream(baosGlyphShapes, getVersion());
for (int i = 0; i < numGlyphs; i++) {
long offset = ((glyphShapeTable.size() + 1/*CodeTableOffset*/) * (fontFlagsWideOffsets ? 4 : 2) + sos3.getPos());
if (offset > 0xffff) {
fontFlagsWideOffsets = true;
checkWideParameters();
return;
}
try {
sos3.writeSHAPE(glyphShapeTable.get(i), 1);
} catch (IOException ex) {
//should not happen
return;
}
}
byte[] baGlyphShapes = baosGlyphShapes.toByteArray();
if (numGlyphs > 0) {
long offset = (glyphShapeTable.size() + 1/*CodeTableOffset*/) * (fontFlagsWideOffsets ? 4 : 2) + baGlyphShapes.length;
if (offset > 0xffff) {
fontFlagsWideOffsets = true;
checkWideParameters();
return;
}
}
}
if (!fontFlagsWideCodes) {
for (int i = 0; i < numGlyphs; i++) {
long code = codeTable.get(i);
if (code > 0xffff) {
fontFlagsWideCodes = true;
}
}
}
}
/**
* Gets data bytes
*
@@ -203,6 +245,7 @@ public class DefineFont2Tag extends FontTag {
*/
@Override
public void getData(SWFOutputStream sos) throws IOException {
checkWideParameters();
sos.writeUI16(fontId);
sos.writeUB(1, fontFlagsHasLayout ? 1 : 0);
sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0);
@@ -442,6 +485,7 @@ public class DefineFont2Tag extends FontTag {
}
}
checkWideParameters();
setModified(true);
}

View File

@@ -185,6 +185,48 @@ public class DefineFont3Tag extends FontTag {
}
}
private void checkWideParameters() {
int numGlyphs = glyphShapeTable.size();
if (!fontFlagsWideOffsets) {
ByteArrayOutputStream baosGlyphShapes = new ByteArrayOutputStream();
SWFOutputStream sos3 = new SWFOutputStream(baosGlyphShapes, getVersion());
for (int i = 0; i < numGlyphs; i++) {
long offset = (glyphShapeTable.size()) * 2 + sos3.getPos();
if (offset > 0xffff) {
fontFlagsWideOffsets = true;
checkWideParameters();
return;
}
try {
sos3.writeSHAPE(glyphShapeTable.get(i), 1);
} catch (IOException ex) {
//should not happen
return;
}
}
byte[] baGlyphShapes = baosGlyphShapes.toByteArray();
if (numGlyphs > 0) {
long maxOffset = (glyphShapeTable.size() + 1/*CodeTableOffset*/) * 2 + baGlyphShapes.length;
if (maxOffset > 0xffff) {
fontFlagsWideOffsets = true;
checkWideParameters();
return;
}
}
}
if (!fontFlagsWideCodes) {
for (int i = 0; i < numGlyphs; i++) {
long code = codeTable.get(i);
if (code > 0xffff) {
fontFlagsWideCodes = true;
}
}
}
}
/**
* Gets data bytes
*
@@ -193,6 +235,7 @@ public class DefineFont3Tag extends FontTag {
*/
@Override
public void getData(SWFOutputStream sos) throws IOException {
checkWideParameters();
List<Long> offsetTable = new ArrayList<>();
ByteArrayOutputStream baosGlyphShapes = new ByteArrayOutputStream();
SWFOutputStream sos3 = new SWFOutputStream(baosGlyphShapes, getVersion());
@@ -203,14 +246,6 @@ public class DefineFont3Tag extends FontTag {
}
byte[] baGlyphShapes = baosGlyphShapes.toByteArray();
if (!fontFlagsWideOffsets && numGlyphs > 0) {
// Set wide offsets when necessary
long maxOffset = (glyphShapeTable.size() + 1/*CodeTableOffset*/) * 2 + baGlyphShapes.length;
if (maxOffset > 65535) {
fontFlagsWideOffsets = true;
}
}
sos.writeUI16(fontId);
sos.writeUB(1, fontFlagsHasLayout ? 1 : 0);
sos.writeUB(1, fontFlagsShiftJIS ? 1 : 0);
@@ -443,6 +478,7 @@ public class DefineFont3Tag extends FontTag {
}
}
checkWideParameters();
setModified(true);
}