fun draw(canvas: Canvas, text: Spanned, layout: Layout) { // ideally the calculations here should be cached since // they are not cheap. However, proper // invalidation of the cache is required whenever // anything related to text has changed. val spans = text.getSpans(0, text.length, Annotation::class.java) spans.forEach { span -> if (span.value.equals("rounded")) { val spanStart = text.getSpanStart(span) val spanEnd = text.getSpanEnd(span) val startLine = layout.getLineForOffset(spanStart) val endLine = layout.getLineForOffset(spanEnd) // start can be on the left or on the right depending // on the language direction. val startOffset = (layout.getPrimaryHorizontal(spanStart) + -1 * layout.getParagraphDirection(startLine) * horizontalPadding).toInt() // end can be on the left or on the right depending // on the language direction. val endOffset = (layout.getPrimaryHorizontal(spanEnd) + layout.getParagraphDirection(endLine) * horizontalPadding).toInt() val renderer = if (startLine == endLine) singleLineRenderer else multiLineRenderer renderer.draw(canvas, layout, startLine, endLine, startOffset, endOffset) } }}
abstract fun draw( canvas: Canvas, layout: Layout, startLine: Int, endLine: Int, startOffset: Int, endOffset: Int )