Created
September 12, 2010 17:08
-
-
Save antimatter15/576244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//A somewhat conservative test for supporting characters. | |
//Actually, it's a test to see if the glyphs of two characters | |
//are identical. This tends to work, however, some implementations | |
//may instead replace the text with a box with the hex code | |
//and this wouldn't work in those cases. One way might be to detect | |
//the presence of a rectangular box, but that may cause issues with | |
//glyphs that are rectangluar boxes (eg. Mail symbol). | |
//Basically, it compares pixels of the character at num and num+1 | |
//if the glyphs are identical, it assumes its non-supported. | |
function supportsCharacter(num){ | |
function text(chrnum){ | |
//convert a character number into a ImageData.data array | |
var x = document.createElement('canvas').getContext('2d'); | |
x.fillText(String.fromCharCode(chrnum),2,8); | |
return x.getImageData(0, 0, 11, 12).data; | |
} | |
var x = text(num), y = text(num+1); | |
for(var i = x.length; x[i] == y[i] && i--;); //loop while pixels are equal or reached end. | |
return i != -1 //if it reached the end, then the characters are the same | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment