diff --git a/midp/gfx.js b/midp/gfx.js index 01f6abc6..2d444338 100644 --- a/midp/gfx.js +++ b/midp/gfx.js @@ -437,10 +437,9 @@ var currentlyFocusedTextEditor; return fontContext.measureText(String.fromCharCode(char)).width | 0; }; - Native["javax/microedition/lcdui/Font.charsWidth.([CII)I"] = function(addr, strAddr, offset, len) { - var str = J2ME.getArrayFromAddr(strAddr); + Native["javax/microedition/lcdui/Font.charsWidth.([CII)I"] = function(addr, charsAddr, offset, len) { var fontContext = NativeMap.get(addr); - return calcStringWidth(fontContext, util.fromJavaChars(str).slice(offset, offset + len)); + return calcStringWidth(fontContext, J2ME.fromJavaChars(charsAddr).slice(offset, offset + len)); }; Native["javax/microedition/lcdui/Font.substringWidth.(Ljava/lang/String;II)I"] = function(addr, strAddr, offset, len) { @@ -1029,8 +1028,7 @@ var currentlyFocusedTextEditor; Native["javax/microedition/lcdui/Graphics.drawChars.([CIIIII)V"] = function(addr, dataAddr, offset, len, x, y, anchor) { - var data = J2ME.getArrayFromAddr(dataAddr); - drawString(NativeMap.get(addr), util.fromJavaChars(data, offset, len), x, y, anchor); + drawString(NativeMap.get(addr), J2ME.fromJavaChars(dataAddr, offset, len), x, y, anchor); }; Native["javax/microedition/lcdui/Graphics.drawChar.(CIII)V"] = function(addr, jChr, x, y, anchor) { diff --git a/tools/lib.d.ts b/tools/lib.d.ts index 2cf1fe1a..1e297073 100644 --- a/tools/lib.d.ts +++ b/tools/lib.d.ts @@ -12196,6 +12196,14 @@ declare var TextEncoder: { new (encoding: string): TextEncoder; } +interface TextDecoder { + decode(data: Uint8Array): string; +} +declare var TextDecoder: { + prototype: TextDecoder; + new (encoding: string): TextDecoder; +} + interface HTMLObjectElement { /** * Gets or sets the path to the preferred media source. This enables the Play To target device to stream the media content, which can be DRM protected, from a different location, such as a cloud media server. diff --git a/util.js b/util.js index 752dbc51..0b8033ca 100644 --- a/util.js +++ b/util.js @@ -47,19 +47,6 @@ var util = (function () { return Long.fromNumber(d); } - var jStringDecoder = new TextDecoder('utf-16'); - - function fromJavaChars(chars, offset, count) { - if (!chars) { - return null; - } - if (typeof count !== 'number') - count = chars.length; - if (typeof offset !== 'number') - offset = 0; - return jStringDecoder.decode(chars.subarray(offset, offset + count)); - } - var id = (function() { var gen = 0; return function() { @@ -151,7 +138,6 @@ var util = (function () { decodeUtf8Array: decodeUtf8Array, double2int: double2int, double2long: double2long, - fromJavaChars: fromJavaChars, id: id, compareTypedArrays: compareTypedArrays, pad: pad,