From 96f002fcd8659c3faf63f2988bb1f97310509ee0 Mon Sep 17 00:00:00 2001 From: "erik%netscape.com" Date: Fri, 4 Jun 1999 00:08:56 +0000 Subject: [PATCH] Bug 7427. Need to convert enumerated font names from system code page to Unicode, and then convert Unicode font names back to system code page when loading font. --- gfx/src/windows/nsFontMetricsWin.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/gfx/src/windows/nsFontMetricsWin.cpp b/gfx/src/windows/nsFontMetricsWin.cpp index 351d35dfacf..8d28fa090c1 100644 --- a/gfx/src/windows/nsFontMetricsWin.cpp +++ b/gfx/src/windows/nsFontMetricsWin.cpp @@ -532,9 +532,19 @@ nsFontMetricsWin::LoadFont(HDC aDC, nsString* aName) LOGFONT logFont; FillLogFont(&logFont); - // XXX need to preserve Unicode chars in face name (use LOGFONTW) -- erik - aName->ToCString(logFont.lfFaceName, LF_FACESIZE); + /* + * XXX we are losing info by converting from Unicode to system code page + * but we don't really have a choice since CreateFontIndirectW is + * not supported on Windows 9X (see below) -- erik + */ + logFont.lfFaceName[0] = 0; + WideCharToMultiByte(CP_ACP, 0, aName->GetUnicode(), aName->Length() + 1, + logFont.lfFaceName, sizeof(logFont.lfFaceName), nsnull, nsnull); + /* + * According to http://msdn.microsoft.com/library/ + * CreateFontIndirectW is only supported on NT/2000 + */ HFONT hfont = ::CreateFontIndirect(&logFont); if (hfont) { @@ -600,8 +610,11 @@ static int CALLBACK enumProc(const LOGFONT* logFont, const TEXTMETRIC* metrics, nsGlobalFont* font = &nsFontMetricsWin::gGlobalFonts[nsFontMetricsWin::gGlobalFontsCount++]; - // XXX do correct character encoding conversion here - font->name = new nsString(logFont->lfFaceName); + PRUnichar name[LF_FACESIZE]; + name[0] = 0; + MultiByteToWideChar(CP_ACP, 0, logFont->lfFaceName, + strlen(logFont->lfFaceName) + 1, name, sizeof(name)/sizeof(name[0])); + font->name = new nsString(name); if (!font->name) { nsFontMetricsWin::gGlobalFontsCount--; return 0;