From: Jeffrey D. <ha...@us...> - 2003-09-26 08:25:47
|
Log Message: ----------- DrawTextEx - gives options for AA and outlined text Modified Files: -------------- /cvsroot/decaldev/source/Inject: FontCache.cpp FontCache.h Inject.idl Revision Data ------------- Index: FontCache.cpp =================================================================== RCS file: /cvsroot/decaldev/source/Inject/FontCache.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- FontCache.cpp 17 Sep 2003 23:08:54 -0000 1.2 +++ FontCache.cpp 26 Sep 2003 08:25:25 -0000 1.3 @@ -81,57 +81,125 @@ STDMETHODIMP cFontCache::DrawText( LPPOINT ppt, BSTR strText, long clr, ICanvas *pCanvas ) { - _ASSERTE( ppt != NULL ); - _ASSERTE( strText != NULL ); - _ASSERTE( pCanvas != NULL ); +/* _ASSERTE( ppt != NULL ); + _ASSERTE( strText != NULL ); + _ASSERTE( pCanvas != NULL ); - if( !checkBuffer() ) - return E_FAIL; + if( !checkBuffer() ) + return E_FAIL; - USES_CONVERSION; + USES_CONVERSION; - LPCTSTR szText = OLE2T( strText ); + LPCTSTR szText = OLE2T( strText ); - // TODO: Draw this a lot faster from a cached bitmap value + // TODO: Draw this a lot faster from a cached bitmap value - HDC hdc; - pCanvas->GetDC( &hdc ); + HDC hdc; + pCanvas->GetDC( &hdc ); - // Draw the text - HFONT hfnt = ::CreateFontIndirect( &m_lf ), - hfntOld = reinterpret_cast< HFONT >( ::SelectObject( hdc, hfnt ) ); + // Draw the text + HFONT hfnt = ::CreateFontIndirect( &m_lf ), + hfntOld = reinterpret_cast< HFONT >( ::SelectObject( hdc, hfnt ) ); - ::SetBkMode( hdc, TRANSPARENT ); - ::SetTextColor( hdc, clr ); - ::SetTextAlign( hdc, TA_TOP | TA_LEFT ); + ::SetBkMode( hdc, TRANSPARENT ); + ::SetTextColor( hdc, clr ); + ::SetTextAlign( hdc, TA_TOP | TA_LEFT ); - LPCSTR szAnsi = OLE2A( strText ); - int cbLength = ::strlen( szAnsi ); + LPCSTR szAnsi = OLE2A( strText ); + int cbLength = ::strlen( szAnsi ); - INT *pDeltas = new INT[ cbLength ]; + INT *pDeltas = new INT[ cbLength ]; - // Fill in the character deltas - const char *i_src = szAnsi; - INT *i_end_deltas = pDeltas + cbLength; - for( INT *i_delta = pDeltas; i_delta != i_end_deltas; ++ i_delta, ++ i_src ) - *i_delta = m_nWidths[ *i_src ].m_nWidth; + // Fill in the character deltas + const char *i_src = szAnsi; + INT *i_end_deltas = pDeltas + cbLength; + for( INT *i_delta = pDeltas; i_delta != i_end_deltas; ++ i_delta, ++ i_src ) + *i_delta = m_nWidths[ *i_src ].m_nWidth; - if( m_bFontSmoothing ) - SystemParametersInfo( SPI_SETFONTSMOOTHING, FALSE, NULL, 0 ); + if( m_bFontSmoothing ) + SystemParametersInfo( SPI_SETFONTSMOOTHING, FALSE, NULL, 0 ); - ::ExtTextOut( hdc, ppt->x, ppt->y, 0, NULL, szAnsi, cbLength, pDeltas ); + ::ExtTextOut( hdc, ppt->x, ppt->y, 0, NULL, szAnsi, cbLength, pDeltas ); - if( m_bFontSmoothing ) - SystemParametersInfo( SPI_SETFONTSMOOTHING, TRUE, NULL, 0 ); + if( m_bFontSmoothing ) + SystemParametersInfo( SPI_SETFONTSMOOTHING, TRUE, NULL, 0 ); - delete[] pDeltas; + delete[] pDeltas; - ::SelectObject( hdc, hfntOld ); - ::DeleteObject( hfnt ); + ::SelectObject( hdc, hfntOld ); + ::DeleteObject( hfnt ); - pCanvas->ReleaseDC(); + pCanvas->ReleaseDC(); - return S_OK; + return S_OK;*/ + return DrawTextEx( ppt, strText, clr, 0, 0, pCanvas ); +} + +STDMETHODIMP cFontCache::DrawTextEx( LPPOINT ppt, BSTR strText, long clr1, long clr2, long lFlags, ICanvas *pCanvas ) +{ + _ASSERTE( ppt != NULL ); + _ASSERTE( strText != NULL ); + _ASSERTE( pCanvas != NULL ); + + if( !checkBuffer() ) + return E_FAIL; + + USES_CONVERSION; + + LPCTSTR szText = OLE2T( strText ); + + // TODO: Draw this a lot faster from a cached bitmap value + + HDC hdc; + pCanvas->GetDC( &hdc ); + + // Draw the text + HFONT hfnt = ::CreateFontIndirect( &m_lf ), + hfntOld = reinterpret_cast< HFONT >( ::SelectObject( hdc, hfnt ) ); + + ::SetBkMode( hdc, TRANSPARENT ); + ::SetTextAlign( hdc, TA_TOP | TA_LEFT ); + + LPCSTR szAnsi = OLE2A( strText ); + int cbLength = ::strlen( szAnsi ); + + INT *pDeltas = new INT[ cbLength ]; + + // Fill in the character deltas + const char *i_src = szAnsi; + INT *i_end_deltas = pDeltas + cbLength; + for( INT *i_delta = pDeltas; i_delta != i_end_deltas; ++ i_delta, ++ i_src ) + *i_delta = m_nWidths[ *i_src ].m_nWidth; + + if( !(lFlags & eAA) ) + if( m_bFontSmoothing ) + SystemParametersInfo( SPI_SETFONTSMOOTHING, FALSE, NULL, 0 ); + + if( lFlags & eOutlined ) + { + ::SetTextColor( hdc, clr2 ); + + ::ExtTextOut( hdc, ppt->x - 1, ppt->y - 1, 0, NULL, szAnsi, cbLength, pDeltas ); + ::ExtTextOut( hdc, ppt->x - 1, ppt->y + 1, 0, NULL, szAnsi, cbLength, pDeltas ); + ::ExtTextOut( hdc, ppt->x + 1, ppt->y - 1, 0, NULL, szAnsi, cbLength, pDeltas ); + ::ExtTextOut( hdc, ppt->x + 1, ppt->y + 1, 0, NULL, szAnsi, cbLength, pDeltas ); + } + + ::SetTextColor( hdc, clr1 ); + ::ExtTextOut( hdc, ppt->x, ppt->y, 0, NULL, szAnsi, cbLength, pDeltas ); + + if( !(lFlags & eAA) ) + if( m_bFontSmoothing ) + SystemParametersInfo( SPI_SETFONTSMOOTHING, TRUE, NULL, 0 ); + + delete[] pDeltas; + + ::SelectObject( hdc, hfntOld ); + ::DeleteObject( hfnt ); + + pCanvas->ReleaseDC(); + + return S_OK; } STDMETHODIMP cFontCache::MeasureText( BSTR strText, LPSIZE pszExt ) Index: FontCache.h =================================================================== RCS file: /cvsroot/decaldev/source/Inject/FontCache.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- FontCache.h 17 Sep 2003 23:08:54 -0000 1.2 +++ FontCache.h 26 Sep 2003 08:25:25 -0000 1.3 @@ -43,7 +43,8 @@ public: STDMETHOD(HitTest)(BSTR szText, long nPos, /*[out, retval]*/ long *nIndex); STDMETHOD(MeasureText)( BSTR szText, /*[out]*/ LPSIZE pszExt ); - STDMETHOD(DrawText)( LPPOINT pt, BSTR szText, long clr, ICanvas *pCanvas ); + STDMETHOD(DrawText)( LPPOINT pt, BSTR szText, long clr, ICanvas *pCanvas ); + STDMETHOD(DrawTextEx)( LPPOINT pt, BSTR szText, long clr1, long clr2, long lFlags, ICanvas *pCanvas ); }; #endif //__FONTCACHE_H_ Index: Inject.idl =================================================================== RCS file: /cvsroot/decaldev/source/Inject/Inject.idl,v retrieving revision 1.42 retrieving revision 1.43 diff -u -d -r1.42 -r1.43 --- Inject.idl 25 Sep 2003 19:50:11 -0000 1.42 +++ Inject.idl 26 Sep 2003 08:25:25 -0000 1.43 @@ -61,6 +61,12 @@ eFontCenter }; +enum eDrawTextExFlags +{ + eAA = 0x1, + eOutlined = 0x2, +}; + enum eDefaultControlType { eCtlButton, @@ -427,6 +433,7 @@ [helpstring("Renders text to a canvas. Only guaranteed to work within the render cycle.")] HRESULT DrawText( LPPOINT pt, BSTR szText, long clr, ICanvas *pTarget ); [helpstring("Returns the width and height of a string of text.")] HRESULT MeasureText(BSTR szText, [out, retval] LPSIZE pszExt); [helpstring("method HitTest")] HRESULT HitTest(BSTR szText, long nPos, [out, retval] long *nIndex); + [helpstring("Renders text to a canvas. Only guaranteed to work within the render cycle.")] HRESULT DrawTextEx( LPPOINT pt, BSTR szText, long clr1, long clr2, long flags, ICanvas *pTarget ); }; [ |