-
-
Notifications
You must be signed in to change notification settings - Fork 375
/
SVGExport.hx
179 lines (144 loc) · 3.77 KB
/
SVGExport.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package;
import format.SVG;
import hxp.*;
import lime.tools.Architecture;
import openfl.display.Bitmap;
import openfl.display.BitmapData;
import openfl.display.PNGEncoderOptions;
import openfl.display.Shape;
import openfl.geom.Matrix;
import sys.io.File;
import sys.io.Process;
import sys.FileSystem;
class SVGExport
{
#if (neko && (haxe_210 || haxe3))
public static function __init__()
{
var haxePath = Sys.getEnv("HAXEPATH");
var command = (haxePath != null && haxePath != "") ? haxePath + "/haxelib" : "haxelib";
var path = "";
if (FileSystem.exists("svg.n"))
{
path = Path.combine(Sys.getCwd(), "../ndll/");
}
if (path == "")
{
var process = new Process("haxelib", ["path", "lime"]);
try
{
while (true)
{
var line = StringTools.trim(process.stdout.readLine());
if (StringTools.startsWith(line, "-L "))
{
path = StringTools.trim(line.substr(2));
break;
}
}
}
catch (e:Dynamic) {}
process.close();
}
switch (System.hostPlatform)
{
case WINDOWS:
// var is64 = neko.Lib.load("std", "sys_is64", 0)();
untyped $loader.path = $array(path + "Windows/", $loader.path);
// if (CFFI.enabled)
// {
try
{
neko.Lib.load("lime", "lime_application_create", 0);
}
catch (e:Dynamic)
{
untyped $loader.path = $array(path + "Windows64/", $loader.path);
}
// }
case MAC:
if (System.hostArchitecture == X64)
{
untyped $loader.path = $array(path + "Mac64/", $loader.path);
}
else if (System.hostArchitecture == ARM64)
{
untyped $loader.path = $array(path + "MacArm64/", $loader.path);
}
case LINUX:
var arguments = Sys.args();
if ( System.hostArchitecture == ARMV7 )
{
untyped $loader.path = $array(path + "LinuxArm/", $loader.path);
}
else if (System.hostArchitecture == ARM64)
{
untyped $loader.path = $array(path + "LinuxArm64/", $loader.path);
}
else if (System.hostArchitecture == X64)
{
untyped $loader.path = $array(path + "Linux64/", $loader.path);
}
else
{
untyped $loader.path = $array(path + "Linux/", $loader.path);
}
default:
}
}
#end
public static function main()
{
var arguments = Sys.args();
/*if (arguments.length > 0) {
// When the command-line tools are called from haxelib,
// the last argument is the project directory and the
// path SWF is the current working directory
var lastArgument = "";
for (i in 0...arguments.length) {
lastArgument = arguments.pop ();
if (lastArgument.length > 0) break;
}
lastArgument = new Path (lastArgument).toString ();
if (((StringTools.endsWith (lastArgument, "/") && lastArgument != "/") || StringTools.endsWith (lastArgument, "\\")) && !StringTools.endsWith (lastArgument, ":\\")) {
lastArgument = lastArgument.substr (0, lastArgument.length - 1);
}
if (FileSystem.exists (lastArgument) && FileSystem.isDirectory (lastArgument)) {
Sys.setCwd (lastArgument);
}
}*/
var words = new Array<String>();
for (arg in arguments)
{
if (arg == "-verbose")
{
Log.verbose = true;
}
else
{
words.push(arg);
}
}
if (words.length > 4 && words[0] == "process")
{
try
{
var inputPath = words[1];
var width = Std.parseInt(words[2]);
var height = Std.parseInt(words[3]);
var outputPath = words[4];
var svg = new SVG(File.getContent(inputPath));
var backgroundColor = 0x00FFFFFF;
var shape = new Shape();
svg.render(shape.graphics, 0, 0, width, height);
var bitmapData = new BitmapData(width, height, true, backgroundColor);
bitmapData.draw(shape);
File.saveBytes(outputPath, bitmapData.encode(bitmapData.rect, new PNGEncoderOptions()));
}
catch (e:Dynamic)
{
Log.error(e);
}
}
}
}