TGlyphMetrics = packed record gmBlackBoxX : UINT; { the smallest rectangle width } gmBlackBoxY : UINT; { the smallest rectangle height } gmptGlyphOrigin : TPoint; { the smallest rectangle origin } gmCellIncX : SHORT; { the next character cell horizontal offset } gmCellIncY : SHORT; { the next character cell vertical offset } end;
GetGlyphOutline
参数:
否则,返回值是GDI_ERROR。如果指定了上述之一值,但缓冲区或地址是0,则返回需要的缓冲区的字节数。
如果一个应用程序需要一种无修改的字形轮廓,应该在那些大小等于字体的em单位的字体中要求一个字符的字形轮廓,
字体的em单位值存在于结构OUTLINETEXTMETRIC的otmEMSquare成员中。
当指定GGO_GRAY2_BITMAP,返回的位图是一种双字对齐、面向行的,其值在0-4之间的字节数组。
当GGO_GRAY4_BITMAP指定时,返回的位图是一种双字对齐、面向行的,其值在0-16之间的字节数组。
当指定GGO_GRAY8_BITMAP时,返回的位图是一种双字对齐,面向行的,其值在0-64之间的字节数组。
应用程序可以指定lpMatrix参数里的2-对-2转换矩阵来将以位图格式获得的字符旋转。
// Convert degrees to radians. //............................ #define RAD(x) ((x) * 3.1415927 / 180) FIXED FixedFromDouble( double d ) { long l; l = (long) ( d * 65536L ); return *(FIXED *) &l; } HBITMAP BitmapFromBits( void * lpBits, WORD width, WORD height ) { BITMAP bm; bm.bmType = 0; bm.bmWidth = width; bm.bmHeight = height; bm.bmWidthBytes = ( ( width + 31 ) >> 5 ) << 2; bm.bmPlanes = 1; bm.bmBitsPixel = 1; bm.bmBits = lpBits; return ( CreateBitmapIndirect( &bm ) ); } void GetGlyphOutlineExample( void ) { HDC hDC, hMemDC; HFONT hFont, hOldFont; GLYPHMETRICS gm; MAT2 m2; DWORD dwRet; LPBYTE lpBuf; HBITMAP hBitmap, hOldBmp; // Create a Times New Roman font. hFont = CreateFont( 32, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DONTCARE, “Times New Roman” ); // Retrieve the device context, select the font into it, // and create a compatible device context. hDC = GetDC( hWnd ); hMemDC = CreateCompatibleDC( hDC ); hOldFont = SelectObject( hDC, hFont ); // Set up the translation matrix to rotate the font 45 degrees. m2.eM11 = FixedFromDouble( cos( RAD(45) ) ); m2.eM12 = FixedFromDouble( sin( RAD(45) ) ); m2.eM21 = FixedFromDouble( -sin( RAD(45) ) ); m2.eM22 = FixedFromDouble( cos( RAD(45) ) ); // Retrieve the size of the bitmap and allocate memory to hold it. dwRet = GetGlyphOutline( hDC, ‘A’, GGO_BITMAP, & gm, 0, NULL, &m2 ); lpBuf = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwRet ); // Retrieve the bitmap for the letter ‘A’. GetGlyphOutline( hDC, ‘A’, GGO_BITMAP, & gm, dwRet, lpBuf, &m2 ); // Create a HBITMAP and display it. hBitmap = BitmapFromBits( lpBuf, (WORD) gm.gmBlackBoxX, (WORD) gm.gmBlackBoxY ); hOldBmp = SelectObject( hMemDC, hBitmap ); BitBlt( hDC, 10, 10, gm.gmBlackBoxX, gm.gmBlackBoxY, hMemDC, 0, 0, SRCCOPY ); // Output a normal ‘A’ character. TextOut( hDC, 40, 10, “A”, 1 ); // Clean up. SelectObject( hMemDC, hOldBmp ); DeleteObject( hBitmap ); HeapFree( GetProcessHeap( ), 0, lpBuf ); SelectObject( hDC, hOldFont ); ReleaseDC( hWnd, hDC ); DeleteObject( hFont ); }