Commits

tabe  committed 905a64e

modified gdPangoSetPangoFontDescriptionFromFile()'s signature; error code as its last argument.

  • Participants
  • Parent commits 1617ebe

Comments (0)

Files changed (3)

  *
  * @param *context Context
  * @param *fontlist path to ttf file
- * @return A null char* on success, or an error string on failure
+ * @param *error output of error code on failure; simply ignored if error = NULL
+ * @return GD_SUCCESS on success, otherwise GD_FAILURE.
  */
-char *gdPangoSetPangoFontDescriptionFromFile(gdPangoContext *context, const char
-		*fontlist, double ptsize)
+int gdPangoSetPangoFontDescriptionFromFile(gdPangoContext *context, const char
+		*fontlist, double ptsize, int *error)
 {
 	FcPattern *fcPattern;
 	FcBlanks *fcBlanks;
 	FcResult fcResult;
 	int numFonts;
 	char *font_desc;
-	char *r = (char *)NULL;
+	int r;
 
 	fcBlanks = FcBlanksCreate();
 	fcPattern = FcFreeTypeQuery(fontlist, 0, fcBlanks, &numFonts);
 	if (!fcPattern) {
-		r = "font not found";
+		if (error) *error = GD_PANGO_ERROR_FC_FT;
+		r = GD_FAILURE;
 		goto fail0;
 	}
 	fcResult = FcPatternGet(fcPattern, FC_FAMILY, 0, &fcFamilyName);
 	if (fcResult != FcResultMatch) {
-		r = "could not get font family";
+		if (error) *error = GD_PANGO_ERROR_FC_PAT;
+		r = GD_FAILURE;
 		goto fail1;
 	}
 
 	context->font_desc = pango_font_description_from_string(font_desc);
 	g_free(font_desc);
 	gdPangoSetDpi(context, ptsize, ptsize);
+	r = GD_SUCCESS;
  fail1:
 	FcPatternDestroy(fcPattern);
  fail0:
 		double ptsize, double angle, int x, int y, char *string)
 {
 	int w, h;
-	char *r;
+	int r;
 	gdPangoContext *context;
 	gdPangoColors default_colors;
 	PangoContext *pangocontext;
 	angle *= 180 / G_PI;
 
 	context = gdPangoCreateContext();
-	r = gdPangoSetPangoFontDescriptionFromFile(context, fontlist, ptsize);
-	if (r) {
+	r = gdPangoSetPangoFontDescriptionFromFile(context, fontlist, ptsize, NULL);
+	if (r != GD_SUCCESS) {
 		gdPangoFreeContext(context);
-		return r;
+		return "font description not found";
 	}
 	gdPangoSetDefaultColor(context, &default_colors);
 	gdPangoSetMarkup(context, string, -1);
 		pc.blue >> 8, \
 		0)
 
+enum {
+	GD_PANGO_ERROR_FC_FT,
+	GD_PANGO_ERROR_FC_PAT,
+};
+
 /**
  * Defines a colors set. The foreground and background can be
  * defined using a integer value returned by gdTrueColor(r,g,b).
 extern  void gdPangoSetBaseDirection(
 	gdPangoContext *context, PangoDirection pango_dir);
 
-extern char *gdPangoSetPangoFontDescriptionFromFile(
-	gdPangoContext *context, const char *fontlist, double ptsize);
+extern int gdPangoSetPangoFontDescriptionFromFile(
+	gdPangoContext *context, const char *fontlist, double ptsize, int *error);
 
 #ifdef __FT2_BUILD_UNIX_H__
 

File tests/pango/units.c

 /* 
- * NOTE: prefer "gdtest.h" to <assert.h>, so
+ * NOTE: prefer "gdtest.h" to <assert.h>, and
  * fix it as soon as possible.
  */
 #include <assert.h>
 		"/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf",
 		NULL,
 	};
-	int i;
-	char *r;
+	int i, r, error;
 	context = gdPangoCreateContext();
 	for (i=0; paths[i]; i++) {
-		r = gdPangoSetPangoFontDescriptionFromFile(context, paths[i], 12);
-		if (r == NULL) {
+		r = gdPangoSetPangoFontDescriptionFromFile(context, paths[i], 12, NULL);
+		if (r == GD_SUCCESS) {
 			gdTestAssert(context->font_desc);
 		}
 	}
-	r = gdPangoSetPangoFontDescriptionFromFile(context, "you have no file of such a name", 10);
-	gdTestAssert(strcmp(r, "font not found") == 0);
+	r = gdPangoSetPangoFontDescriptionFromFile(context, "you have no file of such a name", 10, &error);
+	gdTestAssert(r == GD_FAILURE && error == GD_PANGO_ERROR_FC_FT);
 	gdPangoFreeContext(context);
 }