@@ -174,19 +174,26 @@ private static void resolveTypefaces(@NonNull String text, @NonNull Spanned span
174174
175175 int spaceGlyph = typeface .getGlyphId (' ' );
176176 int replacementSize = replacement .getSize (null , spanned , runStart , runEnd , metrics );
177+ int runLength = runEnd - runStart ;
177178
178179 WritingDirection writingDirection = engine .getWritingDirection ();
179180 int [] glyphIds = new int [] { spaceGlyph };
180181 float [] offsets = new float [] { 0.0f , 0.0f };
181182 float [] advances = new float [] { replacementSize };
182- int [] clusterMap = new int [runEnd - runStart ];
183- FloatList caretEdges = FloatList .of (new float [runEnd - runStart + 1 ]);
183+ int [] clusterMap = new int [runLength ];
184+ float [] caretEdges = new float [runLength + 1 ];
185+
186+ if ((bidiLevel & 1 ) == 0 ) {
187+ caretEdges [runLength ] = replacementSize ;
188+ } else {
189+ caretEdges [0 ] = replacementSize ;
190+ }
184191
185192 intrinsicRun = new IntrinsicRun (runStart , runEnd , false , bidiLevel ,
186193 writingDirection , typeface , typeSize ,
187194 -metrics .ascent , metrics .descent , metrics .leading ,
188195 glyphIds , offsets , advances ,
189- clusterMap , caretEdges );
196+ clusterMap , FloatList . of ( caretEdges ) );
190197 }
191198
192199 runs .add (intrinsicRun );
0 commit comments