unicode-range.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*!
  2. {
  3. "name": "Unicode Range",
  4. "property": "unicoderange",
  5. "notes": [{
  6. "name": "W3C Spec",
  7. "href": "https://www.w3.org/TR/2013/CR-css-fonts-3-20131003/#descdef-unicode-range"
  8. }, {
  9. "name": "24 Way article",
  10. "href": "https://24ways.org/2011/creating-custom-font-stacks-with-unicode-range"
  11. }]
  12. }
  13. !*/
  14. define(['Modernizr', 'testStyles', 'createElement'], function(Modernizr, testStyles, createElement) {
  15. Modernizr.addTest('unicoderange', function() {
  16. return testStyles('@font-face{font-family:"unicodeRange";src:local("Arial");unicode-range:U+0020,U+002E}#modernizr span{font-size:20px;display:inline-block;font-family:"unicodeRange",monospace}#modernizr .mono{font-family:monospace}', function(elem) {
  17. // we use specify a unicode-range of 002E (the `.` glyph,
  18. // and a monospace font as the fallback. If the first of
  19. // these test glyphs is a different width than the other
  20. // the other three (which are all monospace), then we
  21. // have a winner.
  22. var testGlyphs = ['.', '.', 'm', 'm'];
  23. for (var i = 0; i < testGlyphs.length; i++) {
  24. var elm = createElement('span');
  25. elm.innerHTML = testGlyphs[i];
  26. elm.className = i % 2 ? 'mono' : '';
  27. elem.appendChild(elm);
  28. testGlyphs[i] = elm.clientWidth;
  29. }
  30. return (testGlyphs[0] !== testGlyphs[1] && testGlyphs[2] === testGlyphs[3]);
  31. });
  32. });
  33. });