vanilladocs
vanillapunch.com
API / misc/uifont

misc/uifont

UI 글꼴. (화면 위의 모든 글자, 여러 문자의 글꼴 조각을 한 이름 아래 묶음, UIFont 로 들여온다)

  • 글꼴 이름, 목록 파일과 폴더, 맨 뒤 묶음, 굵기, 기다리는 시간은 configureUiFont 로 정한다. (처음은 GameUI, ./assets/fonts/fonts.json, latin, 500 과 700)
  • 목록은 fonts.json(색인 { fonts: [{ group, manifest }] })과 fonts-<묶음>.json(조각 { faces: [{ file, weight, style, unicodeRange }] })이다.

화면의 모든 언어를 한 글꼴 이름(configureUiFont 의 family) 아래에 모아 그린다. 라틴, 키릴 문자는 기본 글꼴(Exo 2)이고, 그 밖의 문자는 그와 비슷한 느낌의 글꼴이다. 글꼴 파일을 합치지 않는다. Google Fonts 가 나눠 둔 조각마다 FontFace 를 만들어 그 조각의 글자 범위(unicode-range)로 올린다. 그래서 브라우저는 화면에 쓰는 글자가 든 조각만 받는다. (한, 중, 일 글꼴은 조각이 수백 개이다) 한자처럼 여러 글꼴이 함께 가진 글자는 나중에 올린 글꼴이 그린다. 고른 언어의 글꼴 묶음을 라틴 바로 앞(뒤에서 둘째)에 올려 일본어면 일본 글꼴, 중국어 번체면 번체 글꼴의 한자가 나오게 한다. 라틴은 늘 맨 뒤라 숫자와 영문은 어느 언어에서나 라틴 글꼴이다. 한 글꼴 이름 아래의 조각은 굵기의 표시가 모두 같아야 글자 범위로 함께 고른다. (굵기를 먼저 고르고 그 굵기의 조각만 보기 때문이다) 그래서 모든 조각을 configureUiFont 의 weights(처음은 500, 700) 두 굵기로만 올린다. 가변 굵기 조각은 두 번(500 과 700), 400 뿐인 조각은 500 으로 올린다. 화면이 400 을 청하면 500, 600 을 청하면 700 조각이 그린다. 캔버스는 받지 않은 조각을 기다리지 않고 다른 글꼴로 그려 버리므로, 쓸 글자를 그릴 조각을 미리 받는다. (loadUiFontText) 조각을 받으면 엔진(EngineConfiguration.rebakeTextOnFontLoad)이 그 조각의 글자로 구운 글자 그림만 버려 다시 굽는다. 글꼴의 목록은 묶음마다 나뉘어 있다. (fonts.json 은 색인, fonts-<묶음>.json 이 그 묶음의 조각들) 처음에는 고른 언어와 라틴의 목록만 받고, 나머지(언어 창의 언어 이름, 사람 이름처럼 다른 문자)는 놀이를 시작하고 조금 뒤에 받는다. 처음의 조각은 configureUiFont 의 waitMilliseconds 까지만 기다리고, 그 뒤는 놀이를 먼저 시작해 받는 대로 다시 굽는다. (첫 로딩 줄이기) 경로를 글자 그대로 적어 두어 빌드의 캐시 무효화가 지문을 붙이게 한다. (조각의 지문은 빌드가 목록에 붙인다)

UI font. (all on-screen text, groups font subsets for many scripts under one name, imported as UIFont)

  • Font name, list file and folder, last group, weights and wait time are set with configureUiFont. (initially GameUI, ./assets/fonts/fonts.json, latin, 500 and 700)
  • The lists are fonts.json (index { fonts: [{ group, manifest }] }) and fonts-<group>.json (subsets { faces: [{ file, weight, style, unicodeRange }] }).

Draws all on-screen languages under one font name (the family of configureUiFont). Latin and Cyrillic use the base font (Exo 2), and other scripts use fonts with a similar feel. Font files are not merged. A FontFace is created for each subset split by Google Fonts and registered with that subset's character range (unicode-range). So the browser downloads only the subsets containing characters used on screen. (Korean, Chinese and Japanese fonts have hundreds of subsets) Characters shared by several fonts, such as Han characters, are drawn by the font registered later. The selected language's font group is registered right before Latin (second from the end) so that Japanese gets Japanese-font Han characters and Traditional Chinese gets Traditional-font ones. Latin is always last, so digits and Latin letters use the Latin font in every language. Subsets under one font name must all declare the same weight to be selected together by character range. (because the weight is chosen first and only subsets of that weight are considered) So every subset is registered with only the two weights in configureUiFont's weights (initially 500, 700). Variable-weight subsets are registered twice (500 and 700), and 400-only subsets as 500. When the screen requests 400, the 500 subset draws, and for 600 the 700 subset draws. The canvas does not wait for subsets not yet downloaded and draws with another font, so subsets for the characters to be drawn are fetched in advance. (loadUiFontText) When a subset is downloaded, the engine (EngineConfiguration.rebakeTextOnFontLoad) discards and rebakes only the text images baked with that subset's characters. The font lists are split per group. (fonts.json is the index, fonts-<group>.json holds that group's subsets) At first only the lists for the selected language and Latin are fetched, and the rest (language names in the language window, other scripts such as person names) are fetched a little after play starts. Initial subsets are waited for only up to configureUiFont's waitMilliseconds, after which play starts first and text is rebaked as subsets arrive. (shorter first load) Paths are written as literal strings so the build's cache busting can add fingerprints. (subset fingerprints are added to the lists by the build)

예제ExampleUI 글꼴 설정하고 글꼴 문자열 만들기Configure the UI font and build a font string
import { UIFont } from "./build/vanilla.js";

UIFont.configureUiFont({ family: "ExampleUI", manifestPath: "./assets/fonts/fonts.json", directoryPath: "./assets/fonts/", weights: [500, 700], waitMilliseconds: 1000 });
const fontString = UIFont.buildUiFontString(700, 24);
console.log(UIFont.readUiFontFamily(), fontString, UIFont.readUiFontFace());

함수Functions

함수functionasync loadUiFont(fontGroup, text)#0.4.0 부터since 0.4.0소스source

UI 글꼴 불러오기. (고른 언어와 라틴의 묶음을 올려 앞세우고, 그 언어의 글자를 미리 받는다) 쓸 글자의 조각은 uiFontWaitMilliseconds 까지만 기다리고 나머지는 뒤에서 받는다. 나머지 묶음은 처음 한 번 remainingGroupsDelayMilliseconds 뒤에 받기 시작한다. 못 불러와도 게임은 시스템 글꼴로 이어진다.

Loads the UI font. (registers and prioritizes the groups of the selected language and Latin, and prefetches that language's text) Subsets for the text in use are waited for only up to uiFontWaitMilliseconds, and the rest are fetched in the background. The remaining groups start downloading remainingGroupsDelayMilliseconds after the first call, once only. If loading fails, the game continues with the system font.

fontGroupstring
고른 언어의 글꼴 묶음. (languages.json 의 fontGroup)Font group of the selected language. (fontGroup in languages.json)
textstring
미리 받을 글자. (그 언어의 글자 모두)Text to prefetch. (all text of that language)

짝Counterpart: vanilla-engine load_ui_font

함수functionapplyUiFontGroup(fontGroup)#0.4.0 부터since 0.4.0소스source

고른 언어의 글꼴 묶음 앞세우기. (그 묶음을 라틴 바로 앞에 두고 모든 조각을 다시 올린다)

Prioritizes the selected language's font group. (places that group right before Latin and re-registers all subsets)

fontGroupstring
앞세울 글꼴 묶음. (languages.json 의 fontGroup, 올린 묶음이 하나도 없으면 아무것도 하지 않는다)Font group to put first. (fontGroup in languages.json, does nothing if no group has been loaded)

짝Counterpart: vanilla-engine apply_ui_font_group

함수functionasync loadUiFontText(text)#0.4.0 부터since 0.4.0소스source

글자의 조각 받기. (그 글자가 든 조각만, 다 받을 때까지 기다린다)

Fetches the subsets for text. (only subsets containing that text, waits until all are downloaded)

textstring
그릴 글자. (빈 글이거나 올린 묶음이 없으면 아무것도 하지 않는다)Characters to draw. (does nothing if empty or no group has been loaded)

짝Counterpart: vanilla-engine load_ui_font_text

함수functionrequestUiFontText(text)#0.4.0 부터since 0.4.0소스source

글자의 조각 받기 청하기. (사람 이름처럼 그때그때 나오는 글자, 기다리지 않고 처음 보는 글자만)

Requests fetching the subsets for text. (text that appears on the fly, such as person names, does not wait, only characters not seen before)

textstring
그릴 글자. (전에 청하지 않은 글자만 받는다)Characters to draw. (only fetches characters not requested before)

짝Counterpart: vanilla-engine request_ui_font_text

함수functionreadUiFontFace()#0.4.0 부터since 0.4.0소스source

불러온 UI 글꼴의 대표 FontFace 반환. (엔진의 UILabel, UIInputField 에 준다, 글꼴 이름만 쓰이다, 못 불러왔으면 null)

Returns the representative FontFace of the loaded UI font. (given to the engine's UILabel and UIInputField, only the font name is used, null if not loaded)

반환ReturnsFontFace | null 맨 뒤 묶음의 첫 조각. 못 불러왔으면 null.The first face of the last group. null if not loaded.

짝Counterpart: vanilla-engine read_ui_font_face

함수functionbuildUiFontString(fontWeight, fontSize)#0.4.0 부터since 0.4.0소스source

UI 글꼴 문자열. (굵기, 크기)

UI font string. (weight, size)

fontWeightnumber
굵기. (500, 700 같은 수)Weight. (a number like 500 or 700)
fontSizenumber
크기. (픽셀)Size. (pixels)

반환Returnsstring 캔버스 font 꼴의 글. (예: 700 24px "GameUI", sans-serif)Text in canvas font form. (e.g. 700 24px "GameUI", sans-serif)

짝Counterpart: vanilla-engine build_ui_font_string

함수functionconfigureUiFont(options)#0.4.0 부터since 0.4.0소스source

UI 글꼴 설정. (불러오기 전에 부른다, 주지 않은 칸은 그대로)

Sets the UI font. (call before loading, fields not given stay unchanged)

optionsobject
{ family, manifestPath, directoryPath, primaryGroup, weights, waitMilliseconds, remainingDelayMilliseconds }

짝Counterpart: vanilla-engine configure_ui_font

함수functionreadUiFontFamily()#0.4.0 부터since 0.4.0소스source

UI 글꼴 이름 반환.

Returns the UI font name.

반환Returnsstring UI 글꼴 이름. (처음은 "GameUI")UI font family name. ("GameUI" at first)

짝Counterpart: vanilla-engine read_ui_font_family