From 7d22e4e6adc3f29a1303296626c0f5a06c3a17af Mon Sep 17 00:00:00 2001 From: Sup Yut Sum Date: Thu, 27 Dec 2012 08:06:52 +0800 Subject: [PATCH] Introduces CComPtr in ExtTextOutFL.h Based on TortoiseSVN revision 18374 Signed-off-by: Sup Yut Sum --- src/Utils/MiscUI/ExtTextOutFL.h | 107 ++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/src/Utils/MiscUI/ExtTextOutFL.h b/src/Utils/MiscUI/ExtTextOutFL.h index c7c7cde7e..dbcfc6b61 100644 --- a/src/Utils/MiscUI/ExtTextOutFL.h +++ b/src/Utils/MiscUI/ExtTextOutFL.h @@ -1,6 +1,6 @@ // TortoiseGit - a Windows shell extension for easy version control -// Copyright (C) 2008 - TortoiseSVN +// Copyright (C) 2008, 2010 - TortoiseSVN // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -26,68 +26,67 @@ HRESULT TextOutFL(HDC hdc, int x, int y, LPCWSTR psz, int cch) { - HRESULT hr; - IMLangFontLink2 *pfl; - if (SUCCEEDED(hr = CoCreateInstance(CLSID_CMultiLanguage, NULL, - CLSCTX_ALL, IID_IMLangFontLink2, (void**)&pfl))) + ATL::CComPtr pfl; + HRESULT hr = pfl.CoCreateInstance(CLSID_CMultiLanguage, NULL, CLSCTX_ALL); + if (FAILED(hr)) + return hr; + + HFONT hfOrig = (HFONT)GetCurrentObject(hdc, OBJ_FONT); + POINT ptOrig; + DWORD dwAlignOrig = GetTextAlign(hdc); + if (!(dwAlignOrig & TA_UPDATECP)) + { + SetTextAlign(hdc, dwAlignOrig | TA_UPDATECP); + } + MoveToEx(hdc, x, y, &ptOrig); + DWORD dwFontCodePages = 0; + hr = pfl->GetFontCodePages(hdc, hfOrig, &dwFontCodePages); + if (SUCCEEDED(hr)) { - HFONT hfOrig = (HFONT)GetCurrentObject(hdc, OBJ_FONT); - POINT ptOrig; - DWORD dwAlignOrig = GetTextAlign(hdc); - if (!(dwAlignOrig & TA_UPDATECP)) + while (cch > 0) + { + DWORD dwActualCodePages; + long cchActual; + hr = pfl->GetStrCodePages(psz, cch, dwFontCodePages, &dwActualCodePages, &cchActual); + if (FAILED(hr)) { - SetTextAlign(hdc, dwAlignOrig | TA_UPDATECP); + break; } - MoveToEx(hdc, x, y, &ptOrig); - DWORD dwFontCodePages = 0; - hr = pfl->GetFontCodePages(hdc, hfOrig, &dwFontCodePages); - if (SUCCEEDED(hr)) - { - while (cch > 0) - { - DWORD dwActualCodePages; - long cchActual; - hr = pfl->GetStrCodePages(psz, cch, dwFontCodePages, &dwActualCodePages, &cchActual); - if (FAILED(hr)) - { - break; - } - if (dwActualCodePages & dwFontCodePages) - { - TextOut(hdc, 0, 0, psz, cchActual); - } - else - { - HFONT hfLinked; - if (FAILED(hr = pfl->MapFont(hdc, dwActualCodePages, 0, &hfLinked))) - { - break; - } - SelectObject(hdc, (HGDIOBJ)(HFONT)hfLinked); - TextOut(hdc, 0, 0, psz, cchActual); - SelectObject(hdc, (HGDIOBJ)(HFONT)hfOrig); - pfl->ReleaseFont(hfLinked); - } - psz += cchActual; - cch -= cchActual; - } - if (FAILED(hr)) + if (dwActualCodePages & dwFontCodePages) + { + TextOut(hdc, 0, 0, psz, cchActual); + } + else + { + HFONT hfLinked; + if (FAILED(hr = pfl->MapFont(hdc, dwActualCodePages, 0, &hfLinked))) { - // We started outputting characters so we have to finish. - // Do the rest without font linking since we have no choice. - TextOut(hdc, 0, 0, psz, cch); - hr = S_FALSE; + break; } + SelectObject(hdc, (HGDIOBJ)(HFONT)hfLinked); + TextOut(hdc, 0, 0, psz, cchActual); + SelectObject(hdc, (HGDIOBJ)(HFONT)hfOrig); + pfl->ReleaseFont(hfLinked); } + psz += cchActual; + cch -= cchActual; + } + if (FAILED(hr)) + { + // We started outputting characters so we have to finish. + // Do the rest without font linking since we have no choice. + TextOut(hdc, 0, 0, psz, cch); + hr = S_FALSE; + } + } - pfl->Release(); + pfl.Release(); - if (!(dwAlignOrig & TA_UPDATECP)) - { - SetTextAlign(hdc, dwAlignOrig); - MoveToEx(hdc, ptOrig.x, ptOrig.y, NULL); - } + if (!(dwAlignOrig & TA_UPDATECP)) + { + SetTextAlign(hdc, dwAlignOrig); + MoveToEx(hdc, ptOrig.x, ptOrig.y, NULL); } return hr; -- 2.11.4.GIT