diff --git a/lib/checks/label/label-content-name-mismatch.js b/lib/checks/label/label-content-name-mismatch.js index 50c6ea9605..230b95dd4f 100644 --- a/lib/checks/label/label-content-name-mismatch.js +++ b/lib/checks/label/label-content-name-mismatch.js @@ -1,5 +1,5 @@ const { text } = axe.commons; -const { pixelThreshold, occuranceThreshold } = options || {}; +const { differenceThreshold, occuranceThreshold } = options || {}; const accText = text.accessibleText(node).toLowerCase(); if (text.isHumanInterpretable(accText) < 1) { @@ -10,7 +10,7 @@ const textVNodes = text.visibleTextNodes(virtualNode); const nonLigatureText = textVNodes .filter( textVNode => - !text.isIconLigature(textVNode, pixelThreshold, occuranceThreshold) + !text.isIconLigature(textVNode, differenceThreshold, occuranceThreshold) ) .map(textVNode => textVNode.actualNode.nodeValue) .join(''); diff --git a/lib/checks/label/label-content-name-mismatch.json b/lib/checks/label/label-content-name-mismatch.json index a8da4c1a26..27cd238e88 100644 --- a/lib/checks/label/label-content-name-mismatch.json +++ b/lib/checks/label/label-content-name-mismatch.json @@ -2,7 +2,7 @@ "id": "label-content-name-mismatch", "evaluate": "label-content-name-mismatch.js", "options": { - "pixelThreshold": 0.1, + "differenceThreshold": 0.15, "occuranceThreshold": 3 }, "metadata": { diff --git a/lib/commons/text/is-icon-ligature.js b/lib/commons/text/is-icon-ligature.js index 772574f50c..030737acc9 100644 --- a/lib/commons/text/is-icon-ligature.js +++ b/lib/commons/text/is-icon-ligature.js @@ -159,9 +159,7 @@ text.isIconLigature = function( context.textAlign = 'left'; context.textBaseline = 'top'; context.fillText(firstChar, 0, 0); - const compareData = new Uint32Array( - context.getImageData(0, 0, width, fontSize).data.buffer - ); + const compareData = context.getImageData(0, 0, width, fontSize).data; // if the font doesn't even have character data for a single char then // it has to be an icon ligature (e.g. Material Icon) @@ -172,21 +170,25 @@ text.isIconLigature = function( context.clearRect(0, 0, width, fontSize); context.fillText(nodeValue, 0, 0); - const compareWith = new Uint32Array( - context.getImageData(0, 0, width, fontSize).data.buffer - ); + const compareWith = context.getImageData(0, 0, width, fontSize).data; // calculate the number of differences between the first letter and the - // entire string, ignoring color differences - const differences = compareData.reduce((diff, pixel, i) => { - if (pixel === 0 && compareWith[i] === 0) { - return diff; + // entire string + let differences = 0; + const size = compareWith.length / 4; + for (let i = 0; i < compareWith.length; i += 4) { + // ignore color differences, only deal with pixel placement differences + let compareDataHasPixel = false; + let compareWithHasPixel = false; + for (let j = 0; j < 4; j++) { + compareDataHasPixel = compareDataHasPixel || !!compareData[i + j]; + compareWithHasPixel = compareWithHasPixel || !!compareWith[i + j]; } - if (pixel !== 0 && compareWith[i] !== 0) { - return diff; + + if (compareDataHasPixel !== compareWithHasPixel) { + differences++; } - return ++diff; - }, 0); + } // calculate the difference between the width of each character and the // combined with of all characters @@ -195,7 +197,7 @@ text.isIconLigature = function( }, 0); const actualWidth = context.measureText(nodeValue).width; - const pixelDifference = differences / compareData.length; + const pixelDifference = differences / size; const sizeDifference = 1 - actualWidth / expectedWidth; if ( diff --git a/lib/core/imports/index.js b/lib/core/imports/index.js index 1eb9d0440b..05575cb64b 100644 --- a/lib/core/imports/index.js +++ b/lib/core/imports/index.js @@ -14,10 +14,6 @@ if (!('Promise' in window)) { require('es6-promise').polyfill(); } -if (!('Uint32Array' in window)) { - require('core-js/features/typed-array/uint32-array'); -} - /** * Polyfill `WeakMap` * Reference: https://github.com/polygonplanet/weakmap-polyfill diff --git a/package.json b/package.json index 11007453f2..f8d76030e6 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,6 @@ "browserify": "^16.2.3", "chai": "~4.2.0", "clone": "~2.1.1", - "core-js": "^3.2.1", "css-selector-parser": "^1.3.0", "derequire": "^2.0.6", "emoji-regex": "8.0.0",