From 1dd9dcec816abd63ccb95a0afdc8d836b4cc35a4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Sat, 1 Aug 2009 20:23:06 +0000 Subject: [PATCH] Partly applied advice of bug #1659784. --- grepday.c | 90 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/grepday.c b/grepday.c index 937ec3a..c880089 100644 --- a/grepday.c +++ b/grepday.c @@ -45,35 +45,39 @@ char s[15]; #include #define SARGgdImageStringFT I18NgdImageStringFT -char * I18NgdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, +char * I18NgdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, double ptsize, double angle, int x, int y, char *string) { - iconv_t localtoutf; - char *sstring, *str, *sstr, *retval; - size_t slen, sslen; - - slen = strlen(string) + 1; // We must include string termination character - sslen = slen * 2; // We assume that UTF8 maximum 2 times large than local - sstring = (char *)malloc(sslen); + iconv_t localtoutf; + char *sstring, *str, *sstr, *retval; + size_t slen, sslen; + + slen = strlen(string) + 1; // We must include string termination character + sslen = slen * 2; // We assume that UTF8 maximum 2 times large than local + sstring = (char *)malloc(sslen); + if (!sstring) { + fprintf(stderr, "SARG: %s (%ld):\n",text[59],sslen); + exit(1); + } - str = (char *) string; - sstr = (char *) sstring; + str = (char *) string; + sstr = (char *) sstring; - localtoutf = iconv_open ("UTF-8", CharSet); - iconv (localtoutf, (ICONV_CONST char **)&str, &slen, &sstr, &sslen); - iconv_close (localtoutf); + localtoutf = iconv_open ("UTF-8", CharSet); + iconv (localtoutf, (ICONV_CONST char **)&str, &slen, &sstr, &sslen); + iconv_close (localtoutf); - retval = gdImageStringFTEx (im, brect, fg, fontlist, ptsize, angle, x, y, sstring, gdFTEX_Unicode); - free(sstring); + retval = gdImageStringFTEx (im, brect, fg, fontlist, ptsize, angle, x, y, sstring, gdFTEX_Unicode); + free(sstring); - return retval; + return retval; } #else #define SARGgdImageStringFT gdImageStringFT #endif void bar(long long int n) -{ +{ #ifdef HAVE_GD gdPoint points[4]; int brect[8]; @@ -181,7 +185,7 @@ void bar(long long int n) blue = gdImageColorAllocate(im, 0, 0, 255); white = gdImageColorAllocate(im, 255, 255, 255); - dimgray = gdImageColorAllocate(im, 105, 105, 105); + dimgray = gdImageColorAllocate(im, 105, 105, 105); goldenrod = gdImageColorAllocate(im, 234, 234, 174); goldenrod2 = gdImageColorAllocate(im, 207, 181, 59); @@ -206,14 +210,14 @@ void bar(long long int n) points[3].y = val-5; gdImageFilledPolygon(im, points, 4, color1); - gdImageLine(im, x1+8, val-2, x1+8, val-10, dimgray); + gdImageLine(im, x1+8, val-2, x1+8, val-10, dimgray); gdImageFilledRectangle(im, x1-2, val-20, x1+18, val-10, goldenrod); gdImageRectangle(im, x1-2, val-20, x1+18, val-10, goldenrod2); snprintf(v,6,"%s",fixnum(num,0)); SARGgdImageStringFT(im,&brect[0],black,font1,6,0.0,x1-1,val-12,v); - + points[0].x = x1+17; points[0].y = val-5; points[1].x = x1+11; @@ -255,13 +259,13 @@ void greport_day(const char *user) im = gdImageCreate(720, 480); - lavender = gdImageColorAllocate(im, 230, 230, 250); - white = gdImageColorAllocate(im, 255, 255, 255); - gray = gdImageColorAllocate(im, 192, 192, 192); - silver = gdImageColorAllocate(im, 211, 211, 211); - black = gdImageColorAllocate(im, 0, 0, 0); - blue = gdImageColorAllocate(im, 35, 35, 227); - dimgray = gdImageColorAllocate(im, 105, 105, 105); + lavender = gdImageColorAllocate(im, 230, 230, 250); + white = gdImageColorAllocate(im, 255, 255, 255); + gray = gdImageColorAllocate(im, 192, 192, 192); + silver = gdImageColorAllocate(im, 211, 211, 211); + black = gdImageColorAllocate(im, 0, 0, 0); + blue = gdImageColorAllocate(im, 35, 35, 227); + dimgray = gdImageColorAllocate(im, 105, 105, 105); darkblue = gdImageColorAllocate(im, 0, 0, 139); gdImageRectangle(im, 0, 0, 719, 479, dimgray); @@ -286,26 +290,26 @@ void greport_day(const char *user) points[3].x = 700; points[3].y = 420; gdImageFilledPolygon(im, points, 4, gray); - - gdImageLine(im, 50, 65, 50, 430, black); - gdImageLine(im, 45, 425, 690, 425, black); - gdImageLine(im, 50, 425, 60, 420, black); - gdImageLine(im, 60, 420, 60, 60, black); - gdImageLine(im, 700, 60, 700, 420, black); - gdImageLine(im, 690, 425, 700, 420, black); + + gdImageLine(im, 50, 65, 50, 430, black); + gdImageLine(im, 45, 425, 690, 425, black); + gdImageLine(im, 50, 425, 60, 420, black); + gdImageLine(im, 60, 420, 60, 60, black); + gdImageLine(im, 700, 60, 700, 420, black); + gdImageLine(im, 690, 425, 700, 420, black); for(x=415; x>=65; x=x-10) { - gdImageLine(im, 50, x, 60, x-5, dimgray); - gdImageLine(im, 47, x, 50, x, dimgray); + gdImageLine(im, 50, x, 60, x-5, dimgray); + gdImageLine(im, 47, x, 50, x, dimgray); } for(x=60; x<=420; x=x+10) - gdImageLine(im, 60, x, 700, x, dimgray); - - gdImageLine(im, 60, 420, 700, 420, black); + gdImageLine(im, 60, x, 700, x, dimgray); + + gdImageLine(im, 60, 420, 700, 420, black); for(x=70; x<=680; x=x+20) - gdImageLine(im, x, 425, x, 428, dimgray); + gdImageLine(im, x, 425, x, 428, dimgray); y=65; for(x=1; x<=31; x++) { @@ -370,7 +374,7 @@ void greport_day(const char *user) SARGgdImageStringFT(im,&brect[0],dimgray,font1,7,0.0,23, 68," 5G"); SARGgdImageStringFT(im,&brect[0],black,font1,10,3.14/2,20,248,text[93]); SARGgdImageStringFT(im,&brect[0],black,font1,10,0.0,330,460,text[127]); - + if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",dirname,user)>=sizeof(graph)) { fprintf(stderr, "SARG: user name too long for: %s/%s/graph_day.png\n",dirname,user); exit(1); @@ -463,8 +467,8 @@ void greport_day(const char *user) fclose(fp_in); unlink(wdirname); unlink(tmp5); - -#endif + +#endif return; } -- 2.47.2