Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -680,24 +680,41 @@ open class PieChartRenderer(
val width = centerTextLastBounds.width()

// If width is 0, it will crash. Always have a minimum of 1
centerTextLayout = StaticLayout(
centerText, 0, centerText.length, paintCenterText, max(ceil(width.toDouble()), 1.0).toInt(), Layout.Alignment.ALIGN_CENTER, 1f, 0f, false
)
}

val layoutHeight = centerTextLayout!!.height.toFloat()

canvas.withSave {
val path = mDrawCenterTextPathBuffer
path.reset()
path.addOval(holeRect, Path.Direction.CW)
clipPath(path)

translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2f)
centerTextLayout!!.draw(this)
// centerTextLayout = StaticLayout(
// centerText,
// 0,
// centerText.length,
// paintCenterText,
// max(ceil(width.toDouble()), 1.0).toInt(),
// Layout.Alignment.ALIGN_CENTER,
// 1f,
// 0f,
// false
// )
centerTextLayout = StaticLayout.Builder.obtain(
centerText,
0,
centerText.length,
paintCenterText,
max(ceil(width.toDouble()), 1.0).toInt()
).setAlignment(Layout.Alignment.ALIGN_CENTER)
.setLineSpacing(0f, 1f)
.setIncludePad(false)
.build()

val layoutHeight = centerTextLayout!!.height.toFloat()

canvas.withSave {
val path = mDrawCenterTextPathBuffer
path.reset()
path.addOval(holeRect, Path.Direction.CW)
clipPath(path)

translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2f)
centerTextLayout!!.draw(this)

}
}

PointF.recycleInstance(center)
PointF.recycleInstance(offset)
}
Expand Down
Loading