Skip to content

Commit

Permalink
Merge branch 'master' into introduce-kotlin-1.7-support
Browse files Browse the repository at this point in the history
Conflicts:
	kotlitex/src/main/java/io/github/karino2/kotlitex/view/MathExpressionSpan.kt
  • Loading branch information
BenHenning committed Mar 21, 2023
2 parents e261bfe + 43139c1 commit 11b3a2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.karino2.kotlitex.view

import android.content.Context
import android.content.res.AssetManager
import android.graphics.Color
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.util.AttributeSet
Expand Down Expand Up @@ -107,7 +108,7 @@ class SpannableMathSpanHandler(val assetManager: AssetManager, val baseSize: Flo
private fun appendMathSpan(exp: String, isMathMode: Boolean) {
isMathExist = true
val size = if (isMathMode) mathExpressionSize else baseSize
val span = MathExpressionSpan(exp, size, assetManager, isMathMode)
val span = MathExpressionSpan(exp, size, assetManager, isMathMode, equationColor = Color.BLACK)
span.ensureDrawable()
val begin = spannable.length
spannable.append("\$\$${exp}\$\$")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import kotlin.math.absoluteValue
import kotlin.math.max
import kotlin.math.roundToInt

private class MathExpressionDrawable(expr: String, baseSize: Float, val fontLoader: FontLoader, val isMathMode: Boolean, val drawBounds: Boolean = false) {
private class MathExpressionDrawable(expr: String, baseSize: Float, val fontLoader: FontLoader, val isMathMode: Boolean, val drawBounds: Boolean = false, equationColor: Int) {
var rootNode: VerticalList
val colorEquation = equationColor

val firstVListRowBound: Bounds?
get() {
Expand All @@ -43,7 +44,7 @@ private class MathExpressionDrawable(expr: String, baseSize: Float, val fontLoad

val paint = Paint()
val textPaint = TextPaint(Paint.ANTI_ALIAS_FLAG).apply {
color = Color.BLACK
color = equationColor
typeface = Typeface.SERIF
}

Expand Down Expand Up @@ -117,7 +118,7 @@ private class MathExpressionDrawable(expr: String, baseSize: Float, val fontLoad
drawBounds(drawableSurface, parent.bounds)
}
is HorizontalLineNode -> {
paint.color = Color.BLACK
paint.color = colorEquation
paint.strokeWidth = max(1.0f, parent.bounds.height.toFloat())
val x = translateX(parent.bounds.x)
val y = translateY(parent.bounds.y)
Expand Down Expand Up @@ -156,7 +157,7 @@ private class MathExpressionDrawable(expr: String, baseSize: Float, val fontLoad
mat.postTranslate(x, y)

// TODO: more suitable handling.
paint.color = Color.BLACK
paint.color = colorEquation
paint.strokeWidth = 2.0f
paint.style = Paint.Style.FILL_AND_STROKE

Expand Down Expand Up @@ -222,7 +223,7 @@ private class MathExpressionDrawable(expr: String, baseSize: Float, val fontLoad
@Suppress("UNUSED_PARAMETER")
// Similar to DynamicDrawableSpan, but getSize is a little different.
// I created super class of DynamicDrawableSpan because getCachedDrawable is private and we neet it.
class MathExpressionSpan(val expr: String, val baseHeight: Float, val assetManager: AssetManager, val isMathMode: Boolean) : ReplacementSpan() {
class MathExpressionSpan(val expr: String, val baseHeight: Float, val assetManager: AssetManager, val isMathMode: Boolean, val equationColor: Int) : ReplacementSpan() {
enum class Align {
Bottom, BaseLine
}
Expand Down Expand Up @@ -365,7 +366,7 @@ class MathExpressionSpan(val expr: String, val baseHeight: Float, val assetManag
// TODO: drawBounds should be always false. Unlike baseSize, we don't have to expose the flag to end-users.
val drawable = MathExpressionDrawable(
expr, baseHeight,
AndroidFontLoader(assetManager), isMathMode, drawBounds = false
AndroidFontLoader(assetManager), isMathMode, drawBounds = false, equationColor = equationColor
)
return drawable
}
Expand Down

0 comments on commit 11b3a2f

Please sign in to comment.