mirror of https://github.com/axmolengine/axmol.git
there is a bug for getStringUTFChars function. it can't translate the emotion utf8 code. so change the getStringUTFChars to getStringChars. and translate unicode to utf8 in c++ program
This commit is contained in:
parent
f9b6d6b670
commit
979700e343
|
@ -35,6 +35,8 @@
|
|||
#include "platform/CCFileUtils.h"
|
||||
#include "platform/android/jni/JniHelper.h"
|
||||
|
||||
#include "base/ccUTF8.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
namespace network {
|
||||
|
@ -582,13 +584,16 @@ private:
|
|||
|
||||
const char* str = nullptr;
|
||||
char* ret = nullptr;
|
||||
str = env->GetStringUTFChars(jstr, nullptr);
|
||||
if (nullptr != str)
|
||||
const unsigned short * unicodeChar = (const unsigned short *)env->GetStringChars(jstr, nullptr);
|
||||
std::u16string unicodeStr((char16_t *)unicodeChar);
|
||||
std::string strValue;
|
||||
cocos2d::StringUtils::UTF16ToUTF8(unicodeStr, strValue);
|
||||
if (strValue.length() > 0)
|
||||
{
|
||||
ret = strdup(str);
|
||||
ret = strdup(strValue.c_str());
|
||||
}
|
||||
|
||||
env->ReleaseStringUTFChars(jstr, str);
|
||||
env->ReleaseStringChars(jstr, unicodeChar);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ THE SOFTWARE.
|
|||
#include "../CCApplication.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include <jni.h>
|
||||
#include "base/ccUTF8.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
|
@ -59,10 +60,11 @@ std::string getStringWithEllipsisJni(const char* text, float width, float fontSi
|
|||
}
|
||||
|
||||
jstring retFromJava = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID, stringArg1, width, fontSize);
|
||||
const char* str = t.env->GetStringUTFChars(retFromJava, 0);
|
||||
ret = str;
|
||||
const unsigned short * str = (const unsigned short *)t.env->GetStringChars(retFromJava, nullptr);
|
||||
std::u16string unicodeStr((char16_t *)str);
|
||||
cocos2d::StringUtils::UTF16ToUTF8(unicodeStr, ret);
|
||||
|
||||
t.env->ReleaseStringUTFChars(retFromJava, str);
|
||||
t.env->ReleaseStringChars(retFromJava, str);
|
||||
t.env->DeleteLocalRef(stringArg1);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include "JniHelper.h"
|
||||
#include <jni.h>
|
||||
|
||||
#include "base/ccUTF8.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
extern "C" {
|
||||
|
@ -33,9 +35,13 @@ extern "C" {
|
|||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInsertText(JNIEnv* env, jobject thiz, jstring text) {
|
||||
const char* pszText = env->GetStringUTFChars(text, NULL);
|
||||
const unsigned short * unicodeChar = (const unsigned short *)env->GetStringChars(text, nullptr);
|
||||
std::u16string unicodeStr((char16_t *)unicodeChar);
|
||||
std::string strValue;
|
||||
cocos2d::StringUtils::UTF16ToUTF8(unicodeStr, strValue);
|
||||
const char* pszText = strValue.c_str();
|
||||
cocos2d::IMEDispatcher::sharedDispatcher()->dispatchInsertText(pszText, strlen(pszText));
|
||||
env->ReleaseStringUTFChars(text, pszText);
|
||||
env->ReleaseStringChars(text, unicodeChar);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeDeleteBackward(JNIEnv* env, jobject thiz) {
|
||||
|
|
|
@ -27,6 +27,8 @@ THE SOFTWARE.
|
|||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "base/ccUTF8.h"
|
||||
|
||||
#define LOG_TAG "JniHelper"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
|
||||
|
@ -268,9 +270,11 @@ namespace cocos2d {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
const char* chars = env->GetStringUTFChars(jstr, nullptr);
|
||||
std::string ret(chars);
|
||||
env->ReleaseStringUTFChars(jstr, chars);
|
||||
const unsigned short * unicodeChar = (const unsigned short *)env->GetStringChars(jstr, nullptr);
|
||||
std::u16string unicodeStr((char16_t *)unicodeChar);
|
||||
std::string ret;
|
||||
cocos2d::StringUtils::UTF16ToUTF8(unicodeStr, ret);
|
||||
env->ReleaseStringChars(jstr, unicodeChar);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "spidermonkey_specifics.h"
|
||||
#include "ScriptingCore.h"
|
||||
#include "js_manual_conversions.h"
|
||||
#include "base/ccUTF8.h"
|
||||
|
||||
#define LOG_TAG "CCJavascriptJavaBridge"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
@ -38,9 +39,13 @@ extern "C" {
|
|||
JNIEXPORT jint JNICALL Java_org_cocos2dx_lib_Cocos2dxJavascriptJavaBridge_evalString
|
||||
(JNIEnv *env, jclass cls, jstring value)
|
||||
{
|
||||
const char *_value = env->GetStringUTFChars(value, NULL);
|
||||
ScriptingCore::getInstance()->evalString(_value,NULL);
|
||||
env->ReleaseStringUTFChars(value, _value);
|
||||
|
||||
const unsigned short * unicodeChar = (const unsigned short *)env->GetStringChars(value, nullptr);
|
||||
std::u16string unicodeStr((char16_t *)unicodeChar);
|
||||
std::string strValue;
|
||||
cocos2d::StringUtils::UTF16ToUTF8(unicodeStr, strValue);
|
||||
ScriptingCore::getInstance()->evalString(strValue.c_str(), nullptr);
|
||||
env->ReleaseStringChars(value, unicodeChar);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -79,9 +84,13 @@ bool JavascriptJavaBridge::CallInfo::execute(void)
|
|||
|
||||
case TypeString:
|
||||
m_retjstring = (jstring)m_env->CallStaticObjectMethod(m_classID, m_methodID);
|
||||
const char *stringBuff = m_env->GetStringUTFChars(m_retjstring, 0);
|
||||
m_ret.stringValue = new string(stringBuff);
|
||||
m_env->ReleaseStringUTFChars(m_retjstring, stringBuff);
|
||||
const unsigned short * unicodeChar = (const unsigned short *)m_env->GetStringChars(m_retjstring, nullptr);
|
||||
std::u16string unicodeStr((char16_t *)unicodeChar);
|
||||
std::string strValue;
|
||||
cocos2d::StringUtils::UTF16ToUTF8(unicodeStr, strValue);
|
||||
|
||||
m_ret.stringValue = new string(strValue);
|
||||
m_env->ReleaseStringChars(m_retjstring, unicodeChar);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -119,9 +128,12 @@ bool JavascriptJavaBridge::CallInfo::executeWithArgs(jvalue *args)
|
|||
|
||||
case TypeString:
|
||||
m_retjstring = (jstring)m_env->CallStaticObjectMethodA(m_classID, m_methodID, args);
|
||||
const char *stringBuff = m_env->GetStringUTFChars(m_retjstring, 0);
|
||||
m_ret.stringValue = new string(stringBuff);
|
||||
m_env->ReleaseStringUTFChars(m_retjstring, stringBuff);
|
||||
const unsigned short * unicodeChar = (const unsigned short *)m_env->GetStringChars(m_retjstring, nullptr);
|
||||
std::u16string unicodeStr((char16_t *)unicodeChar);
|
||||
std::string strValue;
|
||||
cocos2d::StringUtils::UTF16ToUTF8(unicodeStr, strValue);
|
||||
m_ret.stringValue = new string(strValue);
|
||||
m_env->ReleaseStringChars(m_retjstring, unicodeChar);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -429,4 +441,4 @@ void JavascriptJavaBridge::_js_register(JSContext *cx, JS::HandleObject global)
|
|||
|
||||
JavascriptJavaBridge::js_parent = NULL;
|
||||
JavascriptJavaBridge::js_proto = JS_InitClass(cx, global, JS::NullPtr(), &JavascriptJavaBridge::js_class , JavascriptJavaBridge::_js_constructor, 0, props, funcs, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "CCLuaJavaBridge.h"
|
||||
#include "platform/android/jni/JniHelper.h"
|
||||
#include <android/log.h>
|
||||
#include "base/ccUTF8.h"
|
||||
|
||||
#define LOG_TAG "luajc"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
@ -40,9 +41,12 @@ bool LuaJavaBridge::CallInfo::execute(void)
|
|||
|
||||
case TypeString:
|
||||
m_retjs = (jstring)m_env->CallStaticObjectMethod(m_classID, m_methodID);
|
||||
const char *stringBuff = m_env->GetStringUTFChars(m_retjs, 0);
|
||||
m_ret.stringValue = new string(stringBuff);
|
||||
m_env->ReleaseStringUTFChars(m_retjs, stringBuff);
|
||||
const unsigned short * stringBuff = (const unsigned short *)m_env->GetStringChars(m_retjs, nullptr);
|
||||
std::u16string unicodeStr((char16_t *)stringBuff);
|
||||
std::string strValue;
|
||||
cocos2d::StringUtils::UTF16ToUTF8(unicodeStr, strValue);
|
||||
m_ret.stringValue = new string(strValue);
|
||||
m_env->ReleaseStringChars(m_retjs, stringBuff);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -80,9 +84,12 @@ bool LuaJavaBridge::CallInfo::executeWithArgs(jvalue *args)
|
|||
|
||||
case TypeString:
|
||||
m_retjs = (jstring)m_env->CallStaticObjectMethodA(m_classID, m_methodID, args);
|
||||
const char *stringBuff = m_env->GetStringUTFChars(m_retjs, 0);
|
||||
m_ret.stringValue = new string(stringBuff);
|
||||
m_env->ReleaseStringUTFChars(m_retjs, stringBuff);
|
||||
const unsigned short * unicodeChar = (const unsigned short *)m_env->GetStringChars(m_retjs, nullptr);
|
||||
std::u16string unicodeStr((char16_t *)unicodeChar);
|
||||
std::string strValue;
|
||||
cocos2d::StringUtils::UTF16ToUTF8(unicodeStr, strValue);
|
||||
m_ret.stringValue = new string(strValue);
|
||||
m_env->ReleaseStringChars(m_retjs, unicodeChar);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include "CCLuaJavaBridge.h"
|
||||
|
||||
#include "base/ccUTF8.h"
|
||||
|
||||
#define LOG_TAG "Cocos2dxLuaJavaBridge_java"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
||||
|
@ -13,9 +15,12 @@ extern "C" {
|
|||
JNIEXPORT jint JNICALL Java_org_cocos2dx_lib_Cocos2dxLuaJavaBridge_callLuaFunctionWithString
|
||||
(JNIEnv *env, jclass cls, jint functionId, jstring value)
|
||||
{
|
||||
const char *value_ = env->GetStringUTFChars(value, 0);
|
||||
int ret = LuaJavaBridge::callLuaFunctionById(functionId, value_);
|
||||
env->ReleaseStringUTFChars(value, value_);
|
||||
const unsigned short * unicodeChar = (const unsigned short *)env->GetStringChars(value, nullptr);
|
||||
std::u16string unicodeStr((char16_t *)unicodeChar);
|
||||
std::string strValue;
|
||||
cocos2d::StringUtils::UTF16ToUTF8(unicodeStr, strValue);
|
||||
int ret = LuaJavaBridge::callLuaFunctionById(functionId, strValue.c_str());
|
||||
env->ReleaseStringChars(value, unicodeChar);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue