bug 396315. correctly fetch cmaps for all fonts. r=vlad
authorpavlov@pavlov.net
Tue, 06 Nov 2007 20:58:16 -0800
changeset 7376 57c69aa913fd8641aaaf6025b4b2ba1b12ea92bb
parent 7375 0d54f8eec70353ff7064a7457eeeb91cc89c5359
child 7377 b0e6d49a1f46b3b4258444e7a2da20bf434e582b
push idunknown
push userunknown
push dateunknown
reviewersvlad
bugs396315
milestone1.9a9pre
bug 396315. correctly fetch cmaps for all fonts. r=vlad
gfx/thebes/src/gfxWindowsPlatform.cpp
--- a/gfx/thebes/src/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/src/gfxWindowsPlatform.cpp
@@ -139,16 +139,21 @@ gfxWindowsPlatform::FontEnumProc(const E
     fe->mCharset[metrics.tmCharSet] = 1;
 
     // put the default weight in the weight table
     fe->mWeightTable.SetWeight(PR_MAX(1, PR_MIN(9, metrics.tmWeight / 100)), PR_TRUE);
 
     // store the default font weight
     fe->mDefaultWeight = metrics.tmWeight;
 
+    if (metrics.ntmFlags & NTM_TYPE1) {
+        fe->mSymbolFont = PR_TRUE;
+        fe->mUnicodeFont = PR_FALSE;
+    }
+
     fe->mFamily = logFont.lfPitchAndFamily & 0xF0;
     fe->mPitch = logFont.lfPitchAndFamily & 0x0F;
 
     if (nmetrics->ntmFontSig.fsUsb[0] == 0x00000000 &&
         nmetrics->ntmFontSig.fsUsb[1] == 0x00000000 &&
         nmetrics->ntmFontSig.fsUsb[2] == 0x00000000 &&
         nmetrics->ntmFontSig.fsUsb[3] == 0x00000000) {
         // no unicode ranges
@@ -304,17 +309,18 @@ ReadCMAPTableFormat4(PRUint8 *aBuf, PRIn
 }
 
 static nsresult
 ReadCMAP(HDC hdc, FontEntry *aFontEntry)
 {
     const PRUint32 kCMAP = (('c') | ('m' << 8) | ('a' << 16) | ('p' << 24));
 
     DWORD len = GetFontData(hdc, kCMAP, 0, nsnull, 0);
-    NS_ENSURE_TRUE(len != GDI_ERROR && len != 0, NS_ERROR_FAILURE);
+    if (len == GDI_ERROR || len == 0) // not a truetype font --
+        return NS_ERROR_FAILURE;      // we'll treat it as a symbol font
 
     nsAutoTArray<PRUint8,16384> buffer;
     if (!buffer.AppendElements(len))
         return NS_ERROR_OUT_OF_MEMORY;
     PRUint8 *buf = buffer.Elements();
 
     DWORD newLen = GetFontData(hdc, kCMAP, 0, buf, len);
     NS_ENSURE_TRUE(newLen == len, NS_ERROR_FAILURE);
@@ -386,29 +392,16 @@ ReadCMAP(HDC hdc, FontEntry *aFontEntry)
     return rv;
 }
 
 PLDHashOperator PR_CALLBACK
 gfxWindowsPlatform::FontGetCMapDataProc(nsStringHashKey::KeyType aKey,
                                         nsRefPtr<FontEntry>& aFontEntry,
                                         void* userArg)
 {
-    if (aFontEntry->mFontType != TRUETYPE_FONTTYPE) {
-        /* bitmap fonts suck -- just claim they support everything
-           between 0x20 and 0xFF.  All the ones on my system do...
-           If we really wanted to test which characters in this
-           range were supported we could just generate a string with
-           each codepoint and do GetGlyphIndicies or similar to determine
-           what is there.
-        */
-        for (PRUint16 ch = 0x20; ch <= 0xFF; ch++)
-            aFontEntry->mCharacterMap.set(ch);
-        return PL_DHASH_NEXT;
-    }
-
     HDC hdc = GetDC(nsnull);
 
     LOGFONTW logFont;
     memset(&logFont, 0, sizeof(LOGFONTW));
     logFont.lfCharSet = DEFAULT_CHARSET;
     logFont.lfPitchAndFamily = 0;
     PRUint32 l = PR_MIN(aFontEntry->mName.Length(), LF_FACESIZE - 1);
     memcpy(logFont.lfFaceName,
@@ -429,16 +422,28 @@ gfxWindowsPlatform::FontGetCMapDataProc(
         }
 
         SelectObject(hdc, oldFont);
         DeleteObject(font);
     }
 
     ReleaseDC(nsnull, hdc);
 
+    if (!aFontEntry->mUnicodeFont) {
+        /* non-unicode fonts.. boy lets just set all code points
+           between 0x20 and 0xFF.  All the ones on my system do...
+           If we really wanted to test which characters in this
+           range were supported we could just generate a string with
+           each codepoint and do GetGlyphIndicies or similar to determine
+           what is there.
+        */
+        aFontEntry->mCharacterMap.SetRange(0x20, 0xFF);
+        return PL_DHASH_NEXT;
+    }
+
     return PL_DHASH_NEXT;
 }
 
 
 struct FontListData {
     FontListData(const nsACString& aLangGroup, const nsACString& aGenericFamily, nsStringArray& aListOfFonts) :
         mLangGroup(aLangGroup), mGenericFamily(aGenericFamily), mStringArray(aListOfFonts) {}
     const nsACString& mLangGroup;