From 7bca0df0fd6b84c82464f14518b0da6bb02938e1 Mon Sep 17 00:00:00 2001 From: Koichi KAMICHI Date: Fri, 1 Feb 2013 21:13:21 +0900 Subject: [PATCH] Added stretch flag. --- kage.js | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 111 insertions(+), 10 deletions(-) diff --git a/kage.js b/kage.js index e6dda8c..cc98136 100755 --- a/kage.js +++ b/kage.js @@ -8,6 +8,13 @@ function Kage(size){ } Kage.prototype.makeGlyph = makeGlyph; + function makeGlyph2(polygons, data){ // void + if(data != ""){ + this.drawStrokesArray(polygons, this.adjustKirikuchi(this.adjustUroko2(this.adjustUroko(this.adjustKakato(this.adjustTate(this.adjustMage(this.adjustHane(this.getEachStrokes(data))))))))); + } + } + Kage.prototype.makeGlyph2 = makeGlyph2; + function getEachStrokes(glyphData){ // strokes array var strokesArray = new Array(); var strokes = glyphData.split("$"); @@ -34,7 +41,9 @@ function Kage(size){ Math.floor(columns[3]), Math.floor(columns[4]), Math.floor(columns[5]), - Math.floor(columns[6])) + Math.floor(columns[6]), + Math.floor(columns[1]), + Math.floor(columns[2])) ); } } @@ -43,10 +52,27 @@ function Kage(size){ } Kage.prototype.getEachStrokes = getEachStrokes; - function getEachStrokesOfBuhin(buhin, x1, y1, x2, y2){ + function getEachStrokesOfBuhin(buhin, x1, y1, x2, y2, a1, a2){ var temp = this.getEachStrokes(buhin); var result = new Array(); + var box = getBox(buhin); for(var i = 0; i < temp.length; i++){ + + var sx = a1; + var sy = a2; + if(sx != 0 || sy != 0){ + temp[i][3] = stretch(sx, temp[i][3], box.minX, box.maxX); + temp[i][4] = stretch(sy, temp[i][4], box.minY, box.maxY); + temp[i][5] = stretch(sx, temp[i][5], box.minX, box.maxX); + temp[i][6] = stretch(sy, temp[i][6], box.minY, box.maxY); + if(temp[i][0] != 99){ + temp[i][7] = stretch(sx, temp[i][7], box.minX, box.maxX); + temp[i][8] = stretch(sy, temp[i][8], box.minY, box.maxY); + } + temp[i][9] = stretch(sx, temp[i][9], box.minX, box.maxX); + temp[i][10] = stretch(sy, temp[i][10], box.minY, box.maxY); + } + result.push([temp[i][0], temp[i][1], temp[i][2], @@ -65,29 +91,32 @@ function Kage(size){ function adjustHane(sa){ // strokesArray for(var i = 0; i < sa.length; i++){ - if((sa[i][0] == 1 || sa[i][0] == 2) && sa[i][2] == 4){ + if((sa[i][0] == 1 || sa[i][0] == 2 || sa[i][0] == 6) && sa[i][2] == 4){ var lpx; // lastPointX var lpy; // lastPointY if(sa[i][0] == 1){ lpx = sa[i][5]; lpy = sa[i][6]; - } else { + } else if(sa[i][0] == 2){ lpx = sa[i][7]; lpy = sa[i][8]; + } else { + lpx = sa[i][9]; + lpy = sa[i][10]; } var mn = Infinity; // mostNear if(lpx + 18 < 100){ mn = lpx + 18; } for(var j = 0; j < sa.length; j++){ - if(i != j && sa[j][0] == 1 && sa[j][3] == sa[j][5] && sa[j][4] <= lpy && sa[j][6] >= lpy){ - if(lpx - sa[j][3] < 900){ + if(i != j && sa[j][0] == 1 && sa[j][3] == sa[j][5] && sa[j][3] < lpx && sa[j][4] <= lpy && sa[j][6] >= lpy){ + if(lpx - sa[j][3] < 100){ mn = Math.min(mn, lpx - sa[j][3]); } } } if(mn != Infinity){ - sa[i][2] += Math.min(400, 400 - Math.floor(mn / 20) * 100); // 0-8 -> 0-400 + sa[i][2] += 700 - Math.floor(mn / 15) * 100; // 0-99 -> 0-700 } } } @@ -274,17 +303,86 @@ function Kage(size){ Math.floor(columns[3]), Math.floor(columns[4]), Math.floor(columns[5]), - Math.floor(columns[6])); + Math.floor(columns[6]), + Math.floor(columns[1]), + Math.floor(columns[2])); } } } } Kage.prototype.drawGlyph = drawGlyph; - function drawBuhin(polygons, glyph, x1, y1, x2, y2){ // void + function getBox(glyph){ // minX, minY, maxX, maxY + var a = new Object(); + a.minX = 200; + a.minY = 200; + a.maxX = 0; + a.maxY = 0; + + var strokes = getEachStrokes(glyph); + for(var i = 0; i < strokes.length; i++){ + if(strokes[i][0] == 0){ continue; } + a.minX = Math.min(a.minX, strokes[i][3]); + a.maxX = Math.max(a.maxX, strokes[i][3]); + a.minY = Math.min(a.minY, strokes[i][4]); + a.maxY = Math.max(a.maxY, strokes[i][4]); + a.minX = Math.min(a.minX, strokes[i][5]); + a.maxX = Math.max(a.maxX, strokes[i][5]); + a.minY = Math.min(a.minY, strokes[i][6]); + a.maxY = Math.max(a.maxY, strokes[i][6]); + if(strokes[i][0] == 1){ continue; } + if(strokes[i][0] == 99){ continue; } + a.minX = Math.min(a.minX, strokes[i][7]); + a.maxX = Math.max(a.maxX, strokes[i][7]); + a.minY = Math.min(a.minY, strokes[i][8]); + a.maxY = Math.max(a.maxY, strokes[i][8]); + if(strokes[i][0] == 2){ continue; } + if(strokes[i][0] == 3){ continue; } + a.minX = Math.min(a.minX, strokes[i][9]); + a.maxX = Math.max(a.maxX, strokes[i][9]); + a.minY = Math.min(a.minY, strokes[i][10]); + a.maxY = Math.max(a.maxY, strokes[i][10]); + } + return a; + } + Kage.prototype.getBox = getBox; + + function stretch(dp, sp, min, max){ // interger + var p1, p2, p3, p4; + if(sp < 100){ + p1 = min; + p3 = min; + p2 = 100; + p4 = 100 + dp; + } else { + p1 = 100; + p3 = 100 + dp; + p2 = max; + p4 = max; + } + return Math.floor(((sp - p1) / (p2 - p1)) * (p4 - p3) + p3); + } + Kage.prototype.stretch = stretch; + + function drawBuhin(polygons, glyph, x1, y1, x2, y2, sx, sy){ // void var strokes = glyph.split("$"); + var box = getBox(glyph); for(var i = 0; i < strokes.length; i++){ var columns = strokes[i].split(":"); + + if(sx != 0 || sy != 0){ + columns[3] = stretch(sx, columns[3], box.minX, box.maxX); + columns[4] = stretch(sy, columns[4], box.minY, box.maxY); + columns[5] = stretch(sx, columns[5], box.minX, box.maxX); + columns[6] = stretch(sy, columns[6], box.minY, box.maxY); + if(columns[0] != 99){ + columns[7] = stretch(sx, columns[7], box.minX, box.maxX); + columns[8] = stretch(sy, columns[8], box.minY, box.maxY); + } + columns[9] = stretch(sx, columns[9], box.minX, box.maxX); + columns[10] = stretch(sy, columns[10], box.minY, box.maxY); + } + if(Math.floor(columns[0]) != 99){ dfDrawFont(this, polygons, Math.floor(columns[0]), @@ -305,7 +403,9 @@ function Kage(size){ x1 + Math.floor(columns[3]) * (x2 - x1) / 200, y1 + Math.floor(columns[4]) * (y2 - y1) / 200, x1 + Math.floor(columns[5]) * (x2 - x1) / 200, - y1 + Math.floor(columns[6]) * (y2 - y1) / 200); + y1 + Math.floor(columns[6]) * (y2 - y1) / 200, + Math.floor(columns[1]), + Math.floor(columns[2])); } } } @@ -372,3 +472,4 @@ function Kage(size){ return this; } + -- 1.7.10.4