/* * builtinfont - demonstrate unicode builtin font loading for Nano-X */ #include #include #define MWINCLUDECOLORS #include "nano-X.h" GR_FONT_ID font = 0; GR_WINDOW_ID main_wid; GR_FONT_INFO finfo; static void drawSymbol(void) { int x = 10; int y = 10; unsigned short tmp = 1024; //This should be the first symbol of cyrillic alphabet GR_GC_ID gc = GrNewGC(); GrSetGCFont(gc, font); GrSetGCForeground(gc, GR_RGB(255, 255, 255)); //GrSetGCBackground(gc, GR_RGB(0, 0, 0)); //this crash the application GrSetGCUseBackground(gc, GR_FALSE); GrText(main_wid, gc, x, y, &tmp, 1, GR_TFTOP | GR_TFUC16); GrText(main_wid, gc, x, y+20, "ASCII", 5, GR_TFTOP | GR_TFASCII); GrDestroyGC(gc); } static void drawFileUTF8(const char * fname){ /* see static int utf8_to_utf16(const unsigned char *utf8, int cc, unsigned short *unicode16) in microwin_cvs/src/engine/devfont.c for text array type */ unsigned char buf[20]; int x = 10; int y = 50; FILE * pfile; GR_GC_ID gc = GrNewGC(); GrSetGCFont(gc, font); GrSetGCForeground(gc, GR_RGB(255, 255, 255)); GrSetGCUseBackground(gc, GR_FALSE); pfile = fopen(fname, "r"); if( pfile > 0 ){ fread(buf, 1, 20, pfile); GrText(main_wid, gc, x, y, buf, 20, GR_TFTOP | GR_TFUTF8); fclose(pfile); } GrDestroyGC(gc); } static void drawFileUC16(const char * fname){ /* see static int utf8_to_utf16(const unsigned char *utf8, int cc, unsigned short *unicode16) in microwin_cvs/src/engine/devfont.c for text array type */ unsigned short buf[20]; int x = 10; int y = 70; FILE * pfile; GR_GC_ID gc = GrNewGC(); GrSetGCFont(gc, font); GrSetGCForeground(gc, GR_RGB(255, 255, 255)); GrSetGCUseBackground(gc, GR_FALSE); pfile = fopen(fname, "r"); if( pfile > 0 ){ fread(buf, 1, 20, pfile); GrText(main_wid, gc, x, y, buf, 20, GR_TFTOP | GR_TFUC16); fclose(pfile); } GrDestroyGC(gc); } int main(int argc, char **argv) { int width, height; if (GrOpen() == -1) return (-1); font = GrCreateFont("DejaVuSans", 19, 0); if (!font) printf("Unable to load font\n"); GrGetFontInfo(font, &finfo); width = ((finfo.maxwidth + 2) * 16); height = (((finfo.lastchar - finfo.firstchar) / 16) + 5) * finfo.height; main_wid = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, "builtinfont", GR_ROOT_WINDOW_ID, 0, 0, width, height, BLACK); GrSelectEvents(main_wid, GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_CLOSE_REQ); GrMapWindow(main_wid); while (1) { GR_EVENT event; GrGetNextEvent(&event); if (event.type == GR_EVENT_TYPE_EXPOSURE) drawSymbol(); drawFileUTF8("utf8.txt"); drawFileUC16("unicode.txt"); if(event.type == GR_EVENT_TYPE_CLOSE_REQ) { GrClose(); exit(0); } } }