mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-06 00:18:39 +00:00
Canvas export: refactorings, place function, font handling
This commit is contained in:
@@ -1466,7 +1466,12 @@ public final class SWF implements TreeItem, Timelined {
|
||||
|
||||
for (int c : library) {
|
||||
CharacterTag ch = fswf.characters.get(c);
|
||||
if (ch instanceof ImageTag) {
|
||||
if(ch instanceof FontTag){
|
||||
fos.write(Utf8Helper.getBytes("function " + getTypePrefix(ch) + c + "(ctx,ch,textColor){\r\n"));
|
||||
fos.write(Utf8Helper.getBytes(((FontTag) ch).toHtmlCanvas(1)));
|
||||
fos.write(Utf8Helper.getBytes("}\r\n\r\n"));
|
||||
}
|
||||
else if (ch instanceof ImageTag) {
|
||||
ImageTag image = (ImageTag) ch;
|
||||
String format = image.getImageFormat();
|
||||
InputStream imageStream = image.getImageData();
|
||||
@@ -2281,26 +2286,24 @@ public final class SWF implements TreeItem, Timelined {
|
||||
sb.append("\t\t\tfctx.applyTransforms(ctx._matrices);\r\n");
|
||||
sb.append("\t\t\tctx = fctx;\r\n");
|
||||
}
|
||||
sb.append("\t\t\tctx.save();\r\n");
|
||||
sb.append("\t\t\tctx.transform(").append(Helper.doubleStr(placeMatrix.scaleX)).append(",");
|
||||
sb.append(Helper.doubleStr(placeMatrix.rotateSkew0)).append(",");
|
||||
sb.append(Helper.doubleStr(placeMatrix.rotateSkew1)).append(",");
|
||||
sb.append(Helper.doubleStr(placeMatrix.scaleY)).append(",");
|
||||
sb.append(Helper.doubleStr(placeMatrix.translateX)).append(",");
|
||||
sb.append(Helper.doubleStr(placeMatrix.translateY));
|
||||
sb.append(");\r\n");
|
||||
|
||||
ColorTransform ctrans =layer.colorTransForm;
|
||||
String ctrans_str = "ctrans";
|
||||
if(ctrans==null){
|
||||
ctrans = new ColorTransform();
|
||||
sb.append("\t\t\tvar nctrans = ctrans;\r\n");
|
||||
}else{
|
||||
sb.append("\t\t\tvar nctrans = ctrans.merge(new cxform("+
|
||||
ctrans_str = "ctrans.merge(new cxform("+
|
||||
ctrans.getRedAdd()+","+ctrans.getGreenAdd()+","+ctrans.getBlueAdd()+","+ctrans.getAlphaAdd()+","+
|
||||
ctrans.getRedMulti()+","+ctrans.getGreenMulti()+","+ctrans.getBlueMulti()+","+ctrans.getAlphaMulti()
|
||||
+"));\r\n");
|
||||
+"))";
|
||||
}
|
||||
sb.append("\t\t\t").append(getTypePrefix(character)).append(layer.characterId).append("(ctx,nctrans,").append(f).append(",").append(layer.ratio < 0 ? 0 : layer.ratio).append(");\r\n");
|
||||
sb.append("\t\t\tctx.restore();\r\n");
|
||||
sb.append("\t\t\t").append("place(\"").append(getTypePrefix(character)).append(layer.characterId).append("\",canvas,ctx,[").append(placeMatrix.scaleX).append(",")
|
||||
.append(placeMatrix.rotateSkew0).append(",")
|
||||
.append(placeMatrix.rotateSkew1).append(",")
|
||||
.append(placeMatrix.scaleY).append(",")
|
||||
.append(placeMatrix.translateX).append(",")
|
||||
.append(placeMatrix.translateY).append("],").append(ctrans_str).append(",").append(f).append(",").append(layer.ratio < 0 ? 0 : layer.ratio).append(");\r\n");
|
||||
|
||||
if(layer.filters!=null){
|
||||
for(FILTER filter:layer.filters){
|
||||
if(filter instanceof COLORMATRIXFILTER){
|
||||
|
||||
@@ -261,7 +261,7 @@ public class CanvasMorphShapeExporter extends MorphShapeExporterBase {
|
||||
|
||||
}
|
||||
|
||||
fillData += "\tvar fimg = ctrans.applyToImage(image" + bitmapId + ");";
|
||||
fillData += "\tvar fimg = ctrans.applyToImage(image" + bitmapId + ");\r\n";
|
||||
fillData += "\tvar pat=ctx.createPattern(fimg,\"repeat\");\r\n";
|
||||
fillData += "\tctx.fillStyle = pat;\r\n";
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public class CanvasShapeExporter extends ShapeExporterBase {
|
||||
+ "\tvar imdata=ictx.getImageData(0,0,icanvas.width,icanvas.height);\r\n"
|
||||
+ "\tvar idata=imdata.data;\r\n"
|
||||
+ "\tfor(var i=0;i<idata.length;i+=4){\r\n"
|
||||
+ "\t\tvar c=this.apply([idata[i],idata[i+1],idata[i+2],idata[i+3]/255]);"
|
||||
+ "\t\tvar c=this.apply([idata[i],idata[i+1],idata[i+2],idata[i+3]/255]);\r\n"
|
||||
+ "\t\tidata[i] = c[0];\r\n"
|
||||
+ "\t\tidata[i+1] = c[1];\r\n"
|
||||
+ "\t\tidata[i+2] = c[2];\r\n"
|
||||
@@ -163,6 +163,13 @@ public class CanvasShapeExporter extends ShapeExporterBase {
|
||||
+ "); return r;};\r\n"
|
||||
+ "this.isEmpty = function(){return this.r_add==0 && this.g_add==0 && this.b_add==0 && this.a_add==0 && this.r_mult==255 && this.g_mult==255 && this.b_mult==255 && this.a_mult==255};"
|
||||
+ "};\r\n"
|
||||
+ "\r\n"
|
||||
+ "var place = function(obj,canvas,ctx,matrix,ctrans,frame,ratio){\r\n"
|
||||
+ "\tctx.save();\r\n"
|
||||
+ "\tctx.transform(matrix[0],matrix[1],matrix[2],matrix[3],matrix[4],matrix[5]);\r\n"
|
||||
+ "\teval(obj+\"(ctx,ctrans,frame,ratio);\");\r\n"
|
||||
+ "\tctx.restore();\r\n"
|
||||
+ "}\r\n"
|
||||
+ "var tocolor = function(c){var r= \"rgba(\"+c[0]+\",\"+c[1]+\",\"+c[2]+\",\"+c[3]+\")\"; return r;};\r\n"
|
||||
+ "var ctrans = new cxform(0,0,0,0,255,255,255,255);\r\n";
|
||||
}
|
||||
@@ -242,9 +249,10 @@ public class CanvasShapeExporter extends ShapeExporterBase {
|
||||
public void beginFill(RGB color) {
|
||||
finalizePath();
|
||||
if (color == null) {
|
||||
color = basicFill;
|
||||
fillData += "\tctx.fillStyle=defaultFill;\r\n";
|
||||
}else{
|
||||
fillData += "\tctx.fillStyle=" + color(color) + ";\r\n";
|
||||
}
|
||||
fillData += "\tctx.fillStyle=" + color(color) + ";\r\n";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -339,7 +347,7 @@ public class CanvasShapeExporter extends ShapeExporterBase {
|
||||
fillMatrix = matrix;
|
||||
}
|
||||
|
||||
fillData += "\tvar fimg = ctrans.applyToImage(image" + bitmapId + ");";
|
||||
fillData += "\tvar fimg = ctrans.applyToImage(image" + bitmapId + ");\r\n";
|
||||
fillData += "\tvar pat=ctx.createPattern(fimg,\"repeat\");\r\n";
|
||||
fillData += "\tctx.fillStyle = pat;\r\n";
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.Matrix;
|
||||
import com.jpexs.decompiler.flash.exporters.commonshape.SVGExporter;
|
||||
import com.jpexs.decompiler.flash.exporters.shape.CanvasShapeExporter;
|
||||
import com.jpexs.decompiler.flash.helpers.FontHelper;
|
||||
import com.jpexs.decompiler.flash.tags.DefineFontNameTag;
|
||||
import com.jpexs.decompiler.flash.tags.DefineText2Tag;
|
||||
@@ -29,6 +30,7 @@ import com.jpexs.decompiler.flash.timeline.DepthState;
|
||||
import com.jpexs.decompiler.flash.types.ColorTransform;
|
||||
import com.jpexs.decompiler.flash.types.GLYPHENTRY;
|
||||
import com.jpexs.decompiler.flash.types.RECT;
|
||||
import com.jpexs.decompiler.flash.types.RGBA;
|
||||
import com.jpexs.decompiler.flash.types.SHAPE;
|
||||
import com.jpexs.decompiler.flash.types.TEXTRECORD;
|
||||
import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD;
|
||||
@@ -314,6 +316,21 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable
|
||||
|
||||
@Override
|
||||
public String toHtmlCanvas(double unitDivisor) {
|
||||
return ""; //TODO
|
||||
List<SHAPE> shapes = getGlyphShapeTable();
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.append("\tdefaultFill = textColor;\r\n");
|
||||
sb.append("\tswitch(ch){\r\n");
|
||||
for(int i=0;i<shapes.size();i++){
|
||||
char c= glyphToChar(i);
|
||||
String cs = ""+c;
|
||||
cs = cs.replace("\"", "\\\"");
|
||||
sb.append("\t\tcase \"").append(cs).append("\":\r\n");
|
||||
CanvasShapeExporter exporter = new CanvasShapeExporter(null, unitDivisor, swf, shapes.get(i), new ColorTransform(), 0, 0);
|
||||
exporter.export();
|
||||
sb.append("\t\t").append(exporter.getShapeData().replaceAll("\r\n", "\r\n\t\t"));
|
||||
sb.append("\tbreak;\r\n");
|
||||
}
|
||||
sb.append("\t}\r\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,9 +320,11 @@ public abstract class TextTag extends CharacterTag implements BoundedTag, Drawab
|
||||
Color textColor = new Color(0, 0, 0);
|
||||
String ret = "";
|
||||
FontTag font = null;
|
||||
int fontId = -1;
|
||||
int textHeight = 12;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int y = 0;
|
||||
|
||||
List<SHAPE> glyphs = new ArrayList<>();
|
||||
for (TEXTRECORD rec : textRecords) {
|
||||
if (rec.styleFlagsHasColor) {
|
||||
@@ -334,6 +336,7 @@ public abstract class TextTag extends CharacterTag implements BoundedTag, Drawab
|
||||
}
|
||||
if (rec.styleFlagsHasFont) {
|
||||
font = (FontTag) swf.characters.get(rec.fontId);
|
||||
fontId = rec.fontId;
|
||||
glyphs = font.getGlyphShapeTable();
|
||||
textHeight = rec.textHeight;
|
||||
}
|
||||
@@ -346,17 +349,15 @@ public abstract class TextTag extends CharacterTag implements BoundedTag, Drawab
|
||||
|
||||
double rat = textHeight / 1024.0 / font.getDivider();
|
||||
|
||||
|
||||
ret += "\tvar textColor = "+CanvasShapeExporter.color(textColor)+";\r\n";
|
||||
for (GLYPHENTRY entry : rec.glyphEntries) {
|
||||
Matrix mat = (new Matrix(textMatrix).concatenate(Matrix.getTranslateInstance(x, y))).concatenate(Matrix.getScaleInstance(rat));
|
||||
if (entry.glyphIndex != -1) {
|
||||
// shapeNum: 1
|
||||
ret += "\tctx.save();\r\n";
|
||||
ret += "\tctx.transform(" + mat.scaleX + "," + mat.rotateSkew0 + "," + mat.rotateSkew1 + "," + mat.scaleY + "," + mat.translateX + "," + mat.translateY + ");\r\n";
|
||||
|
||||
SHAPE shape = glyphs.get(entry.glyphIndex);
|
||||
CanvasShapeExporter exporter = new CanvasShapeExporter(new RGBA(textColor), unitDivisor, swf, shape, colorTransform, 0, 0);
|
||||
exporter.export();
|
||||
ret += exporter.getShapeData();
|
||||
ret += "\tfont"+fontId+"(ctx,\""+(""+font.glyphToChar(entry.glyphIndex)).replace("\"", "\\\"")+"\",textColor);\r\n";
|
||||
ret += "\tctx.restore();\r\n";
|
||||
x += entry.glyphAdvance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user