次のようなコードがあります。
// highlight text
vi.prototype.parse = function (text) {
// some code
this.data = data;
};
// place it on canvas
vi.prototype.render = function () {
/* loop */
this.ctx.clearRect(/* ... */);
this.ctx.fillStyle = this.data[i].bg;
this.ctx.fillRect(/* ... */);
this.ctx.fillText(data[i].text, /* ... */);
// ....
/* end loop */
};
テキストが変更されるたびに、テキストを解析してレンダリングします。線がキャンバスに入らないという事実により、すべてが複雑になります。
1 Some line
2 Some long line line line line line line line li
ne line line
3 Some line
背景色と前景色を含むテキストを解析して保存する最良の方法は何ですか?
構文を強調表示してテキストを印刷する必要があります。テキストを解析して何らかの形式で返す関数があります。たとえば、
text = "var x;";
highlightedText = vi.parse (text);
console.log (highlightedText);
>> [[ {text: "var", fg: "#dd5", bg: "#000"},
{text: " ", fg: "#FFF", bg: "#000"},
{text: "x", fg: "#5dd", bg: "#000"},
{text: ";", fg: "#FFF", bg: "#000"}]];
// Displays the text in canvas
vi.render (highlightedText);
テキストデータの保存方法としては良くないと思います