@@ -1587,6 +1587,13 @@ static void backend_test_reset_surfaces()
15871587 g_context->Flush ();
15881588}
15891589
1590+ static void backend_test_finalise_state ()
1591+ {
1592+ ve_fontcache_reset_transient_test_state ( &cache );
1593+ clear_backend_test_surfaces ( true );
1594+ g_context->Flush ();
1595+ }
1596+
15901597#ifdef VE_FONTCACHE_FREETYPE_RASTERISATION
15911598static void dx11_update_r8_texture_region_from_greyscale ( ID3D11Texture2D* texture, UINT texture_height, int x, int y, int w, int h, const uint8_t * pixels )
15921599{
@@ -1746,7 +1753,6 @@ static int run_backend_test_mode()
17461753 cache = ve_fontcache ();
17471754 ve_fontcache_init ( &cache, use_freetype );
17481755 ve_fontcache_configure_snap ( &cache, window_size.width , window_size.height );
1749- load_demo_fonts ();
17501756
17511757 std::vector< uint8_t > huge_buffer;
17521758 std::vector< uint8_t > fallback_print_buffer;
@@ -1774,33 +1780,69 @@ static int run_backend_test_mode()
17741780 if ( !use_freetype ) {
17751781 apply_font_fallbacks ();
17761782 }
1777- ve_font_id huge_test_font = load_demo_font ( &cache, " fonts/NotoSansJP-Light.otf" , huge_buffer, 200 .0f );
1778- if ( huge_test_font < 0 && !use_freetype ) {
1779- huge_test_font = load_demo_font ( &cache, " fonts/OpenSans-Regular.ttf" , huge_buffer, 200 .0f );
1780- }
1781- normalize_demo_font_ids ( &huge_test_font );
1782-
1783- bool fonts_ready =
1784- print_font >= 0
1785- && huge_test_font >= 0 ;
1786- if ( !fonts_ready ) {
1787- std::printf ( " VEFontCache backend tests [%s] failed to load one or more demo fonts.\n " , mode_name );
1788- ve_fontcache_shutdown ( &cache );
1789- return false ;
1790- }
17911783
17921784 clear_backend_test_surfaces ( use_freetype ? false : true );
17931785
17941786 ve_fontcache_backend_test_options options;
17951787 options.cache = &cache;
1796- options.font = print_font;
1797- options.secondary_font = title_font >= 0 ? title_font : print_font;
1798- options.small_font = small_font >= 0 ? small_font : print_font;
1799- options.latin_font = demo_grid3_font >= 0 ? demo_grid3_font : options.secondary_font ;
1800- options.cjk_font = demo_grid2_font >= 0 ? demo_grid2_font : print_font;
1801- options.huge_font = huge_test_font;
1802- options.arabic_font = use_freetype ? demo_arabic_font : -1 ;
1803- options.hebrew_font = use_freetype ? demo_hebrew_font : -1 ;
1788+ options.provision_fonts = [&, use_freetype](
1789+ ve_fontcache* target_cache,
1790+ const ve_fontcache_backend_test_font_spec* roles,
1791+ size_t role_count ) -> ve_fontcache_backend_test_font_set {
1792+ ve_fontcache_backend_test_font_set font_set;
1793+ if ( target_cache != &cache ) {
1794+ for ( size_t i = 0 ; i < role_count; i++ ) {
1795+ font_set.mark_unavailable ( roles[ i ].role , " demo test runner expected the active demo cache" );
1796+ }
1797+ return font_set;
1798+ }
1799+
1800+ load_demo_fonts ();
1801+ if ( !use_freetype ) {
1802+ apply_font_fallbacks ();
1803+ }
1804+ ve_font_id huge_test_font = load_demo_font ( &cache, " fonts/NotoSansJP-Light.otf" , huge_buffer, 200 .0f );
1805+ if ( huge_test_font < 0 && !use_freetype ) {
1806+ huge_test_font = load_demo_font ( &cache, " fonts/OpenSans-Regular.ttf" , huge_buffer, 200 .0f );
1807+ }
1808+ normalize_demo_font_ids ( &huge_test_font );
1809+
1810+ const auto assign_role = [&]( ve_fontcache_backend_test_font_role role, ve_font_id id, const char * reason ) {
1811+ if ( id >= 0 ) {
1812+ font_set.set ( role, id );
1813+ } else {
1814+ font_set.mark_unavailable ( role, reason );
1815+ }
1816+ };
1817+
1818+ assign_role ( VE_FONTCACHE_BACKEND_TEST_FONT_ROLE_PRIMARY, print_font, " demo primary font failed to load" );
1819+ assign_role (
1820+ VE_FONTCACHE_BACKEND_TEST_FONT_ROLE_SECONDARY,
1821+ title_font >= 0 ? title_font : print_font,
1822+ " demo secondary font failed to load" );
1823+ assign_role (
1824+ VE_FONTCACHE_BACKEND_TEST_FONT_ROLE_SMALL,
1825+ small_font >= 0 ? small_font : print_font,
1826+ " demo small font failed to load" );
1827+ assign_role (
1828+ VE_FONTCACHE_BACKEND_TEST_FONT_ROLE_LATIN,
1829+ demo_grid3_font >= 0 ? demo_grid3_font : ( title_font >= 0 ? title_font : print_font ),
1830+ " demo latin font failed to load" );
1831+ assign_role (
1832+ VE_FONTCACHE_BACKEND_TEST_FONT_ROLE_CJK,
1833+ demo_grid2_font >= 0 ? demo_grid2_font : print_font,
1834+ " demo CJK font failed to load" );
1835+ assign_role ( VE_FONTCACHE_BACKEND_TEST_FONT_ROLE_HUGE, huge_test_font, " demo huge font failed to load" );
1836+ assign_role (
1837+ VE_FONTCACHE_BACKEND_TEST_FONT_ROLE_ARABIC,
1838+ use_freetype ? demo_arabic_font : -1 ,
1839+ use_freetype ? " demo Arabic font failed to load" : " Arabic role is only used in FreeType mode" );
1840+ assign_role (
1841+ VE_FONTCACHE_BACKEND_TEST_FONT_ROLE_HEBREW,
1842+ use_freetype ? demo_hebrew_font : -1 ,
1843+ use_freetype ? " demo Hebrew font failed to load" : " Hebrew role is only used in FreeType mode" );
1844+ return font_set;
1845+ };
18041846 options.capabilities .has_present_surface = true ;
18051847 options.capabilities .has_target_linear_surface = true ;
18061848#ifdef VE_FONTCACHE_FREETYPE_RASTERISATION
@@ -1829,17 +1871,9 @@ static int run_backend_test_mode()
18291871 cache = ve_fontcache ();
18301872 ve_fontcache_init ( &cache, use_freetype );
18311873 ve_fontcache_configure_snap ( &cache, window_size.width , window_size.height );
1832- load_demo_fonts ();
1833- if ( !use_freetype ) {
1834- apply_font_fallbacks ();
1835- }
1836- ve_font_id refreshed_huge_font = load_demo_font ( &cache, " fonts/NotoSansJP-Light.otf" , huge_buffer, 200 .0f );
1837- if ( refreshed_huge_font < 0 && !use_freetype ) {
1838- refreshed_huge_font = load_demo_font ( &cache, " fonts/OpenSans-Regular.ttf" , huge_buffer, 200 .0f );
1839- }
1840- normalize_demo_font_ids ( &refreshed_huge_font );
18411874 clear_backend_test_surfaces ( true );
18421875 };
1876+ options.finalise_test_state = backend_test_finalise_state;
18431877
18441878 ve_fontcache_backend_test_result result = ve_fontcache_backend_test_run ( options );
18451879 std::printf (
0 commit comments