Icon refactoring
This commit is contained in:
@@ -24,12 +24,12 @@ public class FontGenerator{
|
||||
|
||||
Log.info("Session...");
|
||||
|
||||
OS.exec("curl", "--fail", "--output", "core/assets-raw/fontgen/out/session", "--form", "config=@core/assets-raw/fontgen/config.json", "http://fontello.com");
|
||||
OS.exec("curl", "--fail", "--output", "core/assets-raw/fontgen/out/session", "--form", "config=@core/assets-raw/fontgen/config.json", "https://fontello.com");
|
||||
|
||||
Log.info("Zip...");
|
||||
|
||||
String session = folder.child("session").readString();
|
||||
net.httpGet("http://fontello.com/" + session + "/get", result -> {
|
||||
net.httpGet("https://fontello.com/" + session + "/get", result -> {
|
||||
try{
|
||||
Streams.copy(result.getResultAsStream(), folder.child("font.zip").write());
|
||||
}catch(IOException e){
|
||||
@@ -46,8 +46,7 @@ public class FontGenerator{
|
||||
|
||||
Log.info("Merge...");
|
||||
|
||||
//don't merge since it breaks the font
|
||||
//OS.exec("fontforge", "-script", "core/assets-raw/fontgen/merge.pe");
|
||||
OS.exec("fontforge", "-script", "core/assets-raw/fontgen/merge.pe");
|
||||
|
||||
Log.info("Done.");
|
||||
}
|
||||
|
||||
@@ -1,40 +1,62 @@
|
||||
package mindustry.tools;
|
||||
|
||||
import arc.*;
|
||||
import arc.files.*;
|
||||
import arc.graphics.*;
|
||||
import arc.graphics.g2d.*;
|
||||
import arc.graphics.gl.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
|
||||
public class SquareMarcher{
|
||||
final int resolution;
|
||||
FrameBuffer buffer;
|
||||
public class IconConverter{
|
||||
StringBuilder out = new StringBuilder();
|
||||
float width, height;
|
||||
|
||||
SquareMarcher(int resolution){
|
||||
this.resolution = resolution;
|
||||
this.buffer = new FrameBuffer(resolution, resolution);
|
||||
public static void main(String[] __){
|
||||
|
||||
Log.info("Converting icons...");
|
||||
Time.mark();
|
||||
Fi.get("fontgen/icons").deleteDirectory();
|
||||
Fi.get("fontgen/icon_parts").deleteDirectory();
|
||||
Fi[] list = new Fi("icons").list();
|
||||
|
||||
ArcNativesLoader.load();
|
||||
Seq<Fi> files = new Seq<>();
|
||||
|
||||
for(Fi img : list){
|
||||
if(img.extension().equals("png")){
|
||||
Fi dst = new Fi("fontgen/icons").child(img.nameWithoutExtension().replace("icon-", "") + ".svg");
|
||||
new IconConverter().convert(new Pixmap(img), dst);
|
||||
dst.copyTo(new Fi("fontgen/icon_parts/").child(dst.name()));
|
||||
files.add(dst);
|
||||
}
|
||||
}
|
||||
|
||||
Seq<String> args = Seq.with("inkscape", "--batch-process", "--verb", "EditSelectAll;SelectionUnion;FitCanvasToSelectionOrDrawing;FileSave");
|
||||
args.addAll(files.map(Fi::absolutePath));
|
||||
|
||||
Fi.get("fontgen/extra").findAll().each(f -> f.copyTo(Fi.get("fontgen/icons").child(f.name())));
|
||||
|
||||
Log.info("Merging paths...");
|
||||
Log.info(OS.exec(args.toArray(String.class)));
|
||||
|
||||
Log.info("Done converting icons in &lm@&lgs.", Time.elapsed()/1000f);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
void render(Pixmap pixmap, Fi file){
|
||||
void convert(Pixmap pixmap, Fi output){
|
||||
boolean[][] grid = new boolean[pixmap.getWidth()][pixmap.getHeight()];
|
||||
|
||||
for(int x = 0; x < pixmap.getWidth(); x++){
|
||||
for(int y = 0; y < pixmap.getHeight(); y++){
|
||||
Tmp.c1.set(pixmap.getPixel(x, y));
|
||||
grid[x][pixmap.getHeight() - 1 - y] = Tmp.c1.a > 0.01f;
|
||||
grid[x][pixmap.getHeight() - 1 - y] = !Pixmaps.empty(pixmap.getPixel(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
float xscl = resolution / (float)pixmap.getWidth(), yscl = resolution / (float)pixmap.getHeight();
|
||||
float xscl = 1f, yscl = 1f;//resolution / (float)pixmap.getWidth(), yscl = resolution / (float)pixmap.getHeight();
|
||||
float scl = xscl;
|
||||
|
||||
Draw.flush();
|
||||
Draw.proj().setOrtho(-xscl / 2f, -yscl / 2f, resolution, resolution);
|
||||
width = pixmap.getWidth();
|
||||
height = pixmap.getHeight();
|
||||
|
||||
buffer.begin();
|
||||
Core.graphics.clear(Color.clear);
|
||||
Draw.color(Color.white);
|
||||
out.append("<svg width=\"").append(pixmap.getWidth()).append("\" height=\"").append(pixmap.getHeight()).append("\">\n");
|
||||
|
||||
for(int x = -1; x < pixmap.getWidth(); x++){
|
||||
for(int y = -1; y < pixmap.getHeight(); y++){
|
||||
@@ -47,24 +69,24 @@ public class SquareMarcher{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
Fill.tri(
|
||||
tri(
|
||||
leftx, midy,
|
||||
leftx, topy,
|
||||
midx, topy
|
||||
);
|
||||
break;
|
||||
case 2:
|
||||
Fill.tri(
|
||||
tri(
|
||||
midx, topy,
|
||||
rightx, topy,
|
||||
rightx, midy
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
Fill.crect(leftx, midy, scl, scl / 2f);
|
||||
rect(leftx, midy, scl, scl / 2f);
|
||||
break;
|
||||
case 4:
|
||||
Fill.tri(
|
||||
tri(
|
||||
midx, boty,
|
||||
rightx, boty,
|
||||
rightx, midy
|
||||
@@ -74,125 +96,148 @@ public class SquareMarcher{
|
||||
//ambiguous
|
||||
|
||||
//7
|
||||
Fill.tri(
|
||||
tri(
|
||||
leftx, midy,
|
||||
midx, midy,
|
||||
midx, boty
|
||||
);
|
||||
|
||||
//13
|
||||
Fill.tri(
|
||||
tri(
|
||||
midx, topy,
|
||||
midx, midy,
|
||||
rightx, midy
|
||||
);
|
||||
|
||||
Fill.crect(leftx, midy, scl / 2f, scl / 2f);
|
||||
Fill.crect(midx, boty, scl / 2f, scl / 2f);
|
||||
rect(leftx, midy, scl / 2f, scl / 2f);
|
||||
rect(midx, boty, scl / 2f, scl / 2f);
|
||||
|
||||
break;
|
||||
case 6:
|
||||
Fill.crect(midx, boty, scl / 2f, scl);
|
||||
rect(midx, boty, scl / 2f, scl);
|
||||
break;
|
||||
case 7:
|
||||
//invert triangle
|
||||
Fill.tri(
|
||||
tri(
|
||||
leftx, midy,
|
||||
midx, midy,
|
||||
midx, boty
|
||||
);
|
||||
|
||||
//3
|
||||
Fill.crect(leftx, midy, scl, scl / 2f);
|
||||
rect(leftx, midy, scl, scl / 2f);
|
||||
|
||||
Fill.crect(midx, boty, scl / 2f, scl / 2f);
|
||||
rect(midx, boty, scl / 2f, scl / 2f);
|
||||
break;
|
||||
case 8:
|
||||
Fill.tri(
|
||||
tri(
|
||||
leftx, boty,
|
||||
leftx, midy,
|
||||
midx, boty
|
||||
);
|
||||
break;
|
||||
case 9:
|
||||
Fill.crect(leftx, boty, scl / 2f, scl);
|
||||
rect(leftx, boty, scl / 2f, scl);
|
||||
break;
|
||||
case 10:
|
||||
//ambiguous
|
||||
|
||||
//11
|
||||
Fill.tri(
|
||||
tri(
|
||||
midx, boty,
|
||||
midx, midy,
|
||||
rightx, midy
|
||||
);
|
||||
|
||||
//14
|
||||
Fill.tri(
|
||||
tri(
|
||||
leftx, midy,
|
||||
midx, midy,
|
||||
midx, topy
|
||||
);
|
||||
|
||||
Fill.crect(midx, midy, scl / 2f, scl / 2f);
|
||||
Fill.crect(leftx, boty, scl / 2f, scl / 2f);
|
||||
rect(midx, midy, scl / 2f, scl / 2f);
|
||||
rect(leftx, boty, scl / 2f, scl / 2f);
|
||||
|
||||
break;
|
||||
case 11:
|
||||
//invert triangle
|
||||
|
||||
Fill.tri(
|
||||
tri(
|
||||
midx, boty,
|
||||
midx, midy,
|
||||
rightx, midy
|
||||
);
|
||||
|
||||
//3
|
||||
Fill.crect(leftx, midy, scl, scl / 2f);
|
||||
rect(leftx, midy, scl, scl / 2f);
|
||||
|
||||
Fill.crect(leftx, boty, scl / 2f, scl / 2f);
|
||||
rect(leftx, boty, scl / 2f, scl / 2f);
|
||||
break;
|
||||
case 12:
|
||||
Fill.crect(leftx, boty, scl, scl / 2f);
|
||||
rect(leftx, boty, scl, scl / 2f);
|
||||
break;
|
||||
case 13:
|
||||
//invert triangle
|
||||
|
||||
Fill.tri(
|
||||
tri(
|
||||
midx, topy,
|
||||
midx, midy,
|
||||
rightx, midy
|
||||
);
|
||||
|
||||
//12
|
||||
Fill.crect(leftx, boty, scl, scl / 2f);
|
||||
rect(leftx, boty, scl, scl / 2f);
|
||||
|
||||
Fill.crect(leftx, midy, scl / 2f, scl / 2f);
|
||||
rect(leftx, midy, scl / 2f, scl / 2f);
|
||||
break;
|
||||
case 14:
|
||||
//invert triangle
|
||||
|
||||
Fill.tri(
|
||||
tri(
|
||||
leftx, midy,
|
||||
midx, midy,
|
||||
midx, topy
|
||||
);
|
||||
|
||||
//12
|
||||
Fill.crect(leftx, boty, scl, scl / 2f);
|
||||
rect(leftx, boty, scl, scl / 2f);
|
||||
|
||||
Fill.crect(midx, midy, scl / 2f, scl / 2f);
|
||||
rect(midx, midy, scl / 2f, scl / 2f);
|
||||
break;
|
||||
case 15:
|
||||
Fill.square(midx, midy, scl / 2f);
|
||||
square(midx, midy, scl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Draw.flush();
|
||||
ScreenUtils.saveScreenshot(file, 0, 0, resolution, resolution);
|
||||
buffer.end();
|
||||
out.append("</svg>");
|
||||
|
||||
output.writeString(out.toString());
|
||||
}
|
||||
|
||||
void square(float x, float y, float size){
|
||||
rect(x - size/2f, y - size/2f, size, size);
|
||||
}
|
||||
|
||||
void tri(float x1, float y1, float x2, float y2, float x3, float y3){
|
||||
out.append("<polygon points=\"");
|
||||
out.append(x1 + 0.5f).append(",").append(flip(y1 + 0.5f)).append(" ");
|
||||
out.append(x2 + 0.5f).append(",").append(flip(y2 + 0.5f)).append(" ");
|
||||
out.append(x3 + 0.5f).append(",").append(flip(y3 + 0.5f)).append("\" ");
|
||||
out.append("style=\"fill:white\" />\n");
|
||||
}
|
||||
|
||||
void rect(float x1, float y1, float width, float height){
|
||||
out.append("<rect x=\"")
|
||||
.append(x1 + 0.5f).append("\" y=\"").append(flip(y1 + 0.5f) - height)
|
||||
.append("\" width=\"").append(width).append("\" height=\"")
|
||||
.append(height).append("\" style=\"fill:white\" />\n");
|
||||
}
|
||||
|
||||
float flip(float y){
|
||||
return height - y;
|
||||
}
|
||||
|
||||
int index(int x, int y, int w, int h, boolean[][] grid){
|
||||
@@ -204,6 +249,6 @@ public class SquareMarcher{
|
||||
}
|
||||
|
||||
int sample(boolean[][] grid, int x, int y){
|
||||
return (x < 0 || y < 0 || x >= grid.length || y >= grid.length) ? 0 : grid[x][y] ? 1 : 0;
|
||||
return (x < 0 || y < 0 || x >= grid.length || y >= grid[0].length) ? 0 : grid[x][y] ? 1 : 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user