From ca61fdcac919f799b5273c24932adc0cbd8300e2 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 30 Jun 2014 23:30:03 +0200 Subject: libreofficekit JNI for Android Change-Id: Ia905c20fb4ee9b126d65fd3c8e3c1f54649abe1a --- .../src/org/libreoffice/kit/Document.java | 57 ++++++++++ .../Bootstrap/src/org/libreoffice/kit/Office.java | 34 ++++++ desktop/Library_sofficeapp.mk | 6 + desktop/source/lib/lokandroid.cxx | 124 +++++++++++++++++++++ 4 files changed, 221 insertions(+) create mode 100644 android/Bootstrap/src/org/libreoffice/kit/Document.java create mode 100644 android/Bootstrap/src/org/libreoffice/kit/Office.java create mode 100644 desktop/source/lib/lokandroid.cxx diff --git a/android/Bootstrap/src/org/libreoffice/kit/Document.java b/android/Bootstrap/src/org/libreoffice/kit/Document.java new file mode 100644 index 000000000000..2670b9ebc65b --- /dev/null +++ b/android/Bootstrap/src/org/libreoffice/kit/Document.java @@ -0,0 +1,57 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package org.libreoffice.kit; + +import java.nio.ByteBuffer; + +public class Document { + + private final long handle; + + private native void setPartNative(long handle, int part); + private native int getNumberOfPartsNative(long handle); + private native int getDocumentTypeNative(long handle); + private native void paintTileNative(long handle, ByteBuffer buffer, int canvasWidth, int canvasHeight, int tilePositionX, int tilePositionY, int tileWidth, int tileHeight); + private native long getDocumentHeightNative(long handle); + private native long getDocumentWidthNative(long handle); + + public Document(long handle) { + this.handle = handle; + } + + public boolean saveAs(String url) { + return false; + } + + public int getDocumentType() { + return getDocumentTypeNative(handle); + } + + public int getNumberOfParts() { + return getNumberOfPartsNative(handle); + } + + public void setPart(int part) { + setPartNative(handle, part); + } + + void paintTile(ByteBuffer buffer, int canvasWidth, int canvasHeight, int tilePositionX, int tilePositionY, int tileWidth, int tileHeight) { + paintTileNative(handle, buffer, canvasWidth, canvasHeight, tilePositionX, tilePositionY, tileWidth, tileHeight); + } + + public long getDocumentWidth() { + return getDocumentWidthNative(handle); + } + + public long getDocumentHeight() { + return getDocumentHeightNative(handle); + } + +} diff --git a/android/Bootstrap/src/org/libreoffice/kit/Office.java b/android/Bootstrap/src/org/libreoffice/kit/Office.java new file mode 100644 index 000000000000..abd98c775e0a --- /dev/null +++ b/android/Bootstrap/src/org/libreoffice/kit/Office.java @@ -0,0 +1,34 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package org.libreoffice.kit; + +import android.util.Log; + +public class Office { + + private long handle; + + public Office(long handle) { + this.handle = handle; + } + + public native String getErrorNative(); + + private native long documentLoadNative(String url); + + public Document documentLoad(String url) { + long handle = documentLoadNative(url); + Document document = null; + if (handle > 0) { + document = new Document(handle); + } + return document; + } +} diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk index 867e39885ac4..d81420fe5b35 100644 --- a/desktop/Library_sofficeapp.mk +++ b/desktop/Library_sofficeapp.mk @@ -100,6 +100,12 @@ $(eval $(call gb_Library_add_exception_objects,sofficeapp,\ desktop/source/lib/init \ )) +ifeq ($(OS),ANDROID) +$(eval $(call gb_Library_add_exception_objects,sofficeapp,\ + desktop/source/lib/lokandroid \ +)) +endif + ifeq ($(ENABLE_TELEPATHY),TRUE) $(eval $(call gb_Library_use_libraries,sofficeapp,tubes)) endif diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx new file mode 100644 index 000000000000..5b0559147cee --- /dev/null +++ b/desktop/source/lib/lokandroid.cxx @@ -0,0 +1,124 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include + +#include + +#include + +#define LOK_USE_UNSTABLE_API + +#include + +#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "LibreOfficeKit", __VA_ARGS__)) + +/* LibreOfficeKit */ + +jfieldID getHandleField(JNIEnv* pEnv, jobject aObject) +{ + jclass clazz = pEnv->GetObjectClass(aObject); + return pEnv->GetFieldID(clazz, "handle", "J"); +} + +template +T* getHandle(JNIEnv* pEnv, jobject aObject) +{ + jlong aHandle = pEnv->GetLongField(aObject, getHandleField(pEnv, aObject)); + return reinterpret_cast(aHandle); +} + +template +void setHandle(JNIEnv* pEnv, jobject aObject, T* aType) +{ + jlong aHandle = reinterpret_cast(aType); + pEnv->SetLongField(aObject, getHandleField(pEnv, aObject), aHandle); +} + +extern "C" SAL_JNI_EXPORT jstring JNICALL Java_org_libreoffice_kit_Office_getErrorNative(JNIEnv* pEnv, jobject aObject) +{ + LibreOfficeKit* pLibreOfficeKit = getHandle(pEnv, aObject); + char* pError = pLibreOfficeKit->pClass->getError(pLibreOfficeKit); + return pEnv->NewStringUTF(pError); +} + +extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_initialize(JNIEnv* pEnv, jobject aObject, jlong aLokHandle) +{ + pEnv->SetLongField(aObject, getHandleField(pEnv, aObject), aLokHandle); +} + +extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Office_documentLoadNative(JNIEnv* pEnv, jobject aObject, jstring documentPath) +{ + const char* aCloneDocumentPath; + + const char* aCharDocumentPath = pEnv->GetStringUTFChars(documentPath, NULL); + aCloneDocumentPath = strdup(aCharDocumentPath); + pEnv->ReleaseStringUTFChars(documentPath, aCharDocumentPath); + + LibreOfficeKit* pLibreOfficeKit = getHandle(pEnv, aObject); + LOGI("D( %s ): %d", aCloneDocumentPath, (int) pLibreOfficeKit); + + LibreOfficeKitDocument* pDocument = pLibreOfficeKit->pClass->documentLoad(pLibreOfficeKit, aCloneDocumentPath); + return (jlong) (intptr_t) pDocument; +} + +/* Document */ +extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_setPartNative + (JNIEnv* pEnv, jobject aObject, jint aPart) +{ + LibreOfficeKitDocument* pDocument = getHandle(pEnv, aObject); + pDocument->pClass->setPart(pDocument, aPart); +} + +extern "C" SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Document_getNumberOfPartsNative + (JNIEnv* pEnv, jobject aObject) +{ + LibreOfficeKitDocument* pDocument = getHandle(pEnv, aObject); + return (jint) pDocument->pClass->getNumberOfParts(pDocument); +} + +extern "C" SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Document_getDocumentTypeNative + (JNIEnv* pEnv, jobject aObject) +{ + LibreOfficeKitDocument* pDocument = getHandle(pEnv, aObject); + return (jint) pDocument->pClass->getDocumentType(pDocument); +} + +extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_paintTileNative + (JNIEnv* pEnv, jobject aObject, jobject /*aByteBuffer*/, + jint nCanvasWidth, jint nCanvasHeight, jint nTilePosX, jint nTilePosY, + jint nTileWidth, jint nTileHeight) +{ + LibreOfficeKitDocument* pDocument = getHandle(pEnv, aObject); + return pDocument->pClass->paintTile(pDocument, NULL, nCanvasWidth, nCanvasHeight, NULL, nTilePosX, nTilePosY, nTileWidth, nTileHeight); +} + +extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Document_getDocumentHeightNative + (JNIEnv* pEnv, jobject aObject) +{ + LibreOfficeKitDocument* pDocument = getHandle(pEnv, aObject); + long nWidth; + long nHeight; + pDocument->pClass->getDocumentSize(pDocument, &nWidth, &nHeight); + return nHeight; +} + +extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Document_getDocumentWidthNative + (JNIEnv* pEnv, jobject aObject) +{ + LibreOfficeKitDocument* pDocument = getHandle(pEnv, aObject); + long nWidth; + long nHeight; + pDocument->pClass->getDocumentSize(pDocument, &nWidth, &nHeight); + return nWidth; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit