Texts converting

This commit is contained in:
Jindra Petřík
2016-11-25 11:29:09 +01:00
parent 6df722eda9
commit 3fc47c5afc
3 changed files with 54 additions and 30 deletions

View File

@@ -89,19 +89,19 @@ public class IggyDataReader implements StructureInterface {
textDataSizes[(int) header.font_count - 1] = offsetAfterTexts - lastOffset;
}
for (int i = 0; i < textOffsets.size(); i++) {
long textOffset = textOffsets.get(i);
for (int textIndex = 0; textIndex < textOffsets.size(); textIndex++) {
long textOffset = textOffsets.get(textIndex);
stream.seek(textOffset, SeekMode.SET);
byte[] textData = stream.readBytes((int) textDataSizes[i]);
byte[] textData = stream.readBytes((int) textDataSizes[textIndex]);
IggyText text = new IggyText(new ByteArrayDataStream(textData, stream.is64()));
text2Font.put(text.textId, text.fontId);
texts.put(text.textId, text);
text2Font.put(textIndex, text.fontIndex);
texts.put(textIndex, text);
}
fonts = new HashMap<>();
for (int i = 0; i < header.font_count; i++) {
stream.seek(fontOffsets[i], SeekMode.SET);
for (int fontIndex = 0; fontIndex < header.font_count; fontIndex++) {
stream.seek(fontOffsets[fontIndex], SeekMode.SET);
IggyFont font = new IggyFont(stream);
fonts.put(font.fontId, font);
fonts.put(fontIndex, font);
}
}

View File

@@ -13,7 +13,7 @@ public class IggyText implements StructureInterface {
@IggyFieldType(DataType.uint16_t)
int type; // Tag type
@IggyFieldType(DataType.uint16_t)
int textId;
int textIndex;
@IggyArrayFieldType(value = DataType.uint8_t, count = 28)
byte zeroone[];
@IggyFieldType(DataType.float_t)
@@ -27,7 +27,7 @@ public class IggyText implements StructureInterface {
@IggyFieldType(DataType.uint16_t)
int enum_hex;
@IggyFieldType(DataType.uint16_t)
int fontId;
int fontIndex;
@IggyFieldType(DataType.uint32_t)
long zero;
@IggyFieldType(DataType.uint64_t)
@@ -39,14 +39,14 @@ public class IggyText implements StructureInterface {
public IggyText(int type, int order_in_iggy_file, byte[] zeroone, float par1, float par2, float par3, float par4, int enum_hex, int for_which_font_order_in_iggyfile, long zero, long one, byte[] some, long offset_of_name, String name) {
this.type = type;
this.textId = order_in_iggy_file;
this.textIndex = order_in_iggy_file;
this.zeroone = zeroone;
this.par1 = par1;
this.par2 = par2;
this.par3 = par3;
this.par4 = par4;
this.enum_hex = enum_hex;
this.fontId = for_which_font_order_in_iggyfile;
this.fontIndex = for_which_font_order_in_iggyfile;
this.zero = zero;
this.one = one;
this.some = some;
@@ -60,14 +60,14 @@ public class IggyText implements StructureInterface {
@Override
public void readFromDataStream(AbstractDataStream s) throws IOException {
type = s.readUI16();
textId = s.readUI16();
textIndex = s.readUI16();
zeroone = s.readBytes(28);
par1 = s.readFloat();
par2 = s.readFloat();
par3 = s.readFloat();
par4 = s.readFloat();
enum_hex = s.readUI16();
fontId = s.readUI16();
fontIndex = s.readUI16();
zero = s.readUI32();
one = s.readUI64();
some = s.readBytes(32);
@@ -91,8 +91,8 @@ public class IggyText implements StructureInterface {
return type;
}
public int getOrder_in_iggy_file() {
return textId;
public int getTextIndex() {
return textIndex;
}
public byte[] getZeroone() {
@@ -119,8 +119,8 @@ public class IggyText implements StructureInterface {
return enum_hex;
}
public int getFor_which_font_order_in_iggyfile() {
return fontId;
public int getFontIndex() {
return fontIndex;
}
public long getZero() {
@@ -135,7 +135,7 @@ public class IggyText implements StructureInterface {
return some;
}
public String getIntitalText() {
public String getInitialText() {
return initialText;
}

View File

@@ -6,6 +6,7 @@ import com.jpexs.decompiler.flash.iggy.IggyChar;
import com.jpexs.decompiler.flash.iggy.IggyFile;
import com.jpexs.decompiler.flash.iggy.IggyFont;
import com.jpexs.decompiler.flash.iggy.IggyText;
import com.jpexs.decompiler.flash.tags.DefineEditTextTag;
import com.jpexs.decompiler.flash.tags.DefineFont2Tag;
import com.jpexs.decompiler.flash.tags.EndTag;
import com.jpexs.decompiler.flash.tags.FileAttributesTag;
@@ -16,6 +17,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
@@ -76,22 +79,26 @@ public class IggyToSwfConvertor {
fat.useNetwork = false;
swf.addTag(fat);
Set<Integer> fontKeys = file.getFontIds(swfIndex);
Set<Integer> fontIndices = file.getFontIds(swfIndex);
for (int fontKey : fontKeys) {
IggyFont iggyFontData = file.getFont(swfIndex, fontKey);
IggyText fontInfo = file.getText(swfIndex, fontKey);
int currentCharId = 0;
Map<Integer, Integer> fontIndex2CharId = new HashMap<>();
for (int fontIndex : fontIndices) {
IggyFont iggyFont = file.getFont(swfIndex, fontIndex);
DefineFont2Tag fontTag = new DefineFont2Tag(swf);
fontTag.fontID = fontKey + 1;
currentCharId++;
fontIndex2CharId.put(fontIndex, currentCharId);
fontTag.fontID = currentCharId;
fontTag.codeTable = new ArrayList<>();
fontTag.fontName = iggyFontData.getName();
fontTag.fontName = iggyFont.getName();
fontTag.glyphShapeTable = new ArrayList<>();
fontTag.fontAdvanceTable = new ArrayList<>();
fontTag.fontBoundsTable = new ArrayList<>();
for (int i = 0; i < iggyFontData.getCharacterCount(); i++) {
int code = iggyFontData.getCharIndices().getChars().get(i);
IggyChar chr = iggyFontData.getChars().get(i);
for (int i = 0; i < iggyFont.getCharacterCount(); i++) {
int code = iggyFont.getCharIndices().getChars().get(i);
IggyChar chr = iggyFont.getChars().get(i);
if (chr != null) {
fontTag.codeTable.add(code);
SHAPE shp = IggyCharToShapeConvertor.convertCharToShape(chr);
@@ -100,11 +107,29 @@ public class IggyToSwfConvertor {
fontTag.fontBoundsTable.add(shp.getBounds());
}
//TODO: handle spaces, etc.
//FIXME: handle spaces (with no vectors), etc.
}
fontTag.setModified(true);
swf.addTag(fontTag);
}
Map<Integer, Integer> textIndex2CharId = new HashMap<>();
Set<Integer> textIds = file.getTextIds(swfIndex);
for (int textId : textIds) {
IggyText iggyText = file.getText(swfIndex, textId);
DefineEditTextTag textTag = new DefineEditTextTag(swf);
currentCharId++;
textIndex2CharId.put(iggyText.getTextIndex(), currentCharId);
textTag.characterID = currentCharId;
textTag.hasText = true;
textTag.initialText = iggyText.getInitialText();
//textTag.hasFont = true;
//textTag.fontId = fontIndex2CharId.get(iggyText.getFontIndex());
textTag.setModified(true);
swf.addTag(textTag);
}
swf.addTag(new EndTag(swf));
swf.setModified(true);
@@ -112,6 +137,5 @@ public class IggyToSwfConvertor {
}
public static void main(String[] args) throws IOException {
}
}