Correct conversion of fonts

This commit is contained in:
Jindra Petřík
2016-11-25 07:53:05 +01:00
parent 27c29368d8
commit c5c146906d
4 changed files with 76 additions and 53 deletions

View File

@@ -23,7 +23,7 @@ public class IggyChar implements StructureInterface {
@IggyFieldType(DataType.float_t)
float maxy;
@IggyFieldType(DataType.uint64_t)
long unk; // stejny vetsinou - napr. 48 - JP: to by mohlo byt advance
long advance; // stejny vetsinou - napr. 48 - JP: to by mohlo byt advance
@IggyFieldType(DataType.uint64_t)
long count;
@IggyFieldType(DataType.uint64_t)
@@ -46,12 +46,12 @@ public class IggyChar implements StructureInterface {
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<IggyCharNode> nodes) {
public IggyChar(float minx, float miny, float maxx, float maxy, long advance, long count, long one, long one2, long one3, long one4, long two1, List<IggyCharNode> nodes) {
this.minx = minx;
this.miny = miny;
this.maxx = maxx;
this.maxy = maxy;
this.unk = unk;
this.advance = advance;
this.count = count;
this.one = one;
this.one2 = one2;
@@ -68,7 +68,7 @@ public class IggyChar implements StructureInterface {
miny = s.readFloat();
maxx = s.readFloat();
maxy = s.readFloat();
unk = s.readUI64();
advance = s.readUI64();
count = s.readUI64();
one = s.readUI64();
one2 = s.readUI64();
@@ -108,8 +108,8 @@ public class IggyChar implements StructureInterface {
return maxy;
}
public long getUnk() {
return unk;
public long getAdvance() {
return advance;
}
public long getOne() {

View File

@@ -18,14 +18,14 @@ public class IggyCharNode implements StructureInterface {
public static int NODE_TYPE_CURVE_POINT = 3;
@IggyFieldType(DataType.float_t)
float x1;
float targetX;
@IggyFieldType(DataType.float_t)
float y1; // zaporne
float targetY; // negative
@IggyFieldType(DataType.float_t)
float x2;
float controlX; // for curves
@IggyFieldType(DataType.float_t)
float y2; // zaporne
@IggyFieldType(DataType.uint8_t) //1-pocatek,2-point/line,3-curve
float controlY; // for curves, negative
@IggyFieldType(DataType.uint8_t) //1-moveto, 2-lineto , 3 - curve to
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;
@@ -39,10 +39,10 @@ public class IggyCharNode implements StructureInterface {
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.targetX = x1;
this.targetY = y1;
this.controlX = x2;
this.controlY = y2;
this.node_type = node_type;
this.node_subtype = node_subtype;
this.zer1 = zer1;
@@ -57,10 +57,10 @@ public class IggyCharNode implements StructureInterface {
@Override
public void readFromDataStream(AbstractDataStream s) throws IOException {
x1 = s.readFloat();
y1 = s.readFloat();
x2 = s.readFloat();
y2 = s.readFloat();
targetX = s.readFloat();
targetY = s.readFloat();
controlX = s.readFloat();
controlY = s.readFloat();
node_type = s.readUI8();
node_subtype = s.readUI8();
zer1 = s.readUI8();
@@ -84,19 +84,19 @@ public class IggyCharNode implements StructureInterface {
}
public float getX1() {
return x1;
return targetX;
}
public float getY1() {
return y1;
return targetY;
}
public float getX2() {
return x2;
return controlX;
}
public float getY2() {
return y2;
return controlY;
}
public int getNodeType() {

View File

@@ -4,12 +4,16 @@ import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.iggy.IggyChar;
import com.jpexs.decompiler.flash.iggy.IggyCharNode;
import com.jpexs.decompiler.flash.types.FILLSTYLEARRAY;
import com.jpexs.decompiler.flash.types.LINESTYLE;
import com.jpexs.decompiler.flash.types.LINESTYLEARRAY;
import com.jpexs.decompiler.flash.types.RGB;
import com.jpexs.decompiler.flash.types.SHAPE;
import com.jpexs.decompiler.flash.types.shaperecords.CurvedEdgeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD;
import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord;
import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
@@ -19,46 +23,61 @@ import java.util.List;
*/
public class IggyCharToShapeConvertor {
private static int convertDistance(double val) {
return (int) (val * SWF.unitDivisor);
private static int convertDistanceX(double val) {
return (int) (20.0 * val * 1024.0);
}
private static int convertDistanceY(double val) {
return (int) (20.0 * val * 1024.0);
}
public static SHAPE convertCharToShape(IggyChar igchar) {
SHAPE shape = new SHAPE();
List<SHAPERECORD> retList = new ArrayList<>();
List<IggyCharNode> ignodes = igchar.getNodes();
int prevX = 0;
int prevY = 0;
for (IggyCharNode ign : ignodes) {
if (ign.getNodeType() == IggyCharNode.NODE_TYPE_MOVE) {
StyleChangeRecord scr = new StyleChangeRecord();
scr.fillStyle0 = 1;
scr.stateFillStyle0 = true;
scr.stateMoveTo = true;
scr.moveDeltaX = convertDistance(ign.getX1());
scr.moveDeltaY = convertDistance(ign.getY1());
scr.lineStyles = new LINESTYLEARRAY();
prevX = scr.moveDeltaX = convertDistanceX(ign.getX1());
prevY = scr.moveDeltaY = convertDistanceY(ign.getY1());
scr.fillStyles = new FILLSTYLEARRAY();
scr.lineStyles = new LINESTYLEARRAY();
scr.calculateBits();
retList.add(scr);
}
if (ign.getNodeType() == IggyCharNode.NODE_TYPE_LINE_TO) {
StraightEdgeRecord ser = new StraightEdgeRecord();
ser.deltaX = convertDistance(ign.getX2() - ign.getX1());
ser.deltaY = convertDistance(ign.getY2() - ign.getY1());
ser.generalLineFlag = true;
ser.vertLineFlag = false;
ser.calculateBits();
retList.add(ser);
}
} else {
if (ign.getNodeType() == IggyCharNode.NODE_TYPE_CURVE_POINT) {
//TODO: Make curve record
StraightEdgeRecord ser = new StraightEdgeRecord();
ser.deltaX = convertDistance(ign.getX2() - ign.getX1());
ser.deltaY = convertDistance(ign.getY2() - ign.getY1());
ser.generalLineFlag = true;
ser.vertLineFlag = false;
ser.calculateBits();
retList.add(ser);
int curX1 = convertDistanceX(ign.getX1());
int curY1 = convertDistanceY(ign.getY1());
int curX2 = convertDistanceX(ign.getX2());
int curY2 = convertDistanceY(ign.getY2());
if (ign.getNodeType() == IggyCharNode.NODE_TYPE_LINE_TO) {
StraightEdgeRecord ser = new StraightEdgeRecord();
ser.deltaX = curX1 - prevX;
ser.deltaY = curY1 - prevY;
ser.generalLineFlag = true;
ser.simplify();
ser.calculateBits();
prevX = curX1;
prevY = curY1;
retList.add(ser);
} else if (ign.getNodeType() == IggyCharNode.NODE_TYPE_CURVE_POINT) {
CurvedEdgeRecord cer = new CurvedEdgeRecord();
cer.controlDeltaX = curX2 - prevX;
cer.controlDeltaY = curY2 - prevY;
cer.anchorDeltaX = curX1 - curX2;
cer.anchorDeltaY = curY1 - curY2;
prevX = curX1;
prevY = curY1;
cer.calculateBits();
retList.add(cer);
}
}
}
@@ -71,8 +90,8 @@ public class IggyCharToShapeConvertor {
}
retList.add(new EndShapeRecord());
init.stateFillStyle0 = true;
init.fillStyle0 = 1;
init.stateFillStyle1 = true;
init.fillStyle1 = 1;
shape.shapeRecords = retList;
shape.numFillBits = 1;
shape.numLineBits = 0;

View File

@@ -85,14 +85,18 @@ public class IggyToSwfConvertor {
fontTag.fontName = iggyFontData.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);
if (chr != null) {
fontTag.codeTable.add(code);
fontTag.glyphShapeTable.add(IggyCharToShapeConvertor.convertCharToShape(chr));
fontTag.fontAdvanceTable.add((int) chr.getUnk());
SHAPE shp = IggyCharToShapeConvertor.convertCharToShape(chr);
fontTag.glyphShapeTable.add(shp);
fontTag.fontAdvanceTable.add((int) chr.getAdvance());
fontTag.fontBoundsTable.add(shp.getBounds());
}
//TODO: handle spaces, etc.
}