Home  |  Linux  | Mysql  | PHP  | XML
From:Takeshi Abe Date:Sat Jun 21 09:11:48 2008
Subject:cvs: gd /gd-pango gd_pango.c gd_pango.h /gd-pango/examples rotated.c simple.c
tabe		Sat Jun 21 15:11:48 2008 UTC

  Modified files:              
    /gd/gd-pango	gd_pango.c gd_pango.h 
    /gd/gd-pango/examples	rotated.c simple.c 
  Log:
  - export gdPangoSetPangoFontDescriptionFromFile()
  - elaborate messages on error
  - some cosmetic fixes
  
http://cvs.php.net/viewvc.cgi/gd/gd-pango/gd_pango.c?r1=1.5&r2=1.6&diff_format=u
Index: gd/gd-pango/gd_pango.c
diff -u gd/gd-pango/gd_pango.c:1.5 gd/gd-pango/gd_pango.c:1.6
--- gd/gd-pango/gd_pango.c:1.5	Wed Jun 18 16:31:42 2008
+++ gd/gd-pango/gd_pango.c	Sat Jun 21 15:11:48 2008
@@ -15,7 +15,7 @@
   | Authors: Pierre-A. Joye <pierre@php.net>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: gd_pango.c,v 1.5 2008/06/18 16:31:42 tabe Exp $ */
+/* $Id: gd_pango.c,v 1.6 2008/06/21 15:11:48 tabe Exp $ */
 /**
  * @file
  * @brief Pango support for GD
@@ -24,7 +24,7 @@
  *
  * @author Pierre-Alain Joye
  * @date   2006/12/19
- * $Id: gd_pango.c,v 1.5 2008/06/18 16:31:42 tabe Exp $
+ * $Id: gd_pango.c,v 1.6 2008/06/21 15:11:48 tabe Exp $
  */
 /**
  * \mainpage
@@ -460,7 +460,7 @@
  *
  * @return always GD_SUCCESS.
 */
-int gdPangoInit() {
+int gdPangoInit(void) {
 	g_type_init();
 	GD_PANGO_IS_INITIALIZED = 1;
 	return GD_SUCCESS;
@@ -472,7 +472,7 @@
  *
  * @return positive if it was initialized, otherwise zero.
  */
-int gdPangoIsInitialized()
+int gdPangoIsInitialized(void)
 {
 	return GD_PANGO_IS_INITIALIZED;
 }
@@ -482,7 +482,7 @@
  *
  * @return A pointer to the context as a gdPangoContext*.
  */
-gdPangoContext* gdPangoCreateContext()
+gdPangoContext* gdPangoCreateContext(void)
 {
 	gdPangoContext *context = g_malloc(sizeof(gdPangoContext));
 	G_CONST_RETURN char *charset;
@@ -693,7 +693,7 @@
  * Define the default foreground, background and alpha component.
  *
  * @param *context	gdPangoContext context
- * @param *colors		a gdPangoColors ptr, defines fg, bgd or alpha default
+ * @param *colors		a gdPangoColors ptr, defines fg, bg or alpha default
  */
 void gdPangoSetDefaultColor(gdPangoContext *context,
 	const gdPangoColors  *colors)
@@ -791,28 +791,44 @@
 }
 
 /**
- * Set font description from a ttf file
+ * Set font description from a ttf file.
  *
  * @param *context Context
  * @param *fontlist path to ttf file
+ * @return A null char* on success, or an error string on failure
  */
-void gdPangoSetPangoFontDescriptionFromFile(gdPangoContext *context, char
+char *gdPangoSetPangoFontDescriptionFromFile(gdPangoContext *context, const char
 		*fontlist, double ptsize)
 {
 	FcPattern *fcPattern;
 	FcBlanks *fcBlanks;
 	FcValue fcFamilyName;
+	FcResult fcResult;
 	int numFonts;
 	char *font_desc;
+	char *r = (char *)NULL;
 
 	fcBlanks = FcBlanksCreate();
 	fcPattern = FcFreeTypeQuery(fontlist, 0, fcBlanks, &numFonts);
-	FcPatternGet(fcPattern, FC_FAMILY, 0, &fcFamilyName);
+	if (!fcPattern) {
+		r = "font not found";
+		goto fail0;
+	}
+	fcResult = FcPatternGet(fcPattern, FC_FAMILY, 0, &fcFamilyName);
+	if (fcResult != FcResultMatch) {
+		r = "could not get font family";
+		goto fail1;
+	}
 
 	font_desc = g_strdup_printf("%s %d", fcFamilyName.u.s, (int) ptsize);
 	context->font_desc = pango_font_description_from_string(font_desc);
 	g_free(font_desc);
 	gdPangoSetDpi(context, ptsize, ptsize);
+ fail1:
+	FcPatternDestroy(fcPattern);
+ fail0:
+	FcBlanksDestroy(fcBlanks);
+	return r;
 }
 
 PangoFontMap* gdPangoGetPangoFontMap(gdPangoContext *context)
@@ -869,6 +885,7 @@
 		double ptsize, double angle, int x, int y, char *string)
 {
 	int w, h;
+	char *r;
 	gdPangoContext *context;
 	gdPangoColors default_colors;
 	PangoContext *pangocontext;
@@ -883,7 +900,11 @@
 	angle *= 180 / G_PI;
 
 	context = gdPangoCreateContext();
-	gdPangoSetPangoFontDescriptionFromFile(context, fontlist, ptsize);
+	r = gdPangoSetPangoFontDescriptionFromFile(context, fontlist, ptsize);
+	if (r) {
+		gdPangoFreeContext(context);
+		return r;
+	}
 	gdPangoSetDefaultColor(context, &default_colors);
 	gdPangoSetMarkup(context, string, -1);
 	pangocontext = gdPangoGetPangoContext(context);
http://cvs.php.net/viewvc.cgi/gd/gd-pango/gd_pango.h?r1=1.6&r2=1.7&diff_format=u
Index: gd/gd-pango/gd_pango.h
diff -u gd/gd-pango/gd_pango.h:1.6 gd/gd-pango/gd_pango.h:1.7
--- gd/gd-pango/gd_pango.h:1.6	Wed Jun 18 16:31:42 2008
+++ gd/gd-pango/gd_pango.h	Sat Jun 21 15:11:48 2008
@@ -15,14 +15,14 @@
   | Authors: Pierre-A. Joye <pierre@php.net>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: gd_pango.h,v 1.6 2008/06/18 16:31:42 tabe Exp $ */
+/* $Id: gd_pango.h,v 1.7 2008/06/21 15:11:48 tabe Exp $ */
 /**
  * @file
  * @brief Header file of gd-pango
  *
  * @author Pierre-Alain Joye
  * @date   2006/12/19
- * $Id: gd_pango.h,v 1.6 2008/06/18 16:31:42 tabe Exp $
+ * $Id: gd_pango.h,v 1.7 2008/06/21 15:11:48 tabe Exp $
  */
 
 #ifndef GD_PANGO_H
@@ -78,9 +78,9 @@
 	double angle;
 } gdPangoContext;
 
-extern int gdPangoInit();
-extern int gdPangoIsInitialized();
-extern gdPangoContext* gdPangoCreateContext();
+extern int gdPangoInit(void);
+extern int gdPangoIsInitialized(void);
+extern gdPangoContext* gdPangoCreateContext(void);
 extern void gdPangoFreeContext(gdPangoContext *context);
 
 extern gdImagePtr gdPangoCreateSurfaceDraw(
@@ -122,6 +122,8 @@
 extern  void gdPangoSetBaseDirection(
 	gdPangoContext *context, PangoDirection pango_dir);
 
+extern char *gdPangoSetPangoFontDescriptionFromFile(
+	gdPangoContext *context, const char *fontlist, double ptsize);
 
 #ifdef __FT2_BUILD_UNIX_H__
 
http://cvs.php.net/viewvc.cgi/gd/gd-pango/examples/rotated.c?r1=1.3&r2=1.4&diff_format=u
Index: gd/gd-pango/examples/rotated.c
diff -u gd/gd-pango/examples/rotated.c:1.3 gd/gd-pango/examples/rotated.c:1.4
--- gd/gd-pango/examples/rotated.c:1.3	Wed Jun 18 16:34:30 2008
+++ gd/gd-pango/examples/rotated.c	Sat Jun 21 15:11:48 2008
@@ -15,7 +15,7 @@
   | Authors: Pierre-A. Joye <pierre@php.net>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: rotated.c,v 1.3 2008/06/18 16:34:30 tabe Exp $ */
+/* $Id: rotated.c,v 1.4 2008/06/21 15:11:48 tabe Exp $ */
 
 #include <pango/pango.h>
 #include <pango/pangoft2.h>
@@ -35,8 +35,16 @@
 
 	fseek(file, 0, SEEK_END);
 	file_size = ftell(file);
+	if (file_size == -1) {
+		printf("Cannot tell file <%s>\n", filename);
+		exit(2);
+	}
 	fseek(file, 0, SEEK_SET);
 	text = (char *)malloc(file_size + 1);
+	if (!text) {
+		printf("Cannot allocate\n");
+		exit(3);
+	}
 	fread(text, file_size, 1, file);
 	text[file_size] = '\0';
 
http://cvs.php.net/viewvc.cgi/gd/gd-pango/examples/simple.c?r1=1.3&r2=1.4&diff_format=u
Index: gd/gd-pango/examples/simple.c
diff -u gd/gd-pango/examples/simple.c:1.3 gd/gd-pango/examples/simple.c:1.4
--- gd/gd-pango/examples/simple.c:1.3	Wed Jun 18 16:34:30 2008
+++ gd/gd-pango/examples/simple.c	Sat Jun 21 15:11:48 2008
@@ -15,7 +15,7 @@
   | Authors: Pierre-A. Joye <pierre@php.net>                             |
   +----------------------------------------------------------------------+
 */
-/* $Id: simple.c,v 1.3 2008/06/18 16:34:30 tabe Exp $ */
+/* $Id: simple.c,v 1.4 2008/06/21 15:11:48 tabe Exp $ */
 
 #include <pango/pango.h>
 #include <pango/pangoft2.h>
@@ -35,8 +35,16 @@
 
 	fseek(file, 0, SEEK_END);
 	file_size = ftell(file);
+	if (file_size == -1) {
+		printf("Cannot tell file <%s>\n", filename);
+		exit(2);
+	}
 	fseek(file, 0, SEEK_SET);
 	text = (char *)malloc(file_size + 1);
+	if (!text) {
+		printf("Cannot allocate\n");
+		exit(3);
+	}
 	fread(text, file_size, 1, file);
 	text[file_size] = '\0';
 


Navigate in group php.gd.cvs at sever news.php.net
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants