String fixes

This commit is contained in:
Joshua Granick
2019-03-14 16:25:38 -07:00
parent ac0f49aeea
commit a5de7d83c2
7 changed files with 26 additions and 14 deletions

View File

@@ -1109,7 +1109,12 @@ namespace lime {
#ifdef LIME_FREETYPE
Font *font = (Font*)fontHandle->ptr;
wchar_t *name = font->GetFamilyName ();
return (vbyte*)name;
int size = std::wcslen (name);
char* result = (char*)malloc (size + 1);
std::wcstombs (result, name, size);
result[size] = '\0';
delete name;
return (vbyte*)result;
#else
return 0;
#endif

View File

@@ -2272,7 +2272,6 @@ namespace lime {
int length = strlen (version);
char* _version = (char*)malloc (length + 1);
strcpy (_version, version);
_version[length] = '\0';
return (vbyte*)_version;
}

View File

@@ -2207,7 +2207,6 @@ namespace lime {
int length = strlen (result);
char* _result = (char*)malloc (length + 1);
strcpy (_result, result);
_result[length] = '\0';
return (vbyte*)_result;
}
@@ -3389,7 +3388,6 @@ namespace lime {
int length = strlen (result);
char* _result = (char*)malloc (length + 1);
strcpy (_result, result);
_result[length] = '\0';
return (vbyte*)_result;
}

View File

@@ -2191,7 +2191,6 @@ namespace lime {
int length = strlen (result);
char* _result = (char*)malloc (length + 1);
strcpy (_result, result);
_result[length] = '\0';
return (vbyte*)_result;
}
@@ -2211,7 +2210,6 @@ namespace lime {
int length = strlen (result);
char* _result = (char*)malloc (length + 1);
strcpy (_result, result);
_result[length] = '\0';
return (vbyte*)_result;
}
@@ -2762,7 +2760,6 @@ namespace lime {
int length = strlen (result);
char* _result = (char*)malloc (length + 1);
strcpy (_result, result);
_result[length] = '\0';
return (vbyte*)_result;
}

View File

@@ -622,11 +622,28 @@ namespace lime {
hl_dyn_seti (ret, hl_hash_utf8 ("is_bold"), &hlt_bool, ((FT_Face)face)->style_flags & FT_STYLE_FLAG_BOLD);
hl_dyn_seti (ret, hl_hash_utf8 ("num_glyphs"), &hlt_i32, num_glyphs);
// TODO: if family_name is null, convert to wide string
char* _family_name = NULL;
if (family_name != NULL) {
int length = std::wcslen (family_name);
char* result = (char*)malloc (length + 1);
std::wcstombs (result, family_name, length);
result[length] = '\0';
delete family_name;
} else {
int length = strlen (((FT_Face)face)->family_name);
_family_name = (char*)malloc (length + 1);
strcpy (_family_name, ((FT_Face)face)->family_name);
}
char* style_name = (char*)malloc(strlen(((FT_Face)face)->style_name) + 1);
strcpy(style_name, ((FT_Face)face)->style_name);
hl_dyn_setp (ret, hl_hash_utf8 ("family_name"), &hlt_bytes, family_name);
hl_dyn_setp (ret, hl_hash_utf8 ("family_name"), &hlt_bytes, _family_name);
hl_dyn_setp (ret, hl_hash_utf8 ("style_name"), &hlt_bytes, style_name);
hl_dyn_seti (ret, hl_hash_utf8 ("em_size"), &hlt_i32, ((FT_Face)face)->units_per_EM);
hl_dyn_seti (ret, hl_hash_utf8 ("ascend"), &hlt_i32, ((FT_Face)face)->ascender);

View File

@@ -727,7 +727,6 @@ namespace lime {
int length = strlen (result);
char* _result = (char*)malloc (length + 1);
strcpy (_result, result);
_result[length] = '\0';
return (vbyte*)_result;
}
@@ -1149,7 +1148,6 @@ namespace lime {
int length = strlen (result);
char* _result = (char*)malloc (length + 1);
strcpy (_result, result);
_result[length] = '\0';
return (vbyte*)_result;
}
@@ -1419,7 +1417,6 @@ namespace lime {
int length = strlen (result);
char* _result = (char*)malloc (length + 1);
strcpy (_result, result);
_result[length] = '\0';
return (vbyte*)_result;
}
@@ -1608,7 +1605,6 @@ namespace lime {
int length = strlen (result);
char* _result = (char*)malloc (length + 1);
strcpy (_result, result);
_result[length] = '\0';
return (vbyte*)_result;
}

View File

@@ -472,7 +472,7 @@ class Font
if (name == null)
{
#if hl
name = @:privateAccess String.fromUCS2(NativeCFFI.lime_font_get_family_name(src));
name = @:privateAccess String.fromUTF8(NativeCFFI.lime_font_get_family_name(src));
#else
name = cast NativeCFFI.lime_font_get_family_name(src);
#end