📄 udbmffnt.c
字号:
} else if (pBMFFont == pBMFFontDriver->pLastFont) { pBMFFontDriver->pLastFont = pBMFFont->pPrevFont; if (UGL_NULL != pBMFFontDriver->pLastFont) { pBMFFontDriver->pLastFont->pNextFont = UGL_NULL; } } else { UGL_BMF_FONT * pBMFFont = pBMFFontDriver->pFirstFont; while (UGL_NULL != pBMFFont && pBMFFont->pNextFont != (UGL_BMF_FONT *)pFont) { pBMFFont = pBMFFont->pNextFont; } if (UGL_NULL != pBMFFont) { pBMFFont->pNextFont = ((UGL_BMF_FONT *)pFont)->pNextFont; if (UGL_NULL != pBMFFont->pNextFont) { pBMFFont->pNextFont->pPrevFont = pBMFFont; } } else { status = UGL_STATUS_ERROR; } } /* Free up the glyph cache entrys */ if (UGL_STATUS_OK == status) {#ifdef INCLUDE_UGL_UNICODE int i; for (i = 0; i < 256; i++) if (pBMFFont->pageTable[i]) { int j; for (j = 0; j < 256; j++) { void ** ppPageData = &(*pBMFFont->pageTable[i])[j]; /* Make sure element is in cache first */ if (*ppPageData && 0 == *(UGL_UINT8 *)*ppPageData) uglBMFGlyphCacheFree((UGL_FONT_DRIVER *)pBMFFontDriver, ppPageData); } }#else /*INCLUDE_UGL_UNICODE */ int j; for (j = 0; j < 256; j++) { void ** ppPageData = &pBMFFont->pageZero[j]; if (*ppPageData && 0 == *(UGL_UINT8 *)*ppPageData) uglBMFGlyphCacheFree((UGL_FONT_DRIVER *)pBMFFontDriver, ppPageData); }#endif /*INCLUDE_UGL_UNICODE */ UGL_FREE(pFont); pFont = UGL_NULL; } } uglOSUnlock(pBMFFontDriver->lockId); return(status); }/***************************************************************************** uglBMFFontDriverDestroy - ** NOMANUAL**/UGL_LOCAL UGL_STATUS uglBMFFontDriverDestroy ( UGL_FONT_DRIVER * pFontDriver ) { UGL_STATUS status = UGL_STATUS_OK; UGL_BMF_FONT_DRIVER * pBMFFontDriver = (UGL_BMF_FONT_DRIVER *)pFontDriver; /* Destroy any remaining fonts that may still exist. However, the application really should take care of this first */ if (pBMFFontDriver->pFirstFont != UGL_NULL) { UGL_BMF_FONT * pBMFFont = pBMFFontDriver->pFirstFont; UGL_BMF_FONT * pNextBMFFont; while(pBMFFont != UGL_NULL) { pNextBMFFont = pBMFFont->pNextFont; pBMFFont->referenceCount = 1; (*pFontDriver->fontDestroy)((UGL_FONT *)pBMFFont); pBMFFont = pNextBMFFont; } } uglOSLockDelete(pBMFFontDriver->lockId); /* Delete lock */ UGL_FREE(pFontDriver); pFontDriver = UGL_NULL; return(status); }/***************************************************************************** uglBMFFontFindFirst - ** NOMANUAL**/UGL_LOCAL UGL_SEARCH_ID uglBMFFontFindFirst ( UGL_FONT_DRIVER * pFontDriver, UGL_FONT_DESC * pFontDescriptor ) { UGL_SEARCH_ID searchId = UGL_NULL_ID; if (uglBMFFontData[0] != UGL_NULL) { searchId = (UGL_SEARCH_ID)UGL_MALLOC(sizeof (UGL_SEARCH_ID)); *pFontDescriptor = *(UGL_FONT_DESC *)(uglBMFFontData[0]); *(UGL_UINT32 *)searchId = 1; } return(searchId); }/***************************************************************************** uglBMFFontFindNext - ** NOMANUAL**/UGL_LOCAL UGL_STATUS uglBMFFontFindNext ( UGL_FONT_DRIVER * pFontDriver, UGL_FONT_DESC * pFontDescriptor, UGL_SEARCH_ID searchId ) { if(searchId == UGL_NULL_ID) return (UGL_STATUS_ERROR); if (uglBMFFontData[*(UGL_UINT32 *)searchId] != UGL_NULL) { *pFontDescriptor = *(UGL_FONT_DESC *)(uglBMFFontData[*(UGL_UINT32 *)searchId]); (*(UGL_UINT32 *)searchId)++; return (UGL_STATUS_OK); } else return (UGL_STATUS_FINISHED); }/***************************************************************************** uglBMFFontFindClose - ** NOMANUAL**/UGL_LOCAL UGL_STATUS uglBMFFontFindClose ( UGL_FONT_DRIVER * pFontDriver, UGL_SEARCH_ID searchId ) { if (searchId == UGL_NULL_ID) return (UGL_STATUS_ERROR); UGL_FREE (searchId); searchId = UGL_NULL_ID; return(UGL_STATUS_OK); }/***************************************************************************** uglBMFFontDriverInfo - ** NOMANUAL**/UGL_LOCAL UGL_STATUS uglBMFFontDriverInfo ( UGL_FONT_DRIVER * pFontDriver, UGL_INFO_REQ infoRequest, void * pInfo ) { UGL_STATUS status = UGL_STATUS_ERROR; switch (infoRequest) { /* This should not be done after uglInitialize() */ case UGL_BMF_GLYPH_CACHE_CONFIG: { UGL_BMF_FONT_DRIVER * pBMFFontDriver = (UGL_BMF_FONT_DRIVER *)pFontDriver; if(uglBMFCacheConfig != UGL_FALSE) return(UGL_STATUS_ERROR); if(UGL_NULL != pInfo) { if (((UGL_BMF_CACHE_CONFIG *)pInfo)->glyphCacheSize < 0) { pBMFFontDriver->glyphCacheSize = UGL_BMF_GLYPH_CACHE_SIZE_MAX; } pBMFFontDriver->glyphCacheSize = ((UGL_BMF_CACHE_CONFIG *)pInfo)->glyphCacheSize; pBMFFontDriver->glyphCachePoolId = ((UGL_BMF_CACHE_CONFIG *)pInfo)->glyphCachePoolId; uglBMFCacheConfig = UGL_TRUE; status = UGL_STATUS_OK; } else status = UGL_STATUS_ERROR; } break; case UGL_FONT_TEXT_ORIGIN: { UGL_BMF_FONT_DRIVER * pBMFFontDriver = (UGL_BMF_FONT_DRIVER *)pFontDriver; if(UGL_NULL != pInfo) { if(*(UGL_ORD *)pInfo == UGL_FONT_TEXT_UPPER_LEFT || *(UGL_ORD *)pInfo == UGL_FONT_TEXT_BASELINE) { pBMFFontDriver->textOrigin = *(UGL_ORD *)pInfo; status = UGL_STATUS_OK; } else status = UGL_STATUS_ERROR; } else status = UGL_STATUS_ERROR; } break; default: return (UGL_STATUS_ERROR); } return(status); }/***************************************************************************** uglBMFFontMetricsGet - ** NOMANUAL**/UGL_LOCAL UGL_STATUS uglBMFFontMetricsGet ( UGL_FONT * pFont, UGL_FONT_METRICS * pFontMetrics ) { UGL_BMF_FONT *pBMFFont = (UGL_BMF_FONT *)pFont; pFontMetrics->pixelSize = pBMFFont->pBMFFontDesc->header.pixelSize.min; pFontMetrics->weight = pBMFFont->pBMFFontDesc->header.weight.min; pFontMetrics->italic = pBMFFont->pBMFFontDesc->header.italic; pFontMetrics->maxAscent = pBMFFont->pBMFFontDesc->maxAscent; pFontMetrics->maxDescent = pBMFFont->pBMFFontDesc->maxDescent; pFontMetrics->maxAdvance = pBMFFont->pBMFFontDesc->maxAdvance; pFontMetrics->height = pFontMetrics->maxAscent + pFontMetrics->maxDescent; pFontMetrics->leading = pBMFFont->pBMFFontDesc->leading; pFontMetrics->spacing = pBMFFont->pBMFFontDesc->header.spacing; pFontMetrics->fontType = UGL_FONT_BITMAPPED; pFontMetrics->scalable = UGL_FALSE; pFontMetrics->charSet = pBMFFont->pBMFFontDesc->header.charSet; strncpy(pFontMetrics->faceName, pBMFFont->pBMFFontDesc->header.faceName, UGL_FONT_FACE_NAME_MAX_LENGTH); pFontMetrics->faceName[UGL_FONT_FACE_NAME_MAX_LENGTH - 1] = 0; strncpy(pFontMetrics->familyName, pBMFFont->pBMFFontDesc->header.familyName, UGL_FONT_FAMILY_NAME_MAX_LENGTH); pFontMetrics->familyName[UGL_FONT_FAMILY_NAME_MAX_LENGTH - 1] = 0; return(UGL_STATUS_OK); }/***************************************************************************** uglBMFFontRotationAngleSet - Unsupported in BMF driver** This function is a stub for the uglFontRotationAngleSet() function.* The BMF driver does not implement any functionality for this feature.**/UGL_LOCAL UGL_STATUS uglBMFFontRotationAngleSet ( UGL_FONT * pFont, UGL_ORD angle ) { return(UGL_STATUS_ERROR); }/***************************************************************************** uglBMFFontSizeSet - Unsupported in BMF driver** This function is a stub for the uglFontSizeSet() function.* The BMF driver does not implement any functionality for this feature.**/UGL_LOCAL UGL_STATUS uglBMFFontSizeSet ( UGL_FONT * pFont, UGL_SIZE size ) { return(UGL_STATUS_ERROR); }/***************************************************************************** uglBMFFontWeightSet - Unsupported in BMF driver** This function is a stub for the uglFontWeightSet() function. * The BMF driver does not implement any functionality for this feature.**/UGL_LOCAL UGL_STATUS uglBMFFontWeightSet ( UGL_FONT * pFont, UGL_SIZE weight ) { return(UGL_STATUS_ERROR); }/***************************************************************************** uglBMFTextDraw - draw text** NOMANUAL**/UGL_LOCAL UGL_STATUS uglBMFTextDraw ( UGL_GC * pGc, UGL_POS x, UGL_POS y, UGL_SIZE length, const UGL_CHAR * text ) { int page, fontInPage; UGL_UGI_DRIVER * pDriver = pGc->pDriver; UGL_BMF_FONT * pBMFFont = (UGL_BMF_FONT *)pGc->pFont; UGL_BMF_FONT_DRIVER * pBMFFontDriver = (UGL_BMF_FONT_DRIVER *)pBMFFont->header.pFontDriver; UGL_FONT_DRIVER * pFontDriver = (UGL_FONT_DRIVER *)pBMFFont->header.pFontDriver; UGL_GLYPH_CACHE_ELEMENT *pCacheElement; UGL_STATUS status = UGL_STATUS_OK; UGL_SIZE maxAscent = pBMFFont->pBMFFontDesc->maxAscent; void ** ppPageZero = pBMFFont->pageZero; void ** ppPageElement; UGL_COLOR saveColor; UGL_POINT point; int i; /* Make sure the font and text are valid */ if (pBMFFont == UGL_NULL || text == UGL_NULL || text[0] == 0) return (UGL_STATUS_ERROR); /* Set a large text length, if -1 is specified */ if (length <= 0) length = 0x0fff; /* Draw the text background */ if (pGc->backgroundColor != UGL_COLOR_TRANSPARENT) { UGL_SIZE width, height; UGL_RECT rect; UGL_POS tmpY; (*pFontDriver->textSizeGet)(pGc->pFont, &width, &height, length, text); if(pBMFFontDriver->textOrigin == UGL_FONT_TEXT_UPPER_LEFT) { rect.right = x + width - 1; rect.bottom = y + height - 1; rect.left = x; rect.top = y; } else if(pBMFFontDriver->textOrigin == UGL_FONT_TEXT_BASELINE) { tmpY = y - maxAscent; rect.right = x + width - 1; rect.bottom = tmpY + height - 1; rect.left = x; rect.top = tmpY; } else { return(UGL_STATUS_ERROR); } saveColor = pGc->foregroundColor; pGc->foregroundColor = UGL_COLOR_TRANSPARENT; pGc->changed |= UGL_GC_FOREGROUND_COLOR_CHANGED; UGL_GC_CHANGED_SET(pGc); UGL_GC_SET(pDriver, pGc); (*pDriver->rectangle)(pDriver, &rect); pGc->foregroundColor = saveColor; pGc->changed |= UGL_GC_FOREGROUND_COLOR_CHANGED; UGL_GC_CHANGED_SET(pGc); UGL_GC_SET(pDriver, pGc); } saveColor = pGc->backgroundColor; pGc->backgroundColor = UGL_COLOR_TRANSPARENT; pGc->changed |= UGL_GC_BACKGROUND_COLOR_CHANGED; UGL_GC_CHANGED_SET(pGc); UGL_GC_SET(pDriver, pGc); /* Blit each character to the screen */ for (i = 0; UGL_NULL != *text && i < length; i++) { if ( ( ( * text ) & 0x80 ) && ( ( * ( text + 1 ) ) & 0x80 ) && ( * ( text + 2 ) == '^' ) ){ page = * ( (unsigned char * ) text ); fontInPage = * ( (unsigned char * ) ( text + 1 ) ); font24Draw(pGc, x+1, y+1, 0, page, fontInPage); text += 3; x += 24; continue; }else if ( ( ( * text ) & 0x80 ) && ( ( * ( text + 1 ) ) & 0x80 ) && ( * ( text + 2 ) == '~' ) ){ page = * ( (unsigned char * ) text ); fontInPage = * ( (unsigned char * ) ( text + 1 ) ); font12Draw(pGc, x+1, y+1, 0, page, fontInPage); text += 3; x += 12; continue; }else if ( ( ( * text ) & 0x80 ) && ( ( * ( text + 1 ) ) & 0x80 ) ){ page = * ( (unsigned char * ) text ); fontInPage = * ( (unsigned char * ) ( text + 1 ) ); font16Draw(pGc, x+1, y+1, 0, page, fontInPage); text += 2; x += 16; continue; } ppPageElement = &ppPageZero[(UGL_UINT8)*(text++)]; pCacheElement = (UGL_GLYPH_CACHE_ELEMENT *)*ppPageElement; /* If encoding doesn't map to a glyph, don't do anything */ if (UGL_NULL == pCacheElement) { continue; } /* Check to see if glyph is in cache or not */ if (UGL_BMF_GLYPH_IN_CACHE != pCacheElement->cacheFlag) { pCacheElement = uglBMFGlyphCacheAlloc(pFontDriver, ppPageElement); if (UGL_NULL == pCacheElement) { status = UGL_STATUS_ERROR; break; } } /* Blit glyph to the screen */ if(pBMFFontDriver->textOrigin == UGL_FONT_TEXT_UPPER_LEFT) { point.x = x; point.y = y + maxAscent - (UGL_POS)pCacheElement->ascent; (*pDriver->monoBitmapBlt)(pDriver, pCacheElement->bitmapID, &pCacheElement->bitmapRect, UGL_DEFAULT_ID, &point); x += pCacheElement->width;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -