Use Illustration api instead of deprecated favicon for Book

This commit is contained in:
Matthieu Gautier 2023-01-18 19:23:16 +01:00
parent 876d38b9f3
commit 9426c6fcb8
6 changed files with 90 additions and 6 deletions

View File

@ -52,6 +52,7 @@ add_library(
libkiwix/kiwixserver.cpp
libkiwix/library.cpp
libkiwix/manager.cpp
libkiwix/illustration.cpp
)
find_library(libkiwix

View File

@ -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(...) {

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) 2020 Matthieu Gautier <mgautier@kymeria.fr>
*
* 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 <jni.h>
#include "org_kiwix_libkiwix_Book.h"
#include "utils.h"
#include "book.h"
#include <zim/archive.h>
#define NATIVE_TYPE kiwix::Book::Illustration
#define TYPENAME libkiwix_Illustration
#include <macros.h>
METHOD0(void, dispose)
{
dispose<NATIVE_TYPE>(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)

View File

@ -147,8 +147,10 @@ template<typename T>
struct JType { };
template<> struct JType<bool>{ typedef jboolean type_t; };
template<> struct JType<int16_t>{ typedef jint type_t; };
template<> struct JType<int32_t>{ typedef jint type_t; };
template<> struct JType<int64_t>{ typedef jlong type_t; };
template<> struct JType<uint16_t>{ typedef jint type_t; };
template<> struct JType<uint64_t> { typedef jlong type_t; };
template<> struct JType<uint32_t> { typedef jlong type_t; };
template<> struct JType<std::string>{ typedef jstring type_t; };

View File

@ -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();

View File

@ -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;
}