037-font-face.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>037 font-face</title>
  6. <style>
  7. @font-face {
  8. font-family: "Ladder Mono";
  9. src: url("/ramfs/fonts/mono.ttf") format("truetype");
  10. }
  11. @font-face {
  12. font-family: "Missing Face";
  13. src: url("/ramfs/fonts/does-not-exist.ttf") format("truetype");
  14. }
  15. html, body { margin: 0; padding: 0; background: #ffffff; color: #202020; }
  16. body { font-family: sans-serif; font-size: 13px; padding: 10px; }
  17. h1 { font-size: 20px; margin: 0 0 6px 0; }
  18. p { margin: 0 0 10px 0; }
  19. .pane { float: left; width: 440px; margin-left: 10px; }
  20. .label { background: #eeeeee; padding: 4px 6px; margin-bottom: 4px; }
  21. .box { width: 220px; background: #f4f4f4; border: 1px solid #999999; padding: 6px; }
  22. .custom { font-family: "Ladder Mono"; font-size: 15px; }
  23. .mono { font-family: monospace; font-size: 15px; }
  24. .missing { font-family: "Missing Face", sans-serif; font-size: 15px; }
  25. .plain { font-family: sans-serif; font-size: 15px; }
  26. #result { clear: both; margin-top: 14px; padding: 8px; background: #eeeeee; color: #000000; font-family: monospace; font-weight: bold; }
  27. </style>
  28. </head>
  29. <body>
  30. <h1>037 &middot; @font-face</h1>
  31. <p>The custom face must load from the pack and measure like the built-in mono face; a missing URL must fall back to sans.</p>
  32. <div class="pane">
  33. <div class="label">A &middot; @font-face</div>
  34. <div class="box"><span class="custom">The quick brown fox jumps over the lazy dog and the five boxing wizards jump quickly.</span></div>
  35. <div class="box" style="margin-top:8px"><span class="missing">Missing face falls back to the inherited sans text.</span></div>
  36. </div>
  37. <div class="pane">
  38. <div class="label">B &middot; reference</div>
  39. <div class="box"><span class="mono">The quick brown fox jumps over the lazy dog and the five boxing wizards jump quickly.</span></div>
  40. <div class="box" style="margin-top:8px"><span class="plain">Missing face falls back to the inherited sans text.</span></div>
  41. </div>
  42. <p id="metrics" style="clear:both;margin-top:12px">checking...</p>
  43. <span id="custom-run" class="custom" style="display:inline-block">AVAVAVAVAV</span>
  44. <span id="mono-run" class="mono" style="display:inline-block">AVAVAVAVAV</span>
  45. <span id="missing-run" class="missing" style="display:inline-block">AVAVAVAVAV</span>
  46. <span id="plain-run" class="plain" style="display:inline-block">AVAVAVAVAV</span>
  47. <div id="result">checking...</div>
  48. <script>
  49. setTimeout(function () {
  50. var ca = document.getElementById('custom-run').getBoundingClientRect();
  51. var cb = document.getElementById('mono-run').getBoundingClientRect();
  52. var cm = document.getElementById('missing-run').getBoundingClientRect();
  53. var cp = document.getElementById('plain-run').getBoundingClientRect();
  54. var ok = Math.abs(ca.width - cb.width) <= 1 &&
  55. Math.abs(cm.width - cp.width) <= 1 &&
  56. ca.width > 0 && cb.width > 0;
  57. var msg = 'custom=' + Math.round(ca.width) + ' mono=' + Math.round(cb.width) +
  58. ' missing=' + Math.round(cm.width) + ' sans=' + Math.round(cp.width);
  59. var out = document.getElementById('result');
  60. out.textContent = ok ? 'PASS: @font-face metrics (' + msg + ')' :
  61. 'FAIL: @font-face metrics (' + msg + ')';
  62. out.style.background = ok ? '#ccffcc' : '#ffcccc';
  63. }, 600);
  64. </script>
  65. </body>
  66. </html>