From 04ec728a6227d7c46f95faa875c61a1f770ffce2 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Tue, 6 Aug 2002 09:28:00 +0000 Subject: [PATCH] make gr_remap_font just reload the whole thing --- 2d/font.c | 64 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/2d/font.c b/2d/font.c index e13f965c..16758ff8 100644 --- a/2d/font.c +++ b/2d/font.c @@ -1,4 +1,4 @@ -/* $Id: font.c,v 1.16 2002-07-30 11:05:53 btb Exp $ */ +/* $Id: font.c,v 1.17 2002-08-06 09:28:00 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -1764,8 +1764,8 @@ void gr_remap_font( grs_font *font, char * fontname, char *font_data ) int nchars; CFILE *fontfile; char file_id[4]; - int32_t datasize; //size up to (but not including) palette - int data_len; + int datasize; //size up to (but not including) palette + unsigned char *ptr; if (! (font->ft_flags & FT_COLOR)) return; @@ -1782,36 +1782,52 @@ void gr_remap_font( grs_font *font, char * fontname, char *font_data ) datasize = cfile_read_int(fontfile); datasize -= GRS_FONT_SIZE; // subtract the size of the header. - nchars = font->ft_maxchar-font->ft_minchar+1; + d_free(font->ft_chars); + grs_font_read(font, fontfile); // have to reread in case mission hogfile overrides font. + + cfread(font_data, 1, datasize, fontfile); //read raw data + + // make these offsets relative to font_data + font->ft_data = (ubyte *)((int)font->ft_data - GRS_FONT_SIZE); + font->ft_widths = (short *)((int)font->ft_widths - GRS_FONT_SIZE); + font->ft_kerndata = (ubyte *)((int)font->ft_kerndata - GRS_FONT_SIZE); + + nchars = font->ft_maxchar - font->ft_minchar + 1; - //compute data length - data_len = 0; if (font->ft_flags & FT_PROPORTIONAL) { + font->ft_widths = (short *) &font_data[(int)font->ft_widths]; + font->ft_data = &font_data[(int)font->ft_data]; + font->ft_chars = (unsigned char **)d_malloc( nchars * sizeof(unsigned char *)); + + ptr = font->ft_data; + for (i=0; i< nchars; i++ ) { + font->ft_widths[i] = INTEL_SHORT(font->ft_widths[i]); + font->ft_chars[i] = ptr; if (font->ft_flags & FT_COLOR) - data_len += font->ft_widths[i] * font->ft_h; + ptr += font->ft_widths[i] * font->ft_h; else - data_len += BITS_TO_BYTES(font->ft_widths[i]) * font->ft_h; + ptr += BITS_TO_BYTES(font->ft_widths[i]) * font->ft_h; } - } else - data_len = nchars * font->ft_w * font->ft_h; + } else { - cfseek(fontfile, GRS_FONT_SIZE, SEEK_CUR); // skip past header + font->ft_data = font_data; + font->ft_chars = NULL; + font->ft_widths = NULL; - cfread(font_data, 1, datasize, fontfile); //read raw data + ptr = font->ft_data + (nchars * font->ft_w * font->ft_h); + } - for (i=0; i< nchars; i++ ) - font->ft_widths[i] = INTEL_SHORT(font->ft_widths[i]); + if (font->ft_flags & FT_KERNED) + font->ft_kerndata = &font_data[(int)font->ft_kerndata]; if (font->ft_flags & FT_COLOR) { //remap palette ubyte palette[256*3]; ubyte colormap[256]; int freq[256]; - cfseek(fontfile,-sizeof(palette),SEEK_END); - cfread(palette,3,256,fontfile); //read the palette #ifdef MACINTOSH // swap the first and last palette entries (black and white) @@ -1827,11 +1843,11 @@ void gr_remap_font( grs_font *font, char * fontname, char *font_data ) // we also need to swap the data entries as well. black is white and white is black - for (i = 0; i < data_len; i++) { - if (font->ft_data[i] == 0) - font->ft_data[i] = 255; - else if (font->ft_data[i] == 255) - font->ft_data[i] = 0; + for (i = 0; i < ptr-newfont->ft_data; i++) { + if (newfont->ft_data[i] == 0) + newfont->ft_data[i] = 255; + else if (newfont->ft_data[i] == 255) + newfont->ft_data[i] = 0; } } @@ -1839,12 +1855,12 @@ void gr_remap_font( grs_font *font, char * fontname, char *font_data ) build_colormap_good( (ubyte *)&palette, colormap, freq ); - colormap[TRANSPARENCY_COLOR] = TRANSPARENCY_COLOR; // changed from colormap[255] = 255; - - decode_data_asm(font->ft_data, data_len, colormap, freq ); + colormap[TRANSPARENCY_COLOR] = TRANSPARENCY_COLOR; // chaged from colormap[255] = 255 to this for macintosh + decode_data_asm(font->ft_data, ptr - font->ft_data, colormap, freq ); } + cfclose(fontfile); #ifdef OGL -- 2.39.2