misc/uifont
UI 글꼴. (원본 misc/uifont.js, 화면 위의 모든 글자, 여러 문자의 글꼴 조각을 한 이름 아래 묶음)
- 글꼴 이름, 목록 파일과 폴더, 맨 뒤 묶음, 굵기, 기다리는 시간은 configure_ui_font 로 정한다. (처음은 GameUI, ./assets/fonts/fonts.json, latin, 500 과 700)
- 목록은 fonts.json(색인 { fonts: [{ group, manifest }] })과 fonts-<묶음>.json(조각 { faces: [{ file, weight, style, unicodeRange }] })이다.
- 화면의 모든 언어를 한 글꼴 이름 아래에 모아 그린다. 글꼴 파일을 합치지 않고 조각마다 글꼴 얼굴을 만들어 그 조각의 글자 범위로 올린다. 그래서 화면에 쓰는 글자가 든 조각만 받는다. (한, 중, 일 글꼴은 조각이 수백 개이다) 한자처럼 여러 글꼴이 함께 가진 글자는 나중에 올린 글꼴이 그린다. 고른 언어의 묶음을 라틴 바로 앞(뒤에서 둘째)에 두어 일본어면 일본 글꼴, 중국어 번체면 번체 글꼴의 한자가 나오게 한다. 라틴은 늘 맨 뒤라 숫자와 영문은 어느 언어에서나 라틴 글꼴이다.
- 모든 조각을 configure_ui_font 의 weights(처음은 500, 700) 두 굵기로만 올린다. 가변 굵기 조각은 두 번(500 과 700), 400 뿐인 조각은 500 으로 올린다.
- 쓸 글자의 조각은 미리 받는다. (load_ui_font_text) 조각을 받으면 엔진(EngineConfiguration.rebake_text_on_font_load)이 그 조각의 글자로 구운 글자만 버려 다시 굽는다. 미리 받지 않은 글자도 그 글꼴로 재거나 그리면 update 가 그 글자의 조각을 받는다. (원본 브라우저는 올려 둔 FontFace 의 범위에 든 글자를 그릴 때 그 얼굴을 받는다) 받기 전에는 원본 캔버스처럼 다른 글꼴로 그리고, 받으면 (rebake_text_on_font_load 를 켰을 때) 다시 굽는다.
- 처음에는 고른 언어와 라틴의 목록만 받고, 나머지 묶음은 놀이를 시작하고 조금 뒤(remaining_delay_milliseconds)에 받는다. 처음의 조각은 wait_milliseconds 까지만 기다린다. (is_ui_font_ready 가 그 시간이 지나거나 다 받으면 참)
- 원본과 다른 것: 원본은 FontFace 를 만들어 document.fonts 에 넣고 async 로 기다린다. 러스트 판은 데스크탑과 웹 모두 조각 파일의 바이트를 받아 엔진의 글자 캐시에 같은 이름의 얼굴로 올린다. (Engine.register_font_face_when_loaded, 차례는 Engine.set_font_face_order) 그래서 웹에서도 브라우저 글꼴이 아니라 엔진의 모양 짓기로 그린다. 받는 일은 요청만 하고 update(engine) 를 프레임마다 불러 이어 간다. load_ui_font 는 원본처럼 await 할 수 있는 UiFontLoadHandle 을 돌려준다. (기다리는 동안 update 를 불러 주고, 처음 글자를 다 올렸거나 wait_milliseconds 가 지나면 끝난다) load_ui_font_text 는 그 글자의 얼굴들을 글꼴 목록에 올리면 끝나는 UiFontTextLoadHandle 을 돌려준다. (원본 await loadUiFontText(글자)) 원본 readUiFontFace(FontFace) 는 read_ui_font_face(올린 이름, 못 불러왔으면 None) 다. options 객체는 UiFontOptions 구조체다.
UI font. (the original misc/uifont.js, all on-screen text, groups font subsets for many scripts under one name)
- Font name, list file and folder, last group, weights and wait time are set with configure_ui_font. (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. Font files are not merged; a font face is made for each subset and registered with that subset's character range. So only the subsets containing characters used on screen are fetched. (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 group is placed 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.
- Every subset is registered with only the two weights in configure_ui_font's weights (initially 500, 700). Variable-weight subsets are registered twice (500 and 700), and 400-only subsets as 500.
- Subsets for the text in use are fetched in advance. (load_ui_font_text) When a subset arrives, the engine (EngineConfiguration.rebake_text_on_font_load) discards and rebakes only the text baked with that subset's characters. Characters not fetched in advance also get their subset fetched by update when measured or drawn with that font. (in the original, the browser fetches a registered FontFace when drawing characters in its range) Before it arrives, it is drawn with another font like the original canvas, and once it arrives it is rebaked (when rebake_text_on_font_load is on).
- At first only the lists for the selected language and Latin are fetched, and the remaining groups are fetched a little after play starts (remaining_delay_milliseconds). Initial subsets are waited for only up to wait_milliseconds. (is_ui_font_ready is true once that time passes or everything arrives)
- Differences from the original: The original creates FontFaces, adds them to document.fonts and waits with async. The Rust version receives the bytes of the subset files on both desktop and web and registers them as faces of the same name in the engine's text cache. (Engine.register_font_face_when_loaded, order by Engine.set_font_face_order) So on web too it draws with the engine's shaping, not browser fonts. Receiving only makes requests, and calling update(engine) every frame carries it on. load_ui_font returns a UiFontLoadHandle that can be awaited as in the original. (calls update while waiting, and finishes once the initial text is all registered or wait_milliseconds passes) load_ui_font_text returns a UiFontTextLoadHandle that finishes once the faces for that text are registered in the font list. (the original await loadUiFontText(text)) The original readUiFontFace(FontFace) is read_ui_font_face (the registered name, None if it could not be loaded). The options object is the UiFontOptions struct.
UiFontOptionsstruct traits Clone, Debug, Default, PartialEq
UI 글꼴 설정. (원본 configureUiFont 의 options, None 인 칸은 그대로)
- 기본값은 모든 칸이 None 이다. 바꿀 칸만 Some 으로 채우고 ..UiFontOptions::default() 로 나머지를 비운다.
UI font settings. (the options of the original configureUiFont, fields that are None stay unchanged)
- By default every field is None. Fill only the fields to change with Some and leave the rest with ..UiFontOptions::default().
use vanilla::{uifont, UiFontOptions};
uifont::configure_ui_font(UiFontOptions {
family: Some(String::from("MenuFont")),
manifest_path: Some(String::from("./assets/menufonts/fonts.json")),
directory_path: Some(String::from("./assets/menufonts/")),
..UiFontOptions::default()
});
assert_eq!(uifont::read_ui_font_family(), "MenuFont");
assert_eq!(uifont::build_ui_font_string(700, 24.0), "700 24px \"MenuFont\", sans-serif");올릴 글꼴 이름. (처음은 "GameUI", 글자 컴포넌트의 set_font_family 에 줄 이름)
Font name to register. (initially "GameUI", the name given to the text component's set_font_family)
반환ReturnsOption<String>
글꼴 색인 파일 경로. (애셋 경로, 처음은 "./assets/fonts/fonts.json")
Font index file path. (asset path, initially "./assets/fonts/fonts.json")
반환ReturnsOption<String>
묶음 목록과 조각 파일이 있는 폴더. (뒤에 파일 이름을 그대로 붙이므로 / 로 끝낸다, 처음은 "./assets/fonts/")
Folder holding the group lists and subset files. (file names are appended as is, so end it with /, initially "./assets/fonts/")
반환ReturnsOption<String>
맨 뒤에 둘 묶음. (처음은 "latin", 숫자와 영문을 늘 이 묶음으로 그린다)
Group to put last. (initially "latin", digits and Latin letters are always drawn with this group)
반환ReturnsOption<String>
조각을 올릴 굵기 목록. (처음은 500 과 700)
List of weights to register subsets with. (initially 500 and 700)
반환ReturnsOption<Vec<u16>>
처음 글자의 조각을 기다리는 시간. (밀리초, 처음은 1500)
Time to wait for the subsets of the initial text. (milliseconds, initially 1500)
반환ReturnsOption<f64>
처음 불러오기 뒤 나머지 묶음을 받기까지 쉬는 시간. (밀리초, 처음은 3000)
Time to rest after the initial load before fetching the remaining groups. (milliseconds, initially 3000)
반환ReturnsOption<f64>
UiFontLoadHandlestruct traits Clone, Copy, Debug, Default, IntoFuture
UI 글꼴 불러오기 손잡이. (load_ui_font 가 돌려준다. 원본 loadUiFont 의 Promise 자리)
- await 하면 처음 글자를 다 올렸거나 wait_milliseconds 가 지날 때까지 기다린다.
UI font load handle. (returned by load_ui_font. Stands in for the Promise of the original loadUiFont)
- Awaiting it waits until the initial text is all registered or wait_milliseconds passes.
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{uifont, Engine, EngineConfiguration, UiFontOptions};
uifont::configure_ui_font(UiFontOptions {
manifest_path: Some(String::from("missing-fonts/fonts.json")),
..UiFontOptions::default()
});
let engine = Engine::new(EngineConfiguration::new());
let is_ready = Rc::new(Cell::new(false));
let is_ready_for_task = is_ready.clone();
engine.spawn_task(move |mut engine_context| async move {
engine_context.with(|engine| uifont::load_ui_font(engine, "korean", "Start")).await;
is_ready_for_task.set(true);
});
assert!(is_ready.get());
assert!(uifont::is_ui_font_ready());
assert_eq!(uifont::read_ui_font_face(), None);UiFontLoadFuturestruct traits Clone, Copy, Debug, Default, Future
UI 글꼴 처음 불러오기를 기다리는 퓨처.
- UiFontLoadHandle 을 await 하거나 wait_for_load 가 돌려준다. 폴링할 때마다 update 를 부른다.
Future that waits for the initial UI font load.
- Made by awaiting UiFontLoadHandle or returned by wait_for_load. Calls update on every poll.
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{uifont, Engine, EngineConfiguration};
let engine = Engine::new(EngineConfiguration::new());
let is_finished = Rc::new(Cell::new(false));
let is_finished_for_task = is_finished.clone();
engine.spawn_task(move |_engine_context| async move {
uifont::wait_for_load().await;
is_finished_for_task.set(true);
});
assert!(is_finished.get());UiFontTextLoadHandlestruct traits Clone, Debug, Default, IntoFuture
글자 조각 받기 손잡이. (load_ui_font_text 가 돌려준다. 원본 loadUiFontText 의 Promise 자리, 청한 얼굴을 모두 올리면 끝난다)
Text subset fetch handle. (returned by load_ui_font_text. Stands in for the Promise of the original loadUiFontText, finishes once all requested faces are registered)
use vanilla::{uifont, Engine, EngineConfiguration};
let engine = Engine::new(EngineConfiguration::new());
let text_load_handle = uifont::load_ui_font_text(engine, "Ready");
if !text_load_handle.is_finished() {
engine.spawn_task(move |_engine_context| async move {
text_load_handle.await;
});
}청한 얼굴의 글꼴 받기 손잡이 목록. (씬에 맡길 때는 저마다의 get_load_handle)
List of font fetch handles for the requested faces. (each one's get_load_handle when handing them to a scene)
반환Returns&[FontLoadHandle] 청한 얼굴마다 하나인 글꼴 받기 손잡이 목록. 청한 것이 없으면 빈 목록.List of font fetch handles, one per requested face. Empty list if nothing was requested.
다 끝났는지. (올렸거나 실패했거나, 청한 것이 없으면 참)
Whether everything finished. (registered or failed, true if nothing was requested)
반환Returnsbool 모든 손잡이가 끝났으면 true.true if all handles finished.
UiFontTextLoadFuturestruct traits Clone, Debug, Future
글자 조각 받기를 기다리는 퓨처. (원본처럼 받지 못한 조각이 있어도 실패로 끝내지 않는다)
- UiFontTextLoadHandle 을 await 하면 이것이 된다.
Future that waits for text subset fetches. (as in the original, does not end in failure even if some subsets could not be fetched)
- Awaiting UiFontTextLoadHandle gives this.
use std::cell::Cell;
use std::future::IntoFuture;
use std::rc::Rc;
use vanilla::{uifont, Engine, EngineConfiguration, UiFontTextLoadFuture};
let engine = Engine::new(EngineConfiguration::new());
let text_load_future: UiFontTextLoadFuture = uifont::load_ui_font_text(engine, "Ready").into_future();
let is_finished = Rc::new(Cell::new(false));
let is_finished_for_task = is_finished.clone();
engine.spawn_task(move |_engine_context| async move {
text_load_future.await;
is_finished_for_task.set(true);
});
assert!(is_finished.get());함수Functions
조각의 굵기 → 올릴 굵기. ("400 700" → [500, 700], "400" → [500], "700" → [700], 원본 readTargetWeights)
- 범위면 그 안의 굵기 모두, 한 값이면 가장 가까운 하나이다.
- 숫자가 없으면 400 으로 본다. 가까운 굵기가 둘이면 weights 의 앞 것이다.
Subset weight → weights to register. ("400 700" → [500, 700], "400" → [500], "700" → [700], the original readTargetWeights)
- For a range, all weights inside it; for a single value, the closest one.
- Treated as 400 if there is no number. If two weights are equally close, the earlier one in weights.
- weight_descriptor&str
- 조각 목록의 weight 글. ("400" 같은 한 값, "100 900" 같은 범위)Weight text from the subset list. (a single value like "400", a range like "100 900")
- weights&[u16]
- 올릴 굵기 목록.List of weights to register.
반환ReturnsVec<u16> 올릴 굵기 목록. 범위면 범위 안(양 끝 포함)의 굵기 모두, 한 값이면 가장 가까운 하나. weights 가 비면 빈 목록.List of weights to register. For a range, all weights inside it (both ends included); for a single value, the closest one. Empty list if weights is empty.
use vanilla::uifont;
let weights = [500, 700];
assert_eq!(uifont::read_target_weights("400 700", &weights), vec![500, 700]);
assert_eq!(uifont::read_target_weights("400", &weights), vec![500]);
assert_eq!(uifont::read_target_weights("700", &weights), vec![700]);
assert!(uifont::read_target_weights("100 450", &weights).is_empty());UI 글꼴 불러오기. (고른 언어와 라틴의 묶음을 올려 앞세우고, 그 언어의 글자를 미리 받는다. 원본 loadUiFont)
- 받는 동안은 update 를 프레임마다 부른다. 처음 글자가 준비됐는지는 is_ui_font_ready 로 본다. (돌려준 손잡이를 await 하면 준비될 때까지 기다린다)
Loads the UI font. (registers and prioritizes the groups of the selected language and Latin, and prefetches that language's text. the original loadUiFont)
- Call update every frame while receiving. Whether the initial text is ready is checked with is_ui_font_ready. (awaiting the returned handle waits until it is ready)
- engine&Engine
- 애셋을 받고 글꼴 얼굴을 올릴 엔진.Engine to receive assets with and register font faces on.
- font_group&str
- 고른 언어의 글꼴 묶음 이름. (색인 fonts.json 의 group)Font group name of the selected language. (group in the index fonts.json)
- text&str
- 미리 받을 글자. (그 언어의 화면 글자 모두 같은 것)Text to prefetch. (such as all on-screen text of that language)
반환ReturnsUiFontLoadHandle await 할 수 있는 불러오기 손잡이.Load handle that can be awaited.
짝Counterpart: vanilla.js loadUiFont
이어 가기. (받은 색인과 묶음 목록을 들고, 처음 불러오기를 마저 하고, 때가 되면 나머지 묶음을 받는다. 프레임마다 부른다)
- 이 글꼴로 재거나 그렸는데 받은 조각에 없던 글자의 조각도 여기서 받는다.
Continues. (takes the received index and group lists, finishes the initial load, and fetches the remaining groups when the time comes. Call every frame)
- Also fetches here the subsets for characters measured or drawn with this font that were not in the fetched subsets.
- engine&Engine
- 애셋을 받고 글꼴 얼굴을 올릴 엔진.Engine to receive assets with and register font faces on.
고른 언어의 글꼴 묶음 앞세우기. (그 묶음을 라틴 바로 앞에 두고 모든 얼굴의 차례를 다시 정한다, 원본 applyUiFontGroup)
- 받은 묶음이 하나도 없으면 아무것도 하지 않는다. 차례를 바꾸면 엔진의 글자 캐시를 비운다.
Prioritizes the selected language's font group. (places that group right before Latin and reorders all faces, the original applyUiFontGroup)
- Does nothing if no group has been received. Changing the order clears the engine's text cache.
- engine&Engine
- 얼굴 차례를 걸 엔진.Engine to set the face order on.
- font_group&str
- 앞세울 묶음 이름. (언어를 바꿀 때 그 언어의 묶음)Group name to prioritize. (the language's group when switching languages)
짝Counterpart: vanilla.js applyUiFontGroup
글자의 조각 받기. (그 글자를 그릴 얼굴만, 원본 loadUiFontText. 청한 얼굴을 모두 올리면 끝나는 손잡이를 돌려준다)
- 같은 파일을 여러 굵기로 올리면 바이트는 한 번 받고 굵기마다 올린다.
- 받은 묶음이 없거나 글이 비면 아무것도 청하지 않는다. 이미 받기를 청한 얼굴은 다시 청하지 않는다.
Fetches subsets for text. (only the faces that draw that text, the original loadUiFontText. Returns a handle that finishes once all requested faces are registered)
- When the same file is registered with several weights, the bytes are fetched once and registered per weight.
- Requests nothing if no group has been received or the text is empty. Faces already requested are not requested again.
- engine&Engine
- 애셋을 받고 글꼴 얼굴을 올릴 엔진.Engine to receive assets with and register font faces on.
- text&str
- 쓸 글자. (글자마다 굵기마다 그릴 얼굴을 찾는다)Text to use. (finds the faces that draw each character at each weight)
반환ReturnsUiFontTextLoadHandle 이번에 청한 얼굴들을 모두 올리면(또는 실패하면) 끝나는 손잡이. 청한 것이 없으면 바로 끝난 손잡이.Handle that finishes once all faces requested this time are registered (or fail). A handle already finished if nothing was requested.
짝Counterpart: vanilla.js loadUiFontText
use vanilla::{uifont, Engine, EngineConfiguration};
let engine = Engine::new(EngineConfiguration::new());
let text_load_handle = uifont::load_ui_font_text(engine, "Player One");
assert!(text_load_handle.get_font_load_handles().is_empty());
assert!(text_load_handle.is_finished());글자의 조각 받기 청하기. (사람 이름처럼 그때그때 나오는 글자, 처음 보는 글자만. 원본 requestUiFontText)
- 받은 묶음이 없으면 아무것도 하지 않는다. 손잡이는 돌려주지 않는다.
Requests subsets for text. (text that comes up on the fly like person names, only characters not seen before. the original requestUiFontText)
- Does nothing if no group has been received. Returns no handle.
- engine&Engine
- 애셋을 받고 글꼴 얼굴을 올릴 엔진.Engine to receive assets with and register font faces on.
- text&str
- 쓸 글자. (앞서 청한 글자는 뺀다)Text to use. (characters requested earlier are skipped)
짝Counterpart: vanilla.js requestUiFontText
처음 불러오기를 기다리는 퓨처. (원본 await loadUiFont(묶음, 글자) 의 await 자리, load_ui_font 가 돌려준 손잡이를 await 하는 것과 같다)
- 기다리는 동안 프레임마다 update 를 부른다. 원본처럼 처음 글자를 다 올렸거나 wait_milliseconds 가 지나면 끝난다. (is_ui_font_ready)
Future that waits for the initial load. (the await of the original await loadUiFont(group, text), same as awaiting the handle returned by load_ui_font)
- Calls update every frame while waiting. As in the original, finishes once the initial text is all registered or wait_milliseconds passes. (is_ui_font_ready)
반환ReturnsUiFontLoadFuture is_ui_font_ready 가 참이 되면 끝나는 퓨처.Future that finishes when is_ui_font_ready becomes true.
처음 불러오기가 준비됐는지. (처음 글자의 조각을 다 받았거나 wait_milliseconds 가 지났으면 참, 원본 loadUiFont 의 기다림)
- 불러오기를 시작하지 않았거나 목록을 못 읽었으면 참이다. (시스템 글꼴로 이어 간다)
Whether the initial load is ready. (true once the subsets of the initial text have all arrived or wait_milliseconds has passed, the wait of the original loadUiFont)
- true if loading has not started or the list could not be read. (carries on with the system font)
반환Returnsbool 처음 불러오기가 준비됐으면 true.true if the initial load is ready.
불러온 UI 글꼴의 이름. (엔진의 글자 컴포넌트에 set_font_family 로 준다, 못 불러왔으면 None. 원본 readUiFontFace)
Name of the loaded UI font. (given to the engine's text component with set_font_family, None if it could not be loaded. the original readUiFontFace)
반환ReturnsOption<String> 처음 묶음을 받아 올렸으면 글꼴 이름. 아직이거나 못 불러왔으면 None.Font name once the initial group has been received and registered. None if not yet or it could not be loaded.
짝Counterpart: vanilla.js readUiFontFace
UI 글꼴 문자열. (굵기, 크기. 원본 buildUiFontString)
UI font string. (weight, size. the original buildUiFontString)
- font_weightu16
- 글자 굵기. (500, 700 같은 CSS 굵기)Font weight. (a CSS weight like 500, 700)
- font_sizef64
- 글자 크기. (픽셀)Font size. (pixels)
반환ReturnsString Canvas2D font 꼴 글. (500 16px "GameUI", sans-serif 꼴)Canvas2D font style text. (in the form 500 16px "GameUI", sans-serif)
짝Counterpart: vanilla.js buildUiFontString
UI 글꼴 설정. (불러오기 전에 부른다, None 인 칸은 그대로. 원본 configureUiFont)
- primary_group 을 주면 지금 고른 묶음도 그것으로 돌린다.
Sets the UI font. (call before loading, fields that are None stay unchanged. the original configureUiFont)
- Giving primary_group also switches the currently selected group to it.
- optionsUiFontOptions
- 바꿀 칸만 Some 으로 채운 설정.Settings with only the fields to change filled with Some.
짝Counterpart: vanilla.js configureUiFont
UI 글꼴 이름 반환. (원본 readUiFontFamily)
Returns the UI font name. (the original readUiFontFamily)
반환ReturnsString 올릴 글꼴 이름. (처음은 "GameUI", 불러오지 않았어도 돌려준다)Font name to register. (initially "GameUI", returned even if not loaded)
짝Counterpart: vanilla.js readUiFontFamily