diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt index 614878a05..dae05f88c 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt @@ -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) }