1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105

content / test / data / font_src_local_matching.html [blame]

<meta charset="utf-8">
<style id="fontfaces">
</style>
<body>
<script>
function getFontsWithTestCharsForOS() {
  if (navigator.userAgent.indexOf("Android") !== -1) {
    // Intersection of available fonts from Android Kitkat (API 19) to Android
    // 15 (API 35) that kept the same family names to compare against for these
    // postscript or full font names. (RobotoThin* and RobotoLight* had
    // differing family names on different Android versions.
    return [
      ["AndroidClock-Regular", "0"],
      ["DroidSansMono", "0"],
      ["Roboto-Regular", "0"],
      ["Noto Color Emoji", "☺"],
      ["NotoSansLaoUI-Bold", "0"],
      ["NotoSansLaoUI", "0"],
      ["NotoSansThai-Bold", "๐"],
      ["NotoSansThai", "๐"],
      ["NotoSansThaiUI-Bold", "๐"],
      ["NotoSansThaiUI", "๐"],
    ];
  } else if (navigator.userAgent.indexOf("Linux") !== -1
             || navigator.userAgent.indexOf("CrOS") !== -1) {
    return [
      ["Ahem", "0"],
      ["Arimo-Bold", "0"],
      ["Arimo-BoldItalic", "0"],
      ["Arimo-Italic", "0"],
      ["Arimo-Regular", "0"],
      ["Cousine-Bold", "0"],
      ["Cousine-BoldItalic", "0"],
      ["Cousine-Italic", "0"],
      ["Cousine-Regular", "0"],
      ["DejaVuSans", "0"],
      ["DejaVuSans-Bold", "0"],
      ["Garuda", "0"],
      ["Gelasio-Bold", "0"],
      ["Gelasio-BoldItalic", "0"],
      ["Gelasio-Italic", "0"],
      ["Gelasio-Regular", "0"],
      ["Lohit-Devanagari", "0"],
      ["Lohit-Gurmukhi", "0"],
      ["Lohit-Tamil", "0"],
      ["NotoSansKhmer-Regular", "០"],
      ["Tinos-Bold", "0"],
      ["Tinos-BoldItalic", "0"],
      ["Tinos-Italic", "0"],
      ["Tinos-Regular", "0"],
      ["muktinarrow", "0"],
      ["Tinos-Regular", "0"]
    ];
  } else if (navigator.userAgent.indexOf("Macintosh") !== -1) {
    return [
      [ "AmericanTypewriter-CondensedLight", "0" ],
      [ "ArialNarrow-BoldItalic", "0" ],
      [ "Baskerville-SemiBoldItalic", "0" ],
      [ "DevanagariMT", "0" ],
      [ "DINAlternate-Bold", "0" ],
      [ "GillSans-LightItalic", "0" ],
      [ "IowanOldStyle-Titling", "0" ],
      [ "MalayalamSangamMN", "0" ],
      [ "HiraMaruPro-W4", "0" ],
      [ "HiraKakuStdN-W8", "0" ],
    ];
  } else if (navigator.userAgent.indexOf("Windows") !== -1) {
    return [
      ["CambriaMath", "0"],
      ["Ming-Lt-HKSCS-ExtB", "0"],
      ["NSimSun", "0"],
      ["calibri-bolditalic", "0"]
      ];
  }
  return [];
}

function stripSpaces(fontName) {
  return fontName.replace(/\s+/g, '');
}

async function addTestNodes() {
  var containerDiv = document.createElement("div");
  var fontFaceDeclarations = "";
    for (font_name_and_testchars of getFontsWithTestCharsForOS()) {
    var font_name = font_name_and_testchars[0];
    // Add cursive to font stack to avoid ignoring failures when Roboto is used as fallback.
    fontFaceDeclarations +=
      `@font-face { font-family: ${stripSpaces(font_name)}_webfont; \
      src: local("${font_name}"); } .${stripSpaces(font_name)}_style \
      { font-family: ${stripSpaces(font_name)}_webfont, cursive; } `;
    var testElement = document.createElement("div");
    testElement.classList += `testnode ${stripSpaces(font_name)}_style`;
    testElement.innerText = font_name_and_testchars[1];
    containerDiv.appendChild(testElement);
  }
  fontfaces.innerText = fontFaceDeclarations;
  document.body.appendChild(containerDiv);
  await document.fonts.ready;
  // Force layout so that the DevTools side of the test can start accessing
  // nodes' font information reliably.
  document.body.offsetTop;
  return containerDiv.children.length;
}
</script>