1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
23 // these functions are taken from an article of the 'old new thing' blog:
\r
24 // http://blogs.msdn.com/oldnewthing/archive/2004/07/16/185261.aspx
\r
27 HRESULT TextOutFL(HDC hdc, int x, int y, LPCWSTR psz, int cch)
\r
30 IMLangFontLink2 *pfl;
\r
31 if (SUCCEEDED(hr = CoCreateInstance(CLSID_CMultiLanguage, NULL,
\r
32 CLSCTX_ALL, IID_IMLangFontLink2, (void**)&pfl)))
\r
34 HFONT hfOrig = (HFONT)GetCurrentObject(hdc, OBJ_FONT);
\r
36 DWORD dwAlignOrig = GetTextAlign(hdc);
\r
37 if (!(dwAlignOrig & TA_UPDATECP))
\r
39 SetTextAlign(hdc, dwAlignOrig | TA_UPDATECP);
\r
41 MoveToEx(hdc, x, y, &ptOrig);
\r
42 DWORD dwFontCodePages = 0;
\r
43 hr = pfl->GetFontCodePages(hdc, hfOrig, &dwFontCodePages);
\r
48 DWORD dwActualCodePages;
\r
50 hr = pfl->GetStrCodePages(psz, cch, dwFontCodePages, &dwActualCodePages, &cchActual);
\r
56 if (dwActualCodePages & dwFontCodePages)
\r
58 TextOut(hdc, 0, 0, psz, cchActual);
\r
63 if (FAILED(hr = pfl->MapFont(hdc, dwActualCodePages, 0, &hfLinked)))
\r
67 SelectObject(hdc, (HGDIOBJ)(HFONT)hfLinked);
\r
68 TextOut(hdc, 0, 0, psz, cchActual);
\r
69 SelectObject(hdc, (HGDIOBJ)(HFONT)hfOrig);
\r
70 pfl->ReleaseFont(hfLinked);
\r
77 // We started outputting characters so we have to finish.
\r
78 // Do the rest without font linking since we have no choice.
\r
79 TextOut(hdc, 0, 0, psz, cch);
\r
86 if (!(dwAlignOrig & TA_UPDATECP))
\r
88 SetTextAlign(hdc, dwAlignOrig);
\r
89 MoveToEx(hdc, ptOrig.x, ptOrig.y, NULL);
\r
96 void TextOutTryFL(HDC hdc, int x, int y, LPCWSTR psz, int cch)
\r
98 if (FAILED(TextOutFL(hdc, x, y, psz, cch)))
\r
100 TextOut(hdc, x, y, psz, cch);
\r