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);
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);
nscoord largerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size,
NS_ASSERTION(aFont->mSize > parentSize, "FindNextLargerFontSize failed.");
}
else {
aFont->mSize = nsStyleUtil::FindNextSmallerFontSize(parentSize, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS);
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);
}
NS_ASSERTION(aFont->mSize < parentSize,
"FindNextSmallerFontSize failed; this is expected if parentFont size <= 1px");
}
} else {
NS_NOTREACHED("unexpected value");

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

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

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

@ -403,19 +403,29 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize
return OldCalcFontPointSize(aHTMLSize, aBasePointSize, aScalingFactor);
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
nscoord nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType)
{
PRInt32 index;
PRInt32 indexMin;
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) {
indexMin = 1;
@ -425,44 +435,65 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi
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)))
smallestIndexFontSize = CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (aFontSize > smallestIndexFontSize) {
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;
}
else { // larger than HTML table
return indexMax;
// for (index = 8; ; index++)
// if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) {
// index--;
// 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, drop by 33%
smallerSize = NSToCoordRound(float(aFontSize) / 1.5);
}
}
else { // smaller than HTML table
return indexMin;
// for (index = 0; -25<index ; index--) //prevent infinite loop (bug 17045)
// if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) {
// break;
// }
else { // smaller than HTML table, drop by 1px
smallerSize = PR_MAX(aFontSize - onePx, onePx);
}
return index;
return smallerSize;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
nscoord nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType)
{
PRInt32 index;
PRInt32 indexMin;
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) {
indexMin = 1;
@ -472,31 +503,44 @@ PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePoin
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)))
smallestIndexFontSize = CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (aFontSize > (smallestIndexFontSize - onePx)) {
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;
}
else { // larger than HTML table
return indexMax;
// for (index = 8; ; index++)
// if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext)))
// 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, increase by 50%
largerSize = NSToCoordRound(float(aFontSize) * 1.5);
}
}
else { // smaller than HTML table
return indexMin;
// for (index = 0; -25<index ; index--) //prevent infinite loop (bug 17045)
// if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) {
// index++;
// break;
// }
else { // smaller than HTML table, increase by 1px
float p2t;
aPresContext->GetPixelsToTwips(&p2t);
largerSize = aFontSize + NSToCoordRound(p2t);
}
return index;
return largerSize;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------

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

@ -1982,41 +1982,15 @@ SetFont(nsIPresContext* aPresContext, nsStyleContext* aContext,
nsStyleFont::UnZoomText(aPresContext, aParentFont->mSize);
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);
nscoord largerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size,
NS_ASSERTION(aFont->mSize > parentSize, "FindNextLargerFontSize failed.");
}
else {
aFont->mSize = nsStyleUtil::FindNextSmallerFontSize(parentSize, (PRInt32)aDefaultFont.size,
scaleFactor, aPresContext, eFontSize_CSS);
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);
}
NS_ASSERTION(aFont->mSize < parentSize,
"FindNextSmallerFontSize failed; this is expected if parentFont size <= 1px");
}
} else {
NS_NOTREACHED("unexpected value");

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

@ -403,19 +403,29 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize
return OldCalcFontPointSize(aHTMLSize, aBasePointSize, aScalingFactor);
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
nscoord nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType)
{
PRInt32 index;
PRInt32 indexMin;
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) {
indexMin = 1;
@ -425,44 +435,65 @@ PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePoi
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)))
smallestIndexFontSize = CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (aFontSize > smallestIndexFontSize) {
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;
}
else { // larger than HTML table
return indexMax;
// for (index = 8; ; index++)
// if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) {
// index--;
// 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, drop by 33%
smallerSize = NSToCoordRound(float(aFontSize) / 1.5);
}
}
else { // smaller than HTML table
return indexMin;
// for (index = 0; -25<index ; index--) //prevent infinite loop (bug 17045)
// if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) {
// break;
// }
else { // smaller than HTML table, drop by 1px
smallerSize = PR_MAX(aFontSize - onePx, onePx);
}
return index;
return smallerSize;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
nscoord nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
float aScalingFactor, nsIPresContext* aPresContext,
nsFontSizeType aFontSizeType)
{
PRInt32 index;
PRInt32 indexMin;
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) {
indexMin = 1;
@ -472,31 +503,44 @@ PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePoin
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)))
smallestIndexFontSize = CalcFontPointSize(indexMin, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aScalingFactor, aPresContext, aFontSizeType);
if (aFontSize > (smallestIndexFontSize - onePx)) {
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;
}
else { // larger than HTML table
return indexMax;
// for (index = 8; ; index++)
// if (fontSize < NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext)))
// 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, increase by 50%
largerSize = NSToCoordRound(float(aFontSize) * 1.5);
}
}
else { // smaller than HTML table
return indexMin;
// for (index = 0; -25<index ; index--) //prevent infinite loop (bug 17045)
// if (fontSize > NSTwipsToFloorIntPoints(CalcFontPointSize(index, aBasePointSize, aScalingFactor, aPresContext))) {
// index++;
// break;
// }
else { // smaller than HTML table, increase by 1px
float p2t;
aPresContext->GetPixelsToTwips(&p2t);
largerSize = aFontSize + NSToCoordRound(p2t);
}
return index;
return largerSize;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------

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

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