@@ -10,7 +10,6 @@ import {
1010 getIfcContribution ,
1111 createIfcShapedItems ,
1212 createIfcLineboxes ,
13- positionIfcItems ,
1413 sliceIfcRenderText ,
1514 collapseWhitespace
1615} from './layout-text.ts' ;
@@ -830,16 +829,18 @@ export class BlockContainerOfInlines extends BlockContainerBase {
830829 text : string ;
831830 buffer : AllocatedUint16Array ;
832831 items : ShapedItem [ ] ;
833- lineboxes : Linebox [ ] ;
834- fragments : Map < Inline , InlineFragment [ ] > ;
832+ fragments : InlineFragment [ ] ;
833+ lastBaseline : number ;
834+ intrinsicISize : number ;
835835
836836 constructor ( style : Style , attrs : number ) {
837837 super ( style , attrs ) ;
838838 this . text = '' ;
839839 this . buffer = EmptyBuffer ;
840840 this . items = [ ] ;
841- this . lineboxes = [ ] ;
842- this . fragments = new Map ( ) ;
841+ this . fragments = [ ] ;
842+ this . lastBaseline = 0 ;
843+ this . intrinsicISize = 0 ;
843844 }
844845
845846 prelayoutPostorder ( layout : Layout , ctx : PrelayoutContext ) {
@@ -849,7 +850,7 @@ export class BlockContainerOfInlines extends BlockContainerBase {
849850 this . buffer . destroy ( ) ;
850851 this . buffer = createIfcBuffer ( this . text ) ;
851852 this . items = createIfcShapedItems ( layout , this , inline ) ;
852- this . fragments . clear ( ) ;
853+ this . fragments = [ ] ;
853854 }
854855 }
855856
@@ -908,14 +909,11 @@ export class BlockContainerOfInlines extends BlockContainerBase {
908909 }
909910 }
910911
911- for ( const [ inline , fragments ] of this . fragments ) {
912- const { dx, dy} = inlineShifts . get ( inline ) ! ;
913-
914- for ( const fragment of fragments ) {
915- fragment . blockOffset += contentArea . y + dy ;
916- fragment . start += contentArea . x + dx ;
917- fragment . end += contentArea . x + dx ;
918- }
912+ for ( const fragment of this . fragments ) {
913+ const { dx, dy} = inlineShifts . get ( fragment . inline ) ! ;
914+ fragment . blockOffset += contentArea . y + dy ;
915+ fragment . left += contentArea . x + dx ;
916+ fragment . right += contentArea . x + dx ;
919917 }
920918 }
921919
@@ -956,6 +954,7 @@ export class BlockContainerOfInlines extends BlockContainerBase {
956954 let ml = i ;
957955 let mr = i ;
958956
957+ // TODO this is wrong!
959958 while ( mr < r && ! layout . tree [ mr ] . isRun ( ) && ! layout . tree [ mr ] . isInline ( ) ) mr ++ ;
960959 while ( ml > l && ! layout . tree [ ml ] . isRun ( ) && ! layout . tree [ ml ] . isInline ( ) ) ml -- ;
961960
@@ -977,15 +976,6 @@ export class BlockContainerOfInlines extends BlockContainerBase {
977976 return sliceIfcRenderText ( layout , this , item , start , end ) ;
978977 }
979978
980- getLineboxHeight ( ) {
981- if ( this . lineboxes . length ) {
982- const line = this . lineboxes . at ( - 1 ) ! ;
983- return line . blockOffset + line . height ( ) ;
984- } else {
985- return 0 ;
986- }
987- }
988-
989979 shouldLayoutContent ( layout : Layout ) {
990980 const inline = layout . tree [ this . treeStart + 1 ] ;
991981 if ( ! inline . isInline ( ) ) throw new Error ( 'Assertion failed' ) ;
@@ -998,10 +988,12 @@ export class BlockContainerOfInlines extends BlockContainerBase {
998988 doTextLayout ( layout : Layout , ctx : LayoutContext ) {
999989 const blockSize = this . style . getBlockSize ( this . getContainingBlock ( ) ) ;
1000990 if ( this . shouldLayoutContent ( layout ) ) {
1001- this . lineboxes = createIfcLineboxes ( layout , this , ctx ) ;
1002- positionIfcItems ( layout , this ) ;
991+ const ifc = createIfcLineboxes ( layout , this , ctx ) ;
992+ if ( blockSize === 'auto' && ifc . lines . length ) {
993+ const line = ifc . lines [ ifc . lines . length - 1 ] ;
994+ this . setBlockSize ( line . blockOffset + line . height ( ) ) ;
995+ }
1003996 }
1004- if ( blockSize === 'auto' ) this . setBlockSize ( this . getLineboxHeight ( ) ) ;
1005997 }
1006998}
1007999
@@ -1384,23 +1376,22 @@ export class Inline extends Box {
13841376 return this . style . hasLineRightGap ( this . getContainingBlock ( ) ) ;
13851377 }
13861378
1387- getInlineSideSize ( side : 'pre' | 'post' ) {
1379+ getInlineStartSize ( ) {
13881380 const direction = this . getDirectionAsParticipant ( ) ;
13891381 const containingBlock = this . getContainingBlock ( ) ;
1390- if (
1391- direction === 'ltr' && side === 'pre' ||
1392- direction === 'rtl' && side === 'post'
1393- ) {
1394- const marginLineLeft = this . style . getMarginLineLeft ( containingBlock ) ;
1395- return ( marginLineLeft === 'auto' ? 0 : marginLineLeft )
1396- + this . style . getBorderLineLeftWidth ( containingBlock )
1397- + this . style . getPaddingLineLeft ( containingBlock ) ;
1398- } else {
1399- const marginLineRight = this . style . getMarginLineRight ( containingBlock ) ;
1400- return ( marginLineRight === 'auto' ? 0 : marginLineRight )
1401- + this . style . getBorderLineRightWidth ( containingBlock )
1402- + this . style . getPaddingLineRight ( containingBlock ) ;
1403- }
1382+ const marginStart = this . style . getMarginInlineStart ( containingBlock , direction ) ;
1383+ return ( marginStart === 'auto' ? 0 : marginStart )
1384+ + this . style . getBorderInlineStartWidth ( containingBlock , direction )
1385+ + this . style . getPaddingInlineStart ( containingBlock , direction ) ;
1386+ }
1387+
1388+ getInlineEndSize ( ) {
1389+ const direction = this . getDirectionAsParticipant ( ) ;
1390+ const containingBlock = this . getContainingBlock ( ) ;
1391+ const marginEnd = this . style . getMarginInlineEnd ( containingBlock , direction ) ;
1392+ return ( marginEnd === 'auto' ? 0 : marginEnd )
1393+ + this . style . getBorderInlineEndWidth ( containingBlock , direction )
1394+ + this . style . getPaddingInlineEnd ( containingBlock , direction ) ;
14041395 }
14051396
14061397 isInline ( ) : this is Inline {
@@ -1463,9 +1454,12 @@ export class ReplacedBox extends FormattingBox {
14631454 }
14641455
14651456 getLogSymbol ( ) {
1466- return "◼️" ;
1457+ if ( this . isFloat ( ) ) {
1458+ return '●' ;
1459+ } else {
1460+ return '◼️' ;
1461+ }
14671462 }
1468-
14691463 hasBackground ( ) {
14701464 return this . style . hasPaint ( ) ;
14711465 }
@@ -1530,7 +1524,7 @@ export class ReplacedBox extends FormattingBox {
15301524export type InlineLevel = Inline | Run | Break | BlockContainer | ReplacedBox ;
15311525
15321526type InlineIteratorBuffered = { state : 'pre' | 'post' , item : Inline }
1533- | { state : 'text' , item : Run }
1527+ | { state : 'text' , item : Run , treeIndex : number }
15341528 | { state : 'box' , item : BlockLevel }
15351529 | { state : 'break' }
15361530 | { state : 'breakop' } ;
@@ -1593,7 +1587,8 @@ export function inlineIteratorStateNext(state: InlineIteratorState) {
15931587 state . emitBreakspot = state . minlevel !== state . parents . length ;
15941588 state . minlevel = state . parents . length ;
15951589 if ( item . isRun ( ) ) {
1596- state . buffered . push ( { state : 'text' , item} ) ;
1590+ const treeIndex = state . index - 1 ;
1591+ state . buffered . push ( { state : 'text' , item, treeIndex} ) ;
15971592 } else if ( item . isBreak ( ) ) {
15981593 state . buffered . push ( { state : 'break' } ) ;
15991594 } else {
0 commit comments