From 040a45a49910ad4b3c4f716cf0cd559ea401425f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 24 Nov 2016 11:05:14 +0100 Subject: [PATCH] Font part classes (WIP) --- .../jpexs/decompiler/flash/iggy/IggyChar.java | 95 ++++++++++++++ .../flash/iggy/IggyCharIndices.java | 40 ++++++ .../flash/iggy/IggyCharKerning.java | 42 +++++++ .../decompiler/flash/iggy/IggyCharNode.java | 81 ++++++++++++ .../decompiler/flash/iggy/IggyCharOffset.java | 60 +++++++++ .../decompiler/flash/iggy/IggyCharScales.java | 33 +++++ .../jpexs/decompiler/flash/iggy/IggyFile.java | 1 + .../decompiler/flash/iggy/IggyFontPart.java | 119 ++++++++++++++++-- 8 files changed, 459 insertions(+), 12 deletions(-) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyChar.java create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharIndices.java create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharKerning.java create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharNode.java create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharOffset.java create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharScales.java diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyChar.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyChar.java new file mode 100644 index 000000000..cc69dd00d --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyChar.java @@ -0,0 +1,95 @@ +package com.jpexs.decompiler.flash.iggy; + +import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +/** + * + * @author JPEXS + */ +public class IggyChar implements StructureInterface { + + private static Logger LOGGER = Logger.getLogger(IggyChar.class.getName()); + + //if offset = 1, zadnychar, 1 byte[1] + @IggyFieldType(DataType.float_t) + float minx; + @IggyFieldType(DataType.float_t) + float miny; + @IggyFieldType(DataType.float_t) + float maxx; + @IggyFieldType(DataType.float_t) + float maxy; + @IggyFieldType(DataType.uint64_t) + long unk; // stejny vetsinou - napr. 48 + @IggyFieldType(DataType.uint64_t) + long count; + @IggyFieldType(DataType.uint64_t) + long one; // 1 + @IggyFieldType(DataType.uint64_t) + long one2; // 1 + @IggyFieldType(DataType.uint64_t) + long one3; // 1 + @IggyFieldType(DataType.uint32_t) + long one4; // 1 + @IggyFieldType(DataType.uint32_t) + long two1; // 2 + + List nodes; + + private long offset; + + public IggyChar(AbstractDataStream stream, long offset) throws IOException { + this.offset = offset; + readFromDataStream(stream); + } + + public IggyChar(float minx, float miny, float maxx, float maxy, long unk, long count, long one, long one2, long one3, long one4, long two1, List nodes) { + this.minx = minx; + this.miny = miny; + this.maxx = maxx; + this.maxy = maxy; + this.unk = unk; + this.count = count; + this.one = one; + this.one2 = one2; + this.one3 = one3; + this.one4 = one4; + this.two1 = two1; + this.nodes = nodes; + } + + @Override + public void readFromDataStream(AbstractDataStream s) throws IOException { + minx = s.readFloat(); + miny = s.readFloat(); + maxx = s.readFloat(); + maxy = s.readFloat(); + unk = s.readUI64(); + count = s.readUI64(); + one = s.readUI64(); + one2 = s.readUI64(); + one3 = s.readUI64(); + one4 = s.readUI32(); + two1 = s.readUI32(); + + if ((one != 1) | (one2 != 1) | (one3 != 1) | (one4 != 1) | (two1 != 2)) { + LOGGER.warning(String.format("Unique header at pos %08X\n", offset)); + } + + nodes = new ArrayList<>(); + for (int i = 0; i < count; i++) { + nodes.add(new IggyCharNode(s, i == 0)); + } + + } + + @Override + public void writeToDataStream(AbstractDataStream stream) throws IOException { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharIndices.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharIndices.java new file mode 100644 index 000000000..ff2e44047 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharIndices.java @@ -0,0 +1,40 @@ +package com.jpexs.decompiler.flash.iggy; + +import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class IggyCharIndices implements StructureInterface { + + @IggyFieldType(value = DataType.widechar_t) + List chars; + @IggyFieldType(DataType.uint32_t) + long padd; + + private long charCount; + + public IggyCharIndices(AbstractDataStream stream, long charCount) throws IOException { + this.charCount = charCount; + readFromDataStream(stream); + } + + @Override + public void readFromDataStream(AbstractDataStream stream) throws IOException { + chars = new ArrayList<>(); + for (int i = 0; i < charCount; i++) { + chars.add((char) stream.readUI16()); + } + padd = stream.readUI32(); + } + + @Override + public void writeToDataStream(AbstractDataStream stream) throws IOException { + throw new UnsupportedOperationException("Not supported yet."); + } + +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharKerning.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharKerning.java new file mode 100644 index 000000000..28041216e --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharKerning.java @@ -0,0 +1,42 @@ +package com.jpexs.decompiler.flash.iggy; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class IggyCharKerning implements StructureInterface { + + private long kernCount; + List charsA; + List charsB; + List kerningOffsets; + long pad; + + public IggyCharKerning(AbstractDataStream stream, long kernCount) throws IOException { + this.kernCount = kernCount; + readFromDataStream(stream); + } + + @Override + public void readFromDataStream(AbstractDataStream stream) throws IOException { + charsA = new ArrayList<>(); + charsB = new ArrayList<>(); + kerningOffsets = new ArrayList<>(); + for (int i = 0; i < kernCount; i++) { + charsA.add((char) stream.readUI16()); + charsB.add((char) stream.readUI16()); + kerningOffsets.add((short) stream.readUI16()); + } + pad = stream.readUI32(); + } + + @Override + public void writeToDataStream(AbstractDataStream stream) throws IOException { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharNode.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharNode.java new file mode 100644 index 000000000..b9fa70b15 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharNode.java @@ -0,0 +1,81 @@ +package com.jpexs.decompiler.flash.iggy; + +import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author JPEXS + */ +public class IggyCharNode implements StructureInterface { + + private static Logger LOGGER = Logger.getLogger(IggyCharNode.class.getName()); + + @IggyFieldType(DataType.float_t) + float x1; + @IggyFieldType(DataType.float_t) + float y1; // zaporne + @IggyFieldType(DataType.float_t) + float x2; + @IggyFieldType(DataType.float_t) + float y2; // zaporne + @IggyFieldType(DataType.uint8_t) //1-pocatek,2-point/line,3-curve + int node_type; + @IggyFieldType(DataType.uint8_t) // 208 start smooth (for j=1 only), 61 smooth interupt (muze a nemusi byt pro novy oddeleny kus charu - kdyz je subtype predchoziho vetsi nez 0 (kupr 5) bude pro oddeleny usek 61, jinak pokud je subtype predchoziho 0 bude pro oddeleny usek 0) + int node_subtype; + @IggyFieldType(DataType.uint8_t) + int zer1; + @IggyFieldType(DataType.uint8_t) + int zer2; + @IggyFieldType(DataType.uint32_t) + long isstart; // 1 v prubehu nebo 0 pouze pro prvni (i kdyz jsou delene jako dvojtecka!!!) + + private boolean first; + + public IggyCharNode(float x1, float y1, float x2, float y2, int node_type, int node_subtype, int zer1, int zer2, long isstart) { + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.node_type = node_type; + this.node_subtype = node_subtype; + this.zer1 = zer1; + this.zer2 = zer2; + this.isstart = isstart; + } + + public IggyCharNode(AbstractDataStream s, boolean first) throws IOException { + this.first = first; + readFromDataStream(s); + } + + @Override + public void readFromDataStream(AbstractDataStream s) throws IOException { + x1 = s.readFloat(); + y1 = s.readFloat(); + x2 = s.readFloat(); + y2 = s.readFloat(); + node_type = s.readUI8(); + node_subtype = s.readUI8(); + zer1 = s.readUI8(); + zer2 = s.readUI8(); + isstart = s.readUI32(); + + if ((zer1 != 0) | (zer2 != 0)) { + LOGGER.warning(String.format("Unknown zeroes at pos %08X\n", s.position() - 6)); + } + if ((!first) & (isstart != 1)) { + LOGGER.warning(String.format("Unknown format at pos %08X\n", s.position() - 4)); + } + if ((first) & (isstart != 0)) { + LOGGER.warning(String.format("Unknown format at pos %08X\n", s.position() - 4)); + } + } + + @Override + public void writeToDataStream(AbstractDataStream stream) throws IOException { + throw new UnsupportedOperationException("Not supported yet."); + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharOffset.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharOffset.java new file mode 100644 index 000000000..707d1c794 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharOffset.java @@ -0,0 +1,60 @@ +package com.jpexs.decompiler.flash.iggy; + +import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType; +import java.io.IOException; + +/** + * + * @author JPEXS + */ +public class IggyCharOffset implements StructureInterface { + + @IggyFieldType(DataType.uint64_t) + long zero; + @IggyFieldType(DataType.uint16_t) + int ischar1; + @IggyFieldType(DataType.uint16_t) + int ischar2; + @IggyFieldType(DataType.uint32_t) + long zero2; + @IggyFieldType(DataType.uint16_t) + int xscale; + @IggyFieldType(DataType.uint16_t) + int yscale; + @IggyFieldType(DataType.uint32_t) + long zero3; + @IggyFieldType(DataType.uint64_t) + long offset; + + public IggyCharOffset(AbstractDataStream stream) throws IOException { + readFromDataStream(stream); + } + + public IggyCharOffset(long zero, int ischar1, int ischar2, long zero2, int xscale, int yscale, long zero3, long offset) { + this.zero = zero; + this.ischar1 = ischar1; + this.ischar2 = ischar2; + this.zero2 = zero2; + this.xscale = xscale; + this.yscale = yscale; + this.zero3 = zero3; + this.offset = offset; + } + + @Override + public void readFromDataStream(AbstractDataStream stream) throws IOException { + zero = stream.readUI64(); + ischar1 = stream.readUI16(); + ischar2 = stream.readUI16(); + zero2 = stream.readUI32(); + xscale = stream.readUI16(); + yscale = stream.readUI16(); + zero3 = stream.readUI32(); + offset = ischar1 > 0 ? stream.position() + stream.readUI64() : 0 /*napr. mezera*/; + } + + @Override + public void writeToDataStream(AbstractDataStream stream) throws IOException { + throw new UnsupportedOperationException("Not supported yet."); + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharScales.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharScales.java new file mode 100644 index 000000000..1c67ad985 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyCharScales.java @@ -0,0 +1,33 @@ +package com.jpexs.decompiler.flash.iggy; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class IggyCharScales implements StructureInterface { + + List scales; + private long charCount; + + public IggyCharScales(AbstractDataStream stream, long charCount) throws IOException { + this.charCount = charCount; + readFromDataStream(stream); + } + + @Override + public void readFromDataStream(AbstractDataStream stream) throws IOException { + scales = new ArrayList<>(); + for (int i = 0; i < charCount; i++) { + scales.add(stream.readFloat()); + } + } + + @Override + public void writeToDataStream(AbstractDataStream stream) throws IOException { + throw new UnsupportedOperationException("Not supported yet."); + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java index 80e6e7321..677daee86 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFile.java @@ -77,6 +77,7 @@ public class IggyFile extends AbstractDataStream implements AutoCloseable { for (int swfIndex = 0; swfIndex < headers.size(); swfIndex++) { IggyFlashHeaderInterface hdr = headers.get(swfIndex); + System.out.println("hdr=" + hdr); IggyDataReader dataReader = new IggyDataReader((IggyFlashHeader64) hdr /*FIXME for 32*/, flashDataStreams.get(swfIndex), offsetTables.get(swfIndex)); flashDataReaders.add(dataReader); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFontPart.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFontPart.java index 2dba0ea58..9a9d94028 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFontPart.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/iggy/IggyFontPart.java @@ -3,6 +3,8 @@ package com.jpexs.decompiler.flash.iggy; import com.jpexs.decompiler.flash.iggy.annotations.IggyArrayFieldType; import com.jpexs.decompiler.flash.iggy.annotations.IggyFieldType; import java.io.IOException; +import java.util.List; +import org.omg.CORBA.StructMemberHelper; /** * @@ -55,25 +57,118 @@ public class IggyFontPart implements StructureInterface { @IggyFieldType(DataType.float_t) float ssr2; @IggyFieldType(DataType.uint32_t) - int char_count; + long char_count; @IggyFieldType(DataType.uint64_t) long zero_padd_4; @IggyFieldType(DataType.uint64_t) long what_3; + @IggyFieldType(value = DataType.uint8_t, count = 272) + byte[] zeroes; + @IggyFieldType(DataType.float_t) + float sss1; + @IggyFieldType(DataType.uint32_t) + long one_padd2; + @IggyFieldType(DataType.float_t) + float sss2; + @IggyFieldType(DataType.uint32_t) + long one_padd3; + @IggyFieldType(DataType.float_t) + float sss3; + @IggyFieldType(DataType.uint32_t) + long one_padd4; + @IggyFieldType(DataType.float_t) + float sss4; + @IggyFieldType(DataType.uint32_t) + long one_padd5; - //TO BE CONTINUED... + //FSeek(start_name); + @IggyFieldType(value = DataType.widechar_t, count = 16) + String name; + + List charOffsets; + List chars; + IggyCharIndices charIndices; + IggyCharScales charScales; + IggyCharKerning charKernings; + + byte[] padTo4byteBoundary; - /* - local uint printchars=0; - local uint64 start_charstruct; -local uint64 start_charindex; -local uint64 start_scale; -local uint64 start_kern; -local uint64 start_name; - */ @Override - public void readFromDataStream(AbstractDataStream stream) throws IOException { - throw new UnsupportedOperationException("Not supported yet."); + public void readFromDataStream(AbstractDataStream s) throws IOException { + type = s.readUI16(); + order_in_iggy_file = s.readUI16(); + zeroone = s.readBytes(28); + char_count2 = s.readUI16(); + what_1 = new int[3]; + for (int i = 0; i < what_1.length; i++) { + what_1[i] = s.readUI16(); + } + flags = s.readUI64(); + start_of_char_struct = s.position() + s.readUI64(); + start_of_char_index = s.position() + s.readUI64(); + start_of_scale = s.position() + s.readUI64(); + kern_count = s.readUI32(); + unk_float = new float[5]; + for (int i = 0; i < unk_float.length; i++) { + unk_float[i] = s.readFloat(); + } + start_of_kern = s.position() + s.readUI64(); + zero_padd = s.readUI64(); + what_2 = s.readUI64(); + zero_padd_2 = s.readUI64(); + start_of_name = s.position() + s.readUI64(); + one_padd = s.readUI64(); + xscale = s.readUI16(); + yscale = s.readUI16(); + zero_padd_3 = s.readUI64(); + ssr1 = s.readFloat(); + ssr2 = s.readFloat(); + char_count = s.readUI32(); + zero_padd_4 = s.readUI64(); + what_3 = s.readUI64(); + s.seek(272, SeekMode.CUR); + sss1 = s.readFloat(); + one_padd2 = s.readUI32(); + sss2 = s.readFloat(); + one_padd3 = s.readUI32(); + sss3 = s.readFloat(); + one_padd4 = s.readUI32(); + sss4 = s.readFloat(); + one_padd5 = s.readUI32(); + s.seek(start_of_name, SeekMode.CUR); + + StringBuilder nameBuilder = new StringBuilder(); + int nameCharCnt = 0; + do { + char c = (char) s.readUI16(); + nameCharCnt++; + if (c == '\0') { + break; + } + nameBuilder.append(c); + } while (true); + s.seek(16 - nameCharCnt * 2, SeekMode.CUR); + name = nameBuilder.toString(); + s.seek(start_of_char_struct, SeekMode.CUR); + + for (int i = 0; i < char_count; i++) { + charOffsets.add(new IggyCharOffset(s)); + } + for (int i = 0; i < char_count; i++) { + long offset = charOffsets.get(i).offset; + if (offset > 0) { + chars.add(new IggyChar(s, offset)); + } else { + s.readUI8(); + chars.add(null); + } + } + s.seek(start_of_char_index, SeekMode.CUR); + charIndices = new IggyCharIndices(s, char_count); + s.seek(start_of_scale, SeekMode.CUR); + charScales = new IggyCharScales(s, char_count); + s.seek(start_of_kern, SeekMode.CUR); + charKernings = new IggyCharKerning(s, kern_count); } @Override