static void initTOC(JNIEnv *env, jobject javaModel, const ContentsTree &tree) { const std::vector<shared_ptr<ContentsTree> > &children = tree.children(); for (std::vector<shared_ptr<ContentsTree> >::const_iterator it = children.begin(); it != children.end(); ++it) { const ContentsTree &child = **it; JString text(env, child.text()); AndroidUtil::Method_BookModel_addTOCItem->call(javaModel, text.j(), child.reference()); initTOC(env, javaModel, child); AndroidUtil::Method_BookModel_leaveTOCItem->call(javaModel); } }
static void initTOC(JNIEnv *env, jobject javaModel, const ContentsTree &tree) { const std::vector<shared_ptr<ContentsTree> > &children = tree.children(); for (std::vector<shared_ptr<ContentsTree> >::const_iterator it = children.begin(); it != children.end(); ++it) { const ContentsTree &child = **it; jstring text = AndroidUtil::createJavaString(env, child.text()); const int ref = child.reference(); AndroidUtil::Method_NativeBookModel_addTOCItem->call(javaModel, text, ref); env->DeleteLocalRef(text); initTOC(env, javaModel, child); AndroidUtil::Method_NativeBookModel_leaveTOCItem->call(javaModel); } }
JNIEXPORT jboolean JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readModelNative(JNIEnv* env, jobject thiz, jobject javaModel) { shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz); if (plugin.isNull()) { return JNI_FALSE; } jobject javaBook = AndroidUtil::Field_NativeBookModel_Book->value(javaModel); shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook); shared_ptr<BookModel> model = new BookModel(book, javaModel); if (!plugin->readModel(*model)) { return JNI_FALSE; } if (!model->flush()) { AndroidUtil::throwCachedCharStorageException("Cannot write file from native code"); return JNI_FALSE; } if (!initInternalHyperlinks(env, javaModel, *model)) { return JNI_FALSE; } initTOC(env, javaModel, *model->contentsTree()); shared_ptr<ZLTextModel> textModel = model->bookTextModel(); jobject javaTextModel = createTextModel(env, javaModel, *textModel); if (javaTextModel == 0) { return JNI_FALSE; } AndroidUtil::Method_NativeBookModel_setBookTextModel->call(javaModel, javaTextModel); if (env->ExceptionCheck()) { return JNI_FALSE; } env->DeleteLocalRef(javaTextModel); const std::map<std::string,shared_ptr<ZLTextModel> > &footnotes = model->footnotes(); std::map<std::string,shared_ptr<ZLTextModel> >::const_iterator it = footnotes.begin(); for (; it != footnotes.end(); ++it) { jobject javaFootnoteModel = createTextModel(env, javaModel, *it->second); if (javaFootnoteModel == 0) { return JNI_FALSE; } AndroidUtil::Method_NativeBookModel_setFootnoteModel->call(javaModel, javaFootnoteModel); if (env->ExceptionCheck()) { return JNI_FALSE; } env->DeleteLocalRef(javaFootnoteModel); } return JNI_TRUE; }
int main(int argc, char *argv[]) { glutInit(&argc, argv); options(argc, argv); if (mapmode) { /* read map data */ readDigitalMap(MAPDIR "nara.map"); readMeshData(MAPDIR "nara.mem"); calcAllAltitude(); } mapwindow = openMapWindow(argv[0]); /* initialize 3D map window */ /* 970904 イベントハンドラの設定 */ glutDisplayFunc(drawScene); glutKeyboardFunc(mapKeyFunc); glutSpecialFunc(mapSpecialFunc); /* 特殊キー用 */ glutMouseFunc(mapMouseFunc); glutMotionFunc(mapMotionFunc); readdata(); /* read guide data */ initGuide(); /* initialize the guide */ initIndex(); /* initialize the index */ initTOC(); /* initialize the TOC */ /* prepare graphics objects */ setPartNVec(&compass); setPartNVec(&pencursor); /* texture */ /* 970904 あとで参考にするかもしれない if (!wiremode && !mapmode && texturemode) { tevdef(1, 0, tevprops[0]); tevbind(TV_ENV0, 1); if ((tid = readTexture(texturename, texturemode - 1)) == 0) { perror("cannot read texture data\n"); exit(0); } texbind(TX_TEXTURE_0, tid); } */ calcLookAtPoint(lookAt, FALSE); glutSetWindow(mapwindow); glutPostRedisplay(); /* main loop */ glutMainLoop(); }
JNIEXPORT jint JNICALL Java_org_geometerplus_fbreader_formats_NativeFormatPlugin_readModelNative(JNIEnv* env, jobject thiz, jobject javaModel, jstring javaCacheDir) { shared_ptr<FormatPlugin> plugin = findCppPlugin(thiz); if (plugin.isNull()) { return 1; } const std::string cacheDir = AndroidUtil::fromJavaString(env, javaCacheDir); jobject javaBook = AndroidUtil::Field_BookModel_Book->value(javaModel); shared_ptr<Book> book = Book::loadFromJavaBook(env, javaBook); shared_ptr<BookModel> model = new BookModel(book, javaModel, cacheDir); if (!plugin->readModel(*model)) { return 2; } if (!model->flush()) { return 3; } if (!initInternalHyperlinks(env, javaModel, *model, cacheDir)) { return 4; } initTOC(env, javaModel, *model->contentsTree()); shared_ptr<ZLTextModel> textModel = model->bookTextModel(); jobject javaTextModel = createTextModel(env, javaModel, *textModel); if (javaTextModel == 0) { return 5; } AndroidUtil::Method_BookModel_setBookTextModel->call(javaModel, javaTextModel); if (env->ExceptionCheck()) { return 6; } env->DeleteLocalRef(javaTextModel); const std::map<std::string,shared_ptr<ZLTextModel> > &footnotes = model->footnotes(); std::map<std::string,shared_ptr<ZLTextModel> >::const_iterator it = footnotes.begin(); for (; it != footnotes.end(); ++it) { jobject javaFootnoteModel = createTextModel(env, javaModel, *it->second); if (javaFootnoteModel == 0) { return 7; } AndroidUtil::Method_BookModel_setFootnoteModel->call(javaModel, javaFootnoteModel); if (env->ExceptionCheck()) { return 8; } env->DeleteLocalRef(javaFootnoteModel); } const std::vector<std::vector<std::string> > familyLists = model->fontManager().familyLists(); for (std::vector<std::vector<std::string> >::const_iterator it = familyLists.begin(); it != familyLists.end(); ++it) { const std::vector<std::string> &lst = *it; jobjectArray jList = env->NewObjectArray(lst.size(), AndroidUtil::Class_java_lang_String.j(), 0); for (std::size_t i = 0; i < lst.size(); ++i) { JString jString(env, lst[i]); env->SetObjectArrayElement(jList, i, jString.j()); } AndroidUtil::Method_BookModel_registerFontFamilyList->call(javaModel, jList); env->DeleteLocalRef(jList); } const std::map<std::string,shared_ptr<FontEntry> > entries = model->fontManager().entries(); for (std::map<std::string,shared_ptr<FontEntry> >::const_iterator it = entries.begin(); it != entries.end(); ++it) { if (it->second.isNull()) { continue; } JString family(env, it->first); jobject normal = createJavaFileInfo(env, it->second->Normal); jobject bold = createJavaFileInfo(env, it->second->Bold); jobject italic = createJavaFileInfo(env, it->second->Italic); jobject boldItalic = createJavaFileInfo(env, it->second->BoldItalic); AndroidUtil::Method_BookModel_registerFontEntry->call( javaModel, family.j(), normal, bold, italic, boldItalic ); if (boldItalic != 0) env->DeleteLocalRef(boldItalic); if (italic != 0) env->DeleteLocalRef(italic); if (bold != 0) env->DeleteLocalRef(bold); if (normal != 0) env->DeleteLocalRef(normal); } return 0; }