2017-09-24 19:59:28 +02:00
|
|
|
//
|
|
|
|
// 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 <stdio.h>
|
|
|
|
#include <TargetConditionals.h>
|
2018-01-05 22:53:57 +01:00
|
|
|
#define LOK_USE_UNSTABLE_API 1
|
|
|
|
#include "LibreOfficeKit.h"
|
|
|
|
|
2017-09-24 19:59:28 +02:00
|
|
|
#include <LibreOfficeKit/LibreOfficeKitInit.h>
|
|
|
|
|
|
|
|
#include <osl/process.h>
|
|
|
|
|
|
|
|
// generated by solenv/bin/native-code.py:
|
2018-01-14 12:02:29 +01:00
|
|
|
#include "../generated/native-code.h"
|
2017-09-24 19:59:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
// pointers to our instance
|
2018-01-08 20:03:44 +01:00
|
|
|
static LibreOfficeKit* kit;
|
2017-09-24 19:59:28 +02:00
|
|
|
static LibreOfficeKitDocument* document;
|
2017-09-29 08:59:42 +02:00
|
|
|
|
2017-09-24 19:59:28 +02:00
|
|
|
|
2017-11-16 14:27:56 +01:00
|
|
|
// Tile variables
|
|
|
|
static int tileSizeX, tileSizeY, tileMaxY, documentParts;
|
|
|
|
static double twipsPerXtile, twipsPerYtile;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-24 19:59:28 +02:00
|
|
|
// Bridge functions to LibreOfficeKit
|
2017-11-26 12:23:45 +01:00
|
|
|
__attribute__((visibility("default")))
|
2018-01-24 22:00:52 +11:00
|
|
|
int BridgeLOkit_Init(const char *appPath, const char *userPath)
|
2017-09-24 19:59:28 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
// Initialize LibreOfficeKit
|
2017-10-18 20:53:14 +02:00
|
|
|
if (!kit) {
|
2018-01-24 22:00:52 +11:00
|
|
|
kit = lok_init_2(appPath, userPath);
|
2017-10-18 20:53:14 +02:00
|
|
|
if (!kit)
|
|
|
|
return 1;
|
|
|
|
}
|
2017-09-24 19:59:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-16 14:14:30 +02:00
|
|
|
|
|
|
|
|
2017-11-26 12:23:45 +01:00
|
|
|
__attribute__((visibility("default")))
|
2017-11-16 14:27:56 +01:00
|
|
|
int BridgeLOkit_Sizing(const int countXtiles, const int countYtiles,
|
|
|
|
const int pixelsXtile, const int pixelsYtile)
|
|
|
|
{
|
|
|
|
long docWidth, docHeight;
|
|
|
|
|
2017-11-23 08:47:59 +01:00
|
|
|
(void)countXtiles;
|
|
|
|
(void)countYtiles;
|
|
|
|
|
2017-11-16 14:27:56 +01:00
|
|
|
// Remember for later
|
|
|
|
tileSizeX = pixelsXtile;
|
|
|
|
tileSizeY = pixelsYtile;
|
|
|
|
|
|
|
|
// Calculate twips to pixels in X,Y direction
|
|
|
|
document->pClass->getDocumentSize(document, &docWidth, &docHeight);
|
|
|
|
twipsPerXtile = docWidth / countXtiles;
|
|
|
|
double ratio = (double)docHeight / (double)docWidth + 0.05;
|
|
|
|
int x0 = (int)((ratio - (int)ratio) * 10.0);
|
|
|
|
int x1 = x0 * countXtiles / 10;
|
|
|
|
int x2 = (int)ratio;
|
|
|
|
tileMaxY = x1 + x2;
|
|
|
|
twipsPerYtile = docHeight / tileMaxY;
|
|
|
|
documentParts = document->pClass->getParts(document);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-26 12:23:45 +01:00
|
|
|
__attribute__((visibility("default")))
|
2017-10-16 14:14:30 +02:00
|
|
|
int BridgeLOkit_open(const char *path)
|
2017-09-24 19:59:28 +02:00
|
|
|
{
|
2017-10-16 14:14:30 +02:00
|
|
|
document = kit->pClass->documentLoad(kit, path);
|
2017-09-24 19:59:28 +02:00
|
|
|
document->pClass->initializeForRendering(document, "");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-16 14:14:30 +02:00
|
|
|
|
|
|
|
|
2017-11-26 12:23:45 +01:00
|
|
|
__attribute__((visibility("default")))
|
2017-10-16 14:14:30 +02:00
|
|
|
int BridgeLOkit_ClientCommand(const char *input)
|
|
|
|
{
|
2017-11-23 08:47:59 +01:00
|
|
|
(void)input;
|
2017-10-29 11:05:39 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-26 12:23:45 +01:00
|
|
|
__attribute__((visibility("default")))
|
2017-10-29 11:05:39 +01:00
|
|
|
int BridgeLOkit_Hipernate()
|
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
// check if document needs to be saved, to avoid data loss
|
|
|
|
// terminate all threads (basically terminate LOkit)
|
|
|
|
return 0;
|
2017-10-16 14:14:30 +02:00
|
|
|
}
|
2017-10-29 11:05:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-26 12:23:45 +01:00
|
|
|
__attribute__((visibility("default")))
|
2017-10-29 11:05:39 +01:00
|
|
|
int BridgeLOkit_LeaveHipernate()
|
|
|
|
{
|
|
|
|
//FIXME
|
|
|
|
// restart LOkit
|
|
|
|
// reload document (it may have been changed by other programs, especially if iCloud
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-08 20:03:44 +01:00
|
|
|
__attribute__((visibility("default")))
|
|
|
|
LibreOfficeKit* BridgeLOkit_getLOK()
|
|
|
|
{
|
|
|
|
return kit;
|
|
|
|
}
|