Author: pbartok
Date: 2005-05-25 15:15:09 -0400 (Wed, 25 May 2005)
New Revision: 45011
Modified:
trunk/libgdiplus/src/ChangeLog
trunk/libgdiplus/src/font.c
trunk/libgdiplus/src/gdip.h
trunk/libgdiplus/src/general.c
trunk/libgdiplus/src/graphics.c
trunk/libgdiplus/src/image.c
Log:
2005-05-25 Peter Bartok <[EMAIL PROTECTED]>
* graphics.c, font.c, image.c, general.c, gdip.h: Replaced UTF8/UTF16
conversion with UCS2/UTF8 conversion (The MS APIs do not use UTF16)
Modified: trunk/libgdiplus/src/ChangeLog
===================================================================
--- trunk/libgdiplus/src/ChangeLog 2005-05-25 19:11:41 UTC (rev 45010)
+++ trunk/libgdiplus/src/ChangeLog 2005-05-25 19:15:09 UTC (rev 45011)
@@ -1,3 +1,8 @@
+2005-05-25 Peter Bartok <[EMAIL PROTECTED]>
+
+ * graphics.c, font.c, image.c, general.c, gdip.h: Replaced UTF8/UTF16
+ conversion with UCS2/UTF8 conversion (The MS APIs do not use UTF16)
+
2005-05-24 Duncan Mak <[EMAIL PROTECTED]>
* graphics-path.c (append_arc): Append PathPointTypeLine instead
Modified: trunk/libgdiplus/src/font.c
===================================================================
--- trunk/libgdiplus/src/font.c 2005-05-25 19:11:41 UTC (rev 45010)
+++ trunk/libgdiplus/src/font.c 2005-05-25 19:15:09 UTC (rev 45011)
@@ -138,9 +138,8 @@
if (!font_collection || !filename)
return InvalidParameter;
- file = (unsigned char*) g_utf16_to_utf8 ((const gunichar2 *)filename,
-1,
- NULL, NULL, NULL);
-
+ file = (unsigned char*) ucs2_to_utf8 ((const gunichar2 *)filename);
+
FcConfigAppFontAddFile (font_collection->config, file);
g_free (file);
@@ -221,13 +220,12 @@
GpFontFamily **gpfam = gpfamilies;
FcPattern **pattern = font_collection->fontset->fonts;
int i;
-
+
if (!font_collection || !gpfamilies || !num_found)
return InvalidParameter;
if (font_collection->config)
gdip_createPrivateFontSet (font_collection);
-
for (i = 0; i < font_collection->fontset->nfont; gpfam++, pattern++,
i++) {
gdip_createFontFamily (gpfam);
@@ -242,8 +240,6 @@
GpStatus
GdipCreateFontFamilyFromName (GDIPCONST WCHAR *name, GpFontCollection
*font_collection, GpFontFamily **fontFamily)
{
- glong items_read = 0;
- glong items_written = 0;
unsigned char *string;
FcPattern **gpfam;
FcChar8 *str;
@@ -252,8 +248,7 @@
if (!name || !fontFamily)
return InvalidParameter;
- string = (unsigned char*)g_utf16_to_utf8 ((const gunichar2 *)name, -1,
- &items_read, &items_written,
NULL);
+ string = (unsigned char*)ucs2_to_utf8 ((const gunichar2 *)name);
if (!font_collection) {
FcChar8 *str;
@@ -299,13 +294,10 @@
return FontFamilyNotFound;
}
-
GpStatus
GdipGetFamilyName (GDIPCONST GpFontFamily *family, WCHAR name[LF_FACESIZE],
int language)
{
FcChar8 *fc_str;
- glong items_read = 0;
- glong items_written = 0;
FcResult r;
gunichar2 *string;
@@ -314,16 +306,7 @@
r = FcPatternGetString (family->pattern, FC_FAMILY, 0, &fc_str);
- string = g_utf8_to_utf16 ((const gchar *)fc_str, -1, &items_read,
&items_written,NULL);
-
- if (items_written>= (LF_FACESIZE-1))
- items_written= (LF_FACESIZE-1);
-
- memcpy (name, string, items_written * sizeof (WCHAR));
- name [1+items_written*sizeof (WCHAR)]=0;
-
- g_free (string);
-
+ utf8_to_ucs2((const gchar *)fc_str, (gunichar2 *)name, LF_FACESIZE);
return Ok;
}
Modified: trunk/libgdiplus/src/gdip.h
===================================================================
--- trunk/libgdiplus/src/gdip.h 2005-05-25 19:11:41 UTC (rev 45010)
+++ trunk/libgdiplus/src/gdip.h 2005-05-25 19:15:09 UTC (rev 45011)
@@ -1265,7 +1265,10 @@
cairo_surface_t * gdip_bitmap_ensure_surface (GpBitmap *bitmap);
const EncoderParameter *gdip_find_encoder_parameter (GDIPCONST
EncoderParameters *eps, const GUID *guid);
+gchar *ucs2_to_utf8(const gunichar2 *ucs2);
+bool utf8_to_ucs2(const gchar *utf8, gunichar2 *ucs2, int ucs2_len);
+
/* Stream handling bits */
typedef int (*GetHeaderDelegate) (unsigned char *, int);
typedef int (*GetBytesDelegate) (unsigned char *, int, BOOL);
Modified: trunk/libgdiplus/src/general.c
===================================================================
--- trunk/libgdiplus/src/general.c 2005-05-25 19:11:41 UTC (rev 45010)
+++ trunk/libgdiplus/src/general.c 2005-05-25 19:15:09 UTC (rev 45011)
@@ -422,3 +422,78 @@
return constant * series;
}
+
+gchar *
+ucs2_to_utf8(const gunichar2 *ucs2) {
+ unsigned int ch;
+ unsigned int len;
+ const gunichar2 *ptr;
+ gunichar *dest;
+ gunichar *uni;
+ gchar *utf8;
+
+ // Count length
+ ptr = ucs2;
+ len = 0;
+ while (*ptr != 0) {
+ ptr++;
+ len++;
+ }
+
+ uni = malloc((len + 1) * sizeof(gunichar));
+ if (uni == NULL) {
+ return NULL;
+ }
+
+ dest = uni;
+ ptr = ucs2;
+ while (*ptr != 0) {
+ if (*ptr < 0xd800 || *ptr >= 0xe000) {
+ *dest = *ptr;
+ dest++;
+ }
+ ptr++;
+ }
+ *dest = 0;
+ dest++;
+
+ utf8 = (gchar *) g_ucs4_to_utf8 ((const gunichar *)uni, -1, NULL, NULL,
NULL);
+
+ free(uni);
+
+ return utf8;
+}
+
+bool
+utf8_to_ucs2(const gchar *utf8, gunichar2 *ucs2, int ucs2_len) {
+ int i;
+ glong items_read;
+ glong count;
+ gunichar *ucs4;
+ unsigned char *ptr;
+
+ items_read = 0;
+ count = 0;
+
+ ucs2_len--; // Space for null terminator
+
+ ucs4 = g_utf8_to_ucs4(utf8, -1, &items_read, &count, NULL);
+ if (ucs4 == NULL) {
+ return FALSE;
+ }
+
+ ptr = (unsigned char *)ucs2;
+ for (i = 0; (i < count) && (i < ucs2_len); i++) {
+ if (ucs4[i] < 0x1000 && !(ucs4[i] >= 0xd800 && ucs4[i] <
0xe000)) {
+ ptr[0] = (unsigned char)ucs4[i];
+ ptr[1] = (unsigned char)(ucs4[i] >> 8);
+ ptr += 2;
+ } // we're simply ignoring any chars that don't fit into
ucs2
+ }
+ ucs2[ptr - (unsigned char *)ucs2] = 0; // terminate
+
+ // free the intermediate ucs4 string
+ g_free(ucs4);
+
+ return TRUE;
+}
Modified: trunk/libgdiplus/src/graphics.c
===================================================================
--- trunk/libgdiplus/src/graphics.c 2005-05-25 19:11:41 UTC (rev 45010)
+++ trunk/libgdiplus/src/graphics.c 2005-05-25 19:15:09 UTC (rev 45011)
@@ -1873,7 +1873,7 @@
}
/* Convert string from Gdiplus format to UTF8, suitable for cairo */
- String= (unsigned char *) g_utf16_to_utf8 ((const gunichar2
*)CleanString, (glong)StringLen, NULL, NULL, NULL);
+ String = (unsigned char *) ucs2_to_utf8 ((const gunichar2
*)CleanString);
if (!String) {
free (CleanString);
free (StringDetails);
@@ -2291,7 +2291,7 @@
continue;
}
- String= (unsigned char *) g_utf16_to_utf8
((const gunichar2 *)(CleanString+i), (glong)StringDetails[i].LineLen, NULL,
NULL, NULL);
+ String= (unsigned char *) ucs2_to_utf8 ((const
gunichar2 *)(CleanString+i));
#ifdef DRAWSTRING_DEBUG
printf("Displaying line >%s<\n", String);
#endif
@@ -2644,7 +2644,7 @@
}
/* Convert string from Gdiplus format to UTF8, suitable for cairo */
- String=(unsigned char *) g_utf16_to_utf8 ((const gunichar2
*)CleanString, (glong)StringLen, NULL, NULL, NULL);
+ String=(unsigned char *) ucs2_to_utf8 ((const gunichar2 *)CleanString);
if (!String) {
free (CleanString);
free (StringDetails);
Modified: trunk/libgdiplus/src/image.c
===================================================================
--- trunk/libgdiplus/src/image.c 2005-05-25 19:11:41 UTC (rev 45010)
+++ trunk/libgdiplus/src/image.c 2005-05-25 19:15:09 UTC (rev 45011)
@@ -464,16 +464,14 @@
char format_peek[10];
int format_peek_sz;
- GError *err = NULL;
-
if (!image || !file)
return InvalidParameter;
- file_name = (char *) g_utf16_to_utf8 ((const gunichar2 *)file, -1,
NULL, NULL, &err);
- if (file_name == NULL || err != NULL) {
+ file_name = (char *) ucs2_to_utf8 ((const gunichar2 *)file);
+ if (file_name == NULL) {
*image = NULL;
return InvalidParameter;
- }
+ }
fp = fopen(file_name, "rb");
g_free (file_name);
@@ -568,7 +566,6 @@
FILE *fp = 0;
GpStatus status = 0;
char *file_name;
- GError *err = NULL;
ImageFormat format;
if (image->type != imageBitmap)
@@ -581,8 +578,8 @@
if (format == INVALID)
return UnknownImageFormat;
- file_name = (char *) g_utf16_to_utf8 ((const gunichar2 *)file, -1,
NULL, NULL, &err);
- if (file_name == NULL || err != NULL)
+ file_name = (char *) ucs2_to_utf8 ((const gunichar2 *)file);
+ if (file_name == NULL)
return InvalidParameter;
if (format == GIF) { /* gif library has to open the file itself*/
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches