📄 wfnttest.c
字号:
/* Copyright 2000 Wind River Systems, Inc. All Rights Reserved *//* wfnttest.c Font test application for WindML *//*modification history--------------------01g,22feb02,msr Backward compatability for input API.01f,29jan02,rbp Addition of support for Native Unix.01e,28aug01,rbp Fix for __unix__ macro.01h,05nov01,gav Fixed misnamed devIds01g,05nov01,gav Change to new registry01f,05nov01,gav Change to new registry01e,09oct01,msr Ported to new UGL_Q_EVENT architecture.01d,19dec00,gav Entry point identical to filename w/o extension.01c,28nov00,gav Conditional compilation around metric discrepency flagging.01b,14nov00,gav Fixed font line display clearing.01a,24oct00,gav Miscellaneous clean-up.*//*DESCRIPTIONThis application opens all of the fonts available and displays themone at a time. The user change the font displayed by using the arrowand page keys. For fonts that are multibyte/Unicode, the arrow keys,home, and end keys can be used to display different pages.Glyphs that may have a metric error are displayed on a colored background.*/#include <stdio.h>#include <ugl/ugl.h>#include <ugl/uglos.h>#include <ugl/uglinput.h>#include <ugl/uglMsg.h>#include <ugl/uglfont.h>#include <ugl/uglucode.h>/* #include <ugl/driver/graphics/generic/udgen.h> */UGL_LOCAL int windMLTestFont (void);#define BLACK (0)#define BLUE (1)#define GREEN (2)#define YELLOW (3)#define WHITE (4)UGL_LOCAL volatile UGL_BOOL stopTest;UGL_LOCAL int displayHeight, displayWidth;UGL_LOCAL int bannerHeight;UGL_LOCAL int x,y;UGL_LOCAL UGL_DEVICE_ID devId;UGL_LOCAL UGL_GC_ID gc;UGL_LOCAL UGL_FONT_ID fontBanner;UGL_LOCAL UGL_FONT_ID *glyphFontId;UGL_LOCAL UGL_FONT_METRICS metric;UGL_LOCAL UGL_INT16 page, maxPage = 255;UGL_FONT_DRIVER_ID fontDrvId;UGL_INT16 fontNum, fontCount;UGL_INPUT_SERVICE_ID inputServiceId;UGL_LOCAL struct _colorStruct { UGL_ARGB rgbColor; UGL_COLOR uglColor; }colorTable[] = { { UGL_MAKE_RGB(0, 0, 0), 0}, /* Black */ { UGL_MAKE_RGB(0, 0, 168), 0}, /* Blue */ { UGL_MAKE_RGB(0, 168, 0), 0}, /* Green */ { UGL_MAKE_RGB(255, 255, 84), 0}, /* Yellow */ { UGL_MAKE_RGB(255, 255, 255), 0} /* White */ };/** This function finds all of the installed fonts and makes them available* for use by the program.*/UGL_LOCAL void acquireFonts(void) { UGL_STATUS status; UGL_FONT_DESC fontDesc; UGL_SEARCH_ID fontSrchId; UGL_FONT_DEF fontDef; /* If these are don't cares, the same font is always returned. */ UGL_FONT_DESC_PRIORITY fdPriority = {1,2,3,4,5,6}; /* Find how many fonts we need to track so we can allocate memory. */ fontCount = 0; fontSrchId = uglFontFindFirst(fontDrvId, &fontDesc); if (fontSrchId == 0) { glyphFontId = UGL_NULL; return; } fontCount++; for(;;) { if ((status = uglFontFindNext(fontDrvId, &fontDesc, fontSrchId)) == UGL_STATUS_ERROR) { printf("The the iterating font finder broke.\n"); return; } if (status == UGL_STATUS_FINISHED) break; fontCount++; } uglFontFindClose(fontDrvId,fontSrchId); /* Allocate an Id array to hold all of the fonts to be created. */ if ((glyphFontId = (UGL_FONT_ID *)UGL_MALLOC(fontCount * sizeof(UGL_FONT_ID))) == 0) { printf("Couldn't allocate the memory for the font ID array.\n"); return; } /* * At one time we couldn't call uglFontFind from within a First-Next * construct, so we did this... */ /* For each font... */ printf("\n %d fonts found.\n",fontCount); for (fontNum = 0; fontNum < fontCount; fontNum++) { UGL_INT16 i; /* Walk the list as far as we need. */ fontSrchId = uglFontFindFirst(fontDrvId, &fontDesc); if (fontSrchId == 0) { UGL_FREE(glyphFontId); glyphFontId = UGL_NULL; return; } i = 0; while(i < fontNum) { if ((status = uglFontFindNext(fontDrvId, &fontDesc, fontSrchId)) == UGL_STATUS_ERROR) { UGL_FREE(glyphFontId); glyphFontId = UGL_NULL; printf("The the iterating font finder broke.\n"); return; } i++; } uglFontFindClose(fontDrvId,fontSrchId); if (uglFontFind(fontDrvId, &fontDesc, &fdPriority, &fontDef) == UGL_STATUS_ERROR) { UGL_FREE(glyphFontId); glyphFontId = UGL_NULL; printf("The the font finder broke.\n"); printf("fontNum = %d\n",fontNum); return; } if ((glyphFontId[fontNum] = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL) { UGL_FREE(glyphFontId); glyphFontId = UGL_NULL; printf("The the font maker broke.\n"); return; } } }/* Put a page of glyphs on the screen. */UGL_LOCAL void pagePaint (void) { UGL_SIZE textWidth, textHeight; UGL_SIZE fontWidth, fontHeight, cellWidth, cellHeight; UGL_WCHAR output[] = { 0, 0 }; UGL_SIZE ix, iy; UGL_BOOL wide; char snum[80]; uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[BLACK].uglColor); uglRectangle(gc,0,bannerHeight, displayWidth - 1, displayHeight - 1); /* The 'metric' of a font includes its height, width, name, etc. */ uglFontSet(gc, glyphFontId[fontNum]); if (uglFontMetricsGet(glyphFontId[fontNum], &metric) != 0) { printf("uglFontMetricsGet failed.\n"); return; } /* Use the font's information for formating the display of glyphs. */ fontWidth = metric.maxAdvance; fontHeight = metric.maxAscent + metric.maxDescent; cellWidth = fontWidth + 4; cellHeight = fontHeight + 4; /* Test to see if the driver supports wide character sets. */ output[0] = 'M'; if (uglTextSizeGetW(glyphFontId[fontNum], &textWidth, &textHeight, 1, output) == UGL_STATUS_ERROR) { wide = UGL_FALSE; output[0] = 0; } else { wide = UGL_TRUE; /* * If the driver and the font support wide character sets, then use * page value. */ output[0] = 0; output[0] |= page << 8; } uglForegroundColorSet(gc, colorTable[GREEN].uglColor); /* Draw the grid to contain the glyphs. */ for (iy = 0; iy <= 16; iy++) uglLine(gc, 0,iy * cellHeight + (bannerHeight << 1) + 3, 16 * cellWidth, iy * cellHeight + (bannerHeight << 1) + 3); for (ix = 0; ix <= 16; ix++) uglLine(gc, ix * cellWidth, (bannerHeight << 1) + 3, ix * cellWidth, 16 * cellHeight + (bannerHeight << 1) + 3); uglForegroundColorSet(gc, colorTable[WHITE].uglColor); /* Draw the glyphs */ for (iy = 0; iy < 16; iy++) for (ix = 0; ix < 16; ix++) { /* Check the font itself for any metric errors. */ if (wide) uglTextSizeGetW(glyphFontId[fontNum], &textWidth, &textHeight, 1, output); else uglTextSizeGet(glyphFontId[fontNum], &textWidth, &textHeight, 1, (char *) output);#if defined(GLYPH_METRIC_FLAGGING) if (textWidth > fontWidth || textHeight > fontHeight || textHeight < 0 || textWidth < 0) { uglForegroundColorSet(gc, colorTable[GREEN].uglColor); uglBackgroundColorSet(gc, colorTable[YELLOW].uglColor); uglRectangle(gc, ix * cellWidth, iy * cellHeight + (bannerHeight << 1) + 3, (ix + 1) * cellWidth, (iy + 1) * cellHeight + (bannerHeight << 1) + 3); uglForegroundColorSet(gc, colorTable[BLACK].uglColor); if (wide) uglTextDrawW(gc, ix * cellWidth + 2, iy * cellHeight + (bannerHeight << 1) + 5, 1, output); else uglTextDraw(gc, ix * cellWidth + 2, iy * cellHeight + (bannerHeight << 1) + 5, 1, (char *) output); uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[WHITE].uglColor); } else#endif { if (wide) uglTextDrawW(gc, ix * cellWidth + 2, iy * cellHeight + (bannerHeight << 1) + 5, 1, output); else uglTextDraw(gc, ix * cellWidth + 2, iy * cellHeight + (bannerHeight << 1) + 5, 1, (char *) output); } if (wide) output[0]++; else ((char *)output)[0]++; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -