Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 668a1e8

Browse files
Android now handles unicode filenames
1 parent b1d0be4 commit 668a1e8

File tree

7 files changed

+47
-29
lines changed

7 files changed

+47
-29
lines changed

Application.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ APP_PROJECT_PATH := $(call my-dir)/_build/android/debug
1111
APP_OPTIM := debug
1212
#APP_CPPFLAGS += -D_MOBILE -DTARGET_PLATFORM_MOBILE -DTARGET_SUBPLATFORM_ANDROID -D_DEBUG -fvisibility=hidden -g
1313
APP_CFLAGS += -D_MOBILE -DTARGET_PLATFORM_MOBILE -DTARGET_SUBPLATFORM_ANDROID -D_DEBUG -DANDROID_NDK -fvisibility=hidden -g
14+
APP_STL := gnustl_static
1415

1516
else
1617

engine/src/mblandroidfs.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,19 @@ bool apk_list_folder_entries(MCSystemListFolderEntriesCallback p_callback, void
152152
t_entry . group_id = t_stat . st_gid;
153153
t_entry . permissions = t_stat . st_mode & 0444;
154154

155-
char *t_next_entry = strclone(MCStringGetCString(*t_list));
156-
while (t_success && t_next_entry[0] != '\0')
155+
uindex_t t_length;
156+
char* t_next_entry;
157+
MCAutoStringRefAsUTF8String t_utf8_files;
158+
159+
t_success = t_utf8_files . Lock(*t_list);
160+
161+
if (t_success)
162+
{
163+
t_next_entry = *t_utf8_files;
164+
t_length = t_utf8_files . Size();
165+
}
166+
167+
while (t_success && t_length != 0)
157168
{
158169
uint32_t t_next_index = 0;
159170
uint32_t t_size_index = 0;
@@ -300,6 +311,9 @@ bool MCAndroidSystem::GetCurrentFolder(MCStringRef& r_path)
300311
if (NULL == getcwd((char*)t_folder_char . Chars(), PATH_MAX + 1))
301312
return false;
302313

314+
// SN-2014-01-15: avoid to create an MCString with junk chars in the end
315+
t_folder_char . Resize(strlen((char*)t_folder_char . Chars()));
316+
303317
return t_folder_char.CreateString(r_path);
304318
}
305319
}

libfoundation/include/foundation-auto.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class MCAutoStringRefAsUTF8String
268268

269269
bool Lock(MCStringRef p_string)
270270
{
271-
return MCStringConvertToUTF8String(p_string, m_utf8string);
271+
return MCStringConvertToUTF8(p_string, m_utf8string, m_size);
272272
}
273273

274274
void Unlock(void)
@@ -282,8 +282,14 @@ class MCAutoStringRefAsUTF8String
282282
return m_utf8string;
283283
}
284284

285+
uindex_t Size()
286+
{
287+
return m_size;
288+
}
289+
285290
private:
286291
char *m_utf8string;
292+
uindex_t m_size;
287293
};
288294

289295
////////////////////////////////////////////////////////////////////////////////

libgraphics/include/graphics.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1818
#define __MC_GRAPHICS__
1919

2020
#include "foundation.h"
21+
#include "foundation-auto.h"
2122

2223
////////////////////////////////////////////////////////////////////////////////
2324

libgraphics/src/mblandroidtext.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ void MCGContextDrawPlatformText(MCGContextRef self, const unichar_t *p_text, uin
4040
return;
4141

4242
bool t_success;
43-
t_success = true;
44-
45-
char *t_text;
46-
t_text = nil;
47-
if (t_success)
48-
{
49-
p_length = p_length / 2;
50-
t_success = MCCStringFromUnicodeSubstring(p_text, p_length, t_text);
51-
}
43+
t_success = true;
44+
45+
MCAutoStringRef t_unicode_string;
46+
MCAutoStringRefAsUTF8String t_utf8_string;
47+
48+
t_success = MCStringCreateWithChars(p_text, p_length / 2, &t_unicode_string);
49+
50+
if (t_success)
51+
t_success = t_utf8_string . Lock(*t_unicode_string);
5252

5353
if (t_success)
5454
{
@@ -68,10 +68,9 @@ void MCGContextDrawPlatformText(MCGContextRef self, const unichar_t *p_text, uin
6868
t_typeface = (SkTypeface *) p_font . fid;
6969
t_paint . setTypeface(t_typeface);
7070

71-
self -> layer -> canvas -> drawText(t_text, p_length, MCGCoordToSkCoord(p_location . x), MCGCoordToSkCoord(p_location . y), t_paint);
71+
self -> layer -> canvas -> drawText(*t_utf8_string, t_utf8_string . Size(), MCGCoordToSkCoord(p_location . x), MCGCoordToSkCoord(p_location . y), t_paint);
7272
}
7373

74-
MCCStringFree(t_text);
7574
self -> is_valid = t_success;
7675
}
7776

@@ -81,16 +80,16 @@ MCGFloat __MCGContextMeasurePlatformText(MCGContextRef self, const unichar_t *p_
8180
// return 0.0;
8281

8382
bool t_success;
84-
t_success = true;
85-
86-
char *t_text;
87-
t_text = nil;
88-
if (t_success)
89-
{
90-
p_length = p_length / 2;
91-
t_success = MCCStringFromUnicodeSubstring(p_text, p_length, t_text);
92-
}
93-
83+
t_success = true;
84+
85+
MCAutoStringRef t_unicode_string;
86+
MCAutoStringRefAsUTF8String t_utf8_string;
87+
88+
t_success = MCStringCreateWithChars(p_text, p_length / 2, &t_unicode_string);
89+
90+
if (t_success)
91+
t_success = t_utf8_string . Lock(*t_unicode_string);
92+
9493
MCGFloat t_width;
9594
t_width = 0.0;
9695
if (t_success)
@@ -102,10 +101,9 @@ MCGFloat __MCGContextMeasurePlatformText(MCGContextRef self, const unichar_t *p_
102101
t_typeface = (SkTypeface *) p_font . fid;
103102
t_paint . setTypeface(t_typeface);
104103

105-
t_width = (MCGFloat) t_paint . measureText(t_text, p_length);
104+
t_width = (MCGFloat) t_paint . measureText(*t_utf8_string, t_utf8_string . Size());
106105
}
107106

108-
MCCStringFree(t_text);
109107
//self -> is_valid = t_success;
110108
return t_width;
111109
}

revdb/Android.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ LOCAL_SRC_FILES := $(addprefix src/,revdb.cpp unxsupport.cpp database.cpp dbdriv
1212

1313
LOCAL_C_INCLUDES := \
1414
$(LOCAL_PATH)/include \
15-
$(LOCAL_PATH)/../libcore/include \
1615
$(LOCAL_PATH)/../libexternal/include \
1716
$(LOCAL_PATH)/../thirdparty/libzip/include \
1817
$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/include \
1918
$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/libs/$(TARGET_ARCH_ABI)/include
2019

2120
LOCAL_CPPFLAGS += -frtti -fexceptions
2221

23-
LOCAL_STATIC_LIBRARIES := libexternal libcore
22+
LOCAL_STATIC_LIBRARIES := libexternal
2423

2524
LOCAL_LDLIBS += -lz -llog \
2625
$(call host-path,$(ANDROID_NDK)/sources/cxx-stl/gnu-libstdc++/libs/$(TARGET_ARCH_ABI)/libstdc++.a)

revdb/src/unxsupport.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1919

2020
#include "unxsupport.h"
2121
#include <stdlib.h>
22-
#include <core.h>
2322

2423
void FreeDatabaseDriver( DATABASEREC *tdatabaserec)
2524
{

0 commit comments

Comments
 (0)