Bug 1348267 - used display density pixel ratio to scale the font size; r=pbro

Added also a `getDisplayPixelRatio` method, since we're probably going to use it
more often, instead of doing this math all the time in the code, it will be more
clear.

MozReview-Commit-ID: HLtbwDBvbF6

--HG--
extra : rebase_source : aca60ea8c57e175c2cca5ff7ed478796c5b6c53f
This commit is contained in:
Matteo Ferretti 2017-03-17 12:07:11 +01:00
Родитель c486e7014c
Коммит ddc362186a
2 изменённых файлов: 29 добавлений и 6 удалений

Просмотреть файл

@ -15,6 +15,7 @@ const {
} = require("./utils/markup");
const {
getCurrentZoom,
getDisplayPixelRatio,
setIgnoreLayoutChanges,
getWindowDimensions,
getMaxSurfaceSize,
@ -28,6 +29,9 @@ const DEFAULT_GRID_COLOR = "#4B0082";
const COLUMNS = "cols";
const ROWS = "rows";
const GRID_FONT_SIZE = 10;
const GRID_FONT_FAMILY = "sans-serif";
const GRID_LINES_PROPERTIES = {
"edge": {
lineDash: [0, 0],
@ -879,19 +883,21 @@ CssGridHighlighter.prototype = extend(AutoRefreshHighlighter.prototype, {
* The grid dimension type which is either the constant COLUMNS or ROWS.
*/
renderGridLineNumber(lineNumber, linePos, startPos, dimensionType) {
let ratio = this.win.devicePixelRatio;
let devicePixelRatio = this.win.devicePixelRatio;
let displayPixelRatio = getDisplayPixelRatio(this.win);
linePos = Math.round(linePos * ratio);
startPos = Math.round(startPos * ratio);
linePos = Math.round(linePos * devicePixelRatio);
startPos = Math.round(startPos * devicePixelRatio);
this.ctx.save();
let fontSize = (GRID_FONT_SIZE * displayPixelRatio);
this.ctx.font = fontSize + "px " + GRID_FONT_FAMILY;
let textWidth = this.ctx.measureText(lineNumber).width;
// Guess the font height based on the measured width
let textHeight = textWidth * 2;
if (dimensionType === COLUMNS) {
let yPos = Math.max(startPos, textHeight);
let yPos = Math.max(startPos, fontSize);
this.ctx.fillText(lineNumber, linePos, yPos);
} else {
let xPos = Math.max(startPos, textWidth);

Просмотреть файл

@ -632,6 +632,23 @@ function getCurrentZoom(node) {
}
exports.getCurrentZoom = getCurrentZoom;
/**
* Get the display pixel ratio for a given window.
* The `devicePixelRatio` property is affected by the zoom (see bug 809788), so we have to
* divide by the zoom value in order to get just the display density, expressed as pixel
* ratio (the physical display pixel compares to a pixel on a normal density screen).
*
* @param {DOMNode|DOMWindow}
* The node for which the zoom factor should be calculated, or its
* owner window.
* @return {Number}
*/
function getDisplayPixelRatio(node) {
let win = getWindowFor(node);
return win.devicePixelRatio / utilsFor(win).fullZoom;
}
exports.getDisplayPixelRatio = getDisplayPixelRatio;
/**
* Returns the window's dimensions for the `window` given.
*