ImageSpan
extends ReplacementSpan
so any characters you are spanning won't get rendered, as the TextLayout
is expecting that the span itself will be doing all the rendering.
What I would recommend is implementing your own ReplacementSpan
subclass. Since it looks like your graphics are associated with one character, you would wrap the single character.
In the getSize
override, you would use start
and end
to index into text
and get the character(s) you are spanning, then use paint.getTextBounds()
to measure the width of the text and return that value. You want the width calculation to work in a way that the width of the span doesn't affect the default spacing of the text.
Another thing this method might need to do is change the FontMetrics
by increasing the ascent and descent in order to give you some space to draw the lines.
In the draw
override, you use the paint
to render the text that isn't being rendered within the span. The paint and font metrics should already have the proper values so that your text render looks like the surrounding text. Of course, you'll also render the line graphics you want.
For some sample code, take a look at my answer to a similar question. This has all the pieces I just discussed.
If you want me to write some code for this, you'll need to provide some code that gives me a starting point with some actual Kannada text along with what the lines are and where they go. I don't even know if Kannada text is LTR or RTL; that might affect how the span subclass is coded. Preferably the text would correspond to the image you posted so I can see how it should look when it's working.