Define font as variable

This commit is contained in:
Andreas Hocevar
2017-11-03 13:05:50 +01:00
parent 5483fa3181
commit 72eb8ab5e8
+3 -2
View File
@@ -103,13 +103,14 @@ ol.render.canvas.checkedFonts_ = {};
ol.render.canvas.checkFont = (function() { ol.render.canvas.checkFont = (function() {
var checked = ol.render.canvas.checkedFonts_; var checked = ol.render.canvas.checkedFonts_;
var labelCache = ol.render.canvas.labelCache; var labelCache = ol.render.canvas.labelCache;
var font = '32px monospace';
var text = 'wmytzilWMYTZIL@#/&?$%10'; var text = 'wmytzilWMYTZIL@#/&?$%10';
var context, referenceWidth; var context, referenceWidth;
function isAvailable(fontFamily) { function isAvailable(fontFamily) {
if (!context) { if (!context) {
context = ol.dom.createCanvasContext2D(1, 1); context = ol.dom.createCanvasContext2D(1, 1);
context.font = '32px monospace'; context.font = font;
referenceWidth = context.measureText(text).width; referenceWidth = context.measureText(text).width;
} }
var available = true; var available = true;
@@ -123,7 +124,7 @@ ol.render.canvas.checkFont = (function() {
// Setting the font back to a different one works around an issue in // Setting the font back to a different one works around an issue in
// Safari where subsequent `context.font` assignments with the same font // Safari where subsequent `context.font` assignments with the same font
// will not re-attempt to use a font that is currently loading. // will not re-attempt to use a font that is currently loading.
context.font = '32px monospace'; context.font = font;
} }
return available; return available;
} }