JetBrains / skija

Java bindings for Skia
Apache License 2.0
2.63k stars 127 forks source link

TypeFace GetFamilyNames return String[]? #108

Closed AnzerWall closed 3 years ago

AnzerWall commented 3 years ago

it's not FontFamilyName[]?

extern "C" JNIEXPORT jobjectArray JNICALL Java_org_jetbrains_skija_Typeface__1nGetFamilyNames
  (JNIEnv* env, jclass jclass, jlong ptr) {
    SkTypeface* instance = reinterpret_cast<SkTypeface*>(static_cast<uintptr_t>(ptr));
    SkTypeface::LocalizedStrings* iter = instance->createFamilyNameIterator();
    std::vector<SkTypeface::LocalizedString> names;
    SkTypeface::LocalizedString name;
    while (iter->next(&name)) {
        names.push_back(name);
    }
    iter->unref();
    jobjectArray res = env->NewObjectArray((jsize) names.size(), skija::FontFamilyName::cls, nullptr);
    for (int i = 0; i < names.size(); ++i) {
        jstring nameStr = javaString(env, names[i].fString);
        jstring langStr = javaString(env, names[i].fLanguage);
        jobject obj = env->NewObject(skija::FontFamilyName::cls, skija::FontFamilyName::ctor, nameStr, langStr);
        env->SetObjectArrayElement(res, i, obj);
    }
    return res;
}
public static native Font[] _nGetFamilyNames(long ptr)

what?

    public String[] getFamilyNames() {
        try {
            Stats.onNativeCall();
            return _nGetFamilyNames(_ptr);
        } finally {
            Reference.reachabilityFence(this);
        }
    }

what?

tonsky commented 3 years ago

Probably a mistake. Do you want to provide a patch?

tonsky commented 3 years ago

Fixed in 0.91.8. Thank you for reporting!