@@ -3,9 +3,8 @@ package com.opensource.svgaplayer.drawer
3
3
import android.annotation.TargetApi
4
4
import android.graphics.*
5
5
import android.os.Build
6
- import android.text.BoringLayout
7
- import android.text.StaticLayout
8
- import android.text.TextUtils
6
+ import android.text.*
7
+ import android.text.style.StyleSpan
9
8
import android.widget.FrameLayout
10
9
import android.widget.ImageView
11
10
import com.opensource.svgaplayer.SVGADynamicEntity
@@ -245,15 +244,16 @@ internal class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVG
245
244
textBitmap = it
246
245
} ? : kotlin.run {
247
246
textBitmap = Bitmap .createBitmap(drawingBitmap.width, drawingBitmap.height, Bitmap .Config .ARGB_8888 )
247
+ val drawRect = Rect (0 , 0 , drawingBitmap.width, drawingBitmap.height)
248
248
val textCanvas = Canvas (textBitmap)
249
249
drawingTextPaint.isAntiAlias = true
250
- val bounds = Rect ()
251
- drawingTextPaint.getTextBounds(drawingText, 0 , drawingText.length, bounds)
252
- val x = (drawingBitmap.width - bounds.width()) / 2.0
253
- val targetRectTop = 0
254
- val targetRectBottom = drawingBitmap.height
255
- val y = (targetRectBottom + targetRectTop - drawingTextPaint.fontMetrics.bottom - drawingTextPaint.fontMetrics.top) / 2
256
- textCanvas.drawText(drawingText, x. toFloat(), y, drawingTextPaint)
250
+ drawingTextPaint.setStyle( Paint . Style . FILL );
251
+ drawingTextPaint.setTextAlign( Paint . Align . CENTER );
252
+ val fontMetrics = drawingTextPaint.getFontMetrics();
253
+ val top = fontMetrics.top
254
+ val bottom = fontMetrics.bottom
255
+ val baseLineY = drawRect.centerY() - top / 2 - bottom / 2
256
+ textCanvas.drawText(drawingText, drawRect.centerX(). toFloat(),baseLineY, drawingTextPaint);
257
257
drawTextCache.put(imageKey, textBitmap as Bitmap )
258
258
}
259
259
}
0 commit comments