Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
fix: issue [#185](#185) drawTextOnBitmap 部分特殊文字会出现IndexOutOfBoundsExc…
Browse files Browse the repository at this point in the history
…eption【必现.
  • Loading branch information
errnull committed Dec 24, 2019
1 parent 0133a0b commit 1534cd2
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package com.opensource.svgaplayer.drawer
import android.annotation.TargetApi
import android.graphics.*
import android.os.Build
import android.text.BoringLayout
import android.text.StaticLayout
import android.text.TextUtils
import android.text.*
import android.text.style.StyleSpan
import android.widget.FrameLayout
import android.widget.ImageView
import com.opensource.svgaplayer.SVGADynamicEntity
Expand Down Expand Up @@ -245,15 +244,16 @@ internal class SVGACanvasDrawer(videoItem: SVGAVideoEntity, val dynamicItem: SVG
textBitmap = it
} ?: kotlin.run {
textBitmap = Bitmap.createBitmap(drawingBitmap.width, drawingBitmap.height, Bitmap.Config.ARGB_8888)
val drawRect = Rect(0, 0, drawingBitmap.width, drawingBitmap.height)
val textCanvas = Canvas(textBitmap)
drawingTextPaint.isAntiAlias = true
val bounds = Rect()
drawingTextPaint.getTextBounds(drawingText, 0, drawingText.length, bounds)
val x = (drawingBitmap.width - bounds.width()) / 2.0
val targetRectTop = 0
val targetRectBottom = drawingBitmap.height
val y = (targetRectBottom + targetRectTop - drawingTextPaint.fontMetrics.bottom - drawingTextPaint.fontMetrics.top) / 2
textCanvas.drawText(drawingText, x.toFloat(), y, drawingTextPaint)
drawingTextPaint.setStyle(Paint.Style.FILL);
drawingTextPaint.setTextAlign(Paint.Align.CENTER);
val fontMetrics = drawingTextPaint.getFontMetrics();
val top = fontMetrics.top
val bottom = fontMetrics.bottom
val baseLineY = drawRect.centerY() - top/2 - bottom/2
textCanvas.drawText(drawingText, drawRect.centerX().toFloat(),baseLineY,drawingTextPaint);
drawTextCache.put(imageKey, textBitmap as Bitmap)
}
}
Expand Down

0 comments on commit 1534cd2

Please sign in to comment.