00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "precomp.h"
00028 #include "debug.h"
00029 #include "oemps.h"
00030 #include "GlyphTranslator.h"
00031
00037 bool GlyphToText::Initialize(const LOGFONT& lf, HDC hDC)
00038 {
00039
00040 HFONT hFont = ::CreateFontIndirect(&lf);
00041 if (hFont == NULL)
00042
00043 return false;
00044
00045
00046 HGDIOBJ hOldFont = ::SelectObject(hDC, hFont);
00047 DWORD dwSize = ::GetFontUnicodeRanges(hDC, NULL);
00048 if (dwSize == 0)
00049 {
00050
00051 ::SelectObject(hDC, hOldFont);
00052 return true;
00053 }
00054
00055
00056 LPGLYPHSET pSet = (LPGLYPHSET)new char[dwSize];
00057 ::GetFontUnicodeRanges(hDC, pSet);
00058
00059
00060 WORD dwGlyphs[1];
00061 TCHAR c[1];
00062 int nCount = 0;
00063 for (UINT i=0;i<pSet->cRanges;i++)
00064 {
00065
00066 for (UINT u=0;u<pSet->ranges[i].cGlyphs;u++)
00067 {
00068
00069 c[0] = pSet->ranges[i].wcLow + u;
00070
00071 if (::GetGlyphIndices(hDC, c, 1, (LPWORD)&dwGlyphs, GGI_MARK_NONEXISTING_GLYPHS) != 1)
00072 {
00073
00074 delete [] pSet;
00075 ::SelectObject(hDC, hOldFont);
00076 return false;
00077 }
00078
00079 if (find(dwGlyphs[0]) == end())
00080 operator[](dwGlyphs[0]) = c[0];
00081 }
00082 }
00083
00084
00085 delete [] pSet;
00086 ::SelectObject(hDC, hOldFont);
00087 return true;
00088 }
00089
00095 const GlyphToText* GlyphTranslator::GetFontTranslation(const LOGFONT& lf, HDC hDC )
00096 {
00097
00098 TCHAR cFontID[LF_FACESIZE + 128];
00099 _stprintf_s(cFontID, _S(cFontID), _T("%.*s|%d|%d|%d|%d|%d"), LF_FACESIZE, lf.lfFaceName, lf.lfHeight, lf.lfWeight, (lf.lfItalic ? 1 : 0) | (lf.lfUnderline ? 2 : 0) | (lf.lfStrikeOut ? 4 : 0), lf.lfPitchAndFamily);
00100 iterator iGlyphData;
00101
00102 if ((iGlyphData = find(cFontID)) == end())
00103 {
00104
00105 insert(std::pair<std::tstring, GlyphToText>(cFontID, GlyphToText()));
00106 iGlyphData = find(cFontID);
00107 _ASSERT(iGlyphData != end());
00108
00109 HDC hUseDC = (hDC == NULL) ? GetDC(NULL) : hDC;
00110 if (hUseDC == NULL)
00111 return NULL;
00112 bool bRet = !(*iGlyphData).second.Initialize(lf, hUseDC);
00113 if (hUseDC != hDC)
00114 DeleteDC(hUseDC);
00115 if (!bRet)
00116 {
00117
00118 erase(iGlyphData);
00119 return NULL;
00120 }
00121 }
00122
00123
00124 return &((*iGlyphData).second);
00125 }