vanilladocs
vanillapunch.com
API / platform/desktop/systemfont

platform/desktop/systemfont

데스크탑 시스템 글꼴 찾기. (글꼴 이름의 파일, 글꼴에 없는 글자를 그릴 대체 글꼴)

  • 원본에 없는 파일이다. 원본은 브라우저가 CSS 글꼴 이름을 운영체제 글꼴로 찾고, 글꼴 목록에 없는 글자는 운영체제의 대체 글꼴로 그린다. 크롬은 맥에서 CoreText, 윈도우에서 DirectWrite, 리눅스에서 fontconfig 로 찾는다. 러스트 판 데스크탑도 같은 API 로 파일을 찾아 글자 캐시에 올린다.
  • find_family_font_file: 글꼴 이름, 굵기, 기울기로 파일과 얼굴을 찾는다. 그 이름의 글꼴이 없으면 None 이다. (CSS 처럼 다른 글꼴로 바꿔 주지 않는다)
  • 맥: system-ui, BlinkMacSystemFont 는 시스템 UI 글꼴(CTFontCreateUIFontForLanguage, 기울이면 CTFontCreateCopyWithSymbolicTraits 의 기울임 특성, 크롬 font_matcher_mac.mm 의 MatchSystemUIFont), 그 밖은 이름과 굵기 특성으로 지은 글꼴 서술자. -apple-system 과 ui-serif, ui-sans-serif, ui-monospace, ui-rounded 는 크롬이 모르는 이름이라 None 이다. (사파리만 안다. 맥 크롬 158 의 Canvas2D 에서 "16px -apple-system" 은 기본 글꼴로 그려진다)
  • 윈도우: system-ui 는 크롬처럼 메뉴 글꼴(NONCLIENTMETRICS 의 lfMenuFont, 읽지 못하면 Segoe UI), 그 밖은 시스템 글꼴 모음의 이름(FindFamilyName)과 GetFirstMatchingFont.
  • 리눅스: fontconfig 의 FcFontMatch. 크롬(Skia SkFontConfigInterface_direct.cpp 의 isAcceptableMatch)처럼 찾은 글꼴의 이름이 청한 이름이나 설정을 거친 이름과 같거나, 치수가 같은 대체 글꼴(Arial 과 Liberation Sans 같은 표)이거나, 청한 이름이 sans, serif, monospace 일 때만 받는다.
  • 일반 이름(serif, sans-serif, monospace, cursive, fantasy, math, -webkit-body 는 표준 글꼴)은 크롬의 기본 글꼴 표대로 글꼴 이름으로 바꾼 뒤 찾는다. (resolve_generic_family_name) 큰따옴표로 감싼 이름("\"monospace\"")은 크롬처럼 바꾸지 않고 그 글자의 글꼴을 찾는다. (맥과 윈도우에는 그 이름의 글꼴이 없고, 리눅스 fontconfig 는 monospace 를 받는다) 표는 크로미엄 chrome/app/resources/locale_settings_<운영체제>.grd 의 IDS_*_FONT_FAMILY 와 그 언어 번역(platform_locale_settings/*.xtb)이다. 크롬은 브라우저 언어(화면 언어)로 Common(Zyyy) 스크립트 값을 정하고, 문서 lang 이 없는 캔버스는 기본 로캘(브라우저 언어)의 스크립트로 글꼴을 고른다. 그 스크립트의 따로 정한 값은 브라우저 언어의 스크립트라 등록하지 않으므로(prefs_tab_helper.cc 의 RegisterProfilePrefs) 결국 Common 값을 쓴다. 원본이 글을 굽는 캔버스는 문서에 붙이지 않아 문서의 lang 을 바꿔도 그대로다. (맥 크롬 158 로 확인) 러스트 판은 시스템 선호 언어에서 크롬이 고르는 화면 언어를 찾아(read_browser_locale) 같은 표를 쓴다. 예: 맥 한국어는 serif AppleMyungjo, sans-serif Apple SD Gothic Neo, monospace Menlo, 영어는 Times, Helvetica, Menlo. 윈도우 한국어는 serif Batang, sans-serif Malgun Gothic.
  • find_fallback_font_file: 글(글자 묶음 하나)을 그릴 대체 글꼴을 운영체제가 고르게 한다.
  • 맥: 시스템 UI 글꼴에서 CTFontCreateForString. (크롬 맥의 글꼴 대체와 같은 API) 색 이모지를 바라면 Apple Color Emoji 를 먼저 본다.
  • 윈도우: IDWriteFontFallback.MapCharacters (기본 이름 Segoe UI, 사용자 언어)
  • 리눅스: 글자를 담은 charset 으로 FcFontSort 해 그 글자를 가진 첫 글꼴. 색 이모지를 바라면 color 속성을 건다.
  • 돌려주는 FontFileSource 의 얼굴 번호는 운영체제가 알려 주면(윈도우, 리눅스) 넣고, 맥은 PostScript 이름을 넣어 글꼴을 읽을 때 맞는 얼굴을 찾는다. 가변 글꼴(맥 시스템 UI 글꼴 SFNS 같은)의 굵기는 글자 캐시가 축 값으로 만든다.

Desktop system font lookup. (the file for a font name, fallback fonts to draw characters missing from the fonts)

  • A file not in the original. In the original the browser finds CSS font names among OS fonts, and draws characters not in the font list with the OS fallback font. Chrome finds them with CoreText on Mac, DirectWrite on Windows and fontconfig on Linux. The Rust version on desktop also finds files with the same APIs and registers them in the text cache.
  • find_family_font_file: finds the file and face by font name, weight and italic. None if there is no font with that name. (does not substitute another font like CSS)
  • Mac: system-ui, BlinkMacSystemFont are the system UI font (CTFontCreateUIFontForLanguage, the italic trait of CTFontCreateCopyWithSymbolicTraits when italic, MatchSystemUIFont in Chrome's font_matcher_mac.mm), others a font descriptor built from the name and weight traits. -apple-system and ui-serif, ui-sans-serif, ui-monospace, ui-rounded are names Chrome does not know, so None. (only Safari knows them. In Canvas2D of Chrome 158 on Mac, "16px -apple-system" is drawn with the default font)
  • Windows: system-ui is the menu font like Chrome (lfMenuFont of NONCLIENTMETRICS, Segoe UI if it cannot be read), others the name in the system font collection (FindFamilyName) and GetFirstMatchingFont.
  • Linux: fontconfig's FcFontMatch. Like Chrome (isAcceptableMatch in Skia SkFontConfigInterface_direct.cpp), accepts only if the found font's name equals the requested name or the name after configuration, or it is a metric-compatible substitute (a table like Arial and Liberation Sans), or the requested name is sans, serif, monospace.
  • Generic names (serif, sans-serif, monospace, cursive, fantasy, math, and -webkit-body as the standard font) are turned into font names by Chrome's default font table before searching. (resolve_generic_family_name) A name wrapped in double quotes ("\"monospace\"") is not converted, like Chrome, and the font spelled that way is looked up. (Mac and Windows have no font of that name, Linux fontconfig accepts monospace) The table is IDS_*_FONT_FAMILY of Chromium chrome/app/resources/locale_settings_<os>.grd and its translations per language (platform_locale_settings/*.xtb). Chrome sets the Common (Zyyy) script value by the browser language (UI language), and a canvas without a document lang picks fonts by the script of the default locale (browser language). The separately set value for that script is not registered because it is the browser language's script (RegisterProfilePrefs in prefs_tab_helper.cc), so in the end the Common value is used. The canvas the original bakes text on is not attached to the document, so changing the document's lang leaves it as is. (checked with Chrome 158 on Mac) The Rust version finds the UI language Chrome would pick from the system preferred languages (read_browser_locale) and uses the same table. Example: Mac Korean is serif AppleMyungjo, sans-serif Apple SD Gothic Neo, monospace Menlo, English is Times, Helvetica, Menlo. Windows Korean is serif Batang, sans-serif Malgun Gothic.
  • find_fallback_font_file: lets the OS pick a fallback font to draw text (one grapheme cluster).
  • Mac: CTFontCreateForString on the system UI font. (the same API as Chrome Mac's font fallback) If color emoji is wanted, checks Apple Color Emoji first.
  • Windows: IDWriteFontFallback.MapCharacters (base name Segoe UI, user language)
  • Linux: the first font with that character from FcFontSort with a charset containing it. If color emoji is wanted, sets the color property.
  • The face index of the returned FontFileSource is included when the OS reports it (Windows, Linux), and on Mac the PostScript name is included to find the right face when reading the font. The weight of variable fonts (such as SFNS, the Mac system UI font) is made by the text cache from axis values.
예제Example일반 이름 sans-serif 의 굵은 글꼴 파일 찾기Find the bold font file for the generic name sans-serif
use vanilla::platform::desktop::systemfont::{find_family_font_file, resolve_generic_family_name, GenericFamily};

assert_eq!(GenericFamily::from_family_name("Sans-Serif"), Some(GenericFamily::SansSerif));
assert_eq!(GenericFamily::from_family_name("Helvetica"), None);
if let Some(family_name) = resolve_generic_family_name(GenericFamily::SansSerif) {
	if let Some(source) = find_family_font_file(&family_name, 700, false) {
		assert!(source.path.exists());
	}
}

함수Functions

함수functionpub fn read_double_click_seconds() -> f32#0.4.0 부터since 0.4.0소스source

이어 누르기(두 번 누르기)로 볼 시간. (초, 입력 필드의 두 번, 세 번 누르기)

  • 맥: 크롬은 NSEvent clickCount 를 쓰고, 그 시간은 시스템 설정의 두 번 클릭 속도인 NSEvent.doubleClickInterval 이다.
  • 윈도우, 리눅스: 크롬 aura 는 운영체제 값을 읽지 않고 ui/events/event_constants.h 의 kDoubleClickTimeMs 500 을 쓴다.

Time within which presses count as repeated (double clicks). (seconds, for double and triple clicks in input fields)

  • macOS: Chrome uses NSEvent clickCount, and the time is NSEvent.doubleClickInterval, the double-click speed in System Settings.
  • Windows, Linux: Chrome aura does not read the OS value and uses kDoubleClickTimeMs 500 from ui/events/event_constants.h.

반환Returnsf32 이어 누르기로 볼 시간. (초, 맥은 시스템 설정 값, 읽지 못하거나 다른 운영체제면 0.5)Time within which presses count as repeated. (seconds, the System Settings value on macOS, 0.5 if it cannot be read or on other operating systems)

함수functionpub fn is_overlay_scrollbar_preferred() -> bool#0.4.0 부터since 0.4.0소스source

시스템이 얹는 스크롤 막대를 바라는지. (맥 시스템 설정의 스크롤 막대 보기, 크롬 os_settings_provider_mac.mm 의 PrefersOverlayScrollbars)

  • 맥: NSScroller.preferredScrollerStyle 이 NSScrollerStyleOverlay(1) 이면 참. (자동이면 마우스와 트랙패드에 따라 시스템이 정한다)
  • 윈도우, 리눅스: 크롬은 얹는 막대 기능(kOverlayScrollbar)이 꺼져 있어 늘 거짓.

Whether the system prefers overlay scroll bars. (Show scroll bars in macOS System Settings, PrefersOverlayScrollbars in Chrome's os_settings_provider_mac.mm)

  • macOS: true if NSScroller.preferredScrollerStyle is NSScrollerStyleOverlay (1). (when automatic, the system decides based on the mouse and trackpad)
  • Windows, Linux: always false because Chrome's overlay scroll bar feature (kOverlayScrollbar) is off.

반환Returnsbool 얹는 스크롤 막대를 바라면 true. (윈도우, 리눅스는 늘 false)true if overlay scroll bars are preferred. (always false on Windows and Linux)

함수functionpub fn find_family_font_file(family_name: &str, weight: u16, is_italic: bool) -> Option<FontFileSource>#0.4.0 부터since 0.4.0소스source

글꼴 이름으로 파일 찾기. (CSS 글꼴 이름 하나, 일반 이름은 크롬 기본 글꼴 표의 이름으로 바꿔 찾는다. 없으면 None)

  • 큰따옴표로 감싼 이름은 일반 이름과 같은 글자라도 바꾸지 않고 그 이름의 글꼴을 찾는다. (크롬 FontSelector::FamilyNameFromSettings 는 따옴표 친 이름을 기본 글꼴 표로 바꾸지 않고, FontCache 가 그 글자로 찾는다)

Finds a file by font name. (one CSS font name, generic names are converted to names from Chrome's default font table before searching. None if not found)

  • A name wrapped in double quotes is not converted even when spelled like a generic name, and the font of that name is looked up. (Chrome's FontSelector::FamilyNameFromSettings does not convert quoted names through the default font table, and FontCache looks up that spelling)
family_name&str
글꼴 이름 하나. (앞뒤 빈칸은 뗀다, "\"monospace\"" 처럼 큰따옴표로 감싸면 글꼴 이름)One font name. (leading and trailing spaces are trimmed, wrapped in double quotes like "\"monospace\"" it is a font name)
weightu16
굵기. (CSS font-weight, 100 ~ 900, 400 이 보통)Weight. (CSS font-weight, 100 ~ 900, 400 is normal)
is_italicbool
기울인 얼굴을 찾으려면 true.true to find the italic face.

반환ReturnsOption<FontFileSource> 찾은 파일과 얼굴. 이름이 비었거나, 그 이름의 글꼴이 없거나, 일반 이름에 맞는 글꼴이 없으면 None.The found file and face. None if the name is empty, there is no font with that name, or no font matches the generic name.

예제Example이름으로 찾고 없으면 대체 글꼴로Find by name, and fall back to a fallback font if missing
use vanilla::platform::{find_fallback_font_file, find_family_font_file};

let source = find_family_font_file("NoSuchFamily", 400, false).or_else(|| find_fallback_font_file("A", 400, false, false));
if let Some(source) = source {
	assert!(source.path.exists());
}
assert!(find_family_font_file("  ", 400, false).is_none());
assert!(find_family_font_file("\"monospace\"", 400, false).is_none() || find_family_font_file("monospace", 400, false).is_some());
함수functionpub fn list_family_font_faces(family_name: &str) -> Vec<FamilyFontFace>#0.4.0 부터since 0.4.0소스source

글꼴 이름의 모든 굵기, 기울기 얼굴 나열. (CSS 굵기 규칙으로 얼굴을 고르는 후보, 맥 CoreText 의 가족 얼굴, 윈도우 DirectWrite 의 가족 글꼴, 리눅스 fontconfig 의 굵기)

Lists every weight and slant face of a font name. (candidates for picking a face with the CSS weight rule: the family faces of Mac CoreText, the family fonts of Windows DirectWrite, the weights of Linux fontconfig)

family_name&str
글꼴 이름 하나. (find_family_font_file 과 같다)One font name. (same as find_family_font_file)

반환ReturnsVec<FamilyFontFace> 얼굴 목록. 이름의 글꼴이 없거나 얼굴을 나열하지 못하는 이름(맥 system-ui)이면 빈 목록.Face list. Empty if the named font does not exist or the name cannot list faces (Mac system-ui).

예제Example굵기와 기울기 얼굴Weight and slant faces
use vanilla::platform::list_family_font_faces;

for face in list_family_font_faces("Helvetica Neue") {
	assert!((100..=900).contains(&face.weight));
	assert!(face.source.path.exists());
}
assert!(list_family_font_faces("NoSuchFamily").is_empty());
함수functionpub fn find_fallback_font_file(text: &str, weight: u16, is_italic: bool, is_color_wanted: bool) -> Option<FontFileSource>#0.4.0 부터since 0.4.0소스source

글을 그릴 대체 글꼴 파일 찾기. (운영체제가 고른다, is_color_wanted 면 색 이모지 글꼴을 먼저)

Finds a fallback font file to draw text. (picked by the OS, color emoji fonts first if is_color_wanted)

text&str
그릴 글. (글자 묶음 하나)Text to draw. (one grapheme cluster)
weightu16
굵기. (CSS font-weight)Weight. (CSS font-weight)
is_italicbool
기울인 얼굴을 바라면 true.true if an italic face is wanted.
is_color_wantedbool
색 이모지 글꼴을 먼저 보려면 true.true to check color emoji fonts first.

반환ReturnsOption<FontFileSource> 운영체제가 고른 파일과 얼굴. 글이 비었거나 고른 것이 없으면 None.File and face picked by the OS. None if the text is empty or nothing was picked.

함수functionpub fn find_last_resort_font_file() -> Option<(FontFileSource, String)>#0.4.0 부터since 0.4.0소스source

마지막 대체 글꼴 파일. (크롬 FontCache::GetLastResortFallbackFont, 글꼴 이름도 돌려준다. 없으면 None)

  • 문서에 붙이지 않은 캔버스의 폰트 문자열에서 글꼴에 대는 단위(em 밖의 ex, ch, cap, ic, lh)를 셀 때 부모 글꼴이 된다. (맥 크롬 158 에서 Times 의 치수로 확인)
  • 맥: Times, 없으면 Lucida Grande. (font_cache_mac.mm)
  • 윈도우, 리눅스: 이름 없음(운영체제 기본), Sans, Arial, 윈도우는 그 뒤 MS UI Gothic, Microsoft Sans Serif, Segoe UI, Calibri, Times New Roman, Courier New. (font_cache_skia.cc)

Last resort fallback font file. (Chrome FontCache::GetLastResortFallbackFont, also returns the font name. None if not found)

  • It becomes the parent font when computing font-relative units (ex, ch, cap, ic, lh besides em) in the font string of a canvas not attached to a document. (checked with Times metrics in Chrome 158 on Mac)
  • Mac: Times, or Lucida Grande if missing. (font_cache_mac.mm)
  • Windows, Linux: no name (OS default), Sans, Arial, and on Windows then MS UI Gothic, Microsoft Sans Serif, Segoe UI, Calibri, Times New Roman, Courier New. (font_cache_skia.cc)

반환ReturnsOption<(FontFileSource, String)> (찾은 파일과 얼굴, 목록의 글꼴 이름). 목록의 어느 이름도 찾지 못하면 None.(found file and face, font name from the list). None if no name in the list could be found.

함수functionpub fn read_last_resort_family_name() -> Option<String>#0.4.0 부터since 0.4.0소스source

마지막 대체 글꼴의 이름. (깔린 첫 이름, 이름 없음(운영체제 기본)은 넘긴다. 처음 한 번 찾는다, 없으면 None)

  • 글자 캐시가 시스템 대체 글꼴 뒤에 이 글꼴을 둔다. (크롬 FontFallbackIterator 의 마지막 단계)

Name of the last resort fallback font. (the first installed name, skipping no name (OS default). Looked up once at first, None if not found)

  • The text cache places this font after the system fallback font. (the last step of Chrome's FontFallbackIterator)

반환ReturnsOption<String> 깔린 첫 이름. 목록의 이름이 하나도 깔려 있지 않으면 None. (스레드마다 처음 찾은 값을 그대로 쓴다)The first installed name. None if no name in the list is installed. (each thread keeps using the value found first)

함수functionpub fn read_browser_locale() -> String#0.4.0 부터since 0.4.0소스source

크롬이 고르는 화면 언어. (시스템 선호 언어 차례에서 크롬에 번역이 있는 첫 언어, 없으면 "en")

  • 언어 부분으로 맞춘다. 중국어는 번체(Hant)나 대만, 홍콩, 마카오면 zh-TW, 아니면 zh-CN. 옛 이름 iw 는 he, tl 은 fil, in 은 id, nb 는 no 다. (l10n_util 의 별칭)
  • 글꼴 표가 언어마다 다른 것은 맥 ar, fa, he, ja, ko, zh-CN, zh-TW, 윈도우 bn, ja, ko, th, zh-CN, zh-TW, 리눅스 bn, ja, ko, th 뿐이다.

UI language Chrome picks. (the first language in the system preferred language order that Chrome has a translation for, "en" if none)

  • Matches by the language part. Chinese is zh-TW if Traditional (Hant) or Taiwan, Hong Kong, Macau, otherwise zh-CN. The old names iw is he, tl is fil, in is id, nb is no. (aliases of l10n_util)
  • The only languages whose font tables differ are Mac ar, fa, he, ja, ko, zh-CN, zh-TW, Windows bn, ja, ko, th, zh-CN, zh-TW, Linux bn, ja, ko, th.

반환ReturnsString 크롬 화면 언어 이름. ("ko", "en", "zh-TW" 같은, 맞는 것이 없으면 "en")Chrome UI language name. (such as "ko", "en", "zh-TW", "en" if nothing matches)

함수functionpub fn resolve_generic_family_name(generic_family: GenericFamily) -> Option<String>#0.4.0 부터since 0.4.0소스source

일반 이름 → 글꼴 이름. (크롬 GenericFontFamilySettings::Get 과 같은 값, 표가 없는 운영체제는 None)

  • 쉼표로 시작하는 목록은 깔린 첫 글꼴, 하나도 없으면 첫 이름이다. (gfx::FontList::FirstAvailableOrFirst)
  • 맥: monospace 가 Osaka 면 Osaka-Mono. (generic_font_family_settings.cc)
  • 윈도우: monospace 가 Courier 로 시작하고 ClearType 이 켜져 있으면 Consolas. (prefs_tab_helper.cc 의 ShouldUseAlternateDefaultFixedFont)

Generic name → font name. (the same value as Chrome GenericFontFamilySettings::Get, None on OSes without a table)

  • A comma-separated list gives the first installed font, or the first name if none is installed. (gfx::FontList::FirstAvailableOrFirst)
  • Mac: if monospace is Osaka, Osaka-Mono. (generic_font_family_settings.cc)
  • Windows: if monospace starts with Courier and ClearType is on, Consolas. (ShouldUseAlternateDefaultFixedFont in prefs_tab_helper.cc)
generic_familyGenericFamily
일반 이름의 종류.Kind of generic name.

반환ReturnsOption<String> 고른 글꼴 이름. 표가 없는 운영체제이거나 그 칸의 값이 비었으면 None. (스레드마다 처음 고른 값을 그대로 쓴다)Picked font name. None on an OS without a table or if that entry's value is empty. (each thread keeps using the value picked first)

GenericFamilyenum traits Clone, Copy, Debug, PartialEq, Eq

소스source

CSS 일반 글꼴 이름의 종류. (크롬 GenericFontFamilySettings 의 종류, 표의 칸 차례와 같다)

Kind of CSS generic font name. (the kinds of Chrome GenericFontFamilySettings, in the same order as the table columns)

이름Name설명Description
Standard기본 글꼴. (표의 첫 칸, 일반 이름 -webkit-body 가 이것이다. 크롬 FontBuilder::GenericFontFamilyName 이 표준 글꼴 이름을 준다)Standard font. (the first column of the table, the generic name -webkit-body is this one. Chrome's FontBuilder::GenericFontFamilyName gives the standard font name)
Serifserif.
SansSerifsans-serif.
Monospacemonospace.
Cursivecursive.
Fantasyfantasy.
Mathmath.
정적staticpub fn from_family_name(family_name: &str) -> Option<GenericFamily>#0.4.0 부터since 0.4.0소스source

일반 이름 → 종류. (serif, sans-serif, monospace, cursive, fantasy, math, -webkit-body 는 Standard, 대소문자를 가리지 않는다. 크롬 font_selector.cc 가 아는 이름만, 아니면 None)

Generic name → kind. (serif, sans-serif, monospace, cursive, fantasy, math, -webkit-body is Standard, case-insensitive. Only names Chrome's font_selector.cc knows, otherwise None)

family_name&str
CSS 글꼴 이름 하나. (앞뒤 빈칸은 뗀다)One CSS font name. (leading and trailing spaces are trimmed)

반환ReturnsOption<GenericFamily> 그 일반 이름의 종류. 일반 이름이 아니면 None. (system-ui 같은 이름도 None)Kind of that generic name. None if it is not a generic name. (names like system-ui are None too)