From 86f379019f3b96c555a60d621fae4263209f4006 Mon Sep 17 00:00:00 2001 From: kamichi Date: Fri, 1 Feb 2013 21:20:27 +0900 Subject: [PATCH] Added stretch function. --- engine/kage.js | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 103 insertions(+), 5 deletions(-) diff --git a/engine/kage.js b/engine/kage.js index cbb41b4..cc98136 100755 --- a/engine/kage.js +++ b/engine/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], @@ -277,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]), @@ -308,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])); } } } @@ -375,3 +472,4 @@ function Kage(size){ return this; } + -- 1.7.10.4