resource/fontasset
폰트 애셋.
Font asset.
FontAssetextends Asset
폰트 애셋.
Font asset.
import { FontAsset } from "./build/vanilla.js";
const fontAsset = new FontAsset();
await fontAsset.loadFont("DOSGothic", "examples/assets/DOSGothic.woff", { weight: "normal", style: "normal" });
console.log(fontAsset.family, fontAsset.isLoaded(), document.fonts.check("16px DOSGothic"));등록한 글꼴 패밀리 이름. (읽기 전에는 빈 글)
Registered font family name. (empty string before loading)
반환Returnsstring
짝Counterpart: vanilla-engine FontAsset.get_family
등록한 FontFace. (읽기 전이나 언로드 뒤에는 null)
Registered FontFace. (null before loading or after unloading)
반환ReturnsFontFace
비동기 애셋 로드. (파일 이름을 글꼴 패밀리 이름으로 loadFont 한다)
Loads the asset asynchronously. (calls loadFont with the file name as the font family name)
- assetPathstring
- 글꼴 파일 경로. (파일 이름에서 확장자를 뗀 것이 패밀리 이름이 된다, "assets/DOSGothic.woff" 면 "DOSGothic")Font file path. (the file name without its extension becomes the family name, "DOSGothic" for "assets/DOSGothic.woff")
반환ReturnsPromise<void> 글꼴을 읽어 document.fonts 에 올리면 풀리는 프로미스. (이미 읽었으면 바로 풀린다, 읽지 못하면 거부된다)A promise resolved once the font is loaded and added to document.fonts. (resolves at once if already loaded, rejects if it cannot be loaded)
짝Counterpart: vanilla-engine FontAsset.load
import { FontAsset } from "./build/vanilla.js";
const fontAsset = new FontAsset();
await fontAsset.load("examples/assets/DOSGothic.woff");
console.log(fontAsset.family, fontAsset.isLoaded(), document.fonts.check("16px DOSGothic"));비동기 애셋 로드.
Loads the asset asynchronously.
- familystring
- 등록할 글꼴 패밀리 이름. (CSS font-family 로 쓴다)Font family name to register. (used as the CSS font-family)
- assetPathstring
- 글꼴 파일 경로.Font file path.
- descriptorsobject
- FontFace 서술자. (weight, style, stretch, unicodeRange, display 등)FontFace descriptors. (weight, style, stretch, unicodeRange, display, etc)
반환ReturnsPromise<void> 글꼴을 읽어 document.fonts 에 올리면 풀리는 프로미스. (이미 읽었으면 바로 풀린다, 읽지 못하면 거부된다)A promise resolved once the font is loaded and added to document.fonts. (resolves at once if already loaded, rejects if it cannot be loaded)
짝Counterpart: vanilla-engine FontAsset.load_font
이미 가진 글꼴 바이트로 읽기. (ttf, otf, woff, woff2, 다 읽히면 document.fonts 에 family 이름으로 오른다)
Loads from font bytes already held. (ttf, otf, woff, woff2, once loaded it is added to document.fonts under the family name)
- familystring
- 등록할 글꼴 패밀리 이름. (CSS font-family 로 쓴다)Font family name to register. (used as the CSS font-family)
- bytesArrayBuffer | ArrayBufferView
- 글꼴 파일의 바이트. (넘긴 것은 바뀌지 않는다)The bytes of the font file. (What is passed is not changed)
- descriptorsobject
- FontFace 서술자. (weight, style 등, 없으면 생략)FontFace descriptors. (weight, style, etc, omitted if none)
짝Counterpart: vanilla-engine FontAsset.load_font_from_bytes
import { FontAsset } from "./build/vanilla.js";
const response = await fetch("examples/assets/DOSGothic.woff");
const bytes = await response.arrayBuffer();
const fontAsset = new FontAsset();
await fontAsset.loadFontFromBytes("DOSGothicBytes", bytes);
console.log(fontAsset.family, fontAsset.isLoaded());