Overview#
Implement @font-face support to load and parse web fonts, using the existing text crate for font parsing and net crate for network fetching.
Requirements#
Parsing#
- Parse
@font-facerule with descriptors:font-family: the family name to registersrc:url()references (WOFF2 not required initially; TTF/OTF via URL)font-weight:normal,bold, or numeric (100-900)font-style:normal,italic,obliquefont-display:auto,block,swap,fallback,optionalunicode-range(optional, can defer)
Font Loading#
- Fetch font files via
netcrate when@font-facerules are encountered - Support
url()sources (absolute and relative URLs) - Implement font loading states: loading → loaded / failed
font-displaycontrols rendering behavior during load:swap: use fallback immediately, swap when loadedblock: invisible text briefly, then fallbackfallback: short block period, short swap periodoptional: very short block period, no swap
Font Registration#
- Parse downloaded font bytes with
textcrate's OTF/TTF parser - Register the font under the declared
font-familyname - Integrate with font matching: when layout requests a font-family, check @font-face fonts before system fonts
- Match by weight and style
Integration#
- Extend CSS
@font-faceparsing incrates/css/ - Add font loading to resource loader in
crates/browser/orcrates/net/ - Integrate with font discovery in
crates/text/ - Trigger relayout when web fonts finish loading
Acceptance Criteria#
-
@font-face { font-family: "MyFont"; src: url(...); }parses correctly - Font files are fetched from URLs
- Downloaded fonts are parsed and available for text rendering
-
font-family: "MyFont"in CSS matches the web font - Fallback to system font works when web font fails to load
-
font-display: swapshows fallback then swaps - Relayout occurs when web font finishes loading
- All existing tests continue to pass
- New unit tests for @font-face parsing and font matching