Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Unified Diff: third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html

Issue 1505713002: Include glyph overflow in SVG text bounding boxes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More expectations Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html
diff --git a/third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html b/third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html
index f05043d0d2082748b24a5799c688aab6eed4b2d8..ea8a29ba2f892c0b3ccdbf95eb7034fea69c0739 100644
--- a/third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html
+++ b/third_party/WebKit/LayoutTests/svg/text/text-rect-precision.html
@@ -12,17 +12,6 @@
</g>
</svg>
<script>
-
- var hasSubpixelPrecision = false;
-
- function subpixelTolerance(testElement)
- {
- // Due to fixed-point rounding, each single-character measurement may differ by up to
- // one LayoutUnit (i.e., 0.16 pixel) from the same character's measurement in the full
- // string.
- var str = testElement.firstChild.nodeValue;
- return str.length * 0.16;
- }
function measureText(testElement)
{
@@ -39,7 +28,6 @@
measureElement.firstChild.nodeValue = c;
w = measureElement.getBoundingClientRect().width;
characterWidths[c] = w;
- hasSubpixelPrecision = hasSubpixelPrecision || w.toFixed(2) != Math.round(w);
}
width += w;
}
@@ -49,11 +37,20 @@
var el = document.getElementById('test');
var elementWidth = el.getBoundingClientRect().width;
var textWidth = measureText(el);
- var tolerance = hasSubpixelPrecision ? subpixelTolerance(el) : 2; // enclosing may expand up to one pixel in each direction.
- if (Math.abs(elementWidth - textWidth) <= tolerance)
- testPassed('Width of text element is the sum of the width of all characters.');
- else
- testFailed('Width of text element is ' + elementWidth + ', expected ' + textWidth);
+ // This tolerance value is made up but our goal is to ensure that the
+ // sum of individual glyph widths is roughly similar to the total element
+ // width.
+ var glyphOverflowTolerance = Math.min(elementWidth, textWidth) / 2;
+ if (elementWidth > textWidth) {
+ // The sum of individual character widths will include the glyph
+ // overflow of each character separately and therefore the total element
+ // width should be smaller.
+ testFailed('Width of text element is ' + elementWidth + ', expected the sum of individual character widths, ' + textWidth + ', to be larger.');
+ } else if (Math.abs(elementWidth - textWidth) > glyphOverflowTolerance) {
+ testFailed('Width of text element is ' + elementWidth + ', expected the sum of individal character widths, ' + textWidth + ', to be similar.');
+ } else {
+ testPassed('Width of text element is similar to the sum of the width of all characters.');
+ }
</script>
</body>
</html>

Powered by Google App Engine
This is Rietveld 408576698