А вот код из БИТМАПА...
| Код | BOOL FitCheck( PCSTR pStr, UINT lStr ) { // it is possible to draw exact count of chars // but not entire string // so check it before lengthy operations
SIZE draft;
GetTextExtentPoint32( g_hFitDC, pStr, lStr, &draft );
if( ( draft.cx - g_rClockCli.right ) * ( long )lStr > draft.cx ) { return FALSE; // draft.cx > g_rClockCli.right // ok signed }
if ( g_FitBox.x2 == g_rFit.right - 1 ) g_FitBox.xt -= g_FitBox.x1 / 2; else if( g_FitBox.x1 == 0 ) g_FitBox.xt += ( g_rFit.right - g_FitBox.x2 ) / 2;
if ( g_FitBox.y2 == g_rFit.bottom - 1 ) g_FitBox.yt -= g_FitBox.y1 / 2; else if( g_FitBox.y1 == 0 ) g_FitBox.yt += ( g_rFit.bottom - g_FitBox.y2 ) / 2;
// 1,5xx ticks FillRect ( g_hFitDC, &g_rFit, BRUSH_BACK );
// 2,2xx ticks ExtTextOut ( g_hFitDC, g_FitBox.xt, g_FitBox.yt, 0, NULL, pStr, lStr, NULL );
/* test patterns
// RECT _tst = { 7, 5, 7 + 120, 5 + 45 }; // L = 1, T = 2, R = 2, B = 1 // RECT _tst = { 7, 5, 7 + 122, 5 + 47 }; // L = 0, T = 1, R = 1, B = 0 RECT _tst = { 7, 5, 7 + 123, 5 + 48 }; // L = 0, T = 0, R = 0, B = 0 RECT _bk = { 7, 5, 7 + 1, 5 + 1 }; // background must be there
FillRect( g_hFitDC, &_tst, ( HBRUSH )( COLOR_WINDOW + 1 ) ); FillRect( g_hFitDC, &_bk, ( HBRUSH )( BRUSH_BACK ) ); */
// it seems works in spite of MSDN warning // "... must not be selected into a device context ..." // // or this warning not applies to memory DC ?
// 1,60x,xxx ticks GetDIBits( g_hFitDC, g_hFitBmp, 0, g_rFit.bottom, g_pFitBmpBits, &g_FitBmpInfo, DIB_RGB_COLORS );
// it is assumed in next loops // that some was drawn in ExtTextOut() // // if entire output is blank ('cause of font) // then access violation can be prodused // // but it is too odd for font having empty glyph at [0..9]
// DWORD-aligned at the end of every scanline // (here 32-bit per pixel, so all ok)
// top
UINT width ( g_rFit.right );
DWORD( * p )( g_pFitBmpBits ); DWORD( * pEnd )( p + width );
DWORD bkgnd ( *p ); // assumed nothing drawn there
while( TRUE ) { do { if( ( *p ^ bkgnd ) & 0xFFFFFF ) { goto found_y1; } } while( ++p < pEnd );
pEnd += width; }
found_y1: g_FitBox.y1 = ( p - g_pFitBmpBits ) / width;
// bottom
p = g_pFitBmpBits + width * ( g_rFit.bottom - 1 ); // last scanline pEnd = p + width;
while( TRUE ) { do { if( ( *p ^ bkgnd ) & 0xFFFFFF ) { goto found_y2; } } while( ++p < pEnd );
p -= width * 2; pEnd -= width; }
found_y2: g_FitBox.y2 = ( p - g_pFitBmpBits ) / width;
if( g_FitBox.ys() > g_rClockCli.bottom ) { return FALSE; }
// left
DWORD( * pb ) ( g_pFitBmpBits + width * g_FitBox.y1 ); // first on found top
p = pb; pEnd = pb + width * g_FitBox.ys();
while( TRUE ) { do { if( ( *p ^ bkgnd ) & 0xFFFFFF ) { goto found_x1; } } while( ( p += width ) < pEnd );
p = ++pb; }
found_x1: g_FitBox.x1 = ( p - g_pFitBmpBits ) % width;
// right
pb = g_pFitBmpBits + width * g_FitBox.y1 + ( width - 1 ); // last on found top p = pb;
while( TRUE ) { do { if( ( *p ^ bkgnd ) & 0xFFFFFF ) { goto found_x2; } } while( ( p += width ) < pEnd );
p = --pb; }
found_x2: g_FitBox.x2 = ( p - g_pFitBmpBits ) % width;
// 170,xxx ticks
return g_FitBox.xs() <= g_rClockCli.right; }
|
лови файл... |