@@ -66,9 +66,23 @@ int32_t GPUDisplayBackend::InitBackend()
6666 if (retVal) {
6767 return retVal;
6868 }
69- if (mDisplay ->cfg ().noFreetype ) {
70- return retVal;
69+ if (!mDisplay ->cfg ().noFreetype ) {
70+ loadFont ();
71+ }
72+ return retVal;
73+ }
74+
75+ void GPUDisplayBackend::updateFontScale (float scale)
76+ {
77+ if (mFreetypeInitialized && scale != mFontRasterScale ) {
78+ clearFontSymbols ();
79+ mFreetypeInitialized = false ;
80+ loadFont ();
7181 }
82+ }
83+
84+ void GPUDisplayBackend::loadFont ()
85+ {
7286 std::string fontName = mDisplay ->cfg ().font ;
7387#ifdef GPUCA_BUILD_EVENT_DISPLAY_FONTCONFIG
7488 FcInit ();
@@ -97,24 +111,25 @@ int32_t GPUDisplayBackend::InitBackend()
97111 FT_Face face;
98112 if (FT_Init_FreeType (&ft)) {
99113 GPUError (" Error initializing freetype" );
100- return 0 ;
114+ return ;
101115 }
102116 if (FT_New_Face (ft, fontName.c_str (), 0 , &face)) {
103117 GPUError (" Error loading freetypoe font" );
104- return 0 ;
118+ return ;
105119 }
106120
107121 int32_t fontSize = mDisplay ->cfg ().fontSize ;
108122 mDisplay ->drawTextFontSize () = fontSize;
109123 if (smoothFont ()) {
110124 fontSize *= 4 ; // Font size scaled by 4, can be downsampled
111125 }
112- FT_Set_Pixel_Sizes (face, 0 , fontSize);
126+ mFontRasterScale = mDisplay ->frontend ()->getDisplayScale ();
127+ FT_Set_Pixel_Sizes (face, 0 , (uint32_t )(fontSize * mFontRasterScale + 0 .5f )); // Rasterize at physical pixel size for HiDPI
113128
114129 for (uint32_t i = 0 ; i < 128 ; i++) {
115130 if (FT_Load_Char (face, i, FT_LOAD_RENDER )) {
116131 GPUError (" Error loading freetype symbol" );
117- return 0 ;
132+ return ;
118133 }
119134 const auto & glyph = face->glyph ;
120135 addFontSymbol (i, glyph->bitmap .width , glyph->bitmap .rows , glyph->bitmap_left , glyph->bitmap_top , glyph->advance .x , glyph->bitmap .buffer );
@@ -124,7 +139,6 @@ int32_t GPUDisplayBackend::InitBackend()
124139 FT_Done_FreeType (ft);
125140 mFreetypeInitialized = true ;
126141#endif // GPUCA_BUILD_EVENT_DISPLAY_FREETYPE
127- return retVal;
128142}
129143
130144void GPUDisplayBackend::ExitBackend ()
0 commit comments