function Polygons(){\r
// method\r
+ function clear(){ // void\r
+ this.array = new Array();\r
+ }\r
+ Polygons.prototype.clear = clear;\r
+ \r
function push(polygon){ // void\r
// only a simple check\r
var minx = 200;\r
var maxx = 0;\r
var miny = 200;\r
var maxy = 0;\r
+ var error = 0;\r
for(var i = 0; i < polygon.array.length; i++){\r
if(polygon.array[i].x < minx){\r
- minx = polygon.array[i].x;\r
+ minx = polygon.array[i].x;\r
}\r
if(polygon.array[i].x > maxx){\r
- maxx = polygon.array[i].x;\r
+ maxx = polygon.array[i].x;\r
}\r
if(polygon.array[i].y < miny){\r
- miny = polygon.array[i].y;\r
+ miny = polygon.array[i].y;\r
}\r
if(polygon.array[i].y > maxy){\r
- maxy = polygon.array[i].y;\r
+ maxy = polygon.array[i].y;\r
+ }\r
+ if(isNaN(polygon.array[i].x) || isNaN(polygon.array[i].y)){\r
+ error++;\r
}\r
}\r
- if(minx != maxx && miny != maxy && polygon.array.length >= 3){\r
+ if(error == 0 && minx != maxx && miny != maxy && polygon.array.length >= 3){\r
var newArray = new Array();\r
newArray.push(polygon.array.shift());\r
while(polygon.array.length != 0){\r
- var temp = polygon.array.shift();\r
- if(newArray[newArray.length - 1].x != temp.x ||\r
- newArray[newArray.length - 1].y != temp.y){\r
- newArray.push(temp);\r
- }\r
+ var temp = polygon.array.shift();\r
+ //if(newArray[newArray.length - 1].x != temp.x ||\r
+ // newArray[newArray.length - 1].y != temp.y){\r
+ newArray.push(temp);\r
+ //}\r
}\r
if(newArray.length >= 3){\r
- polygon.array = newArray;\r
- this.array.push(polygon);\r
+ polygon.array = newArray;\r
+ this.array.push(polygon);\r
}\r
}\r
}\r
Polygons.prototype.push = push;\r
\r
- function generateSVG(){ // string\r
+ function generateSVG(curve){ // string\r
var buffer = "";\r
- buffer += "<?xml version=\"1.0\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n";\r
- buffer += "<svg width=\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" baseProfile=\"full\">\n";\r
- buffer += "<g fill=\"black\">\n";\r
+ 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 200 200\" width=\"200\" height=\"200\">\n";\r
+ if(curve){\r
+ for(var i = 0; i < this.array.length; i++){\r
+ var mode = "L";\r
+ buffer += "<path d=\"M ";\r
+ buffer += this.array[i].array[0].x + "," + this.array[i].array[0].y + " ";\r
+ for(var j = 1; j < this.array[i].array.length; j++){\r
+ if(this.array[i].array[j].off == 1){\r
+ buffer += "Q ";\r
+ mode = "Q";\r
+ } else if(mode == "Q" && this.array[i].array[j - 1].off != 1){\r
+ buffer += "L ";\r
+ } else if(mode == "L" && j == 1){\r
+ buffer += "L ";\r
+ }\r
+ buffer += this.array[i].array[j].x + "," + this.array[i].array[j].y + " ";\r
+ }\r
+ buffer += "Z\" fill=\"black\" />\n";\r
+ }\r
+ buffer += "</svg>\n";\r
+ } else {\r
+ buffer += "<g fill=\"black\">\n";\r
+ for(var i = 0; i < this.array.length; i++){\r
+ buffer += "<polygon points=\"";\r
+ for(var j = 0; j < this.array[i].array.length; j++){\r
+ buffer += this.array[i].array[j].x + "," + this.array[i].array[j].y + " ";\r
+ }\r
+ buffer += "\" />\n";\r
+ }\r
+ buffer += "</g>\n";\r
+ buffer += "</svg>\n";\r
+ }\r
+ return buffer;\r
+ }\r
+ Polygons.prototype.generateSVG = generateSVG;\r
+ \r
+ function generateEPS(){ // string\r
+ var buffer = "";\r
+ buffer += "%!PS-Adobe-3.0 EPSF-3.0\n";\r
+ buffer += "%%BoundingBox: 0 -208 1024 816\n";\r
+ buffer += "%%Pages: 0\n";\r
+ buffer += "%%Title: Kanji glyph\n";\r
+ buffer += "%%Creator: GlyphWiki powered by KAGE system\n";\r
+ buffer += "%%CreationDate: " + new Date() + "\n";\r
+ buffer += "%%EndComments\n";\r
+ buffer += "%%EndProlog\n";\r
+ \r
for(var i = 0; i < this.array.length; i++){\r
- buffer += "<polygon points=\"";\r
for(var j = 0; j < this.array[i].array.length; j++){\r
- buffer += this.array[i].array[j].x + "," + this.array[i].array[j].y + " ";\r
+ buffer += (this.array[i].array[j].x * 5) + " " + (1000 - this.array[i].array[j].y * 5 - 200) + " ";\r
+ if(j == 0){\r
+ buffer += "newpath\nmoveto\n";\r
+ } else {\r
+ buffer += "lineto\n";\r
+ }\r
}\r
- buffer += "\" />\n";\r
+ buffer += "closepath\nfill\n";\r
}\r
- buffer += "</g>\n";\r
- buffer += "</svg>\n";\r
+ buffer += "%%EOF\n";\r
return buffer;\r
}\r
- Polygons.prototype.generateSVG = generateSVG;\r
+ Polygons.prototype.generateEPS = generateEPS;\r
\r
// property\r
this.array = new Array();\r