2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
23 #include "pa_enabl.h" //$$POLY_ACC
39 #define MAX_OPEN_FONTS 50
40 #define FILENAME_LEN 13
42 typedef struct openfont {
43 char filename[FILENAME_LEN];
47 //list of open fonts, for use (for now) for palette remapping
48 openfont open_font[MAX_OPEN_FONTS];
50 #define FONT grd_curcanv->cv_font
51 #define FG_COLOR grd_curcanv->cv_font_fg_color
52 #define BG_COLOR grd_curcanv->cv_font_bg_color
53 #define FWIDTH FONT->ft_w
54 #define FHEIGHT FONT->ft_h
55 #define FBASELINE FONT->ft_baseline
56 #define FFLAGS FONT->ft_flags
57 #define FMINCHAR FONT->ft_minchar
58 #define FMAXCHAR FONT->ft_maxchar
59 #define FDATA FONT->ft_data
60 #define FCHARS FONT->ft_chars
61 #define FWIDTHS FONT->ft_widths
63 #define BITS_TO_BYTES(x) (((x)+7)>>3)
65 int gr_internal_string_clipped(int x, int y, char *s );
66 int gr_internal_string_clipped_m(int x, int y, char *s );
68 ubyte *find_kern_entry(grs_font *font,ubyte first,ubyte second)
70 ubyte *p=font->ft_kerndata;
73 if (p[0]==first && p[1]==second)
81 //takes the character AFTER being offset into font
82 #define INFONT(_c) ((_c >= 0) && (_c <= FMAXCHAR-FMINCHAR))
84 //takes the character BEFORE being offset into current font
85 void get_char_width(ubyte c,ubyte c2,int *width,int *spacing)
91 if (!INFONT(letter)) { //not in font, draw as space
93 if (FFLAGS & FT_PROPORTIONAL)
100 if (FFLAGS & FT_PROPORTIONAL)
101 *width = FWIDTHS[letter];
107 if (FFLAGS & FT_KERNED) {
110 if (!(c2==0 || c2=='\n')) {
113 letter2 = c2-FMINCHAR;
115 if (INFONT(letter2)) {
117 p = find_kern_entry(FONT,letter,letter2);
126 int get_centered_x(char *s)
130 for (w=0;*s!=0 && *s!='\n';s++) {
131 get_char_width(s[0],s[1],&w2,&s2);
135 return ((grd_curcanv->cv_bitmap.bm_w - w) / 2);
139 int gr_internal_string0(int x, int y, char *s )
142 ubyte * text_ptr, * next_row, * text_ptr1;
143 int r, BitMask, i, bits, width, spacing, letter, underline;
146 unsigned int VideoOffset, VideoOffset1;
150 VideoOffset1 = y * ROWSIZE + x;
154 while (next_row != NULL )
156 text_ptr1 = next_row;
159 if (x==0x8000) { //centered
160 int xx = get_centered_x(text_ptr1);
161 VideoOffset1 = y * ROWSIZE + xx;
164 for (r=0; r<FHEIGHT; r++)
167 text_ptr = text_ptr1;
169 VideoOffset = VideoOffset1;
173 if (*text_ptr == '\n' )
175 next_row = &text_ptr[1];
179 if (*text_ptr == CC_COLOR) {
180 FG_COLOR = *(text_ptr+1);
185 if (*text_ptr == CC_LSPACING) {
186 skip_lines = *(text_ptr+1) - '0';
192 if (*text_ptr == CC_UNDERLINE )
194 if ((r==FBASELINE+2) || (r==FBASELINE+3))
199 get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);
201 letter = *text_ptr-FMINCHAR;
203 if (!INFONT(letter)) { //not in font, draw as space
204 VideoOffset += spacing;
209 if (FFLAGS & FT_PROPORTIONAL)
212 fp = FDATA + letter * BITS_TO_BYTES(width)*FHEIGHT;
215 for (i=0; i< width; i++ )
216 DATA[VideoOffset++] = FG_COLOR;
219 fp += BITS_TO_BYTES(width)*r;
223 for (i=0; i< width; i++ )
231 DATA[VideoOffset++] = FG_COLOR;
233 DATA[VideoOffset++] = BG_COLOR;
238 VideoOffset += spacing-width; //for kerning
243 VideoOffset1 += ROWSIZE; y++;
247 VideoOffset1 += ROWSIZE * skip_lines;
253 int gr_internal_string0m(int x, int y, char *s )
256 ubyte * text_ptr, * next_row, * text_ptr1;
257 int r, BitMask, i, bits, width, spacing, letter, underline;
260 unsigned int VideoOffset, VideoOffset1;
264 VideoOffset1 = y * ROWSIZE + x;
268 while (next_row != NULL )
270 text_ptr1 = next_row;
273 if (x==0x8000) { //centered
274 int xx = get_centered_x(text_ptr1);
275 VideoOffset1 = y * ROWSIZE + xx;
278 for (r=0; r<FHEIGHT; r++)
281 text_ptr = text_ptr1;
283 VideoOffset = VideoOffset1;
287 if (*text_ptr == '\n' )
289 next_row = &text_ptr[1];
293 if (*text_ptr == CC_COLOR) {
294 FG_COLOR = *(text_ptr+1);
299 if (*text_ptr == CC_LSPACING) {
300 skip_lines = *(text_ptr+1) - '0';
306 if (*text_ptr == CC_UNDERLINE )
308 if ((r==FBASELINE+2) || (r==FBASELINE+3))
313 get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);
315 letter = *text_ptr-FMINCHAR;
317 if (!INFONT(letter)) { //not in font, draw as space
318 VideoOffset += spacing;
323 if (FFLAGS & FT_PROPORTIONAL)
326 fp = FDATA + letter * BITS_TO_BYTES(width)*FHEIGHT;
329 for (i=0; i< width; i++ )
330 DATA[VideoOffset++] = FG_COLOR;
333 fp += BITS_TO_BYTES(width)*r;
337 for (i=0; i< width; i++ )
345 DATA[VideoOffset++] = FG_COLOR;
353 VideoOffset += spacing-width;
356 VideoOffset1 += ROWSIZE; y++;
359 VideoOffset1 += ROWSIZE * skip_lines;
366 int gr_internal_string2(int x, int y, char *s )
369 char * text_ptr, * next_row, * text_ptr1;
370 int r, BitMask, i, bits, width, spacing, letter, underline;
371 int page_switched, skip_lines = 0;
373 unsigned int VideoOffset, VideoOffset1;
375 VideoOffset1 = (unsigned int)DATA + y * ROWSIZE + x;
377 gr_vesa_setpage(VideoOffset1 >> 16);
379 VideoOffset1 &= 0xFFFF;
383 while (next_row != NULL )
385 text_ptr1 = next_row;
388 if (x==0x8000) { //centered
389 int xx = get_centered_x(text_ptr1);
390 VideoOffset1 = y * ROWSIZE + xx;
391 gr_vesa_setpage(VideoOffset1 >> 16);
392 VideoOffset1 &= 0xFFFF;
395 for (r=0; r<FHEIGHT; r++)
397 text_ptr = text_ptr1;
399 VideoOffset = VideoOffset1;
405 if (*text_ptr == '\n' )
407 next_row = &text_ptr[1];
411 if (*text_ptr == CC_COLOR) {
412 FG_COLOR = *(text_ptr+1);
417 if (*text_ptr == CC_LSPACING) {
418 skip_lines = *(text_ptr+1) - '0';
424 if (*text_ptr == CC_UNDERLINE )
426 if ((r==FBASELINE+2) || (r==FBASELINE+3))
431 get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);
433 Assert(width==spacing); //no kerning support here
435 letter = *text_ptr-FMINCHAR;
437 if (!INFONT(letter)) { //not in font, draw as space
438 VideoOffset += spacing;
443 if (FFLAGS & FT_PROPORTIONAL)
446 fp = FDATA + letter * BITS_TO_BYTES(width)*FHEIGHT;
450 if ( VideoOffset+width > 0xFFFF )
452 for (i=0; i< width; i++ )
454 gr_video_memory[VideoOffset++] = FG_COLOR;
456 if (VideoOffset > 0xFFFF )
458 VideoOffset -= 0xFFFF + 1;
466 for (i=0; i< width; i++ )
467 gr_video_memory[VideoOffset++] = FG_COLOR;
476 fp += BITS_TO_BYTES(width)*r;
480 if ( VideoOffset+width > 0xFFFF )
482 for (i=0; i< width; i++ )
490 gr_video_memory[VideoOffset++] = FG_COLOR;
492 gr_video_memory[VideoOffset++] = BG_COLOR;
496 if (VideoOffset > 0xFFFF )
498 VideoOffset -= 0xFFFF + 1;
510 if (bits & 0x80) gr_video_memory[VideoOffset+0] = FG_COLOR;
511 else gr_video_memory[VideoOffset+0] = BG_COLOR;
513 if (bits & 0x40) gr_video_memory[VideoOffset+1] = FG_COLOR;
514 else gr_video_memory[VideoOffset+1] = BG_COLOR;
516 if (bits & 0x20) gr_video_memory[VideoOffset+2] = FG_COLOR;
517 else gr_video_memory[VideoOffset+2] = BG_COLOR;
519 if (bits & 0x10) gr_video_memory[VideoOffset+3] = FG_COLOR;
520 else gr_video_memory[VideoOffset+3] = BG_COLOR;
522 if (bits & 0x08) gr_video_memory[VideoOffset+4] = FG_COLOR;
523 else gr_video_memory[VideoOffset+4] = BG_COLOR;
525 if (bits & 0x04) gr_video_memory[VideoOffset+5] = FG_COLOR;
526 else gr_video_memory[VideoOffset+5] = BG_COLOR;
528 if (bits & 0x02) gr_video_memory[VideoOffset+6] = FG_COLOR;
529 else gr_video_memory[VideoOffset+6] = BG_COLOR;
531 if (bits & 0x01) gr_video_memory[VideoOffset+7] = FG_COLOR;
532 else gr_video_memory[VideoOffset+7] = BG_COLOR;
536 for (i=0; i< width/2 ; i++ )
544 gr_video_memory[VideoOffset++] = FG_COLOR;
546 gr_video_memory[VideoOffset++] = BG_COLOR;
558 gr_video_memory[VideoOffset++] = FG_COLOR;
560 gr_video_memory[VideoOffset++] = BG_COLOR;
570 VideoOffset1 += ROWSIZE;
572 if (VideoOffset1 > 0xFFFF ) {
573 VideoOffset1 -= 0xFFFF + 1;
580 VideoOffset1 += ROWSIZE * skip_lines;
586 int gr_internal_string2m(int x, int y, char *s )
589 char * text_ptr, * next_row, * text_ptr1;
590 int r, BitMask, i, bits, width, spacing, letter, underline;
591 int page_switched, skip_lines = 0;
593 unsigned int VideoOffset, VideoOffset1;
595 VideoOffset1 = (unsigned int)DATA + y * ROWSIZE + x;
597 gr_vesa_setpage(VideoOffset1 >> 16);
599 VideoOffset1 &= 0xFFFF;
603 while (next_row != NULL )
605 text_ptr1 = next_row;
608 if (x==0x8000) { //centered
609 int xx = get_centered_x(text_ptr1);
610 VideoOffset1 = y * ROWSIZE + xx;
611 gr_vesa_setpage(VideoOffset1 >> 16);
612 VideoOffset1 &= 0xFFFF;
615 for (r=0; r<FHEIGHT; r++)
617 text_ptr = text_ptr1;
619 VideoOffset = VideoOffset1;
625 if (*text_ptr == '\n' )
627 next_row = &text_ptr[1];
631 if (*text_ptr == CC_COLOR) {
632 FG_COLOR = *(text_ptr+1);
637 if (*text_ptr == CC_LSPACING) {
638 skip_lines = *(text_ptr+1) - '0';
644 if (*text_ptr == CC_UNDERLINE )
646 if ((r==FBASELINE+2) || (r==FBASELINE+3))
651 get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);
653 letter = *text_ptr-FMINCHAR;
655 if (!INFONT(letter)) { //not in font, draw as space
656 VideoOffset += width;
661 if (FFLAGS & FT_PROPORTIONAL)
664 fp = FDATA + letter * BITS_TO_BYTES(width)*FHEIGHT;
668 if ( VideoOffset+width > 0xFFFF )
670 for (i=0; i< width; i++ )
672 gr_video_memory[VideoOffset++] = FG_COLOR;
674 if (VideoOffset > 0xFFFF )
676 VideoOffset -= 0xFFFF + 1;
684 for (i=0; i< width; i++ )
685 gr_video_memory[VideoOffset++] = FG_COLOR;
690 fp += BITS_TO_BYTES(width)*r;
694 if ( VideoOffset+width > 0xFFFF )
696 for (i=0; i< width; i++ )
704 gr_video_memory[VideoOffset++] = FG_COLOR;
710 if (VideoOffset > 0xFFFF )
712 VideoOffset -= 0xFFFF + 1;
719 for (i=0; i< width; i++ )
727 gr_video_memory[VideoOffset++] = FG_COLOR;
736 VideoOffset += spacing-width;
740 VideoOffset1 += ROWSIZE;
742 if (VideoOffset1 > 0xFFFF ) {
743 VideoOffset1 -= 0xFFFF + 1;
750 VideoOffset1 += ROWSIZE * skip_lines;
756 #endif // __ENV_MSDOS__
758 #if defined(POLY_ACC)
759 int gr_internal_string5(int x, int y, char *s )
762 ubyte * text_ptr, * next_row, * text_ptr1;
763 int r, BitMask, i, bits, width, spacing, letter, underline;
766 unsigned int VideoOffset, VideoOffset1;
769 VideoOffset1 = y * ROWSIZE + x * PA_BPP;
773 while (next_row != NULL )
775 text_ptr1 = next_row;
778 if (x==0x8000) { //centered
779 int xx = get_centered_x(text_ptr1);
780 VideoOffset1 = y * ROWSIZE + xx * PA_BPP;
783 for (r=0; r<FHEIGHT; r++)
786 text_ptr = text_ptr1;
788 VideoOffset = VideoOffset1;
792 if (*text_ptr == '\n' )
794 next_row = &text_ptr[1];
798 if (*text_ptr == CC_COLOR) {
799 FG_COLOR = *(text_ptr+1);
804 if (*text_ptr == CC_LSPACING) {
805 skip_lines = *(text_ptr+1) - '0';
811 if (*text_ptr == CC_UNDERLINE )
813 if ((r==FBASELINE+2) || (r==FBASELINE+3))
818 get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);
820 letter = *text_ptr-FMINCHAR;
822 if (!INFONT(letter)) { //not in font, draw as space
823 VideoOffset += spacing * PA_BPP;
828 if (FFLAGS & FT_PROPORTIONAL)
831 fp = FDATA + letter * BITS_TO_BYTES(width)*FHEIGHT;
834 for (i=0; i< width; i++ )
835 { *(short *)(DATA + VideoOffset) = pa_clut[FG_COLOR]; VideoOffset += PA_BPP; }
838 fp += BITS_TO_BYTES(width)*r;
842 for (i=0; i< width; i++ )
850 { *(short *)(DATA + VideoOffset) = pa_clut[FG_COLOR]; VideoOffset += PA_BPP; }
852 { *(short *)(DATA + VideoOffset) = pa_clut[BG_COLOR]; VideoOffset += PA_BPP; }
857 VideoOffset += PA_BPP * (spacing-width); //for kerning
862 VideoOffset1 += ROWSIZE; y++;
866 VideoOffset1 += ROWSIZE * skip_lines;
872 int gr_internal_string5m(int x, int y, char *s )
875 ubyte * text_ptr, * next_row, * text_ptr1;
876 int r, BitMask, i, bits, width, spacing, letter, underline;
879 unsigned int VideoOffset, VideoOffset1;
882 VideoOffset1 = y * ROWSIZE + x * PA_BPP;
886 while (next_row != NULL )
888 text_ptr1 = next_row;
891 if (x==0x8000) { //centered
892 int xx = get_centered_x(text_ptr1);
893 VideoOffset1 = y * ROWSIZE + xx * PA_BPP;
896 for (r=0; r<FHEIGHT; r++)
899 text_ptr = text_ptr1;
901 VideoOffset = VideoOffset1;
905 if (*text_ptr == '\n' )
907 next_row = &text_ptr[1];
911 if (*text_ptr == CC_COLOR) {
912 FG_COLOR = *(text_ptr+1);
917 if (*text_ptr == CC_LSPACING) {
918 skip_lines = *(text_ptr+1) - '0';
924 if (*text_ptr == CC_UNDERLINE )
926 if ((r==FBASELINE+2) || (r==FBASELINE+3))
931 get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);
933 letter = *text_ptr-FMINCHAR;
935 if (!INFONT(letter)) { //not in font, draw as space
936 VideoOffset += spacing * PA_BPP;
941 if (FFLAGS & FT_PROPORTIONAL)
944 fp = FDATA + letter * BITS_TO_BYTES(width)*FHEIGHT;
947 for (i=0; i< width; i++ )
948 { *(short *)(DATA + VideoOffset) = pa_clut[FG_COLOR]; VideoOffset += PA_BPP; }
951 fp += BITS_TO_BYTES(width)*r;
955 for (i=0; i< width; i++ )
963 { *(short *)(DATA + VideoOffset) = pa_clut[FG_COLOR]; VideoOffset += PA_BPP; }
965 VideoOffset += PA_BPP;
971 VideoOffset += PA_BPP * (spacing-width);
974 VideoOffset1 += ROWSIZE; y++;
977 VideoOffset1 += ROWSIZE * skip_lines;
984 //a bitmap for the character
985 grs_bitmap char_bm = {
988 BM_FLAG_TRANSPARENT, //flags
994 int gr_internal_color_string(int x, int y, char *s )
997 ubyte * text_ptr, * next_row, * text_ptr1;
998 int width, spacing,letter;
1001 char_bm.bm_h = FHEIGHT; //set height for chars of this font
1008 while (next_row != NULL)
1010 text_ptr1 = next_row;
1013 text_ptr = text_ptr1;
1017 if (xx==0x8000) //centered
1018 xx = get_centered_x(text_ptr);
1022 if (*text_ptr == '\n' )
1024 next_row = &text_ptr[1];
1029 letter = *text_ptr-FMINCHAR;
1031 get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);
1033 if (!INFONT(letter)) { //not in font, draw as space
1039 if (FFLAGS & FT_PROPORTIONAL)
1040 fp = FCHARS[letter];
1042 fp = FDATA + letter * BITS_TO_BYTES(width)*FHEIGHT;
1044 char_bm.bm_w = char_bm.bm_rowsize = width;
1046 char_bm.bm_data = fp;
1047 gr_bitmapm(xx,yy,&char_bm);
1058 int gr_string(int x, int y, char *s )
1063 Assert(FONT != NULL);
1065 if ( x == 0x8000 ) {
1066 if ( y<0 ) clipped |= 1;
1067 gr_get_string_size(s, &w, &h, &aw );
1068 // for x, since this will be centered, only look at
1070 if ( w > grd_curcanv->cv_bitmap.bm_w ) clipped |= 1;
1071 if ( (y+h) > grd_curcanv->cv_bitmap.bm_h ) clipped |= 1;
1073 if ( (y+h) < 0 ) clipped |= 2;
1074 if ( y > grd_curcanv->cv_bitmap.bm_h ) clipped |= 2;
1077 if ( (x<0) || (y<0) ) clipped |= 1;
1078 gr_get_string_size(s, &w, &h, &aw );
1079 if ( (x+w) > grd_curcanv->cv_bitmap.bm_w ) clipped |= 1;
1080 if ( (y+h) > grd_curcanv->cv_bitmap.bm_h ) clipped |= 1;
1081 if ( (x+w) < 0 ) clipped |= 2;
1082 if ( (y+h) < 0 ) clipped |= 2;
1083 if ( x > grd_curcanv->cv_bitmap.bm_w ) clipped |= 2;
1084 if ( y > grd_curcanv->cv_bitmap.bm_h ) clipped |= 2;
1088 return gr_ustring(x, y, s );
1090 if ( clipped & 2 ) {
1091 // Completely clipped...
1092 mprintf( (1, "Text '%s' at (%d,%d) is off screen!\n", s, x, y ));
1096 if ( clipped & 1 ) {
1097 // Partially clipped...
1098 //mprintf( (0, "Text '%s' at (%d,%d) is getting clipped!\n", s, x, y ));
1101 // Partially clipped...
1103 if (FFLAGS & FT_COLOR)
1104 return gr_internal_color_string( x, y, s);
1106 if ( BG_COLOR == -1)
1107 return gr_internal_string_clipped_m( x, y, s );
1109 return gr_internal_string_clipped( x, y, s );
1112 int gr_ustring(int x, int y, char *s )
1114 if (FFLAGS & FT_COLOR) {
1116 return gr_internal_color_string(x,y,s);
1123 if ( BG_COLOR == -1)
1124 return gr_internal_string0m(x,y,s);
1126 return gr_internal_string0(x,y,s);
1127 #ifdef __ENV_MSDOS__
1129 if ( BG_COLOR == -1)
1130 return gr_internal_string2m(x,y,s);
1132 return gr_internal_string2(x,y,s);
1133 #endif // __ENV_MSDOS__
1134 #if defined(POLY_ACC)
1136 if ( BG_COLOR == -1)
1137 return gr_internal_string5m(x,y,s);
1139 return gr_internal_string5(x,y,s);
1147 void gr_get_string_size(char *s, int *string_width, int *string_height, int *average_width )
1149 int i = 0, longest_width = 0;
1152 *string_height = FHEIGHT;
1154 *average_width = FWIDTH;
1161 // if (*s == CC_UNDERLINE)
1166 *string_height += FHEIGHT;
1172 // 1 = next byte specifies color, so skip the 1 and the color value
1175 else if (*s == CC_LSPACING) {
1176 *string_height += *(s+1)-'0';
1179 get_char_width(s[0],s[1],&width,&spacing);
1180 *string_width += spacing;
1181 if (*string_width > longest_width)
1182 longest_width = *string_width;
1188 *string_width = longest_width;
1192 int gr_uprintf( int x, int y, char * format, ... )
1197 va_start(args, format );
1198 vsprintf(buffer,format,args);
1199 return gr_ustring( x, y, buffer );
1202 int gr_printf( int x, int y, char * format, ... )
1207 va_start(args, format );
1208 vsprintf(buffer,format,args);
1209 return gr_string( x, y, buffer );
1212 void gr_close_font( grs_font * font )
1219 for (fontnum=0;fontnum<MAX_OPEN_FONTS && open_font[fontnum].ptr!=font;fontnum++);
1220 Assert(fontnum<MAX_OPEN_FONTS); //did we find slot?
1222 open_font[fontnum].ptr = NULL;
1224 if ( font->ft_chars )
1225 d_free( font->ft_chars );
1231 //remap (by re-reading) all the color fonts
1232 void gr_remap_color_fonts()
1236 for (fontnum=0;fontnum<MAX_OPEN_FONTS;fontnum++) {
1239 font = open_font[fontnum].ptr;
1241 if (font && (font->ft_flags & FT_COLOR))
1242 gr_remap_font(font,open_font[fontnum].filename);
1246 void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq );
1247 void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count );
1249 #pragma aux decode_data_asm parm [esi] [ecx] [edi] [ebx] modify exact [esi edi eax ebx ecx] = \
1253 "inc dword ptr [ebx+eax*4]" \
1254 "mov al,[edi+eax]" \
1262 grs_font * gr_init_font( char * fontname )
1264 static int first_time=1;
1267 unsigned char * ptr;
1271 int datasize; //size up to (but not including) palette
1275 for (i=0;i<MAX_OPEN_FONTS;i++)
1276 open_font[i].ptr = NULL;
1280 //find free font slot
1281 for (fontnum=0;fontnum<MAX_OPEN_FONTS && open_font[fontnum].ptr!=NULL;fontnum++);
1282 Assert(fontnum<MAX_OPEN_FONTS); //did we find one?
1284 strncpy(open_font[fontnum].filename,fontname,FILENAME_LEN);
1286 fontfile = cfopen(fontname, "rb");
1289 Error( "Can't open font file %s", fontname );
1291 cfread( file_id, 1, 4, fontfile );
1292 datasize = cfile_read_int(fontfile);
1295 if ((file_id[0] != 'P') ||
1296 (file_id[1] != 'S') ||
1297 (file_id[2] != 'F') ||
1298 (file_id[3] != 'N'))
1299 Error( "File %s is not a font file", fontname );
1301 font = (grs_font *) d_malloc(datasize);
1303 open_font[fontnum].ptr = font;
1305 cfread(font,1,datasize,fontfile);
1308 // gotta translate those endian things
1310 font->ft_w = SWAPSHORT(font->ft_w);
1311 font->ft_h = SWAPSHORT(font->ft_h);
1312 font->ft_flags = SWAPSHORT(font->ft_flags);
1313 font->ft_bytewidth = SWAPSHORT(font->ft_bytewidth);
1314 font->ft_data = (ubyte *)SWAPINT((int)(font->ft_data));
1315 font->ft_chars = (ubyte **)SWAPINT((int)(font->ft_chars));
1316 font->ft_widths = (short *)SWAPINT((int)(font->ft_widths));
1317 font->ft_kerndata = (ubyte *)SWAPINT((int)(font->ft_kerndata));
1320 nchars = font->ft_maxchar-font->ft_minchar+1;
1322 if (font->ft_flags & FT_PROPORTIONAL) {
1324 font->ft_widths = (short *) (((int) font->ft_widths) + ((ubyte *) font));
1327 for (i = 0; i < nchars; i++)
1328 font->ft_widths[i] = SWAPSHORT(font->ft_widths[i]);
1331 font->ft_data = ((int) font->ft_data) + ((ubyte *) font);
1333 font->ft_chars = (unsigned char **)d_malloc( nchars * sizeof(unsigned char *));
1335 ptr = font->ft_data;
1337 for (i=0; i< nchars; i++ ) {
1338 font->ft_chars[i] = ptr;
1339 if (font->ft_flags & FT_COLOR)
1340 ptr += font->ft_widths[i] * font->ft_h;
1342 ptr += BITS_TO_BYTES(font->ft_widths[i]) * font->ft_h;
1347 font->ft_data = ((unsigned char *) font) + sizeof(*font);
1349 font->ft_chars = NULL;
1350 font->ft_widths = NULL;
1352 ptr = font->ft_data + (nchars * font->ft_w * font->ft_h);
1355 if (font->ft_flags & FT_KERNED)
1356 font->ft_kerndata = ((int) font->ft_kerndata) + ((ubyte *) font);
1359 if (font->ft_flags & FT_COLOR) { //remap palette
1360 ubyte palette[256*3];
1361 ubyte colormap[256];
1364 cfread(palette,3,256,fontfile); //read the palette
1366 #ifdef MACINTOSH // swap the first and last palette entries (black and white)
1371 for (i = 0; i < 3; i++) {
1373 palette[i] = palette[765+i];
1377 // we also need to swap the data entries as well. black is white and white is black
1379 for (i = 0; i < ptr-font->ft_data; i++) {
1380 if (font->ft_data[i] == 0)
1381 font->ft_data[i] = 255;
1382 else if (font->ft_data[i] == 255)
1383 font->ft_data[i] = 0;
1389 build_colormap_good( (ubyte *)&palette, colormap, freq );
1391 colormap[TRANSPARENCY_COLOR] = TRANSPARENCY_COLOR; // chaged from colormap[255] = 255 to this for macintosh
1393 decode_data_asm(font->ft_data, ptr-font->ft_data, colormap, freq );
1409 //remap a font by re-reading its data & palette
1410 void gr_remap_font( grs_font *font, char * fontname )
1416 int datasize; //size up to (but not including) palette
1417 int data_ofs,data_len;
1419 if (! (font->ft_flags & FT_COLOR))
1422 fontfile = cfopen(fontname, "rb");
1425 Error( "Can't open font file %s", fontname );
1427 cfread( file_id, 1, 4, fontfile );
1428 datasize = cfile_read_int(fontfile);
1431 if ((file_id[0] != 'P') ||
1432 (file_id[1] != 'S') ||
1433 (file_id[2] != 'F') ||
1434 (file_id[3] != 'N'))
1435 Error( "File %s is not a font file", fontname );
1437 nchars = font->ft_maxchar-font->ft_minchar+1;
1439 //compute data length
1441 if (font->ft_flags & FT_PROPORTIONAL) {
1443 for (i=0; i< nchars; i++ ) {
1444 if (font->ft_flags & FT_COLOR)
1445 data_len += font->ft_widths[i] * font->ft_h;
1447 data_len += BITS_TO_BYTES(font->ft_widths[i]) * font->ft_h;
1451 data_len = nchars * font->ft_w * font->ft_h;
1453 data_ofs = font->ft_data - ((ubyte *) font);
1455 cfseek(fontfile,data_ofs,SEEK_CUR);
1456 cfread(font->ft_data,1,data_len,fontfile); //read raw data
1458 if (font->ft_flags & FT_COLOR) { //remap palette
1459 ubyte palette[256*3];
1460 ubyte colormap[256];
1463 cfseek(fontfile,-sizeof(palette),SEEK_END);
1465 cfread(palette,3,256,fontfile); //read the palette
1467 #ifdef MACINTOSH // swap the first and last palette entries (black and white)
1472 for (i = 0; i < 3; i++) {
1474 palette[i] = palette[765+i];
1478 // we also need to swap the data entries as well. black is white and white is black
1480 for (i = 0; i < data_len; i++) {
1481 if (font->ft_data[i] == 0)
1482 font->ft_data[i] = 255;
1483 else if (font->ft_data[i] == 255)
1484 font->ft_data[i] = 0;
1490 build_colormap_good( (ubyte *)&palette, colormap, freq );
1492 colormap[TRANSPARENCY_COLOR] = TRANSPARENCY_COLOR; // changed from colormap[255] = 255;
1494 decode_data_asm(font->ft_data, data_len, colormap, freq );
1503 void gr_set_fontcolor( int fg, int bg )
1509 void gr_set_curfont( grs_font * new )
1515 int gr_internal_string_clipped(int x, int y, char *s )
1518 char * text_ptr, * next_row, * text_ptr1;
1519 int r, BitMask, i, bits, width, spacing, letter, underline;
1526 while (next_row != NULL )
1528 text_ptr1 = next_row;
1532 if (x==0x8000) //centered
1533 x = get_centered_x(text_ptr1);
1537 for (r=0; r<FHEIGHT; r++) {
1538 text_ptr = text_ptr1;
1542 if (*text_ptr == '\n' ) {
1543 next_row = &text_ptr[1];
1547 if (*text_ptr == CC_COLOR) {
1548 FG_COLOR = *(text_ptr+1);
1553 if (*text_ptr == CC_LSPACING) {
1554 Int3(); // Warning: skip lines not supported for clipped strings.
1560 if (*text_ptr == CC_UNDERLINE ) {
1561 if ((r==FBASELINE+2) || (r==FBASELINE+3))
1566 get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);
1568 letter = *text_ptr-FMINCHAR;
1570 if (!INFONT(letter)) { //not in font, draw as space
1576 if (FFLAGS & FT_PROPORTIONAL)
1577 fp = FCHARS[letter];
1579 fp = FDATA + letter * BITS_TO_BYTES(width)*FHEIGHT;
1582 for (i=0; i< width; i++ ) {
1583 gr_setcolor(FG_COLOR);
1587 fp += BITS_TO_BYTES(width)*r;
1591 for (i=0; i< width; i++ ) {
1597 gr_setcolor(FG_COLOR);
1599 gr_setcolor(BG_COLOR);
1605 x += spacing-width; //for kerning
1615 int gr_internal_string_clipped_m(int x, int y, char *s )
1618 char * text_ptr, * next_row, * text_ptr1;
1619 int r, BitMask, i, bits, width, spacing, letter, underline;
1626 while (next_row != NULL )
1628 text_ptr1 = next_row;
1632 if (x==0x8000) //centered
1633 x = get_centered_x(text_ptr1);
1637 for (r=0; r<FHEIGHT; r++) {
1640 text_ptr = text_ptr1;
1643 if (*text_ptr == '\n' ) {
1644 next_row = &text_ptr[1];
1648 if (*text_ptr == CC_COLOR) {
1649 FG_COLOR = *(text_ptr+1);
1654 if (*text_ptr == CC_LSPACING) {
1655 Int3(); // Warning: skip lines not supported for clipped strings.
1661 if (*text_ptr == CC_UNDERLINE ) {
1662 if ((r==FBASELINE+2) || (r==FBASELINE+3))
1667 get_char_width(text_ptr[0],text_ptr[1],&width,&spacing);
1669 letter = *text_ptr-FMINCHAR;
1671 if (!INFONT(letter)) { //not in font, draw as space
1677 if (FFLAGS & FT_PROPORTIONAL)
1678 fp = FCHARS[letter];
1680 fp = FDATA + letter * BITS_TO_BYTES(width)*FHEIGHT;
1683 for (i=0; i< width; i++ ) {
1684 gr_setcolor(FG_COLOR);
1688 fp += BITS_TO_BYTES(width)*r;
1692 for (i=0; i< width; i++ ) {
1697 if (bits & BitMask) {
1698 gr_setcolor(FG_COLOR);
1707 x += spacing-width; //for kerning