Merge pull request #15 from Live2D/feature/fix_text_decode

Fix text decode.
translate
Takuya Ito 2018-11-02 14:15:54 +09:00 committed by GitHub
commit b2b7dc3e72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 18 deletions

View File

@ -22,6 +22,7 @@ export namespace Live2DCubismFramework
const CSM_JSON_ERROR_TYPE_MISMATCH: string = "Error: type mismatch";
const CSM_JSON_ERROR_INDEX_OF_BOUNDS: string = "Error: index out of bounds";
/**
* JSON
*/
@ -307,27 +308,17 @@ export namespace Live2DCubismFramework
return this._root;
}
/**
* UnicodeString
*/
public LongArrayBufferToString(buffer: ArrayBuffer, len: number) : string
{
let tmp: string[] = [];
for (let p: number = 0; p < buffer.byteLength; p += len)
{
tmp.push(this.ArrayBufferToString(buffer.slice(p, p + len)));
}
return tmp.join("");
}
/**
* UnicodeString
*
* @param buffer
* @return
*/
public ArrayBufferToString( buffer: ArrayBuffer ): string
public arrayBufferToString(buffer: ArrayBuffer): string
{
// 8ビット変換
return String.fromCharCode.apply("", new Uint8Array(buffer));
let encodedString: string = String.fromCharCode.apply(null, new Uint8Array(buffer));
let decodedString: string = decodeURIComponent(escape(encodedString));
return decodedString;
}
/**
@ -340,7 +331,7 @@ export namespace Live2DCubismFramework
public parseBytes(buffer: ArrayBuffer, size: number): boolean
{
let endPos: number[] = new Array(1); // 参照渡しにするため配列
let decodeBuffer: string = this.LongArrayBufferToString(buffer, 1024);
let decodeBuffer: string = this.arrayBufferToString(buffer);
this._root = this.parseValue(decodeBuffer, size, 0, endPos);
if(this._error)