Commit d1506a1f authored by Jonas Smedegaard's avatar Jonas Smedegaard

Imported Upstream version 0.11.5

parents
CC=gcc
# gcc 2.7.1 or better is required
# CFLAGS=
# CFLAGS=-g -ansi -pedantic
# ----- build path -----
GDC_INCL=./
GDC_LD=./
GDC_LIB=libgdc.a
# ----- install locations -----
PREFIX_INC = /usr/local/include
PREFIX_LIB = /usr/local/lib
# INCLUDEDIRS=-I. -I/usr/include/freetype2 -I/usr/include/X11 -I/usr/X11R6/include/X11 -I/usr/local/include
# ----- lib gd -----
# GDChart requires the gd library - www.boutell.com/gd/
# gd 2.0.28 or better is required (GIF support has returned to libgd)
# if it's not installed in a standard location edit these lines for your installation
GD_INCL=/usr/local/include/
GD_LD=/usr/local/lib/
GD_LIB=libgd.so
# a static libgd is also available
# GD_LIB=libgd.a
# ----- lib png -----
# libgd requires libpng
# if it's not installed in a standard location edit these lines for your installation
# PNG_INCL = ../libpng-1.0.8
# PNG_LD = ../libpng-1.0.8
# ----- lib z -----
# libgd requires zlib
# if it's not installed in a standard location edit these lines for your installation
# ZLIB_INCL = ../zlib-1.1.3
# ZLIB_LD = ../zlib-1.1.3
# ----- lib jpeg -----
# libgd optionally uses libjpeg to produce JPEG images
# JPEG_INCL = ../libjpeg
# JPEG_LD = ../libjpeg
JPEG_DEF = -DHAVE_JPEG
JPEG_LK = -ljpeg
# libgd optionally uses libfreetype to use TTFs
# FT_LD = /usr/local/lib
FT_DEF = -DHAVE_LIBFREETYPE
FT_LK = -lfreetype
DEFS = $(FT_DEF) $(JPEG_DEF)
LIBS = $(FT_LK) $(JPEG_LK)
LIB_PATHS = -L$(GD_LD) -L$(GDC_LD)
# if not installed in standard paths (/lib, /usr/lib), or LD_LIBRARY_PATH
# LIB_PATHS = -L$(GD_LD) -L$(PNG_LD) -L$(ZLIB_LD) -L$(JPEG_LD)
# NOTE:
# libpng, libz, etc. are usually linked in as dynamic libs
# either use a link line similar to one of these, or set environment LD_LIBRARY_PATH
# these should likely be absolute paths, as resolved at runtime
# LIB_PATHS = $(LIB_PATHS) -R$(PNG_LD) -R$(ZLIB_LD)
# LIB_PATHS = $(LIB_PATHS) -Xlinker -rpath -Xlinker $(PNG_LD) -Xlinker -rpath -Xlinker $(ZLIB_LD)
all: libgdc.a gdc_samp1 gdc_samp2 gdc_pie_samp ft_samp
# --- compile the samples ---
gdc_pie_samp.o: $(GDC_INCL)gdc.h $(GDC_INCL)gdcpie.h gdc_pie_samp.c
$(CC) $(CFLAGS) -I$(GDC_INCL) $(DEFS) -c gdc_pie_samp.c
gdc_samp1.o: $(GDC_INCL)gdc.h $(GDC_INCL)gdchart.h gdc_samp1.c
$(CC) $(CFLAGS) -I$(GDC_INCL) $(DEFS) -c gdc_samp1.c
gdc_samp2.o: $(GDC_INCL)gdc.h $(GDC_INCL)gdchart.h gdc_samp2.c
$(CC) $(CFLAGS) -I$(GDC_INCL) $(DEFS) -c gdc_samp2.c
ft_samp.o: $(GDC_INCL)gdc.h $(GDC_INCL)gdchart.h ft_samp.c
$(CC) $(CFLAGS) -I$(GDC_INCL) $(DEFS) -c ft_samp.c
# --- link the samples ---
gdc_samp1: $(GDC_LD)libgdc.a gdc_samp1.o $(GD_LD)/$(GD_LIB) $(GDC_LD)/$(GDC_LIB)
$(CC) -o gdc_samp1 \
gdc_samp1.o \
$(LIB_PATHS) \
-lgdc -lgd -lz -lpng $(LIBS) -lm
gdc_samp2: $(GDC_LD)libgdc.a gdc_samp2.o $(GD_LD)/$(GD_LIB) $(GDC_LD)/$(GDC_LIB)
$(CC) -o gdc_samp2 \
gdc.o gdchart.o price_conv.o \
gdc_samp2.o \
$(LIB_PATHS) \
-lgdc -lgd -lz -lpng $(LIBS) -lm
gdc_pie_samp: $(GDC_LD)libgdc.a gdc_pie_samp.o $(GD_LD)/$(GD_LIB) $(GDC_LD)/$(GDC_LIB)
$(CC) -o gdc_pie_samp \
gdc.o gdc_pie.o price_conv.o \
gdc_pie_samp.o \
$(LIB_PATHS) \
-lgdc -lgd -lz -lpng $(LIBS) -lm
ft_samp: $(GDC_LD)libgdc.a ft_samp.o $(GD_LD)/$(GD_LIB) $(GDC_LD)/$(GDC_LIB)
$(CC) -o ft_samp \
gdc.o gdchart.o price_conv.o \
ft_samp.o \
$(LIB_PATHS) \
-lgdc -lgd -lz -lpng $(LIBS) -lm
# --- compile the lib ---
gdc.h: $(GD_INCL)gd.h $(GD_INCL)gdfonts.h $(GD_INCL)gdfontt.h $(GD_INCL)gdfontmb.h $(GD_INCL)gdfontg.h $(GD_INCL)gdfontl.h $(GDC_INCL)array_alloc.h
price_conv.o: price_conv.c
$(CC) $(CFLAGS) -c price_conv.c
gdc.o: gdc.c $(GDC_INCL)gdc.h
$(CC) $(CFLAGS) -I$(GD_INCL) -I$(GDC_INCL) $(DEFS) -c gdc.c
gdc_pie.o: $(GDC_INCL)gdc.h $(GDC_INCL)gdcpie.h gdc_pie.c
$(CC) $(CFLAGS) -I$(GD_INCL) -I$(GDC_INCL) $(DEFS) -c gdc_pie.c
gdchart.o: $(GDC_INCL)gdc.h $(GDC_INCL)gdchart.h gdchart.c
$(CC) $(CFLAGS) -I$(GD_INCL) -I$(GDC_INCL) $(DEFS) -c gdchart.c
array_alloc.o: array_alloc.c array_alloc.h
$(CC) $(CFLAGS) -c array_alloc.c
libgdc.a: price_conv.o gdc.o gdc_pie.o gdchart.o array_alloc.o
ar cr libgdc.a gdc.o gdchart.o gdc_pie.o price_conv.o array_alloc.o
ranlib libgdc.a
# --- supporting libraries ---
# should be compile & installed separately
# $(GD_LD)/$(GD_LIB):
# cd $(GD_LD) ; make -f Makefile $(GD_LIB)
# ----- install -----
install: gdc.h gdchart.h gdcpie.h libgdc.a
cp gdc.h gdchart.h gdcpie.h $(PREFIX_INC)/
cp libgdc.a $(PREFIX_LIB)/
# --- clean ---
clean:
rm -f *.o *.a gdc_samp1 gdc_samp2 gdc_pie_samp ft_samp
/* GDCHART 0.11.5dev 17 Dec 2004 */
/* Copyright Bruce Verderaime 1998-2004 */
GDChart 0.11.5 relies on the latest version of libgd ( gd 2.0.28 or higher available: www.boutell.com/gd/ ).
gd 2.0.28 in turn relies on libpng and zlib (and optionally libjpeg, and libfreetype).
If libgd 2.0.28 or higher isn't installed, do that first.
There's no configure script.
Makefile may need to be edited to change paths to libgd (It's set to libgd's defualt install path).
The makefile defaults to include jpeg and freetype, and assumes they are installed,
and libgd was built with those options as well.
Though dev, it is a stable release.
--
brv@fred.net
Note: GDChart is copyrighted code:
Permission has been granted to copy, distribute and modify GDChart in any context without fee, including a commercial
application, provided that this notice is present in user-accessible supporting documentation.
This does not affect your ownership of the derived work itself, and the intent is to assure proper credit for the authors of
GDChart, not to interfere with your productive use of GDChart. If you have questions, ask. "Derived works" includes all programs that
utilize the library. Credit must be given in user-accessible documentation.
This software is provided "AS IS." The copyright holders disclaim all warranties, either express or implied, including but
not limited to implied warranties of merchantability and fitness for a particular purpose, with respect to this code and
accompanying documentation.
Note: gd is copyrighted code:
COPYRIGHT STATEMENT FOLLOWS THIS LINE
Portions copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
2002 by Cold Spring Harbor Laboratory. Funded under Grant
P41-RR02188 by the National Institutes of Health.
Portions copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 by
Boutell.Com, Inc.
Portions relating to GD2 format copyright 1999, 2000, 2001, 2002
Philip Warner.
Portions relating to PNG copyright 1999, 2000, 2001, 2002 Greg
Roelofs.
Portions relating to gdttf.c copyright 1999, 2000, 2001, 2002 John
Ellson (ellson@lucent.com).
Portions relating to gdft.c copyright 2001, 2002 John Ellson
(ellson@lucent.com).
Portions relating to JPEG and to color quantization copyright 2000,
2001, 2002, Doug Becker and copyright (C) 1994, 1995, 1996, 1997,
1998, 1999, 2000, 2001, 2002, Thomas G. Lane. This software is
based in part on the work of the Independent JPEG Group. See the
file README-JPEG.TXT for more information.
Portions relating to WBMP copyright 2000, 2001, 2002 Maurice
Szmurlo and Johan Van den Brande.
Permission has been granted to copy, distribute and modify gd in
any context without fee, including a commercial application,
provided that this notice is present in user-accessible supporting
documentation.
This does not affect your ownership of the derived work itself, and
the intent is to assure proper credit for the authors of gd, not to
interfere with your productive use of gd. If you have questions,
ask. "Derived works" includes all programs that utilize the
library. Credit must be given in user-accessible documentation.
This software is provided "AS IS." The copyright holders disclaim
all warranties, either express or implied, including but not
limited to implied warranties of merchantability and fitness for a
particular purpose, with respect to this code and accompanying
documentation.
Although their code does not appear in gd, the authors wish to thank
David Koblas, David Rowley, and Hutchison Avenue Software Corporation
for their prior contributions.
END OF GD COPYRIGHT STATEMENT
/* GDCHART 0.11.2dev ARRAY_ALLOC.C Mar 2002 */
/* Copyright Bruce Verderaime 2002-2004 */
/* Contributed in part or whole by Don Fasen and Darren Kent */
#if !defined (__GNUC__) || defined (__STRICT_ANSI__)
#include <stdio.h>
#include "array_alloc.h"
/*F***************************************************************************
*
* Function Name: allocate_array_float
*
* Function Prototype: float ** allocate_array_float (int nr, int nc)
*
* Allocates memory for a two-dimensional array of floats
* referenced as arr[r][c]
*
***************************************************************************
*
* access array as arr[i1=0-nr][i2=0-nc] = *(&arr[0][0]+nr*i1+i2)
* row col makes fewest pointer array elements
* assuming Ncol>>Nrow
* Ex: NC=2
* _______ __________
* **arr |arr[0] |------>arr[0]-->|arr[0][0] |
* |_______| |__________|
* |arr[1] |----- |arr[0][1] |
* |_______| | |__________|
* | . | --------->|arr[1][0] |
* | . | |__________|
* |_______| |arr[1][1] |
* |arr[NR-1]
* | |
* pointer array data array
*
******************************************************************************
*
* Parameters :
*
* Name Type Use Description
* ---- ---- --- -----------
* nr int Input Number of rows
* nc int Input Number of columns
*
******************************************************************************
*
* Function Return: float** with allocated memory all set up as float[][].
*
******************************************************************************
*
* Author: Don Fasen
* Date : 12/18/98
* Modified: Darren Kent 20/03/2002
*
****************************************************************************F*/
float **
allocate_array_float( int nr, /* number of pointer array elements */
int nc ) /* larger number for min memory usage */
{
int i;
float **arr;
/* Try to allocate memory for the pointer array, 'nr' pointers-to-float: */
arr = (float**)malloc( nr * sizeof(float*) );
/* no test for success ala glib, i.e., if you're outa memory, ... */
#ifdef DBUG
if( arr == NULL )
{
perror( "Unable to malloc pointer array in allocate_array_float()\n" );
exit( 2 );
}
#endif
/* Now allocate memory for the data array, 'nr * nc' floats: */
arr[0] = (float*)malloc( nr * nc * sizeof(float) );
#ifdef DBUG
if( arr == NULL )
{
perror( "Unable to malloc data array in allocate_array_float()\n" );
exit( 2 );
}
#endif
/* fill in the array pointers to point to successive columns. */
/* Don't need to do the first (zeroth) one, because it was set up by the data malloc. */
/* Note that adding 1 to (float*)a.arr[0] adds sizeof(float*) automatically. */
for (i = 1; i < nr; i++)
arr[i] = arr[0] + i*nc;
return arr;
} /* End of FUNCTION allocate_array_float */
/***********************************************************************************
*
* Same Implementation for a Char array.
*
************************************************************************************/
char **
allocate_array_char( int nr,
int nc )
{
int i;
char **arr;
/* Try to allocate memory for the pointer array, 'nr' pointers-to-chars: */
arr = (char**)malloc( nr * sizeof(char*) );
/* no test for success ala glib, i.e., if you're outa memory, ... */
#ifdef DBUG
if( arr == NULL )
{
perror( "Unable to malloc pointer array in allocate_array_char()\n" );
exit( 2 );
}
#endif
/* Now allocate memory for the data array, 'nr * nc' char: */
arr[0] = (char*)malloc( nr * nc * sizeof(char) );
#ifdef DBUG
if( arr == NULL )
{
perror( "Unable to malloc data array in allocate_array_char()\n" );
exit( 2 );
}
#endif
/* fill in the array pointers to point to successive columns. */
/* Don't need to do the first (zeroth) one, because it was set up by the data malloc. */
/* Note that adding 1 to (char*)a.arr[0] adds sizeof(char*) automatically. */
for (i = 1; i < nr; i++)
arr[i] = arr[0] + i*nc;
return arr;
} /* End of FUNCTION allocate_array_char */
/***********************************************************************************
*
* Same Implementation for a Int array.
*
************************************************************************************/
int **
allocate_array_int( int nr,
int nc )
{
int i;
int **arr;
/* Try to allocate memory for the pointer array, 'nr' pointers-to-ints: */
arr = (int**)malloc( nr * sizeof(int*) );
/* no test for success ala glib, i.e., if you're outa memory, ... */
#ifdef DBUG
if( arr == NULL )
{
perror( "Unable to malloc pointer array in allocate_array_int()\n" );
exit( 2 );
}
#endif
/* Now allocate memory for the data array, 'nr * nc' int: */
arr[0] = (int*)malloc( nr * nc * sizeof(int) );
#ifdef DBUG
if( arr == NULL )
{
perror( "Unable to malloc data array in allocate_array_int()\n" );
exit( 2 );
}
#endif
/* fill in the array pointers to point to successive columns. */
/* Don't need to do the first (zeroth) one, because it was set up by the data malloc. */
/* Note that adding 1 to (int*)a.arr[0] adds sizeof(int*) automatically. */
for (i = 1; i < nr; i++)
arr[i] = arr[0] + i*nc;
return arr;
} /* End of FUNCTION allocate_array_int */
#endif /* !defined (__GNUC__) || defined (__STRICT_ANSI__) */
/* GDCHART 0.11.2dev ARRAY_ALLOC.H Mar 2002 */
/* Copyright Bruce Verderaime 2002-2004 */
/* Contributed in part or whole by Don Fasen and Darren Kent */
#ifndef _ARRAY_ALLOC_H
#define _ARRAY_ALLOC_H
/* ----- no dynamic auto array, need to mallocate space ----- */
#if !defined (__GNUC__) || defined (__STRICT_ANSI__)
#include <stdlib.h>
float **allocate_array_float( int nrs, int ncs );
char **allocate_array_char( int nrs, int ncs );
int **allocate_array_int( int nrs, int ncs );
#define CREATE_ARRAY1( arr, type, nels ) type *arr = (type*)malloc( (nels) * sizeof(type) )
/* array2 can't do ptr (*) types */
#define CREATE_ARRAY2( arr, type, nrs, ncs ) type **arr = allocate_array_##type( nrs, ncs )
#define FREE_ARRAY1( arr ) if( arr ) { free( (void*)arr ); arr = NULL; } else
#define FREE_ARRAY2( arr ) if( arr ) \
{ \
if( arr[0] ) \
free( (void*)arr[0] ); \
free( (void*)arr ); \
arr = NULL; \
} \
else
/* ----- avoid alloc, let the stack do the work ----- */
#else
#define CREATE_ARRAY1( arr, type, nels ) type arr[ nels ]
#define CREATE_ARRAY2( arr, type, nrs, ncs ) type arr[ nrs ][ ncs ]
#define FREE_ARRAY1( arr )
#define FREE_ARRAY2( arr )
#endif
#endif /*_ARRAY_ALLOC_H */
/* GDCHART 0.11.1b 3D Bar sample 17 June 2001 */
/* NOTE: fonts and locations specified are machine specific */
/* should be able to set font-search-path env GDFONTPATH */
/* see libgd documentation */
/* will default to builtin font, if specified TTF not found */
#include <stdio.h>
#include "gdc.h"
#include "gdchart.h"
#define NUM_SETS 1
#define NUM_POINTS 4
main()
{
float data [ NUM_SETS ][ NUM_POINTS ];
unsigned long extclr[ NUM_SETS ][ NUM_POINTS ];
char *lbls[] = { "angle - 45", "font - zirkle", "ptsz - 10", "Color - blue", "" };
get_data( data, 0, 500 );
get_individual_colors( extclr );
GDC_BGColor = 0xFFFFFF;
GDC_PlotColor = 0x4080FF;
GDC_ExtColor = &(extclr[0][0]); /* set color option */
GDC_title = "GDC_title\r\n(benjamingothic 12)";
GDC_title_font = "/usr/share/enlightenment/E-docs/benjamingothic.ttf";
GDC_title_ptsize = 12;
GDC_xtitle = "GDC_xtitle\r\n(x-files 12)";
GDC_xtitle_font = "/usr/share/enlightenment/E-docs/x-files.ttf";
GDC_xtitle_ptsize = 12;
GDC_ytitle = "GDC_ytitle\r\n(times 10 i)";
GDC_ytitle_font = "/dos/C/windows/fonts/timesi.ttf";
GDC_ytitle_ptsize = 10;
GDC_xaxis_angle = 45.0;
GDC_xaxis_font = "/usr/share/enlightenment/themes/DEFAULT/ttfonts/zirkle.ttf";
GDC_xaxis_ptsize = 11.0;
GDC_XLabelColor = 0x000080;
GDC_bar_width = 60; /* (%) */
GDC_image_type = GDC_PNG;
/* ---- call the lib V0.95b ----- */
GDC_out_graph( 400, 300, /* width, height */
stdout, /* open FILE pointer */
GDC_3DBAR, /* chart type */
NUM_POINTS, /* num points per data set */
lbls, /* X labels array of char* */
1, /* number of data sets */
(float*)data, /* data */
(float*)NULL ); /* no right-hand-axis data */
exit(0);
}
/* --------------------------------------------------------- */
/* sample data gathering routine */
/* data can come from anywhere, generally a DB or data file */
/* here it's randomly generated */
/* --------------------------------------------------------- */
#include <stdlib.h> /* for rand() */
#include <time.h> /* for seed */
get_data( float data[NUM_SETS][NUM_POINTS],
int low,
int high )
{
int i, j;
srand( (unsigned int)time((time_t)NULL) );
for( i=0; i<NUM_SETS; ++i )
for( j=0; j<NUM_POINTS; ++j )
/* random number between low & high */
data[i][j] = 1.0+low+(high * rand()/(RAND_MAX+1.0));
}
/* -------- also random colors ----------------------------- */
get_individual_colors( unsigned long extclr[NUM_SETS][NUM_POINTS] )
{
int i, j;
for( i=0; i<NUM_SETS; ++i )
for( j=0; j<NUM_POINTS; ++j )
extclr[i][j] = (unsigned long)rand();
}
/* GDCHART 0.11.1b 3D Bar sample 17 June 2001 */
/* NOTE: fonts and locations specified are machine specific */
/* should be able to set font-search-path env GDFONTPATH */
/* see libgd documentation */
/* will default to builtin font, if specified TTF not found */
#include <stdio.h>
#include "gdc.h"
#include "gdchart.h"
#define NUM_SETS 1
#define NUM_POINTS 4
main()
{
float data [ NUM_SETS ][ NUM_POINTS ];
unsigned long extclr[ NUM_SETS ][ NUM_POINTS ];
char *lbls[] = { "angle - 45", "font - zirkle", "ptsz - 10", "Color - blue", "" };
get_data( data, 0, 500 );
get_individual_colors( extclr );
GDC_BGColor = 0xFFFFFF;
GDC_PlotColor = 0x4080FF;
GDC_ExtColor = &(extclr[0][0]); /* set color option */
GDC_title = "GDC_title\r\n(benjamingothic 12)";
GDC_title_font = "/usr/share/enlightenment/E-docs/benjamingothic.ttf";
GDC_title_ptsize = 12;
GDC_xtitle = "GDC_xtitle\r\n(x-files 12)";
GDC_xtitle_font = "/usr/share/enlightenment/E-docs/x-files.ttf";
GDC_xtitle_ptsize = 12;
GDC_ytitle = "GDC_ytitle\r\n(times 10 i)";
GDC_ytitle_font = "/dos/C/windows/fonts/timesi.ttf";
GDC_ytitle_ptsize = 10;
GDC_xaxis_angle = 45.0;
GDC_xaxis_font = "/usr/share/enlightenment/themes/DEFAULT/ttfonts/zirkle.ttf";
GDC_xaxis_ptsize = 11.0;
GDC_XLabelColor = 0x000080;
GDC_bar_width = 60; /* (%) */
GDC_image_type = GDC_PNG;
/* ---- call the lib V0.95b ----- */
GDC_out_graph( 400, 300, /* width, height */
stdout, /* open FILE pointer */
GDC_3DBAR, /* chart type */
NUM_POINTS, /* num points per data set */
lbls, /* X labels array of char* */
1, /* number of data sets */
(float*)data, /* data */
(float*)NULL ); /* no right-hand-axis data */
exit(0);
}
/* --------------------------------------------------------- */
/* sample data gathering routine */
/* data can come from anywhere, generally a DB or data file */
/* here it's randomly generated */
/* --------------------------------------------------------- */
#include <stdlib.h> /* for rand() */
#include <time.h> /* for seed */
get_data( float data[NUM_SETS][NUM_POINTS],
int low,
int high )
{
int i, j;
srand( (unsigned int)time((time_t)NULL) );
for( i=0; i<NUM_SETS; ++i )
for( j=0; j<NUM_POINTS; ++j )
/* random number between low & high */
data[i][j] = 1.0+low+(high * rand()/(RAND_MAX+1.0));
}
/* -------- also random colors ----------------------------- */
get_individual_colors( unsigned long extclr[NUM_SETS][NUM_POINTS] )
{
int i, j;
for( i=0; i<NUM_SETS; ++i )
for( j=0; j<NUM_POINTS; ++j )
extclr[i][j] = (unsigned long)rand();
}
/* GDCHART 0.11.3dev GDC.C 11 Mar 2003 */
/* Copyright Bruce Verderaime 1998-2004 */
#define GDC_INCL
#define GDC_LIB
#include <math.h>
#include "gdc.h"
struct GDC_FONT_T GDC_fontc[GDC_numfonts] = { (gdFontPtr)NULL, 8, 5,
(gdFontPtr)NULL, 8, 5,
(gdFontPtr)NULL, 12, 6,
(gdFontPtr)NULL, 13, 7,
(gdFontPtr)NULL, 16, 8,
(gdFontPtr)NULL, 15, 9 };
/* ------------------------------------------------------------------- *\
* convert from enum GDC_font_size to gd fonts
* for now load them all
* #defines and #ifdefs might enable loading only needed fonts
* gd2.0 is to be built as a shared obj.
\* ------------------------------------------------------------------- */
void
load_font_conversions()
{
GDC_fontc[GDC_pad].f = gdFontTiny;
GDC_fontc[GDC_TINY].f = gdFontTiny;
GDC_fontc[GDC_SMALL].f = gdFontSmall;
GDC_fontc[GDC_MEDBOLD].f = gdFontMediumBold;
GDC_fontc[GDC_LARGE].f = gdFontLarge;
GDC_fontc[GDC_GIANT].f = gdFontGiant;
}
/* ------------------------------------------------------------------ *\
* count (natural) substrings (new line sep)
\* ------------------------------------------------------------------ */
short
cnt_nl( char *nstr,
int *len ) /* strlen - max seg */
{
short c = 1;
short max_seg_len = 0;
short tmplen = 0;
if( !nstr )
{
if( len )
*len = 0;
return 0;
}
while( *nstr )
{
if( *nstr == '\n' )
{
++c;
max_seg_len = MAX( tmplen, max_seg_len );
tmplen = 0;
}
else
++tmplen;
++nstr;
}
if( len )
*len = MAX( tmplen, max_seg_len ); /* don't forget last seg */
return c;
}
/* ------------------------------------------------------------------ *\
* gd out a string with '\n's
* handle FTs (TTFs) and gd fonts
* gdImageString() draws from the upper left;
* gdImageStringFT() draws from lower left (one font height, even with '\n's)! >:-|
\* ------------------------------------------------------------------ */
int
GDCImageStringNL( gdImagePtr im,
struct GDC_FONT_T *f,
char *ftfont,
double ftptsz,
double rad,
int x,
int y,
char *str,
int clr,
GDC_justify_t justify,
char **sts )
{
int retval = 0;
char *err = NULL;
#ifdef HAVE_LIBFREETYPE
/* TODO: honor justifies */
if( ftfont && ftptsz )
{
/* need one line height */
/* remember last one (will likely be the same) */
/* is this needed? */
/* gdImageStringFT() utilizes some caching */
/* saves a couple floating point trig calls */
static int f1hgt = 0;
static double xs,
ys;
static double lftptsz = 0.0;
static char *lftfont = (char*)-1;
if( !f1hgt ||
( lftfont != ftfont || lftptsz != ftptsz ) )
{
f1hgt = GDCfnt_sz( "Aj",
0,
ftfont,
ftptsz,
rad,
NULL ).h;
xs = (double)f1hgt * sin(rad);
ys = (double)(f1hgt-1) * cos(rad);
}
x += (int)xs;
y += (int)ys;
if( (err = gdImageStringFT( im,
(int*)NULL,
clr,
ftfont,
ftptsz,
rad,
x,
y,
str)) == NULL )
{
if( sts ) *sts = err;
return 0;
}
else
{
/* TTF failed */
retval = 1;
/* fall through - default to gdFonts */
/* reinstate upper left reference */
x -= (int)xs;
y -= (int)ys;
}
}
#endif
{
int i;
int len;
int max_len;
short strs_num = cnt_nl( str, &max_len );
CREATE_ARRAY1( sub_str, unsigned char, max_len+1 ); /* char sub_str[max