Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web API - CSS Font Loading #65

Open
taoliujun opened this issue Mar 5, 2024 · 1 comment
Open

Web API - CSS Font Loading #65

taoliujun opened this issue Mar 5, 2024 · 1 comment
Labels

Comments

@taoliujun
Copy link
Owner

CSS Font Loading

MDN: https://developer.mozilla.org/en-US/docs/Web/API/CSS_Font_Loading_API

CSS Font Loading和css的@font-face所作功能一致,在javascript中加载字体可以更精确控制其加载状态,并用在canvas等场景中。

接口

FontFace

创建字体对象。

const font1 = new FontFace(
    'f1',
    `url(https://fonts.gstatic.com/s/kodemono/v1/A2BYn5pb0QgtVEPFnlYOnYLweZGZuA.woff2) format('woff2')`,
    {
      weight: '800'
    }
);
font1.load();
document.fonts.add(font1);

第三个参数描述符和css @font-face的属性font-style等是一样的作用,用于精确匹配字体源的。

示例

示例:https://taoliujun.github.io/example/web-api/CSS_Font_Loading_API/index.html

  1. 加载字体,在dom中自动生效,以及在canvas中作图。

image

@taoliujun
Copy link
Owner Author

字体的学问可不少,拜读相关文章:https://fonts.google.com/knowledge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant