@@ -6,7 +6,7 @@ use bevy_ecs::{
66 system:: ResMut ,
77} ;
88use bevy_image:: prelude:: * ;
9- use bevy_log:: { once , warn } ;
9+ use bevy_log:: warn_once ;
1010use bevy_math:: { Rect , UVec2 , Vec2 } ;
1111use bevy_reflect:: { std_traits:: ReflectDefault , Reflect } ;
1212
@@ -166,9 +166,7 @@ impl TextPipeline {
166166 computed. needs_rerender = false ;
167167
168168 if scale_factor <= 0.0 {
169- once ! ( warn!(
170- "Text scale factor is <= 0.0. No text will be displayed." ,
171- ) ) ;
169+ warn_once ! ( "Text scale factor is <= 0.0. No text will be displayed." , ) ;
172170
173171 return Err ( TextError :: DegenerateScaleFactor ) ;
174172 }
@@ -212,13 +210,24 @@ impl TextPipeline {
212210
213211 // Save spans that aren't zero-sized.
214212 if text_font. font_size <= 0.0 {
215- once ! ( warn !(
213+ warn_once ! (
216214 "Text span {entity} has a font size <= 0.0. Nothing will be displayed." ,
217- ) ) ;
215+ ) ;
218216
219217 continue ;
220218 }
221219
220+ const WARN_FONT_SIZE : f32 = 1000.0 ;
221+ if text_font. font_size * scale_factor as f32 > WARN_FONT_SIZE {
222+ warn_once ! (
223+ "Text span {entity} has an excessively large font size ({} with scale factor {}). \
224+ Extremely large font sizes will cause performance issues with font atlas \
225+ generation and high memory usage.",
226+ text_font. font_size,
227+ scale_factor,
228+ ) ;
229+ }
230+
222231 let attrs = get_attrs ( span_index, text_font, line_height, family, scale_factor) ;
223232
224233 sections. push ( ( span, attrs) ) ;
@@ -583,19 +592,22 @@ fn get_attrs<'a>(
583592 family : Family < ' a > ,
584593 scale_factor : f64 ,
585594) -> Attrs < ' a > {
595+ let font_size = ( text_font. font_size * scale_factor as f32 ) . round ( ) ;
596+ let line_height = match line_height {
597+ LineHeight :: Px ( px) => px * scale_factor as f32 ,
598+ LineHeight :: RelativeToFont ( s) => s * font_size,
599+ } ;
600+
586601 Attrs :: new ( )
587602 . metadata ( span_index)
588603 . family ( family)
589604 . stretch ( text_font. width . into ( ) )
590605 . style ( text_font. style . into ( ) )
591606 . weight ( text_font. weight . into ( ) )
592- . metrics (
593- Metrics {
594- font_size : text_font. font_size ,
595- line_height : line_height. eval ( text_font. font_size ) ,
596- }
597- . scale ( scale_factor as f32 ) ,
598- )
607+ . metrics ( Metrics {
608+ font_size,
609+ line_height,
610+ } )
599611 . font_features ( ( & text_font. font_features ) . into ( ) )
600612}
601613
0 commit comments