@@ -59,8 +59,18 @@ private void SetTextCustom(string value)
5959 private string ReplaceRubyTags ( string str )
6060 {
6161 if ( string . IsNullOrEmpty ( str ) ) return str ;
62- var pVal = GetPreferredValues ( "\u00A0 " ) ;
63- var hiddenSpaceW = GetPreferredValues ( "\u00A0 " ) . x * ( m_isOrthographic ? 1 : 10f ) ;
62+ // warning! bad Know-how
63+ // Can not get GetPreferredValues("\u00A0").x at width,
64+ // add string and calculate.
65+ // and Use GetPreferredValues, change this.m_maxFontSize value.
66+ var nonBreakSpaceW = GetPreferredValues ( "\u00A0 a" ) . x - GetPreferredValues ( "a" ) . x ;
67+ var fontSizeScale = 1f ;
68+ if ( this . m_enableAutoSizing )
69+ {
70+ fontSizeScale = ( this . m_fontSize / this . m_maxFontSize ) ;
71+ }
72+ var dir = isRightToLeftText ? 1 : - 1 ;
73+ var hiddenSpaceW = dir * nonBreakSpaceW * ( m_isOrthographic ? 1 : 10f ) * rubyScale * fontSizeScale ;
6474 // Replace <ruby> tags text layout.
6575 var matches = RubyRegex . Matches ( str ) ;
6676 var compensationOffset = 0f ;
@@ -75,11 +85,9 @@ private string ReplaceRubyTags(string str)
7585 var baseTextW = GetPreferredValues ( baseText ) . x * ( m_isOrthographic ? 1 : 10f ) ;
7686 if ( this . m_enableAutoSizing )
7787 {
78- var calc = ( this . m_fontSize / this . m_maxFontSize ) ;
79- rubyTextW *= calc ;
80- baseTextW *= calc ;
88+ rubyTextW *= fontSizeScale ;
89+ baseTextW *= fontSizeScale ;
8190 }
82- var dir = isRightToLeftText ? 1 : - 1 ;
8391 var rubyTextOffset = dir * ( baseTextW / 2f + rubyTextW / 2f ) ;
8492 compensationOffset = - dir * ( ( baseTextW - rubyTextW ) / 2f ) ;
8593 var replace = CreateReplaceValue ( baseText , rubyText , rubyTextOffset , compensationOffset , isRightToLeftText ) ;
@@ -90,7 +98,7 @@ private string ReplaceRubyTags(string str)
9098 // warning! bad Know-how
9199 // line-height tag is down the next line start.
92100 // now line can't change, corresponding by putting a hidden ruby
93- str = $ "<line-height={ allVCompensationRubyLineHeight } ><voffset={ rubyVerticalOffset } ><size={ rubyScale * 100f } %>\u00A0 </size></voffset><space={ compensationOffset } >" + str ;
101+ str = $ "<line-height={ allVCompensationRubyLineHeight } ><voffset={ rubyVerticalOffset } ><size={ rubyScale * 100f } %>\u00A0 </size></voffset><space={ hiddenSpaceW } >" + str ;
94102 }
95103
96104 return str ;
@@ -208,7 +216,6 @@ protected override void OnValidate()
208216
209217 SetTextCustom ( m_uneditedText ) ;
210218 }
211-
212219#endif
213220 }
214221}
0 commit comments