lib/gifLabel.c File Reference

#include "common.h"
#include "memgfx.h"
#include "gifLabel.h"

Include dependency graph for gifLabel.c:

Go to the source code of this file.

Functions

int gifLabelMaxWidth (char **labels, int labelCount)
static struct memGfxaltColorLabels (char **labels, int labelCount, int width)
boolean sameFileContents (char *n1, char *n2)
void gifLabelVerticalText (char *fileName, char **labels, int labelCount, int height)

Variables

static char const rcsid [] = "$Id: gifLabel.c,v 1.7 2005/06/06 20:20:10 galt Exp $"


Function Documentation

static struct memGfx* altColorLabels ( char **  labels,
int  labelCount,
int  width 
) [static, read]

Definition at line 29 of file gifLabel.c.

References memGfx::height, MG_BLACK, mgDrawBox(), mgFindColor(), mgFontLineHeight(), mgMediumFont(), mgNew(), and mgTextRight().

Referenced by gifLabelVerticalText().

00031 {
00032 struct memGfx *mg = NULL;
00033 Color c1,c2;
00034 MgFont *font = mgMediumFont();
00035 int lineHeight = mgFontLineHeight(font)-1;
00036 int height = lineHeight * labelCount, i;
00037 int y = 0;
00038 
00039 /* Allocate picture and set up colors. */
00040 mg = mgNew(width, height);
00041 c1 = mgFindColor(mg, 0xE0, 0xE0, 0xFF);
00042 c2 = mgFindColor(mg, 0xFF, 0xC8, 0xC8);
00043 
00044 /* Draw text. */
00045 for (i=labelCount-1; i >= 0; --i)
00046     {
00047     Color c = ((i&1) ? c2 : c1);
00048     mgDrawBox(mg, 0, y, width, lineHeight, c);
00049     mgTextRight(mg, 0+1, y+1, width-1, lineHeight, MG_BLACK, font, labels[i]);
00050     y += lineHeight;
00051     }
00052 
00053 return mg;
00054 }

Here is the call graph for this function:

Here is the caller graph for this function:

int gifLabelMaxWidth ( char **  labels,
int  labelCount 
)

Definition at line 9 of file gifLabel.c.

References mgFontStringWidth(), and mgMediumFont().

00012 {
00013 int width = 0, w, i;
00014 MgFont *font = mgMediumFont();
00015 for (i=0; i<labelCount; ++i)
00016     {
00017     char *label = labels[i];
00018     if (label != NULL)
00019         {
00020         w = mgFontStringWidth(font, labels[i]);
00021         if (w > width)
00022             width = w;
00023         }
00024     }
00025 width += 2;
00026 return width;
00027 }

Here is the call graph for this function:

void gifLabelVerticalText ( char *  fileName,
char **  labels,
int  labelCount,
int  height 
)

Definition at line 81 of file gifLabel.c.

References altColorLabels(), mgFree(), mgRotate90(), mgSaveGif(), safef(), and sameFileContents().

00085 {
00086 struct memGfx *straight = altColorLabels(labels, labelCount, height);
00087 struct memGfx *rotated = mgRotate90(straight);
00088 char tempName[512];
00089 safef(tempName, sizeof(tempName), "%s_trash", fileName);
00090 mgSaveGif(rotated, tempName);  /* note we cannot delete this later because of permissions */
00091 /* the savings here is in the user's own browser cache - not updated if no change */
00092 if (!sameFileContents(tempName,fileName))  
00093     mgSaveGif(rotated, fileName);
00094 mgFree(&straight);
00095 mgFree(&rotated);
00096 }

Here is the call graph for this function:

boolean sameFileContents ( char *  n1,
char *  n2 
)

Definition at line 57 of file gifLabel.c.

References FALSE, and TRUE.

Referenced by gifLabelVerticalText().

00059 {
00060 int r1 = 0, r2 = 0;
00061 char buf1[4096];
00062 char buf2[4096];
00063 FILE *f1 = NULL, *f2 = NULL;
00064 boolean result = TRUE;
00065 f1 = fopen(n1,"r"); if (f1 == NULL) { return FALSE; }
00066 f2 = fopen(n2,"r"); if (f2 == NULL) { fclose(f1); return FALSE; }
00067 while (TRUE)
00068     {
00069     r1 = fread(buf1, 1, sizeof(buf1), f1);
00070     r2 = fread(buf2, 1, sizeof(buf2), f2);
00071     if (r1 != r2) { result = FALSE; break; } /* diff file size */
00072     if (r1 == 0) { break; }  /* eof */
00073     if (memcmp(buf1,buf2,r1)!=0) { result = FALSE; break; } /* file contents differ */
00074     }
00075 fclose(f2);
00076 fclose(f1);
00077 return result;
00078 }

Here is the caller graph for this function:


Variable Documentation

char const rcsid[] = "$Id: gifLabel.c,v 1.7 2005/06/06 20:20:10 galt Exp $" [static]

Definition at line 7 of file gifLabel.c.


Generated on Tue Dec 25 19:52:26 2007 for blat by  doxygen 1.5.2