@@ -82,14 +82,14 @@ text.isIconLigature = function(
82
82
return false ;
83
83
}
84
84
85
- if ( ! axe . _cache . get ( 'context ' ) ) {
85
+ if ( ! axe . _cache . get ( 'canvasContext ' ) ) {
86
86
axe . _cache . set (
87
- 'context ' ,
87
+ 'canvasContext ' ,
88
88
document . createElement ( 'canvas' ) . getContext ( '2d' )
89
89
) ;
90
90
}
91
- const context = axe . _cache . get ( 'context ' ) ;
92
- const canvas = context . canvas ;
91
+ const canvasContext = axe . _cache . get ( 'canvasContext ' ) ;
92
+ const canvas = canvasContext . canvas ;
93
93
94
94
// keep track of each font encountered and the number of times it shows up
95
95
// as a ligature.
@@ -138,9 +138,9 @@ text.isIconLigature = function(
138
138
let fontStyle = `${ fontSize } px ${ fontFamily } ` ;
139
139
140
140
// set the size of the canvas to the width of the first letter
141
- context . font = fontStyle ;
141
+ canvasContext . font = fontStyle ;
142
142
const firstChar = nodeValue . charAt ( 0 ) ;
143
- let width = context . measureText ( firstChar ) . width ;
143
+ let width = canvasContext . measureText ( firstChar ) . width ;
144
144
145
145
// ensure font meets the 30px width requirement (30px font-size doesn't
146
146
// necessarily mean its 30px wide when drawn)
@@ -155,12 +155,12 @@ text.isIconLigature = function(
155
155
156
156
// changing the dimensions of a canvas resets all properties (include font)
157
157
// and clears it
158
- context . font = fontStyle ;
159
- context . textAlign = 'left' ;
160
- context . textBaseline = 'top' ;
161
- context . fillText ( firstChar , 0 , 0 ) ;
158
+ canvasContext . font = fontStyle ;
159
+ canvasContext . textAlign = 'left' ;
160
+ canvasContext . textBaseline = 'top' ;
161
+ canvasContext . fillText ( firstChar , 0 , 0 ) ;
162
162
const compareData = new Uint32Array (
163
- context . getImageData ( 0 , 0 , width , fontSize ) . data . buffer
163
+ canvasContext . getImageData ( 0 , 0 , width , fontSize ) . data . buffer
164
164
) ;
165
165
166
166
// if the font doesn't even have character data for a single char then
@@ -170,10 +170,10 @@ text.isIconLigature = function(
170
170
return true ;
171
171
}
172
172
173
- context . clearRect ( 0 , 0 , width , fontSize ) ;
174
- context . fillText ( nodeValue , 0 , 0 ) ;
173
+ canvasContext . clearRect ( 0 , 0 , width , fontSize ) ;
174
+ canvasContext . fillText ( nodeValue , 0 , 0 ) ;
175
175
const compareWith = new Uint32Array (
176
- context . getImageData ( 0 , 0 , width , fontSize ) . data . buffer
176
+ canvasContext . getImageData ( 0 , 0 , width , fontSize ) . data . buffer
177
177
) ;
178
178
179
179
// calculate the number of differences between the first letter and the
@@ -191,9 +191,9 @@ text.isIconLigature = function(
191
191
// calculate the difference between the width of each character and the
192
192
// combined with of all characters
193
193
const expectedWidth = nodeValue . split ( '' ) . reduce ( ( width , char ) => {
194
- return width + context . measureText ( char ) . width ;
194
+ return width + canvasContext . measureText ( char ) . width ;
195
195
} , 0 ) ;
196
- const actualWidth = context . measureText ( nodeValue ) . width ;
196
+ const actualWidth = canvasContext . measureText ( nodeValue ) . width ;
197
197
198
198
const pixelDifference = differences / compareData . length ;
199
199
const sizeDifference = 1 - actualWidth / expectedWidth ;
0 commit comments