gdc.cpp File Reference

#include "gdc.h"
#include <string.h>

Go to the source code of this file.

Defines

#define GDC_INCL
#define GDC_LIB

Functions

void load_font_conversions ()
short cnt_nl (char *nstr, int *len)
void GDCImageStringNL (gdImagePtr im, struct GDC_FONT_T *f, int x, int y, char *str, int clr, GDC_justify_t justify)
void GDC_destroy_image (void *im)
void out_err (int GIFWIDTH, int GIFHEIGHT, FILE *fptr, unsigned long BGColor, unsigned long LineColor, char *err_str)

Variables

GDC_FONT_T GDC_fontc [GDC_numfonts]


Define Documentation

#define GDC_INCL

Definition at line 3 of file gdc.cpp.

#define GDC_LIB

Definition at line 4 of file gdc.cpp.


Function Documentation

short cnt_nl ( char *  nstr,
int *  len 
)

Definition at line 38 of file gdc.cpp.

References MAX.

Referenced by GDCImageStringNL(), out_graph(), and pie_gif().

00040 {
00041         short   c           = 1;
00042         short   max_seg_len = 0;
00043         short   tmplen      = 0;
00044 
00045         if( !nstr )
00046                 {
00047                 if( len )
00048                         *len = 0;
00049                 return 0;
00050                 }
00051 
00052         while( *nstr )
00053                 {
00054                 if( *nstr == '\n' )
00055                         {
00056                         ++c;
00057                         max_seg_len = MAX( tmplen, max_seg_len );
00058                         tmplen = 0;
00059                         }
00060                 else
00061                         ++tmplen;
00062                 ++nstr;
00063                 }
00064 
00065         if( len )
00066                 *len = MAX( tmplen, max_seg_len );              /* don't forget last seg */
00067         return c;
00068 }

void GDC_destroy_image ( void *  im  ) 

Definition at line 128 of file gdc.cpp.

References gdImageDestroy().

00129 {
00130         if( im )
00131                 gdImageDestroy( (gdImagePtr)im );
00132 }

void GDCImageStringNL ( gdImagePtr  im,
struct GDC_FONT_T *  f,
int  x,
int  y,
char *  str,
int  clr,
GDC_justify_t  justify 
)

Definition at line 74 of file gdc.cpp.

References cnt_nl(), and gdImageString().

Referenced by pie_gif().

00081 {
00082         int             i;
00083         int             len;
00084         int     max_len;
00085         short   strs_num = cnt_nl( str, &max_len );
00086 
00087 #ifdef WIN32
00088         unsigned char    sub_str[1000];
00089 #else
00090         unsigned char    sub_str[max_len+1];
00091 #endif
00092         len      = -1;
00093         strs_num = -1;
00094         i = -1;
00095         do
00096                 {
00097                 ++i;
00098                 ++len;
00099                 sub_str[len] = *(str+i);
00100                 if( *(str+i) == '\n' ||
00101                         *(str+i) == '\0' )
00102                         {
00103                         int     xpos;
00104 
00105                         sub_str[len] = '\0';
00106                         ++strs_num;
00107                         switch( justify )
00108                           {
00109                           case GDC_JUSTIFY_LEFT:        xpos = x;                                        break;
00110                           case GDC_JUSTIFY_RIGHT:       xpos = x+f->w*(max_len-len); break;
00111                           case GDC_JUSTIFY_CENTER:
00112                           default:                                      xpos = x+f->w*(max_len-len)/2;
00113                           }
00114                         gdImageString( im,
00115                                                    f->f,
00116                                                    xpos,
00117                                                    y + (f->h-1)*strs_num,
00118                                                    sub_str,
00119                                                    clr );
00120                         len = -1;
00121                         }
00122                 }
00123         while( *(str+i) );
00124 }

void load_font_conversions (  ) 

Definition at line 24 of file gdc.cpp.

References GDC_fontc, GDC_GIANT, GDC_LARGE, GDC_MEDBOLD, GDC_pad, GDC_SMALL, GDC_TINY, gdFontGiant, gdFontLarge, gdFontMediumBold, gdFontSmall, and gdFontTiny.

Referenced by out_graph(), and pie_gif().

void out_err ( int  GIFWIDTH,
int  GIFHEIGHT,
FILE *  fptr,
unsigned long  BGColor,
unsigned long  LineColor,
char *  err_str 
)

Definition at line 136 of file gdc.cpp.

References GDC_EXPOSE_IMAGE, GDC_fontc, GDC_generate_gif, GDC_hold_img, GDC_image, GDC_MEDBOLD, GDC_REUSE_IMAGE, gdFontMediumBold, gdImageColorAllocate(), gdImageCreate(), gdImageDestroy(), gdImageGif(), gdImageString(), and l2gdcal.

Referenced by out_graph().

00142 {
00143 
00144         gdImagePtr      im;
00145         int                     lineclr;
00146         int                     bgclr;
00147 
00148 
00149         if( (GDC_hold_img & GDC_REUSE_IMAGE) &&
00150                 GDC_image != (void*)NULL )
00151                 im = (gdImage *) GDC_image;
00152         else
00153                 im = gdImageCreate( GIFWIDTH, GIFHEIGHT );
00154 
00155         bgclr    = gdImageColorAllocate( im, l2gdcal(BGColor) );
00156         lineclr  = gdImageColorAllocate( im, l2gdcal(LineColor) );
00157 
00158         gdImageString( im,
00159                                    gdFontMediumBold,
00160                                    GIFWIDTH/2 - GDC_fontc[GDC_MEDBOLD].w*strlen((const char *)err_str)/2,
00161                                    GIFHEIGHT/3,
00162                                    (unsigned char *) err_str,
00163                                    lineclr );
00164 
00165         /* usually GDC_generate_gif is used in conjunction with hard or hold options */
00166         if( GDC_generate_gif )
00167                 {
00168                 fflush(fptr);                   // clear anything buffered 
00169                 gdImageGif(im, fptr);
00170                 }
00171 
00172         if( GDC_hold_img & GDC_EXPOSE_IMAGE )
00173                 GDC_image = (void*)im;
00174         else
00175                 gdImageDestroy(im);
00176         return;
00177 }


Variable Documentation

struct GDC_FONT_T GDC_fontc[GDC_numfonts]

Initial value:

 { {(gdFontPtr)NULL, 8,  5},
        {(gdFontPtr)NULL, 8,  5},
        {(gdFontPtr)NULL, 12, 6},
        {(gdFontPtr)NULL, 13, 7},
        {(gdFontPtr)NULL, 16, 8},
        {(gdFontPtr)NULL, 15, 9} }

Definition at line 11 of file gdc.cpp.

Referenced by load_font_conversions(), out_err(), out_graph(), and pie_gif().


Generated on Sat Dec 15 00:01:27 2007 for BulmaGes by  doxygen 1.5.1