Esempio n. 1
0
/* old LoadFont.c*/
Font
XLoadFont(Display * dpy, _Xconst char *name)
{
 	GR_FONT_ID font = 0;
	int height;
	char *fontname;

DPRINTF("XLoadFont('%s')\n", name);
	/* first try to find XLFD or fontname from X11/fonts.dir and fonts.alias files*/
	fontname = font_findfont((char *)name, 0, 0, &height);
	if(fontname) {
#if HAVE_STATICFONTS
		int size;
		unsigned char *data;

		/* check static font list*/
		if (font_staticGetBufferInfo(fontname, &data, &size))
			font = GrCreateFontFromBuffer(data, size, "TTF", height, height);
		else
#endif
 		font = GrCreateFontEx(fontname, height, height, NULL);
	} else if (!strcmp(name, "fixed")) {
DPRINTF("XLoadFont: mapping 'fixed' to builtin SystemFixed\n");
		/* special-case handle 'fixed' and map to builtin system fixed font*/
		fontname = strdup(MWFONT_SYSTEM_FIXED);
		height = 13;
		font = GrCreateFontEx(fontname, 0, 0, NULL); /* height zero to force builtin lookup by name*/
	}
    GrSetFontAttr(font, GR_TFKERNING | GR_TFANTIALIAS, 0);
DPRINTF("XLoadFont('%s') = '%s' height %d [%d]\n", name, fontname, height, font);
	if (fontname)
		Xfree(fontname);
	return font;
}
Esempio n. 2
0
static void
GrCreateLogFontWrapper(void *r)
{
	nxCreateLogFontReq *req = r;
	GR_FONT_ID fontid;

	fontid = GrCreateFontEx(NULL, 0, 0, &req->lf);

	GsWriteType(current_fd, GrNumCreateLogFont);
	GsWrite(current_fd, &fontid, sizeof(fontid));
}
Esempio n. 3
0
static void
GrCreateFontExWrapper(void *r)
{
	nxCreateFontExReq *req = r;
	GR_FONT_ID 	fontid;

	fontid = GrCreateFontEx(GetReqData(req), req->height, req->width, NULL);

	GsWriteType(current_fd, GrNumCreateFontEx);
	GsWrite(current_fd, &fontid, sizeof(fontid));
}
Esempio n. 4
0
//------------------------------------------------------------------------------
// Function Name  : init_ui_manager()
// Description    : 
//------------------------------------------------------------------------------
BOOL init_ui_manager(void)
{
	CObject* pObject;
	UINT id;

	PRINT_FUNC_CO();
	
	// start nano-x service
	if (GrOpen() < 0) {
	//	DBGMSG(DBG_MAIN, "[Failure]\r\n--> %s: GrOpen Failed!!\r\n", __func__);
		return FALSE;
	}

	GrSetErrorHandler(error_handler);
	GrGetScreenInfo(&g_scr_info);

	// prepare g_font
	g_font = GrCreateFontEx((GR_CHAR *)FONT_PATH, 18, 18, NULL);
	GrSetFontAttr(g_font, (GR_TFKERNING | GR_TFANTIALIAS), 0);

	g_wid = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, g_scr_info.cols, g_scr_info.rows, 0, BLACK, 0);
	if (g_wid == 0) {
	//	DBGMSG(DBG_MAIN, "[Failure]\r\n--> %s: GrNewWindow failure\r\n", __func__);
		GrClose();
		return FALSE;
	}

	g_gc = GrNewGC();

	GrRaiseWindow(g_wid);
	GrMapWindow(g_wid);

	GrSelectEvents(g_wid, GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_EXPOSURE);

	GrSetGCUseBackground(g_gc, FALSE);
//	GrSetGCUseBackground(g_gc, TRUE);
	GrSetGCFont(g_gc, g_font);

//	GrSetGCBackground(g_gc, BLACK);
	GrSetGCForeground(g_gc, WHITE);

//	BuildObject();

	return TRUE;
}
Esempio n. 5
0
int
main(int ac, char **av)
{
	GR_WINDOW_ID window;
	GR_GC_ID gc;
	GR_FONT_ID fontid;
	int x, y, fnum;
	GR_REGION_ID regionid;
#if CLIP_POLYGON
	GR_POINT points[] = { {20, 20}, {300, 20}, {300, 300}, {20, 300} };
#else
	GR_RECT clip_rect = { 20, 20, 300, 300 };
#endif

	if (GrOpen() < 0)
		exit(1);

	window = GrNewWindowEx(GR_WM_PROPS_APPWINDOW,
		"t1demo loadable fonts (truetype, t1lib, pcf, mgl, hzk)",
		GR_ROOT_WINDOW_ID, 50, 50, WIDTH, HEIGHT, BLACK);
	GrSelectEvents(window, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ);
	GrMapWindow(window);

	gc = GrNewGC();
	GrSetGCUseBackground(gc, GR_FALSE);
	GrSetGCBackground(gc, BLACK);

#if CLIP_POLYGON
	/* polygon clip region */
	regionid = GrNewPolygonRegion(MWPOLY_EVENODD, 3, points);
#else
	/* rectangle clip region */
	regionid = GrNewRegion();
	GrUnionRectWithRegion(regionid, &clip_rect);
#endif
	GrSetGCRegion(gc, regionid);

	srand(time(0));
	while (1) {
		GR_EVENT event;

		GrCheckNextEvent(&event);
		if (event.type == GR_EVENT_TYPE_CLOSE_REQ) {
			GrClose();
			exit(0);
		}

		fontid = GrCreateFontEx(names[fnum=RAND(MAXFONTS)], 0, 0, NULL);
		GrSetFontSizeEx(fontid, RAND(80) + 1, RAND(80) + 1);
		GrSetFontRotation(fontid, 330);		/* 33 degrees */
		GrSetFontAttr(fontid, GR_TFKERNING | GR_TFANTIALIAS, 0);
		GrSetGCFont(gc, fontid);

		GrSetGCForeground(gc, rand() & 0xffffff);
		/*GrSetGCBackground(gc, rand() & 0xffffff); */

		x = RAND(WIDTH);
		y = RAND(HEIGHT);

#if HAVE_HZK_SUPPORT
		{
#if HZKBIG5
		/* hzk big5 unicode-16 test*/
		static unsigned short buffer[] = {
		    0x9060, 0x898b, 0x79d1, 0x6280, 0x0061, 0x0041, 0
		};
		GrText(window, gc, x, y, buffer, 7, GR_TFUC16);

		/* hzk big5 dbcs test #1*/
		x = RAND(WIDTH);
		y = RAND(HEIGHT);
		GrText(window, gc, x, y,
		       "Microwindows,Åwªï¨Ï¥Î¤¤­^¤åÂI°}¦rÅé", -1, GR_TFASCII);

		/* hzk big5 dbcs test #2*/
		x = RAND(WIDTH);
		y = RAND(HEIGHT);
		GrText(window, gc, x, y, "£t£u£v£w£¸£¹£º", -1, GR_TFASCII);
#else
	#if 0
		/* hzk test #1*/
		static char buffer[] = {
			0x6c, 0x49, 0x73, 0x8b, 0x79,
			0xd1, 0x62, 0x80, 0x61, 0x00,
			0x41, 0x00, 0x00, 0xa1, 0x00,
			0xa6, 0x6c, 0x49, 0, 0
		};

		/* *static unsigned short buffer[] = {
			0x496c, 0x8b73, 0xd179, 0x8062, 0x0061,
			0x0041, 0xa100, 0xa600, 0x496c, 0
		};***/

		GrText(window, gc, x, y, buffer, 9, GR_TFUC16);
	#endif
		/* HZK Metrix font test, includes Chinese and English */
		x = RAND(WIDTH);
		y = RAND(HEIGHT);
		GrText(window, gc, x, y,
		       "Microwindows,»¶Ó­Ê¹ÓÃÖÐÓ¢ÎĵãÕó×ÖÌå", -1, GR_TFASCII);
#endif /* HZKBIG5*/
		}
#elif HAVE_BIG5_SUPPORT
		/* encoding BIG5 test 61 B1 64 B1 64 61 */
		GrText(window, gc, x, y, "\151\261\144\261\144\151", 6, MWTF_DBCS_BIG5);
#elif HAVE_GB2312_SUPPORT
		/* encoding GB2312 test BD A1 BD A1 */
		GrText(window, gc, x, y, "\275\241\275\241", 4, MWTF_DBCS_GB);
#elif HAVE_EUCJP_SUPPORT
		/* encoding EUC_JP test A2 A1 */
		GrText(window, gc, x, y, "ï¿½Þ¥ï¿½ï¿½ï¿½ï¿½í¥¦ï¿½ï¿½ï¿½ï¿½ï¿½É¥ï¿½ï¿½ï¿½ï¿½Ø¤è¤¦ï¿½ï¿½ï¿½ï¿½!", -1, MWTF_DBCS_EUCJP);
#elif HAVE_JISX0213_SUPPORT
		/* encoding JISX0213 test A2 A1 */
		GrText(window, gc, x, y, "\242\241", 2, MWTF_DBCS_JIS);
#elif HAVE_KSC5601_SUPPORT
		/* encoding KSC5601 test B0 B0 */
		GrText(window, gc, x, y, "\273\273", 2, MWTF_DBCS_EUCKR);
#elif HAVE_FREETYPE_2_SUPPORT
		/* ASCII test */
		GrText(window, gc, x, y, "Microwindows", -1, GR_TFASCII);
#elif HAVE_PCF_SUPPORT
		/* note: large PCF fonts require XCHAR2B, this is not
		   figured out yet for these fonts.  FIXME */
		if (fnum == 3) {
			/* japanese jiskan24*/
			unsigned short text[] =
			    { 0x213a, 0x213b, 0x2170, 0x2276, 0x2339 };
			GrText(window, gc, x,y, text, 5, GR_TFUC16);
		} else if (fnum == 4) {
			/* chinese gb24st*/
			unsigned short text[] =
			    /* FIXME: why doesn't first row index correctly?*/
			    /*{ 0x7765, 0x7766, 0x7767, 0x777a, 0x777e };*/
			    { 0x2129, 0x212a, 0x212b, 0x212c, 0x212d };
			GrText(window, gc, x,y, text, 5, GR_TFUC16);
		} else
			GrText(window, gc, x,y, "Microwindows", -1, GR_TFASCII);
#elif HAVE_FNT_SUPPORT
		/* UC16 test */
		if (fnum == 2 || fnum == 3) {
			/* japanese jiskan24, jiskan16-2000-1*/
			unsigned short text[] =
			    { 0x213a, 0x213b, 0x2170, 0x2276, 0x2339 };
			GrText(window, gc, x,y, text, 5, GR_TFUC16);
		} else if (fnum == 4) {
			/* chinese gbk16-xke*/
			unsigned short text[] =
			    { 0x8144, 0x8147, 0x8148, 0xfe4e, 0xfe4f };
			GrText(window, gc, x,y, text, 5, GR_TFUC16);
		} else
			GrText(window, gc, x,y, "Microwindows", -1, GR_TFASCII);
#else
		/* ASCII test */
		GrText(window, gc, x, y, "Microwindows", -1, GR_TFASCII);
#endif
		GrFlush();
		GrDestroyFont(fontid);
	}
	GrDestroyRegion(regionid);
	GrClose();
	return 0;
}
Esempio n. 6
0
int
main(int ac,char **av)
{
	GR_WINDOW_ID 	w;
	GR_GC_ID	gc;
	GR_FONT_ID	font;
	GR_WINDOW_INFO wi;

	if (GrOpen() < 0) {
		GrError("Can't open graphics\n");
		return 1;
	}

	//w = GrNewWindowEx(GR_WM_PROPS_APPWINDOW|GR_WM_PROPS_NOBACKGROUND, "Nano-X Demo2",
		//GR_ROOT_WINDOW_ID, 20, 20, 320, 240, BLACK);
	w = GrNewWindowEx(GR_WM_PROPS_BORDER|GR_WM_PROPS_NOBACKGROUND, "Nano-X Demo2",
		GR_ROOT_WINDOW_ID, 20, 20, 320, 240, BLACK);

	gc = GrNewGC();
	//font = GrCreateFontEx("lubI24.pcf", 0, 0, NULL);
	font = GrCreateFontEx("helvB12.pcf.gz", 0, 0, NULL);
	GrSetGCFont(gc, font);

	GrSelectEvents(w, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ
		| GR_EVENT_MASK_BUTTON_DOWN | GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP);
	GrMapWindow(w);
	GrSetFocus(w);

	// pass errors through main loop
	GrSetErrorHandler(NULL);

	for (;;) {
		GR_EVENT 	event;

		GrGetNextEvent(&event);

		switch (event.type) {
		case GR_EVENT_TYPE_EXPOSURE:
			GrSetGCForeground(gc,GrGetSysColor(GR_COLOR_APPWINDOW));
			GrFillRect(w, gc, event.exposure.x, event.exposure.y,
				event.exposure.width, event.exposure.height);
			GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_APPTEXT));
			GrSetGCUseBackground(gc, GR_FALSE);
			GrText(w, gc, 10, 30, "Hello World", -1, GR_TFASCII);
            GrRect(w, gc, 5, 5, 300, 60);
			GrGetWindowInfo(w, &wi);
			GrError("Exposure:wi.width:%d,wi.height:%d,wi.x:%d,wi.y:%d,wi.parent:%d\n",wi.width,wi.height,wi.x,wi.y,wi.parent);
			break;

		case GR_EVENT_TYPE_BUTTON_DOWN:
			// FIXME unmap window is broken
			GrUnmapWindow(w);
			GrFlush();
			GrMapWindow(w);

			//uncomment to test server error on bad syscall
			//GrMoveWindow(GR_ROOT_WINDOW_ID, 0, 0);

			GrGetWindowInfo(w, &wi);
			GrError("Button:  wi.width:%d,wi.height:%d,wi.x:%d,wi.y:%d,wi.parent:%d\n",wi.width,wi.height,wi.x,wi.y,wi.parent);
			break;

		case GR_EVENT_TYPE_ERROR:
			GrError("demo2: Error (%s) ", event.error.name);
			GrError(nxErrorStrings[event.error.code], event.error.id);
			break;

		case GR_EVENT_TYPE_CLOSE_REQ:
			GrClose();
			return 0;
		}
	}
	return 0;
}
Esempio n. 7
0
int
main(int argc,char **argv)
{
	GR_EVENT	event;		/* current event */
	struct app_info	* act;
	int		width, height;

#ifdef USE_WEIRD_POINTER
	GR_BITMAP	bitmap1fg[7];	/* bitmaps for first cursor */
	GR_BITMAP	bitmap1bg[7];
#endif

	for(act = Apps; act->app_id[0] != '\0'; act++, num_apps++);

	if (GrOpen() < 0) {
		GrError("cannot open graphics\n");
		return 1;
	}
	
	GrGetScreenInfo(&si);

	signal(SIGCHLD, &reaper);

	gc = GrNewGC();
	bgc = GrNewGC();

	GrSetGCForeground(bgc, GRAY);
	GrSetGCFont(gc, GrCreateFontEx(GR_FONT_SYSTEM_FIXED, 0, 0, NULL));

	GrGetGCTextSize(gc, "A", 1, GR_TFASCII, &fwidth, &fheight, &fbase);
	width = fwidth * 8 + 4;
	height = (fheight) * num_apps + 4;

	w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 5, 5, width,
		height, 1, WHITE, BLACK);

	GrSelectEvents(w1, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN
			| GR_EVENT_MASK_CLOSE_REQ);
	GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_EXPOSURE |
					GR_EVENT_MASK_CHLD_UPDATE);

	GrMapWindow(w1);

#ifdef USE_WEIRD_POINTER
	bitmap1bg[0] = MASK(_,_,X,X,X,_,_);
	bitmap1bg[1] = MASK(_,X,X,X,X,X,_);
	bitmap1bg[2] = MASK(_,X,X,X,X,X,_);
	bitmap1bg[3] = MASK(_,X,X,X,X,X,_);
	bitmap1bg[4] = MASK(_,X,X,X,X,X,_);
	bitmap1bg[5] = MASK(_,X,X,X,X,X,_);
	bitmap1bg[6] = MASK(X,X,X,X,X,X,X);

	bitmap1fg[0] = MASK(_,_,_,_,_,_,_);
	bitmap1fg[1] = MASK(_,_,_,X,_,_,_);
	bitmap1fg[2] = MASK(_,_,X,X,X,_,_);
	bitmap1fg[3] = MASK(_,_,X,X,X,_,_);
	bitmap1fg[4] = MASK(_,_,X,X,X,_,_);
	bitmap1fg[5] = MASK(_,_,X,X,X,_,_);
	bitmap1fg[6] = MASK(_,X,X,X,X,X,_);

	GrSetCursor(w1, 7, 7, 3, 3, WHITE, BLACK, bitmap1fg, bitmap1bg);
#endif

	GrFillRect(GR_ROOT_WINDOW_ID, bgc, 0, 0, si.cols, si.rows);

	GrSetGCForeground(gc, BLACK);
	GrSetGCBackground(gc, WHITE);

	while (1) {
		GrGetNextEvent(&event);

		switch (event.type) {
			case GR_EVENT_TYPE_EXPOSURE:
				do_exposure(&event.exposure);
				break;
			case GR_EVENT_TYPE_BUTTON_DOWN:
				do_buttondown(&event.button);
				break;
			case GR_EVENT_TYPE_BUTTON_UP:
				do_buttonup(&event.button);
				break;
			case GR_EVENT_TYPE_UPDATE:
				do_update(&event.update);
				break;
			case GR_EVENT_TYPE_MOUSE_POSITION:
				do_mouse(&event.mouse);
				break;
			case GR_EVENT_TYPE_CLOSE_REQ:
				GrClose();
				return 0;
		}
	}
}
Esempio n. 8
0
int
main(int argc, char **argv)
{
	GR_WINDOW_ID main_wid;
	GR_TIMEOUT timeout;
	int width, height;

	if (argc != 2)
		return (-1);

	if (GrOpen() == -1)
		return (-1);

	font = GrCreateFontEx(argv[1], 12, 12, 0);
	if (!font)
		printf("Unable to load %s\n", argv[1]);

	GrGetFontInfo(font, &finfo);

	printf("font_id = %d\n", font);
	printf("First char = %d, last char = %d\n", finfo.firstchar, finfo.lastchar);
	printf("Max width = %d, max height = %d\n", finfo.maxwidth, finfo.height);
	printf("baseline = ascent = %d, descent = %d\n", finfo.baseline, finfo.descent);
	printf("max ascent = %d, max descent = %d\n", finfo.maxascent, finfo.maxdescent);
	printf("linespacing = %d, fixed = %s\n", finfo.linespacing, finfo.fixed? "yes": "no");

//	finfo.firstchar = 0;	/* force display of undefined chars, test with jiskan24.pcf.gz*/

	/* determine window metrics*/
	width = (finfo.maxwidth + spacer) * line_width + 2 * border - spacer;
	if (width > 640) {
		line_width /= 2;
		lines *= 2;
		width = (finfo.maxwidth + 2) * line_width + 2 * border - spacer;
    }
	height = lines * (finfo.height + spacer) + 2 * border - spacer;
	chars_to_show = lines * line_width;

	/* create the main application window*/
	main_wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "pcfdemo",
			GR_ROOT_WINDOW_ID, 0, 0, width, height, BLACK);
	GrSelectEvents(main_wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ);
	GrMapWindow(main_wid);

	if (finfo.lastchar >= chars_to_show)
		timeout = 8 * 1000;
    else timeout = 0;

	while (1) {
		GR_EVENT event;
		GrGetNextEventTimeout(&event, timeout);

		if (event.type == GR_EVENT_TYPE_TIMEOUT) {
			first_char += chars_to_show;
            draw_string(main_wid);
		}
		if (event.type == GR_EVENT_TYPE_EXPOSURE)
			draw_string(main_wid);
		if(event.type == GR_EVENT_TYPE_CLOSE_REQ) {
			GrClose();
			exit(0);
	   }
	}
}
Esempio n. 9
0
int main(int argc, char **argv)
{
  FILE *file;
  GR_EVENT event;
  GR_WINDOW_ID window;

  if (GrOpen() < 0) {
	fprintf(stderr, "cannot open graphics\n");
	exit(1);
  }

  window = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "ftdemo",
  	GR_ROOT_WINDOW_ID, 50,50, MAXW,MAXH, WHITE);
  GrMapWindow(window);

  gid = GrNewGC ();
  GrSelectEvents(window, GR_EVENT_MASK_KEY_DOWN |
		GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE);

  if ((file = fopen("/demo/ftdemo.txt", "r")) == NULL) {
	printf("Can't open text file\n");
	return (-1);
  }

  n = 0;

  if(fgets(buffer, 128, file) != NULL) {
  	for (n = 0; n < 128 && buffer[n]; n++) {
		if (buffer[n] == '\n')
			break;
	}
  }
  fclose(file);

  fontid = GrCreateFontEx(FONTNAME, 20, 20, NULL);
  fontid2 = GrCreateFontEx(FONTNAME, 36, 36, NULL);

  Render(window);
 
  while (1) {
    GrGetNextEvent(&event);

    switch (event.type) {
    case GR_EVENT_TYPE_KEY_DOWN:
      switch(event.keystroke.ch) {
        case 171: /* + */
        case '+':
        case '=':
          angle += 100; /* Increase 10 degrees */
          angle %= 3600;
          break;
        case 173: /* - */
        case '-':
        case '_':
          angle -= 100; /* Decrease 10 degrees */
          angle %= 3600;
          break;
        case 'a':
          aa = !aa;
          break;
        case 'b':
          bold = !bold;
          break;
        case 'k':
          kerning = !kerning;
          break;
        case 'l':
          state = (state == GR_TFBOTTOM)?GR_TFBASELINE:
                  (state == GR_TFBASELINE)?GR_TFTOP:GR_TFBOTTOM;
          break;
        case 'u':
          underline = underline? GR_FALSE: GR_TRUE;
          break;
        default:
          continue;
          /* Unknown keystroke */
      }
      Render(window);
      break;
    case GR_EVENT_TYPE_EXPOSURE:
      Render(window);
      break;
    case GR_EVENT_TYPE_CLOSE_REQ:
      GrClose();
      exit(0);
    }
  }

  return 0;
}