From 96aa05bdaeae1258dff9387427ae24ca26410178 Mon Sep 17 00:00:00 2001 From: "pierre%netscape.com" Date: Sat, 25 Mar 2000 13:48:50 +0000 Subject: [PATCH] Related to #18136. Enable the IE-compatible font size table in strict mode. It required to pass the nsFontSizeType to FindNextSmaller/LargerFontSize. --- content/html/style/src/nsCSSStyleRule.cpp | 12 ++-- content/html/style/src/nsStyleUtil.cpp | 73 ++++++++++++++++------- content/shared/src/nsStyleUtil.cpp | 73 ++++++++++++++++------- layout/html/style/public/nsStyleUtil.h | 8 ++- layout/html/style/src/nsCSSStyleRule.cpp | 12 ++-- layout/html/style/src/nsStyleUtil.cpp | 73 ++++++++++++++++------- layout/style/nsCSSStyleRule.cpp | 12 ++-- layout/style/nsStyleUtil.cpp | 73 ++++++++++++++++------- 8 files changed, 236 insertions(+), 100 deletions(-) diff --git a/content/html/style/src/nsCSSStyleRule.cpp b/content/html/style/src/nsCSSStyleRule.cpp index 7b728f9c00a4..24ad2519a868 100644 --- a/content/html/style/src/nsCSSStyleRule.cpp +++ b/content/html/style/src/nsCSSStyleRule.cpp @@ -1386,14 +1386,14 @@ MapDeclarationFontInto(nsICSSDeclaration* aDeclaration, font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS); } else if (NS_STYLE_FONT_SIZE_LARGER == value) { - PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext); + PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS); } else if (NS_STYLE_FONT_SIZE_SMALLER == value) { - PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext); + PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS); } // this does NOT explicitly set font size font->mFlags &= ~NS_STYLE_FONT_SIZE_EXPLICIT; diff --git a/content/html/style/src/nsStyleUtil.cpp b/content/html/style/src/nsStyleUtil.cpp index 964097b293e6..92aa63422318 100644 --- a/content/html/style/src/nsStyleUtil.cpp +++ b/content/html/style/src/nsStyleUtil.cpp @@ -176,8 +176,13 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, #define sFontSizeTableMin 9 #define sFontSizeTableMax 16 -#if 0 - static PRInt32 sFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = +// This table seems to be the one used by MacIE5. We hope its adoption in Mozilla +// and eventually in WinIE5.5 will help to establish a standard rendering across +// platforms and browsers. For now, it is used only in Strict mode. More can be read +// in the document written by Todd Farhner at: +// http://style.verso.com/font_size_intervals/altintervals.html +// + static PRInt32 sStrictFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = { { 9, 9, 9, 9, 11, 14, 18, 27}, { 9, 9, 9, 10, 12, 15, 20, 30}, @@ -193,7 +198,7 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // | // user pref // -#else +//------------------------------------------------------------ // // This table gives us compatibility with WinNav4 for the default fonts only. // In WinNav4, the default fonts were: @@ -209,7 +214,7 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // going below 9px, and maintaining a "diagonal" relationship. See for // example the 13s -- they follow a diagonal line through the table. // - static PRInt32 sFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = + static PRInt32 sQuirksFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = { { 9, 9, 9, 9, 11, 14, 18, 28 }, { 9, 9, 9, 10, 12, 15, 20, 31 }, @@ -224,7 +229,6 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // CSS xxs xs s m l xl xxl // | // user pref -#endif #if 0 // @@ -276,7 +280,14 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, aPresContext->GetPixelsToTwips(&p2t); PRInt32 row = fontSize - sFontSizeTableMin; - dFontSize = NSIntPixelsToTwips(sFontSizeTable[row][column[aHTMLSize]], p2t); + + nsCompatibility mode; + aPresContext->GetCompatibilityMode(&mode); + if (mode == eCompatibility_NavQuirks) { + dFontSize = NSIntPixelsToTwips(sQuirksFontSizeTable[row][column[aHTMLSize]], p2t); + } else { + dFontSize = NSIntPixelsToTwips(sStrictFontSizeTable[row][column[aHTMLSize]], p2t); + } } else { @@ -317,19 +328,30 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize //------------------------------------------------------------------------------ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, - float aScalingFactor, nsIPresContext* aPresContext) + float aScalingFactor, nsIPresContext* aPresContext, + nsFontSizeType aFontSizeType) { PRInt32 index; + PRInt32 indexMin; + PRInt32 indexMax; PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); - if (NSTwipsToFloorIntPoints(CalcFontPointSize(1, aBasePointSize, aScalingFactor, aPresContext)) < fontSize) { - if (fontSize <= NSTwipsToFloorIntPoints(CalcFontPointSize(7, aBasePointSize, aScalingFactor, aPresContext))) { // in HTML table - for (index = 7; index > 1; index--) - if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) + if (aFontSizeType == eFontSize_HTML) { + indexMin = 1; + indexMax = 7; + } else { + indexMin = 0; + indexMax = 6; + } + + if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) < fontSize) { + if (fontSize <= NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table + for (index = indexMax; index > indexMin; index--) + if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) break; } else { // larger than HTML table - return 7; + return indexMax; // for (index = 8; ; index++) // if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // index--; @@ -338,7 +360,7 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi } } else { // smaller than HTML table - return 1; + return indexMin; // for (index = 0; -25 NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // break; @@ -353,26 +375,37 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi //------------------------------------------------------------------------------ PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, - float aScalingFactor, nsIPresContext* aPresContext) + float aScalingFactor, nsIPresContext* aPresContext, + nsFontSizeType aFontSizeType) { PRInt32 index; + PRInt32 indexMin; + PRInt32 indexMax; PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); - if (NSTwipsToFloorIntPoints(CalcFontPointSize(1, aBasePointSize, aScalingFactor, aPresContext)) <= fontSize) { - if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(7, aBasePointSize, aScalingFactor, aPresContext))) { // in HTML table - for (index = 1; index < 7; index++) - if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) + if (aFontSizeType == eFontSize_HTML) { + indexMin = 1; + indexMax = 7; + } else { + indexMin = 0; + indexMax = 6; + } + + if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) <= fontSize) { + if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table + for (index = indexMin; index < indexMax; index++) + if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) break; } else { // larger than HTML table - return 7; + return indexMax; // for (index = 8; ; index++) // if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) // break; } } else { // smaller than HTML table - return 1; + return indexMin; // for (index = 0; -25 NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // index++; diff --git a/content/shared/src/nsStyleUtil.cpp b/content/shared/src/nsStyleUtil.cpp index 964097b293e6..92aa63422318 100644 --- a/content/shared/src/nsStyleUtil.cpp +++ b/content/shared/src/nsStyleUtil.cpp @@ -176,8 +176,13 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, #define sFontSizeTableMin 9 #define sFontSizeTableMax 16 -#if 0 - static PRInt32 sFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = +// This table seems to be the one used by MacIE5. We hope its adoption in Mozilla +// and eventually in WinIE5.5 will help to establish a standard rendering across +// platforms and browsers. For now, it is used only in Strict mode. More can be read +// in the document written by Todd Farhner at: +// http://style.verso.com/font_size_intervals/altintervals.html +// + static PRInt32 sStrictFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = { { 9, 9, 9, 9, 11, 14, 18, 27}, { 9, 9, 9, 10, 12, 15, 20, 30}, @@ -193,7 +198,7 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // | // user pref // -#else +//------------------------------------------------------------ // // This table gives us compatibility with WinNav4 for the default fonts only. // In WinNav4, the default fonts were: @@ -209,7 +214,7 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // going below 9px, and maintaining a "diagonal" relationship. See for // example the 13s -- they follow a diagonal line through the table. // - static PRInt32 sFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = + static PRInt32 sQuirksFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = { { 9, 9, 9, 9, 11, 14, 18, 28 }, { 9, 9, 9, 10, 12, 15, 20, 31 }, @@ -224,7 +229,6 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // CSS xxs xs s m l xl xxl // | // user pref -#endif #if 0 // @@ -276,7 +280,14 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, aPresContext->GetPixelsToTwips(&p2t); PRInt32 row = fontSize - sFontSizeTableMin; - dFontSize = NSIntPixelsToTwips(sFontSizeTable[row][column[aHTMLSize]], p2t); + + nsCompatibility mode; + aPresContext->GetCompatibilityMode(&mode); + if (mode == eCompatibility_NavQuirks) { + dFontSize = NSIntPixelsToTwips(sQuirksFontSizeTable[row][column[aHTMLSize]], p2t); + } else { + dFontSize = NSIntPixelsToTwips(sStrictFontSizeTable[row][column[aHTMLSize]], p2t); + } } else { @@ -317,19 +328,30 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize //------------------------------------------------------------------------------ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, - float aScalingFactor, nsIPresContext* aPresContext) + float aScalingFactor, nsIPresContext* aPresContext, + nsFontSizeType aFontSizeType) { PRInt32 index; + PRInt32 indexMin; + PRInt32 indexMax; PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); - if (NSTwipsToFloorIntPoints(CalcFontPointSize(1, aBasePointSize, aScalingFactor, aPresContext)) < fontSize) { - if (fontSize <= NSTwipsToFloorIntPoints(CalcFontPointSize(7, aBasePointSize, aScalingFactor, aPresContext))) { // in HTML table - for (index = 7; index > 1; index--) - if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) + if (aFontSizeType == eFontSize_HTML) { + indexMin = 1; + indexMax = 7; + } else { + indexMin = 0; + indexMax = 6; + } + + if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) < fontSize) { + if (fontSize <= NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table + for (index = indexMax; index > indexMin; index--) + if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) break; } else { // larger than HTML table - return 7; + return indexMax; // for (index = 8; ; index++) // if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // index--; @@ -338,7 +360,7 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi } } else { // smaller than HTML table - return 1; + return indexMin; // for (index = 0; -25 NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // break; @@ -353,26 +375,37 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi //------------------------------------------------------------------------------ PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, - float aScalingFactor, nsIPresContext* aPresContext) + float aScalingFactor, nsIPresContext* aPresContext, + nsFontSizeType aFontSizeType) { PRInt32 index; + PRInt32 indexMin; + PRInt32 indexMax; PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); - if (NSTwipsToFloorIntPoints(CalcFontPointSize(1, aBasePointSize, aScalingFactor, aPresContext)) <= fontSize) { - if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(7, aBasePointSize, aScalingFactor, aPresContext))) { // in HTML table - for (index = 1; index < 7; index++) - if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) + if (aFontSizeType == eFontSize_HTML) { + indexMin = 1; + indexMax = 7; + } else { + indexMin = 0; + indexMax = 6; + } + + if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) <= fontSize) { + if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table + for (index = indexMin; index < indexMax; index++) + if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) break; } else { // larger than HTML table - return 7; + return indexMax; // for (index = 8; ; index++) // if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) // break; } } else { // smaller than HTML table - return 1; + return indexMin; // for (index = 0; -25 NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // index++; diff --git a/layout/html/style/public/nsStyleUtil.h b/layout/html/style/public/nsStyleUtil.h index e10a327d31d0..891a0c2f5443 100644 --- a/layout/html/style/public/nsStyleUtil.h +++ b/layout/html/style/public/nsStyleUtil.h @@ -44,10 +44,14 @@ public: static nscoord CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, float aScalingFactor, nsIPresContext* aPresContext, nsFontSizeType aFontSizeType = eFontSize_HTML); + static PRInt32 FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, - float aScalingFactor, nsIPresContext* aPresContext); + float aScalingFactor, nsIPresContext* aPresContext, + nsFontSizeType aFontSizeType = eFontSize_HTML); + static PRInt32 FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, - float aScalingFactor, nsIPresContext* aPresContext); + float aScalingFactor, nsIPresContext* aPresContext, + nsFontSizeType aFontSizeType = eFontSize_HTML); static PRInt32 ConstrainFontWeight(PRInt32 aWeight); diff --git a/layout/html/style/src/nsCSSStyleRule.cpp b/layout/html/style/src/nsCSSStyleRule.cpp index 7b728f9c00a4..24ad2519a868 100644 --- a/layout/html/style/src/nsCSSStyleRule.cpp +++ b/layout/html/style/src/nsCSSStyleRule.cpp @@ -1386,14 +1386,14 @@ MapDeclarationFontInto(nsICSSDeclaration* aDeclaration, font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS); } else if (NS_STYLE_FONT_SIZE_LARGER == value) { - PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext); + PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS); } else if (NS_STYLE_FONT_SIZE_SMALLER == value) { - PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext); + PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS); } // this does NOT explicitly set font size font->mFlags &= ~NS_STYLE_FONT_SIZE_EXPLICIT; diff --git a/layout/html/style/src/nsStyleUtil.cpp b/layout/html/style/src/nsStyleUtil.cpp index 964097b293e6..92aa63422318 100644 --- a/layout/html/style/src/nsStyleUtil.cpp +++ b/layout/html/style/src/nsStyleUtil.cpp @@ -176,8 +176,13 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, #define sFontSizeTableMin 9 #define sFontSizeTableMax 16 -#if 0 - static PRInt32 sFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = +// This table seems to be the one used by MacIE5. We hope its adoption in Mozilla +// and eventually in WinIE5.5 will help to establish a standard rendering across +// platforms and browsers. For now, it is used only in Strict mode. More can be read +// in the document written by Todd Farhner at: +// http://style.verso.com/font_size_intervals/altintervals.html +// + static PRInt32 sStrictFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = { { 9, 9, 9, 9, 11, 14, 18, 27}, { 9, 9, 9, 10, 12, 15, 20, 30}, @@ -193,7 +198,7 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // | // user pref // -#else +//------------------------------------------------------------ // // This table gives us compatibility with WinNav4 for the default fonts only. // In WinNav4, the default fonts were: @@ -209,7 +214,7 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // going below 9px, and maintaining a "diagonal" relationship. See for // example the 13s -- they follow a diagonal line through the table. // - static PRInt32 sFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = + static PRInt32 sQuirksFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = { { 9, 9, 9, 9, 11, 14, 18, 28 }, { 9, 9, 9, 10, 12, 15, 20, 31 }, @@ -224,7 +229,6 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // CSS xxs xs s m l xl xxl // | // user pref -#endif #if 0 // @@ -276,7 +280,14 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, aPresContext->GetPixelsToTwips(&p2t); PRInt32 row = fontSize - sFontSizeTableMin; - dFontSize = NSIntPixelsToTwips(sFontSizeTable[row][column[aHTMLSize]], p2t); + + nsCompatibility mode; + aPresContext->GetCompatibilityMode(&mode); + if (mode == eCompatibility_NavQuirks) { + dFontSize = NSIntPixelsToTwips(sQuirksFontSizeTable[row][column[aHTMLSize]], p2t); + } else { + dFontSize = NSIntPixelsToTwips(sStrictFontSizeTable[row][column[aHTMLSize]], p2t); + } } else { @@ -317,19 +328,30 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize //------------------------------------------------------------------------------ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, - float aScalingFactor, nsIPresContext* aPresContext) + float aScalingFactor, nsIPresContext* aPresContext, + nsFontSizeType aFontSizeType) { PRInt32 index; + PRInt32 indexMin; + PRInt32 indexMax; PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); - if (NSTwipsToFloorIntPoints(CalcFontPointSize(1, aBasePointSize, aScalingFactor, aPresContext)) < fontSize) { - if (fontSize <= NSTwipsToFloorIntPoints(CalcFontPointSize(7, aBasePointSize, aScalingFactor, aPresContext))) { // in HTML table - for (index = 7; index > 1; index--) - if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) + if (aFontSizeType == eFontSize_HTML) { + indexMin = 1; + indexMax = 7; + } else { + indexMin = 0; + indexMax = 6; + } + + if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) < fontSize) { + if (fontSize <= NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table + for (index = indexMax; index > indexMin; index--) + if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) break; } else { // larger than HTML table - return 7; + return indexMax; // for (index = 8; ; index++) // if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // index--; @@ -338,7 +360,7 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi } } else { // smaller than HTML table - return 1; + return indexMin; // for (index = 0; -25 NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // break; @@ -353,26 +375,37 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi //------------------------------------------------------------------------------ PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, - float aScalingFactor, nsIPresContext* aPresContext) + float aScalingFactor, nsIPresContext* aPresContext, + nsFontSizeType aFontSizeType) { PRInt32 index; + PRInt32 indexMin; + PRInt32 indexMax; PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); - if (NSTwipsToFloorIntPoints(CalcFontPointSize(1, aBasePointSize, aScalingFactor, aPresContext)) <= fontSize) { - if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(7, aBasePointSize, aScalingFactor, aPresContext))) { // in HTML table - for (index = 1; index < 7; index++) - if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) + if (aFontSizeType == eFontSize_HTML) { + indexMin = 1; + indexMax = 7; + } else { + indexMin = 0; + indexMax = 6; + } + + if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) <= fontSize) { + if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table + for (index = indexMin; index < indexMax; index++) + if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) break; } else { // larger than HTML table - return 7; + return indexMax; // for (index = 8; ; index++) // if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) // break; } } else { // smaller than HTML table - return 1; + return indexMin; // for (index = 0; -25 NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // index++; diff --git a/layout/style/nsCSSStyleRule.cpp b/layout/style/nsCSSStyleRule.cpp index 7b728f9c00a4..24ad2519a868 100644 --- a/layout/style/nsCSSStyleRule.cpp +++ b/layout/style/nsCSSStyleRule.cpp @@ -1386,14 +1386,14 @@ MapDeclarationFontInto(nsICSSDeclaration* aDeclaration, font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS); } else if (NS_STYLE_FONT_SIZE_LARGER == value) { - PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext); + PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS); } else if (NS_STYLE_FONT_SIZE_SMALLER == value) { - PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext); - font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext); + PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFont.size, scaleFactor, aPresContext, eFontSize_CSS); + font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)defaultFixedFont.size, scaleFactor, aPresContext, eFontSize_CSS); } // this does NOT explicitly set font size font->mFlags &= ~NS_STYLE_FONT_SIZE_EXPLICIT; diff --git a/layout/style/nsStyleUtil.cpp b/layout/style/nsStyleUtil.cpp index 964097b293e6..92aa63422318 100644 --- a/layout/style/nsStyleUtil.cpp +++ b/layout/style/nsStyleUtil.cpp @@ -176,8 +176,13 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, #define sFontSizeTableMin 9 #define sFontSizeTableMax 16 -#if 0 - static PRInt32 sFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = +// This table seems to be the one used by MacIE5. We hope its adoption in Mozilla +// and eventually in WinIE5.5 will help to establish a standard rendering across +// platforms and browsers. For now, it is used only in Strict mode. More can be read +// in the document written by Todd Farhner at: +// http://style.verso.com/font_size_intervals/altintervals.html +// + static PRInt32 sStrictFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = { { 9, 9, 9, 9, 11, 14, 18, 27}, { 9, 9, 9, 10, 12, 15, 20, 30}, @@ -193,7 +198,7 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // | // user pref // -#else +//------------------------------------------------------------ // // This table gives us compatibility with WinNav4 for the default fonts only. // In WinNav4, the default fonts were: @@ -209,7 +214,7 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // going below 9px, and maintaining a "diagonal" relationship. See for // example the 13s -- they follow a diagonal line through the table. // - static PRInt32 sFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = + static PRInt32 sQuirksFontSizeTable[sFontSizeTableMax - sFontSizeTableMin + 1][8] = { { 9, 9, 9, 9, 11, 14, 18, 28 }, { 9, 9, 9, 10, 12, 15, 20, 31 }, @@ -224,7 +229,6 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, // CSS xxs xs s m l xl xxl // | // user pref -#endif #if 0 // @@ -276,7 +280,14 @@ static nscoord NewCalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize, aPresContext->GetPixelsToTwips(&p2t); PRInt32 row = fontSize - sFontSizeTableMin; - dFontSize = NSIntPixelsToTwips(sFontSizeTable[row][column[aHTMLSize]], p2t); + + nsCompatibility mode; + aPresContext->GetCompatibilityMode(&mode); + if (mode == eCompatibility_NavQuirks) { + dFontSize = NSIntPixelsToTwips(sQuirksFontSizeTable[row][column[aHTMLSize]], p2t); + } else { + dFontSize = NSIntPixelsToTwips(sStrictFontSizeTable[row][column[aHTMLSize]], p2t); + } } else { @@ -317,19 +328,30 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize //------------------------------------------------------------------------------ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, - float aScalingFactor, nsIPresContext* aPresContext) + float aScalingFactor, nsIPresContext* aPresContext, + nsFontSizeType aFontSizeType) { PRInt32 index; + PRInt32 indexMin; + PRInt32 indexMax; PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); - if (NSTwipsToFloorIntPoints(CalcFontPointSize(1, aBasePointSize, aScalingFactor, aPresContext)) < fontSize) { - if (fontSize <= NSTwipsToFloorIntPoints(CalcFontPointSize(7, aBasePointSize, aScalingFactor, aPresContext))) { // in HTML table - for (index = 7; index > 1; index--) - if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) + if (aFontSizeType == eFontSize_HTML) { + indexMin = 1; + indexMax = 7; + } else { + indexMin = 0; + indexMax = 6; + } + + if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) < fontSize) { + if (fontSize <= NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table + for (index = indexMax; index > indexMin; index--) + if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) break; } else { // larger than HTML table - return 7; + return indexMax; // for (index = 8; ; index++) // if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // index--; @@ -338,7 +360,7 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi } } else { // smaller than HTML table - return 1; + return indexMin; // for (index = 0; -25 NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // break; @@ -353,26 +375,37 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi //------------------------------------------------------------------------------ PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, - float aScalingFactor, nsIPresContext* aPresContext) + float aScalingFactor, nsIPresContext* aPresContext, + nsFontSizeType aFontSizeType) { PRInt32 index; + PRInt32 indexMin; + PRInt32 indexMax; PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); - if (NSTwipsToFloorIntPoints(CalcFontPointSize(1, aBasePointSize, aScalingFactor, aPresContext)) <= fontSize) { - if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(7, aBasePointSize, aScalingFactor, aPresContext))) { // in HTML table - for (index = 1; index < 7; index++) - if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) + if (aFontSizeType == eFontSize_HTML) { + indexMin = 1; + indexMax = 7; + } else { + indexMin = 0; + indexMax = 6; + } + + if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) <= fontSize) { + if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table + for (index = indexMin; index < indexMax; index++) + if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) break; } else { // larger than HTML table - return 7; + return indexMax; // for (index = 8; ; index++) // if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) // break; } } else { // smaller than HTML table - return 1; + return indexMin; // for (index = 0; -25 NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { // index++;