Esempio n. 1
0
static void ini_objects(void)
{
    grf_std = GrLoadFont("lucb21.fnt");
    if (grf_std == NULL) {
	grf_std = GrLoadFont("../fonts/lucb21.fnt");
	if (grf_std == NULL)
	    disaster("lucb21.fnt not found");
    }

    grf_big = GrLoadFont("lucb40.fnt");
    if (grf_big == NULL) {
	grf_big = GrLoadFont("../fonts/lucb40.fnt");
	if (grf_big == NULL)
	    disaster("lucb40.fnt not found");
    }

    grt_centered.txo_bgcolor.v = GrNOCOLOR;
    grt_centered.txo_direct = GR_TEXT_RIGHT;
    grt_centered.txo_xalign = GR_ALIGN_CENTER;
    grt_centered.txo_yalign = GR_ALIGN_CENTER;
    grt_centered.txo_chrtype = GR_BYTE_TEXT;

    grt_left.txo_bgcolor.v = GrNOCOLOR;
    grt_left.txo_direct = GR_TEXT_RIGHT;
    grt_left.txo_xalign = GR_ALIGN_LEFT;
    grt_left.txo_yalign = GR_ALIGN_CENTER;
    grt_left.txo_chrtype = GR_BYTE_TEXT;
}
Esempio n. 2
0
/* Initialize Grfx-Mode&Mouse.Try to use xres,yres,colors and font <fontname>.
   If you are successful, return a 1.
   If you can't initialize this mode, return a 0. */
int ws_initgrfx(int xres, int yres, int colors, const char *fontname) {
    static char pixels[2];
/* unsigned char value; 
    Why?  -jgk*/
    GrBitmap pat_bm = {
        0, 2, pixels, 1, 0, 0
    };


    if ( ( ws_private.textopt.txo_font =
              GrLoadFont( (char *)(fontname == NULL ?
                                   DEFAULT_FONT :
                                   fontname) ) ) == NULL ) {
        fprintf(errf, "Can't find font %s\n", fontname);
        return 0;
    }

    if ( !GrSetMode(GR_width_height_color_graphics, xres, yres, colors) ) {
        fprintf(errf, "Can't set grfx-mode. Try to load VESA-driver\n");
        return 0;
    }

    if (GrSizeX() != xres || GrSizeY() != yres) {
        fprintf(errf, "Can't set grfx-mode. Try to load VESA-driver\n");
        return 0;
    }

    GrClearScreen(0);

    if ( !GrMouseDetect() ) {
        fprintf(errf, "Can't find mouse\n");
        return 0;
    }

    GrMouseInit();
    GrMouseSetColors(255, 0);
    GrMouseDisplayCursor();
    pixels[0] = 0x79;   /* Prevent compiler warning for now */
    pixels[1] = 0x55;
    ws_private.pat_box.gp_bitmap = pat_bm;
/* value=_farpeekb(0x40,0x17);
   _farpokeb(0x40,0x17,value^0x20); */
    return 1;
}
Esempio n. 3
0
int main(int argc, char **argv)
{
	int i, n;
	char *s;
	char *bad = NULL;
	int c;

	int width = 0, height = 0, bpp = 8, gray = 192, attributes = 0;

	char *name, *testname;
	GrFontHeader *hdr;
	FILE *f;
	char buffer[210];
	GrEvent ev;
	int key;

	/* unfortunately not all systems support getopt() */
	for(i = 1; i < argc; i++) {
	    s = argv[i];
	    if(*s != '-' || ((c = *++s) == '\0') || *++s != '\0') break;
	    if(c == '-') {
		i++;
		break;
	    }
	    if(++i == argc) {
		fprintf(stderr, "-%c: argument required\n", c);
		return(1);
	    }
	    if(sscanf(argv[i], "%d", &n) != 1 || n < 0) {
		fprintf(stderr, "%s: invalid argument\n", argv[i]);
		exit(1);
	    }
	    switch(c) {
		case 'x' : width = n; break;
		case 'y' : height = n; break;
		case 'b' : if((bpp = n) < 2 || bpp > 32) bad = "bpp"; break;
		case 'g' : if((gray = n) > 255) bad = "gray"; break;
		case 'X' : if((deltax = n) > 31) bad = "deltax"; break;
		case 'Y' : if((deltax = n) > 31) bad = "deltay"; break;
		case 'a' : if((attributes = n) > 3) bad = "attributes"; break;
		default  : {
		    fprintf(stderr, "-%c: invalid option\n", c);
		    return(1);
		}
	    }
	    if(bad) {
		fprintf(stderr, "%d: %s out of range\n", n, bad);
		return(1);
	    }
	}

	if(i == argc) {
	    printf(
		"usage:\tfontdemo [-x WIDTH] [-y HEIGHT] [-b BPP] [-g COMPONENT]\n"
		      "\t[-X DELTAX] [-Y DELTAY] [-a ATTRIBUTES] FONT [FILE...]\n"
	    );
	    return(0);
	}

	name = argv[i++];
	opt.txo_font = GrLoadFont(name);
        if(opt.txo_font == NULL && (testname = malloc(strlen(name) + 10)) != NULL) {
            /* try again, this is a test and the path can not been set yet */
#if defined(__MSDOS__) || defined(__WIN32__)
            sprintf( testname,"..\\fonts\\%s",name );
#else
            sprintf( testname,"../fonts/%s",name );
#endif
            opt.txo_font = GrLoadFont(testname);
	    free(testname);
        }
	if(opt.txo_font == NULL) {
	    fprintf(stderr, "%s: load error\n", name);
	    return(1);
	}
	hdr = &opt.txo_font->h;

	if(height == 0) {
	    if(width == 0) {
		switch(hdr->height) {
		    case 8 :
		    case 14 : height = 400; break;
		    case 16 : height = 480; break;
		    case 20 : height = 600; break;
		    case 24 : height = 768; break;
		    default : height = hdr->height < 20 ? 480 : 768;
		}
	    }
	    else height = width * 3 / 4;
	}
	if(width == 0) width = height == 400 ? 640 : height * 4 / 3;

	GrSetMode(GR_width_height_bpp_graphics, width, height, bpp);
	if(!gray || (opt.txo_fgcolor.v = GrAllocColor(gray, gray, gray)) == GrNOCOLOR) opt.txo_fgcolor.v = GrWhite();
	if(attributes & 0x02) opt.txo_fgcolor.v |= GR_UNDERLINE_TEXT;
	opt.txo_bgcolor.v = GrBlack();
	if(attributes & 0x01) revert();
	opt.txo_chrtype = GR_BYTE_TEXT;
	opt.txo_direct = GR_TEXT_RIGHT;
	opt.txo_xalign = GR_ALIGN_LEFT;
	opt.txo_yalign = GR_ALIGN_TOP;

	sprintf(buffer, "Font name:%s %dx%d", hdr->name, GrCharWidth('A', &opt), GrCharHeight('A', &opt));
        if (hdr->proportional)
	    strcat(buffer, " proportional");
	else
	    strcat(buffer, " fixed");
	gputs(buffer);
	sprintf(buffer, "Font family: %s", hdr->family);
	gputs(buffer);
	sprintf(buffer, "Min char, num chars: %d, %d", hdr->minchar,hdr->numchars);
	gputs(buffer);
	sprintf(buffer, "Screen res: %dx%d@%lu", GrSizeX(), GrSizeY(), (unsigned long) GrNumColors());
	gputs(buffer);
	gnewl();

	gputs("THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG");
	gputs("the quick brown fox jumps over the lazy dog");
	gnewl();

//	if(hdr->minchar <= 0xC0 && hdr->minchar + hdr->numchars >= 0x100) {
//	    gputs("������� ��� ���� ���� ��");
//	    gputs("������� ��� ���� ���� ��");
//	    gnewl();
//	}

	/* ascii table, or to be precise, a full table of the current font */
	opt.txo_chrtype = GR_WORD_TEXT;
	for(c = 0; c < hdr->numchars; c++) {
	    gputc(hdr->minchar + c);
	    if(c % 0x20 == 0x1F) gnewl();
	}
	gnewl();
	if(c % 0x20 != 0) gnewl();
	opt.txo_chrtype = GR_BYTE_TEXT;

	while(i < argc) {
	    name = argv[i++];
	    if((f = fopen(name, "r")) == NULL) {
		perror(name);
		return(1);
	    }
	    while((c = getc(f)) != EOF) if(c != '\n') gputc(c); else gnewl();
	    if(ferror(f) != 0 || fclose(f) != 0) {
		perror(name);
		return(1);
	    }
	}

	/* enter and esc are < 0x100 and displayed 1:1 */
	gputs("F1-new line  F5-toggle reverse  F7-toggle underline  F10-exit");
	gnewl();

	GrEventInit();
	while(1) {
	    GrEventWait(&ev);
	    if(ev.type == GREV_KEY) {
		key = ev.p1;
		if( key == GrKey_F10) break;
		if(key == GrKey_F1) gnewl();
		else if(key == GrKey_F5) revert();
		else if(key == GrKey_F7) opt.txo_fgcolor.v ^= GR_UNDERLINE_TEXT;
		else if(key < 0x100) gputc(key);
	    }
	}
	GrEventUnInit();

	GrUnloadFont(opt.txo_font);

	return(0);
}