зеркало из https://github.com/mozilla/gecko-dev.git
#76097 Need to include external leading for CJK normal Line-height
Font metrics returns both internal and external leading to layout. Layout now is responsible for calculating the normalLineHeight. It take consideration of external leading, and compensate if it does not exist. All these are controled by a preference switch. r=rbs, sr=attinasi,
This commit is contained in:
Родитель
1a4c177e1c
Коммит
84eb514a5a
|
@ -138,21 +138,43 @@ public:
|
|||
*/
|
||||
NS_IMETHOD GetHeight(nscoord &aHeight) = 0;
|
||||
|
||||
|
||||
#if defined(XP_WIN)
|
||||
#define FONT_LEADING_APIS_V2 1
|
||||
#endif
|
||||
|
||||
#if defined(XP_UNIX) || defined(XP_PC) || defined(XP_MAC) || defined(XP_BEOS)
|
||||
#define NEW_FONT_HEIGHT_APIS 1
|
||||
#endif
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
#ifndef FONT_LEADING_APIS_V2
|
||||
/**
|
||||
* Returns the normal line height (em height + leading).
|
||||
*/
|
||||
NS_IMETHOD GetNormalLineHeight(nscoord &aHeight) = 0;
|
||||
#endif /* not FONT_LEADING_APIS_V2 */
|
||||
#endif /* NEW_FONT_HEIGHT_APIS */
|
||||
|
||||
#ifdef FONT_LEADING_APIS_V2
|
||||
/**
|
||||
* Returns the amount of internal leading (in app units) for the font. This
|
||||
* is computed as the "height - (ascent + descent)"
|
||||
*/
|
||||
NS_IMETHOD GetInternalLeading(nscoord &aLeading) = 0;
|
||||
|
||||
/**
|
||||
* Returns the amount of external leading (in app units) as suggested by font
|
||||
* vendor. This value is suggested by font vendor to add to normal line-height
|
||||
* beside font height.
|
||||
*/
|
||||
NS_IMETHOD GetExternalLeading(nscoord &aLeading) = 0;
|
||||
#else
|
||||
/**
|
||||
* Returns the amount of internal leading (in app units) for the font. This
|
||||
* is computed as the "height - (ascent + descent)"
|
||||
*/
|
||||
NS_IMETHOD GetLeading(nscoord &aLeading) = 0;
|
||||
#endif /* FONT_LEADING_APIS_V2 */
|
||||
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ static nsIAtom* gZHTW = nsnull;
|
|||
static nsIAtom* gZHCN = nsnull;
|
||||
|
||||
static int gInitialized = 0;
|
||||
|
||||
static PRBool gDoingLineheightFixup = PR_FALSE;
|
||||
static PRUint16* gUserDefinedCCMap = nsnull;
|
||||
|
||||
static nsCharsetInfo gCharsetInfo[eCharset_COUNT] =
|
||||
|
@ -299,6 +299,15 @@ InitGlobals(void)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// if we do not include/compensate external leading in calculating normal
|
||||
// line height, we don't set gDoingLineheightFixup either to keep old behavior.
|
||||
// These code should be eliminated in future when we choose to stay with
|
||||
// one normal lineheight calculation method.
|
||||
PRInt32 intPref;
|
||||
if (NS_SUCCEEDED(gPref->GetIntPref(
|
||||
"browser.display.normal_lineheight_calc_control", &intPref)))
|
||||
gDoingLineheightFixup = (intPref != 0);
|
||||
|
||||
nsCOMPtr<nsILanguageAtomService> langService;
|
||||
langService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);
|
||||
if (langService) {
|
||||
|
@ -3262,7 +3271,10 @@ nsFontMetricsWin::RealizeFont()
|
|||
mStrikeoutSize = PR_MAX(onePixel, NSToCoordRound(oMetrics.otmsStrikeoutSize * dev2app));
|
||||
mStrikeoutOffset = NSToCoordRound(oMetrics.otmsStrikeoutPosition * dev2app);
|
||||
mUnderlineSize = PR_MAX(onePixel, NSToCoordRound(oMetrics.otmsUnderscoreSize * dev2app));
|
||||
mUnderlineOffset = NSToCoordRound(oMetrics.otmsUnderscorePosition * dev2app);
|
||||
if (gDoingLineheightFixup)
|
||||
mUnderlineOffset = NSToCoordRound(PR_MIN(oMetrics.otmsUnderscorePosition, oMetrics.otmDescent) * dev2app);
|
||||
else
|
||||
mUnderlineOffset = NSToCoordRound(oMetrics.otmsUnderscorePosition * dev2app);
|
||||
|
||||
// Begin -- section of code to get the real x-height with GetGlyphOutline()
|
||||
GLYPHMETRICS gm;
|
||||
|
@ -3287,7 +3299,8 @@ nsFontMetricsWin::RealizeFont()
|
|||
mUnderlineOffset = -NSToCoordRound((float)metrics.tmDescent * dev2app * 0.30f); // 30% of descent
|
||||
}
|
||||
|
||||
mLeading = NSToCoordRound(metrics.tmInternalLeading * dev2app);
|
||||
mInternalLeading = NSToCoordRound(metrics.tmInternalLeading * dev2app);
|
||||
mExternalLeading = NSToCoordRound(metrics.tmExternalLeading * dev2app);
|
||||
mEmHeight = NSToCoordRound((metrics.tmHeight - metrics.tmInternalLeading) *
|
||||
dev2app);
|
||||
mEmAscent = NSToCoordRound((metrics.tmAscent - metrics.tmInternalLeading) *
|
||||
|
@ -3361,19 +3374,35 @@ nsFontMetricsWin::GetHeight(nscoord &aHeight)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef FONT_LEADING_APIS_V2
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsWin::GetNormalLineHeight(nscoord &aHeight)
|
||||
nsFontMetricsWin::GetInternalLeading(nscoord &aLeading)
|
||||
{
|
||||
aHeight = mEmHeight + mLeading;
|
||||
aLeading = mInternalLeading;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsWin::GetLeading(nscoord &aLeading)
|
||||
nsFontMetricsWin::GetExternalLeading(nscoord &aLeading)
|
||||
{
|
||||
aLeading = mLeading;
|
||||
aLeading = mExternalLeading;
|
||||
return NS_OK;
|
||||
}
|
||||
#else
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsWin::GetLeading(nscoord &aLeading)
|
||||
{
|
||||
aLeading = mInternalLeading;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsWin::GetNormalLineHeight(nscoord &aHeight)
|
||||
{
|
||||
aHeight = mEmHeight + mInternalLeading;
|
||||
return NS_OK;
|
||||
}
|
||||
#endif //FONT_LEADING_APIS_V2
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontMetricsWin::GetEmHeight(nscoord &aHeight)
|
||||
|
@ -4973,6 +5002,7 @@ nsFontMetricsWinA::ResolveForwards(HDC aDC,
|
|||
|
||||
//do it for last part of the string
|
||||
fontSwitch.mFontWin = currSubset;
|
||||
NS_ASSERTION(currSubset, "invalid font here. ");
|
||||
(*aFunc)(&fontSwitch, firstChar, currChar - firstChar, aData);
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -186,8 +186,13 @@ public:
|
|||
NS_IMETHOD GetStrikeout(nscoord& aOffset, nscoord& aSize);
|
||||
NS_IMETHOD GetUnderline(nscoord& aOffset, nscoord& aSize);
|
||||
NS_IMETHOD GetHeight(nscoord &aHeight);
|
||||
NS_IMETHOD GetNormalLineHeight(nscoord &aHeight);
|
||||
#ifdef FONT_LEADING_APIS_V2
|
||||
NS_IMETHOD GetInternalLeading(nscoord &aLeading);
|
||||
NS_IMETHOD GetExternalLeading(nscoord &aLeading);
|
||||
#else
|
||||
NS_IMETHOD GetLeading(nscoord &aLeading);
|
||||
NS_IMETHOD GetNormalLineHeight(nscoord &aHeight);
|
||||
#endif //FONT_LEADING_APIS_V2
|
||||
NS_IMETHOD GetEmHeight(nscoord &aHeight);
|
||||
NS_IMETHOD GetEmAscent(nscoord &aAscent);
|
||||
NS_IMETHOD GetEmDescent(nscoord &aDescent);
|
||||
|
@ -301,7 +306,8 @@ protected:
|
|||
|
||||
HFONT mFontHandle;
|
||||
|
||||
nscoord mLeading;
|
||||
nscoord mExternalLeading;
|
||||
nscoord mInternalLeading;
|
||||
nscoord mEmHeight;
|
||||
nscoord mEmAscent;
|
||||
nscoord mEmDescent;
|
||||
|
|
|
@ -65,9 +65,17 @@
|
|||
#include "nsIFormManager.h"
|
||||
|
||||
// Prefs-driven control for |text-decoration: blink|
|
||||
static PRPackedBool sBlinkPrefIsLoaded = PR_FALSE;
|
||||
static PRPackedBool sPrefIsLoaded = PR_FALSE;
|
||||
static PRPackedBool sBlinkIsAllowed = PR_TRUE;
|
||||
|
||||
enum eNormalLineHeightControl {
|
||||
eUninitialized = -1,
|
||||
eNoExternalLeading = 0, // does not include external leading
|
||||
eIncludeExternalLeading, // use whatever value font vendor provides
|
||||
eCompensateLeading // compensate leading if leading provided by font vendor is not enough
|
||||
};
|
||||
static eNormalLineHeightControl sNormalLineHeightControl = eUninitialized;
|
||||
|
||||
#ifdef DEBUG
|
||||
const char*
|
||||
nsHTMLReflowState::ReasonToString(nsReflowReason aReason)
|
||||
|
@ -1574,12 +1582,13 @@ nsHTMLReflowState::ComputeContainingBlockRectangle(nsIPresContext* aPre
|
|||
// Prefs callback to pick up changes
|
||||
static int PR_CALLBACK PrefsChanged(const char *aPrefName, void *instance)
|
||||
{
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs) {
|
||||
PRBool boolPref;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs && NS_SUCCEEDED(prefs->GetBoolPref("browser.blink_allowed",
|
||||
&boolPref)))
|
||||
sBlinkIsAllowed = boolPref;
|
||||
return 0; /* PREF_OK */
|
||||
if (NS_SUCCEEDED(prefs->GetBoolPref("browser.blink_allowed", &boolPref)))
|
||||
sBlinkIsAllowed = boolPref;
|
||||
}
|
||||
return 0; /* PREF_OK */
|
||||
}
|
||||
|
||||
// Check to see if |text-decoration: blink| is allowed. The first time
|
||||
|
@ -1587,16 +1596,33 @@ static int PR_CALLBACK PrefsChanged(const char *aPrefName, void *instance)
|
|||
// just use the cached value.
|
||||
static PRBool BlinkIsAllowed(void)
|
||||
{
|
||||
if (!sBlinkPrefIsLoaded) {
|
||||
// Set up a listener and check the initial value
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs)
|
||||
prefs->RegisterCallback("browser.blink_allowed", PrefsChanged,
|
||||
nsnull);
|
||||
PrefsChanged(nsnull, nsnull);
|
||||
sBlinkPrefIsLoaded = PR_TRUE;
|
||||
if (!sPrefIsLoaded) {
|
||||
// Set up a listener and check the initial value
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs) {
|
||||
prefs->RegisterCallback("browser.blink_allowed", PrefsChanged,
|
||||
nsnull);
|
||||
}
|
||||
return sBlinkIsAllowed;
|
||||
PrefsChanged(nsnull, nsnull);
|
||||
sPrefIsLoaded = PR_TRUE;
|
||||
}
|
||||
return sBlinkIsAllowed;
|
||||
}
|
||||
|
||||
static eNormalLineHeightControl GetNormalLineHeightCalcControl(void)
|
||||
{
|
||||
if (sNormalLineHeightControl == eUninitialized) {
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
PRInt32 intPref;
|
||||
// browser.display.normal_lineheight_calc_control is not user changable, so
|
||||
// no need to register callback for it.
|
||||
if (prefs && NS_SUCCEEDED(prefs->GetIntPref(
|
||||
"browser.display.normal_lineheight_calc_control", &intPref)))
|
||||
sNormalLineHeightControl = NS_STATIC_CAST(eNormalLineHeightControl, intPref);
|
||||
else
|
||||
sNormalLineHeightControl = eNoExternalLeading;
|
||||
}
|
||||
return sNormalLineHeightControl;
|
||||
}
|
||||
|
||||
// XXX refactor this code to have methods for each set of properties
|
||||
|
@ -2189,8 +2215,53 @@ nsHTMLReflowState::UseComputedHeight()
|
|||
return useComputedHeight;
|
||||
}
|
||||
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
#define NORMAL_LINE_HEIGHT_FACTOR 1.2f // in term of emHeight
|
||||
// For "normal" we use the font's normal line height (em height + leading).
|
||||
// If both internal leading and external leading specified by font itself
|
||||
// are zeros, we should compensate this by creating extra (external) leading
|
||||
// in eCompensateLeading mode. This is necessary because without this
|
||||
// compensation, normal line height might looks too tight.
|
||||
|
||||
// For risk management, we use preference to control the behavior, and
|
||||
// eNoExternalLeading is the old behavior.
|
||||
static nscoord
|
||||
ComputeLineHeight(nsIRenderingContext* aRenderingContext,
|
||||
GetNormalLineHeight(nsIFontMetrics* aFontMetrics)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aFontMetrics, "no font metrics");
|
||||
|
||||
nscoord normalLineHeight;
|
||||
nscoord emHeight;
|
||||
|
||||
#ifdef FONT_LEADING_APIS_V2
|
||||
nscoord externalLeading, internalLeading;
|
||||
aFontMetrics->GetExternalLeading(externalLeading);
|
||||
aFontMetrics->GetInternalLeading(internalLeading);
|
||||
aFontMetrics->GetEmHeight(emHeight);
|
||||
switch (GetNormalLineHeightCalcControl()) {
|
||||
case eIncludeExternalLeading:
|
||||
normalLineHeight = emHeight+ internalLeading + externalLeading;
|
||||
break;
|
||||
case eCompensateLeading:
|
||||
if (!internalLeading && !externalLeading)
|
||||
normalLineHeight = NSToCoordRound(emHeight * NORMAL_LINE_HEIGHT_FACTOR);
|
||||
else
|
||||
normalLineHeight = emHeight+ internalLeading + externalLeading;
|
||||
break;
|
||||
default:
|
||||
//case eNoExternalLeading:
|
||||
normalLineHeight = emHeight + internalLeading;
|
||||
}
|
||||
#else
|
||||
aFontMetrics->GetNormalLineHeight(normalLineHeight);
|
||||
#endif // FONT_LEADING_APIS_V2
|
||||
return normalLineHeight;
|
||||
}
|
||||
#endif // NEW_FONT_HEIGHT_APIS
|
||||
|
||||
static nscoord
|
||||
ComputeLineHeight(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRenderingContext,
|
||||
nsIStyleContext* aStyleContext)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aRenderingContext, "no rendering context");
|
||||
|
@ -2206,17 +2277,10 @@ ComputeLineHeight(nsIRenderingContext* aRenderingContext,
|
|||
|
||||
nsStyleUnit unit = text->mLineHeight.GetUnit();
|
||||
|
||||
if (eStyleUnit_Coord == unit) {
|
||||
if (unit == eStyleUnit_Coord) {
|
||||
// For length values just use the pre-computed value
|
||||
lineHeight = text->mLineHeight.GetCoordValue();
|
||||
}
|
||||
else {
|
||||
// For "normal" or factor units the computed value of the
|
||||
// line-height property is found by multiplying the factor by the
|
||||
// font's <b>actual</b> em height. For "normal" we use the font's
|
||||
// normal line height (em height + leading).
|
||||
nscoord emHeight = -1;
|
||||
nscoord normalLineHeight = -1;
|
||||
} else {
|
||||
nsCOMPtr<nsIDeviceContext> deviceContext;
|
||||
aRenderingContext->GetDeviceContext(*getter_AddRefs(deviceContext));
|
||||
nsCOMPtr<nsIAtom> langGroup;
|
||||
|
@ -2225,33 +2289,35 @@ ComputeLineHeight(nsIRenderingContext* aRenderingContext,
|
|||
}
|
||||
nsCOMPtr<nsIFontMetrics> fm;
|
||||
deviceContext->GetMetricsFor(font->mFont, langGroup, *getter_AddRefs(fm));
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
if (fm) {
|
||||
fm->GetEmHeight(emHeight);
|
||||
fm->GetNormalLineHeight(normalLineHeight);
|
||||
}
|
||||
#endif
|
||||
float factor;
|
||||
if (eStyleUnit_Factor == unit) {
|
||||
|
||||
if (unit == eStyleUnit_Factor) {
|
||||
// For factor units the computed value of the line-height property
|
||||
// is found by multiplying the factor by the font's <b>actual</b>
|
||||
// em height.
|
||||
float factor;
|
||||
factor = text->mLineHeight.GetFactorValue();
|
||||
}
|
||||
else {
|
||||
// Note: we normally use the actual font height for computing the
|
||||
// line-height raw value from the style context. On systems where
|
||||
// they disagree the actual font height is more appropriate. This
|
||||
// little hack lets us override that behavior to allow for more
|
||||
// precise layout in the face of imprecise fonts.
|
||||
nscoord emHeight = font->mFont.size;
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
if (!nsHTMLReflowState::UseComputedHeight()) {
|
||||
fm->GetEmHeight(emHeight);
|
||||
}
|
||||
#endif
|
||||
lineHeight = NSToCoordRound(factor * emHeight);
|
||||
} else {
|
||||
NS_ASSERTION(eStyleUnit_Normal == unit, "bad unit");
|
||||
factor = (((float) normalLineHeight) / PR_MAX(1, emHeight));
|
||||
lineHeight = font->mFont.size;
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
if (!nsHTMLReflowState::UseComputedHeight()) {
|
||||
lineHeight = GetNormalLineHeight(fm);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Note: we normally use the actual font height for computing the
|
||||
// line-height raw value from the style context. On systems where
|
||||
// they disagree the actual font height is more appropriate. This
|
||||
// little hack lets us override that behavior to allow for more
|
||||
// precise layout in the face of imprecise fonts.
|
||||
if (nsHTMLReflowState::UseComputedHeight()) {
|
||||
emHeight = font->mFont.size;
|
||||
}
|
||||
|
||||
lineHeight = NSToCoordRound(factor * emHeight);
|
||||
}
|
||||
|
||||
return lineHeight;
|
||||
}
|
||||
|
||||
|
@ -2264,7 +2330,7 @@ nsHTMLReflowState::CalcLineHeight(nsIPresContext* aPresContext,
|
|||
nsCOMPtr<nsIStyleContext> sc;
|
||||
aFrame->GetStyleContext(getter_AddRefs(sc));
|
||||
if (sc) {
|
||||
lineHeight = ComputeLineHeight(aRenderingContext, sc);
|
||||
lineHeight = ComputeLineHeight(aPresContext, aRenderingContext, sc);
|
||||
}
|
||||
if (lineHeight < 0) {
|
||||
// Negative line-heights are not allowed by the spec. Translate
|
||||
|
@ -2280,7 +2346,7 @@ nsHTMLReflowState::CalcLineHeight(nsIPresContext* aPresContext,
|
|||
aRenderingContext->GetFontMetrics(*getter_AddRefs(fm));
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
if (fm) {
|
||||
fm->GetNormalLineHeight(lineHeight);
|
||||
lineHeight = GetNormalLineHeight(fm);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -65,9 +65,17 @@
|
|||
#include "nsIFormManager.h"
|
||||
|
||||
// Prefs-driven control for |text-decoration: blink|
|
||||
static PRPackedBool sBlinkPrefIsLoaded = PR_FALSE;
|
||||
static PRPackedBool sPrefIsLoaded = PR_FALSE;
|
||||
static PRPackedBool sBlinkIsAllowed = PR_TRUE;
|
||||
|
||||
enum eNormalLineHeightControl {
|
||||
eUninitialized = -1,
|
||||
eNoExternalLeading = 0, // does not include external leading
|
||||
eIncludeExternalLeading, // use whatever value font vendor provides
|
||||
eCompensateLeading // compensate leading if leading provided by font vendor is not enough
|
||||
};
|
||||
static eNormalLineHeightControl sNormalLineHeightControl = eUninitialized;
|
||||
|
||||
#ifdef DEBUG
|
||||
const char*
|
||||
nsHTMLReflowState::ReasonToString(nsReflowReason aReason)
|
||||
|
@ -1574,12 +1582,13 @@ nsHTMLReflowState::ComputeContainingBlockRectangle(nsIPresContext* aPre
|
|||
// Prefs callback to pick up changes
|
||||
static int PR_CALLBACK PrefsChanged(const char *aPrefName, void *instance)
|
||||
{
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs) {
|
||||
PRBool boolPref;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs && NS_SUCCEEDED(prefs->GetBoolPref("browser.blink_allowed",
|
||||
&boolPref)))
|
||||
sBlinkIsAllowed = boolPref;
|
||||
return 0; /* PREF_OK */
|
||||
if (NS_SUCCEEDED(prefs->GetBoolPref("browser.blink_allowed", &boolPref)))
|
||||
sBlinkIsAllowed = boolPref;
|
||||
}
|
||||
return 0; /* PREF_OK */
|
||||
}
|
||||
|
||||
// Check to see if |text-decoration: blink| is allowed. The first time
|
||||
|
@ -1587,16 +1596,33 @@ static int PR_CALLBACK PrefsChanged(const char *aPrefName, void *instance)
|
|||
// just use the cached value.
|
||||
static PRBool BlinkIsAllowed(void)
|
||||
{
|
||||
if (!sBlinkPrefIsLoaded) {
|
||||
// Set up a listener and check the initial value
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs)
|
||||
prefs->RegisterCallback("browser.blink_allowed", PrefsChanged,
|
||||
nsnull);
|
||||
PrefsChanged(nsnull, nsnull);
|
||||
sBlinkPrefIsLoaded = PR_TRUE;
|
||||
if (!sPrefIsLoaded) {
|
||||
// Set up a listener and check the initial value
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs) {
|
||||
prefs->RegisterCallback("browser.blink_allowed", PrefsChanged,
|
||||
nsnull);
|
||||
}
|
||||
return sBlinkIsAllowed;
|
||||
PrefsChanged(nsnull, nsnull);
|
||||
sPrefIsLoaded = PR_TRUE;
|
||||
}
|
||||
return sBlinkIsAllowed;
|
||||
}
|
||||
|
||||
static eNormalLineHeightControl GetNormalLineHeightCalcControl(void)
|
||||
{
|
||||
if (sNormalLineHeightControl == eUninitialized) {
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
PRInt32 intPref;
|
||||
// browser.display.normal_lineheight_calc_control is not user changable, so
|
||||
// no need to register callback for it.
|
||||
if (prefs && NS_SUCCEEDED(prefs->GetIntPref(
|
||||
"browser.display.normal_lineheight_calc_control", &intPref)))
|
||||
sNormalLineHeightControl = NS_STATIC_CAST(eNormalLineHeightControl, intPref);
|
||||
else
|
||||
sNormalLineHeightControl = eNoExternalLeading;
|
||||
}
|
||||
return sNormalLineHeightControl;
|
||||
}
|
||||
|
||||
// XXX refactor this code to have methods for each set of properties
|
||||
|
@ -2189,8 +2215,53 @@ nsHTMLReflowState::UseComputedHeight()
|
|||
return useComputedHeight;
|
||||
}
|
||||
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
#define NORMAL_LINE_HEIGHT_FACTOR 1.2f // in term of emHeight
|
||||
// For "normal" we use the font's normal line height (em height + leading).
|
||||
// If both internal leading and external leading specified by font itself
|
||||
// are zeros, we should compensate this by creating extra (external) leading
|
||||
// in eCompensateLeading mode. This is necessary because without this
|
||||
// compensation, normal line height might looks too tight.
|
||||
|
||||
// For risk management, we use preference to control the behavior, and
|
||||
// eNoExternalLeading is the old behavior.
|
||||
static nscoord
|
||||
ComputeLineHeight(nsIRenderingContext* aRenderingContext,
|
||||
GetNormalLineHeight(nsIFontMetrics* aFontMetrics)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aFontMetrics, "no font metrics");
|
||||
|
||||
nscoord normalLineHeight;
|
||||
nscoord emHeight;
|
||||
|
||||
#ifdef FONT_LEADING_APIS_V2
|
||||
nscoord externalLeading, internalLeading;
|
||||
aFontMetrics->GetExternalLeading(externalLeading);
|
||||
aFontMetrics->GetInternalLeading(internalLeading);
|
||||
aFontMetrics->GetEmHeight(emHeight);
|
||||
switch (GetNormalLineHeightCalcControl()) {
|
||||
case eIncludeExternalLeading:
|
||||
normalLineHeight = emHeight+ internalLeading + externalLeading;
|
||||
break;
|
||||
case eCompensateLeading:
|
||||
if (!internalLeading && !externalLeading)
|
||||
normalLineHeight = NSToCoordRound(emHeight * NORMAL_LINE_HEIGHT_FACTOR);
|
||||
else
|
||||
normalLineHeight = emHeight+ internalLeading + externalLeading;
|
||||
break;
|
||||
default:
|
||||
//case eNoExternalLeading:
|
||||
normalLineHeight = emHeight + internalLeading;
|
||||
}
|
||||
#else
|
||||
aFontMetrics->GetNormalLineHeight(normalLineHeight);
|
||||
#endif // FONT_LEADING_APIS_V2
|
||||
return normalLineHeight;
|
||||
}
|
||||
#endif // NEW_FONT_HEIGHT_APIS
|
||||
|
||||
static nscoord
|
||||
ComputeLineHeight(nsIPresContext* aPresContext,
|
||||
nsIRenderingContext* aRenderingContext,
|
||||
nsIStyleContext* aStyleContext)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aRenderingContext, "no rendering context");
|
||||
|
@ -2206,17 +2277,10 @@ ComputeLineHeight(nsIRenderingContext* aRenderingContext,
|
|||
|
||||
nsStyleUnit unit = text->mLineHeight.GetUnit();
|
||||
|
||||
if (eStyleUnit_Coord == unit) {
|
||||
if (unit == eStyleUnit_Coord) {
|
||||
// For length values just use the pre-computed value
|
||||
lineHeight = text->mLineHeight.GetCoordValue();
|
||||
}
|
||||
else {
|
||||
// For "normal" or factor units the computed value of the
|
||||
// line-height property is found by multiplying the factor by the
|
||||
// font's <b>actual</b> em height. For "normal" we use the font's
|
||||
// normal line height (em height + leading).
|
||||
nscoord emHeight = -1;
|
||||
nscoord normalLineHeight = -1;
|
||||
} else {
|
||||
nsCOMPtr<nsIDeviceContext> deviceContext;
|
||||
aRenderingContext->GetDeviceContext(*getter_AddRefs(deviceContext));
|
||||
nsCOMPtr<nsIAtom> langGroup;
|
||||
|
@ -2225,33 +2289,35 @@ ComputeLineHeight(nsIRenderingContext* aRenderingContext,
|
|||
}
|
||||
nsCOMPtr<nsIFontMetrics> fm;
|
||||
deviceContext->GetMetricsFor(font->mFont, langGroup, *getter_AddRefs(fm));
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
if (fm) {
|
||||
fm->GetEmHeight(emHeight);
|
||||
fm->GetNormalLineHeight(normalLineHeight);
|
||||
}
|
||||
#endif
|
||||
float factor;
|
||||
if (eStyleUnit_Factor == unit) {
|
||||
|
||||
if (unit == eStyleUnit_Factor) {
|
||||
// For factor units the computed value of the line-height property
|
||||
// is found by multiplying the factor by the font's <b>actual</b>
|
||||
// em height.
|
||||
float factor;
|
||||
factor = text->mLineHeight.GetFactorValue();
|
||||
}
|
||||
else {
|
||||
// Note: we normally use the actual font height for computing the
|
||||
// line-height raw value from the style context. On systems where
|
||||
// they disagree the actual font height is more appropriate. This
|
||||
// little hack lets us override that behavior to allow for more
|
||||
// precise layout in the face of imprecise fonts.
|
||||
nscoord emHeight = font->mFont.size;
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
if (!nsHTMLReflowState::UseComputedHeight()) {
|
||||
fm->GetEmHeight(emHeight);
|
||||
}
|
||||
#endif
|
||||
lineHeight = NSToCoordRound(factor * emHeight);
|
||||
} else {
|
||||
NS_ASSERTION(eStyleUnit_Normal == unit, "bad unit");
|
||||
factor = (((float) normalLineHeight) / PR_MAX(1, emHeight));
|
||||
lineHeight = font->mFont.size;
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
if (!nsHTMLReflowState::UseComputedHeight()) {
|
||||
lineHeight = GetNormalLineHeight(fm);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Note: we normally use the actual font height for computing the
|
||||
// line-height raw value from the style context. On systems where
|
||||
// they disagree the actual font height is more appropriate. This
|
||||
// little hack lets us override that behavior to allow for more
|
||||
// precise layout in the face of imprecise fonts.
|
||||
if (nsHTMLReflowState::UseComputedHeight()) {
|
||||
emHeight = font->mFont.size;
|
||||
}
|
||||
|
||||
lineHeight = NSToCoordRound(factor * emHeight);
|
||||
}
|
||||
|
||||
return lineHeight;
|
||||
}
|
||||
|
||||
|
@ -2264,7 +2330,7 @@ nsHTMLReflowState::CalcLineHeight(nsIPresContext* aPresContext,
|
|||
nsCOMPtr<nsIStyleContext> sc;
|
||||
aFrame->GetStyleContext(getter_AddRefs(sc));
|
||||
if (sc) {
|
||||
lineHeight = ComputeLineHeight(aRenderingContext, sc);
|
||||
lineHeight = ComputeLineHeight(aPresContext, aRenderingContext, sc);
|
||||
}
|
||||
if (lineHeight < 0) {
|
||||
// Negative line-heights are not allowed by the spec. Translate
|
||||
|
@ -2280,7 +2346,7 @@ nsHTMLReflowState::CalcLineHeight(nsIPresContext* aPresContext,
|
|||
aRenderingContext->GetFontMetrics(*getter_AddRefs(fm));
|
||||
#ifdef NEW_FONT_HEIGHT_APIS
|
||||
if (fm) {
|
||||
fm->GetNormalLineHeight(lineHeight);
|
||||
lineHeight = GetNormalLineHeight(fm);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -79,6 +79,10 @@ pref("browser.display.use_system_colors", false);
|
|||
pref("browser.display.foreground_color", "#000000");
|
||||
pref("browser.display.background_color", "#FFFFFF");
|
||||
pref("browser.display.force_inline_alttext", false); // true = force ALT text for missing images to be layed out inline
|
||||
// 0 = no external leading,
|
||||
// 1 = use external leading only when font provides,
|
||||
// 2 = add extra leading both internal leading and external leading are zero
|
||||
pref("browser.display.normal_lineheight_calc_control", 2);
|
||||
pref("browser.display.show_image_placeholders", true); // true = show image placeholders while image is loaded and when image is broken
|
||||
pref("browser.anchor_color", "#0000EE");
|
||||
pref("browser.visited_color", "#551A8B");
|
||||
|
|
Загрузка…
Ссылка в новой задаче