「ラクラク罫線」の版間の差分

MSY-07 (トーク | 投稿記録)
ソースコードの整形
MSY-07 (トーク | 投稿記録)
セミコロンの追加と除去
79行目: 79行目:
var notch = "";
var notch = "";
var depth = 35;
var depth = 35;
var single_spc = " "
var single_spc = " ";
var bouble_spc = " ";
var bouble_spc = " ";


93行目: 93行目:
var c = this.charCodeAt(i);
var c = this.charCodeAt(i);
return ((c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4));
return ((c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4));
}
};
// 文字列の長さ。半角換算。
// 文字列の長さ。半角換算。
String.prototype.blength = function() {
String.prototype.blength = function() {
101行目: 101行目:
}
}
return blen;
return blen;
}
};
// インデックス番号の変換(半角→通常)。
// インデックス番号の変換(半角→通常)。
String.prototype.bindex2i = function(bi) {
String.prototype.bindex2i = function(bi) {
if (bi < 0) {
if (bi < 0) {
Alert("bi < 0 in bindex2i !!");
Alert("bi < 0 in bindex2i !!");
Quit()
Quit();
}
}
var n = 0;
var n = 0;
for (var i = 0; i < this.length; i++) {
for (var i = 0; i < this.length; i++) {
if (!this.isHan(i)) {
if (!this.isHan(i)) {
n++
n++;
};
}
if (i + n >= bi) {
if (i + n >= bi) {
return i
return i;
}
}
}
}
return bi
return bi;
}
};
// 文字列から指定した位置の文字を抜き出し。半角指定。
// 文字列から指定した位置の文字を抜き出し。半角指定。
String.prototype.bcharAt = function(bi) {
String.prototype.bcharAt = function(bi) {
var i = this.bindex2i(bi);
var i = this.bindex2i(bi);
if (bi >= this.blength()) {
if (bi >= this.blength()) {
i = this.length
i = this.length;
}
}
return this.charAt(i);
return this.charAt(i);
}
};


// 文字列を分割。半角指定。
// 文字列を分割。半角指定。
134行目: 134行目:
front: this.substr(0, i),
front: this.substr(0, i),
tail: this.substr(i, this.length - i)
tail: this.substr(i, this.length - i)
}
};
}
};
// 文字列の繰り返し。
// 文字列の繰り返し。
String.prototype.repeat = function(n) {
String.prototype.repeat = function(n) {
var str = this
var str = this;
var s = "";
var s = "";
while (n > 0) {
while (n > 0) {
if (n & 1) {
if (n & 1) {
s += str
s += str;
}
}
n = n >> 1;
n = n >> 1;
148行目: 148行目:
}
}
return s;
return s;
}
};
// 文字列を指定桁数まで延長。半角指定。
// 文字列を指定桁数まで延長。半角指定。
String.prototype.beven = function(bn) {
String.prototype.beven = function(bn) {
160行目: 160行目:
var s = "";
var s = "";
if (bn == 0) {
if (bn == 0) {
s = str + this.spcS.repeat(str.blength() % 2)
s = str + this.spcS.repeat(str.blength() % 2);
} else {
} else {
bn += bn % 2;
bn += bn % 2;
168行目: 168行目:
s = s.replace(re, this.spcW);
s = s.replace(re, this.spcW);
return s;
return s;
}
};


// 最長要素の長さ。半角換算。
// 最長要素の長さ。半角換算。
176行目: 176行目:
if (typeof(this[i]) != "string") {
if (typeof(this[i]) != "string") {
Alert("maxbLen!");
Alert("maxbLen!");
Quit()
Quit();
}
}
var s = this[i].blength();
var s = this[i].blength();
182行目: 182行目:
}
}
return blen;
return blen;
}
};




188行目: 188行目:
TblRuler = function() {
TblRuler = function() {
this.initialize.apply(this, arguments);
this.initialize.apply(this, arguments);
}
};
TblRuler.prototype = {
TblRuler.prototype = {
spcS: single_spc,
spcS: single_spc,
208行目: 208行目:
},
},
length: function() {
length: function() {
return this.tbl.length
return this.tbl.length;
},
},
vline: function() {
vline: function() {
228行目: 228行目:
}
}
var lenL = l_ary.maxbLen();
var lenL = l_ary.maxbLen();
var lenR = r_ary.maxbLen()
var lenR = r_ary.maxbLen();


for (var i = 0; i < this.tbl.length; i++) {
for (var i = 0; i < this.tbl.length; i++) {
243行目: 243行目:
var rend = work.pop();
var rend = work.pop();
if (/[─│┌┐└┘├┤┬┴┼]/.test(rend)) {
if (/[─│┌┐└┘├┤┬┴┼]/.test(rend)) {
work.push(this.spcW + rend)
work.push(this.spcW + rend);
} else {
} else {
work.push(rend + this.spcW)
work.push(rend + this.spcW);
};
}
this.tbl[i] = work.join("");
this.tbl[i] = work.join("");
}
}
260行目: 260行目:
if (s.length >= 3 && regK.test(s.charAt(0)) && regK.test(s.charAt(s.length - 1)) && !reg.test(mid)) {
if (s.length >= 3 && regK.test(s.charAt(0)) && regK.test(s.charAt(s.length - 1)) && !reg.test(mid)) {
var reg2 = new RegExp(this.spcW, "ig");
var reg2 = new RegExp(this.spcW, "ig");
var c = this.tbl[this.y1].split("")
var c = this.tbl[this.y1].split("");
s = s.replace(reg2, hksen);
s = s.replace(reg2, hksen);
c.splice(tx - 1, bx - tx, s);
c.splice(tx - 1, bx - tx, s);
297行目: 297行目:
var c = this.tbl[y - 1].bcharAt(bx);
var c = this.tbl[y - 1].bcharAt(bx);
if (/[┌┐│┬├┼┤]/.test(c)) {
if (/[┌┐│┬├┼┤]/.test(c)) {
s += 8
s += 8;
}
}
}
}
304行目: 304行目:
var c = this.tbl[y + 1].bcharAt(bx);
var c = this.tbl[y + 1].bcharAt(bx);
if (/[└┘│┴├┼┤]/.test(c)) {
if (/[└┘│┴├┼┤]/.test(c)) {
s += 4
s += 4;
}
}
}
}
311行目: 311行目:
var c = this.tbl[y].charAt(this.tbl[y].bindex2i(bx) - 1);
var c = this.tbl[y].charAt(this.tbl[y].bindex2i(bx) - 1);
if (/[┌└─┬┼├┴]/.test(c)) {
if (/[┌└─┬┼├┴]/.test(c)) {
s += 2
s += 2;
}
}
}
}
318行目: 318行目:
var c = this.tbl[y].charAt(this.tbl[y].bindex2i(bx) + 1);
var c = this.tbl[y].charAt(this.tbl[y].bindex2i(bx) + 1);
if (/[┐┘─┬┼┤┴]/.test(c)) {
if (/[┐┘─┬┼┤┴]/.test(c)) {
s += 1
s += 1;
}
}
}
}
376行目: 376行目:
} else {
} else {
ex += s;
ex += s;
};
}
if (s.isHan()) {
if (s.isHan()) {
bi += 1
bi += 1;
} else {
} else {
bi += 2
bi += 2;
};
}
}
}
work[y] = ex;
work[y] = ex;
401行目: 401行目:
var s = line.bcharAt(bi);
var s = line.bcharAt(bi);
if (/[─│┌┐└┘├┤┬┴┼ ]/.test(s) && ks2.length != 0) {
if (/[─│┌┐└┘├┤┬┴┼ ]/.test(s) && ks2.length != 0) {
ex += ks2
ex += ks2;
} else {
} else {
ex += s
ex += s;
};
}
if (s.isHan()) {
if (s.isHan()) {
bi += 1
bi += 1;
} else {
} else {
bi += 2
bi += 2;
};
}
}
}
this.tbl[y] = ex;
this.tbl[y] = ex;
}
}
}
};


function ruler_action() {
function ruler_action() {
if (tx == 1 && tx == bx && by == tblTop) {
if (tx == 1 && tx == bx && by == tblTop) {
return "makeframe"
return "makeframe";
} else if (tx == 1 && tx == bx && ty == tblBottom) {
} else if (tx == 1 && tx == bx && ty == tblBottom) {
return "adjust"
return "adjust";
} else if (tx == 1 && by == ty && ax == 1) {
} else if (tx == 1 && by == ty && ax == 1) {
return "adjust_line"
return "adjust_line";
} else if (tx == document.GetLine(ty).length + 1) {
} else if (tx == document.GetLine(ty).length + 1) {
return "vline_at_end"
return "vline_at_end";
} else if (tx != bx && ty == by) {
} else if (tx != bx && ty == by) {
return "hline"
return "hline";
}
}
return "vline";
return "vline";
449行目: 449行目:
} else {
} else {
sel.EndOfLine(true, mePosLogical);
sel.EndOfLine(true, mePosLogical);
};
}


var tblTop = ty;
var tblTop = ty;
468行目: 468行目:
}
}
if (ty < tblTop) {
if (ty < tblTop) {
tblTop = ty
tblTop = ty;
};
}
if (by > tblBottom) {
if (by > tblBottom) {
tblBottom = by
tblBottom = by;
};
}
sel.SetActivePoint(mePosLogical, 1, tblTop, false)
sel.SetActivePoint(mePosLogical, 1, tblTop, false);
sel.SetActivePoint(mePosLogical, 1, tblBottom, true)
sel.SetActivePoint(mePosLogical, 1, tblBottom, true);
sel.EndOfLine(true, mePosLogical);
sel.EndOfLine(true, mePosLogical);


498行目: 498行目:
}
}


sel.SetActivePoint(mePosLogical, 1, tblTop, false)
sel.SetActivePoint(mePosLogical, 1, tblTop, false);
sel.SetActivePoint(mePosLogical, 1, tblBottom, true)
sel.SetActivePoint(mePosLogical, 1, tblBottom, true);
sel.EndOfLine(true, mePosLogical);
sel.EndOfLine(true, mePosLogical);
sel.Text = tblruler.tbl.join("\r\n");
sel.Text = tblruler.tbl.join("\r\n");
スポンサーリンク