@@ -178,7 +178,7 @@ export interface TextStyleProps extends TextStylePropsPart {
178178 * truncate: truncate the text and show ellipsis
179179 * Do nothing if not set
180180 */
181- overflow ?: 'break' | 'breakAll' | 'truncate' | 'none'
181+ overflow ?: 'break' | 'breakAll' | 'truncate' | 'fit' | ' none'
182182
183183 /**
184184 * Strategy when text lines exceeds textHeight.
@@ -635,6 +635,23 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
635635 subElStyle . font = textFont ;
636636 setSeparateFont ( subElStyle , style ) ;
637637
638+ // Apply horizontal scaling when overflow is 'fit'.
639+ // The scaleX transform stretches or compresses text glyphs to exactly fill the target width.
640+ if ( contentBlock . fitScaleX != null && contentBlock . fitScaleX !== 1 ) {
641+ el . scaleX = contentBlock . fitScaleX ;
642+ el . scaleY = 1 ;
643+ // Adjust the x-origin so that the text scales from the correct anchor point
644+ // based on textAlign. For 'left' alignment, origin is the text x position.
645+ // For 'center', the origin should be the center; for 'right', the right edge.
646+ el . originX = subElStyle . x ;
647+ el . originY = subElStyle . y ;
648+ }
649+ else {
650+ // Reset to avoid stale transforms from previous updates
651+ el . scaleX = 1 ;
652+ el . scaleY = 1 ;
653+ }
654+
638655 textY += lineHeight ;
639656
640657 // Always set tspan bounding rect to guarantee the consistency if users lays out based
@@ -728,7 +745,7 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
728745 leftIndex < tokenCount
729746 && ( token = tokens [ leftIndex ] , ! token . align || token . align === 'left' )
730747 ) {
731- this . _placeToken ( token , style , lineHeight , lineTop , lineXLeft , 'left' , bgColorDrawn ) ;
748+ this . _placeToken ( token , style , lineHeight , lineTop , lineXLeft , 'left' , bgColorDrawn , contentBlock . fitScaleX ) ;
732749 remainedWidth -= token . width ;
733750 lineXLeft += token . width ;
734751 leftIndex ++ ;
@@ -738,7 +755,7 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
738755 rightIndex >= 0
739756 && ( token = tokens [ rightIndex ] , token . align === 'right' )
740757 ) {
741- this . _placeToken ( token , style , lineHeight , lineTop , lineXRight , 'right' , bgColorDrawn ) ;
758+ this . _placeToken ( token , style , lineHeight , lineTop , lineXRight , 'right' , bgColorDrawn , contentBlock . fitScaleX ) ;
742759 remainedWidth -= token . width ;
743760 lineXRight -= token . width ;
744761 rightIndex -- ;
@@ -751,7 +768,7 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
751768 // Consider width specified by user, use 'center' rather than 'left'.
752769 this . _placeToken (
753770 token , style , lineHeight , lineTop ,
754- lineXLeft + token . width / 2 , 'center' , bgColorDrawn
771+ lineXLeft + token . width / 2 , 'center' , bgColorDrawn , contentBlock . fitScaleX
755772 ) ;
756773 lineXLeft += token . width ;
757774 leftIndex ++ ;
@@ -768,7 +785,8 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
768785 lineTop : number ,
769786 x : number ,
770787 textAlign : string ,
771- parentBgColorDrawn : boolean
788+ parentBgColorDrawn : boolean ,
789+ fitScaleX ?: number
772790 ) {
773791 const tokenStyle = style . rich [ token . styleName ] || { } ;
774792 tokenStyle . text = token . text ;
@@ -865,6 +883,18 @@ class ZRText extends Displayable<TextProps> implements GroupLike {
865883 subElStyle . fill = textFill ;
866884 }
867885
886+ // Apply horizontal scaling when overflow is 'fit'.
887+ if ( fitScaleX != null && fitScaleX !== 1 ) {
888+ el . scaleX = fitScaleX ;
889+ el . scaleY = 1 ;
890+ el . originX = subElStyle . x ;
891+ el . originY = subElStyle . y ;
892+ }
893+ else {
894+ el . scaleX = 1 ;
895+ el . scaleY = 1 ;
896+ }
897+
868898 // NOTE: Should not call dirtyStyle after setBoundingRect. Or it will be cleared.
869899 el . setBoundingRect ( tSpanCreateBoundingRect2 (
870900 subElStyle ,
0 commit comments