3 function clear(){ // void
\r
4 this.array = new Array();
\r
6 Polygons.prototype.clear = clear;
\r
8 function push(polygon){ // void
\r
9 // only a simple check
\r
15 for(var i = 0; i < polygon.array.length; i++){
\r
16 if(polygon.array[i].x < minx){
\r
17 minx = polygon.array[i].x;
\r
19 if(polygon.array[i].x > maxx){
\r
20 maxx = polygon.array[i].x;
\r
22 if(polygon.array[i].y < miny){
\r
23 miny = polygon.array[i].y;
\r
25 if(polygon.array[i].y > maxy){
\r
26 maxy = polygon.array[i].y;
\r
28 if(isNaN(polygon.array[i].x) || isNaN(polygon.array[i].y)){
\r
32 if(error == 0 && minx != maxx && miny != maxy && polygon.array.length >= 3){
\r
33 var newArray = new Array();
\r
34 newArray.push(polygon.array.shift());
\r
35 while(polygon.array.length != 0){
\r
36 var temp = polygon.array.shift();
\r
37 if(newArray[newArray.length - 1].x != temp.x ||
\r
38 newArray[newArray.length - 1].y != temp.y){
\r
39 newArray.push(temp);
\r
42 if(newArray.length >= 3){
\r
43 polygon.array = newArray;
\r
44 this.array.push(polygon);
\r
48 Polygons.prototype.push = push;
\r
50 function generateSVG(){ // string
\r
52 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
53 buffer += "<g fill=\"black\">\n";
\r
54 for(var i = 0; i < this.array.length; i++){
\r
55 buffer += "<polygon points=\"";
\r
56 for(var j = 0; j < this.array[i].array.length; j++){
\r
57 buffer += this.array[i].array[j].x + "," + this.array[i].array[j].y + " ";
\r
59 buffer += "\" />\n";
\r
62 buffer += "</svg>\n";
\r
65 Polygons.prototype.generateSVG = generateSVG;
\r
67 function generateEPS(){ // string
\r
69 buffer += "%!PS-Adobe-3.0 EPSF-3.0\n";
\r
70 buffer += "%%BoundingBox: 0 -208 1024 816\n";
\r
71 buffer += "%%Pages: 0\n";
\r
72 buffer += "%%Title: Kanji glyph\n";
\r
73 buffer += "%%Creator: GlyphWiki powered by KAGE system\n";
\r
74 buffer += "%%CreationDate: " + new Date() + "\n";
\r
75 buffer += "%%EndComments\n";
\r
76 buffer += "%%EndProlog\n";
\r
78 for(var i = 0; i < this.array.length; i++){
\r
79 for(var j = 0; j < this.array[i].array.length; j++){
\r
80 buffer += (this.array[i].array[j].x * 5) + " " + (1000 - this.array[i].array[j].y * 5 - 200) + " ";
\r
82 buffer += "newpath\nmoveto\n";
\r
84 buffer += "lineto\n";
\r
87 buffer += "closepath\nfill\n";
\r
89 buffer += "%%EOF\n";
\r
92 Polygons.prototype.generateEPS = generateEPS;
\r
95 this.array = new Array();
\r