Fix font comparison, less context.font operations

This commit is contained in:
ahocevar
2019-07-04 16:06:13 +02:00
parent 621a573dd8
commit b4306da7bb
2 changed files with 8 additions and 3 deletions

View File

@@ -80,7 +80,7 @@
"loglevelnext": "^3.0.1", "loglevelnext": "^3.0.1",
"marked": "0.6.3", "marked": "0.6.3",
"mocha": "6.1.4", "mocha": "6.1.4",
"ol-mapbox-style": "^5.0.0-beta.2", "ol-mapbox-style": "^5.0.0-beta.3",
"pixelmatch": "^5.0.0", "pixelmatch": "^5.0.0",
"pngjs": "^3.4.0", "pngjs": "^3.4.0",
"proj4": "2.5.0", "proj4": "2.5.0",

View File

@@ -180,6 +180,10 @@ export const checkedFonts = {};
*/ */
let measureContext = null; let measureContext = null;
/**
* @type {string}
*/
let measureFont;
/** /**
* @type {!Object<string, number>} * @type {!Object<string, number>}
@@ -238,6 +242,7 @@ export const checkFont = (function() {
clear(textHeights); clear(textHeights);
// Make sure that loaded fonts are picked up by Safari // Make sure that loaded fonts are picked up by Safari
measureContext = null; measureContext = null;
measureFont = undefined;
labelCache.clear(); labelCache.clear();
} else { } else {
++checked[font]; ++checked[font];
@@ -317,8 +322,8 @@ export const measureTextHeight = (function() {
*/ */
export function measureTextWidth(font, text) { export function measureTextWidth(font, text) {
const measureContext = getMeasureContext(); const measureContext = getMeasureContext();
if (font != measureContext.font) { if (font != measureFont) {
measureContext.font = font; measureContext.font = measureFont = font;
} }
return measureContext.measureText(text).width; return measureContext.measureText(text).width;
} }