Special fix to enable the WindDings font. Also homogenized identation&printf while there. b=77265 r=shanjian sr=blizzard

This commit is contained in:
rbs%maths.uq.edu.au 2001-05-16 02:38:14 +00:00
Родитель 340a54de59
Коммит 233d2e3996
3 изменённых файлов: 220 добавлений и 189 удалений

Просмотреть файл

@ -79,3 +79,7 @@ encoding.math5monobold.ttf = x-mathematica5
# MathType Extra
encoding.mtextra.ttf = x-mtextra
# Hack for compatibility with Nav4.x (bug 77265)
# Treat these Symbol fonts as if they have the given encoding
encoding.wingdings.ttf = windows-1252

Просмотреть файл

@ -273,17 +273,15 @@ InitGlobals(void)
return NS_OK;
}
static void CheckFontLangGroup(
static void
CheckFontLangGroup(
nsIAtom* lang1, nsIAtom* lang2, const char* lang3, PRBool& hit,
PRBool& check, PRBool& have)
{
if( (!have) && (!hit) && (lang1 == lang2))
{
if ((!have) && (!hit) && (lang1 == lang2)) {
hit = PR_TRUE; // so next time we don't bother to ask
if(!check)
{
if (!check) {
nsFontEnumeratorWin enumerator;
if (NS_SUCCEEDED(enumerator.HaveFontFor(lang3, &have)))
check = PR_TRUE; // so next time we don't bother to check.
}
@ -1255,8 +1253,7 @@ nsFontMetricsWin::GetCMAP(HDC aDC, const char* aShortName, int* aFontType, PRUin
}
PR_Free(buf);
// XXX Need to check if an identical map has already been added
// XXX See Bug 75260 "Investigate the sharing of font maps"
// XXX Need to check if an identical map has already been added - Bug 75260
NS_ASSERTION(hep, "bad code");
he = PL_HashTableRawAdd(gFontMaps, hep, hash, name, nsnull);
if (he) {
@ -1286,8 +1283,7 @@ nsFontMetricsWin::GetCMAP(HDC aDC, const char* aShortName, int* aFontType, PRUin
}
PR_Free(buf);
// XXX Need to check if an identical map has already been added
// XXX See Bug 75260 "Investigate the sharing of font maps"
// XXX Need to check if an identical map has already been added - Bug 75260
NS_ASSERTION(hep, "bad code");
he = PL_HashTableRawAdd(gFontMaps, hep, hash, name, nsnull);
if (he) {
@ -1416,8 +1412,7 @@ nsFontMetricsWin::GetCMAP(HDC aDC, const char* aShortName, int* aFontType, PRUin
*aFontType = NS_FONT_TYPE_UNICODE;
}
// XXX Need to check if an identical map has already been added
// XXX See Bug 75260 "Investigate the sharing of font maps"
// XXX Need to check if an identical map has already been added - Bug 75260
NS_ASSERTION(hep, "bad code");
he = PL_HashTableRawAdd(gFontMaps, hep, hash, name, nsnull);
if (he) {
@ -1942,14 +1937,12 @@ static int CALLBACK enumProc(const LOGFONT* logFont, const TEXTMETRIC* metrics,
for (int i = 0; i < nsFontMetricsWin::gGlobalFontsCount; i++) {
if (!strcmp(nsFontMetricsWin::gGlobalFonts[i].logFont.lfFaceName,
logFont->lfFaceName)) {
// work-around for Win95/98 problem
int charSetSigBit = charSetToBit[gCharSetToIndex[logFont->lfCharSet]];
if (charSetSigBit >= 0) {
DWORD charsetSigAdd = 1 << charSetSigBit;
nsFontMetricsWin::gGlobalFonts[i].signature.fsCsb[0] |= charsetSigAdd;
}
return 1;
}
}
@ -1969,40 +1962,66 @@ static int CALLBACK enumProc(const LOGFONT* logFont, const TEXTMETRIC* metrics,
}
}
nsGlobalFont font;
nsGlobalFont* font =
&nsFontMetricsWin::gGlobalFonts[nsFontMetricsWin::gGlobalFontsCount];
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) {
font->name = new nsString(name);
if (!font->name) {
return 0;
}
font.map = nsnull;
font.logFont = *logFont;
font.skip = 0;
font.signature.fsCsb[0] = 0;
font.signature.fsCsb[1] = 0;
font->map = nsnull;
font->logFont = *logFont;
font->flags = 0;
font->signature.fsCsb[0] = 0;
font->signature.fsCsb[1] = 0;
if (fontType & TRUETYPE_FONTTYPE) {
font->flags |= NS_GLOBALFONT_TRUETYPE;
}
if (logFont->lfCharSet == SYMBOL_CHARSET) {
font->flags |= NS_GLOBALFONT_SYMBOL;
}
int charSetSigBit = charSetToBit[gCharSetToIndex[logFont->lfCharSet]];
if (charSetSigBit >= 0) {
DWORD charsetSigAdd = 1 << charSetSigBit;
font.signature.fsCsb[0] |= charsetSigAdd;
font->signature.fsCsb[0] |= charsetSigAdd;
}
static int lastTtfFont = 0;
if (fontType & TRUETYPE_FONTTYPE) {
nsFontMetricsWin::gGlobalFonts[nsFontMetricsWin::gGlobalFontsCount++] =
nsFontMetricsWin::gGlobalFonts[lastTtfFont];
nsFontMetricsWin::gGlobalFonts[lastTtfFont++] = font;
}
else
nsFontMetricsWin::gGlobalFonts[nsFontMetricsWin::gGlobalFontsCount++] = font;
++nsFontMetricsWin::gGlobalFontsCount;
return 1;
}
static int
CompareGlobalFonts(const void* aArg1, const void* aArg2, void* aClosure)
{
const nsGlobalFont* font1 = (const nsGlobalFont*)aArg1;
const nsGlobalFont* font2 = (const nsGlobalFont*)aArg2;
// Sorting criteria is like a tree:
// + TrueType fonts
// + non-Symbol fonts
// + Symbol fonts
// + non-TrueType fonts
// + non-Symbol fonts
// + Symbol fonts
PRInt32 weight1 = 0, weight2 = 0; // computed as node mask
if (!(font1->flags & NS_GLOBALFONT_TRUETYPE))
weight1 |= 0x2;
if (!(font2->flags & NS_GLOBALFONT_TRUETYPE))
weight2 |= 0x2;
if (font1->flags & NS_GLOBALFONT_SYMBOL)
weight1 |= 0x1;
if (font2->flags & NS_GLOBALFONT_SYMBOL)
weight2 |= 0x1;
return weight1 - weight2;
}
nsGlobalFont*
nsFontMetricsWin::InitializeGlobalFonts(HDC aDC)
{
@ -2019,6 +2038,10 @@ nsFontMetricsWin::InitializeGlobalFonts(HDC aDC)
* EnumFontFamiliesExW is only on NT/2000
*/
EnumFontFamiliesEx(aDC, &logFont, enumProc, nsnull, 0);
// Sort the global list of fonts to put the 'preferred' fonts first
NS_QuickSort(gGlobalFonts, gGlobalFontsCount, sizeof(nsGlobalFont),
CompareGlobalFonts, nsnull);
}
return gGlobalFonts;
@ -2028,9 +2051,11 @@ int
nsFontMetricsWin::SameAsPreviousMap(int aIndex)
{
for (int i = 0; i < aIndex; i++) {
if (!gGlobalFonts[i].skip) {
if (gGlobalFonts[i].flags & NS_GLOBALFONT_SKIP) {
continue;
}
if (gGlobalFonts[i].map == gGlobalFonts[aIndex].map) {
gGlobalFonts[aIndex].skip = 1;
gGlobalFonts[aIndex].flags |= NS_GLOBALFONT_SKIP;
return 1;
}
PRUint32* map1 = gGlobalFonts[i].map;
@ -2042,11 +2067,10 @@ nsFontMetricsWin::SameAsPreviousMap(int aIndex)
}
}
if (j == 2048) {
gGlobalFonts[aIndex].skip = 1;
gGlobalFonts[aIndex].flags |= NS_GLOBALFONT_SKIP;
return 1;
}
}
}
return 0;
}
@ -2061,7 +2085,9 @@ nsFontMetricsWin::FindGlobalFont(HDC aDC, PRUnichar c)
}
}
for (int i = 0; i < gGlobalFontsCount; i++) {
if (!gGlobalFonts[i].skip) {
if (gGlobalFonts[i].flags & NS_GLOBALFONT_SKIP) {
continue;
}
if (!gGlobalFonts[i].map) {
HFONT font = ::CreateFontIndirect(&gGlobalFonts[i].logFont);
if (!font) {
@ -2073,7 +2099,7 @@ nsFontMetricsWin::FindGlobalFont(HDC aDC, PRUnichar c)
::SelectObject(aDC, oldFont);
::DeleteObject(font);
if (!gGlobalFonts[i].map || gGlobalFonts[i].map == gEmptyMap) {
gGlobalFonts[i].skip = 1;
gGlobalFonts[i].flags |= NS_GLOBALFONT_SKIP;
continue;
}
if (SameAsPreviousMap(i)) {
@ -2084,7 +2110,6 @@ nsFontMetricsWin::FindGlobalFont(HDC aDC, PRUnichar c)
return LoadGlobalFont(aDC, &(gGlobalFonts[i]));
}
}
}
return nsnull;
}
@ -3353,7 +3378,6 @@ nsFontWinUnicode::GetBoundingMetrics(HDC aDC,
if (GDI_ERROR == len) {
return NS_ERROR_UNEXPECTED;
}
else {
// flip sign of descent for cross-platform compatibility
descent = -(nscoord(gm.gmptGlyphOrigin.y) - nscoord(gm.gmBlackBoxY));
aBoundingMetrics.leftBearing = gm.gmptGlyphOrigin.x;
@ -3361,7 +3385,7 @@ nsFontWinUnicode::GetBoundingMetrics(HDC aDC,
aBoundingMetrics.ascent = gm.gmptGlyphOrigin.y;
aBoundingMetrics.descent = descent;
aBoundingMetrics.width = gm.gmCellIncX;
}
if (1 < aLength) {
// loop over each glyph to get the ascent and descent
PRUint32 i;
@ -3370,7 +3394,6 @@ nsFontWinUnicode::GetBoundingMetrics(HDC aDC,
if (GDI_ERROR == len) {
return NS_ERROR_UNEXPECTED;
}
else {
// flip sign of descent for cross-platform compatibility
descent = -(nscoord(gm.gmptGlyphOrigin.y) - nscoord(gm.gmBlackBoxY));
if (aBoundingMetrics.ascent < gm.gmptGlyphOrigin.y)
@ -3378,7 +3401,6 @@ nsFontWinUnicode::GetBoundingMetrics(HDC aDC,
if (aBoundingMetrics.descent < descent)
aBoundingMetrics.descent = descent;
}
}
// get the final rightBearing and width. Possible kerning is taken into account.
SIZE size;
::GetTextExtentPointW(aDC, aString, aLength, &size);
@ -3485,7 +3507,6 @@ nsFontWinNonUnicode::GetBoundingMetrics(HDC aDC,
if (GDI_ERROR == len) {
return NS_ERROR_UNEXPECTED;
}
else {
// flip sign of descent for cross-platform compatibility
descent = -(nscoord(gm.gmptGlyphOrigin.y) - nscoord(gm.gmBlackBoxY));
aBoundingMetrics.leftBearing = gm.gmptGlyphOrigin.x;
@ -3493,7 +3514,7 @@ nsFontWinNonUnicode::GetBoundingMetrics(HDC aDC,
aBoundingMetrics.ascent = gm.gmptGlyphOrigin.y;
aBoundingMetrics.descent = descent;
aBoundingMetrics.width = gm.gmCellIncX;
}
if (1 < aLength) {
// loop over each glyph to get the ascent and descent
PRUint32 i;
@ -3502,7 +3523,6 @@ nsFontWinNonUnicode::GetBoundingMetrics(HDC aDC,
if (GDI_ERROR == len) {
return NS_ERROR_UNEXPECTED;
}
else {
// flip sign of descent for cross-platform compatibility
descent = -(nscoord(gm.gmptGlyphOrigin.y) - nscoord(gm.gmBlackBoxY));
if (aBoundingMetrics.ascent < gm.gmptGlyphOrigin.y)
@ -3510,7 +3530,6 @@ nsFontWinNonUnicode::GetBoundingMetrics(HDC aDC,
if (aBoundingMetrics.descent < descent)
aBoundingMetrics.descent = descent;
}
}
// get the final rightBearing and width. Possible kerning is taken into account.
SIZE size;
::GetTextExtentPointA(aDC, pstr, aLength, &size);
@ -3657,7 +3676,6 @@ nsFontWinSubstitute::GetBoundingMetrics(HDC aDC,
if (GDI_ERROR == len) {
return NS_ERROR_UNEXPECTED;
}
else {
// flip sign of descent for cross-platform compatibility
descent = -(nscoord(gm.gmptGlyphOrigin.y) - nscoord(gm.gmBlackBoxY));
aBoundingMetrics.leftBearing = gm.gmptGlyphOrigin.x;
@ -3665,7 +3683,7 @@ nsFontWinSubstitute::GetBoundingMetrics(HDC aDC,
aBoundingMetrics.ascent = gm.gmptGlyphOrigin.y;
aBoundingMetrics.descent = descent;
aBoundingMetrics.width = gm.gmCellIncX;
}
if (1 < aLength) {
// loop over each glyph to get the ascent and descent
PRUint32 i;
@ -3674,7 +3692,6 @@ nsFontWinSubstitute::GetBoundingMetrics(HDC aDC,
if (GDI_ERROR == len) {
return NS_ERROR_UNEXPECTED;
}
else {
// flip sign of descent for cross-platform compatibility
descent = -(nscoord(gm.gmptGlyphOrigin.y) - nscoord(gm.gmBlackBoxY));
if (aBoundingMetrics.ascent < gm.gmptGlyphOrigin.y)
@ -3682,7 +3699,6 @@ nsFontWinSubstitute::GetBoundingMetrics(HDC aDC,
if (aBoundingMetrics.descent < descent)
aBoundingMetrics.descent = descent;
}
}
// get the final rightBearing and width. Possible kerning is taken into account.
SIZE size;
::GetTextExtentPointW(aDC, pstr, aLength, &size);
@ -3713,7 +3729,9 @@ nsFontWinSubstitute::DumpFontInfo()
static void
GenerateDefault(nsCharSetInfo* aSelf)
{
#ifdef NS_DEBUG
printf("%s defaulted\n", aSelf->mName);
#endif
PRUint32* map = aSelf->mMap;
for (int i = 0; i < 2048; i++) {
map[i] = 0xFFFFFFFF;
@ -3730,9 +3748,11 @@ GenerateSingleByte(nsCharSetInfo* aSelf)
mb[i] = i;
}
int len = MultiByteToWideChar(aSelf->mCodePage, 0, (char*) mb, 256, wc, 256);
#ifdef NS_DEBUG
if (len != 256) {
printf("%s: MultiByteToWideChar returned %d\n", aSelf->mName, len);
}
#endif
PRUint32* map = aSelf->mMap;
for (i = 0; i < 256; i++) {
ADD_GLYPH(map, wc[i]);
@ -3918,7 +3938,6 @@ nsFontSubset::GetBoundingMetrics(HDC aDC,
if (GDI_ERROR == len) {
return NS_ERROR_UNEXPECTED;
}
else {
// flip sign of descent for cross-platform compatibility
descent = -(nscoord(gm.gmptGlyphOrigin.y) - nscoord(gm.gmBlackBoxY));
aBoundingMetrics.leftBearing = gm.gmptGlyphOrigin.x;
@ -3926,7 +3945,7 @@ nsFontSubset::GetBoundingMetrics(HDC aDC,
aBoundingMetrics.ascent = gm.gmptGlyphOrigin.y;
aBoundingMetrics.descent = descent;
aBoundingMetrics.width = gm.gmCellIncX;
}
if (1 < nb) {
// loop over each glyph to get the ascent and descent
int i;
@ -3935,7 +3954,6 @@ nsFontSubset::GetBoundingMetrics(HDC aDC,
if (GDI_ERROR == len) {
return NS_ERROR_UNEXPECTED;
}
else {
// flip sign of descent for cross-platform compatibility
descent = -(nscoord(gm.gmptGlyphOrigin.y) - nscoord(gm.gmBlackBoxY));
if (aBoundingMetrics.ascent < gm.gmptGlyphOrigin.y)
@ -3943,7 +3961,6 @@ nsFontSubset::GetBoundingMetrics(HDC aDC,
if (aBoundingMetrics.descent > descent)
aBoundingMetrics.descent = descent;
}
}
// get the final rightBearing and width. Possible kerning is taken into account.
SIZE size;
@ -4322,7 +4339,9 @@ nsFontMetricsWinA::FindGlobalFont(HDC aDC, PRUnichar c)
return nsnull;
}
for (int i = 0; i < gGlobalFontsCount; i++) {
if (!gGlobalFonts[i].skip) {
if (gGlobalFonts[i].flags & NS_GLOBALFONT_SKIP) {
continue;
}
if (!gGlobalFonts[i].map) {
HFONT font = ::CreateFontIndirect(&gGlobalFonts[i].logFont);
if (!font) {
@ -4334,7 +4353,7 @@ nsFontMetricsWinA::FindGlobalFont(HDC aDC, PRUnichar c)
::SelectObject(aDC, oldFont);
::DeleteObject(font);
if (!gGlobalFonts[i].map || gGlobalFonts[i].map == gEmptyMap) {
gGlobalFonts[i].skip = 1;
gGlobalFonts[i].flags |= NS_GLOBALFONT_SKIP;
continue;
}
if (SameAsPreviousMap(i)) {
@ -4363,7 +4382,6 @@ nsFontMetricsWinA::FindGlobalFont(HDC aDC, PRUnichar c)
}
}
}
}
return nsnull;
}
@ -4614,6 +4632,7 @@ nsFontEnumeratorWin::EnumerateFonts(const char* aLangGroup,
return NS_OK;
}
NS_IMETHODIMP
nsFontEnumeratorWin::HaveFontFor(const char* aLangGroup, PRBool* aResult)
{

Просмотреть файл

@ -86,11 +86,19 @@ typedef struct nsGlobalFont
nsString* name;
LOGFONT logFont;
PRUint32* map;
PRUint8 skip;
FONTSIGNATURE signature;
int fonttype;
PRUint32 flags;
} nsGlobalFont;
// Bits used for nsGlobalFont.flags
// If this bit is set, then the font is to be ignored
#define NS_GLOBALFONT_SKIP 0x80000000L
// If this bit is set, then the font is a TrueType font
#define NS_GLOBALFONT_TRUETYPE 0x40000000L
// If this bit is set, then the font is a Symbol font (SYMBOL_CHARSET)
#define NS_GLOBALFONT_SYMBOL 0x20000000L
class nsFontMetricsWin : public nsIFontMetrics
{
public: