Make font-size:larger and font-size:smaller smarter about interpolating and

extrapolating font sizes.  Bug 72164, patch by Eric Lawrence
<elawrenc69@yahoo.com>, r=bzbarsky, r+sr=dbaron, a=asa
This commit is contained in:
bzbarsky%mit.edu 2003-05-17 16:11:51 +00:00
Родитель 8cc6308bb7
Коммит f8491914bd
6 изменённых файлов: 200 добавлений и 164 удалений

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

@ -1982,41 +1982,15 @@ SetFont(nsIPresContext* aPresContext, nsStyleContext* aContext,
nsStyleFont::UnZoomText(aPresContext, aParentFont->mSize); nsStyleFont::UnZoomText(aPresContext, aParentFont->mSize);
if (NS_STYLE_FONT_SIZE_LARGER == value) { if (NS_STYLE_FONT_SIZE_LARGER == value) {
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentSize, (PRInt32)aDefaultFont.size, aFont->mSize = nsStyleUtil::FindNextLargerFontSize(parentSize, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS);
NS_ASSERTION(aFont->mSize > parentSize, "FindNextLargerFontSize failed.");
}
else {
aFont->mSize = nsStyleUtil::FindNextSmallerFontSize(parentSize, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS); scaleFactor, aPresContext, eFontSize_CSS);
nscoord largerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size, NS_ASSERTION(aFont->mSize < parentSize,
scaleFactor, aPresContext, eFontSize_CSS); "FindNextSmallerFontSize failed; this is expected if parentFont size <= 1px");
aFont->mSize = PR_MAX(largerSize, aParentFont->mSize);
if (index == 6 &&
aFont->mSize == aParentFont->mSize) {
// 6 is the maximal answer from nsStyleUtil::FindNextLargerFontSize
// when eFontSize_CSS parameter is passed; we reached the limit for
// CSS named sizes, let's apply a %age.
// 150% is more or less the ratio between xx-large and x-large in
// all tables defined in nsStyleUtil.cpp
aFont->mSize = (nscoord)((float)(aParentFont->mSize) * 1.5);
}
else if (index == 0) {
largerSize = (nscoord)((float)(aParentFont->mSize) / 0.9);
aFont->mSize = PR_MIN(largerSize, aFont->mSize);
}
} else {
PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentSize, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS);
nscoord smallerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS);
aFont->mSize = PR_MIN(smallerSize, aParentFont->mSize);
if (index == 0 &&
aFont->mSize == aParentFont->mSize) {
// 0 is the miminal answer from nsStyleUtil::FindNextLargerFontSize
// when eFontSize_CSS parameter is passed; we reached the limit for
// CSS named sizes, let's apply a %age
aFont->mSize = (nscoord)((float)(aParentFont->mSize) * 0.9);
}
else if (index == 6) {
smallerSize = (nscoord)((float)(aParentFont->mSize) / 1.5);
aFont->mSize = PR_MAX(smallerSize, aFont->mSize);
}
} }
} else { } else {
NS_NOTREACHED("unexpected value"); NS_NOTREACHED("unexpected value");

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

@ -60,11 +60,11 @@ public:
float aScalingFactor, nsIPresContext* aPresContext, float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType = eFontSize_HTML); nsFontSizeType aFontSizeType = eFontSize_HTML);
static PRInt32 FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, static nscoord FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext, float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType = eFontSize_HTML); nsFontSizeType aFontSizeType = eFontSize_HTML);
static PRInt32 FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, static nscoord FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext, float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType = eFontSize_HTML); nsFontSizeType aFontSizeType = eFontSize_HTML);

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

@ -403,20 +403,30 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize
return OldCalcFontPointSize(aHTMLSize, aBasePointSize, aScalingFactor); return OldCalcFontPointSize(aHTMLSize, aBasePointSize, aScalingFactor);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, nscoord nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext, float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType) nsFontSizeType aFontSizeType)
{ {
PRInt32 index; PRInt32 index;
PRInt32 indexMin; PRInt32 indexMin;
PRInt32 indexMax; PRInt32 indexMax;
PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); float relativePosition;
nscoord smallerSize;
nscoord indexFontSize;
nscoord smallestIndexFontSize;
nscoord largestIndexFontSize;
nscoord smallerIndexFontSize;
nscoord largerIndexFontSize;
float p2t;
nscoord onePx;
aPresContext->GetPixelsToTwips(&p2t);
onePx = NSToCoordRound(p2t);
if (aFontSizeType == eFontSize_HTML) { if (aFontSizeType == eFontSize_HTML) {
indexMin = 1; indexMin = 1;
indexMax = 7; indexMax = 7;
@ -424,46 +434,67 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi
indexMin = 0; indexMin = 0;
indexMax = 6; indexMax = 6;
} }
if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) < fontSize) { smallestIndexFontSize = CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (fontSize <= NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
for (index = indexMax; index > indexMin; index--) if (aFontSize > smallestIndexFontSize) {
if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) if (aFontSize < NSToCoordRound(float(largestIndexFontSize) * 1.5)) { // smaller will be in HTML table
// find largest index smaller than current
for (index = indexMax; index >= indexMin; index--) {
indexFontSize = CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (indexFontSize < aFontSize)
break; break;
}
// set up points beyond table for interpolation purposes
if (indexFontSize == smallestIndexFontSize) {
smallerIndexFontSize = indexFontSize - onePx;
largerIndexFontSize = CalcFontPointSize(index+1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
} else if (indexFontSize == largestIndexFontSize) {
smallerIndexFontSize = CalcFontPointSize(index-1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largerIndexFontSize = NSToCoordRound(float(largestIndexFontSize) * 1.5);
} else {
smallerIndexFontSize = CalcFontPointSize(index-1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largerIndexFontSize = CalcFontPointSize(index+1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
}
// compute the relative position of the parent size between the two closest indexed sizes
relativePosition = float(aFontSize - indexFontSize) / float(largerIndexFontSize - indexFontSize);
// set the new size to have the same relative position between the next smallest two indexed sizes
smallerSize = smallerIndexFontSize + NSToCoordRound(relativePosition * (indexFontSize - smallerIndexFontSize));
} }
else { // larger than HTML table else { // larger than HTML table, drop by 33%
return indexMax; smallerSize = NSToCoordRound(float(aFontSize) / 1.5);
// for (index = 8; ; index++)
// if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) {
// index--;
// break;
// }
} }
} }
else { // smaller than HTML table else { // smaller than HTML table, drop by 1px
return indexMin; smallerSize = PR_MAX(aFontSize - onePx, onePx);
// for (index = 0; -25<index ; index--) //prevent infinite loop (bug 17045)
// if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) {
// break;
// }
} }
return index; return smallerSize;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, nscoord nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext, float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType) nsFontSizeType aFontSizeType)
{ {
PRInt32 index; PRInt32 index;
PRInt32 indexMin; PRInt32 indexMin;
PRInt32 indexMax; PRInt32 indexMax;
PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); float relativePosition;
nscoord largerSize;
nscoord indexFontSize;
nscoord smallestIndexFontSize;
nscoord largestIndexFontSize;
nscoord smallerIndexFontSize;
nscoord largerIndexFontSize;
float p2t;
nscoord onePx;
aPresContext->GetPixelsToTwips(&p2t);
onePx = NSToCoordRound(p2t);
if (aFontSizeType == eFontSize_HTML) { if (aFontSizeType == eFontSize_HTML) {
indexMin = 1; indexMin = 1;
indexMax = 7; indexMax = 7;
@ -471,32 +502,45 @@ PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePoin
indexMin = 0; indexMin = 0;
indexMax = 6; indexMax = 6;
} }
if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) <= fontSize) { smallestIndexFontSize = CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
for (index = indexMin; index < indexMax; index++) if (aFontSize > (smallestIndexFontSize - onePx)) {
if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) if (aFontSize < largestIndexFontSize) { // larger will be in HTML table
// find smallest index larger than current
for (index = indexMin; index <= indexMax; index++) {
indexFontSize = CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (indexFontSize > aFontSize)
break; break;
}
// set up points beyond table for interpolation purposes
if (indexFontSize == smallestIndexFontSize) {
smallerIndexFontSize = indexFontSize - onePx;
largerIndexFontSize = CalcFontPointSize(index+1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
} else if (indexFontSize == largestIndexFontSize) {
smallerIndexFontSize = CalcFontPointSize(index-1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largerIndexFontSize = NSToCoordRound(float(largestIndexFontSize) * 1.5);
} else {
smallerIndexFontSize = CalcFontPointSize(index-1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largerIndexFontSize = CalcFontPointSize(index+1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
}
// compute the relative position of the parent size between the two closest indexed sizes
relativePosition = float(aFontSize - smallerIndexFontSize) / float(indexFontSize - smallerIndexFontSize);
// set the new size to have the same relative position between the next largest two indexed sizes
largerSize = indexFontSize + NSToCoordRound(relativePosition * (largerIndexFontSize - indexFontSize));
} }
else { // larger than HTML table else { // larger than HTML table, increase by 50%
return indexMax; largerSize = NSToCoordRound(float(aFontSize) * 1.5);
// for (index = 8; ; index++)
// if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext)))
// break;
} }
} }
else { // smaller than HTML table else { // smaller than HTML table, increase by 1px
return indexMin; float p2t;
// for (index = 0; -25<index ; index--) //prevent infinite loop (bug 17045) aPresContext->GetPixelsToTwips(&p2t);
// if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { largerSize = aFontSize + NSToCoordRound(p2t);
// index++;
// break;
// }
} }
return index; return largerSize;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

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

@ -1982,41 +1982,15 @@ SetFont(nsIPresContext* aPresContext, nsStyleContext* aContext,
nsStyleFont::UnZoomText(aPresContext, aParentFont->mSize); nsStyleFont::UnZoomText(aPresContext, aParentFont->mSize);
if (NS_STYLE_FONT_SIZE_LARGER == value) { if (NS_STYLE_FONT_SIZE_LARGER == value) {
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentSize, (PRInt32)aDefaultFont.size, aFont->mSize = nsStyleUtil::FindNextLargerFontSize(parentSize, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS);
NS_ASSERTION(aFont->mSize > parentSize, "FindNextLargerFontSize failed.");
}
else {
aFont->mSize = nsStyleUtil::FindNextSmallerFontSize(parentSize, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS); scaleFactor, aPresContext, eFontSize_CSS);
nscoord largerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size, NS_ASSERTION(aFont->mSize < parentSize,
scaleFactor, aPresContext, eFontSize_CSS); "FindNextSmallerFontSize failed; this is expected if parentFont size <= 1px");
aFont->mSize = PR_MAX(largerSize, aParentFont->mSize);
if (index == 6 &&
aFont->mSize == aParentFont->mSize) {
// 6 is the maximal answer from nsStyleUtil::FindNextLargerFontSize
// when eFontSize_CSS parameter is passed; we reached the limit for
// CSS named sizes, let's apply a %age.
// 150% is more or less the ratio between xx-large and x-large in
// all tables defined in nsStyleUtil.cpp
aFont->mSize = (nscoord)((float)(aParentFont->mSize) * 1.5);
}
else if (index == 0) {
largerSize = (nscoord)((float)(aParentFont->mSize) / 0.9);
aFont->mSize = PR_MIN(largerSize, aFont->mSize);
}
} else {
PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentSize, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS);
nscoord smallerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS);
aFont->mSize = PR_MIN(smallerSize, aParentFont->mSize);
if (index == 0 &&
aFont->mSize == aParentFont->mSize) {
// 0 is the miminal answer from nsStyleUtil::FindNextLargerFontSize
// when eFontSize_CSS parameter is passed; we reached the limit for
// CSS named sizes, let's apply a %age
aFont->mSize = (nscoord)((float)(aParentFont->mSize) * 0.9);
}
else if (index == 6) {
smallerSize = (nscoord)((float)(aParentFont->mSize) / 1.5);
aFont->mSize = PR_MAX(smallerSize, aFont->mSize);
}
} }
} else { } else {
NS_NOTREACHED("unexpected value"); NS_NOTREACHED("unexpected value");

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

@ -403,20 +403,30 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize
return OldCalcFontPointSize(aHTMLSize, aBasePointSize, aScalingFactor); return OldCalcFontPointSize(aHTMLSize, aBasePointSize, aScalingFactor);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, nscoord nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext, float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType) nsFontSizeType aFontSizeType)
{ {
PRInt32 index; PRInt32 index;
PRInt32 indexMin; PRInt32 indexMin;
PRInt32 indexMax; PRInt32 indexMax;
PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); float relativePosition;
nscoord smallerSize;
nscoord indexFontSize;
nscoord smallestIndexFontSize;
nscoord largestIndexFontSize;
nscoord smallerIndexFontSize;
nscoord largerIndexFontSize;
float p2t;
nscoord onePx;
aPresContext->GetPixelsToTwips(&p2t);
onePx = NSToCoordRound(p2t);
if (aFontSizeType == eFontSize_HTML) { if (aFontSizeType == eFontSize_HTML) {
indexMin = 1; indexMin = 1;
indexMax = 7; indexMax = 7;
@ -424,46 +434,67 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi
indexMin = 0; indexMin = 0;
indexMax = 6; indexMax = 6;
} }
if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) < fontSize) { smallestIndexFontSize = CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (fontSize <= NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
for (index = indexMax; index > indexMin; index--) if (aFontSize > smallestIndexFontSize) {
if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) if (aFontSize < NSToCoordRound(float(largestIndexFontSize) * 1.5)) { // smaller will be in HTML table
// find largest index smaller than current
for (index = indexMax; index >= indexMin; index--) {
indexFontSize = CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (indexFontSize < aFontSize)
break; break;
}
// set up points beyond table for interpolation purposes
if (indexFontSize == smallestIndexFontSize) {
smallerIndexFontSize = indexFontSize - onePx;
largerIndexFontSize = CalcFontPointSize(index+1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
} else if (indexFontSize == largestIndexFontSize) {
smallerIndexFontSize = CalcFontPointSize(index-1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largerIndexFontSize = NSToCoordRound(float(largestIndexFontSize) * 1.5);
} else {
smallerIndexFontSize = CalcFontPointSize(index-1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largerIndexFontSize = CalcFontPointSize(index+1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
}
// compute the relative position of the parent size between the two closest indexed sizes
relativePosition = float(aFontSize - indexFontSize) / float(largerIndexFontSize - indexFontSize);
// set the new size to have the same relative position between the next smallest two indexed sizes
smallerSize = smallerIndexFontSize + NSToCoordRound(relativePosition * (indexFontSize - smallerIndexFontSize));
} }
else { // larger than HTML table else { // larger than HTML table, drop by 33%
return indexMax; smallerSize = NSToCoordRound(float(aFontSize) / 1.5);
// for (index = 8; ; index++)
// if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) {
// index--;
// break;
// }
} }
} }
else { // smaller than HTML table else { // smaller than HTML table, drop by 1px
return indexMin; smallerSize = PR_MAX(aFontSize - onePx, onePx);
// for (index = 0; -25<index ; index--) //prevent infinite loop (bug 17045)
// if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) {
// break;
// }
} }
return index; return smallerSize;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, nscoord nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext, float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType) nsFontSizeType aFontSizeType)
{ {
PRInt32 index; PRInt32 index;
PRInt32 indexMin; PRInt32 indexMin;
PRInt32 indexMax; PRInt32 indexMax;
PRInt32 fontSize = NSTwipsToFloorIntPoints(aFontSize); float relativePosition;
nscoord largerSize;
nscoord indexFontSize;
nscoord smallestIndexFontSize;
nscoord largestIndexFontSize;
nscoord smallerIndexFontSize;
nscoord largerIndexFontSize;
float p2t;
nscoord onePx;
aPresContext->GetPixelsToTwips(&p2t);
onePx = NSToCoordRound(p2t);
if (aFontSizeType == eFontSize_HTML) { if (aFontSizeType == eFontSize_HTML) {
indexMin = 1; indexMin = 1;
indexMax = 7; indexMax = 7;
@ -471,32 +502,45 @@ PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePoin
indexMin = 0; indexMin = 0;
indexMax = 6; indexMax = 6;
} }
if (NSTwipsToFloorIntPoints(CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType)) <= fontSize) { smallestIndexFontSize = CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) { // in HTML table largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
for (index = indexMin; index < indexMax; index++) if (aFontSize > (smallestIndexFontSize - onePx)) {
if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType))) if (aFontSize < largestIndexFontSize) { // larger will be in HTML table
// find smallest index larger than current
for (index = indexMin; index <= indexMax; index++) {
indexFontSize = CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (indexFontSize > aFontSize)
break; break;
}
// set up points beyond table for interpolation purposes
if (indexFontSize == smallestIndexFontSize) {
smallerIndexFontSize = indexFontSize - onePx;
largerIndexFontSize = CalcFontPointSize(index+1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
} else if (indexFontSize == largestIndexFontSize) {
smallerIndexFontSize = CalcFontPointSize(index-1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largerIndexFontSize = NSToCoordRound(float(largestIndexFontSize) * 1.5);
} else {
smallerIndexFontSize = CalcFontPointSize(index-1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largerIndexFontSize = CalcFontPointSize(index+1, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
}
// compute the relative position of the parent size between the two closest indexed sizes
relativePosition = float(aFontSize - smallerIndexFontSize) / float(indexFontSize - smallerIndexFontSize);
// set the new size to have the same relative position between the next largest two indexed sizes
largerSize = indexFontSize + NSToCoordRound(relativePosition * (largerIndexFontSize - indexFontSize));
} }
else { // larger than HTML table else { // larger than HTML table, increase by 50%
return indexMax; largerSize = NSToCoordRound(float(aFontSize) * 1.5);
// for (index = 8; ; index++)
// if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext)))
// break;
} }
} }
else { // smaller than HTML table else { // smaller than HTML table, increase by 1px
return indexMin; float p2t;
// for (index = 0; -25<index ; index--) //prevent infinite loop (bug 17045) aPresContext->GetPixelsToTwips(&p2t);
// if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) { largerSize = aFontSize + NSToCoordRound(p2t);
// index++;
// break;
// }
} }
return index; return largerSize;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

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

@ -60,11 +60,11 @@ public:
float aScalingFactor, nsIPresContext* aPresContext, float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType = eFontSize_HTML); nsFontSizeType aFontSizeType = eFontSize_HTML);
static PRInt32 FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, static nscoord FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext, float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType = eFontSize_HTML); nsFontSizeType aFontSizeType = eFontSize_HTML);
static PRInt32 FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize, static nscoord FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext, float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType = eFontSize_HTML); nsFontSizeType aFontSizeType = eFontSize_HTML);