From cd532587e29b4daeaaae383bfa8117500e9a3877 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Sat, 31 Oct 2020 10:13:20 +0800 Subject: [PATCH] =?UTF-8?q?emoji=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/ui.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libs/ui.js b/libs/ui.js index 442aea85..9c548c3e 100644 --- a/libs/ui.js +++ b/libs/ui.js @@ -1138,7 +1138,12 @@ ui.prototype._drawTextContent_next = function (tempCtx, content, config) { return false; } // get next character - var ch = content.charAt(config.index++); + var ch = content.charAt(config.index); + var code = content.charCodeAt(config.index++); + while (code >= 0xD800 && code <= 0xDBFF) { + ch += content.charAt(config.index); + code = content.charCodeAt(config.index++); + } return this._drawTextContent_drawChar(tempCtx, content, config, ch); } @@ -1183,7 +1188,7 @@ ui.prototype._drawTextContent_drawChar = function (tempCtx, content, config, ch) config.forceChangeLine = true; } else { this._drawTextContent_newLine(tempCtx, config); - config.index--; + config.index-=ch.length; return this._drawTextContent_next(tempCtx, content, config); } } else if (forbidEnd.indexOf(ch) >= 0 && config.index < content.length) { @@ -1196,7 +1201,7 @@ ui.prototype._drawTextContent_drawChar = function (tempCtx, content, config, ch) if (config.offsetX + charwidth + nextchwidth > config.maxWidth) { // 下一项会换行,因此在此处换行 this._drawTextContent_newLine(tempCtx, config); - config.index--; + config.index-=ch.length; return this._drawTextContent_next(tempCtx, content, config); } }