Author: spouliot
Date: 2006-05-30 14:59:37 -0400 (Tue, 30 May 2006)
New Revision: 61278
Modified:
trunk/libgdiplus/src/ChangeLog
trunk/libgdiplus/src/font.c
Log:
2006-05-30 Sebastien Pouliot <[EMAIL PROTECTED]>
* font.c: Added more error checking when calling fontconfig API.
Modified: trunk/libgdiplus/src/ChangeLog
===================================================================
--- trunk/libgdiplus/src/ChangeLog 2006-05-30 18:59:11 UTC (rev 61277)
+++ trunk/libgdiplus/src/ChangeLog 2006-05-30 18:59:37 UTC (rev 61278)
@@ -1,3 +1,7 @@
+2006-05-30 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * font.c: Added more error checking when calling fontconfig API.
+
2006-05-29 Sebastien Pouliot <[EMAIL PROTECTED]>
* hatchbrush.c: Ensure we're freeing everything if no more memory can
Modified: trunk/libgdiplus/src/font.c
===================================================================
--- trunk/libgdiplus/src/font.c 2006-05-30 18:59:11 UTC (rev 61277)
+++ trunk/libgdiplus/src/font.c 2006-05-30 18:59:37 UTC (rev 61278)
@@ -238,67 +238,125 @@
return Ok;
}
-GpStatus
-GdipCreateFontFamilyFromName (GDIPCONST WCHAR *name, GpFontCollection
*font_collection, GpFontFamily **fontFamily)
+static GpStatus
+gdip_status_from_fontconfig (FcResult result)
{
- unsigned char *string;
- FcPattern **gpfam;
- FcChar8 *str;
- int i;
-
- if (!name || !fontFamily)
- return InvalidParameter;
+ switch (result) {
+ case FcResultMatch:
+ return Ok;
+ case FcResultNoMatch:
+ case FcResultTypeMismatch:
+ case FcResultNoId:
+ return FontFamilyNotFound;
+ default:
+ return GenericError;
+ }
+}
- string = (unsigned char*)ucs2_to_utf8 ((const gunichar2 *)name, -1);
+static GpStatus
+create_fontfamily_from_name (unsigned char* name, GpFontFamily **fontFamily)
+{
+ GpStatus status;
+ GpFontFamily *ff;
+ FcValue val;
+ FcResult rlt = FcResultMatch;
- if (!font_collection) {
- FcPattern *pat = FcPatternCreate ();
- FcResult rlt;
+ FcPattern *pat = FcPatternCreate ();
+ if (!pat)
+ return OutOfMemory;
- /* find the family we want */
- FcValue val;
-
- val.type = FcTypeString;
- val.u.s = string;
- FcPatternAdd (pat, FC_FAMILY, val, TRUE);
+ /* find the family we want */
+ val.type = FcTypeString;
+ val.u.s = name;
+ if (!FcPatternAdd (pat, FC_FAMILY, val, TRUE)) {
+ FcPatternDestroy (pat);
+ return GenericError;
+ }
- FcConfigSubstitute (0, pat, FcMatchPattern);
- FcDefaultSubstitute (pat);
+ if (!FcConfigSubstitute (0, pat, FcMatchPattern)) {
+ FcPatternDestroy (pat);
+ return GenericError;
+ }
+
+ FcDefaultSubstitute (pat);
- gdip_createFontFamily (fontFamily);
- (*fontFamily)->pattern = FcFontMatch (0, pat, &rlt);
- (*fontFamily)->allocated = TRUE;
- if ((*fontFamily)->pattern == NULL) {
- (*fontFamily)->pattern = pat;
+ gdip_createFontFamily (&ff);
+ if (!ff) {
+ FcPatternDestroy (pat);
+ return OutOfMemory;
+ }
+
+ ff->pattern = FcFontMatch (0, pat, &rlt);
+ status = gdip_status_from_fontconfig (rlt);
+ if (status == Ok) {
+ ff->allocated = TRUE;
+ if (ff->pattern == NULL) {
+ ff->pattern = pat;
} else {
- FcPatternDestroy (pat);
+ FcPatternDestroy (pat);
}
- GdipFree (string);
-
- return Ok;
+ *fontFamily = ff;
+ } else {
+ FcPatternDestroy (pat);
+ GdipDeleteFontFamily (ff);
+ *fontFamily = NULL;
}
- gpfam = font_collection->fontset->fonts;
+ return status;
+}
+
+static GpStatus
+create_fontfamily_from_collection (unsigned char* name, GpFontCollection
*font_collection, GpFontFamily **fontFamily)
+{
+ /* note: fontset can be NULL when we supply an empty private collection
*/
+ if (font_collection->fontset) {
+ int i;
+ FcChar8 *str;
+ FcPattern **gpfam = font_collection->fontset->fonts;
- for (i=0; i < font_collection->fontset->nfont; gpfam++, i++){
- FcPatternGetString (*gpfam, FC_FAMILY, 0, &str);
+ for (i=0; i < font_collection->fontset->nfont; gpfam++, i++) {
+ FcResult rlt = FcPatternGetString (*gpfam, FC_FAMILY,
0, &str);
+ GpStatus status = gdip_status_from_fontconfig (rlt);
+ if (status != Ok)
+ return status;
- if (strcmp ((char *)string, (const char *)str)==0) {
- gdip_createFontFamily (fontFamily);
- (*fontFamily)->pattern = *gpfam;
- (*fontFamily)->allocated = FALSE;
- GdipFree (string);
- return Ok;
+ if (strcmp ((char *)name, (const char *)str) == 0) {
+ gdip_createFontFamily (fontFamily);
+ (*fontFamily)->pattern = *gpfam;
+ (*fontFamily)->allocated = FALSE;
+ return Ok;
+ }
}
}
+ return FontFamilyNotFound;
+}
+
+GpStatus
+GdipCreateFontFamilyFromName (GDIPCONST WCHAR *name, GpFontCollection
*font_collection, GpFontFamily **fontFamily)
+{
+ GpStatus status;
+ unsigned char *string;
+
+ if (!name || !fontFamily)
+ return InvalidParameter;
+
+ string = (unsigned char*)ucs2_to_utf8 ((const gunichar2 *)name, -1);
+
+ if (font_collection) {
+ status = create_fontfamily_from_collection (string,
font_collection, fontFamily);
+ } else {
+ status = create_fontfamily_from_name (string, fontFamily);
+ }
+
GdipFree (string);
- return FontFamilyNotFound;
+ return status;
}
GpStatus
GdipGetFamilyName (GDIPCONST GpFontFamily *family, WCHAR name[LF_FACESIZE],
int language)
-{
+{
+ GpStatus status;
FcChar8 *fc_str;
FcResult r;
@@ -306,6 +364,9 @@
return InvalidParameter;
r = FcPatternGetString (family->pattern, FC_FAMILY, 0, &fc_str);
+ status = gdip_status_from_fontconfig (r);
+ if (status != Ok)
+ return status;
utf8_to_ucs2((const gchar *)fc_str, (gunichar2 *)name, LF_FACESIZE);
return Ok;
@@ -574,6 +635,7 @@
GpStatus
GdipCreateFont (GDIPCONST GpFontFamily* family, float emSize, GpFontStyle
style, Unit unit, GpFont **font)
{
+ GpStatus status;
FcChar8* str;
FcResult r;
GpFont *result;
@@ -582,10 +644,13 @@
float sizeInPixels;
cairo_font_face_t* cairofnt;
- if (!family || !font)
+ if (!family || !font || (unit == UnitDisplay))
return InvalidParameter;
r = FcPatternGetString (family->pattern, FC_FAMILY, 0, &str);
+ status = gdip_status_from_fontconfig (r);
+ if (status != Ok)
+ return status;
gdip_unit_conversion (unit, UnitPixel, gdip_get_display_dpi(),
gtMemoryBitmap, emSize, &sizeInPixels);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches