From 0ed66b8299bc8b9fec702b58b7408f047a6bb942 Mon Sep 17 00:00:00 2001 From: Stefan Neis Date: Sat, 19 Jan 2008 14:10:36 +0000 Subject: [PATCH] Applied patch #1875242 - fixing more bugs related to using OS/2's DevQueryCaps git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@51287 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/os2/dc.cpp | 38 +++++++++++++++++++++----------------- src/os2/fontutil.cpp | 13 +++++++++---- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/os2/dc.cpp b/src/os2/dc.cpp index a9715ad10a..7d0e693fe9 100644 --- a/src/os2/dc.cpp +++ b/src/os2/dc.cpp @@ -513,16 +513,16 @@ bool wxDC::CanGetTextExtent() const int wxDC::GetDepth() const { - LONG lArray[CAPS_COLOR_BITCOUNT]; + LONG lCapsColorBitcount; int nBitsPerPixel = 0; if(::DevQueryCaps( GetHDC() - ,CAPS_FAMILY ,CAPS_COLOR_BITCOUNT - ,lArray + ,1L + ,&lCapsColorBitcount )) { - nBitsPerPixel = (int)lArray[CAPS_COLOR_BITCOUNT]; + nBitsPerPixel = (int)lCapsColorBitcount; } return nBitsPerPixel; } // end of wxDC::GetDepth @@ -2712,55 +2712,59 @@ bool wxDC::DoBlit( wxCoord vXdest, void wxDC::DoGetSize( int* pnWidth, int* pnHeight ) const { - LONG lArray[CAPS_HEIGHT]; + LONG lArray[CAPS_HEIGHT+1]; if(::DevQueryCaps( m_hDC ,CAPS_FAMILY - ,CAPS_HEIGHT + ,CAPS_HEIGHT+1 ,lArray )) { - *pnWidth = lArray[CAPS_WIDTH]; - *pnHeight = lArray[CAPS_HEIGHT]; + if (pnWidth) + *pnWidth = lArray[CAPS_WIDTH]; + if (pnHeight) + *pnHeight = lArray[CAPS_HEIGHT]; } }; // end of wxDC::DoGetSize( void wxDC::DoGetSizeMM( int* pnWidth, int* pnHeight ) const { - LONG lArray[CAPS_VERTICAL_RESOLUTION]; + LONG lArray[CAPS_VERTICAL_RESOLUTION+1]; if(::DevQueryCaps( m_hDC ,CAPS_FAMILY - ,CAPS_VERTICAL_RESOLUTION + ,CAPS_VERTICAL_RESOLUTION+1 ,lArray )) { if(pnWidth) { - int nWidth = lArray[CAPS_WIDTH]; - int nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter - *pnWidth = (nHorzRes/1000) * nWidth; + int nWidth = lArray[CAPS_WIDTH]; + int nHorzRes = lArray[CAPS_HORIZONTAL_RESOLUTION]; // returns pel/meter + // use fp to avoid returning 0 if nHorzRes < 1000 + *pnWidth = (int)((nHorzRes/1000.0) * nWidth); } if(pnHeight) { - int nHeight = lArray[CAPS_HEIGHT]; + int nHeight = lArray[CAPS_HEIGHT]; int nVertRes = lArray[CAPS_VERTICAL_RESOLUTION]; // returns pel/meter - *pnHeight = (nVertRes/1000) * nHeight; + // use fp to avoid returning 0 if nVertRes < 1000 + *pnHeight = (int)((nVertRes/1000.0) * nHeight); } } }; // end of wxDC::DoGetSizeMM wxSize wxDC::GetPPI() const { - LONG lArray[CAPS_VERTICAL_RESOLUTION]; + LONG lArray[CAPS_VERTICAL_RESOLUTION+1]; int nWidth = 0; int nHeight = 0; if(::DevQueryCaps( m_hDC ,CAPS_FAMILY - ,CAPS_VERTICAL_RESOLUTION + ,CAPS_VERTICAL_RESOLUTION+1 ,lArray )) { diff --git a/src/os2/fontutil.cpp b/src/os2/fontutil.cpp index 010a2b6dd6..e6d9b45d7f 100644 --- a/src/os2/fontutil.cpp +++ b/src/os2/fontutil.cpp @@ -281,11 +281,16 @@ void wxConvertVectorFontSize( // NOTE: 1 point == 1/72 of an inch. // - vSizef.cx = (FIXED)(((fxPointSize) / 72 ) * lXFontResolution ); - vSizef.cy = (FIXED)(((fxPointSize) / 72 ) * lYFontResolution ); + // multiply first to avoid getting vSizef.cx,cy = 0 since fxPointSize + // is normally < 72 and FontResolution is typically ca. 100 + vSizef.cx = (FIXED)( (fxPointSize * lXFontResolution) / 72 ); + vSizef.cy = (FIXED)( (fxPointSize * lYFontResolution) / 72 ); - pFattrs->lMaxBaselineExt = MAKELONG( HIUSHORT( vSizef.cy ), 0 ); - pFattrs->lAveCharWidth = MAKELONG( HIUSHORT( vSizef.cx ), 0 ); + if (pFattrs) + { + pFattrs->lMaxBaselineExt = MAKELONG( HIUSHORT( vSizef.cy ), 0 ); + pFattrs->lAveCharWidth = MAKELONG( HIUSHORT( vSizef.cx ), 0 ); + } WinReleasePS(hPS); } // end of wxConvertVectorPointSize