From 5447721bb76e0f1a7289d7955237f48877585003 Mon Sep 17 00:00:00 2001 From: "erik%netscape.com" Date: Tue, 13 Apr 1999 20:04:51 +0000 Subject: [PATCH] Win95's font enumerator returns less info (smaller structs). Added code to get the info via another method. Also enlarged the Unicode range array to prevent reading off the end. Added printf's for debugging the Unicode ranges. --- gfx/src/windows/nsFontMetricsWin.cpp | 190 ++++++++++++++++----------- 1 file changed, 114 insertions(+), 76 deletions(-) diff --git a/gfx/src/windows/nsFontMetricsWin.cpp b/gfx/src/windows/nsFontMetricsWin.cpp index 5c7f417b4c23..4903e1f12dc6 100644 --- a/gfx/src/windows/nsFontMetricsWin.cpp +++ b/gfx/src/windows/nsFontMetricsWin.cpp @@ -23,7 +23,8 @@ static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID); typedef struct UnicodeRange { -#ifdef NS_DEBUG +#undef UNICODE_RANGE_DESCRIPTION +#ifdef UNICODE_RANGE_DESCRIPTION PRUint8 bit; char* description; #endif @@ -31,430 +32,430 @@ typedef struct UnicodeRange PRUint16 end; } UnicodeRange; -static UnicodeRange unicodeRanges[] = +static UnicodeRange unicodeRanges[128] = { { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 0, "Basic Latin", #endif 0x0020, 0x007E }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 1, "Latin-1 Supplement", #endif 0x00A0, 0x00FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 2, "Latin Extended-A", #endif 0x0100, 0x017F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 3, "Latin Extended-B", #endif 0x0180, 0x024F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 4, "IPA Extensions", #endif 0x0250, 0x02AF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 5, "Spacing Modifier Letters", #endif 0x02B0, 0x02FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 6, "Combining Diacritical Marks", #endif 0x0300, 0x036F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 7, "Basic Greek", #endif 0x0370, 0x03CF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 8, "Greek Symbols and Coptic", #endif 0x03D0, 0x03FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 9, "Cyrillic", #endif 0x0400, 0x04FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 10, "Armenian", #endif 0x0530, 0x058F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 11, "Basic Hebrew", #endif 0x05D0, 0x05FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 12, "Hebrew Extended", #endif 0x0590, 0x05CF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 13, "Basic Arabic", #endif 0x0600, 0x0652 }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 14, "Arabic Extended", #endif 0x0653, 0x06FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 15, "Devanagari", #endif 0x0900, 0x097F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 16, "Bengali", #endif 0x0980, 0x09FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 17, "Gurmukhi", #endif 0x0A00, 0x0A7F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 18, "Gujarati", #endif 0x0A80, 0x0AFF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 19, "Oriya", #endif 0x0B00, 0x0B7F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 20, "Tamil", #endif 0x0B80, 0x0BFF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 21, "Telugu", #endif 0x0C00, 0x0C7F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 22, "Kannada", #endif 0x0C80, 0x0CFF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 23, "Malayalam", #endif 0x0D00, 0x0D7F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 24, "Thai", #endif 0x0E00, 0x0E7F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 25, "Lao", #endif 0x0E80, 0x0EFF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 26, "Basic Georgian", #endif 0x10D0, 0x10FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 27, "Georgian Extended", #endif 0x10A0, 0x10CF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 28, "Hangul Jamo", #endif 0x1100, 0x11FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 29, "Latin Extended Additional", #endif 0x1E00, 0x1EFF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 30, "Greek Extended", #endif 0x1F00, 0x1FFF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 31, "General Punctuation", #endif 0x2000, 0x206F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 32, "Subscripts and Superscripts", #endif 0x2070, 0x209F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 33, "Currency Symbols", #endif 0x20A0, 0x20CF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 34, "Combining Diacritical Marks for Symbols", #endif 0x20D0, 0x20FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 35, "Letter-like Symbols", #endif 0x2100, 0x214F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 36, "Number Forms", #endif 0x2150, 0x218F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 37, "Arrows", #endif 0x2190, 0x21FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 38, "Mathematical Operators", #endif 0x2200, 0x22FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 39, "Miscellaneous Technical", #endif 0x2300, 0x23FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 40, "Control Pictures", #endif 0x2400, 0x243F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 41, "Optical Character Recognition", #endif 0x2440, 0x245F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 42, "Enclosed Alphanumerics", #endif 0x2460, 0x24FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 43, "Box Drawing", #endif 0x2500, 0x257F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 44, "Block Elements", #endif 0x2580, 0x259F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 45, "Geometric Shapes", #endif 0x25A0, 0x25FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 46, "Miscellaneous Symbols", #endif 0x2600, 0x26FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 47, "Dingbats", #endif 0x2700, 0x27BF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 48, "Chinese, Japanese, and Korean (CJK) Symbols and Punctuation", #endif 0x3000, 0x303F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 49, "Hiragana", #endif 0x3040, 0x309F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 50, "Katakana", #endif 0x30A0, 0x30FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 51, "Bopomofo", #endif 0x3100, 0x312F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 52, "Hangul Compatibility Jamo", #endif 0x3130, 0x318F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 53, "CJK Miscellaneous", #endif 0x3190, 0x319F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 54, "Enclosed CJK", #endif 0x3200, 0x32FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 55, "CJK Compatibility", #endif 0x3300, 0x33FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 56, "Hangul", #endif 0xAC00, 0xD7A3 }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 57, "Reserved for Unicode Subranges", #endif 0x3D2E, 0x44B7 }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 58, "Reserved for Unicode Subranges", #endif 0x44B8, 0x4DFF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 59, "CJK Unified Ideographs", #endif 0x4E00, 0x9FFF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 60, "Private Use Area", #endif 0xE000, 0xF8FF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 61, "CJK Compatibility Ideographs", #endif 0xF900, 0xFAFF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 62, "Alphabetic Presentation Forms", #endif 0xFB00, 0xFB4F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 63, "Arabic Presentation Forms-A", #endif 0xFB50, 0xFDFF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 64, "Combining Half Marks", #endif 0xFE20, 0xFE2F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 65, "CJK Compatibility Forms", #endif 0xFE30, 0xFE4F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 66, "Small Form Variants", #endif 0xFE50, 0xFE6F }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 67, "Arabic Presentation Forms-B", #endif 0xFE70, 0xFEFE }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 68, "Halfwidth and Fullwidth Forms", #endif 0xFF00, 0xFFEF }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 69, "Specials", #endif 0xFFF0, 0xFFFD }, { -#ifdef NS_DEBUG +#ifdef UNICODE_RANGE_DESCRIPTION 70-127, "Reserved for Unicode Subranges", #endif 0x0000, 0x0000 @@ -655,13 +656,25 @@ FillBitMap(FONTSIGNATURE* aSignature, PRUint8* aMap) { DWORD* array = aSignature->fsUsb; int i = 0; - for (int dword = 0; dword < 4; dword++) { + int dword; +#ifdef UNICODE_RANGE_DESCRIPTION + printf(" FONTSIGNATURE.fsUsb:"); + for (dword = 0; dword < 4; dword++) { + printf(" 0x%08X", array[dword]); + } + printf("\n"); +#endif + for (dword = 0; dword < 4; dword++) { for (int bit = 0; bit < sizeof(DWORD) * 8; bit++) { if ((array[dword] >> bit) & 1) { int end = unicodeRanges[i].end; for (int c = unicodeRanges[i].begin; c <= end; c++) { ADD_GLYPH(aMap, c); } +#ifdef UNICODE_RANGE_DESCRIPTION + printf(" %s\n", + unicodeRanges[i].description?unicodeRanges[i].description:"NULL"); +#endif } i++; } @@ -698,6 +711,9 @@ nsFontMetricsWin::LoadFont(HDC aDC, nsString* aName) memset(font->map, 0, sizeof(font->map)); FONTSIGNATURE signature; GetTextCharsetInfo(aDC, &signature, 0); +#ifdef UNICODE_RANGE_DESCRIPTION + printf("%s\n", logFont.lfFaceName); +#endif FillBitMap(&signature, font->map); ::SelectObject(aDC, (HGDIOBJ) oldFont); @@ -725,10 +741,27 @@ static int CALLBACK enumProc(const LOGFONT* logFont, const TEXTMETRIC* metrics, } } nsGlobalFont* font = &gGlobalFonts[gGlobalFontsCount++]; - NEWTEXTMETRICEX* metricsEx = (NEWTEXTMETRICEX*) metrics; + + // XXX do correct character encoding conversion here font->name = new nsString(logFont->lfFaceName); + +// XXX use the fast way on NT only? +#if 0 + NEWTEXTMETRICEX* metricsEx = (NEWTEXTMETRICEX*) metrics; font->signature = metricsEx->ntmFontSig; +#else + HDC dc = (HDC) closure; + HFONT hfont = ::CreateFontIndirect(logFont); + if (hfont) { + HFONT oldFont = (HFONT) ::SelectObject(dc, (HGDIOBJ) hfont); + GetTextCharsetInfo(dc, &font->signature, 0); + ::SelectObject(dc, (HGDIOBJ) oldFont); + ::DeleteObject(hfont); + } +#endif + font->map = nsnull; + return 1; } @@ -740,7 +773,7 @@ nsFontMetricsWin::FindGlobalFont(HDC aDC, PRUnichar c) logFont.lfCharSet = DEFAULT_CHARSET; logFont.lfFaceName[0] = 0; logFont.lfPitchAndFamily = 0; - EnumFontFamiliesEx(aDC, &logFont, enumProc, NULL, 0); + EnumFontFamiliesEx(aDC, &logFont, enumProc, (LPARAM) aDC, 0); } for (int i = 0; i < gGlobalFontsCount; i++) { if (!gGlobalFonts[i].map) { @@ -748,6 +781,11 @@ nsFontMetricsWin::FindGlobalFont(HDC aDC, PRUnichar c) if (!gGlobalFonts[i].map) { return nsnull; } +#ifdef UNICODE_RANGE_DESCRIPTION + char name[LF_FACESIZE]; + gGlobalFonts[i].name->ToCString(name, sizeof(name)); + printf("%s\n", name); +#endif FillBitMap(&gGlobalFonts[i].signature, gGlobalFonts[i].map); } if (FONT_HAS_GLYPH(gGlobalFonts[i].map, c)) {