vanilladocs
vanillapunch.com
API / resource/fontasset

resource/fontasset

폰트 애셋.

Font asset.

FontAssetextends Asset

짝Counterpart: vanilla-engine FontAsset

폰트 애셋.

Font asset.

예제Example글꼴 파일을 읽어 글꼴 목록에 올리기Load a font file and add it to the font set
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"));
생성자constructorconstructor()#0.0.8 부터since 0.0.8소스source

생성.

Constructor.

짝Counterpart: vanilla-engine FontAsset.new

필드fieldfamily = ""#0.0.8 부터since 0.0.8소스source

등록한 글꼴 패밀리 이름. (읽기 전에는 빈 글)

Registered font family name. (empty string before loading)

반환Returnsstring

짝Counterpart: vanilla-engine FontAsset.get_family

필드fieldfontFace = null#0.0.8 부터since 0.0.8소스source

등록한 FontFace. (읽기 전이나 언로드 뒤에는 null)

Registered FontFace. (null before loading or after unloading)

반환ReturnsFontFace

메서드methodasync load(assetPath)#0.0.8 부터since 0.0.8소스source

비동기 애셋 로드. (파일 이름을 글꼴 패밀리 이름으로 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

예제Example파일 이름을 패밀리 이름으로 글꼴 올리기Registering a font with its file name as the family name
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"));
메서드methodasync loadFont(family, assetPath, descriptors)#0.0.8 부터since 0.0.8소스source

비동기 애셋 로드.

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

메서드methodasync loadFontFromBytes(family, bytes, descriptors)#0.4.0 부터since 0.4.0소스source

이미 가진 글꼴 바이트로 읽기. (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

예제Example받아 둔 바이트로 글꼴 올리기Add a font from bytes already fetched
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());
메서드methodunload()#0.0.8 부터since 0.0.8소스source

애셋 언로드.

Unloads the asset.

짝Counterpart: vanilla-engine FontAsset.unload