@@ -396,20 +396,24 @@ fn layout(
396396 let max_physical_width = options. max_width . map ( |max_width| max_width * scale_factor) ;
397397 let max_physical_height = options. max_height . map ( |max_height| max_height * scale_factor) ;
398398
399- let elision_info = if let ( TextOverflow :: Elide , Some ( max_physical_width) ) =
400- ( options. text_overflow , max_physical_width)
401- {
399+ // Returned None if failed to get the elipsis glyph for some rare reason.
400+ let get_elipsis_glyph = || {
402401 let mut layout = layout_builder. build ( "…" , None , None , None ) ;
403402 layout. break_all_lines ( None ) ;
404- let line = layout. lines ( ) . next ( ) . unwrap ( ) ;
405- let item = line. items ( ) . next ( ) . unwrap ( ) ;
403+ let line = layout. lines ( ) . next ( ) ? ;
404+ let item = line. items ( ) . next ( ) ? ;
406405 let run = match item {
407406 parley:: layout:: PositionedLayoutItem :: GlyphRun ( run) => Some ( run) ,
408- _ => None ,
409- }
410- . unwrap ( ) ;
411- let glyph = run. positioned_glyphs ( ) . next ( ) . unwrap ( ) ;
412- Some ( ElisionInfo { elipsis_glyph : glyph, max_physical_width } )
407+ _ => return None ,
408+ } ?;
409+ let glyph = run. positioned_glyphs ( ) . next ( ) ?;
410+ Some ( glyph)
411+ } ;
412+
413+ let elision_info = if let ( TextOverflow :: Elide , Some ( max_physical_width) ) =
414+ ( options. text_overflow , max_physical_width)
415+ {
416+ get_elipsis_glyph ( ) . map ( |elipsis_glyph| ElisionInfo { elipsis_glyph, max_physical_width } )
413417 } else {
414418 None
415419 } ;
0 commit comments