summaryrefslogtreecommitdiffstats
path: root/desktop
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2018-09-05 22:42:03 +0300
committerTor Lillqvist <tml@iki.fi>2018-09-05 22:46:01 +0300
commita754ce416c844b6b26eff0aab3e6bac65387b433 (patch)
tree4c3c0585c8120f26309802fdf03093dc71e31626 /desktop
parentupgrade curl to 7.61.1 (diff)
downloadcore-a754ce416c844b6b26eff0aab3e6bac65387b433.tar.gz
core-a754ce416c844b6b26eff0aab3e6bac65387b433.zip
Re-introduce code to use the ICU data file in the iOS app bundle
We used to have this code snippet in the TiledLibreOffice app back in the days. Then in LibreOfficeLight it was lost and forgotten (?). Clearly we need to tell ICU abouyt the data that we include as a separate file in iOS apps, and presumably any iOS app will be a LibreOffficeKit-based one, so let's do the initialistion here. Change-Id: Ib08dc9d7386789d10e8c53114e79d0b5beab7232
Diffstat (limited to 'desktop')
-rw-r--r--desktop/Library_sofficeapp.mk6
-rw-r--r--desktop/source/lib/init.cxx51
2 files changed, 56 insertions, 1 deletions
diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk
index 38e427d66173..215c7ed07251 100644
--- a/desktop/Library_sofficeapp.mk
+++ b/desktop/Library_sofficeapp.mk
@@ -99,9 +99,15 @@ $(eval $(call gb_Library_use_system_darwin_frameworks,sofficeapp,\
endif
ifeq ($(OS),IOS)
+
$(eval $(call gb_Library_add_cflags,sofficeapp,\
$(gb_OBJCFLAGS) \
))
+
+$(eval $(call gb_Library_add_cxxflags,sofficeapp,\
+ $(gb_OBJCXXFLAGS) \
+))
+
endif
$(eval $(call gb_Library_add_exception_objects,sofficeapp,\
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 5c89c1dbd386..32c0a0b2b03c 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1,4 +1,4 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
@@ -13,6 +13,16 @@
#include <string.h>
#include <stdlib.h>
+#ifdef IOS
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <unicode/udata.h>
+#include <unicode/ucnv.h>
+#include <premac.h>
+#import <Foundation/Foundation.h>
+#include <postmac.h>
+#endif
+
#include <algorithm>
#include <memory>
#include <iostream>
@@ -3871,6 +3881,45 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
if (osl::FileBase::getFileURLFromSystemPath(aAppPath, aAppURL) != osl::FileBase::E_None)
return 0;
+#ifdef IOS
+ // A LibreOffice-using iOS app should have the ICU data file in the app bundle. Initialize ICU
+ // to use that.
+ NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
+
+ int fd = open([[bundlePath stringByAppendingPathComponent:@U_ICUDATA_NAME".dat"] UTF8String], O_RDONLY);
+ if (fd == -1)
+ NSLog(@"Could not open ICU data file %s", [[bundlePath stringByAppendingPathComponent:@U_ICUDATA_NAME".dat"] UTF8String]);
+ else
+ {
+ struct stat st;
+ if (fstat(fd, &st) == -1)
+ NSLog(@"fstat on ICU data file failed: %s", strerror(errno));
+ else
+ {
+ void *icudata = mmap(0, (size_t) st.st_size, PROT_READ, MAP_FILE|MAP_PRIVATE, fd, 0);
+ if (icudata == MAP_FAILED)
+ NSLog(@"mmap failed: %s", strerror(errno));
+ else
+ {
+ UErrorCode icuStatus = U_ZERO_ERROR;
+ udata_setCommonData(icudata, &icuStatus);
+ if (U_FAILURE(icuStatus))
+ NSLog(@"udata_setCommonData failed");
+ else
+ {
+ // Quick test that ICU works...
+ UConverter *cnv = ucnv_open("iso-8859-3", &icuStatus);
+ NSLog(@"ucnv_open(iso-8859-3)-> %p, err = %s, name=%s",
+ (void *)cnv, u_errorName(icuStatus), (!cnv)?"?":ucnv_getName(cnv,&icuStatus));
+ if (U_SUCCESS(icuStatus))
+ ucnv_close(cnv);
+ }
+ }
+ }
+ close(fd);
+ }
+#endif
+
try
{
if (eStage != SECOND_INIT)