From 51b6b4e271f76a981cff7ffa0913cd36123a2664 Mon Sep 17 00:00:00 2001 From: zicodxx Date: Sat, 7 Apr 2012 11:35:38 +0200 Subject: [PATCH] made code more similar to D2X-Rebirth by introducing open_font which allows to keep track of font_data and free it properly --- 2d/font.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- CHANGELOG.txt | 1 + 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/2d/font.c b/2d/font.c index 7e4a2d344..0d966eabb 100644 --- a/2d/font.c +++ b/2d/font.c @@ -42,6 +42,17 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define FONTSCALE_X(x) ((float)(x)*(FNTScaleX)) #define FONTSCALE_Y(x) ((float)(x)*(FNTScaleY)) +#define MAX_OPEN_FONTS 50 + +typedef struct openfont { + char filename[FILENAME_LEN]; + grs_font *ptr; + char *dataptr; +} openfont; + +//list of open fonts +openfont open_font[MAX_OPEN_FONTS]; + #define BITS_TO_BYTES(x) (((x)+7)>>3) int gr_internal_string_clipped(int x, int y, char *s ); @@ -894,6 +905,19 @@ void gr_close_font( grs_font * font ) { if (font) { + int fontnum; + char * font_data; + + //find font in list + for (fontnum=0;fontnumft_chars ) d_free( font->ft_chars ); #ifdef OGL @@ -925,15 +949,32 @@ void grs_font_read(grs_font *gf, PHYSFS_file *fp) grs_font * gr_init_font( char * fontname ) { + static int first_time=1; grs_font *font; char *font_data; - int i; + int i,fontnum; unsigned char * ptr; int nchars; PHYSFS_file *fontfile; char file_id[4]; int datasize; //size up to (but not including) palette + if (first_time) { + int i; + for (i=0;ift_data = (ubyte *)((size_t)font->ft_data - GRS_FONT_SIZE); font->ft_widths = (short *)((size_t)font->ft_widths - GRS_FONT_SIZE); diff --git a/CHANGELOG.txt b/CHANGELOG.txt index dc254c392..4618cd5b3 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D1X-Rebirth Changelog 20120407 -------- main/fireball.c: made choose_drop_segment more similar to D2X-Rebirth and let fallback correctly check for reactor segment +2d/font.c: made code more similar to D2X-Rebirth by introducing open_font which allows to keep track of font_data and free it properly 20120405 --------