fonts - 谷歌字体 : Language selection not working

标签 fonts webfonts google-font-api

这个问题在这里已经有了答案:





How can I only use Latin subset with Google Fonts WOFF2 files?

(1 个回答)


5 个月前关闭。




我正在使用 Google 字体 Roboto在相当多的客户网站上。

当您在 Google Fonts 上自定义字体时,您有许多语言选项可供选择:

  • 希腊语(由 Roboto 支持)
  • 拉丁语扩展(由 Roboto 支持)
  • 西里尔文(由 Roboto 支持)
  • 越南语(由 Roboto 支持)
  • 西里尔文扩展(由 Roboto 支持)
  • 希腊语扩展(由 Roboto 支持)
  • 拉丁文(所有字体均支持)

  • 对于这些客户端站点,我只需要使用拉丁语,不需要加载任何其他语言。

    但是,当我加载此字体并定义拉丁语言时,您可以看到所有其他语言也加载到生成的样式表中:

    https://fonts.googleapis.com/css?family=Roboto:300&subset=latin
    /* cyrillic-ext */
    @font-face {
      font-family: 'Roboto';
      font-style: normal;
      font-weight: 300;
      src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/0eC6fl06luXEYWpBSJvXCBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
      unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
    }
    /* cyrillic */
    @font-face {
      font-family: 'Roboto';
      font-style: normal;
      font-weight: 300;
      src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Fl4y0QdOxyyTHEGMXX8kcRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
      unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
    }
    /* greek-ext */
    @font-face {
      font-family: 'Roboto';
      font-style: normal;
      font-weight: 300;
      src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/-L14Jk06m6pUHB-5mXQQnRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
      unicode-range: U+1F00-1FFF;
    }
    /* greek */
    @font-face {
      font-family: 'Roboto';
      font-style: normal;
      font-weight: 300;
      src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/I3S1wsgSg9YCurV6PUkTORJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
      unicode-range: U+0370-03FF;
    }
    /* vietnamese */
    @font-face {
      font-family: 'Roboto';
      font-style: normal;
      font-weight: 300;
      src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/NYDWBdD4gIq26G5XYbHsFBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
      unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB;
    }
    /* latin-ext */
    @font-face {
      font-family: 'Roboto';
      font-style: normal;
      font-weight: 300;
      src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Pru33qjShpZSmG3z6VYwnRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2');
      unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF;
    }
    /* latin */
    @font-face {
      font-family: 'Roboto';
      font-style: normal;
      font-weight: 300;
      src: local('Roboto Light'), local('Roboto-Light'), url(https://fonts.gstatic.com/s/roboto/v15/Hgo13k-tfSpn0qi1SFdUfVtXRa8TVwTICgirnJhmVJw.woff2) format('woff2');
      unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
    }
    

    我的理解是定义 &subset=latin仅加载该语言,那么为什么所有语言都加载在这里?

    最佳答案

    我正在复制 this answer来自 Daryl Teo因为他似乎为您的问题提供了正确答案。

    The trick lies with this optimization:

    unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;

    With this, the browser knows whether it needs to download the font, depending on the characters it just loaded in the html.


    在这里查看哪些浏览器有 full support for this .
    早期的浏览器,例如 Firefox < 44 和 Safari < 10,忽略(部分)规范,或者需要启用它,因此 Google Fonts 必须为其提供最小字体规范。

    关于fonts - 谷歌字体 : Language selection not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40463014/

    相关文章:

    javascript - 为什么 Material Icons 不在 phantom js 中呈现?

    css - 如何在 css 中包含 .otf?

    javascript - 您可以使用 Javascript 中的 execCommand 将 ContentEditable 文本的字体系列更改为自定义字体吗?

    css - ie9 网络字体未加载

    c# - 添加 google font api 后仅显示安全内容

    html - CSS - 实现字体系列的不同字体

    css - 本地安装的 TTF 会覆盖 Google 字体

    windows - Google Chrome 在 Windows 10(英语)中使用什么默认字体?

    javascript - IE 中的文本额外别名(锯齿状)- 看起来很糟糕 - 但在 FF 和 Chrome 中还可以

    html - 如何使字体在浏览器中看起来很旧且过时