resource/fontasset
글꼴 애셋. (원본 resource/fontasset.js)
- 원본은 FontFace 를 만들어 document.fonts 에 더한다. 그 뒤로 폰트 문자열("16px 이름")에서 그 이름을 쓴다.
- 러스트 판은 바이트를 받은 뒤 엔진이 다음 프레임 시작에 Graphic 의 글자 캐시에 이름으로 등록한다. WOFF, WOFF2 도 된다. (글자 캐시가 TTF 로 푼다)
- 원본 descriptors(굵기, 기울기, 글자 범위)는 FontFaceDescriptors 로 받는다. (load_font_with_descriptors, 굵기만이면 load_font_with_bold) 같은 이름에 굵기나 기울기가 다른 파일을 여러 개 올리면 글자 캐시가 CSS 처럼 골라 그린다. 진짜 기울인 얼굴이 있으면 가짜 기울임 대신 그것을 쓴다.
- unload 는 원본처럼 그 얼굴을 글꼴 목록에서 뺀다. (document.fonts.delete)
- load: 원본 load(assetPath) 처럼 파일 이름에서 확장자를 뗀 것을 패밀리 이름으로 load_font 한다. ("assets/DOSGothic.woff" 면 "DOSGothic")
- load_font_from_bytes: 이미 가진 글꼴 바이트로 읽는다. (원본 loadFontFromBytes, 서술자의 source_key 가 비면 이름을 쓴다)
- load_font 들은 원본처럼 await 할 수 있는 FontLoadHandle 을 돌려준다. 바이트가 오고 엔진이 글꼴 목록에 올리면 끝난다. (원본 await fontFace.load() 와 document.fonts.add 뒤, 그 뒤로 그 이름으로 그린다) 받기나 올리기에 실패하면 까닭으로 끝난다.
Font asset. (the original resource/fontasset.js)
- The original creates a FontFace and adds it to document.fonts. After that the name is used in font strings ("16px name").
- In the Rust version, after the bytes arrive the engine registers it by name in Graphic's text cache at the start of the next frame. WOFF, WOFF2 work too. (the text cache decodes them to TTF)
- The original descriptors (weight, style, character range) are taken as FontFaceDescriptors. (load_font_with_descriptors, load_font_with_bold for weight only) When several files with different weights or styles are registered under the same name, the text cache picks and draws like CSS. If a real italic face exists, it is used instead of fake slanting.
- unload removes that face from the font list as in the original. (document.fonts.delete)
- load: like the original load(assetPath), calls load_font with the file name minus its extension as the family name. ("DOSGothic" for "assets/DOSGothic.woff")
- load_font_from_bytes: reads from font bytes already in hand. (the original loadFontFromBytes, uses the name if the descriptor's source_key is empty)
- The load_font functions return a FontLoadHandle that can be awaited as in the original. It finishes once the bytes arrive and the engine registers it in the font list. (after the original await fontFace.load() and document.fonts.add, from then on it draws with that name) If receiving or registering fails, it finishes with the reason.
FontLoadHandlestruct traits Clone, Debug, IntoFuture
글꼴 받기 손잡이. (FontAsset 의 load_font 들, Engine::register_font_face_when_loaded 가 돌려준다. 원본 loadFont 의 Promise 자리)
- 엔진이 글꼴 목록에 올리면(또는 실패하면) 끝난다. 복제한 손잡이는 같은 올리기를 가리킨다.
Font fetch handle. (returned by FontAsset's load_font functions and Engine::register_font_face_when_loaded. Stands in for the Promise of the original loadFont)
- Finishes once the engine registers it in the font list (or fails). A cloned handle points to the same registration.
use vanilla::{Engine, EngineConfiguration, FontAsset};
let engine = Engine::new(EngineConfiguration::new());
let mut font_asset = FontAsset::new();
let font_load_handle = font_asset.load_font(engine, "Title", "examples/assets/missing.ttf");
assert!(font_load_handle.get_load_handle().is_failed());
assert!(!font_load_handle.is_finished());바이트 읽기 손잡이. (씬에 맡길 때)
Byte read handle. (for handing to a scene)
반환Returns&AssetLoadHandle 글꼴 파일 바이트의 읽기 손잡이.Load handle of the font file bytes.
끝났는지. (글꼴 목록에 올렸거나 실패했거나)
Whether it finished. (registered in the font list or failed)
반환Returnsbool 엔진이 글꼴 목록에 올렸거나 받기나 올리기에 실패했으면 true.true if the engine registered it in the font list or receiving or registering failed.
FontLoadFuturestruct traits Clone, Debug, Future
글꼴 받기를 기다리는 퓨처. (FontLoadHandle 을 await 하면 된다)
- 올리면 Ok(()), 받기나 올리기에 실패하면 Err(까닭)으로 끝난다.
Future that waits for a font fetch. (just await FontLoadHandle)
- Finishes with Ok(()) once registered, Err(reason) if receiving or registering fails.
use vanilla::{Engine, EngineConfiguration, FontAsset};
let engine = Engine::new(EngineConfiguration::new());
let mut font_asset = FontAsset::new();
let font_load_handle = font_asset.load_font_from_bytes(engine, "Pixel", vec![0, 1, 0, 0]);
let task_handle = engine.spawn_task(|_engine_context| async move {
let _ = font_load_handle.await;
});
assert!(!task_handle.is_finished());FontAssetstruct traits Default, Asset
글꼴 애셋.
- 바이트를 받으면 엔진이 다음 프레임 시작에 family 이름으로 글꼴 목록에 올린다. 그 뒤로 폰트 문자열("16px 이름")에서 그 이름을 쓴다.
Font asset.
- Once the bytes arrive, the engine registers it in the font list under the family name at the start of the next frame. After that the name is used in font strings ("16px name").
use vanilla::{Asset, Engine, EngineConfiguration, FontAsset, FontFaceDescriptors};
let engine = Engine::new(EngineConfiguration::new());
let mut font_asset = FontAsset::new();
font_asset.load_font_from_bytes_with_descriptors(engine, "Pixel", vec![0, 1, 0, 0], FontFaceDescriptors::create_with_bold(true));
assert!(font_asset.is_loaded());
assert_eq!(font_asset.get_family(), "Pixel");
assert!(font_asset.is_bold());
assert_eq!(font_asset.get_descriptors().source_key, "Pixel");
assert_eq!(engine.get_pending_font_face_count(), 1);
font_asset.unload(engine);
assert!(!font_asset.is_loaded());
assert_eq!(engine.get_pending_font_face_count(), 0);생성.
Constructor.
반환ReturnsFontAsset 요청 전의 빈 글꼴 애셋. (이름은 빈 글, 서술자는 FontFaceDescriptors::new())Empty font asset before a request. (the name is empty text, the descriptor is FontFaceDescriptors::new())
짝Counterpart: vanilla.js FontAsset.constructor
글꼴 읽기 요청. (원본 load(assetPath), 파일 이름에서 확장자를 뗀 것을 패밀리 이름으로 load_font 한다)
Requests a font read. (the original load(assetPath), calls load_font with the file name minus its extension as the family name)
- engine&Engine
- 글꼴을 받아 등록할 엔진.Engine that receives and registers the font.
- asset_path&str
- 글꼴 파일 경로. ("assets/DOSGothic.woff" 면 패밀리 이름은 "DOSGothic")Font file path. (the family name is "DOSGothic" for "assets/DOSGothic.woff")
반환ReturnsFontLoadHandle await 할 수 있는 글꼴 받기 손잡이. (받기나 올리기에 실패하면 까닭으로 끝난다)Font load handle that can be awaited. (finishes with the reason if receiving or registering fails)
짝Counterpart: vanilla.js FontAsset.load
pub fn load_font(&mut self, engine: &Engine, family: &str, asset_path: &str) -> FontLoadHandle#글꼴 읽기 요청. (원본 loadFont(family, assetPath). 다 오면 엔진이 family 이름으로 등록한다)
- 굵기 400, 기울이지 않음, 모든 글자의 얼굴이다. 이미 요청했으면 다시 하지 않고 그 손잡이를 돌려준다.
Requests a font read. (the original loadFont(family, assetPath). Once everything arrives the engine registers it under the family name)
- A face with weight 400, not italic, for all characters. If already requested, does not request again and returns that handle.
- engine&Engine
- 바이트를 부탁하고 글꼴을 올릴 엔진.Engine to ask for the bytes and register the font on.
- family&str
- 글꼴 이름. (폰트 문자열에서 쓸 이름)Font name. (the name used in font strings)
- asset_path&str
- 글꼴 파일 경로. (ttf, otf, woff, woff2. 데스크탑은 애셋 폴더 기준, 웹은 asset_base_url 기준)Font file path. (ttf, otf, woff, woff2. Relative to the asset folder on desktop, relative to asset_base_url on web)
반환ReturnsFontLoadHandle 엔진이 글꼴 목록에 올리면(또는 실패하면) 끝나는 손잡이.Handle that finishes once the engine registers it in the font list (or fails).
짝Counterpart: vanilla.js FontAsset.loadFont
pub fn load_font_with_bold(&mut self, engine: &Engine, family: &str, asset_path: &str, is_bold: bool) -> FontLoadHandle#굵은 글꼴 읽기 요청. (원본 descriptors 의 weight 자리)
- 이미 요청했으면 다시 하지 않고 그 손잡이를 돌려준다.
Requests a bold font read. (in place of weight in the original descriptors)
- If already requested, does not request again and returns that handle.
- engine&Engine
- 바이트를 부탁하고 글꼴을 올릴 엔진.Engine to ask for the bytes and register the font on.
- family&str
- 글꼴 이름.Font name.
- asset_path&str
- 글꼴 파일 경로. (데스크탑은 애셋 폴더 기준, 웹은 asset_base_url 기준)Font file path. (relative to the asset folder on desktop, relative to asset_base_url on web)
- is_boldbool
- true 면 굵기 700, false 면 400 의 얼굴로 올린다.If true, registers it as a weight 700 face, if false as 400.
반환ReturnsFontLoadHandle 엔진이 글꼴 목록에 올리면(또는 실패하면) 끝나는 손잡이.Handle that finishes once the engine registers it in the font list (or fails).
pub fn load_font_with_descriptors(&mut self, engine: &Engine, family: &str, asset_path: &str, mut descriptors: FontFaceDescriptors) -> FontLoadHandle#서술자를 주어 글꼴 읽기 요청. (원본 loadFont(family, assetPath, descriptors), 서술자의 source_key 가 비면 경로를 쓴다)
- 이미 요청했으면 다시 하지 않고 그 손잡이를 돌려준다. (원본도 fontFace 가 있으면 바로 끝난다)
Requests a font read with a descriptor. (the original loadFont(family, assetPath, descriptors), uses the path if the descriptor's source_key is empty)
- If already requested, does not request again and returns that handle. (the original also finishes right away if fontFace exists)
- engine&Engine
- 바이트를 부탁하고 글꼴을 올릴 엔진.Engine to ask for the bytes and register the font on.
- family&str
- 글꼴 이름.Font name.
- asset_path&str
- 글꼴 파일 경로. (데스크탑은 애셋 폴더 기준, 웹은 asset_base_url 기준)Font file path. (relative to the asset folder on desktop, relative to asset_base_url on web)
- descriptorsFontFaceDescriptors
- 굵기, 기울기, 글자 범위, 얼굴 열쇠. (열쇠가 비면 asset_path)Weight, style, character range, face key. (asset_path if the key is empty)
반환ReturnsFontLoadHandle 엔진이 글꼴 목록에 올리면(또는 실패하면) 끝나는 손잡이.Handle that finishes once the engine registers it in the font list (or fails).
use vanilla::{Engine, EngineConfiguration, FontAsset, FontFaceDescriptors};
let engine = Engine::new(EngineConfiguration::new());
let mut descriptors = FontFaceDescriptors::new();
descriptors.is_italic = true;
descriptors.unicode_range_list = vec![(0x0020, 0x007e)];
let mut font_asset = FontAsset::new();
let font_load_handle = font_asset.load_font_with_descriptors(engine, "Body", "examples/assets/missing.ttf", descriptors);
assert_eq!(font_asset.get_descriptors().source_key, "examples/assets/missing.ttf");
assert!(font_asset.get_descriptors().is_italic);
assert!(!font_asset.is_bold());
assert!(font_load_handle.get_load_handle().is_failed());pub fn load_font_from_bytes(&mut self, engine: &Engine, family: &str, bytes: Vec<u8>) -> FontLoadHandle#이미 가진 글꼴 바이트로 읽기. (ttf, otf, woff, woff2, 원본 loadFontFromBytes, 엔진이 다음 프레임 시작에 family 이름으로 올린다)
- 서술자는 FontFaceDescriptors::new() 이고 얼굴 열쇠는 family 다. 이미 요청했으면 다시 하지 않고 그 손잡이를 돌려준다.
Reads from font bytes already in hand. (ttf, otf, woff, woff2, the original loadFontFromBytes, the engine registers it under the family name at the start of the next frame)
- The descriptor is FontFaceDescriptors::new() and the face key is family. If already requested, does not request again and returns that handle.
- engine&Engine
- 글꼴을 올릴 엔진.Engine to register the font on.
- family&str
- 글꼴 이름.Font name.
- bytesVec<u8>
- 글꼴 파일 바이트.Font file bytes.
반환ReturnsFontLoadHandle 엔진이 글꼴 목록에 올리면(또는 실패하면) 끝나는 손잡이.Handle that finishes once the engine registers it in the font list (or fails).
짝Counterpart: vanilla.js FontAsset.loadFontFromBytes
pub fn load_font_from_bytes_with_descriptors(&mut self, engine: &Engine, family: &str, bytes: Vec<u8>, mut descriptors: FontFaceDescriptors) -> FontLoadHandle#서술자를 주어 이미 가진 글꼴 바이트로 읽기. (원본 loadFontFromBytes(family, bytes, descriptors))
- 이미 요청했으면 다시 하지 않고 그 손잡이를 돌려준다.
Reads from font bytes already in hand with a descriptor. (the original loadFontFromBytes(family, bytes, descriptors))
- If already requested, does not request again and returns that handle.
- engine&Engine
- 글꼴을 올릴 엔진.Engine to register the font on.
- family&str
- 글꼴 이름.Font name.
- bytesVec<u8>
- 글꼴 파일 바이트.Font file bytes.
- descriptorsFontFaceDescriptors
- 굵기, 기울기, 글자 범위, 얼굴 열쇠. (열쇠가 비면 family, 읽기 손잡이의 경로도 이 열쇠다)Weight, style, character range, face key. (family if the key is empty, and the load handle's path is this key too)
반환ReturnsFontLoadHandle 엔진이 글꼴 목록에 올리면(또는 실패하면) 끝나는 손잡이.Handle that finishes once the engine registers it in the font list (or fails).
애셋 내리기. (원본 unload: 글꼴 목록에서 이 얼굴을 뺀다)
- 요청 전이면 아무것도 하지 않는다. 아직 바이트를 기다리는 등록은 바로 빼고, 올린 얼굴은 다음 프레임 시작에 뺀다.
Unloads the asset. (the original unload: removes this face from the font list)
- Does nothing before a request. A registration still waiting for bytes is removed right away, and a registered face is removed at the start of the next frame.
- engine&Engine
- 얼굴을 뺄 엔진.Engine to remove the face from.
짝Counterpart: vanilla.js FontAsset.unload
얼굴 서술자.
Face descriptors.
반환Returns&FontFaceDescriptors 요청할 때 준 서술자. (열쇠를 채운 것, 요청 전이면 FontFaceDescriptors::new())Descriptor given at request. (with the key filled in, FontFaceDescriptors::new() before a request)
글꼴 이름.
Font name.
반환Returns&str 요청할 때 준 글꼴 이름. 요청 전이면 빈 글.Font name given at request. Empty text before a request.
짝Counterpart: vanilla.js FontAsset.family
굵은 글꼴인지.
Whether it is a bold font.
반환Returnsbool 서술자의 굵기 범위 처음이 600 이상이면 true.true if the start of the descriptor's weight range is 600 or more.