Skip to main content

VectorFont

Struct VectorFont 

Source
pub struct VectorFont {
    face: Face<'static>,
    fallbacks: Vec<Face<'static>>,
    cache: BTreeMap<(char, u32), CachedGlyph>,
    color_cache: BTreeMap<(char, u32, u32, u32), CachedColorGlyph>,
    advance_cache: BTreeMap<(char, u32), u32>,
}
Expand description

動的フォントキャッシュとフォントロードを管理するマネージャ

Fields§

§face: Face<'static>§fallbacks: Vec<Face<'static>>

フォールバックフォント(プライマリにグリフが無い文字をこの順で補う)。

§cache: BTreeMap<(char, u32), CachedGlyph>§color_cache: BTreeMap<(char, u32, u32, u32), CachedColorGlyph>§advance_cache: BTreeMap<(char, u32), u32>

Implementations§

Source§

impl VectorFont

Source

pub fn new(font_bytes: &'static [u8]) -> Result<Self, FaceParsingError>

Source

pub fn new_with_fallbacks( font_bytes: &'static [u8], fallback_bytes: &[&'static [u8]], ) -> Result<Self, FaceParsingError>

プライマリ + フォールバック群でフォントを構築する。 fallback_bytes の各フォントは、プライマリにグリフが無い文字を順に補う。 パース失敗したフォールバックは無視する(プライマリが失敗したらエラー)。

Source

pub fn set_primary( &mut self, font_bytes: &'static [u8], ) -> Result<(), FaceParsingError>

新しいプライマリフォントへ切り替える。旧プライマリはフォールバック チェーンの先頭へ退避するため、既存のグリフカバレッジは失われない (@font-faceで実行時に取得したフォントを、ページ全体で使う 主要フォントとして採用する用途。2026-07-22新設)。キャッシュ済み グリフは全てプライマリ変更前のフォントに基づくため破棄する。

Source

pub fn primary_has_glyph(&self, c: char) -> bool

指定されたサイズでグリフをラスタライズ(またはキャッシュから取得)します 【2026-08-05診断】この符号位置の字形を持っているか。 プライマリと代替の両方を見る(get_glyph と同じ探索)。 【2026-08-05】プライマリだけが字形を持つか。

Google Fonts は unicode-range でファイルを分割して配信するため、 「ウェイト 700 の Noto Sans JP」が Latin だけのサブセットということがある。 ウェイト指定で選んだフォントがその文字を持たないと、 見出しの漢字が欠ける(実測: 「開発アプリケーション」→「□ 発プリケーション」)。 選ぶ前にこれで確かめる。

Source

pub fn has_glyph(&self, c: char) -> bool

Source

pub fn get_glyph(&mut self, c: char, size_px: u32) -> Option<&CachedGlyph>

Source

pub fn get_color_glyph( &mut self, c: char, size_px: u32, fg_color: u32, bg_color: u32, ) -> Option<&CachedColorGlyph>

指定されたサイズ、文字色、背景色でアルファブレンド済みのカラーグリフを取得(またはキャッシュから取得)します

Source

pub fn get_glyph_advance(&mut self, c: char, size_px: u32) -> u32

指定されたサイズでグリフのアドバンス(幅)のみを高速に取得(またはキャッシュから取得)します。 レイアウトの折り返し計算等で重いラスタライズ(Even-Odd法)を回避するために使用します。

Source

pub fn get_string_width(&mut self, s: &str, size_px: u32) -> u32

指定したサイズでの文字列全体のピクセル幅(advance合計)を計算します

Source

pub fn get_string_width_ls(&mut self, s: &str, size_px: u32, ls: i32) -> u32

letter-spacing 対応版。各文字の advance に ls(px, 負も可) を加算する。

Source

pub fn get_string_width_ls_ws( &mut self, s: &str, size_px: u32, ls: i32, ws: i32, ) -> u32

letter-spacing + word-spacing 対応版。半角スペース1文字ごとに ws(px, 負も可) も加算する。

Source

pub fn get_string_wrapped_size( &mut self, s: &str, size_px: u32, max_width: u32, ) -> (u32, u32)

折返し後の (最大行幅, 全体高さ) を返す。

重要: この行分割規則は web_engine.rs flatten_layout のテキスト折返し ('\n' は強制改行・行頭/行末禁則・改行時に先頭文字を即消費) と 完全に同一 でなければならない。ここがズレると layout が計算する 段落高さと flatten が生成する行数が食い違い、後続要素 (


等) が テキストに重なる。どちらかを変更する際は必ず両方を同期すること。

Source

pub fn get_string_wrapped_size_ls( &mut self, s: &str, size_px: u32, max_width: u32, ls: i32, ) -> (u32, u32)

letter-spacing 対応版。各文字 advance に ls を加算して折返し計算する。

Source

pub fn get_string_wrapped_size_ls_ws( &mut self, s: &str, size_px: u32, max_width: u32, ls: i32, ws: i32, ) -> (u32, u32)

Source

pub fn get_string_wrapped_size_ext( &mut self, s: &str, size_px: u32, max_width: u32, ls: i32, ws: i32, word_break_all: bool, white_space_pre_wrap: bool, ) -> (u32, u32)

word-break / white-space 対応版

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.