From 78187127dc8ae233e9347147952aea4e673f1ab4 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Fri, 5 Jul 2024 14:30:21 +0200 Subject: [PATCH] Update core to 4.1.0 (#356) --- app/conanfile.txt | 2 +- app/src/main/cpp/CoreWrapper.cpp | 51 +++++++++++-------- .../cpp/{CoreWrapper.h => CoreWrapper.hpp} | 2 +- 3 files changed, 31 insertions(+), 24 deletions(-) rename app/src/main/cpp/{CoreWrapper.h => CoreWrapper.hpp} (94%) diff --git a/app/conanfile.txt b/app/conanfile.txt index 226aa0345182..00acb71881db 100644 --- a/app/conanfile.txt +++ b/app/conanfile.txt @@ -1,5 +1,5 @@ [requires] -odrcore/3.0.0@ +odrcore/4.1.0@ [generators] CMakeToolchain diff --git a/app/src/main/cpp/CoreWrapper.cpp b/app/src/main/cpp/CoreWrapper.cpp index 9a5aba3d3b70..c29a388df510 100644 --- a/app/src/main/cpp/CoreWrapper.cpp +++ b/app/src/main/cpp/CoreWrapper.cpp @@ -1,4 +1,4 @@ -#include "CoreWrapper.h" +#include "CoreWrapper.hpp" #include #include @@ -14,8 +14,8 @@ std::optional html; JNIEXPORT jobject JNICALL -Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject instance, jobject options) -{ +Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject instance, + jobject options) { jboolean isCopy; jclass resultClass = env->FindClass("at/tomtasche/reader/background/CoreWrapper$CoreResult"); @@ -45,7 +45,8 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject jfieldID editableField = env->GetFieldID(optionsClass, "editable", "Z"); jboolean editable = env->GetBooleanField(options, editableField); - jfieldID outputPathField = env->GetFieldID(optionsClass, "outputPath", "Ljava/lang/String;"); + jfieldID outputPathField = env->GetFieldID(optionsClass, "outputPath", + "Ljava/lang/String;"); auto outputPath = (jstring) env->GetObjectField(options, outputPathField); const auto outputPathC = env->GetStringUTFChars(outputPath, &isCopy); @@ -80,7 +81,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject } fileType = types.back(); - } catch (odr::UnsupportedFileType& e) { + } catch (odr::UnsupportedFileType &e) { fileType = e.file_type; } @@ -98,7 +99,10 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject const auto fileCategory = odr::OpenDocumentReader::category_by_type(file.file_type()); if (!ooxml && - (file.file_type() == odr::FileType::office_open_xml_document || file.file_type() == odr::FileType::office_open_xml_workbook || file.file_type() == odr::FileType::office_open_xml_presentation || file.file_type() == odr::FileType::office_open_xml_encrypted)) { + (file.file_type() == odr::FileType::office_open_xml_document || + file.file_type() == odr::FileType::office_open_xml_workbook || + file.file_type() == odr::FileType::office_open_xml_presentation || + file.file_type() == odr::FileType::office_open_xml_encrypted)) { env->SetIntField(result, errorField, -5); return result; } @@ -115,12 +119,12 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject config.text_document_margin = true; } - const char* passwordC = nullptr; - if (passwordCpp.has_value()) { - passwordC = passwordCpp.value().c_str(); - } - - html = odr::OpenDocumentReader::html(inputPathCpp, passwordC, outputPathCpp, config); + html = odr::OpenDocumentReader::html(inputPathCpp, [&passwordCpp]() -> const char * { + if (passwordCpp.has_value()) { + return passwordCpp.value().c_str(); + } + return nullptr; + }, outputPathCpp, config); { const auto extensionCpp = odr::OpenDocumentReader::type_to_string( @@ -133,20 +137,20 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject env->SetObjectField(result, extensionField, extension); } - for (auto &&page : html->pages()) { + for (auto &&page: html->pages()) { jstring pageName = env->NewStringUTF(page.name.c_str()); env->CallBooleanMethod(pageNames, addMethod, pageName); jstring pagePath = env->NewStringUTF(page.path.c_str()); env->CallBooleanMethod(pagePaths, addMethod, pagePath); } - } catch (odr::UnknownFileType&) { + } catch (odr::UnknownFileType &) { env->SetIntField(result, errorField, -5); return result; - } catch (odr::WrongPassword&) { + } catch (odr::WrongPassword &) { env->SetIntField(result, errorField, -2); return result; - } catch (odr::UnsupportedFileType&) { + } catch (odr::UnsupportedFileType &) { env->SetIntField(result, errorField, -5); return result; } catch (...) { @@ -163,8 +167,9 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject } JNIEXPORT jobject JNICALL -Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, jobject instance, jobject options, jstring htmlDiff) -{ +Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, jobject instance, + jobject options, + jstring htmlDiff) { jboolean isCopy; jclass optionsClass = env->GetObjectClass(options); @@ -176,11 +181,13 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, jfieldID errorField = env->GetFieldID(resultClass, "errorCode", "I"); try { - jfieldID outputPathPrefixField = env->GetFieldID(optionsClass, "outputPath", "Ljava/lang/String;"); + jfieldID outputPathPrefixField = env->GetFieldID(optionsClass, "outputPath", + "Ljava/lang/String;"); jstring outputPathPrefix = (jstring) env->GetObjectField(options, outputPathPrefixField); const auto outputPathPrefixC = env->GetStringUTFChars(outputPathPrefix, &isCopy); - auto outputPathPrefixCpp = std::string(outputPathPrefixC, env->GetStringUTFLength(outputPathPrefix)); + auto outputPathPrefixCpp = std::string(outputPathPrefixC, + env->GetStringUTFLength(outputPathPrefix)); env->ReleaseStringUTFChars(outputPathPrefix, outputPathPrefixC); const auto htmlDiffC = env->GetStringUTFChars(htmlDiff, &isCopy); @@ -220,7 +227,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, } JNIEXPORT void JNICALL -Java_at_tomtasche_reader_background_CoreWrapper_closeNative(JNIEnv *env, jobject instance, jobject options) -{ +Java_at_tomtasche_reader_background_CoreWrapper_closeNative(JNIEnv *env, jobject instance, + jobject options) { html.reset(); } \ No newline at end of file diff --git a/app/src/main/cpp/CoreWrapper.h b/app/src/main/cpp/CoreWrapper.hpp similarity index 94% rename from app/src/main/cpp/CoreWrapper.h rename to app/src/main/cpp/CoreWrapper.hpp index c1c901655612..8451ded32683 100644 --- a/app/src/main/cpp/CoreWrapper.h +++ b/app/src/main/cpp/CoreWrapper.hpp @@ -15,4 +15,4 @@ extern "C" { Java_at_tomtasche_reader_background_CoreWrapper_closeNative(JNIEnv *env, jobject instance, jobject options); } -#endif //ANDROID_CORE_WRAPPER_H \ No newline at end of file +#endif //ANDROID_CORE_WRAPPER_H