diff options
author | Tor Lillqvist <tml@iki.fi> | 2018-09-05 22:42:03 +0300 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2018-10-30 17:00:46 +0000 |
commit | 6cf73ae2491300882a30b8bade1212e9c3c284f9 (patch) | |
tree | 507fb85bc76beafa6235441994ff12d51d41eb14 /desktop | |
parent | b0bfe33719eecacb3527ab7ab70094f442ad104a (diff) |
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
(cherry picked from commit a754ce416c844b6b26eff0aab3e6bac65387b433)
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/Library_sofficeapp.mk | 6 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 51 |
2 files changed, 56 insertions, 1 deletions
diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk index 1491358a510e..133ee5aaf165 100644 --- a/desktop/Library_sofficeapp.mk +++ b/desktop/Library_sofficeapp.mk @@ -103,9 +103,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 0ca3e1bcc48b..4032c25a9613 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> @@ -3909,6 +3919,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) |