fix: use real UTF-8 for jstring -> native conversion
CI / Build Java (push) Has been cancelled
CI / Build Native (macos-latest - macos) (push) Has been cancelled
CI / Build Native (ubuntu-latest - linux) (push) Has been cancelled
CI / Build Native (ubuntu-latest - windows) (push) Has been cancelled
CI / Archive Natives (push) Has been cancelled
CI / Update Binaries (push) Has been cancelled
CI / Release (push) Has been cancelled

JNI's GetStringUTFChars emits MUTF-8, which encodes codepoints above
U+FFFF as a surrogate-pair of two 3-byte sequences. ImGui's UTF-8 decoder
rejects those, so SMP emoji (U+1F000+) never reach the glyph atlas even
when the glyph is registered.

Add Jni::ToTrueUtf8 / Jni::FreeTrueUtf8 helpers in jni_common that decode
via GetStringChars (UTF-16) and emit proper 1/2/3/4-byte UTF-8, then
route every generator- and manually-written JNI call site through them
(1921 occurrences across the generated tree and 3 hand-written files,
plus the jni_content.kt generator template so future regenerations stay
consistent).
This commit is contained in:
MRLokop committed 2026-04-20 11:04:08 +03:00
1 parent 34c40304f6
commit d9aa2c811b
20 files changed
+3897 -3846

No files matched your search

@@ -101,33 +101,33 @@ public final class ImFontAtlas extends ImGuiStructDestroyable {
}
private native long nAddFontFromFileTTF(String obj_filename, float sizePixels); /*MANUAL
auto filename = obj_filename == NULL ? NULL : (char*)env->GetStringUTFChars(obj_filename, JNI_FALSE);
auto filename = obj_filename == NULL ? NULL : Jni::ToTrueUtf8(env, obj_filename);
auto _result = (uintptr_t)THIS->AddFontFromFileTTF(filename, sizePixels);
if (filename != NULL) env->ReleaseStringUTFChars(obj_filename, filename);
if (filename != NULL) Jni::FreeTrueUtf8(filename);
return _result;
*/
private native long nAddFontFromFileTTF(String obj_filename, float sizePixels, long fontConfig); /*MANUAL
auto filename = obj_filename == NULL ? NULL : (char*)env->GetStringUTFChars(obj_filename, JNI_FALSE);
auto filename = obj_filename == NULL ? NULL : Jni::ToTrueUtf8(env, obj_filename);
auto _result = (uintptr_t)THIS->AddFontFromFileTTF(filename, sizePixels, reinterpret_cast<ImFontConfig*>(fontConfig));
if (filename != NULL) env->ReleaseStringUTFChars(obj_filename, filename);
if (filename != NULL) Jni::FreeTrueUtf8(filename);
return _result;
*/
private native long nAddFontFromFileTTF(String obj_filename, float sizePixels, long fontConfig, short[] obj_glyphRanges); /*MANUAL
auto filename = obj_filename == NULL ? NULL : (char*)env->GetStringUTFChars(obj_filename, JNI_FALSE);
auto filename = obj_filename == NULL ? NULL : Jni::ToTrueUtf8(env, obj_filename);
auto glyphRanges = obj_glyphRanges == NULL ? NULL : (short*)env->GetPrimitiveArrayCritical(obj_glyphRanges, JNI_FALSE);
auto _result = (uintptr_t)THIS->AddFontFromFileTTF(filename, sizePixels, reinterpret_cast<ImFontConfig*>(fontConfig), (ImWchar*)&glyphRanges[0]);
if (filename != NULL) env->ReleaseStringUTFChars(obj_filename, filename);
if (filename != NULL) Jni::FreeTrueUtf8(filename);
if (glyphRanges != NULL) env->ReleasePrimitiveArrayCritical(obj_glyphRanges, glyphRanges, JNI_FALSE);
return _result;
*/
private native long nAddFontFromFileTTF(String obj_filename, float sizePixels, short[] obj_glyphRanges); /*MANUAL
auto filename = obj_filename == NULL ? NULL : (char*)env->GetStringUTFChars(obj_filename, JNI_FALSE);
auto filename = obj_filename == NULL ? NULL : Jni::ToTrueUtf8(env, obj_filename);
auto glyphRanges = obj_glyphRanges == NULL ? NULL : (short*)env->GetPrimitiveArrayCritical(obj_glyphRanges, JNI_FALSE);
auto _result = (uintptr_t)THIS->AddFontFromFileTTF(filename, sizePixels, NULL, (ImWchar*)&glyphRanges[0]);
if (filename != NULL) env->ReleaseStringUTFChars(obj_filename, filename);
if (filename != NULL) Jni::FreeTrueUtf8(filename);
if (glyphRanges != NULL) env->ReleasePrimitiveArrayCritical(obj_glyphRanges, glyphRanges, JNI_FALSE);
return _result;
*/
@@ -395,17 +395,17 @@ public final class ImFontAtlas extends ImGuiStructDestroyable {
}
private native long nAddFontFromMemoryCompressedBase85TTF(String obj_compressedFontDataBase85, float sizePixels, long fontConfig); /*MANUAL
auto compressedFontDataBase85 = obj_compressedFontDataBase85 == NULL ? NULL : (char*)env->GetStringUTFChars(obj_compressedFontDataBase85, JNI_FALSE);
auto compressedFontDataBase85 = obj_compressedFontDataBase85 == NULL ? NULL : Jni::ToTrueUtf8(env, obj_compressedFontDataBase85);
auto _result = (uintptr_t)THIS->AddFontFromMemoryCompressedBase85TTF(compressedFontDataBase85, sizePixels, reinterpret_cast<ImFontConfig*>(fontConfig));
if (compressedFontDataBase85 != NULL) env->ReleaseStringUTFChars(obj_compressedFontDataBase85, compressedFontDataBase85);
if (compressedFontDataBase85 != NULL) Jni::FreeTrueUtf8(compressedFontDataBase85);
return _result;
*/
private native long nAddFontFromMemoryCompressedBase85TTF(String obj_compressedFontDataBase85, float sizePixels, long fontConfig, short[] obj_glyphRanges); /*MANUAL
auto compressedFontDataBase85 = obj_compressedFontDataBase85 == NULL ? NULL : (char*)env->GetStringUTFChars(obj_compressedFontDataBase85, JNI_FALSE);
auto compressedFontDataBase85 = obj_compressedFontDataBase85 == NULL ? NULL : Jni::ToTrueUtf8(env, obj_compressedFontDataBase85);
auto glyphRanges = obj_glyphRanges == NULL ? NULL : (short*)env->GetPrimitiveArrayCritical(obj_glyphRanges, JNI_FALSE);
auto _result = (uintptr_t)THIS->AddFontFromMemoryCompressedBase85TTF(compressedFontDataBase85, sizePixels, reinterpret_cast<ImFontConfig*>(fontConfig), (ImWchar*)&glyphRanges[0]);
if (compressedFontDataBase85 != NULL) env->ReleaseStringUTFChars(obj_compressedFontDataBase85, compressedFontDataBase85);
if (compressedFontDataBase85 != NULL) Jni::FreeTrueUtf8(compressedFontDataBase85);
if (glyphRanges != NULL) env->ReleasePrimitiveArrayCritical(obj_glyphRanges, glyphRanges, JNI_FALSE);
return _result;
*/