@@ -3433,6 +3433,15 @@ class InlineFormattingContext {
34333433 bool shapedWithHugeWidth = false ;
34343434 bool shapedWithZeroWidth = false ; // Track when we intentionally shape with 0 width
34353435
3436+ final CSSRenderStyle containerStyle = (container as RenderBoxModel ).renderStyle;
3437+ final CSSPositionType posType = containerStyle.position;
3438+ final bool containerIsOutOfFlow = posType == CSSPositionType .absolute || posType == CSSPositionType .fixed;
3439+ // For out-of-flow positioned blocks with auto width, CSS uses shrink-to-fit sizing.
3440+ // In these cases, shaping/layouting the paragraph to an ancestor "fallback" width can
3441+ // cause RTL start alignment to place glyphs far to the right (outside the shrink-to-fit
3442+ // box), where they may then be clipped by an ancestor overflow.
3443+ final bool outOfFlowShrinkToFit = containerIsOutOfFlow && containerStyle.width.isAuto;
3444+
34363445 final bool hasAtomicInlines = _items.any ((it) => it.isAtomicInline);
34373446 final bool hasExplicitBreaks =
34383447 _items.any ((it) => it.type == InlineItemType .control || it.type == InlineItemType .lineBreakOpportunity);
@@ -3467,10 +3476,15 @@ class InlineFormattingContext {
34673476 final bool preferZeroWidthShaping =
34683477 hasAtomicInlines || hasExplicitBreaks || hasWhitespaceInText || hasCJKBreaks || breakAll;
34693478 if (! constraints.hasBoundedWidth) {
3470- initialWidth =
3471- (fallbackContentMaxWidth != null && fallbackContentMaxWidth > 0 ) ? fallbackContentMaxWidth : 1000000.0 ;
3472- if (initialWidth >= 1000000.0 ) {
3479+ if (outOfFlowShrinkToFit) {
3480+ initialWidth = 1000000.0 ;
34733481 shapedWithHugeWidth = true ;
3482+ } else {
3483+ initialWidth =
3484+ (fallbackContentMaxWidth != null && fallbackContentMaxWidth > 0 ) ? fallbackContentMaxWidth : 1000000.0 ;
3485+ if (initialWidth >= 1000000.0 ) {
3486+ shapedWithHugeWidth = true ;
3487+ }
34743488 }
34753489 } else {
34763490 if (constraints.maxWidth > 0 ) {
@@ -3511,15 +3525,13 @@ class InlineFormattingContext {
35113525 }
35123526 paragraph.layout (ui.ParagraphConstraints (width: initialWidth));
35133527
3514- final CSSDisplay display = (container as RenderBoxModel ).renderStyle .effectiveDisplay;
3528+ final CSSDisplay display = containerStyle .effectiveDisplay;
35153529 final bool isBlockLike = display == CSSDisplay .block || display == CSSDisplay .inlineBlock;
35163530
35173531 if (shapedWithHugeWidth &&
35183532 constraints.hasBoundedWidth &&
35193533 constraints.maxWidth.isFinite &&
35203534 constraints.maxWidth > 0 ) {
3521- final CSSPositionType posType = (container as RenderBoxModel ).renderStyle.position;
3522- final bool containerIsOutOfFlow = posType == CSSPositionType .absolute || posType == CSSPositionType .fixed;
35233535 if (! containerIsOutOfFlow) {
35243536 final double naturalSingleLine = paragraph.longestLine;
35253537 if (constraints.maxWidth + 0.5 >= naturalSingleLine) {
@@ -3534,15 +3546,19 @@ class InlineFormattingContext {
35343546
35353547 if (isBlockLike) {
35363548 if (! constraints.hasBoundedWidth) {
3537- final double targetWidth = (fallbackContentMaxWidth != null && fallbackContentMaxWidth > 0 )
3538- ? fallbackContentMaxWidth
3539- : paragraph.longestLine;
3549+ final double targetWidth = outOfFlowShrinkToFit
3550+ ? paragraph.longestLine
3551+ : (fallbackContentMaxWidth != null && fallbackContentMaxWidth > 0 )
3552+ ? fallbackContentMaxWidth
3553+ : paragraph.longestLine;
35403554 paragraph.layout (ui.ParagraphConstraints (width: targetWidth));
35413555 } else if (constraints.maxWidth <= 0 ) {
35423556 if (! shapedWithZeroWidth) {
3543- final double targetWidth = (fallbackContentMaxWidth != null && fallbackContentMaxWidth > 0 )
3544- ? fallbackContentMaxWidth
3545- : paragraph.longestLine;
3557+ final double targetWidth = outOfFlowShrinkToFit
3558+ ? paragraph.longestLine
3559+ : (fallbackContentMaxWidth != null && fallbackContentMaxWidth > 0 )
3560+ ? fallbackContentMaxWidth
3561+ : paragraph.longestLine;
35463562 paragraph.layout (ui.ParagraphConstraints (width: targetWidth));
35473563 }
35483564 }
0 commit comments