we (web engine): Experimental web browser project to understand the limits of Claude

@font-face: load and parse web fonts #125

open opened by pierrelf.com

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-face rule with descriptors:
    • font-family: the family name to register
    • src: url() references (WOFF2 not required initially; TTF/OTF via URL)
    • font-weight: normal, bold, or numeric (100-900)
    • font-style: normal, italic, oblique
    • font-display: auto, block, swap, fallback, optional
    • unicode-range (optional, can defer)

Font Loading#

  • Fetch font files via net crate when @font-face rules are encountered
  • Support url() sources (absolute and relative URLs)
  • Implement font loading states: loading → loaded / failed
  • font-display controls rendering behavior during load:
    • swap: use fallback immediately, swap when loaded
    • block: invisible text briefly, then fallback
    • fallback: short block period, short swap period
    • optional: very short block period, no swap

Font Registration#

  • Parse downloaded font bytes with text crate's OTF/TTF parser
  • Register the font under the declared font-family name
  • 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-face parsing in crates/css/
  • Add font loading to resource loader in crates/browser/ or crates/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: swap shows 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
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mi4dt4di2y2j