2 // This file is part of the LibreOffice project.
4 // This Source Code Form is subject to the terms of the Mozilla Public
5 // License, v. 2.0. If a copy of the MPL was not distributed with this
6 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 #include <TargetConditionals.h>
10 #define LOK_USE_UNSTABLE_API 1
11 #include "LibreOfficeKit.h"
13 #include <LibreOfficeKit/LibreOfficeKitInit.h>
15 #include <osl/process.h>
17 // generated by solenv/bin/native-code.py:
18 #include <../workdir/CustomTarget/ios/native-code.h>
21 // pointers to our instance
22 static LibreOfficeKit
* kit
;
23 static LibreOfficeKitDocument
* document
;
27 static int tileSizeX
, tileSizeY
, tileMaxY
, documentParts
;
28 static double twipsPerXtile
, twipsPerYtile
;
32 // Bridge functions to LibreOfficeKit
33 __attribute__((visibility("default")))
34 int BridgeLOkit_Init(const char *appPath
, const char *userPath
)
37 // Initialize LibreOfficeKit
39 kit
= lok_init_2(appPath
, userPath
);
48 __attribute__((visibility("default")))
49 int BridgeLOkit_Sizing(const int countXtiles
, const int countYtiles
,
50 const int pixelsXtile
, const int pixelsYtile
)
52 long docWidth
, docHeight
;
58 tileSizeX
= pixelsXtile
;
59 tileSizeY
= pixelsYtile
;
61 // Calculate twips to pixels in X,Y direction
62 document
->pClass
->getDocumentSize(document
, &docWidth
, &docHeight
);
63 twipsPerXtile
= docWidth
/ countXtiles
;
64 double ratio
= (double)docHeight
/ (double)docWidth
+ 0.05;
65 int x0
= (int)((ratio
- (int)ratio
) * 10.0);
66 int x1
= x0
* countXtiles
/ 10;
69 twipsPerYtile
= docHeight
/ tileMaxY
;
70 documentParts
= document
->pClass
->getParts(document
);
76 __attribute__((visibility("default")))
77 int BridgeLOkit_open(const char *path
)
79 document
= kit
->pClass
->documentLoad(kit
, path
);
80 document
->pClass
->initializeForRendering(document
, "");
86 __attribute__((visibility("default")))
87 int BridgeLOkit_ClientCommand(const char *input
)
95 __attribute__((visibility("default")))
96 int BridgeLOkit_Hipernate()
99 // check if document needs to be saved, to avoid data loss
100 // terminate all threads (basically terminate LOkit)
106 __attribute__((visibility("default")))
107 int BridgeLOkit_LeaveHipernate()
111 // reload document (it may have been changed by other programs, especially if iCloud
115 __attribute__((visibility("default")))
116 LibreOfficeKit
* BridgeLOkit_getLOK()