+++ /dev/null
-function Kage(size){\r
- // method\r
- function makeGlyph(polygons, buhin){ // void\r
- var glyphData = this.kBuhin.search(buhin);\r
- this.makeGlyph2(polygons, glyphData);\r
- }\r
- Kage.prototype.makeGlyph = makeGlyph;\r
- \r
- function makeGlyph2(polygons, data){ // void\r
- if(data != ""){\r
- var strokesArray = this.adjustKirikuchi(this.adjustUroko2(this.adjustUroko(this.adjustKakato(this.adjustTate(this.adjustMage(this.adjustHane(this.getEachStrokes(data))))))));\r
- for(var i = 0; i < strokesArray.length; i++){\r
- dfDrawFont(this, polygons,\r
- strokesArray[i][0],\r
- strokesArray[i][1],\r
- strokesArray[i][2],\r
- strokesArray[i][3],\r
- strokesArray[i][4],\r
- strokesArray[i][5],\r
- strokesArray[i][6],\r
- strokesArray[i][7],\r
- strokesArray[i][8],\r
- strokesArray[i][9],\r
- strokesArray[i][10]);\r
- }\r
- }\r
- }\r
- Kage.prototype.makeGlyph2 = makeGlyph2;\r
- \r
- function makeGlyph3(data){ // void\r
- var result = new Array();\r
- if(data != ""){\r
- var strokesArray = this.adjustKirikuchi(this.adjustUroko2(this.adjustUroko(this.adjustKakato(this.adjustTate(this.adjustMage(this.adjustHane(this.getEachStrokes(data))))))));\r
- for(var i = 0; i < strokesArray.length; i++){\r
- var polygons = new Polygons();\r
- dfDrawFont(this, polygons,\r
- strokesArray[i][0],\r
- strokesArray[i][1],\r
- strokesArray[i][2],\r
- strokesArray[i][3],\r
- strokesArray[i][4],\r
- strokesArray[i][5],\r
- strokesArray[i][6],\r
- strokesArray[i][7],\r
- strokesArray[i][8],\r
- strokesArray[i][9],\r
- strokesArray[i][10]);\r
- result.push(polygons);\r
- }\r
- }\r
- return result;\r
- }\r
- Kage.prototype.makeGlyph3 = makeGlyph3;\r
- \r
- function getEachStrokes(glyphData){ // strokes array\r
- var strokesArray = new Array();\r
- var strokes = glyphData.split("$");\r
- for(var i = 0; i < strokes.length; i++){\r
- var columns = strokes[i].split(":");\r
- if(Math.floor(columns[0]) != 99){\r
- strokesArray.push([\r
- Math.floor(columns[0]),\r
- Math.floor(columns[1]),\r
- Math.floor(columns[2]),\r
- Math.floor(columns[3]),\r
- Math.floor(columns[4]),\r
- Math.floor(columns[5]),\r
- Math.floor(columns[6]),\r
- Math.floor(columns[7]),\r
- Math.floor(columns[8]),\r
- Math.floor(columns[9]),\r
- Math.floor(columns[10])\r
- ]);\r
- } else {\r
- var buhin = this.kBuhin.search(columns[7]);\r
- if(buhin != ""){\r
- strokesArray = strokesArray.concat(this.getEachStrokesOfBuhin(buhin,\r
- Math.floor(columns[3]),\r
- Math.floor(columns[4]),\r
- Math.floor(columns[5]),\r
- Math.floor(columns[6]),\r
- Math.floor(columns[1]),\r
- Math.floor(columns[2]),\r
- Math.floor(columns[9]),\r
- Math.floor(columns[10]))\r
- );\r
- }\r
- }\r
- }\r
- return strokesArray;\r
- }\r
- Kage.prototype.getEachStrokes = getEachStrokes;\r
- \r
- function getEachStrokesOfBuhin(buhin, x1, y1, x2, y2, sx, sy, sx2, sy2){\r
- var temp = this.getEachStrokes(buhin);\r
- var result = new Array();\r
- var box = this.getBox(buhin);\r
- if(sx != 0 || sy != 0){\r
- if(sx > 100){\r
- sx -= 200;\r
- } else {\r
- sx2 = 0;\r
- sy2 = 0;\r
- }\r
- }\r
- for(var i = 0; i < temp.length; i++){\r
- if(sx != 0 || sy != 0){\r
- temp[i][3] = stretch(sx, sx2, temp[i][3], box.minX, box.maxX);\r
- temp[i][4] = stretch(sy, sy2, temp[i][4], box.minY, box.maxY);\r
- temp[i][5] = stretch(sx, sx2, temp[i][5], box.minX, box.maxX);\r
- temp[i][6] = stretch(sy, sy2,temp[i][6], box.minY, box.maxY);\r
- if(temp[i][0] != 99){\r
- temp[i][7] = stretch(sx, sx2, temp[i][7], box.minX, box.maxX); \r
- temp[i][8] = stretch(sy, sy2, temp[i][8], box.minY, box.maxY);\r
- temp[i][9] = stretch(sx, sx2, temp[i][9], box.minX, box.maxX);\r
- temp[i][10] = stretch(sy, sy2, temp[i][10], box.minY, box.maxY);\r
- }\r
- }\r
- result.push([temp[i][0],\r
- temp[i][1],\r
- temp[i][2],\r
- x1 + temp[i][3] * (x2 - x1) / 200,\r
- y1 + temp[i][4] * (y2 - y1) / 200,\r
- x1 + temp[i][5] * (x2 - x1) / 200,\r
- y1 + temp[i][6] * (y2 - y1) / 200,\r
- x1 + temp[i][7] * (x2 - x1) / 200,\r
- y1 + temp[i][8] * (y2 - y1) / 200,\r
- x1 + temp[i][9] * (x2 - x1) / 200,\r
- y1 + temp[i][10] * (y2 - y1) / 200]);\r
- }\r
- return result;\r
- }\r
- Kage.prototype.getEachStrokesOfBuhin = getEachStrokesOfBuhin;\r
- \r
- function adjustHane(sa){ // strokesArray\r
- for(var i = 0; i < sa.length; i++){\r
- if((sa[i][0] == 1 || sa[i][0] == 2 || sa[i][0] == 6) && sa[i][2] == 4){\r
- var lpx; // lastPointX\r
- var lpy; // lastPointY\r
- if(sa[i][0] == 1){\r
- lpx = sa[i][5];\r
- lpy = sa[i][6];\r
- } else if(sa[i][0] == 2){\r
- lpx = sa[i][7];\r
- lpy = sa[i][8];\r
- } else {\r
- lpx = sa[i][9];\r
- lpy = sa[i][10];\r
- }\r
- var mn = Infinity; // mostNear\r
- if(lpx + 18 < 100){\r
- mn = lpx + 18;\r
- }\r
- for(var j = 0; j < sa.length; j++){\r
- 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){\r
- if(lpx - sa[j][3] < 100){\r
- mn = Math.min(mn, lpx - sa[j][3]);\r
- }\r
- }\r
- }\r
- if(mn != Infinity){\r
- sa[i][2] += 700 - Math.floor(mn / 15) * 100; // 0-99 -> 0-700\r
- }\r
- }\r
- }\r
- return sa;\r
- }\r
- Kage.prototype.adjustHane = adjustHane;\r
-\r
- function adjustUroko(strokesArray){ // strokesArray\r
- for(var i = 0; i < strokesArray.length; i++){\r
- if(strokesArray[i][0] == 1 && strokesArray[i][2] == 0){ // no operation for TATE\r
- for(var k = 0; k < this.kAdjustUrokoLengthStep; k++){\r
- var tx, ty, tlen;\r
- if(strokesArray[i][4] == strokesArray[i][6]){ // YOKO\r
- tx = strokesArray[i][5] - this.kAdjustUrokoLine[k];\r
- ty = strokesArray[i][6] - 0.5;\r
- tlen = strokesArray[i][5] - strokesArray[i][3];\r
- } else {\r
- var rad = Math.atan((strokesArray[i][6] - strokesArray[i][4]) / (strokesArray[i][5] - strokesArray[i][3]));\r
- tx = strokesArray[i][5] - this.kAdjustUrokoLine[k] * Math.cos(rad) - 0.5 * Math.sin(rad);\r
- ty = strokesArray[i][6] - this.kAdjustUrokoLine[k] * Math.sin(rad) - 0.5 * Math.cos(rad);\r
- tlen = Math.sqrt((strokesArray[i][6] - strokesArray[i][4]) * (strokesArray[i][6] - strokesArray[i][4]) +\r
- (strokesArray[i][5] - strokesArray[i][3]) * (strokesArray[i][5] - strokesArray[i][3]));\r
- }\r
- if(tlen < this.kAdjustUrokoLength[k] ||\r
- isCrossWithOthers(strokesArray, i, tx, ty, strokesArray[i][5], strokesArray[i][6])\r
- ){\r
- strokesArray[i][2] += (this.kAdjustUrokoLengthStep - k) * 100;\r
- k = Infinity;\r
- }\r
- }\r
- }\r
- }\r
- return strokesArray;\r
- }\r
- Kage.prototype.adjustUroko = adjustUroko;\r
- \r
- function adjustUroko2(strokesArray){ // strokesArray\r
- for(var i = 0; i < strokesArray.length; i++){\r
- if(strokesArray[i][0] == 1 && strokesArray[i][2] == 0 && strokesArray[i][4] == strokesArray[i][6]){\r
- var pressure = 0;\r
- for(var j = 0; j < strokesArray.length; j++){\r
- if(i != j && (\r
- (strokesArray[j][0] == 1 && strokesArray[j][4] == strokesArray[j][6] &&\r
- !(strokesArray[i][3] + 1 > strokesArray[j][5] || strokesArray[i][5] - 1 < strokesArray[j][3]) &&\r
- Math.abs(strokesArray[i][4] - strokesArray[j][4]) < this.kAdjustUroko2Length) ||\r
- (strokesArray[j][0] == 3 && strokesArray[j][6] == strokesArray[j][8] &&\r
- !(strokesArray[i][3] + 1 > strokesArray[j][7] || strokesArray[i][5] - 1 < strokesArray[j][5]) &&\r
- Math.abs(strokesArray[i][4] - strokesArray[j][6]) < this.kAdjustUroko2Length)\r
- )){\r
- pressure += Math.pow(this.kAdjustUroko2Length - Math.abs(strokesArray[i][4] - strokesArray[j][6]), 1.1);\r
- }\r
- }\r
- var result = Math.min(Math.floor(pressure / this.kAdjustUroko2Length), this.kAdjustUroko2Step) * 100;\r
- if(strokesArray[i][2] < result){\r
- strokesArray[i][2] = strokesArray[i][2] % 100 + Math.min(Math.floor(pressure / this.kAdjustUroko2Length), this.kAdjustUroko2Step) * 100;\r
- }\r
- }\r
- }\r
- return strokesArray;\r
- }\r
- Kage.prototype.adjustUroko2 = adjustUroko2;\r
- \r
- function adjustTate(strokesArray){ // strokesArray\r
- for(var i = 0; i < strokesArray.length; i++){\r
- if((strokesArray[i][0] == 1 || strokesArray[i][0] == 3 || strokesArray[i][0] == 7) && strokesArray[i][3] == strokesArray[i][5]){\r
- for(var j = 0; j < strokesArray.length; j++){\r
- if(i != j && (strokesArray[j][0] == 1 || strokesArray[j][0] == 3 || strokesArray[j][0] == 7) && strokesArray[j][3] == strokesArray[j][5] &&\r
- !(strokesArray[i][4] + 1 > strokesArray[j][6] || strokesArray[i][6] - 1 < strokesArray[j][4]) &&\r
- Math.abs(strokesArray[i][3] - strokesArray[j][3]) < this.kMinWidthT * this.kAdjustTateStep){\r
- strokesArray[i][1] += (this.kAdjustTateStep - Math.floor(Math.abs(strokesArray[i][3] - strokesArray[j][3]) / this.kMinWidthT)) * 1000;\r
- if(strokesArray[i][1] > this.kAdjustTateStep * 1000){\r
- strokesArray[i][1] = strokesArray[i][1] % 1000 + this.kAdjustTateStep * 1000;\r
- }\r
- }\r
- }\r
- }\r
- }\r
- return strokesArray;\r
- }\r
- Kage.prototype.adjustTate = adjustTate;\r
- \r
- function adjustMage(strokesArray){ // strokesArray\r
- for(var i = 0; i < strokesArray.length; i++){\r
- if((strokesArray[i][0] == 3) && strokesArray[i][6] == strokesArray[i][8]){\r
- for(var j = 0; j < strokesArray.length; j++){\r
- if(i != j && (\r
- (strokesArray[j][0] == 1 && strokesArray[j][4] == strokesArray[j][6] &&\r
- !(strokesArray[i][5] + 1 > strokesArray[j][5] || strokesArray[i][7] - 1 < strokesArray[j][3]) &&\r
- Math.abs(strokesArray[i][6] - strokesArray[j][4]) < this.kMinWidthT * this.kAdjustMageStep) ||\r
- (strokesArray[j][0] == 3 && strokesArray[j][6] == strokesArray[j][8] &&\r
- !(strokesArray[i][5] + 1 > strokesArray[j][7] || strokesArray[i][7] - 1 < strokesArray[j][5]) &&\r
- Math.abs(strokesArray[i][6] - strokesArray[j][6]) < this.kMinWidthT * this.kAdjustMageStep)\r
- )){\r
- strokesArray[i][2] += (this.kAdjustMageStep - Math.floor(Math.abs(strokesArray[i][6] - strokesArray[j][6]) / this.kMinWidthT)) * 1000;\r
- if(strokesArray[i][2] > this.kAdjustMageStep * 1000){\r
- strokesArray[i][2] = strokesArray[i][2] % 1000 + this.kAdjustMageStep * 1000;\r
- }\r
- }\r
- }\r
- }\r
- }\r
- return strokesArray;\r
- }\r
- Kage.prototype.adjustMage = adjustMage;\r
- \r
- function adjustKirikuchi(strokesArray){ // strokesArray\r
- for(var i = 0; i < strokesArray.length; i++){\r
- if(strokesArray[i][0] == 2 && strokesArray[i][1] == 32 &&\r
- strokesArray[i][3] > strokesArray[i][5] &&\r
- strokesArray[i][4] < strokesArray[i][6]){\r
- for(var j = 0; j < strokesArray.length; j++){ // no need to skip when i == j\r
- if(strokesArray[j][0] == 1 &&\r
- strokesArray[j][3] < strokesArray[i][3] && strokesArray[j][5] > strokesArray[i][3] &&\r
- strokesArray[j][4] == strokesArray[i][4] && strokesArray[j][4] == strokesArray[j][6]){\r
- strokesArray[i][1] = 132;\r
- j = strokesArray.length;\r
- }\r
- }\r
- }\r
- }\r
- return strokesArray;\r
- }\r
- Kage.prototype.adjustKirikuchi = adjustKirikuchi;\r
- \r
- function adjustKakato(strokesArray){ // strokesArray\r
- for(var i = 0; i < strokesArray.length; i++){\r
- if(strokesArray[i][0] == 1 &&\r
- (strokesArray[i][2] == 13 || strokesArray[i][2] == 23)){\r
- for(var k = 0; k < this.kAdjustKakatoStep; k++){\r
- if(isCrossBoxWithOthers(strokesArray, i,\r
- strokesArray[i][5] - this.kAdjustKakatoRangeX / 2,\r
- strokesArray[i][6] + this.kAdjustKakatoRangeY[k],\r
- strokesArray[i][5] + this.kAdjustKakatoRangeX / 2,\r
- strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1])\r
- | strokesArray[i][6] + this.kAdjustKakatoRangeY[k + 1] > 200 // adjust for baseline\r
- | strokesArray[i][6] - strokesArray[i][4] < this.kAdjustKakatoRangeY[k + 1] // for thin box\r
- ){\r
- strokesArray[i][2] += (3 - k) * 100;\r
- k = Infinity;\r
- }\r
- }\r
- }\r
- }\r
- return strokesArray;\r
- }\r
- Kage.prototype.adjustKakato = adjustKakato;\r
- \r
- function getBox(glyph){ // minX, minY, maxX, maxY\r
- var a = new Object();\r
- a.minX = 200;\r
- a.minY = 200;\r
- a.maxX = 0;\r
- a.maxY = 0;\r
- \r
- var strokes = this.getEachStrokes(glyph);\r
- for(var i = 0; i < strokes.length; i++){\r
- if(strokes[i][0] == 0){ continue; }\r
- a.minX = Math.min(a.minX, strokes[i][3]);\r
- a.maxX = Math.max(a.maxX, strokes[i][3]);\r
- a.minY = Math.min(a.minY, strokes[i][4]);\r
- a.maxY = Math.max(a.maxY, strokes[i][4]);\r
- a.minX = Math.min(a.minX, strokes[i][5]);\r
- a.maxX = Math.max(a.maxX, strokes[i][5]);\r
- a.minY = Math.min(a.minY, strokes[i][6]);\r
- a.maxY = Math.max(a.maxY, strokes[i][6]);\r
- if(strokes[i][0] == 1){ continue; }\r
- if(strokes[i][0] == 99){ continue; }\r
- a.minX = Math.min(a.minX, strokes[i][7]);\r
- a.maxX = Math.max(a.maxX, strokes[i][7]);\r
- a.minY = Math.min(a.minY, strokes[i][8]);\r
- a.maxY = Math.max(a.maxY, strokes[i][8]);\r
- if(strokes[i][0] == 2){ continue; }\r
- if(strokes[i][0] == 3){ continue; }\r
- if(strokes[i][0] == 4){ continue; }\r
- a.minX = Math.min(a.minX, strokes[i][9]);\r
- a.maxX = Math.max(a.maxX, strokes[i][9]);\r
- a.minY = Math.min(a.minY, strokes[i][10]);\r
- a.maxY = Math.max(a.maxY, strokes[i][10]);\r
- }\r
- return a;\r
- }\r
- Kage.prototype.getBox = getBox;\r
-\r
- function stretch(dp, sp, p, min, max){ // interger\r
- var p1, p2, p3, p4;\r
- if(p < sp + 100){\r
- p1 = min;\r
- p3 = min;\r
- p2 = sp + 100;\r
- p4 = dp + 100;\r
- } else {\r
- p1 = sp + 100;\r
- p3 = dp + 100;\r
- p2 = max;\r
- p4 = max;\r
- }\r
- return Math.floor(((p - p1) / (p2 - p1)) * (p4 - p3) + p3);\r
- }\r
- Kage.prototype.stretch = stretch;\r
-\r
- //properties\r
- Kage.prototype.kMincho = 0;\r
- Kage.prototype.kGothic = 1;\r
- this.kShotai = this.kMincho;\r
- \r
- this.kRate = 100;\r
- \r
- if(size == 1){\r
- this.kMinWidthY = 1.2;\r
- this.kMinWidthT = 3.6;\r
- this.kWidth = 3;\r
- this.kKakato = 1.8;\r
- this.kL2RDfatten = 1.1;\r
- this.kMage = 6;\r
- this.kUseCurve = 0;\r
- \r
- this.kAdjustKakatoL = ([8, 5, 3, 1, 0]); // for KAKATO adjustment 000,100,200,300,400\r
- this.kAdjustKakatoR = ([4, 3, 2, 1]); // for KAKATO adjustment 000,100,200,300\r
- this.kAdjustKakatoRangeX = 12; // check area width\r
- this.kAdjustKakatoRangeY = ([1, 11, 14, 18]); // 3 steps of checking\r
- this.kAdjustKakatoStep = 3; // number of steps\r
- \r
- this.kAdjustUrokoX = ([14, 12, 9, 7]); // for UROKO adjustment 000,100,200,300\r
- this.kAdjustUrokoY = ([7, 6, 5, 4]); // for UROKO adjustment 000,100,200,300\r
- this.kAdjustUrokoLength = ([13, 21, 30]); // length for checking\r
- this.kAdjustUrokoLengthStep = 3; // number of steps\r
- this.kAdjustUrokoLine = ([13, 15, 18]); // check for crossing. corresponds to length\r
- } else {\r
- this.kMinWidthY = 2;\r
- this.kMinWidthT = 6;\r
- this.kWidth = 5;\r
- this.kKakato = 3;\r
- this.kL2RDfatten = 1.1;\r
- this.kMage = 10;\r
- this.kUseCurve = 0;\r
- \r
- this.kAdjustKakatoL = ([14, 9, 5, 2, 0]); // for KAKATO adjustment 000,100,200,300,400\r
- this.kAdjustKakatoR = ([8, 6, 4, 2]); // for KAKATO adjustment 000,100,200,300\r
- this.kAdjustKakatoRangeX = 20; // check area width\r
- this.kAdjustKakatoRangeY = ([1, 19, 24, 30]); // 3 steps of checking\r
- this.kAdjustKakatoStep = 3; // number of steps\r
- \r
- this.kAdjustUrokoX = ([24, 20, 16, 12]); // for UROKO adjustment 000,100,200,300\r
- this.kAdjustUrokoY = ([12, 11, 9, 8]); // for UROKO adjustment 000,100,200,300\r
- this.kAdjustUrokoLength = ([22, 36, 50]); // length for checking\r
- this.kAdjustUrokoLengthStep = 3; // number of steps\r
- this.kAdjustUrokoLine = ([22, 26, 30]); // check for crossing. corresponds to length\r
- \r
- this.kAdjustUroko2Step = 3;\r
- this.kAdjustUroko2Length = 40;\r
- \r
- this.kAdjustTateStep = 4;\r
- \r
- this.kAdjustMageStep = 5;\r
- }\r
- \r
- this.kBuhin = new Buhin();\r
- \r
- return this;\r
-}\r
-\r