jobject AndroidUtil::createJavaImage(JNIEnv *env, const ZLFileImage &image) {
	jstring javaMimeType = createJavaString(env, image.mimeType());
	jobject javaFile = createJavaFile(env, image.file().path());
	jstring javaEncoding = createJavaString(env, image.encoding());

	std::vector<jint> offsets, sizes;
	const ZLFileImage::Blocks &blocks = image.blocks();
	for (std::size_t i = 0; i < blocks.size(); ++i) {
		offsets.push_back((jint)blocks.at(i).offset);
		sizes.push_back((jint)blocks.at(i).size);
	}
	jintArray javaOffsets = createJavaIntArray(env, offsets);
	jintArray javaSizes = createJavaIntArray(env, sizes);

	jobject javaImage = Constructor_ZLFileImage->call(
		javaMimeType, javaFile, javaEncoding,
		javaOffsets, javaSizes
	);

	env->DeleteLocalRef(javaEncoding);
	env->DeleteLocalRef(javaFile);
	env->DeleteLocalRef(javaMimeType);
	env->DeleteLocalRef(javaOffsets);
	env->DeleteLocalRef(javaSizes);

	return javaImage;
}
Esempio n. 2
0
jobject AndroidUtil::createJavaEncryptionInfo(JNIEnv *env, shared_ptr<FileEncryptionInfo> info) {
	if (info.isNull()) {
		return 0;
	}

	jstring uri = createJavaString(env, info->Uri);
	jstring method = createJavaString(env, info->Method);
	jstring algorithm = createJavaString(env, info->Algorithm);
	jstring contentId = createJavaString(env, info->ContentId);

	jobject javaInfo = Constructor_FileEncryptionInfo->call(uri, method, algorithm, contentId);

	env->DeleteLocalRef(contentId);
	env->DeleteLocalRef(algorithm);
	env->DeleteLocalRef(method);
	env->DeleteLocalRef(uri);

	return javaInfo;
}
/*
 * Class:     com_sun_javafx_font_MacFontFinder
 * Method:    getFont
 * Signature: (I)Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_com_sun_javafx_font_MacFontFinder_getFont
  (JNIEnv *env, jclass obj, jint type)
{
    CTFontRef font = CTFontCreateUIFontForLanguage(type, 0, NULL);
    CFStringRef family = CTFontCopyFamilyName(font);
    jstring jfamily = createJavaString(env, family);
    CFRelease(family);
    CFRelease(font);
    return jfamily;
}
CFIndex addCTFontDescriptor(CTFontDescriptorRef fd, JNIEnv *env, jobjectArray result, CFIndex index)
{
    if (fd) {
        CFStringRef name = CTFontDescriptorCopyAttribute(fd, kCTFontDisplayNameAttribute);
        CFStringRef family = CTFontDescriptorCopyAttribute(fd, kCTFontFamilyNameAttribute);
        CFURLRef url = CTFontDescriptorCopyAttribute(fd, kCTFontURLAttribute);
        CFStringRef file = url ? CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle) : NULL;
        if (name && family && file) {
            jstring jname = createJavaString(env, name);
            jstring jfamily = createJavaString(env, family);
            jstring jfile = createJavaString(env, file);
            (*env)->SetObjectArrayElement(env, result, index++, jname);
            (*env)->SetObjectArrayElement(env, result, index++, jfamily);
            (*env)->SetObjectArrayElement(env, result, index++, jfile);
        }
        if (name) CFRelease(name);
        if (family) CFRelease(family);
        if (url) CFRelease(url);
        if (file) CFRelease(file);
    }
    return index;
}
jobject AndroidUtil::createJavaFile(JNIEnv *env, const std::string &path) {
	jstring javaPath = createJavaString(env, path);
	jobject javaFile = StaticMethod_ZLFile_createFileByPath->call(javaPath);
	env->DeleteLocalRef(javaPath);
	return javaFile;
}
Esempio n. 6
0
jstring AndroidUtil::createJavaString(JNIEnv* env, shared_ptr<std::string> str) {
	return str.isNull() ? 0 : createJavaString(env, *str);
}