@@ -21,7 +21,9 @@ let layout: LayoutModule['layout']
2121let layoutWithLines : LayoutModule [ 'layoutWithLines' ]
2222let layoutNextLine : LayoutModule [ 'layoutNextLine' ]
2323let layoutNextLineRange : LayoutModule [ 'layoutNextLineRange' ]
24+ let materializeLineRange : LayoutModule [ 'materializeLineRange' ]
2425let measureLineStats : LayoutModule [ 'measureLineStats' ]
26+ let measureNaturalWidth : LayoutModule [ 'measureNaturalWidth' ]
2527let walkLineRanges : LayoutModule [ 'walkLineRanges' ]
2628let clearCache : LayoutModule [ 'clearCache' ]
2729let setLocale : LayoutModule [ 'setLocale' ]
@@ -280,7 +282,9 @@ beforeAll(async () => {
280282 layoutWithLines,
281283 layoutNextLine,
282284 layoutNextLineRange,
285+ materializeLineRange,
283286 measureLineStats,
287+ measureNaturalWidth,
284288 walkLineRanges,
285289 clearCache,
286290 setLocale,
@@ -1425,6 +1429,16 @@ describe('layout invariants', () => {
14251429 } ) ) )
14261430 } )
14271431
1432+ test ( 'materializeLineRange reproduces streamed layout lines' , ( ) => {
1433+ const prepared = prepareWithSegments ( 'foo trans\u00ADatlantic said "hello" to 世界 and waved.' , FONT )
1434+ const width = prepared . widths [ 0 ] ! + prepared . widths [ 1 ] ! + prepared . widths [ 2 ] ! + prepared . breakableFitAdvances [ 4 ] ! [ 0 ] ! + prepared . discretionaryHyphenWidth + 0.1
1435+ const expected = layoutWithLines ( prepared , width , LINE_HEIGHT ) . lines [ 0 ] !
1436+ const range = layoutNextLineRange ( prepared , { segmentIndex : 0 , graphemeIndex : 0 } , width )
1437+
1438+ expect ( range ) . not . toBeNull ( )
1439+ expect ( materializeLineRange ( prepared , range ! ) ) . toEqual ( expected )
1440+ } )
1441+
14281442 test ( 'measureLineStats matches walked line count and widest line' , ( ) => {
14291443 const prepared = prepareWithSegments ( 'foo trans\u00ADatlantic said "hello" to 世界 and waved.' , FONT )
14301444 const width = prepared . widths [ 0 ] ! + prepared . widths [ 1 ] ! + prepared . widths [ 2 ] ! + prepared . breakableFitAdvances [ 4 ] ! [ 0 ] ! + prepared . discretionaryHyphenWidth + 0.1
@@ -1442,6 +1456,12 @@ describe('layout invariants', () => {
14421456 } )
14431457 } )
14441458
1459+ test ( 'measureNaturalWidth returns the widest forced line' , ( ) => {
1460+ const prepared = prepareWithSegments ( 'wide line\nfit\nmid' , FONT , { whiteSpace : 'pre-wrap' } )
1461+
1462+ expect ( measureNaturalWidth ( prepared ) ) . toBe ( measureWidth ( 'wide line' , FONT ) )
1463+ } )
1464+
14451465 test ( 'line-break geometry helpers stay aligned with streamed line ranges' , ( ) => {
14461466 const prepared = prepareWithSegments ( 'foo trans\u00ADatlantic said "hello" to 世界 and waved.' , FONT )
14471467 const widths = [ 48 , 72 , 120 ]
0 commit comments