Bug 784375: Add a preference to control maximum font size inflation ratio. [r=dbaron]

This commit is contained in:
Scott Johnson 2012-10-15 14:03:37 -05:00
parent e47cb5e5f6
commit e2ecfdda8c
6 changed files with 64 additions and 4 deletions

View File

@ -106,7 +106,8 @@ typedef FrameMetrics::ViewID ViewID;
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationEmPerLine;
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationMinTwips;
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationLineThreshold;
/* static */ int32_t nsLayoutUtils::sFontSizeInflationMappingIntercept;
/* static */ int32_t nsLayoutUtils::sFontSizeInflationMappingIntercept;
/* static */ uint32_t nsLayoutUtils::sFontSizeInflationMaxRatio;
static ViewID sScrollIdCounter = FrameMetrics::START_SCROLL_ID;
@ -4739,6 +4740,8 @@ nsLayoutUtils::SizeOfTextRunsForFrames(nsIFrame* aFrame,
void
nsLayoutUtils::Initialize()
{
Preferences::AddUintVarCache(&sFontSizeInflationMaxRatio,
"font.size.inflation.maxRatio");
Preferences::AddUintVarCache(&sFontSizeInflationEmPerLine,
"font.size.inflation.emPerLine");
Preferences::AddUintVarCache(&sFontSizeInflationMinTwips,
@ -5017,8 +5020,10 @@ nsLayoutUtils::FontSizeInflationInner(const nsIFrame *aFrame,
}
int32_t interceptParam = nsLayoutUtils::FontSizeInflationMappingIntercept();
float maxRatio = (float)nsLayoutUtils::FontSizeInflationMaxRatio() / 100.0f;
float ratio = float(styleFontSize) / float(aMinFontSize);
float inflationRatio;
// Given a minimum inflated font size m, a specified font size s, we want to
// find the inflated font size i and then return the ratio of i to s (i/s).
@ -5041,12 +5046,18 @@ nsLayoutUtils::FontSizeInflationInner(const nsIFrame *aFrame,
// graph is a line from (0, m), to that point). We calculate the
// intersection point to be ((1+P/2)m, (1+P/2)m), where P is the
// intercept parameter above. We then need to return i/s.
return (1.0f + (ratio * (intercept - 1) / intercept)) / ratio;
inflationRatio = (1.0f + (ratio * (intercept - 1) / intercept)) / ratio;
} else {
// This is the case where P is negative. We essentially want to implement
// the case for P=infinity here, so we make i = s + m, which means that
// i/s = s/s + m/s = 1 + 1/ratio
return 1 + 1.0f / ratio;
inflationRatio = 1 + 1.0f / ratio;
}
if (maxRatio > 1.0 && inflationRatio > maxRatio) {
return maxRatio;
} else {
return inflationRatio;
}
}

View File

@ -1611,6 +1611,14 @@ public:
static bool FontSizeInflationEnabled(nsPresContext *aPresContext);
/**
* See comment above "font.size.inflation.maxRatio" in
* modules/libpref/src/init/all.js .
*/
static uint32_t FontSizeInflationMaxRatio() {
return sFontSizeInflationMaxRatio;
}
/**
* See comment above "font.size.inflation.emPerLine" in
* modules/libpref/src/init/all.js .
@ -1751,7 +1759,8 @@ private:
static uint32_t sFontSizeInflationEmPerLine;
static uint32_t sFontSizeInflationMinTwips;
static uint32_t sFontSizeInflationLineThreshold;
static int32_t sFontSizeInflationMappingIntercept;
static int32_t sFontSizeInflationMappingIntercept;
static uint32_t sFontSizeInflationMaxRatio;
};
template<typename PointType, typename RectType, typename CoordType>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<style>
div { background: yellow }
div { font-size: 24px; width: 450px }
</style>
<!--
In a 450px container, the minimum font size at 15em per line is 30px.
This means we map 0px-45px into 30px-45px, so 12px gets mapped to 34px.
However, because we've enabled the maxRatio at a value of 2.0, the mapping
function, which would normally return 34px/12px, or about 2.83, now
returns a ratio capped at 2.0, thus the actual font size is 24px.
-->
<div>Hello world</div>

View File

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<style>
div { background: yellow }
div { font-size: 12px; width: 450px }
</style>
<!--
In a 450px container, the minimum font size at 15em per line is 30px.
This means we map 0px-45px into 30px-45px, so 12px gets mapped to 34px.
However, because we've enabled the maxRatio at a value of 2.0, the mapping
function, which would normally return 34px/12px, or about 2.83, now
returns a ratio capped at 2.0, thus the actual font size is 24px.
-->
<div>Hello world</div>

View File

@ -5,6 +5,7 @@
# with the lineThreshold preference explicitly set to zero. However,
# newer tests should probably focus more on testing nonzero values of
# that preference.
test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) test-pref(font.size.inflation.maxRatio,200) == maxRatio-1.html maxRatio-1-ref.html
test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == text-1.html text-1-ref.html
test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == text-2.html text-2-ref.html
test-pref(font.size.inflation.emPerLine,15) test-pref(font.size.inflation.lineThreshold,0) == text-3.html text-3-ref.html

View File

@ -1816,6 +1816,19 @@ pref("font.size.inflation.lineThreshold", 400);
*/
pref("font.size.inflation.mappingIntercept", 1);
/*
* This controls the percentage that fonts will be inflated, if font
* size inflation is enabled. Essentially, if we have a specified font
* size, s, and an inflated font size, i, this specifies that the ratio
* i/s * 100 should never exceed the value of this preference.
*
* In order for this preference to have any effect, its value must be
* greater than 100, since font inflation can never decrease the ratio
* i/s.
*/
pref("font.size.inflation.maxRatio", 0);
/*
* When enabled, the touch.radius and mouse.radius prefs allow events to be dispatched
* to nearby elements that are sensitive to the event. See PositionedEventTargeting.cpp.