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