зеркало из https://github.com/mozilla/gecko-dev.git
added font scaling support
This commit is contained in:
Родитель
62cb905c58
Коммит
ab09d83870
|
@ -589,20 +589,23 @@ void CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* a
|
||||||
|
|
||||||
const nsFont& normal = aPresContext->GetDefaultFont();
|
const nsFont& normal = aPresContext->GetDefaultFont();
|
||||||
const nsFont& normalFixed = aPresContext->GetDefaultFixedFont();
|
const nsFont& normalFixed = aPresContext->GetDefaultFixedFont();
|
||||||
|
PRInt32 scaler = aPresContext->GetFontScaler();
|
||||||
|
float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);
|
||||||
|
|
||||||
if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&
|
if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&
|
||||||
(value <= NS_STYLE_FONT_SIZE_XXLARGE)) {
|
(value <= NS_STYLE_FONT_SIZE_XXLARGE)) {
|
||||||
font->mFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normal.size);
|
font->mFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normalFixed.size);
|
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normalFixed.size, scaleFactor);
|
||||||
}
|
}
|
||||||
else if (NS_STYLE_FONT_SIZE_LARGER == value) {
|
else if (NS_STYLE_FONT_SIZE_LARGER == value) {
|
||||||
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)normal.size);
|
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size);
|
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size);
|
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size, scaleFactor);
|
||||||
}
|
}
|
||||||
else if (NS_STYLE_FONT_SIZE_SMALLER == value) {
|
else if (NS_STYLE_FONT_SIZE_SMALLER == value) {
|
||||||
PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)normal.size);
|
PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size);
|
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size);
|
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size, scaleFactor);
|
||||||
}
|
}
|
||||||
// this does NOT explicitly set font size
|
// this does NOT explicitly set font size
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,41 @@
|
||||||
#include "nsIStyleContext.h"
|
#include "nsIStyleContext.h"
|
||||||
#include "nsStyleConsts.h"
|
#include "nsStyleConsts.h"
|
||||||
|
|
||||||
nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize)
|
#define POSITIVE_SCALE_FACTOR 1.10 /* 10% */
|
||||||
|
#define NEGATIVE_SCALE_FACTOR .90 /* 10% */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the scaling percentage given a font scaler
|
||||||
|
* Lifted from layutil.c
|
||||||
|
*/
|
||||||
|
float nsStyleUtil::GetScalingFactor(PRInt32 aScaler)
|
||||||
|
{
|
||||||
|
double scale = 1.0;
|
||||||
|
double mult;
|
||||||
|
PRInt32 count;
|
||||||
|
|
||||||
|
if(aScaler < 0) {
|
||||||
|
count = -aScaler;
|
||||||
|
mult = NEGATIVE_SCALE_FACTOR;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
count = aScaler;
|
||||||
|
mult = POSITIVE_SCALE_FACTOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* use the percentage scaling factor to the power of the pref */
|
||||||
|
while(count--) {
|
||||||
|
scale *= mult;
|
||||||
|
}
|
||||||
|
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lifted from winfe/cxdc.cpp
|
||||||
|
*/
|
||||||
|
nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{ // lifted directly from Nav 5.0 code to replicate rounding errors
|
{ // lifted directly from Nav 5.0 code to replicate rounding errors
|
||||||
double dFontSize;
|
double dFontSize;
|
||||||
|
|
||||||
|
@ -54,23 +88,28 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize
|
||||||
default:
|
default:
|
||||||
dFontSize = aBasePointSize;
|
dFontSize = aBasePointSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dFontSize *= aScalingFactor;
|
||||||
|
|
||||||
return (nscoord)dFontSize;
|
return (nscoord)dFontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize)
|
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{
|
{
|
||||||
PRInt32 index;
|
PRInt32 index;
|
||||||
for (index = 7; index > 1; index--)
|
for (index = 7; index > 1; index--)
|
||||||
if (aFontSize > nsStyleUtil::CalcFontPointSize(index, aBasePointSize))
|
if (aFontSize > nsStyleUtil::CalcFontPointSize(index, aBasePointSize, aScalingFactor))
|
||||||
break;
|
break;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize)
|
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{
|
{
|
||||||
PRInt32 index;
|
PRInt32 index;
|
||||||
for (index = 1; index < 7; index++)
|
for (index = 1; index < 7; index++)
|
||||||
if (aFontSize < nsStyleUtil::CalcFontPointSize(index, aBasePointSize))
|
if (aFontSize < nsStyleUtil::CalcFontPointSize(index, aBasePointSize, aScalingFactor))
|
||||||
break;
|
break;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,41 @@
|
||||||
#include "nsIStyleContext.h"
|
#include "nsIStyleContext.h"
|
||||||
#include "nsStyleConsts.h"
|
#include "nsStyleConsts.h"
|
||||||
|
|
||||||
nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize)
|
#define POSITIVE_SCALE_FACTOR 1.10 /* 10% */
|
||||||
|
#define NEGATIVE_SCALE_FACTOR .90 /* 10% */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the scaling percentage given a font scaler
|
||||||
|
* Lifted from layutil.c
|
||||||
|
*/
|
||||||
|
float nsStyleUtil::GetScalingFactor(PRInt32 aScaler)
|
||||||
|
{
|
||||||
|
double scale = 1.0;
|
||||||
|
double mult;
|
||||||
|
PRInt32 count;
|
||||||
|
|
||||||
|
if(aScaler < 0) {
|
||||||
|
count = -aScaler;
|
||||||
|
mult = NEGATIVE_SCALE_FACTOR;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
count = aScaler;
|
||||||
|
mult = POSITIVE_SCALE_FACTOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* use the percentage scaling factor to the power of the pref */
|
||||||
|
while(count--) {
|
||||||
|
scale *= mult;
|
||||||
|
}
|
||||||
|
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lifted from winfe/cxdc.cpp
|
||||||
|
*/
|
||||||
|
nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{ // lifted directly from Nav 5.0 code to replicate rounding errors
|
{ // lifted directly from Nav 5.0 code to replicate rounding errors
|
||||||
double dFontSize;
|
double dFontSize;
|
||||||
|
|
||||||
|
@ -54,23 +88,28 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize
|
||||||
default:
|
default:
|
||||||
dFontSize = aBasePointSize;
|
dFontSize = aBasePointSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dFontSize *= aScalingFactor;
|
||||||
|
|
||||||
return (nscoord)dFontSize;
|
return (nscoord)dFontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize)
|
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{
|
{
|
||||||
PRInt32 index;
|
PRInt32 index;
|
||||||
for (index = 7; index > 1; index--)
|
for (index = 7; index > 1; index--)
|
||||||
if (aFontSize > nsStyleUtil::CalcFontPointSize(index, aBasePointSize))
|
if (aFontSize > nsStyleUtil::CalcFontPointSize(index, aBasePointSize, aScalingFactor))
|
||||||
break;
|
break;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize)
|
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{
|
{
|
||||||
PRInt32 index;
|
PRInt32 index;
|
||||||
for (index = 1; index < 7; index++)
|
for (index = 1; index < 7; index++)
|
||||||
if (aFontSize < nsStyleUtil::CalcFontPointSize(index, aBasePointSize))
|
if (aFontSize < nsStyleUtil::CalcFontPointSize(index, aBasePointSize, aScalingFactor))
|
||||||
break;
|
break;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -569,8 +569,10 @@ nsInputButtonFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aVie
|
||||||
widgetFont.name = "Arail"; // XXX windows specific font
|
widgetFont.name = "Arail"; // XXX windows specific font
|
||||||
widgetFont.weight = NS_FONT_WEIGHT_NORMAL;
|
widgetFont.weight = NS_FONT_WEIGHT_NORMAL;
|
||||||
const nsFont& normal = aPresContext->GetDefaultFont();
|
const nsFont& normal = aPresContext->GetDefaultFont();
|
||||||
PRInt32 fontIndex = nsStyleUtil::FindNextSmallerFontSize(widgetFont.size, (PRInt32)normal.size);
|
PRInt32 scaler = aPresContext->GetFontScaler();
|
||||||
widgetFont.size = nsStyleUtil::CalcFontPointSize(fontIndex, (PRInt32)normal.size);
|
float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);
|
||||||
|
PRInt32 fontIndex = nsStyleUtil::FindNextSmallerFontSize(widgetFont.size, (PRInt32)normal.size, scaleFactor);
|
||||||
|
widgetFont.size = nsStyleUtil::CalcFontPointSize(fontIndex, (PRInt32)normal.size, scaleFactor);
|
||||||
button->SetFont(widgetFont);
|
button->SetFont(widgetFont);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,8 +337,10 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
|
||||||
widgetFont.name = "Arail"; // XXX windows specific font
|
widgetFont.name = "Arail"; // XXX windows specific font
|
||||||
widgetFont.weight = NS_FONT_WEIGHT_NORMAL;
|
widgetFont.weight = NS_FONT_WEIGHT_NORMAL;
|
||||||
const nsFont& normal = aPresContext->GetDefaultFont();
|
const nsFont& normal = aPresContext->GetDefaultFont();
|
||||||
PRInt32 fontIndex = nsStyleUtil::FindNextSmallerFontSize(widgetFont.size, (PRInt32)normal.size);
|
PRInt32 scaler = aPresContext->GetFontScaler();
|
||||||
widgetFont.size = nsStyleUtil::CalcFontPointSize(fontIndex, (PRInt32)normal.size);
|
float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);
|
||||||
|
PRInt32 fontIndex = nsStyleUtil::FindNextSmallerFontSize(widgetFont.size, (PRInt32)normal.size, scaleFactor);
|
||||||
|
widgetFont.size = nsStyleUtil::CalcFontPointSize(fontIndex, (PRInt32)normal.size, scaleFactor);
|
||||||
list->SetFont(widgetFont);
|
list->SetFont(widgetFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,15 @@ struct nsStyleColor;
|
||||||
// Style utility functions
|
// Style utility functions
|
||||||
class nsStyleUtil {
|
class nsStyleUtil {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static float GetScalingFactor(PRInt32 aScaler);
|
||||||
|
|
||||||
static nscoord CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize);
|
static nscoord CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize,
|
||||||
static PRInt32 FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize);
|
float aScalingFactor);
|
||||||
static PRInt32 FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize);
|
static PRInt32 FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor);
|
||||||
|
static PRInt32 FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor);
|
||||||
|
|
||||||
static const nsStyleColor* FindNonTransparentBackground(nsIStyleContext* aContext);
|
static const nsStyleColor* FindNonTransparentBackground(nsIStyleContext* aContext);
|
||||||
};
|
};
|
||||||
|
|
|
@ -589,20 +589,23 @@ void CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* a
|
||||||
|
|
||||||
const nsFont& normal = aPresContext->GetDefaultFont();
|
const nsFont& normal = aPresContext->GetDefaultFont();
|
||||||
const nsFont& normalFixed = aPresContext->GetDefaultFixedFont();
|
const nsFont& normalFixed = aPresContext->GetDefaultFixedFont();
|
||||||
|
PRInt32 scaler = aPresContext->GetFontScaler();
|
||||||
|
float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);
|
||||||
|
|
||||||
if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&
|
if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&
|
||||||
(value <= NS_STYLE_FONT_SIZE_XXLARGE)) {
|
(value <= NS_STYLE_FONT_SIZE_XXLARGE)) {
|
||||||
font->mFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normal.size);
|
font->mFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normalFixed.size);
|
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normalFixed.size, scaleFactor);
|
||||||
}
|
}
|
||||||
else if (NS_STYLE_FONT_SIZE_LARGER == value) {
|
else if (NS_STYLE_FONT_SIZE_LARGER == value) {
|
||||||
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)normal.size);
|
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size);
|
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size);
|
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size, scaleFactor);
|
||||||
}
|
}
|
||||||
else if (NS_STYLE_FONT_SIZE_SMALLER == value) {
|
else if (NS_STYLE_FONT_SIZE_SMALLER == value) {
|
||||||
PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)normal.size);
|
PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size);
|
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size);
|
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size, scaleFactor);
|
||||||
}
|
}
|
||||||
// this does NOT explicitly set font size
|
// this does NOT explicitly set font size
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,41 @@
|
||||||
#include "nsIStyleContext.h"
|
#include "nsIStyleContext.h"
|
||||||
#include "nsStyleConsts.h"
|
#include "nsStyleConsts.h"
|
||||||
|
|
||||||
nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize)
|
#define POSITIVE_SCALE_FACTOR 1.10 /* 10% */
|
||||||
|
#define NEGATIVE_SCALE_FACTOR .90 /* 10% */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the scaling percentage given a font scaler
|
||||||
|
* Lifted from layutil.c
|
||||||
|
*/
|
||||||
|
float nsStyleUtil::GetScalingFactor(PRInt32 aScaler)
|
||||||
|
{
|
||||||
|
double scale = 1.0;
|
||||||
|
double mult;
|
||||||
|
PRInt32 count;
|
||||||
|
|
||||||
|
if(aScaler < 0) {
|
||||||
|
count = -aScaler;
|
||||||
|
mult = NEGATIVE_SCALE_FACTOR;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
count = aScaler;
|
||||||
|
mult = POSITIVE_SCALE_FACTOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* use the percentage scaling factor to the power of the pref */
|
||||||
|
while(count--) {
|
||||||
|
scale *= mult;
|
||||||
|
}
|
||||||
|
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lifted from winfe/cxdc.cpp
|
||||||
|
*/
|
||||||
|
nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{ // lifted directly from Nav 5.0 code to replicate rounding errors
|
{ // lifted directly from Nav 5.0 code to replicate rounding errors
|
||||||
double dFontSize;
|
double dFontSize;
|
||||||
|
|
||||||
|
@ -54,23 +88,28 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize
|
||||||
default:
|
default:
|
||||||
dFontSize = aBasePointSize;
|
dFontSize = aBasePointSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dFontSize *= aScalingFactor;
|
||||||
|
|
||||||
return (nscoord)dFontSize;
|
return (nscoord)dFontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize)
|
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{
|
{
|
||||||
PRInt32 index;
|
PRInt32 index;
|
||||||
for (index = 7; index > 1; index--)
|
for (index = 7; index > 1; index--)
|
||||||
if (aFontSize > nsStyleUtil::CalcFontPointSize(index, aBasePointSize))
|
if (aFontSize > nsStyleUtil::CalcFontPointSize(index, aBasePointSize, aScalingFactor))
|
||||||
break;
|
break;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize)
|
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{
|
{
|
||||||
PRInt32 index;
|
PRInt32 index;
|
||||||
for (index = 1; index < 7; index++)
|
for (index = 1; index < 7; index++)
|
||||||
if (aFontSize < nsStyleUtil::CalcFontPointSize(index, aBasePointSize))
|
if (aFontSize < nsStyleUtil::CalcFontPointSize(index, aBasePointSize, aScalingFactor))
|
||||||
break;
|
break;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
|
@ -589,20 +589,23 @@ void CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* a
|
||||||
|
|
||||||
const nsFont& normal = aPresContext->GetDefaultFont();
|
const nsFont& normal = aPresContext->GetDefaultFont();
|
||||||
const nsFont& normalFixed = aPresContext->GetDefaultFixedFont();
|
const nsFont& normalFixed = aPresContext->GetDefaultFixedFont();
|
||||||
|
PRInt32 scaler = aPresContext->GetFontScaler();
|
||||||
|
float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);
|
||||||
|
|
||||||
if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&
|
if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&
|
||||||
(value <= NS_STYLE_FONT_SIZE_XXLARGE)) {
|
(value <= NS_STYLE_FONT_SIZE_XXLARGE)) {
|
||||||
font->mFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normal.size);
|
font->mFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normalFixed.size);
|
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(value + 1, (PRInt32)normalFixed.size, scaleFactor);
|
||||||
}
|
}
|
||||||
else if (NS_STYLE_FONT_SIZE_LARGER == value) {
|
else if (NS_STYLE_FONT_SIZE_LARGER == value) {
|
||||||
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)normal.size);
|
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentFont->mFont.size, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size);
|
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size);
|
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size, scaleFactor);
|
||||||
}
|
}
|
||||||
else if (NS_STYLE_FONT_SIZE_SMALLER == value) {
|
else if (NS_STYLE_FONT_SIZE_SMALLER == value) {
|
||||||
PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)normal.size);
|
PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(parentFont->mFont.size, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size);
|
font->mFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normal.size, scaleFactor);
|
||||||
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size);
|
font->mFixedFont.size = nsStyleUtil::CalcFontPointSize(index, (PRInt32)normalFixed.size, scaleFactor);
|
||||||
}
|
}
|
||||||
// this does NOT explicitly set font size
|
// this does NOT explicitly set font size
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,41 @@
|
||||||
#include "nsIStyleContext.h"
|
#include "nsIStyleContext.h"
|
||||||
#include "nsStyleConsts.h"
|
#include "nsStyleConsts.h"
|
||||||
|
|
||||||
nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize)
|
#define POSITIVE_SCALE_FACTOR 1.10 /* 10% */
|
||||||
|
#define NEGATIVE_SCALE_FACTOR .90 /* 10% */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the scaling percentage given a font scaler
|
||||||
|
* Lifted from layutil.c
|
||||||
|
*/
|
||||||
|
float nsStyleUtil::GetScalingFactor(PRInt32 aScaler)
|
||||||
|
{
|
||||||
|
double scale = 1.0;
|
||||||
|
double mult;
|
||||||
|
PRInt32 count;
|
||||||
|
|
||||||
|
if(aScaler < 0) {
|
||||||
|
count = -aScaler;
|
||||||
|
mult = NEGATIVE_SCALE_FACTOR;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
count = aScaler;
|
||||||
|
mult = POSITIVE_SCALE_FACTOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* use the percentage scaling factor to the power of the pref */
|
||||||
|
while(count--) {
|
||||||
|
scale *= mult;
|
||||||
|
}
|
||||||
|
|
||||||
|
return scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Lifted from winfe/cxdc.cpp
|
||||||
|
*/
|
||||||
|
nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{ // lifted directly from Nav 5.0 code to replicate rounding errors
|
{ // lifted directly from Nav 5.0 code to replicate rounding errors
|
||||||
double dFontSize;
|
double dFontSize;
|
||||||
|
|
||||||
|
@ -54,23 +88,28 @@ nscoord nsStyleUtil::CalcFontPointSize(PRInt32 aHTMLSize, PRInt32 aBasePointSize
|
||||||
default:
|
default:
|
||||||
dFontSize = aBasePointSize;
|
dFontSize = aBasePointSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dFontSize *= aScalingFactor;
|
||||||
|
|
||||||
return (nscoord)dFontSize;
|
return (nscoord)dFontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize)
|
PRInt32 nsStyleUtil::FindNextSmallerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{
|
{
|
||||||
PRInt32 index;
|
PRInt32 index;
|
||||||
for (index = 7; index > 1; index--)
|
for (index = 7; index > 1; index--)
|
||||||
if (aFontSize > nsStyleUtil::CalcFontPointSize(index, aBasePointSize))
|
if (aFontSize > nsStyleUtil::CalcFontPointSize(index, aBasePointSize, aScalingFactor))
|
||||||
break;
|
break;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize)
|
PRInt32 nsStyleUtil::FindNextLargerFontSize(nscoord aFontSize, PRInt32 aBasePointSize,
|
||||||
|
float aScalingFactor)
|
||||||
{
|
{
|
||||||
PRInt32 index;
|
PRInt32 index;
|
||||||
for (index = 1; index < 7; index++)
|
for (index = 1; index < 7; index++)
|
||||||
if (aFontSize < nsStyleUtil::CalcFontPointSize(index, aBasePointSize))
|
if (aFontSize < nsStyleUtil::CalcFontPointSize(index, aBasePointSize, aScalingFactor))
|
||||||
break;
|
break;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче