Skip to content

Instantly share code, notes, and snippets.

@kfitfk
Created May 8, 2015 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kfitfk/00f15658a6489b5cdda6 to your computer and use it in GitHub Desktop.
Save kfitfk/00f15658a6489b5cdda6 to your computer and use it in GitHub Desktop.
Generate the unicodeRanges property for Flex font embed
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