From 7f69c1069c8e843da73df0e4fe101695138d8f35 Mon Sep 17 00:00:00 2001 From: Koichi KAMICHI Date: Thu, 5 Jun 2008 06:33:07 +0000 Subject: [PATCH] Detect error polygon(stroke) and skip output. --- engine/polygons.js | 176 +++++++++++++++++++++++++++------------------------- 1 file changed, 90 insertions(+), 86 deletions(-) diff --git a/engine/polygons.js b/engine/polygons.js index fed54a1..dd3582a 100755 --- a/engine/polygons.js +++ b/engine/polygons.js @@ -1,91 +1,95 @@ function Polygons(){ - // method - function push(polygon){ // void - // only a simple check - var minx = 200; - var maxx = 0; - var miny = 200; - var maxy = 0; - for(var i = 0; i < polygon.array.length; i++){ - if(polygon.array[i].x < minx){ - minx = polygon.array[i].x; - } - if(polygon.array[i].x > maxx){ - maxx = polygon.array[i].x; - } - if(polygon.array[i].y < miny){ - miny = polygon.array[i].y; - } - if(polygon.array[i].y > maxy){ - maxy = polygon.array[i].y; - } - } - if(minx != maxx && miny != maxy && polygon.array.length >= 3){ - var newArray = new Array(); - newArray.push(polygon.array.shift()); - while(polygon.array.length != 0){ - var temp = polygon.array.shift(); - if(newArray[newArray.length - 1].x != temp.x || - newArray[newArray.length - 1].y != temp.y){ - newArray.push(temp); - } - } - if(newArray.length >= 3){ - polygon.array = newArray; - this.array.push(polygon); - } - } - } - Polygons.prototype.push = push; - - function generateSVG(){ // string - var buffer = ""; - buffer += "\n"; - buffer += "\n"; - for(var i = 0; i < this.array.length; i++){ - buffer += "\n"; - } - buffer += "\n"; - buffer += "\n"; - return buffer; - } - Polygons.prototype.generateSVG = generateSVG; - - function generateEPS(){ // string - var buffer = ""; - buffer += "%!PS-Adobe-3.0 EPSF-3.0\n"; - buffer += "%%BoundingBox: 0 -208 1024 816\n"; - buffer += "%%Pages: 0\n"; - buffer += "%%Title: Kanji glyph\n"; - buffer += "%%Creator: GlyphWiki powered by KAGE system\n"; - buffer += "%%CreationDate: " + new Date() + "\n"; - buffer += "%%EndComments\n"; - buffer += "%%EndProlog\n"; - buffer += "newpath\n"; - - for(var i = 0; i < this.array.length; i++){ - for(var j = 0; j < this.array[i].array.length; j++){ - buffer += (this.array[i].array[j].x * 5) + " " + (1000 - this.array[i].array[j].y * 5 - 200) + " "; - if(j == 0){ - buffer += "moveto\n"; - } else { - buffer += "lineto\n"; + // method + function push(polygon){ // void + // only a simple check + var minx = 200; + var maxx = 0; + var miny = 200; + var maxy = 0; + var error = 0; + for(var i = 0; i < polygon.array.length; i++){ + if(polygon.array[i].x < minx){ + minx = polygon.array[i].x; + } + if(polygon.array[i].x > maxx){ + maxx = polygon.array[i].x; + } + if(polygon.array[i].y < miny){ + miny = polygon.array[i].y; + } + if(polygon.array[i].y > maxy){ + maxy = polygon.array[i].y; + } + if(isNaN(polygon.array[i].x) || isNaN(polygon.array[i].y)){ + error++; + } + } + if(error == 0 && minx != maxx && miny != maxy && polygon.array.length >= 3){ + var newArray = new Array(); + newArray.push(polygon.array.shift()); + while(polygon.array.length != 0){ + var temp = polygon.array.shift(); + if(newArray[newArray.length - 1].x != temp.x || + newArray[newArray.length - 1].y != temp.y){ + newArray.push(temp); + } + } + if(newArray.length >= 3){ + polygon.array = newArray; + this.array.push(polygon); + } + } + } + Polygons.prototype.push = push; + + function generateSVG(){ // string + var buffer = ""; + buffer += "\n"; + buffer += "\n"; + for(var i = 0; i < this.array.length; i++){ + buffer += "\n"; + } + buffer += "\n"; + buffer += "\n"; + return buffer; } - } - buffer += "closepath\n"; - } - buffer += "fill\n"; - buffer += "%%EOF\n"; - return buffer; + Polygons.prototype.generateSVG = generateSVG; + + function generateEPS(){ // string + var buffer = ""; + buffer += "%!PS-Adobe-3.0 EPSF-3.0\n"; + buffer += "%%BoundingBox: 0 -208 1024 816\n"; + buffer += "%%Pages: 0\n"; + buffer += "%%Title: Kanji glyph\n"; + buffer += "%%Creator: GlyphWiki powered by KAGE system\n"; + buffer += "%%CreationDate: " + new Date() + "\n"; + buffer += "%%EndComments\n"; + buffer += "%%EndProlog\n"; + buffer += "newpath\n"; + + for(var i = 0; i < this.array.length; i++){ + for(var j = 0; j < this.array[i].array.length; j++){ + buffer += (this.array[i].array[j].x * 5) + " " + (1000 - this.array[i].array[j].y * 5 - 200) + " "; + if(j == 0){ + buffer += "moveto\n"; + } else { + buffer += "lineto\n"; + } + } + buffer += "closepath\n"; + } + buffer += "fill\n"; + buffer += "%%EOF\n"; + return buffer; } Polygons.prototype.generateEPS = generateEPS; - - // property - this.array = new Array(); - - return this; + + // property + this.array = new Array(); + + return this; } -- 1.7.10.4