зеркало из https://github.com/mozilla/pjs.git
Change the implementation of text zoom so that the zooming happens in the style system. This causes 'em' and similar units to be zoomed as well. Also scale physical / pixel 'line-height' values. b=41847 r=attinasi sr=hyatt
This commit is contained in:
Родитель
d376f6e5e2
Коммит
f3b0f6c470
|
@ -1583,6 +1583,16 @@ nsRuleNode::WalkRuleTree(const nsStyleStructID aSID,
|
|||
return res;
|
||||
}
|
||||
|
||||
static nscoord
|
||||
ZoomFont(nsIPresContext* aPresContext, nscoord aInSize)
|
||||
{
|
||||
nsCOMPtr<nsIDeviceContext> dc;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
||||
float textZoom;
|
||||
dc->GetTextZoom(textZoom);
|
||||
return nscoord(aInSize * textZoom);
|
||||
}
|
||||
|
||||
const nsStyleStruct*
|
||||
nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsIStyleContext* aContext)
|
||||
{
|
||||
|
@ -1592,6 +1602,8 @@ nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsIStyleContext* aConte
|
|||
const nsFont* defaultFont;
|
||||
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultFont);
|
||||
nsStyleFont* fontData = new (mPresContext) nsStyleFont(*defaultFont);
|
||||
fontData->mSize = fontData->mFont.size =
|
||||
ZoomFont(mPresContext, fontData->mFont.size);
|
||||
aContext->SetStyle(eStyleStruct_Font, *fontData);
|
||||
return fontData;
|
||||
}
|
||||
|
@ -1766,7 +1778,7 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
|||
nscoord aMinFontSize, PRBool aUseDocumentFonts, PRBool aChromeOverride,
|
||||
PRBool aIsGeneric, const nsCSSFont& aFontData,
|
||||
const nsFont& aDefaultFont, const nsStyleFont* aParentFont,
|
||||
nsStyleFont* aFont, PRBool& aInherited)
|
||||
nsStyleFont* aFont, PRBool aZoom, PRBool& aInherited)
|
||||
{
|
||||
const nsFont* defaultVariableFont;
|
||||
const nsFont* defaultFixedFont;
|
||||
|
@ -1994,13 +2006,14 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
|||
}
|
||||
|
||||
// font-size: enum, length, percent, inherit
|
||||
PRBool zoom = aZoom;
|
||||
if (eCSSUnit_Enumerated == aFontData.mSize.GetUnit()) {
|
||||
PRInt32 value = aFontData.mSize.GetIntValue();
|
||||
PRInt32 scaler;
|
||||
aPresContext->GetFontScaler(&scaler);
|
||||
float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);
|
||||
|
||||
aInherited = PR_TRUE;
|
||||
zoom = PR_TRUE;
|
||||
if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&
|
||||
(value <= NS_STYLE_FONT_SIZE_XXLARGE)) {
|
||||
aFont->mSize = nsStyleUtil::CalcFontPointSize(value, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);
|
||||
|
@ -2009,31 +2022,58 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
|||
// <font size="7"> is not specified in CSS, so we don't use eFontSize_CSS.
|
||||
aFont->mSize = nsStyleUtil::CalcFontPointSize(value, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext);
|
||||
}
|
||||
else if (NS_STYLE_FONT_SIZE_LARGER == value) {
|
||||
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(aParentFont->mSize, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);
|
||||
nscoord largerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);
|
||||
aFont->mSize = PR_MAX(largerSize, aParentFont->mSize);
|
||||
}
|
||||
else if (NS_STYLE_FONT_SIZE_SMALLER == value) {
|
||||
PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(aParentFont->mSize, (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);
|
||||
else if (NS_STYLE_FONT_SIZE_LARGER == value ||
|
||||
NS_STYLE_FONT_SIZE_SMALLER == value) {
|
||||
|
||||
aInherited = PR_TRUE;
|
||||
|
||||
// Un-zoom so we use the tables correctly. We'll then rezoom due
|
||||
// to the |zoom = PR_TRUE| above.
|
||||
nsCOMPtr<nsIDeviceContext> dc;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
||||
float textZoom;
|
||||
dc->GetTextZoom(textZoom);
|
||||
|
||||
nscoord parentSize = nscoord(aParentFont->mSize / textZoom);
|
||||
|
||||
if (NS_STYLE_FONT_SIZE_LARGER == value) {
|
||||
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentSize, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);
|
||||
nscoord largerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);
|
||||
aFont->mSize = PR_MAX(largerSize, aParentFont->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);
|
||||
}
|
||||
} else {
|
||||
NS_NOTREACHED("unexpected value");
|
||||
}
|
||||
}
|
||||
else if (aFontData.mSize.IsLengthUnit()) {
|
||||
aFont->mSize = CalcLength(aFontData.mSize, &aParentFont->mFont, nsnull, aPresContext, aInherited);
|
||||
zoom = aFontData.mSize.IsFixedLengthUnit() ||
|
||||
aFontData.mSize.GetUnit() == eCSSUnit_Pixel;
|
||||
}
|
||||
else if (eCSSUnit_Percent == aFontData.mSize.GetUnit()) {
|
||||
aInherited = PR_TRUE;
|
||||
aFont->mSize = (nscoord)((float)(aParentFont->mSize) * aFontData.mSize.GetPercentValue());
|
||||
zoom = PR_FALSE;
|
||||
}
|
||||
else if (eCSSUnit_Inherit == aFontData.mSize.GetUnit()) {
|
||||
aInherited = PR_TRUE;
|
||||
aFont->mSize = aParentFont->mSize;
|
||||
zoom = PR_FALSE;
|
||||
}
|
||||
else if (eCSSUnit_Initial == aFontData.mSize.GetUnit()) {
|
||||
aFont->mSize = aDefaultFont.size;
|
||||
zoom = PR_TRUE;
|
||||
}
|
||||
|
||||
// We want to zoom the cascaded size so that em-based measurements,
|
||||
// line-heights, etc., work.
|
||||
if (zoom)
|
||||
aFont->mSize = ZoomFont(aPresContext, aFont->mSize);
|
||||
|
||||
// enforce the user' specified minimum font-size on the value that we expose
|
||||
if (aChromeOverride) {
|
||||
// the chrome is unconstrained, it always uses our cascading size
|
||||
|
@ -2067,7 +2107,7 @@ static void
|
|||
SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
||||
const nsCSSFont& aFontData, PRUint8 aGenericFontID,
|
||||
nscoord aMinFontSize, PRBool aUseDocumentFonts,
|
||||
PRBool aChromeOverride, nsStyleFont* aFont)
|
||||
PRBool aChromeOverride, nsStyleFont* aFont, PRBool aZoom)
|
||||
{
|
||||
// walk up the contexts until a context with the desired generic font
|
||||
nsAutoVoidArray contextPath;
|
||||
|
@ -2135,7 +2175,7 @@ SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
|||
|
||||
SetFont(aPresContext, context, aMinFontSize,
|
||||
aUseDocumentFonts, aChromeOverride, PR_TRUE,
|
||||
fontData, *defaultFont, &parentFont, aFont, dummy);
|
||||
fontData, *defaultFont, &parentFont, aFont, aZoom, dummy);
|
||||
|
||||
// XXX Not sure if we need to do this here
|
||||
// If we have a post-resolve callback, handle that now.
|
||||
|
@ -2152,7 +2192,7 @@ SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
|||
// can just compute the delta from the parent.
|
||||
SetFont(aPresContext, aContext, aMinFontSize,
|
||||
aUseDocumentFonts, aChromeOverride, PR_TRUE,
|
||||
aFontData, *defaultFont, &parentFont, aFont, dummy);
|
||||
aFontData, *defaultFont, &parentFont, aFont, aZoom, dummy);
|
||||
}
|
||||
|
||||
const nsStyleStruct*
|
||||
|
@ -2185,10 +2225,12 @@ nsRuleNode::ComputeFontData(nsStyleStruct* aStartStruct, const nsCSSStruct& aDat
|
|||
}
|
||||
}
|
||||
|
||||
PRBool zoom = PR_FALSE;
|
||||
const nsFont* defaultFont;
|
||||
if (!font) {
|
||||
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultFont);
|
||||
font = new (mPresContext) nsStyleFont(*defaultFont);
|
||||
zoom = PR_TRUE;
|
||||
}
|
||||
if (!parentFont)
|
||||
parentFont = font;
|
||||
|
@ -2257,14 +2299,14 @@ nsRuleNode::ComputeFontData(nsStyleStruct* aStartStruct, const nsCSSStruct& aDat
|
|||
mPresContext->GetDefaultFont(generic, &defaultFont);
|
||||
SetFont(mPresContext, aContext, minimumFontSize,
|
||||
useDocumentFonts, chromeOverride, PR_FALSE,
|
||||
fontData, *defaultFont, parentFont, font, inherited);
|
||||
fontData, *defaultFont, parentFont, font, zoom, inherited);
|
||||
}
|
||||
else {
|
||||
// re-calculate the font as a generic font
|
||||
inherited = PR_TRUE;
|
||||
SetGenericFont(mPresContext, aContext, fontData,
|
||||
generic, minimumFontSize, useDocumentFonts,
|
||||
chromeOverride, font);
|
||||
chromeOverride, font, zoom);
|
||||
}
|
||||
// Set our generic font's bit to inform our descendants
|
||||
font->mFlags &= ~NS_STYLE_FONT_FACE_MASK;
|
||||
|
@ -2332,10 +2374,15 @@ nsRuleNode::ComputeTextData(nsStyleStruct* aStartStruct, const nsCSSStruct& aDat
|
|||
aContext->GetStyleData(eStyleStruct_Font));
|
||||
text->mLineHeight.SetCoordValue((nscoord)((float)(font->mSize) *
|
||||
textData.mLineHeight.GetPercentValue()));
|
||||
} else
|
||||
} else {
|
||||
SetCoord(textData.mLineHeight, text->mLineHeight, parentText->mLineHeight,
|
||||
SETCOORD_LH | SETCOORD_FACTOR | SETCOORD_NORMAL,
|
||||
aContext, mPresContext, inherited);
|
||||
if (textData.mLineHeight.IsFixedLengthUnit() ||
|
||||
textData.mLineHeight.GetUnit() == eCSSUnit_Pixel)
|
||||
text->mLineHeight.SetCoordValue(
|
||||
ZoomFont(mPresContext, text->mLineHeight.GetCoordValue()));
|
||||
}
|
||||
|
||||
|
||||
// text-align: enum, string, inherit
|
||||
|
|
|
@ -221,16 +221,16 @@ nsStyleFont::nsStyleFont()
|
|||
|
||||
nsStyleFont::nsStyleFont(const nsFont& aFont)
|
||||
: mFlags(NS_STYLE_FONT_DEFAULT),
|
||||
mFont(aFont)
|
||||
mFont(aFont),
|
||||
mSize(aFont.size)
|
||||
{
|
||||
mSize = aFont.size;
|
||||
}
|
||||
|
||||
nsStyleFont::nsStyleFont(const nsStyleFont& aSrc)
|
||||
:mFont(aSrc.mFont)
|
||||
: mFlags(aSrc.mFlags),
|
||||
mFont(aSrc.mFont),
|
||||
mSize(aSrc.mSize)
|
||||
{
|
||||
mSize = aSrc.mSize;
|
||||
mFlags = aSrc.mFlags;
|
||||
}
|
||||
|
||||
void*
|
||||
|
|
|
@ -354,8 +354,9 @@ public:
|
|||
NS_IMETHOD SetZoom(float aZoom) = 0;
|
||||
NS_IMETHOD GetZoom(float &aZoom) const = 0;
|
||||
|
||||
//get and set the text zoom value used for display-time
|
||||
//scaling. default is 1.0 (no zoom)
|
||||
//get and set the text zoom value used for display-time scaling.
|
||||
//default is 1.0 (no zoom). The device context doesn't do anything
|
||||
//with this value. It's merely a convenient place to store it.
|
||||
NS_IMETHOD SetTextZoom(float aTextZoom) = 0;
|
||||
NS_IMETHOD GetTextZoom(float &aTextZoom) const = 0;
|
||||
|
||||
|
|
|
@ -138,11 +138,9 @@ NS_IMETHODIMP nsFontMetricsBeOS::Init(const nsFont& aFont, nsIAtom* aLangGroup,
|
|||
float app2dev, app2twip;
|
||||
aContext->GetAppUnitsToDevUnits(app2dev);
|
||||
aContext->GetDevUnitsToTwips(app2twip);
|
||||
float textZoom = 1.0;
|
||||
aContext->GetTextZoom(textZoom);
|
||||
|
||||
app2twip *= app2dev;
|
||||
float rounded = ((float)NSIntPointsToTwips(NSTwipsToFloorIntPoints(nscoord(mFont->size * app2twip * textZoom)))) / app2twip;
|
||||
float rounded = ((float)NSIntPointsToTwips(NSTwipsToFloorIntPoints(nscoord(mFont->size * app2twip)))) / app2twip;
|
||||
|
||||
|
||||
// process specified fonts from first item of the array.
|
||||
|
|
|
@ -1253,9 +1253,7 @@ NS_IMETHODIMP nsFontMetricsGTK::Init(const nsFont& aFont, nsIAtom* aLangGroup,
|
|||
|
||||
float app2dev;
|
||||
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
||||
float textZoom = 1.0;
|
||||
mDeviceContext->GetTextZoom(textZoom);
|
||||
mPixelSize = NSToIntRound(app2dev * textZoom * mFont->size);
|
||||
mPixelSize = NSToIntRound(app2dev * mFont->size);
|
||||
mStretchIndex = 4; // normal
|
||||
mStyleIndex = mFont->style;
|
||||
|
||||
|
|
|
@ -109,10 +109,6 @@ nsFontUtils::GetNativeTextStyle(nsIFontMetrics& inMetrics,
|
|||
|
||||
RGBColor black = {0};
|
||||
|
||||
float textZoom = 1.0;
|
||||
inDevContext.GetTextZoom(textZoom);
|
||||
textSize *= textZoom;
|
||||
|
||||
outStyle.tsFont = (short)fontNum;
|
||||
outStyle.tsFace = textFace;
|
||||
outStyle.tsSize = textSize;
|
||||
|
|
|
@ -1109,10 +1109,8 @@ nsUnicodeRenderingToolkit::GetTextSegmentDimensions(
|
|||
{
|
||||
const nsFont *font;
|
||||
mGS->mFontMetrics->GetFont(font);
|
||||
float textZoom;
|
||||
mContext->GetTextZoom(textZoom);
|
||||
fallbackDone = ATSUIFallbackGetDimensions(aString, segDim, fontNum,
|
||||
font->size * textZoom,
|
||||
font->size,
|
||||
(font->weight > NS_FONT_WEIGHT_NORMAL),
|
||||
((NS_FONT_STYLE_ITALIC == font->style) ||
|
||||
(NS_FONT_STYLE_OBLIQUE == font->style)),
|
||||
|
@ -1271,10 +1269,8 @@ nsresult nsUnicodeRenderingToolkit :: DrawTextSegment(
|
|||
if(! fallbackDone) {
|
||||
const nsFont *font;
|
||||
mGS->mFontMetrics->GetFont(font);
|
||||
float textZoom;
|
||||
mContext->GetTextZoom(textZoom);
|
||||
fallbackDone = ATSUIFallbackDrawChar(aString, x, y, thisWidth, fontNum,
|
||||
font->size * textZoom,
|
||||
font->size,
|
||||
(font->weight > NS_FONT_WEIGHT_NORMAL),
|
||||
((NS_FONT_STYLE_ITALIC == font->style) || (NS_FONT_STYLE_OBLIQUE == font->style)),
|
||||
mGS->mColor );
|
||||
|
|
|
@ -325,10 +325,7 @@ NS_IMETHODIMP DeviceContextImpl::GetMetricsFor(const nsFont& aFont, nsIFontMetri
|
|||
|
||||
NS_IMETHODIMP DeviceContextImpl::SetZoom(float aZoom)
|
||||
{
|
||||
if (mZoom != aZoom) {
|
||||
mZoom = aZoom;
|
||||
FlushFontCache();
|
||||
}
|
||||
mZoom = aZoom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -340,10 +337,7 @@ NS_IMETHODIMP DeviceContextImpl::GetZoom(float &aZoom) const
|
|||
|
||||
NS_IMETHODIMP DeviceContextImpl::SetTextZoom(float aTextZoom)
|
||||
{
|
||||
if (mTextZoom != aTextZoom) {
|
||||
mTextZoom = aTextZoom;
|
||||
FlushFontCache();
|
||||
}
|
||||
mTextZoom = aTextZoom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -552,9 +552,7 @@ static FONTMETRICS* getMetrics( long &lFonts, PCSZ facename, HPS hps)
|
|||
void
|
||||
nsFontMetricsOS2::SetFontHandle( HPS aPS, nsFontOS2* aFont )
|
||||
{
|
||||
float textZoom = 1.0;
|
||||
mDeviceContext->GetTextZoom( textZoom );
|
||||
int points = NSTwipsToIntPoints( mFont.size * textZoom );
|
||||
int points = NSTwipsToIntPoints( mFont.size );
|
||||
|
||||
FATTRS* fattrs = &(aFont->fattrs);
|
||||
if( fattrs->fsFontUse == 0 ) // if image font
|
||||
|
@ -652,9 +650,9 @@ nsFontMetricsOS2::SetFontHandle( HPS aPS, nsFontOS2* aFont )
|
|||
if( fattrs->fsFontUse == 0 ) /* if image font */
|
||||
fHeight = points * gDPI / 72;
|
||||
else
|
||||
fHeight = mFont.size * app2dev * textZoom * gDPI / nsFontMetricsOS2::gSystemRes;
|
||||
fHeight = mFont.size * app2dev * gDPI / nsFontMetricsOS2::gSystemRes;
|
||||
else
|
||||
fHeight = mFont.size * app2dev * textZoom;
|
||||
fHeight = mFont.size * app2dev;
|
||||
|
||||
long lFloor = NSToIntFloor( fHeight );
|
||||
aFont->charbox.cx = MAKEFIXED( lFloor, (fHeight - (float)lFloor) * 65536.0f );
|
||||
|
|
|
@ -156,8 +156,6 @@ NS_IMETHODIMP nsFontMetricsPh::Init ( const nsFont& aFont, nsIAtom* aLangGroup,
|
|||
|
||||
float app2dev;
|
||||
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
||||
float textZoom = 1.0;
|
||||
mDeviceContext->GetTextZoom(textZoom);
|
||||
|
||||
result = aContext->FirstExistingFont(aFont, firstFace);
|
||||
|
||||
|
@ -202,9 +200,8 @@ NS_IMETHODIMP nsFontMetricsPh::Init ( const nsFont& aFont, nsIAtom* aLangGroup,
|
|||
|
||||
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
||||
mDeviceContext->GetCanonicalPixelScale(scale);
|
||||
mDeviceContext->GetTextZoom(textZoom);
|
||||
|
||||
PRInt32 sizePoints = NSToIntRound(app2dev * textZoom * mFont->size * 0.8);
|
||||
PRInt32 sizePoints = NSToIntRound(app2dev * mFont->size * 0.8);
|
||||
|
||||
char NSFontSuffix[5];
|
||||
char NSFullFontName[MAX_FONT_TAG];
|
||||
|
|
|
@ -483,14 +483,10 @@ nsFontMetricsWin::Destroy()
|
|||
|
||||
void
|
||||
nsFontMetricsWin::FillLogFont(LOGFONT* logFont, PRInt32 aWeight,
|
||||
PRBool aSizeOnly, PRBool aSkipZoom)
|
||||
PRBool aSizeOnly)
|
||||
{
|
||||
float app2dev, app2twip, scale;
|
||||
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
||||
float textZoom = 1.0;
|
||||
if (!aSkipZoom) {
|
||||
mDeviceContext->GetTextZoom(textZoom);
|
||||
}
|
||||
if (nsDeviceContextWin::gRound) {
|
||||
mDeviceContext->GetDevUnitsToTwips(app2twip);
|
||||
mDeviceContext->GetCanonicalPixelScale(scale);
|
||||
|
@ -503,13 +499,13 @@ nsFontMetricsWin::FillLogFont(LOGFONT* logFont, PRInt32 aWeight,
|
|||
|
||||
// round font size off to floor point size to be windows compatible
|
||||
// this is proper (windows) rounding
|
||||
logFont->lfHeight = - NSToIntRound(rounded * app2dev * textZoom);
|
||||
logFont->lfHeight = - NSToIntRound(rounded * app2dev);
|
||||
|
||||
// this floor rounding is to make ours compatible with Nav 4.0
|
||||
//logFont->lfHeight = - LONG(rounded * app2dev * textZoom);
|
||||
//logFont->lfHeight = - LONG(rounded * app2dev);
|
||||
}
|
||||
else {
|
||||
logFont->lfHeight = - NSToIntRound(mFont.size * app2dev * textZoom);
|
||||
logFont->lfHeight = - NSToIntRound(mFont.size * app2dev);
|
||||
}
|
||||
|
||||
// Quick return if we came here just to compute the font size
|
||||
|
@ -1962,7 +1958,7 @@ nsFontMetricsWin::CreateFontAdjustHandle(HDC aDC, LOGFONT* aLogFont)
|
|||
nscoord size72 = NSIntPointsToTwips(72); // large value improves accuracy
|
||||
mFont.size = size72;
|
||||
nscoord baselfHeight = aLogFont->lfHeight;
|
||||
FillLogFont(aLogFont, dummy, PR_TRUE, PR_TRUE);
|
||||
FillLogFont(aLogFont, dummy, PR_TRUE);
|
||||
|
||||
HFONT hfont = ::CreateFontIndirect(aLogFont);
|
||||
mFont.size = baseSize;
|
||||
|
|
|
@ -293,7 +293,7 @@ protected:
|
|||
|
||||
nsresult RealizeFont();
|
||||
void FillLogFont(LOGFONT* aLogFont, PRInt32 aWeight,
|
||||
PRBool aSizeOnly=PR_FALSE, PRBool aSkipZoom=PR_FALSE);
|
||||
PRBool aSizeOnly=PR_FALSE);
|
||||
static PLHashTable* InitializeFamilyNames(void);
|
||||
|
||||
nsDeviceContextWin *mDeviceContext;
|
||||
|
|
|
@ -1170,10 +1170,7 @@ nsFontMetricsXlib::Init(const nsFont& aFont, nsIAtom* aLangGroup,
|
|||
float app2dev;
|
||||
mDeviceContext->GetAppUnitsToDevUnits(app2dev);
|
||||
|
||||
float textZoom = 1.0;
|
||||
mDeviceContext->GetTextZoom(textZoom);
|
||||
|
||||
mPixelSize = NSToIntRound(app2dev * textZoom * mFont->size);
|
||||
mPixelSize = NSToIntRound(app2dev * mFont->size);
|
||||
mStretchIndex = 4; // Normal
|
||||
mStyleIndex = mFont->style;
|
||||
|
||||
|
|
|
@ -1583,6 +1583,16 @@ nsRuleNode::WalkRuleTree(const nsStyleStructID aSID,
|
|||
return res;
|
||||
}
|
||||
|
||||
static nscoord
|
||||
ZoomFont(nsIPresContext* aPresContext, nscoord aInSize)
|
||||
{
|
||||
nsCOMPtr<nsIDeviceContext> dc;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
||||
float textZoom;
|
||||
dc->GetTextZoom(textZoom);
|
||||
return nscoord(aInSize * textZoom);
|
||||
}
|
||||
|
||||
const nsStyleStruct*
|
||||
nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsIStyleContext* aContext)
|
||||
{
|
||||
|
@ -1592,6 +1602,8 @@ nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsIStyleContext* aConte
|
|||
const nsFont* defaultFont;
|
||||
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultFont);
|
||||
nsStyleFont* fontData = new (mPresContext) nsStyleFont(*defaultFont);
|
||||
fontData->mSize = fontData->mFont.size =
|
||||
ZoomFont(mPresContext, fontData->mFont.size);
|
||||
aContext->SetStyle(eStyleStruct_Font, *fontData);
|
||||
return fontData;
|
||||
}
|
||||
|
@ -1766,7 +1778,7 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
|||
nscoord aMinFontSize, PRBool aUseDocumentFonts, PRBool aChromeOverride,
|
||||
PRBool aIsGeneric, const nsCSSFont& aFontData,
|
||||
const nsFont& aDefaultFont, const nsStyleFont* aParentFont,
|
||||
nsStyleFont* aFont, PRBool& aInherited)
|
||||
nsStyleFont* aFont, PRBool aZoom, PRBool& aInherited)
|
||||
{
|
||||
const nsFont* defaultVariableFont;
|
||||
const nsFont* defaultFixedFont;
|
||||
|
@ -1994,13 +2006,14 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
|||
}
|
||||
|
||||
// font-size: enum, length, percent, inherit
|
||||
PRBool zoom = aZoom;
|
||||
if (eCSSUnit_Enumerated == aFontData.mSize.GetUnit()) {
|
||||
PRInt32 value = aFontData.mSize.GetIntValue();
|
||||
PRInt32 scaler;
|
||||
aPresContext->GetFontScaler(&scaler);
|
||||
float scaleFactor = nsStyleUtil::GetScalingFactor(scaler);
|
||||
|
||||
aInherited = PR_TRUE;
|
||||
zoom = PR_TRUE;
|
||||
if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&
|
||||
(value <= NS_STYLE_FONT_SIZE_XXLARGE)) {
|
||||
aFont->mSize = nsStyleUtil::CalcFontPointSize(value, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);
|
||||
|
@ -2009,31 +2022,58 @@ SetFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
|||
// <font size="7"> is not specified in CSS, so we don't use eFontSize_CSS.
|
||||
aFont->mSize = nsStyleUtil::CalcFontPointSize(value, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext);
|
||||
}
|
||||
else if (NS_STYLE_FONT_SIZE_LARGER == value) {
|
||||
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(aParentFont->mSize, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);
|
||||
nscoord largerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);
|
||||
aFont->mSize = PR_MAX(largerSize, aParentFont->mSize);
|
||||
}
|
||||
else if (NS_STYLE_FONT_SIZE_SMALLER == value) {
|
||||
PRInt32 index = nsStyleUtil::FindNextSmallerFontSize(aParentFont->mSize, (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);
|
||||
else if (NS_STYLE_FONT_SIZE_LARGER == value ||
|
||||
NS_STYLE_FONT_SIZE_SMALLER == value) {
|
||||
|
||||
aInherited = PR_TRUE;
|
||||
|
||||
// Un-zoom so we use the tables correctly. We'll then rezoom due
|
||||
// to the |zoom = PR_TRUE| above.
|
||||
nsCOMPtr<nsIDeviceContext> dc;
|
||||
aPresContext->GetDeviceContext(getter_AddRefs(dc));
|
||||
float textZoom;
|
||||
dc->GetTextZoom(textZoom);
|
||||
|
||||
nscoord parentSize = nscoord(aParentFont->mSize / textZoom);
|
||||
|
||||
if (NS_STYLE_FONT_SIZE_LARGER == value) {
|
||||
PRInt32 index = nsStyleUtil::FindNextLargerFontSize(parentSize, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);
|
||||
nscoord largerSize = nsStyleUtil::CalcFontPointSize(index, (PRInt32)aDefaultFont.size, scaleFactor, aPresContext, eFontSize_CSS);
|
||||
aFont->mSize = PR_MAX(largerSize, aParentFont->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);
|
||||
}
|
||||
} else {
|
||||
NS_NOTREACHED("unexpected value");
|
||||
}
|
||||
}
|
||||
else if (aFontData.mSize.IsLengthUnit()) {
|
||||
aFont->mSize = CalcLength(aFontData.mSize, &aParentFont->mFont, nsnull, aPresContext, aInherited);
|
||||
zoom = aFontData.mSize.IsFixedLengthUnit() ||
|
||||
aFontData.mSize.GetUnit() == eCSSUnit_Pixel;
|
||||
}
|
||||
else if (eCSSUnit_Percent == aFontData.mSize.GetUnit()) {
|
||||
aInherited = PR_TRUE;
|
||||
aFont->mSize = (nscoord)((float)(aParentFont->mSize) * aFontData.mSize.GetPercentValue());
|
||||
zoom = PR_FALSE;
|
||||
}
|
||||
else if (eCSSUnit_Inherit == aFontData.mSize.GetUnit()) {
|
||||
aInherited = PR_TRUE;
|
||||
aFont->mSize = aParentFont->mSize;
|
||||
zoom = PR_FALSE;
|
||||
}
|
||||
else if (eCSSUnit_Initial == aFontData.mSize.GetUnit()) {
|
||||
aFont->mSize = aDefaultFont.size;
|
||||
zoom = PR_TRUE;
|
||||
}
|
||||
|
||||
// We want to zoom the cascaded size so that em-based measurements,
|
||||
// line-heights, etc., work.
|
||||
if (zoom)
|
||||
aFont->mSize = ZoomFont(aPresContext, aFont->mSize);
|
||||
|
||||
// enforce the user' specified minimum font-size on the value that we expose
|
||||
if (aChromeOverride) {
|
||||
// the chrome is unconstrained, it always uses our cascading size
|
||||
|
@ -2067,7 +2107,7 @@ static void
|
|||
SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
||||
const nsCSSFont& aFontData, PRUint8 aGenericFontID,
|
||||
nscoord aMinFontSize, PRBool aUseDocumentFonts,
|
||||
PRBool aChromeOverride, nsStyleFont* aFont)
|
||||
PRBool aChromeOverride, nsStyleFont* aFont, PRBool aZoom)
|
||||
{
|
||||
// walk up the contexts until a context with the desired generic font
|
||||
nsAutoVoidArray contextPath;
|
||||
|
@ -2135,7 +2175,7 @@ SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
|||
|
||||
SetFont(aPresContext, context, aMinFontSize,
|
||||
aUseDocumentFonts, aChromeOverride, PR_TRUE,
|
||||
fontData, *defaultFont, &parentFont, aFont, dummy);
|
||||
fontData, *defaultFont, &parentFont, aFont, aZoom, dummy);
|
||||
|
||||
// XXX Not sure if we need to do this here
|
||||
// If we have a post-resolve callback, handle that now.
|
||||
|
@ -2152,7 +2192,7 @@ SetGenericFont(nsIPresContext* aPresContext, nsIStyleContext* aContext,
|
|||
// can just compute the delta from the parent.
|
||||
SetFont(aPresContext, aContext, aMinFontSize,
|
||||
aUseDocumentFonts, aChromeOverride, PR_TRUE,
|
||||
aFontData, *defaultFont, &parentFont, aFont, dummy);
|
||||
aFontData, *defaultFont, &parentFont, aFont, aZoom, dummy);
|
||||
}
|
||||
|
||||
const nsStyleStruct*
|
||||
|
@ -2185,10 +2225,12 @@ nsRuleNode::ComputeFontData(nsStyleStruct* aStartStruct, const nsCSSStruct& aDat
|
|||
}
|
||||
}
|
||||
|
||||
PRBool zoom = PR_FALSE;
|
||||
const nsFont* defaultFont;
|
||||
if (!font) {
|
||||
mPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID, &defaultFont);
|
||||
font = new (mPresContext) nsStyleFont(*defaultFont);
|
||||
zoom = PR_TRUE;
|
||||
}
|
||||
if (!parentFont)
|
||||
parentFont = font;
|
||||
|
@ -2257,14 +2299,14 @@ nsRuleNode::ComputeFontData(nsStyleStruct* aStartStruct, const nsCSSStruct& aDat
|
|||
mPresContext->GetDefaultFont(generic, &defaultFont);
|
||||
SetFont(mPresContext, aContext, minimumFontSize,
|
||||
useDocumentFonts, chromeOverride, PR_FALSE,
|
||||
fontData, *defaultFont, parentFont, font, inherited);
|
||||
fontData, *defaultFont, parentFont, font, zoom, inherited);
|
||||
}
|
||||
else {
|
||||
// re-calculate the font as a generic font
|
||||
inherited = PR_TRUE;
|
||||
SetGenericFont(mPresContext, aContext, fontData,
|
||||
generic, minimumFontSize, useDocumentFonts,
|
||||
chromeOverride, font);
|
||||
chromeOverride, font, zoom);
|
||||
}
|
||||
// Set our generic font's bit to inform our descendants
|
||||
font->mFlags &= ~NS_STYLE_FONT_FACE_MASK;
|
||||
|
@ -2332,10 +2374,15 @@ nsRuleNode::ComputeTextData(nsStyleStruct* aStartStruct, const nsCSSStruct& aDat
|
|||
aContext->GetStyleData(eStyleStruct_Font));
|
||||
text->mLineHeight.SetCoordValue((nscoord)((float)(font->mSize) *
|
||||
textData.mLineHeight.GetPercentValue()));
|
||||
} else
|
||||
} else {
|
||||
SetCoord(textData.mLineHeight, text->mLineHeight, parentText->mLineHeight,
|
||||
SETCOORD_LH | SETCOORD_FACTOR | SETCOORD_NORMAL,
|
||||
aContext, mPresContext, inherited);
|
||||
if (textData.mLineHeight.IsFixedLengthUnit() ||
|
||||
textData.mLineHeight.GetUnit() == eCSSUnit_Pixel)
|
||||
text->mLineHeight.SetCoordValue(
|
||||
ZoomFont(mPresContext, text->mLineHeight.GetCoordValue()));
|
||||
}
|
||||
|
||||
|
||||
// text-align: enum, string, inherit
|
||||
|
|
|
@ -221,16 +221,16 @@ nsStyleFont::nsStyleFont()
|
|||
|
||||
nsStyleFont::nsStyleFont(const nsFont& aFont)
|
||||
: mFlags(NS_STYLE_FONT_DEFAULT),
|
||||
mFont(aFont)
|
||||
mFont(aFont),
|
||||
mSize(aFont.size)
|
||||
{
|
||||
mSize = aFont.size;
|
||||
}
|
||||
|
||||
nsStyleFont::nsStyleFont(const nsStyleFont& aSrc)
|
||||
:mFont(aSrc.mFont)
|
||||
: mFlags(aSrc.mFlags),
|
||||
mFont(aSrc.mFont),
|
||||
mSize(aSrc.mSize)
|
||||
{
|
||||
mSize = aSrc.mSize;
|
||||
mFlags = aSrc.mFlags;
|
||||
}
|
||||
|
||||
void*
|
||||
|
|
Загрузка…
Ссылка в новой задаче