mirror of
https://github.com/rileyjshaw/terra.git
synced 2024-11-21 04:54:23 +00:00
Fix #12: only set canvas context font t once
This commit is contained in:
parent
e6c6ce3a33
commit
3482efc8af
@ -2,7 +2,6 @@ var _ = require('./util.js');
|
|||||||
|
|
||||||
module.exports = function (canvas, grid, cellSize) {
|
module.exports = function (canvas, grid, cellSize) {
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
ctx.font = 'bold ' + cellSize + 'px Arial';
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
_.each(grid, function (column, x) {
|
_.each(grid, function (column, x) {
|
||||||
|
17
app/dom.js
17
app/dom.js
@ -5,16 +5,17 @@ var createCanvasElement = function (width, height, id, insertAfter) {
|
|||||||
// resolution, then displays it properly using styles
|
// resolution, then displays it properly using styles
|
||||||
function createHDCanvas (ratio) {
|
function createHDCanvas (ratio) {
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
|
var ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
// Creates a dummy canvas to test device's pixel ratio
|
// Creates a dummy canvas to test device's pixel ratio
|
||||||
ratio = (function () {
|
ratio = (function () {
|
||||||
var context = document.createElement('canvas').getContext('2d');
|
var ctx = document.createElement('canvas').getContext('2d');
|
||||||
var dpr = window.devicePixelRatio || 1;
|
var dpr = window.devicePixelRatio || 1;
|
||||||
var bsr = context.webkitBackingStorePixelRatio ||
|
var bsr = ctx.webkitBackingStorePixelRatio ||
|
||||||
context.mozBackingStorePixelRatio ||
|
ctx.mozBackingStorePixelRatio ||
|
||||||
context.msBackingStorePixelRatio ||
|
ctx.msBackingStorePixelRatio ||
|
||||||
context.oBackingStorePixelRatio ||
|
ctx.oBackingStorePixelRatio ||
|
||||||
context.backingStorePixelRatio || 1;
|
ctx.backingStorePixelRatio || 1;
|
||||||
return dpr / bsr;
|
return dpr / bsr;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -22,7 +23,9 @@ var createCanvasElement = function (width, height, id, insertAfter) {
|
|||||||
canvas.height = height * ratio;
|
canvas.height = height * ratio;
|
||||||
canvas.style.width = width + 'px';
|
canvas.style.width = width + 'px';
|
||||||
canvas.style.height = height + 'px';
|
canvas.style.height = height + 'px';
|
||||||
canvas.getContext('2d').setTransform(ratio, 0, 0, ratio, 0, 0);
|
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
||||||
|
ctx.font = 'bold ' + cellSize + 'px Arial';
|
||||||
|
|
||||||
if (id) canvas.id = id;
|
if (id) canvas.id = id;
|
||||||
|
|
||||||
return canvas;
|
return canvas;
|
||||||
|
18
dist/terra.js
vendored
18
dist/terra.js
vendored
@ -185,7 +185,6 @@ var _ = require('./util.js');
|
|||||||
|
|
||||||
module.exports = function (canvas, grid, cellSize) {
|
module.exports = function (canvas, grid, cellSize) {
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
ctx.font = 'bold ' + cellSize + 'px Arial';
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
_.each(grid, function (column, x) {
|
_.each(grid, function (column, x) {
|
||||||
@ -215,16 +214,17 @@ var createCanvasElement = function (width, height, id, insertAfter) {
|
|||||||
// resolution, then displays it properly using styles
|
// resolution, then displays it properly using styles
|
||||||
function createHDCanvas (ratio) {
|
function createHDCanvas (ratio) {
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
|
var ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
// Creates a dummy canvas to test device's pixel ratio
|
// Creates a dummy canvas to test device's pixel ratio
|
||||||
ratio = (function () {
|
ratio = (function () {
|
||||||
var context = document.createElement('canvas').getContext('2d');
|
var ctx = document.createElement('canvas').getContext('2d');
|
||||||
var dpr = window.devicePixelRatio || 1;
|
var dpr = window.devicePixelRatio || 1;
|
||||||
var bsr = context.webkitBackingStorePixelRatio ||
|
var bsr = ctx.webkitBackingStorePixelRatio ||
|
||||||
context.mozBackingStorePixelRatio ||
|
ctx.mozBackingStorePixelRatio ||
|
||||||
context.msBackingStorePixelRatio ||
|
ctx.msBackingStorePixelRatio ||
|
||||||
context.oBackingStorePixelRatio ||
|
ctx.oBackingStorePixelRatio ||
|
||||||
context.backingStorePixelRatio || 1;
|
ctx.backingStorePixelRatio || 1;
|
||||||
return dpr / bsr;
|
return dpr / bsr;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -232,7 +232,9 @@ var createCanvasElement = function (width, height, id, insertAfter) {
|
|||||||
canvas.height = height * ratio;
|
canvas.height = height * ratio;
|
||||||
canvas.style.width = width + 'px';
|
canvas.style.width = width + 'px';
|
||||||
canvas.style.height = height + 'px';
|
canvas.style.height = height + 'px';
|
||||||
canvas.getContext('2d').setTransform(ratio, 0, 0, ratio, 0, 0);
|
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
|
||||||
|
ctx.font = 'bold ' + cellSize + 'px Arial';
|
||||||
|
|
||||||
if (id) canvas.id = id;
|
if (id) canvas.id = id;
|
||||||
|
|
||||||
return canvas;
|
return canvas;
|
||||||
|
2
dist/terra.min.js
vendored
2
dist/terra.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user