@@ -334,3 +334,62 @@ fn styled_math_renders_through_cid_pipeline() {
334334 path. display( )
335335 ) ;
336336}
337+
338+ /// A store built from BYTES can be given a math default, and without one the
339+ /// math font falls back to the Latin face.
340+ ///
341+ /// This is the browser build's whole problem: `from_bytes_with_abbrevs` sets
342+ /// `math_default: None`, so `Context::math_font` stays at its seed — the text
343+ /// face — which has no `MATH` table. Every constant math layout reads then
344+ /// falls back to a guess and an equation collapses: limits land on their
345+ /// operator, fraction bars vanish, fences stop stretching. It renders, so
346+ /// nothing errors; it is just wrong.
347+ #[ test]
348+ fn a_byte_built_store_takes_a_math_default ( ) {
349+ let path = need_math_font ! ( ) ;
350+ let math = std:: fs:: read ( & path) . expect ( "read math font" ) ;
351+ let text = match std:: fs:: read (
352+ Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) ) . join ( "../../lib-rustyfi/dist/fonts/Junicode.ttf" ) ,
353+ ) {
354+ Ok ( bytes) => bytes,
355+ Err ( _) => {
356+ eprintln ! ( "skipping: the bundled text face is absent — run download-fonts.sh" ) ;
357+ return ;
358+ }
359+ } ;
360+
361+ let store = TtfFontStore :: from_bytes_with_abbrevs (
362+ text,
363+ None ,
364+ None ,
365+ [ ( "lmmath" . to_string ( ) , math) ] ,
366+ "test fonts" ,
367+ )
368+ . expect ( "both faces must parse" ) ;
369+
370+ // The control: this is what the browser build ships today.
371+ assert ! (
372+ store. default_math_font( ) . is_none( ) ,
373+ "a byte-built store must not acquire a math default by itself" ,
374+ ) ;
375+
376+ let key = store. abbrev_key ( "lmmath" ) . expect ( "the abbrev was registered" ) ;
377+ let store = store. with_math_default ( key) ;
378+ assert_eq ! (
379+ store. default_math_font( ) ,
380+ Some ( key) ,
381+ "with_math_default must point the math font at the face given" ,
382+ ) ;
383+ // And it has to be a DIFFERENT face from the text one, or the fix is
384+ // pointing math back at the font that caused the problem.
385+ assert_ne ! ( key, FontKey ( 0 ) , "the math face must not be the Latin slot" ) ;
386+ assert ! (
387+ store. math_constants( key) . is_some( ) ,
388+ "the math default must resolve to a face with a MATH table" ,
389+ ) ;
390+ assert ! (
391+ store. math_constants( FontKey ( 0 ) ) . is_none( ) ,
392+ "the bundled text face must have no MATH table — otherwise this test \
393+ proves nothing about why the math default is needed",
394+ ) ;
395+ }
0 commit comments