Kaydet (Commit) a754ce41 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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
üst d15d3ce6
...@@ -99,9 +99,15 @@ $(eval $(call gb_Library_use_system_darwin_frameworks,sofficeapp,\ ...@@ -99,9 +99,15 @@ $(eval $(call gb_Library_use_system_darwin_frameworks,sofficeapp,\
endif endif
ifeq ($(OS),IOS) ifeq ($(OS),IOS)
$(eval $(call gb_Library_add_cflags,sofficeapp,\ $(eval $(call gb_Library_add_cflags,sofficeapp,\
$(gb_OBJCFLAGS) \ $(gb_OBJCFLAGS) \
)) ))
$(eval $(call gb_Library_add_cxxflags,sofficeapp,\
$(gb_OBJCXXFLAGS) \
))
endif endif
$(eval $(call gb_Library_add_exception_objects,sofficeapp,\ $(eval $(call gb_Library_add_exception_objects,sofficeapp,\
......
/* -*- 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. * This file is part of the LibreOffice project.
* *
...@@ -13,6 +13,16 @@ ...@@ -13,6 +13,16 @@
#include <string.h> #include <string.h>
#include <stdlib.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 <algorithm>
#include <memory> #include <memory>
#include <iostream> #include <iostream>
...@@ -3871,6 +3881,45 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char ...@@ -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) if (osl::FileBase::getFileURLFromSystemPath(aAppPath, aAppURL) != osl::FileBase::E_None)
return 0; 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 try
{ {
if (eStage != SECOND_INIT) if (eStage != SECOND_INIT)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment