3 function push(polygon){ // void
\r
4 // only a simple check
\r
9 for(var i = 0; i < polygon.array.length; i++){
\r
10 if(polygon.array[i].x < minx){
\r
11 minx = polygon.array[i].x;
\r
13 if(polygon.array[i].x > maxx){
\r
14 maxx = polygon.array[i].x;
\r
16 if(polygon.array[i].y < miny){
\r
17 miny = polygon.array[i].y;
\r
19 if(polygon.array[i].y > maxy){
\r
20 maxy = polygon.array[i].y;
\r
23 if(minx != maxx && miny != maxy && polygon.array.length >= 3){
\r
24 var newArray = new Array();
\r
25 newArray.push(polygon.array.shift());
\r
26 while(polygon.array.length != 0){
\r
27 var temp = polygon.array.shift();
\r
28 if(newArray[newArray.length - 1].x != temp.x ||
\r
29 newArray[newArray.length - 1].y != temp.y){
\r
30 newArray.push(temp);
\r
33 if(newArray.length >= 3){
\r
34 polygon.array = newArray;
\r
35 this.array.push(polygon);
\r
39 Polygons.prototype.push = push;
\r
41 function generateSVG(){ // string
\r
43 buffer += "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" baseProfile=\"full\" viewBox=\"0 0 199 199\">\n";
\r
44 buffer += "<g fill=\"black\">\n";
\r
45 for(var i = 0; i < this.array.length; i++){
\r
46 buffer += "<polygon points=\"";
\r
47 for(var j = 0; j < this.array[i].array.length; j++){
\r
48 buffer += this.array[i].array[j].x + "," + this.array[i].array[j].y + " ";
\r
50 buffer += "\" />\n";
\r
53 buffer += "</svg>\n";
\r
56 Polygons.prototype.generateSVG = generateSVG;
\r
58 function generateEPS(){ // string
\r
60 buffer += "%!PS-Adobe-3.0 EPSF-3.0\n";
\r
61 buffer += "%%BoundingBox: 0 -208 1024 816\n";
\r
62 buffer += "%%Pages: 0\n";
\r
63 buffer += "%%Title: Kanji glyph\n";
\r
64 buffer += "%%Creator: GlyphWiki powered by KAGE system\n";
\r
65 buffer += "%%CreationDate: " + new Date() + "\n";
\r
66 buffer += "%%EndComments\n";
\r
67 buffer += "%%EndProlog\n";
\r
68 buffer += "newpath\n";
\r
70 for(var i = 0; i < this.array.length; i++){
\r
71 for(var j = 0; j < this.array[i].array.length; j++){
\r
72 buffer += (this.array[i].array[j].x * 5) + " " + (1000 - this.array[i].array[j].y * 5 - 200) + " ";
\r
74 buffer += "moveto\n";
\r
76 buffer += "lineto\n";
\r
79 buffer += "closepath\n";
\r
82 buffer += "%%EOF\n";
\r
85 Polygons.prototype.generateEPS = generateEPS;
\r
88 this.array = new Array();
\r