From e2ecfdda8c06f6b366dac7744a0319909065ca8d Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Mon, 15 Oct 2012 14:03:37 -0500 Subject: [PATCH] Bug 784375: Add a preference to control maximum font size inflation ratio. [r=dbaron] --- layout/base/nsLayoutUtils.cpp | 17 ++++++++++++++--- layout/base/nsLayoutUtils.h | 11 ++++++++++- .../reftests/font-inflation/maxRatio-1-ref.html | 13 +++++++++++++ layout/reftests/font-inflation/maxRatio-1.html | 13 +++++++++++++ layout/reftests/font-inflation/reftest.list | 1 + modules/libpref/src/init/all.js | 13 +++++++++++++ 6 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 layout/reftests/font-inflation/maxRatio-1-ref.html create mode 100644 layout/reftests/font-inflation/maxRatio-1.html diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 9e203523788..98297728689 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -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; } } diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index c789d968887..f59512a7b67 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -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 diff --git a/layout/reftests/font-inflation/maxRatio-1-ref.html b/layout/reftests/font-inflation/maxRatio-1-ref.html new file mode 100644 index 00000000000..dce6c6d8e38 --- /dev/null +++ b/layout/reftests/font-inflation/maxRatio-1-ref.html @@ -0,0 +1,13 @@ + + + +
Hello world
diff --git a/layout/reftests/font-inflation/maxRatio-1.html b/layout/reftests/font-inflation/maxRatio-1.html new file mode 100644 index 00000000000..0cbc120ae9f --- /dev/null +++ b/layout/reftests/font-inflation/maxRatio-1.html @@ -0,0 +1,13 @@ + + + +
Hello world
diff --git a/layout/reftests/font-inflation/reftest.list b/layout/reftests/font-inflation/reftest.list index 112a95e3f64..1e16aed3780 100644 --- a/layout/reftests/font-inflation/reftest.list +++ b/layout/reftests/font-inflation/reftest.list @@ -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 diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 86b2015ab80..bc481862d02 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -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.