-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathunionpoly.pl
executable file
·62 lines (51 loc) · 1.34 KB
/
unionpoly.pl
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
#!/usr/bin/perl
use Math::Clipper ':all';
$filename = $ARGV[0];
open FH, "<$filename";
my @buffer = <FH>;
close FH;
my @poly = ();
my $count = 0;
foreach(@buffer){
if($_ =~ m/^<polygon points="([^"]+)"/){
my @temp = split(/ /, $1);
@temp = map{ my @temp2 = split(/,/, $_); map{ $_ *= 10; } @temp2; join(",", @temp2) } @temp;
my $temp = "[ [".join('],[', @temp)."] ]";
if(!orientation(eval($temp))){
$temp = "[ [".join('],[', reverse(@temp))."] ]";
}
push(@poly, $temp);
$count++;
}
}
$result = simplify_polygons(eval("[".join(",", @poly)."]"), PFT_NONZERO);
# if($count == 0){
# exit;
# }
# unlink($filename);
open FH, ">$filename.font";
print FH<<"EOT";
<font horiz-adv-x="1000">
<font-face font-family="GlyphWiki" units-per-em="1000" ascent="880" descent="120"/>
EOT
if ($count != 0) {
print FH "<glyph unicode=\"a\" d=\"";
my $i = 0;
while(length($result->[$i][0][0]) > 0){
print FH "M ".($result->[$i][0][0] / 2)." ".(- $result->[$i][0][1] / 2 + 880)." ";
my $j = 1;
while(length($result->[$i][$j][0]) > 0){
print FH "L ".($result->[$i][$j][0] / 2)." ".(- $result->[$i][$j][1] / 2 + 880)." ";
$j++;
}
print FH "Z ";
$i++;
}
print FH "\" />\n";
} else {
print FH "<glyph unicode=\"a\" d=\"\" />\n";
}
print FH <<"EOT";
</font>
EOT
close FH;