Skip to content
Snippets Groups Projects
Verified Commit 6bdafd8f authored by Igor Oliveira's avatar Igor Oliveira Committed by Pier Angelo Vendrame
Browse files

Bug 23104: Add a default line height compensation

Many fonts have issues with their vertical metrics. they
are used to influence the height of ascenders and depth
of descenders. Gecko uses it to calculate the line height
(font height + ascender + descender), however because of
that idiosyncratic behavior across multiple operating
systems, it can be used to identify the user's OS.

The solution proposed in the patch uses a default factor
to be multiplied with the font size, simulating the concept
of ascender and descender. This way all operating
systems will have the same line height.
parent 187cf170
No related branches found
No related tags found
1 merge request!641Bug 41759: Rebase Base Browser to 115 Nightly
......@@ -34,6 +34,7 @@
#include "nsTableCellFrame.h"
#include "nsTableFrame.h"
#include "StickyScrollContainer.h"
#include "nsContentUtils.h"
using namespace mozilla;
using namespace mozilla::css;
......@@ -2732,7 +2733,8 @@ static nscoord GetNormalLineHeight(nsFontMetrics* aFontMetrics) {
nscoord externalLeading = aFontMetrics->ExternalLeading();
nscoord internalLeading = aFontMetrics->InternalLeading();
nscoord emHeight = aFontMetrics->EmHeight();
if (!internalLeading && !externalLeading) {
if ((!internalLeading && !externalLeading) ||
nsContentUtils::ShouldResistFingerprinting()) {
return NSToCoordRound(emHeight * kNormalLineHeightFactor);
}
return emHeight + internalLeading + externalLeading;
......
......@@ -164,3 +164,4 @@ support-files =
[test_scroll_on_display_contents.html]
support-files = !/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js
[test_bug1803209.html]
[test_tor_bug23104.html]
<!DOCTYPE HTML>
<meta charset="UTF-8">
<html>
<head>
<title>Test for Tor Bug #23104: CSS line-height reveals the platform Tor browser is running</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<style type="text/css">
span {
background-color: #000;
color: #fff;
font-size: 16.5px;
}
</style>
</head>
<body>
<span id="test1">Test1</span>
<span id="test2">كلمة</span>
<span id="test3">ação</span>
<script>
let setPref = async function (key, value) {
await SpecialPowers.pushPrefEnv({"set": [[key, value]]});
}
function getStyle(el, styleprop) {
el = document.getElementById(el);
return document.defaultView.getComputedStyle(el, null).getPropertyValue(styleprop);
}
function validateElement(elementName, isFingerprintResistent) {
var fontSize = getStyle(elementName, 'font-size');
var lineHeight = getStyle(elementName, 'line-height');
var validationCb = isFingerprintResistent ? is : isnot;
validationCb(parseFloat(lineHeight), Math.round(parseFloat(fontSize)) * 1.2, 'Line Height validation');
}
add_task(async function() {
await setPref("layout.css.line-height.normal-as-resolved-value.enabled", false);
for (let resistFingerprintingValue of [true, false]) {
await setPref("privacy.resistFingerprinting", resistFingerprintingValue);
for (let elementId of ['test1', 'test2', 'test3']) {
validateElement(elementId, resistFingerprintingValue);
}
}
});
</script>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment