High res rulers (#478)

This commit is contained in:
Mark MacKay
2021-01-30 03:02:48 -06:00
committed by GitHub
parent 35e6de97ef
commit 7c9e9d26d6

View File

@@ -1798,6 +1798,7 @@ editor.init = () => {
const isX = (d === 0); const isX = (d === 0);
const dim = isX ? 'x' : 'y'; const dim = isX ? 'x' : 'y';
const lentype = isX ? 'width' : 'height'; const lentype = isX ? 'width' : 'height';
const narrowtype = isX ? 'height' : 'width';
const contentDim = Number(contentElem.getAttribute(dim)); const contentDim = Number(contentElem.getAttribute(dim));
const $hcanvOrig = $('#ruler_' + dim + ' canvas:first'); const $hcanvOrig = $('#ruler_' + dim + ' canvas:first');
@@ -1808,13 +1809,22 @@ editor.init = () => {
const hcanv = $hcanv[0]; const hcanv = $hcanv[0];
// $canvas.height() or $canvas.width()
const narrowDim = $hcanv[narrowtype]();
// Set the canvas size to the width of the container // Set the canvas size to the width of the container
const scale = window.devicePixelRatio || 1;
let rulerLen = scanvas[lentype](); let rulerLen = scanvas[lentype]();
const totalLen = rulerLen; const totalLen = rulerLen;
hcanv.parentNode.style[lentype] = totalLen + 'px'; hcanv.parentNode.style[lentype] = rulerLen + 'px';
hcanv.width = totalLen;
let ctx = hcanv.getContext('2d'); let ctx = hcanv.getContext('2d');
let ctxArr, num, ctxArrNum; let ctxArr, num, ctxArrNum;
ctx.scale(scale, scale);
hcanv.style[lentype] = totalLen + 'px';
hcanv.style[narrowtype] = narrowDim + 'px';
hcanv[lentype] = totalLen * scale;
hcanv[narrowtype] = narrowDim * scale;
ctx.fillStyle = 'rgb(200,0,0)'; ctx.fillStyle = 'rgb(200,0,0)';
ctx.fillRect(0, 0, hcanv.width, hcanv.height); ctx.fillRect(0, 0, hcanv.width, hcanv.height);
@@ -1828,7 +1838,7 @@ editor.init = () => {
ctxArr[0] = ctx; ctxArr[0] = ctx;
let copy; let copy;
for (i = 1; i < ctxArrNum; i++) { for (i = 1; i < ctxArrNum; i++) {
hcanv[lentype] = limit; hcanv[lentype] = limit * scale;
copy = hcanv.cloneNode(true); copy = hcanv.cloneNode(true);
hcanv.parentNode.append(copy); hcanv.parentNode.append(copy);
ctxArr[i] = copy.getContext('2d'); ctxArr[i] = copy.getContext('2d');
@@ -1840,7 +1850,7 @@ editor.init = () => {
rulerLen = limit; rulerLen = limit;
} }
hcanv[lentype] = rulerLen; hcanv[lentype] = rulerLen * scale;
const uMulti = unit * zoom; const uMulti = unit * zoom;
@@ -1858,6 +1868,7 @@ editor.init = () => {
const bigInt = multi * uMulti; const bigInt = multi * uMulti;
ctx.font = '9px sans-serif'; ctx.font = '9px sans-serif';
ctx.scale(scale, scale);
let rulerD = ((contentDim / uMulti) % multi) * uMulti; let rulerD = ((contentDim / uMulti) % multi) * uMulti;
let labelPos = rulerD - bigInt; let labelPos = rulerD - bigInt;