From 9426c6fcb8600daa136d30e65cd0410a334c86d5 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 18 Jan 2023 19:23:16 +0100 Subject: [PATCH] Use Illustration api instead of deprecated favicon for Book --- lib/src/main/cpp/CMakeLists.txt | 1 + lib/src/main/cpp/libkiwix/book.cpp | 17 ++++-- lib/src/main/cpp/libkiwix/illustration.cpp | 53 +++++++++++++++++++ lib/src/main/cpp/utils.h | 2 + .../main/java/org/kiwix/libkiwix/Book.java | 6 +-- .../java/org/kiwix/libkiwix/Illustration.java | 17 ++++++ 6 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 lib/src/main/cpp/libkiwix/illustration.cpp create mode 100644 lib/src/main/java/org/kiwix/libkiwix/Illustration.java diff --git a/lib/src/main/cpp/CMakeLists.txt b/lib/src/main/cpp/CMakeLists.txt index 27858e5..d72816b 100644 --- a/lib/src/main/cpp/CMakeLists.txt +++ b/lib/src/main/cpp/CMakeLists.txt @@ -52,6 +52,7 @@ add_library( libkiwix/kiwixserver.cpp libkiwix/library.cpp libkiwix/manager.cpp + libkiwix/illustration.cpp ) find_library(libkiwix diff --git a/lib/src/main/cpp/libkiwix/book.cpp b/lib/src/main/cpp/libkiwix/book.cpp index dd9c21c..e95b295 100644 --- a/lib/src/main/cpp/libkiwix/book.cpp +++ b/lib/src/main/cpp/libkiwix/book.cpp @@ -66,10 +66,21 @@ GETTER(jstring, getTags) GETTER(jlong, getArticleCount) GETTER(jlong, getMediaCount) GETTER(jlong, getSize) -GETTER(jstring, getFavicon) -GETTER(jstring, getFaviconUrl) -GETTER(jstring, getFaviconMimeType) +METHOD0(jobjectArray, getIllustrations) { + auto illustrations = THIS->getIllustrations(); + jobjectArray retArray = createArray(env, illustrations.size(), "org/kiwix/libkiwix/Illustration"); + size_t index = 0; + for (auto illu: illustrations) { + auto wrapper = BUILD_WRAPPER("org/kiwix/libkiwx/Illustration", illu); + env->SetObjectArrayElement(retArray, index++, wrapper); + } + return retArray; +} + +METHOD(jobject, getIllustration, jint size) { + return BUILD_WRAPPER("org/kiwix/libkiwix/Illustration", THIS->getIllustration(TO_C(size))); +} METHOD(jstring, getTagStr, jstring tagName) try { return TO_JNI(THIS->getTagStr(TO_C(tagName))); } catch(...) { diff --git a/lib/src/main/cpp/libkiwix/illustration.cpp b/lib/src/main/cpp/libkiwix/illustration.cpp new file mode 100644 index 0000000..f4730d9 --- /dev/null +++ b/lib/src/main/cpp/libkiwix/illustration.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2020 Matthieu Gautier + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + + +#include +#include "org_kiwix_libkiwix_Book.h" + +#include "utils.h" +#include "book.h" +#include + +#define NATIVE_TYPE kiwix::Book::Illustration +#define TYPENAME libkiwix_Illustration +#include + +METHOD0(void, dispose) +{ + dispose(env, thisObj); +} + +METHOD0(jint, width) { + return TO_JNI(THIS->width); +} + +METHOD0(jint, height) { + return TO_JNI(THIS->width); +} + +METHOD0(jstring, mimeType) { + return TO_JNI(THIS->mimeType); +} + +METHOD0(jstring, url) { + return TO_JNI(THIS->url); +} + +GETTER(jstring, getData) diff --git a/lib/src/main/cpp/utils.h b/lib/src/main/cpp/utils.h index ee77347..220a317 100644 --- a/lib/src/main/cpp/utils.h +++ b/lib/src/main/cpp/utils.h @@ -147,8 +147,10 @@ template struct JType { }; template<> struct JType{ typedef jboolean type_t; }; +template<> struct JType{ typedef jint type_t; }; template<> struct JType{ typedef jint type_t; }; template<> struct JType{ typedef jlong type_t; }; +template<> struct JType{ typedef jint type_t; }; template<> struct JType { typedef jlong type_t; }; template<> struct JType { typedef jlong type_t; }; template<> struct JType{ typedef jstring type_t; }; diff --git a/lib/src/main/java/org/kiwix/libkiwix/Book.java b/lib/src/main/java/org/kiwix/libkiwix/Book.java index 9c6edde..5d3e042 100644 --- a/lib/src/main/java/org/kiwix/libkiwix/Book.java +++ b/lib/src/main/java/org/kiwix/libkiwix/Book.java @@ -2,6 +2,7 @@ package org.kiwix.libkiwix; import org.kiwix.libzim.Archive; +import org.kiwix.libkiwix.Illustration; public class Book { @@ -40,9 +41,8 @@ public class Book public native long getMediaCount(); public native long getSize(); - public native String getFavicon(); - public native String getFaviconUrl(); - public native String getFaviconMimeType(); + public native Illustration[] getIllustrations(); + public native Illustration getIllustration(int size); private native void allocate(); private native void dispose(); diff --git a/lib/src/main/java/org/kiwix/libkiwix/Illustration.java b/lib/src/main/java/org/kiwix/libkiwix/Illustration.java new file mode 100644 index 0000000..771a4e2 --- /dev/null +++ b/lib/src/main/java/org/kiwix/libkiwix/Illustration.java @@ -0,0 +1,17 @@ + +package org.kiwix.libkiwix; + +public class Illustration +{ + public native int width(); + public native int height(); + public native String mimeType(); + public native String url(); + + public native String getData(); + @Override + protected void finalize() { dispose(); } + + private native void dispose(); + private long nativeHandle; +}