Created
May 8, 2015 09:34
-
-
Save kfitfk/00f15658a6489b5cdda6 to your computer and use it in GitHub Desktop.
Generate the unicodeRanges property for Flex font embed
This file contains hidden or 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
function flexEmbedCharUnicode(charCode) { | |
var leadingZeros = ''; | |
for (var i = 0; i < 4 - charCode.length; i++) { | |
leadingZeros += '0'; | |
} | |
return 'U+' + leadingZeros + charCode; | |
} | |
function flexEmbedUnicodeRanges(string) { | |
var unicodeRange = [] | |
var temp = ''; | |
for (var i = 0; i < string.length; i++) { | |
temp = flexEmbedCharUnicode(string.charCodeAt(i).toString(16)); | |
if (unicodeRange.indexOf(temp) === -1) { | |
unicodeRange.push(temp); | |
} | |
} | |
return unicodeRange.join(','); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment