portability
This commit is contained in:
parent
e5580bb4dc
commit
cc09ed619c
143
2d/font.c
143
2d/font.c
|
@ -1,4 +1,4 @@
|
|||
/* $Id: font.c,v 1.13 2002-07-26 23:13:09 btb Exp $ */
|
||||
/* $Id: font.c,v 1.14 2002-07-27 02:20:20 btb Exp $ */
|
||||
/*
|
||||
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
|
||||
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
|
||||
|
@ -8,11 +8,11 @@ IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
|
|||
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
|
||||
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
|
||||
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
|
||||
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
||||
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
|
||||
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
* Graphical routines for drawing fonts.
|
||||
*
|
||||
*/
|
||||
|
@ -53,6 +53,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
|||
typedef struct openfont {
|
||||
char filename[FILENAME_LEN];
|
||||
grs_font *ptr;
|
||||
char *dataptr;
|
||||
} openfont;
|
||||
|
||||
//list of open fonts, for use (for now) for palette remapping
|
||||
|
@ -1530,16 +1531,20 @@ void gr_close_font( grs_font * font )
|
|||
if (font)
|
||||
{
|
||||
int fontnum;
|
||||
char * font_data;
|
||||
|
||||
//find font in list
|
||||
for (fontnum=0;fontnum<MAX_OPEN_FONTS && open_font[fontnum].ptr!=font;fontnum++);
|
||||
Assert(fontnum<MAX_OPEN_FONTS); //did we find slot?
|
||||
|
||||
font_data = open_font[fontnum].dataptr;
|
||||
d_free( font_data );
|
||||
|
||||
open_font[fontnum].ptr = NULL;
|
||||
open_font[fontnum].dataptr = NULL;
|
||||
|
||||
if ( font->ft_chars )
|
||||
d_free( font->ft_chars );
|
||||
d_free( font->oldfont );
|
||||
#ifdef OGL
|
||||
if (font->ft_bitmaps)
|
||||
d_free( font->ft_bitmaps );
|
||||
|
@ -1548,6 +1553,7 @@ void gr_close_font( grs_font * font )
|
|||
#endif
|
||||
d_free( font );
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1560,9 +1566,9 @@ void gr_remap_color_fonts()
|
|||
grs_font *font;
|
||||
|
||||
font = open_font[fontnum].ptr;
|
||||
|
||||
|
||||
if (font && (font->ft_flags & FT_COLOR))
|
||||
gr_remap_font(font,open_font[fontnum].filename);
|
||||
gr_remap_font(font, open_font[fontnum].filename, open_font[fontnum].dataptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1583,34 +1589,34 @@ void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count
|
|||
#endif
|
||||
|
||||
/*
|
||||
* reads an old_grs_font structure from a CFILE
|
||||
* reads a grs_font structure from a CFILE
|
||||
*/
|
||||
void old_grs_font_read(old_grs_font *ogf, CFILE *fp)
|
||||
void grs_font_read(grs_font *gf, CFILE *fp)
|
||||
{
|
||||
ogf->ft_w = cfile_read_short(fp);
|
||||
ogf->ft_h = cfile_read_short(fp);
|
||||
ogf->ft_flags = cfile_read_short(fp);
|
||||
ogf->ft_baseline = cfile_read_short(fp);
|
||||
ogf->ft_minchar = cfile_read_byte(fp);
|
||||
ogf->ft_maxchar = cfile_read_byte(fp);
|
||||
ogf->ft_bytewidth = cfile_read_short(fp);
|
||||
ogf->ft_data = (ubyte *)cfile_read_int(fp);
|
||||
ogf->ft_chars = (ubyte **)cfile_read_int(fp);
|
||||
ogf->ft_widths = (short *)cfile_read_int(fp);
|
||||
ogf->ft_kerndata = (ubyte *)cfile_read_int(fp);
|
||||
gf->ft_w = cfile_read_short(fp);
|
||||
gf->ft_h = cfile_read_short(fp);
|
||||
gf->ft_flags = cfile_read_short(fp);
|
||||
gf->ft_baseline = cfile_read_short(fp);
|
||||
gf->ft_minchar = cfile_read_byte(fp);
|
||||
gf->ft_maxchar = cfile_read_byte(fp);
|
||||
gf->ft_bytewidth = cfile_read_short(fp);
|
||||
gf->ft_data = (ubyte *)cfile_read_int(fp);
|
||||
gf->ft_chars = (ubyte **)cfile_read_int(fp);
|
||||
gf->ft_widths = (short *)cfile_read_int(fp);
|
||||
gf->ft_kerndata = (ubyte *)cfile_read_int(fp);
|
||||
}
|
||||
|
||||
grs_font * gr_init_font( char * fontname )
|
||||
{
|
||||
static int first_time=1;
|
||||
old_grs_font *font;
|
||||
grs_font *newfont;
|
||||
grs_font *font;
|
||||
char *font_data;
|
||||
int i,fontnum;
|
||||
unsigned char * ptr;
|
||||
int nchars;
|
||||
CFILE *fontfile;
|
||||
char file_id[4];
|
||||
int32_t datasize; //size up to (but not including) palette
|
||||
int datasize; //size up to (but not including) palette
|
||||
|
||||
if (first_time) {
|
||||
int i;
|
||||
|
@ -1635,64 +1641,54 @@ grs_font * gr_init_font( char * fontname )
|
|||
Error( "File %s is not a font file", fontname );
|
||||
|
||||
datasize = cfile_read_int(fontfile);
|
||||
datasize -= GRS_FONT_SIZE; // subtract the size of the header.
|
||||
|
||||
MALLOC(font, grs_font, sizeof(grs_font));
|
||||
grs_font_read(font, fontfile);
|
||||
|
||||
printf("Font file %s has datasize %d\n", fontname, datasize);
|
||||
MALLOC(font_data, char, datasize);
|
||||
cfread(font_data, 1, datasize, fontfile);
|
||||
|
||||
font = (old_grs_font *) d_malloc(datasize);
|
||||
newfont = (grs_font *) d_malloc(sizeof(grs_font));
|
||||
newfont->oldfont=font;
|
||||
open_font[fontnum].ptr = font;
|
||||
open_font[fontnum].dataptr = font_data;
|
||||
|
||||
open_font[fontnum].ptr = newfont;
|
||||
// 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);
|
||||
|
||||
//old_grs_font_read(font, fontfile);
|
||||
nchars = font->ft_maxchar - font->ft_minchar + 1;
|
||||
|
||||
cfread(font,1,datasize,fontfile);
|
||||
if (font->ft_flags & FT_PROPORTIONAL) {
|
||||
|
||||
newfont->ft_w = font->ft_w = INTEL_SHORT(font->ft_w);
|
||||
newfont->ft_h = font->ft_h = INTEL_SHORT(font->ft_h);
|
||||
newfont->ft_flags = font->ft_flags = INTEL_SHORT(font->ft_flags);
|
||||
newfont->ft_baseline = font->ft_baseline = INTEL_SHORT(font->ft_baseline);
|
||||
newfont->ft_maxchar = font->ft_maxchar;
|
||||
newfont->ft_minchar = font->ft_minchar;
|
||||
newfont->ft_bytewidth = font->ft_bytewidth = INTEL_SHORT(font->ft_bytewidth);
|
||||
newfont->ft_data = font->ft_data = (ubyte *)INTEL_INT((int)font->ft_data);
|
||||
newfont->ft_chars = font->ft_chars = (ubyte **)INTEL_INT((int)font->ft_chars);
|
||||
newfont->ft_widths = font->ft_widths = (short *)INTEL_INT((int)font->ft_widths);
|
||||
newfont->ft_kerndata = font->ft_kerndata = (ubyte *)INTEL_INT((int)font->ft_kerndata);
|
||||
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 *));
|
||||
|
||||
nchars = newfont->ft_maxchar-newfont->ft_minchar+1;
|
||||
|
||||
if (newfont->ft_flags & FT_PROPORTIONAL) {
|
||||
|
||||
newfont->ft_widths = (short *) ((int)font->ft_widths + ((ubyte *) font));
|
||||
newfont->ft_data = (int)font->ft_data + (ubyte *)font;
|
||||
newfont->ft_chars = (unsigned char **)d_malloc( nchars * sizeof(unsigned char *));
|
||||
|
||||
ptr = newfont->ft_data;
|
||||
ptr = font->ft_data;
|
||||
|
||||
for (i=0; i< nchars; i++ ) {
|
||||
newfont->ft_widths[i] = INTEL_INT(newfont->ft_widths[i]);
|
||||
newfont->ft_chars[i] = ptr;
|
||||
if (newfont->ft_flags & FT_COLOR)
|
||||
ptr += newfont->ft_widths[i] * newfont->ft_h;
|
||||
font->ft_widths[i] = INTEL_SHORT(font->ft_widths[i]);
|
||||
font->ft_chars[i] = ptr;
|
||||
if (font->ft_flags & FT_COLOR)
|
||||
ptr += font->ft_widths[i] * font->ft_h;
|
||||
else
|
||||
ptr += BITS_TO_BYTES(newfont->ft_widths[i]) * newfont->ft_h;
|
||||
ptr += BITS_TO_BYTES(font->ft_widths[i]) * font->ft_h;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
newfont->ft_data = ((unsigned char *) font) + sizeof(*font);
|
||||
newfont->ft_chars = NULL;
|
||||
newfont->ft_widths = NULL;
|
||||
font->ft_data = font_data;
|
||||
font->ft_chars = NULL;
|
||||
font->ft_widths = NULL;
|
||||
|
||||
ptr = newfont->ft_data + (nchars * newfont->ft_w * newfont->ft_h);
|
||||
ptr = font->ft_data + (nchars * font->ft_w * font->ft_h);
|
||||
}
|
||||
|
||||
if (newfont->ft_flags & FT_KERNED)
|
||||
newfont->ft_kerndata = (int)font->ft_kerndata + (ubyte *)font;
|
||||
if (font->ft_flags & FT_KERNED)
|
||||
font->ft_kerndata = &font_data[(int)font->ft_kerndata];
|
||||
|
||||
if (newfont->ft_flags & FT_COLOR) { //remap palette
|
||||
if (font->ft_flags & FT_COLOR) { //remap palette
|
||||
ubyte palette[256*3];
|
||||
ubyte colormap[256];
|
||||
int freq[256];
|
||||
|
@ -1726,7 +1722,7 @@ grs_font * gr_init_font( char * fontname )
|
|||
|
||||
colormap[TRANSPARENCY_COLOR] = TRANSPARENCY_COLOR; // chaged from colormap[255] = 255 to this for macintosh
|
||||
|
||||
decode_data_asm(newfont->ft_data, ptr-newfont->ft_data, colormap, freq );
|
||||
decode_data_asm(font->ft_data, ptr - font->ft_data, colormap, freq );
|
||||
|
||||
}
|
||||
|
||||
|
@ -1737,7 +1733,7 @@ grs_font * gr_init_font( char * fontname )
|
|||
|
||||
//set curcanv vars
|
||||
|
||||
FONT = newfont;
|
||||
FONT = font;
|
||||
FG_COLOR = 0;
|
||||
BG_COLOR = 0;
|
||||
|
||||
|
@ -1749,20 +1745,20 @@ grs_font * gr_init_font( char * fontname )
|
|||
}
|
||||
|
||||
#ifdef OGL
|
||||
ogl_init_font(newfont);
|
||||
ogl_init_font(font);
|
||||
#endif
|
||||
|
||||
return newfont;
|
||||
return font;
|
||||
|
||||
}
|
||||
|
||||
//remap a font by re-reading its data & palette
|
||||
void gr_remap_font( grs_font *font, char * fontname )
|
||||
void gr_remap_font( grs_font *font, char * fontname, char *font_data )
|
||||
{
|
||||
int i;
|
||||
int nchars;
|
||||
CFILE *fontfile;
|
||||
u_int32_t file_id;
|
||||
char file_id[4];
|
||||
int32_t datasize; //size up to (but not including) palette
|
||||
int data_len;
|
||||
|
||||
|
@ -1774,12 +1770,13 @@ void gr_remap_font( grs_font *font, char * fontname )
|
|||
if (!fontfile)
|
||||
Error( "Can't open font file %s", fontname );
|
||||
|
||||
file_id = cfile_read_int(fontfile);
|
||||
datasize = cfile_read_int(fontfile);
|
||||
|
||||
if (file_id != MAKE_SIG('N','F','S','P'))
|
||||
cfread(file_id, 4, 1, fontfile);
|
||||
if ( !strncmp( file_id, "NFSP", 4 ) )
|
||||
Error( "File %s is not a font file", fontname );
|
||||
|
||||
datasize = cfile_read_int(fontfile);
|
||||
datasize -= GRS_FONT_SIZE; // subtract the size of the header.
|
||||
|
||||
nchars = font->ft_maxchar-font->ft_minchar+1;
|
||||
|
||||
//compute data length
|
||||
|
@ -1796,7 +1793,9 @@ void gr_remap_font( grs_font *font, char * fontname )
|
|||
} else
|
||||
data_len = nchars * font->ft_w * font->ft_h;
|
||||
|
||||
cfread(font->oldfont, 1, datasize, fontfile); //read raw data
|
||||
cfseek(fontfile, GRS_FONT_SIZE, SEEK_CUR); // skip past header
|
||||
|
||||
cfread(font_data, 1, datasize, fontfile); //read raw data
|
||||
|
||||
if (font->ft_flags & FT_COLOR) { //remap palette
|
||||
ubyte palette[256*3];
|
||||
|
|
48
include/gr.h
48
include/gr.h
|
@ -52,23 +52,6 @@ typedef struct _grs_point {
|
|||
#define CC_LSPACING_S "\x2" //next char specifies line spacing
|
||||
#define CC_UNDERLINE_S "\x3" //next char is underlined
|
||||
|
||||
//old font structure, could not add new items to it without screwing up gr_init_font
|
||||
typedef struct _grs_font {
|
||||
short ft_w; // Width in pixels
|
||||
short ft_h; // Height in pixels
|
||||
short ft_flags; // Proportional?
|
||||
short ft_baseline; //
|
||||
ubyte ft_minchar; // First char defined by this font
|
||||
ubyte ft_maxchar; // Last char defined by this font
|
||||
short ft_bytewidth; // Width in unsigned chars
|
||||
ubyte * ft_data; // Ptr to raw data.
|
||||
ubyte ** ft_chars; // Ptrs to data for each char (required for prop font)
|
||||
short * ft_widths; // Array of widths (required for prop font)
|
||||
ubyte * ft_kerndata; // Array of kerning triplet data
|
||||
} __pack__ old_grs_font;
|
||||
|
||||
#define OLD_GRS_FONT_SIZE 28 // how much file space it uses
|
||||
|
||||
#define BM_LINEAR 0
|
||||
#define BM_MODEX 1
|
||||
#define BM_SVGA 2
|
||||
|
@ -138,25 +121,28 @@ typedef struct _grs_bitmap {
|
|||
|
||||
} grs_bitmap;
|
||||
|
||||
//new font structure, which does not suffer from the inability to add new items
|
||||
typedef struct _new_grs_font {
|
||||
short ft_w,ft_h; // Width and height in pixels
|
||||
short ft_flags; // Proportional?
|
||||
short ft_baseline; //
|
||||
ubyte ft_minchar, // The first and last chars defined by
|
||||
ft_maxchar; // This font
|
||||
short ft_bytewidth; // Width in unsigned chars
|
||||
ubyte * ft_data; // Ptr to raw data.
|
||||
ubyte ** ft_chars; // Ptrs to data for each char (required for prop font)
|
||||
short * ft_widths; // Array of widths (required for prop font)
|
||||
ubyte * ft_kerndata; // Array of kerning triplet data
|
||||
old_grs_font * oldfont;
|
||||
//font structure
|
||||
typedef struct _grs_font {
|
||||
short ft_w; // Width in pixels
|
||||
short ft_h; // Height in pixels
|
||||
short ft_flags; // Proportional?
|
||||
short ft_baseline; //
|
||||
ubyte ft_minchar; // First char defined by this font
|
||||
ubyte ft_maxchar; // Last char defined by this font
|
||||
short ft_bytewidth; // Width in unsigned chars
|
||||
ubyte * ft_data; // Ptr to raw data.
|
||||
ubyte ** ft_chars; // Ptrs to data for each char (required for prop font)
|
||||
short * ft_widths; // Array of widths (required for prop font)
|
||||
ubyte * ft_kerndata; // Array of kerning triplet data
|
||||
#ifdef OGL
|
||||
// These fields do not participate in disk i/o!
|
||||
grs_bitmap *ft_bitmaps;
|
||||
grs_bitmap ft_parent_bitmap;
|
||||
#endif
|
||||
} grs_font;
|
||||
|
||||
#define GRS_FONT_SIZE 28 // how much space it takes up on disk
|
||||
|
||||
typedef struct _grs_canvas {
|
||||
grs_bitmap cv_bitmap; // the bitmap for this canvas
|
||||
short cv_color; // current color
|
||||
|
@ -365,7 +351,7 @@ grs_font * gr_init_font( char * fontfile );
|
|||
void gr_close_font( grs_font * font );
|
||||
|
||||
//remap a font, re-reading its data & palette
|
||||
void gr_remap_font( grs_font *font, char * fontname );
|
||||
void gr_remap_font( grs_font *font, char * fontname, char *font_data );
|
||||
|
||||
//remap (by re-reading) all the color fonts
|
||||
void gr_remap_color_fonts();
|
||||
|
|
Loading…
Reference in a new issue