@@ -680,24 +680,41 @@ open class PieChartRenderer(
680680 val width = centerTextLastBounds.width()
681681
682682 // If width is 0, it will crash. Always have a minimum of 1
683- centerTextLayout = StaticLayout (
684- centerText, 0 , centerText.length, paintCenterText, max(ceil(width.toDouble()), 1.0 ).toInt(), Layout .Alignment .ALIGN_CENTER , 1f , 0f , false
685- )
686- }
687-
688- val layoutHeight = centerTextLayout!! .height.toFloat()
689-
690- canvas.withSave {
691- val path = mDrawCenterTextPathBuffer
692- path.reset()
693- path.addOval(holeRect, Path .Direction .CW )
694- clipPath(path)
695-
696- translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2f )
697- centerTextLayout!! .draw(this )
683+ // centerTextLayout = StaticLayout(
684+ // centerText,
685+ // 0,
686+ // centerText.length,
687+ // paintCenterText,
688+ // max(ceil(width.toDouble()), 1.0).toInt(),
689+ // Layout.Alignment.ALIGN_CENTER,
690+ // 1f,
691+ // 0f,
692+ // false
693+ // )
694+ centerTextLayout = StaticLayout .Builder .obtain(
695+ centerText,
696+ 0 ,
697+ centerText.length,
698+ paintCenterText,
699+ max(ceil(width.toDouble()), 1.0 ).toInt()
700+ ).setAlignment(Layout .Alignment .ALIGN_CENTER )
701+ .setLineSpacing(0f , 1f )
702+ .setIncludePad(false )
703+ .build()
704+
705+ val layoutHeight = centerTextLayout!! .height.toFloat()
706+
707+ canvas.withSave {
708+ val path = mDrawCenterTextPathBuffer
709+ path.reset()
710+ path.addOval(holeRect, Path .Direction .CW )
711+ clipPath(path)
712+
713+ translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2f )
714+ centerTextLayout!! .draw(this )
698715
716+ }
699717 }
700-
701718 PointF .recycleInstance(center)
702719 PointF .recycleInstance(offset)
703720 }
0 commit comments