| 105778 | this.middle = Math.round(size / 2 * (navigator.userAgent.indexOf("Gecko/") >= 0 ? 1.2 : 1)); |
| 105779 | } |
| 105780 | function prepareGrids(imgData, width, height, glyphWidth, glyphHeight, gridOuter, gridInner) { |
| 105781 | // Initialize grids outside the glyph range to alpha 0 |
| 105782 | gridOuter.fill(INF, 0, width * height); |
| 105783 | gridInner.fill(0, 0, width * height); |
| 105784 | var offset = (width - glyphWidth) / 2; // This is zero if we're not extracting metrics |
| 105785 | for(var y = 0; y < glyphHeight; y++)for(var x = 0; x < glyphWidth; x++){ |
| 105786 | var j = (y + offset) * width + x + offset; |
| 105787 | var a = imgData.data[4 * (y * glyphWidth + x) + 3] / 255; // alpha value |
| 105788 | if (a === 1) { |
| 105789 | gridOuter[j] = 0; |
| 105790 | gridInner[j] = INF; |
| 105791 | } else if (a === 0) { |
| 105792 | gridOuter[j] = INF; |
| 105793 | gridInner[j] = 0; |
| 105794 | } else { |
| 105795 | var b = Math.max(0, 0.5 - a); |
| 105796 | var c = Math.max(0, a - 0.5); |
| 105797 | gridOuter[j] = b * b; |
| 105798 | gridInner[j] = c * c; |
| 105799 | } |
| 105800 | } |
| 105801 | } |
| 105802 | function extractAlpha(alphaChannel, width, height, gridOuter, gridInner, radius, cutoff) { |
| 105803 | for(var i = 0; i < width * height; i++){ |
| 105804 | var d = Math.sqrt(gridOuter[i]) - Math.sqrt(gridInner[i]); |