X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=engine%2Fkage.js;h=c58fda5b0d7f3cea07de0a8269462304f4c9bdd3;hb=45dfe74aad98a359dd6e8a0ad46adcb7b3dcfa66;hp=0fe9bdc5f49c339b8366bc2636657c8ac0b108f9;hpb=56ba2717831bb2d60440ef2f3de610887a1b7058;p=chise%2Fkage.git diff --git a/engine/kage.js b/engine/kage.js old mode 100755 new mode 100644 index 0fe9bdc..c58fda5 --- a/engine/kage.js +++ b/engine/kage.js @@ -1,13 +1,57 @@ -function Kage(){ +function Kage(size){ // method function makeGlyph(polygons, buhin){ // void var glyphData = this.kBuhin.search(buhin); - if(glyphData != ""){ - this.drawStrokesArray(polygons, this.adjustKirikuchi(this.adjustUroko(this.adjustKakato(this.getEachStrokes(glyphData))))); - } + this.makeGlyph2(polygons, glyphData); } Kage.prototype.makeGlyph = makeGlyph; + function makeGlyph2(polygons, data){ // void + if(data != ""){ + var strokesArray = this.adjustKirikuchi(this.adjustUroko2(this.adjustUroko(this.adjustKakato(this.adjustTate(this.adjustMage(this.adjustHane(this.getEachStrokes(data)))))))); + for(var i = 0; i < strokesArray.length; i++){ + dfDrawFont(this, polygons, + strokesArray[i][0], + strokesArray[i][1], + strokesArray[i][2], + strokesArray[i][3], + strokesArray[i][4], + strokesArray[i][5], + strokesArray[i][6], + strokesArray[i][7], + strokesArray[i][8], + strokesArray[i][9], + strokesArray[i][10]); + } + } + } + Kage.prototype.makeGlyph2 = makeGlyph2; + + function makeGlyph3(data){ // void + var result = new Array(); + if(data != ""){ + var strokesArray = this.adjustKirikuchi(this.adjustUroko2(this.adjustUroko(this.adjustKakato(this.adjustTate(this.adjustMage(this.adjustHane(this.getEachStrokes(data)))))))); + for(var i = 0; i < strokesArray.length; i++){ + var polygons = new Polygons(); + dfDrawFont(this, polygons, + strokesArray[i][0], + strokesArray[i][1], + strokesArray[i][2], + strokesArray[i][3], + strokesArray[i][4], + strokesArray[i][5], + strokesArray[i][6], + strokesArray[i][7], + strokesArray[i][8], + strokesArray[i][9], + strokesArray[i][10]); + result.push(polygons); + } + } + return result; + } + Kage.prototype.makeGlyph3 = makeGlyph3; + function getEachStrokes(glyphData){ // strokes array var strokesArray = new Array(); var strokes = glyphData.split("$"); @@ -34,7 +78,11 @@ function Kage(){ 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]), + Math.floor(columns[9]), + Math.floor(columns[10])) ); } } @@ -43,10 +91,31 @@ function Kage(){ } Kage.prototype.getEachStrokes = getEachStrokes; - function getEachStrokesOfBuhin(buhin, x1, y1, x2, y2){ + function getEachStrokesOfBuhin(buhin, x1, y1, x2, y2, sx, sy, sx2, sy2){ var temp = this.getEachStrokes(buhin); var result = new Array(); + var box = this.getBox(buhin); + if(sx != 0 || sy != 0){ + if(sx > 100){ + sx -= 200; // Ǥ°ÕÅÀ¥â¡¼¥É + } else { + sx2 = 0; // Ãæ¿´ÅÀ¥â¡¼¥É + sy2 = 0; + } + } for(var i = 0; i < temp.length; i++){ + if(sx != 0 || sy != 0){ + temp[i][3] = stretch(sx, sx2, temp[i][3], box.minX, box.maxX); + temp[i][4] = stretch(sy, sy2, temp[i][4], box.minY, box.maxY); + temp[i][5] = stretch(sx, sx2, temp[i][5], box.minX, box.maxX); + temp[i][6] = stretch(sy, sy2,temp[i][6], box.minY, box.maxY); + if(temp[i][0] != 99){ + temp[i][7] = stretch(sx, sx2, temp[i][7], box.minX, box.maxX); + temp[i][8] = stretch(sy, sy2, temp[i][8], box.minY, box.maxY); + temp[i][9] = stretch(sx, sx2, temp[i][9], box.minX, box.maxX); + temp[i][10] = stretch(sy, sy2, temp[i][10], box.minY, box.maxY); + } + } result.push([temp[i][0], temp[i][1], temp[i][2], @@ -63,7 +132,42 @@ function Kage(){ } Kage.prototype.getEachStrokesOfBuhin = getEachStrokesOfBuhin; - function adjustUroko(strokesArray){ // strokesArray + function adjustHane(sa){ // strokesArray + for(var i = 0; i < sa.length; i++){ + 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 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][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] += 700 - Math.floor(mn / 15) * 100; // 0-99 -> 0-700 + } + } + } + return sa; + } + Kage.prototype.adjustHane = adjustHane; + + function adjustUroko(strokesArray){ // strokesArray for(var i = 0; i < strokesArray.length; i++){ if(strokesArray[i][0] == 1 && strokesArray[i][2] == 0){ // no operation for TATE for(var k = 0; k < this.kAdjustUrokoLengthStep; k++){ @@ -91,8 +195,77 @@ function Kage(){ return strokesArray; } Kage.prototype.adjustUroko = adjustUroko; - - function adjustKirikuchi(strokesArray){ // strokesArray + + function adjustUroko2(strokesArray){ // strokesArray + for(var i = 0; i < strokesArray.length; i++){ + if(strokesArray[i][0] == 1 && strokesArray[i][2] == 0 && strokesArray[i][4] == strokesArray[i][6]){ + var pressure = 0; + for(var j = 0; j < strokesArray.length; j++){ + if(i != j && ( + (strokesArray[j][0] == 1 && strokesArray[j][4] == strokesArray[j][6] && + !(strokesArray[i][3] + 1 > strokesArray[j][5] || strokesArray[i][5] - 1 < strokesArray[j][3]) && + Math.abs(strokesArray[i][4] - strokesArray[j][4]) < this.kAdjustUroko2Length) || + (strokesArray[j][0] == 3 && strokesArray[j][6] == strokesArray[j][8] && + !(strokesArray[i][3] + 1 > strokesArray[j][7] || strokesArray[i][5] - 1 < strokesArray[j][5]) && + Math.abs(strokesArray[i][4] - strokesArray[j][6]) < this.kAdjustUroko2Length) + )){ + pressure += Math.pow(this.kAdjustUroko2Length - Math.abs(strokesArray[i][4] - strokesArray[j][6]), 1.1); + } + } + var result = Math.min(Math.floor(pressure / this.kAdjustUroko2Length), this.kAdjustUroko2Step) * 100; + if(strokesArray[i][2] < result){ + strokesArray[i][2] = strokesArray[i][2] % 100 + Math.min(Math.floor(pressure / this.kAdjustUroko2Length), this.kAdjustUroko2Step) * 100; + } + } + } + return strokesArray; + } + Kage.prototype.adjustUroko2 = adjustUroko2; + + function adjustTate(strokesArray){ // strokesArray + for(var i = 0; i < strokesArray.length; i++){ + if((strokesArray[i][0] == 1 || strokesArray[i][0] == 3 || strokesArray[i][0] == 7) && strokesArray[i][3] == strokesArray[i][5]){ + for(var j = 0; j < strokesArray.length; j++){ + if(i != j && (strokesArray[j][0] == 1 || strokesArray[j][0] == 3 || strokesArray[j][0] == 7) && strokesArray[j][3] == strokesArray[j][5] && + !(strokesArray[i][4] + 1 > strokesArray[j][6] || strokesArray[i][6] - 1 < strokesArray[j][4]) && + Math.abs(strokesArray[i][3] - strokesArray[j][3]) < this.kMinWidthT * this.kAdjustTateStep){ + strokesArray[i][1] += (this.kAdjustTateStep - Math.floor(Math.abs(strokesArray[i][3] - strokesArray[j][3]) / this.kMinWidthT)) * 1000; + if(strokesArray[i][1] > this.kAdjustTateStep * 1000){ + strokesArray[i][1] = strokesArray[i][1] % 1000 + this.kAdjustTateStep * 1000; + } + } + } + } + } + return strokesArray; + } + Kage.prototype.adjustTate = adjustTate; + + function adjustMage(strokesArray){ // strokesArray + for(var i = 0; i < strokesArray.length; i++){ + if((strokesArray[i][0] == 3) && strokesArray[i][6] == strokesArray[i][8]){ + for(var j = 0; j < strokesArray.length; j++){ + if(i != j && ( + (strokesArray[j][0] == 1 && strokesArray[j][4] == strokesArray[j][6] && + !(strokesArray[i][5] + 1 > strokesArray[j][5] || strokesArray[i][7] - 1 < strokesArray[j][3]) && + Math.abs(strokesArray[i][6] - strokesArray[j][4]) < this.kMinWidthT * this.kAdjustMageStep) || + (strokesArray[j][0] == 3 && strokesArray[j][6] == strokesArray[j][8] && + !(strokesArray[i][5] + 1 > strokesArray[j][7] || strokesArray[i][7] - 1 < strokesArray[j][5]) && + Math.abs(strokesArray[i][6] - strokesArray[j][6]) < this.kMinWidthT * this.kAdjustMageStep) + )){ + strokesArray[i][2] += (this.kAdjustMageStep - Math.floor(Math.abs(strokesArray[i][6] - strokesArray[j][6]) / this.kMinWidthT)) * 1000; + if(strokesArray[i][2] > this.kAdjustMageStep * 1000){ + strokesArray[i][2] = strokesArray[i][2] % 1000 + this.kAdjustMageStep * 1000; + } + } + } + } + } + return strokesArray; + } + Kage.prototype.adjustMage = adjustMage; + + function adjustKirikuchi(strokesArray){ // strokesArray for(var i = 0; i < strokesArray.length; i++){ if(strokesArray[i][0] == 2 && strokesArray[i][1] == 32 && strokesArray[i][3] > strokesArray[i][5] && @@ -110,7 +283,7 @@ function Kage(){ return strokesArray; } Kage.prototype.adjustKirikuchi = adjustKirikuchi; - + function adjustKakato(strokesArray){ // strokesArray for(var i = 0; i < strokesArray.length; i++){ if(strokesArray[i][0] == 1 && @@ -121,6 +294,8 @@ function Kage(){ strokesArray[i][6] + this.kAdjustKakatoRangeY[k], strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1]) + | strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1] > 200 // adjust for baseline + | strokesArray[i][6] - strokesArray[i][4] < this.kAdjustKakatoRangeY[k + 1] // for thin box ){ strokesArray[i][2] += (3 - k) * 100; k = Infinity; @@ -132,111 +307,117 @@ function Kage(){ } Kage.prototype.adjustKakato = adjustKakato; - function drawStrokesArray(polygons, strokesArray){ - for(var i = 0; i < strokesArray.length; i++){ - dfDrawFont(this, polygons, - strokesArray[i][0], - strokesArray[i][1], - strokesArray[i][2], - strokesArray[i][3], - strokesArray[i][4], - strokesArray[i][5], - strokesArray[i][6], - strokesArray[i][7], - strokesArray[i][8], - strokesArray[i][9], - strokesArray[i][10]); - } - } - Kage.prototype.drawStrokesArray = drawStrokesArray; - - function drawGlyph(polygons, glyph){ // void - // [glyph] : [stroke]$[stroke]$..... - // [stroke] : [column]:[column]:..... - var strokes = glyph.split("$"); - for(var i = 0; i < strokes.length; i++){ - var columns = strokes[i].split(":"); - if(Math.floor(columns[0]) != 99){ - dfDrawFont(this, polygons, - Math.floor(columns[0]), - Math.floor(columns[1]), Math.floor(columns[2]), - Math.floor(columns[3]), Math.floor(columns[4]), - Math.floor(columns[5]), Math.floor(columns[6]), - Math.floor(columns[7]), Math.floor(columns[8]), - Math.floor(columns[9]), Math.floor(columns[10])); - } else { - var buhin = this.kBuhin.search(columns[7]); - if(buhin != ""){ - this.drawBuhin(polygons, buhin, - Math.floor(columns[3]), - Math.floor(columns[4]), - Math.floor(columns[5]), - Math.floor(columns[6])); - } + 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 = this.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; } + if(strokes[i][0] == 4){ 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.drawGlyph = drawGlyph; - - function drawBuhin(polygons, glyph, x1, y1, x2, y2){ // void - var strokes = glyph.split("$"); - for(var i = 0; i < strokes.length; i++){ - var columns = strokes[i].split(":"); - if(Math.floor(columns[0]) != 99){ - dfDrawFont(this, polygons, - Math.floor(columns[0]), - Math.floor(columns[1]), - Math.floor(columns[2]), - 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, - x1 + Math.floor(columns[7]) * (x2 - x1) / 200, - y1 + Math.floor(columns[8]) * (y2 - y1) / 200, - x1 + Math.floor(columns[9]) * (x2 - x1) / 200, - y1 + Math.floor(columns[10]) * (y2 - y1) / 200); + Kage.prototype.getBox = getBox; + + function stretch(dp, sp, p, min, max){ // interger + var p1, p2, p3, p4; + if(p < sp + 100){ + p1 = min; + p3 = min; + p2 = sp + 100; + p4 = dp + 100; } else { - var buhin = this.kBuhin.search(columns[7]); - if(buhin != ""){ - this.drawBuhin(polygons, buhin, - 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); - } + p1 = sp + 100; + p3 = dp + 100; + p2 = max; + p4 = max; } - } + return Math.floor(((p - p1) / (p2 - p1)) * (p4 - p3) + p3); } - Kage.prototype.drawBuhin = drawBuhin; - + Kage.prototype.stretch = stretch; + //properties Kage.prototype.kMincho = 0; Kage.prototype.kGothic = 1; this.kShotai = this.kMincho; - + this.kRate = 100; - - this.kMinWidthY = 2; - this.kMinWidthT = 6; - this.kWidth = 5; - this.kKakato = 3; - this.kL2RDfatten = 1.1; - this.kMage = 10; - this.kUseCurve = 0; - - this.kAdjustKakatoL = ([14, 9, 5, 2]); // for KAKATO adjustment 000,100,200,300 - this.kAdjustKakatoR = ([8, 6, 4, 2]); // for KAKATO adjustment 000,100,200,300 - this.kAdjustKakatoRangeX = 20; // check area width - this.kAdjustKakatoRangeY = ([1, 19, 24, 30]); // 3 steps of checking - this.kAdjustKakatoStep = 3; // number of steps - - this.kAdjustUrokoX = ([24, 20, 16, 12]); // for UROKO adjustment 000,100,200,300 - this.kAdjustUrokoY = ([12, 11, 9, 8]); // for UROKO adjustment 000,100,200,300 - this.kAdjustUrokoLength = ([22, 36, 50]); // length for checking - this.kAdjustUrokoLengthStep = 3; // number of steps - this.kAdjustUrokoLine = ([22, 26, 30]); // check for crossing. corresponds to length - + + if(size == 1){ + this.kMinWidthY = 1.2; + this.kMinWidthT = 3.6; + this.kWidth = 3; + this.kKakato = 1.8; + this.kL2RDfatten = 1.1; + this.kMage = 6; + this.kUseCurve = 0; + + this.kAdjustKakatoL = ([8, 5, 3, 1]); // for KAKATO adjustment 000,100,200,300 + this.kAdjustKakatoR = ([4, 3, 2, 1]); // for KAKATO adjustment 000,100,200,300 + this.kAdjustKakatoRangeX = 12; // check area width + this.kAdjustKakatoRangeY = ([1, 11, 14, 18]); // 3 steps of checking + this.kAdjustKakatoStep = 3; // number of steps + + this.kAdjustUrokoX = ([14, 12, 9, 7]); // for UROKO adjustment 000,100,200,300 + this.kAdjustUrokoY = ([7, 6, 5, 4]); // for UROKO adjustment 000,100,200,300 + this.kAdjustUrokoLength = ([13, 21, 30]); // length for checking + this.kAdjustUrokoLengthStep = 3; // number of steps + this.kAdjustUrokoLine = ([13, 15, 18]); // check for crossing. corresponds to length + } else { + this.kMinWidthY = 2; + this.kMinWidthT = 6; + this.kWidth = 5; + this.kKakato = 3; + this.kL2RDfatten = 1.1; + this.kMage = 10; + this.kUseCurve = 0; + + this.kAdjustKakatoL = ([14, 9, 5, 2]); // for KAKATO adjustment 000,100,200,300 + this.kAdjustKakatoR = ([8, 6, 4, 2]); // for KAKATO adjustment 000,100,200,300 + this.kAdjustKakatoRangeX = 20; // check area width + this.kAdjustKakatoRangeY = ([1, 19, 24, 30]); // 3 steps of checking + this.kAdjustKakatoStep = 3; // number of steps + + this.kAdjustUrokoX = ([24, 20, 16, 12]); // for UROKO adjustment 000,100,200,300 + this.kAdjustUrokoY = ([12, 11, 9, 8]); // for UROKO adjustment 000,100,200,300 + this.kAdjustUrokoLength = ([22, 36, 50]); // length for checking + this.kAdjustUrokoLengthStep = 3; // number of steps + this.kAdjustUrokoLine = ([22, 26, 30]); // check for crossing. corresponds to length + + this.kAdjustUroko2Step = 3; + this.kAdjustUroko2Length = 40; + + this.kAdjustTateStep = 4; + + this.kAdjustMageStep = 5; + } + this.kBuhin = new Buhin(); return this; } +