Commit 94ccfef1 authored by fs's avatar fs Committed by Commit bot

Ignore minimum font-size for SVG text

In some circumstances, the minimum font-size would be applied to the
"scaled font", messing up rendering. Because of how the font is scaled,
this would trigger much less than one might expect.
Change the useSmartMinimumForFontSize argument to the
FontSize::getComputedSizeFromSpecifiedSize function to be about entirely
ignoring the minimum font-sizes (this function only has two callsites.)
Refactor LayoutSVGInlineText::computeNewScaledFontForStyle a bit to deal
with this new flow. Also always keep the "original" font when we compute
a scale factor of 0 - it should be invisible regardless.

BUG=232332,335725,475795,626936,664961
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2

Review-Url: https://codereview.chromium.org/2575863002
Cr-Commit-Position: refs/heads/master@{#438794}
parent 62073c7a
<!DOCTYPE html>
<div style="width: 100px; height: 100px; background-color: green"></div>
<!DOCTYPE html>
<script src="../../resources/ahem.js"></script>
<script>
internals.settings.setMinimumFontSize(50);
</script>
<svg height="100" font-size="1" font-family="Ahem">
<rect width="100" height="100" fill="green"/>
<text y="101" fill="red">X</text>
<text y="101" fill="red" x="50" text-rendering="geometricPrecision">Y</text>
</svg>
......@@ -41,7 +41,7 @@ float FontSize::getComputedSizeFromSpecifiedSize(
float zoomFactor,
bool isAbsoluteSize,
float specifiedSize,
ESmartMinimumForFontSize useSmartMinimumForFontSize) {
ApplyMinimumFontSize applyMinimumFontSize) {
// Text with a 0px font size should not be visible and therefore needs to be
// exempt from minimum font size rules. Acid3 relies on this for pixel-perfect
// rendering. This is also compatible with other browsers that have minimum
......@@ -65,9 +65,10 @@ float FontSize::getComputedSizeFromSpecifiedSize(
if (!settings)
return 1.0f;
float zoomedSize = specifiedSize * zoomFactor;
if (applyMinimumFontSize) {
int minSize = settings->minimumFontSize();
int minLogicalSize = settings->minimumLogicalFontSize();
float zoomedSize = specifiedSize * zoomFactor;
// Apply the hard minimum first. We only apply the hard minimum if after
// zooming we're still too small.
......@@ -75,14 +76,14 @@ float FontSize::getComputedSizeFromSpecifiedSize(
zoomedSize = minSize;
// Now apply the "smart minimum." This minimum is also only applied if we're
// still too small after zooming. The font size must either be relative to the
// user default or the original size must have been acceptable. In other
// still too small after zooming. The font size must either be relative to
// the user default or the original size must have been acceptable. In other
// words, we only apply the smart minimum whenever we're positive doing so
// won't disrupt the layout.
if (useSmartMinimumForFontSize && zoomedSize < minLogicalSize &&
if (zoomedSize < minLogicalSize &&
(specifiedSize >= minLogicalSize || !isAbsoluteSize))
zoomedSize = minLogicalSize;
}
// Also clamp to a reasonable maximum to prevent insane font sizes from
// causing crashes on various platforms (I'm looking at you, Windows.)
return std::min(maximumAllowedFontSize, zoomedSize);
......
......@@ -30,9 +30,9 @@ namespace blink {
class Document;
enum ESmartMinimumForFontSize {
DoNotUseSmartMinimumForFontSize,
UseSmartMinimumForFontSize
enum ApplyMinimumFontSize {
DoNotApplyMinimumForFontSize,
ApplyMinimumForFontSize
};
class FontSize {
......@@ -44,7 +44,7 @@ class FontSize {
float zoomFactor,
bool isAbsoluteSize,
float specifiedSize,
ESmartMinimumForFontSize = UseSmartMinimumForFontSize);
ApplyMinimumFontSize = ApplyMinimumForFontSize);
// Given a CSS keyword in the range (xx-small to -webkit-xxx-large), this
// function returns
......
......@@ -367,38 +367,40 @@ void LayoutSVGInlineText::updateMetricsList(bool& lastCharacterWasWhiteSpace) {
}
void LayoutSVGInlineText::updateScaledFont() {
computeNewScaledFontForStyle(this, m_scalingFactor, m_scaledFont);
computeNewScaledFontForStyle(*this, m_scalingFactor, m_scaledFont);
}
void LayoutSVGInlineText::computeNewScaledFontForStyle(
LayoutObject* layoutObject,
const LayoutObject& layoutObject,
float& scalingFactor,
Font& scaledFont) {
const ComputedStyle* style = layoutObject->style();
ASSERT(style);
ASSERT(layoutObject);
const ComputedStyle& style = layoutObject.styleRef();
// Alter font-size to the right on-screen value to avoid scaling the glyphs
// themselves, except when GeometricPrecision is specified.
scalingFactor =
SVGLayoutSupport::calculateScreenFontSizeScalingFactor(layoutObject);
if (style->effectiveZoom() == 1 && (scalingFactor == 1 || !scalingFactor)) {
SVGLayoutSupport::calculateScreenFontSizeScalingFactor(&layoutObject);
if (!scalingFactor) {
scalingFactor = 1;
scaledFont = style->font();
scaledFont = style.font();
return;
}
if (style->getFontDescription().textRendering() == GeometricPrecision)
const FontDescription& unscaledFontDescription = style.getFontDescription();
if (unscaledFontDescription.textRendering() == GeometricPrecision)
scalingFactor = 1;
FontDescription fontDescription(style->getFontDescription());
Document& document = layoutObject.document();
float scaledFontSize = FontSize::getComputedSizeFromSpecifiedSize(
&document, scalingFactor, unscaledFontDescription.isAbsoluteSize(),
unscaledFontDescription.specifiedSize(), DoNotApplyMinimumForFontSize);
if (scaledFontSize == unscaledFontDescription.computedSize()) {
scaledFont = style.font();
return;
}
Document& document = layoutObject->document();
// FIXME: We need to better handle the case when we compute very small fonts
// below (below 1pt).
fontDescription.setComputedSize(FontSize::getComputedSizeFromSpecifiedSize(
&document, scalingFactor, fontDescription.isAbsoluteSize(),
fontDescription.specifiedSize(), DoNotUseSmartMinimumForFontSize));
FontDescription fontDescription = unscaledFontDescription;
fontDescription.setComputedSize(scaledFontSize);
scaledFont = Font(fontDescription);
scaledFont.update(document.styleEngine().fontSelector());
......
......@@ -45,7 +45,7 @@ class LayoutSVGInlineText final : public LayoutText {
const Font& scaledFont() const { return m_scaledFont; }
void updateScaledFont();
void updateMetricsList(bool& lastCharacterWasWhiteSpace);
static void computeNewScaledFontForStyle(LayoutObject*,
static void computeNewScaledFontForStyle(const LayoutObject&,
float& scalingFactor,
Font& scaledFont);
......
......@@ -322,7 +322,7 @@ void SVGInlineTextBoxPainter::paintDecoration(const PaintInfo& paintInfo,
float scalingFactor = 1;
Font scaledFont;
LayoutSVGInlineText::computeNewScaledFontForStyle(decorationLayoutObject,
LayoutSVGInlineText::computeNewScaledFontForStyle(*decorationLayoutObject,
scalingFactor, scaledFont);
DCHECK(scalingFactor);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment