From 46aa5707825dc0735dc97ecf33f0cc36bac90c2d Mon Sep 17 00:00:00 2001 From: Koichi KAMICHI Date: Mon, 25 Aug 2008 12:03:30 +0000 Subject: [PATCH] Added adjust KAKATO function. --- engine/kage.js | 399 +++++++++++++++++++++++++++++++++++++++++----------- engine/kagecd.js | 77 +++++++--- engine/kagedf.js | 4 +- engine/polygons.js | 184 ++++++++++++------------ engine/test.js | 1 + 5 files changed, 465 insertions(+), 200 deletions(-) diff --git a/engine/kage.js b/engine/kage.js index 16f2856..b2d9710 100755 --- a/engine/kage.js +++ b/engine/kage.js @@ -1,85 +1,314 @@ -function Kage(){ - // method - function makeGlyph(polygons, target){ // void - var buhin = this.kBuhin.search(target); - if(buhin != ""){ - this.drawGlyph(polygons, buhin); - } - } - Kage.prototype.makeGlyph = makeGlyph; - - 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])); - } - } - } - } - 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); - } 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); - } - } - } - } - Kage.prototype.drawBuhin = drawBuhin; - - //properties - Kage.prototype.kMincho = 0; - Kage.prototype.kGothic = 1; - this.kShotai = this.kMincho; - this.kMage = 10; - this.kRate = 100; - this.kMinWidthY = 2; - this.kMinWidthT = 6; - this.kWidth = 5; - this.kKakato = 3; - //has KAKATO = 2, no KAKATO = 1 - this.kL2RDfatten = 1.1; - this.kBuhin = new Buhin(); - - return this; -} +function Kage(){ + // method + function makeGlyph(polygons, buhin){ // void + var glyphData = this.kBuhin.search(buhin); + if(glyphData != ""){ + this.drawStrokesArray(polygons, this.adjustKakato(this.getEachStrokes(glyphData))); + } + } + Kage.prototype.makeGlyph = makeGlyph; + + function getEachStrokes(glyphData){ // strokes array + var strokesArray = new Array(); + var strokes = glyphData.split("$"); + for(var i = 0; i < strokes.length; i++){ + var columns = strokes[i].split(":"); + if(Math.floor(columns[0]) != 99){ + strokesArray.push([ + 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 != ""){ + strokesArray = strokesArray.concat(this.getEachStrokesOfBuhin(buhin, + Math.floor(columns[3]), + Math.floor(columns[4]), + Math.floor(columns[5]), + Math.floor(columns[6])) + ); + } + } + } + return strokesArray; + } + Kage.prototype.getEachStrokes = getEachStrokes; + + function getEachStrokesOfBuhin(buhin, x1, y1, x2, y2){ + var temp = this.getEachStrokes(buhin); + var result = new Array(); + for(var i = 0; i < temp.length; i++){ + result.push([temp[i][0], + temp[i][1], + temp[i][2], + x1 + temp[i][3] * (x2 - x1) / 200, + y1 + temp[i][4] * (y2 - y1) / 200, + x1 + temp[i][5] * (x2 - x1) / 200, + y1 + temp[i][6] * (y2 - y1) / 200, + x1 + temp[i][7] * (x2 - x1) / 200, + y1 + temp[i][8] * (y2 - y1) / 200, + x1 + temp[i][9] * (x2 - x1) / 200, + y1 + temp[i][10] * (y2 - y1) / 200]); + } + return result; + } + Kage.prototype.getEachStrokesOfBuhin = getEachStrokesOfBuhin; + + function adjustKakato(strokesArray){ // strokesArray + for(var i = 0; i < strokesArray.length; i++){ + if(strokesArray[i][0] == 1 && + (strokesArray[i][2] == 13 || strokesArray[i][2] == 23)){ + for(var k = 0; k < this.kAdjustKakatoStep; k++){ + var crossing = 0; + for(var j = 0; j < strokesArray.length && !crossing; j++){ + if(i == j){ continue; } + switch(strokesArray[j][0]){ + case 0: + case 8: + case 9: + break; + case 6: + case 7: + if(!crossing && isCross(strokesArray[j][7], + strokesArray[j][8], + strokesArray[j][9], + strokesArray[j][10], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k])){ + crossing++; + } + if(!crossing && isCross(strokesArray[j][7], + strokesArray[j][8], + strokesArray[j][9], + strokesArray[j][10], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1])){ + crossing++; + } + if(!crossing && isCross(strokesArray[j][7], + strokesArray[j][8], + strokesArray[j][9], + strokesArray[j][10], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1])){ + crossing++; + } + if(!crossing && isCross(strokesArray[j][7], + strokesArray[j][8], + strokesArray[j][9], + strokesArray[j][10], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1])){ + crossing++; + } + case 2: + case 12: + case 3: + if(!crossing && isCross(strokesArray[j][5], + strokesArray[j][6], + strokesArray[j][7], + strokesArray[j][8], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k])){ + crossing++; + } + if(!crossing && isCross(strokesArray[j][5], + strokesArray[j][6], + strokesArray[j][7], + strokesArray[j][8], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1])){ + crossing++; + } + if(!crossing && isCross(strokesArray[j][5], + strokesArray[j][6], + strokesArray[j][7], + strokesArray[j][8], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1])){ + crossing++; + } + if(!crossing && isCross(strokesArray[j][5], + strokesArray[j][6], + strokesArray[j][7], + strokesArray[j][8], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1])){ + crossing++; + } + default: + if(!crossing && isCross(strokesArray[j][3], + strokesArray[j][4], + strokesArray[j][5], + strokesArray[j][6], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k])){ + crossing++; + } + if(!crossing && isCross(strokesArray[j][3], + strokesArray[j][4], + strokesArray[j][5], + strokesArray[j][6], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1])){ + crossing++; + } + if(!crossing && isCross(strokesArray[j][3], + strokesArray[j][4], + strokesArray[j][5], + strokesArray[j][6], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1])){ + crossing++; + } + if(!crossing && isCross(strokesArray[j][3], + strokesArray[j][4], + strokesArray[j][5], + strokesArray[j][6], + strokesArray[i][5] - this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1], + strokesArray[i][5] + this.kAdjustKakatoRangeX / 2, + strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1])){ + crossing++; + } + } + } + if(crossing){ + strokesArray[i][2] += (3 - k) * 100; + k = Infinity; + } + } + } + } + return strokesArray; + } + 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])); + } + } + } + } + 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); + } 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); + } + } + } + } + Kage.prototype.drawBuhin = drawBuhin; + + //properties + Kage.prototype.kMincho = 0; + Kage.prototype.kGothic = 1; + this.kShotai = this.kMincho; + this.kMage = 10; + this.kRate = 100; + this.kMinWidthY = 2; + this.kMinWidthT = 6; + this.kWidth = 5; + this.kAdjustKakatoL = ([14, 9, 5, 2]); // 調整済みカカト用 + this.kAdjustKakatoR = ([8, 6, 4, 2]); // 調整済みカカト用 + this.kAdjustKakatoRangeX = 20; // 影響判定矩形の大きさ + this.kAdjustKakatoRangeY = ([1, 19, 24, 30]); // 影響判定矩形の大きさ + this.kAdjustKakatoStep = 3; // 影響判定矩形の段階 + this.kKakato = 3; + this.kL2RDfatten = 1.1; + this.kBuhin = new Buhin(); + + return this; +} diff --git a/engine/kagecd.js b/engine/kagecd.js index d98915b..aec3dca 100755 --- a/engine/kagecd.js +++ b/engine/kagecd.js @@ -9,6 +9,7 @@ function cdDrawBezier(kage, polygons, x1, y1, x2, y2, x3, y3, x4, y4, a1, a2){ var deltad; var XX, XY, YX, YY; var poly, poly2; + var hosomi; if(kage.kShotai == kage.kMincho){ // mincho switch(a1){ @@ -76,6 +77,11 @@ function cdDrawBezier(kage, polygons, x1, y1, x2, y2, x3, y3, x4, y4, a1, a2){ y4 = y4 + delta * Math.sin(rad) * v; } + hosomi = 0.5; + if(Math.sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1)) < 50){ + hosomi += 0.4 * (1 - Math.sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1)) / 50); + } + poly = new Polygon(); poly2 = new Polygon(); for(tt = 0; tt <= 1000; tt = tt + kage.kRate){ @@ -103,9 +109,20 @@ function cdDrawBezier(kage, polygons, x1, y1, x2, y2, x3, y3, x4, y4, a1, a2){ ib = kage.kMinWidthT; } - if(a1 == 7){ deltad = Math.sqrt(t); } - else if(a2 == 7){ deltad = Math.sqrt(1.0 - t); } + if(a1 == 7 && a2 == 0){ // L2RD: fatten + deltad = Math.pow(t, hosomi) * kage.kL2RDfatten; + } + else if(a1 == 7){ + deltad = Math.pow(t, hosomi); + } + else if(a2 == 7){ + deltad = Math.pow(1.0 - t, hosomi); + } else{ deltad = 1; } + + if(deltad < 0.15){ + deltad = 0.15; + } ia = ia * deltad; ib = ib * deltad; @@ -472,6 +489,7 @@ function cdDrawCurve(kage, polygons, x1, y1, x2, y2, x3, y3, a1, a2){ var deltad; var XX, XY, YX, YY; var poly, poly2; + var hosomi; if(kage.kShotai == kage.kMincho){ // mincho switch(a1){ @@ -540,6 +558,11 @@ function cdDrawCurve(kage, polygons, x1, y1, x2, y2, x3, y3, a1, a2){ x3 = x3 + delta * Math.cos(rad) * v; y3 = y3 + delta * Math.sin(rad) * v; } + + hosomi = 0.5; + if(Math.sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1)) < 50){ + hosomi += 0.4 * (1 - Math.sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1)) / 50); + } poly = new Polygon(); poly2 = new Polygon(); @@ -570,10 +593,20 @@ function cdDrawCurve(kage, polygons, x1, y1, x2, y2, x3, y3, a1, a2){ ib = kage.kMinWidthT; } - if(a1 == 7 && a2 == 0){ deltad = Math.sqrt(t) * kage.kL2RDfatten; } //L2RD: fatten - else if(a1 == 7){ deltad = Math.sqrt(t); } - else if(a2 == 7){ deltad = Math.sqrt(1.0 - t); } + if(a1 == 7 && a2 == 0){ // L2RD: fatten + deltad = Math.pow(t, hosomi) * kage.kL2RDfatten; + } + else if(a1 == 7){ + deltad = Math.pow(t, hosomi); + } + else if(a2 == 7){ + deltad = Math.pow(1.0 - t, hosomi); + } else{ deltad = 1; } + + if(deltad < 0.15){ + deltad = 0.15; + } ia = ia * deltad; ib = ib * deltad; @@ -937,7 +970,7 @@ function cdDrawCurve(kage, polygons, x1, y1, x2, y2, x3, y3, a1, a2){ function cdDrawLine(kage, polygons, tx1, ty1, tx2, ty2, ta1, ta2){ var rad; var v, x1, y1, x2, y2; - var a1, a2; + var a1, a2, opt1, opt2; var XX, XY, YX, YY; var poly; @@ -946,8 +979,10 @@ function cdDrawLine(kage, polygons, tx1, ty1, tx2, ty2, ta1, ta2){ y1 = ty1; x2 = tx2; y2 = ty2; - a1 = ta1; - a2 = ta2; + a1 = ta1 % 100; + a2 = ta2 % 100; + opt1 = Math.floor(ta1 / 100); + opt2 = Math.floor(ta2 / 100); if(x1 == x2){ //if TATE stroke, use y-axis poly = new Polygon(4); @@ -988,12 +1023,12 @@ function cdDrawLine(kage, polygons, tx1, ty1, tx2, ty2, ta1, ta2){ poly.set(1, x2 + kage.kMinWidthT, y2); break; case 13: - poly.set(2, x2 - kage.kMinWidthT, y2 + kage.kWidth * kage.kKakato + kage.kMinWidthT); - poly.set(1, x2 + kage.kMinWidthT, y2 + kage.kWidth * kage.kKakato); + poly.set(2, x2 - kage.kMinWidthT, y2 + kage.kAdjustKakatoL[opt2] + kage.kMinWidthT); + poly.set(1, x2 + kage.kMinWidthT, y2 + kage.kAdjustKakatoL[opt2]); break; case 23: - poly.set(2, x2 - kage.kMinWidthT, y2 + kage.kWidth * kage.kKakato * 0.5 + kage.kMinWidthT); - poly.set(1, x2 + kage.kMinWidthT, y2 + kage.kWidth * kage.kKakato * 0.5); + poly.set(2, x2 - kage.kMinWidthT, y2 + kage.kAdjustKakatoR[opt2] + kage.kMinWidthT); + poly.set(1, x2 + kage.kMinWidthT, y2 + kage.kAdjustKakatoR[opt2]); break; case 32: poly.set(2, x2 - kage.kMinWidthT, y2 + kage.kMinWidthY); @@ -1028,7 +1063,7 @@ function cdDrawLine(kage, polygons, tx1, ty1, tx2, ty2, ta1, ta2){ poly.push(x2, y2 + kage.kMinWidthT); poly.push(x2 + kage.kMinWidthT * 0.6, y2 + kage.kMinWidthT * 0.6); poly.push(x2 + kage.kMinWidthT, y2); - poly.reverse(); // for fill-rule + poly.reverse(); // for fill-rule polygons.push(poly); } } @@ -1188,17 +1223,17 @@ function cdDrawLine(kage, polygons, tx1, ty1, tx2, ty2, ta1, ta2){ poly.set(2, x2 - Math.sin(rad) * kage.kMinWidthT * v, y2 + Math.cos(rad) * kage.kMinWidthT * v); break; case 13: - poly.set(1, x2 + Math.sin(rad) * kage.kMinWidthT * v + kage.kWidth * kage.kKakato * Math.cos(rad) * v, - y2 - Math.cos(rad) * kage.kMinWidthT * v + kage.kWidth * kage.kKakato * Math.sin(rad) * v); - poly.set(2, x2 - Math.sin(rad) * kage.kMinWidthT * v + (kage.kWidth * kage.kKakato + kage.kMinWidthT) * Math.cos(rad) * v, - y2 + Math.cos(rad) * kage.kMinWidthT * v + (kage.kWidth * kage.kKakato + kage.kMinWidthT) * Math.sin(rad) * v); + poly.set(1, x2 + Math.sin(rad) * kage.kMinWidthT * v + kage.kAdjustKakatoL[opt2] * Math.cos(rad) * v, + y2 - Math.cos(rad) * kage.kMinWidthT * v + kage.kAdjustKakatoL[opt2] * Math.sin(rad) * v); + poly.set(2, x2 - Math.sin(rad) * kage.kMinWidthT * v + (kage.kAdjustKakatoL[opt2] + kage.kMinWidthT) * Math.cos(rad) * v, + y2 + Math.cos(rad) * kage.kMinWidthT * v + (kage.kAdjustKakatoL[opt2] + kage.kMinWidthT) * Math.sin(rad) * v); break; case 23: - poly.set(1, x2 + Math.sin(rad) * kage.kMinWidthT * v + kage.kWidth * kage.kKakato * 0.5 * Math.cos(rad) * v, - y2 - Math.cos(rad) * kage.kMinWidthT * v + kage.kWidth * kage.kKakato * 0.5 * Math.sin(rad) * v); + poly.set(1, x2 + Math.sin(rad) * kage.kMinWidthT * v + kage.kAdjustKakatoR[opt2] * Math.cos(rad) * v, + y2 - Math.cos(rad) * kage.kMinWidthT * v + kage.kAdjustKakatoR[opt2] * Math.sin(rad) * v); poly.set(2, - x2 - Math.sin(rad) * kage.kMinWidthT * v + (kage.kWidth * kage.kKakato * 0.5 + kage.kMinWidthT) * Math.cos(rad) * v, - y2 + Math.cos(rad) * kage.kMinWidthT * v + (kage.kWidth * kage.kKakato * 0.5 + kage.kMinWidthT) * Math.sin(rad) * v); + x2 - Math.sin(rad) * kage.kMinWidthT * v + (kage.kAdjustKakatoR[opt2] + kage.kMinWidthT) * Math.cos(rad) * v, + y2 + Math.cos(rad) * kage.kMinWidthT * v + (kage.kAdjustKakatoR[opt2] + kage.kMinWidthT) * Math.sin(rad) * v); break; case 32: poly.set(1, x2 + Math.sin(rad) * kage.kMinWidthT * v + kage.kMinWidthY * Math.cos(rad) * v, diff --git a/engine/kagedf.js b/engine/kagedf.js index 934b85c..2ec6052 100755 --- a/engine/kagedf.js +++ b/engine/kagedf.js @@ -1,7 +1,7 @@ function dfDrawFont(kage, polygons, a1, a2, a3, x1, y1, x2, y2, x3, y3, x4, y4){ var tx1, tx2, tx3, tx4, ty1, ty2, ty3, ty4, v; var rad; - + if(kage.kShotai == kage.kMincho){ switch(a1 % 100){ // ... no need to divide case 0: @@ -144,7 +144,7 @@ function dfDrawFont(kage, polygons, a1, a2, a3, x1, y1, x2, y2, x3, y3, x4, y4){ cdDrawLine(kage, polygons, x3, y3, x4, y4, 6, a3); break; case 13: -rate = 6; + rate = 6; if(a3 == 5){ if(x1 == x2){ if(y1 < y2){ v = 1; } else{ v = -1; } diff --git a/engine/polygons.js b/engine/polygons.js index dd3582a..5e3c8b8 100755 --- a/engine/polygons.js +++ b/engine/polygons.js @@ -1,95 +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; - 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; - } - 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; + // 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++; + } } - Polygons.prototype.generateEPS = generateEPS; - - // property - this.array = new Array(); - - return this; + 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; + } + 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; } diff --git a/engine/test.js b/engine/test.js index a0c1372..fa9a5f7 100644 --- a/engine/test.js +++ b/engine/test.js @@ -8,6 +8,7 @@ load("buhin.js"); load("kage.js"); load("kagecd.js"); load("kagedf.js"); +load("2d.js"); kage = new Kage(); polygons = new Polygons(); -- 1.7.10.4