Skip to content

Commit 7818712

Browse files
authored
Update core to 4.1.0 (#356)
1 parent 2119bc9 commit 7818712

3 files changed

Lines changed: 31 additions & 24 deletions

File tree

app/conanfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[requires]
2-
odrcore/3.0.0@
2+
odrcore/4.1.0@
33

44
[generators]
55
CMakeToolchain

app/src/main/cpp/CoreWrapper.cpp

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "CoreWrapper.h"
1+
#include "CoreWrapper.hpp"
22

33
#include <odr/document.hpp>
44
#include <odr/file.hpp>
@@ -14,8 +14,8 @@
1414
std::optional<odr::Html> html;
1515

1616
JNIEXPORT jobject JNICALL
17-
Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject instance, jobject options)
18-
{
17+
Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject instance,
18+
jobject options) {
1919
jboolean isCopy;
2020

2121
jclass resultClass = env->FindClass("at/tomtasche/reader/background/CoreWrapper$CoreResult");
@@ -45,7 +45,8 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject
4545
jfieldID editableField = env->GetFieldID(optionsClass, "editable", "Z");
4646
jboolean editable = env->GetBooleanField(options, editableField);
4747

48-
jfieldID outputPathField = env->GetFieldID(optionsClass, "outputPath", "Ljava/lang/String;");
48+
jfieldID outputPathField = env->GetFieldID(optionsClass, "outputPath",
49+
"Ljava/lang/String;");
4950
auto outputPath = (jstring) env->GetObjectField(options, outputPathField);
5051

5152
const auto outputPathC = env->GetStringUTFChars(outputPath, &isCopy);
@@ -80,7 +81,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject
8081
}
8182

8283
fileType = types.back();
83-
} catch (odr::UnsupportedFileType& e) {
84+
} catch (odr::UnsupportedFileType &e) {
8485
fileType = e.file_type;
8586
}
8687

@@ -98,7 +99,10 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject
9899
const auto fileCategory = odr::OpenDocumentReader::category_by_type(file.file_type());
99100

100101
if (!ooxml &&
101-
(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)) {
102+
(file.file_type() == odr::FileType::office_open_xml_document ||
103+
file.file_type() == odr::FileType::office_open_xml_workbook ||
104+
file.file_type() == odr::FileType::office_open_xml_presentation ||
105+
file.file_type() == odr::FileType::office_open_xml_encrypted)) {
102106
env->SetIntField(result, errorField, -5);
103107
return result;
104108
}
@@ -115,12 +119,12 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject
115119
config.text_document_margin = true;
116120
}
117121

118-
const char* passwordC = nullptr;
119-
if (passwordCpp.has_value()) {
120-
passwordC = passwordCpp.value().c_str();
121-
}
122-
123-
html = odr::OpenDocumentReader::html(inputPathCpp, passwordC, outputPathCpp, config);
122+
html = odr::OpenDocumentReader::html(inputPathCpp, [&passwordCpp]() -> const char * {
123+
if (passwordCpp.has_value()) {
124+
return passwordCpp.value().c_str();
125+
}
126+
return nullptr;
127+
}, outputPathCpp, config);
124128

125129
{
126130
const auto extensionCpp = odr::OpenDocumentReader::type_to_string(
@@ -133,20 +137,20 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject
133137
env->SetObjectField(result, extensionField, extension);
134138
}
135139

136-
for (auto &&page : html->pages()) {
140+
for (auto &&page: html->pages()) {
137141
jstring pageName = env->NewStringUTF(page.name.c_str());
138142
env->CallBooleanMethod(pageNames, addMethod, pageName);
139143

140144
jstring pagePath = env->NewStringUTF(page.path.c_str());
141145
env->CallBooleanMethod(pagePaths, addMethod, pagePath);
142146
}
143-
} catch (odr::UnknownFileType&) {
147+
} catch (odr::UnknownFileType &) {
144148
env->SetIntField(result, errorField, -5);
145149
return result;
146-
} catch (odr::WrongPassword&) {
150+
} catch (odr::WrongPassword &) {
147151
env->SetIntField(result, errorField, -2);
148152
return result;
149-
} catch (odr::UnsupportedFileType&) {
153+
} catch (odr::UnsupportedFileType &) {
150154
env->SetIntField(result, errorField, -5);
151155
return result;
152156
} catch (...) {
@@ -163,8 +167,9 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jobject
163167
}
164168

165169
JNIEXPORT jobject JNICALL
166-
Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, jobject instance, jobject options, jstring htmlDiff)
167-
{
170+
Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env, jobject instance,
171+
jobject options,
172+
jstring htmlDiff) {
168173
jboolean isCopy;
169174

170175
jclass optionsClass = env->GetObjectClass(options);
@@ -176,11 +181,13 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env,
176181
jfieldID errorField = env->GetFieldID(resultClass, "errorCode", "I");
177182

178183
try {
179-
jfieldID outputPathPrefixField = env->GetFieldID(optionsClass, "outputPath", "Ljava/lang/String;");
184+
jfieldID outputPathPrefixField = env->GetFieldID(optionsClass, "outputPath",
185+
"Ljava/lang/String;");
180186
jstring outputPathPrefix = (jstring) env->GetObjectField(options, outputPathPrefixField);
181187

182188
const auto outputPathPrefixC = env->GetStringUTFChars(outputPathPrefix, &isCopy);
183-
auto outputPathPrefixCpp = std::string(outputPathPrefixC, env->GetStringUTFLength(outputPathPrefix));
189+
auto outputPathPrefixCpp = std::string(outputPathPrefixC,
190+
env->GetStringUTFLength(outputPathPrefix));
184191
env->ReleaseStringUTFChars(outputPathPrefix, outputPathPrefixC);
185192

186193
const auto htmlDiffC = env->GetStringUTFChars(htmlDiff, &isCopy);
@@ -220,7 +227,7 @@ Java_at_tomtasche_reader_background_CoreWrapper_backtranslateNative(JNIEnv *env,
220227
}
221228

222229
JNIEXPORT void JNICALL
223-
Java_at_tomtasche_reader_background_CoreWrapper_closeNative(JNIEnv *env, jobject instance, jobject options)
224-
{
230+
Java_at_tomtasche_reader_background_CoreWrapper_closeNative(JNIEnv *env, jobject instance,
231+
jobject options) {
225232
html.reset();
226233
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ extern "C" {
1515
Java_at_tomtasche_reader_background_CoreWrapper_closeNative(JNIEnv *env, jobject instance, jobject options);
1616
}
1717

18-
#endif //ANDROID_CORE_WRAPPER_H
18+
#endif //ANDROID_CORE_WRAPPER_H

0 commit comments

Comments
 (0)