Misskeyのカスタム絵文字を大きくする

This commit is contained in:
tateisu 2018-11-04 11:40:28 +09:00
parent 9ed778eb33
commit 0e1dbdf5a4
5 changed files with 17 additions and 14 deletions

View File

@ -13,7 +13,10 @@ import jp.juggler.subwaytooter.Pref
import jp.juggler.subwaytooter.util.LogCategory
import java.lang.ref.WeakReference
class NetworkEmojiSpan internal constructor(private val url : String) : ReplacementSpan(),AnimatableSpan {
class NetworkEmojiSpan internal constructor(
private val url : String,
private val scale : Float = 1f
) : ReplacementSpan(),AnimatableSpan {
companion object {
@ -54,8 +57,7 @@ class NetworkEmojiSpan internal constructor(private val url : String) : Replacem
@IntRange(from = 0) end : Int,
fm : Paint.FontMetricsInt?
) : Int {
val size = (0.5f + scale_ratio * paint.textSize).toInt()
val size = (paint.textSize * scale_ratio * scale + 0.5f).toInt()
if(fm != null) {
val c_descent = (0.5f + size * descent_ratio).toInt()
val c_ascent = c_descent - size
@ -111,7 +113,7 @@ class NetworkEmojiSpan internal constructor(private val url : String) : Replacem
rect_src.set(0, 0, srcWidth, srcHeight )
// 絵文字の正方形のサイズ
val dstSize = scale_ratio * textPaint.textSize
val dstSize = textPaint.textSize * scale_ratio * scale
// ベースラインから上下方向にずらすオフセット
val c_descent = dstSize * descent_ratio

View File

@ -3,20 +3,15 @@ package jp.juggler.subwaytooter.util
import android.content.Context
import android.os.Handler
import android.os.SystemClock
import java.util.ArrayList
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
import jp.juggler.subwaytooter.App1
import jp.juggler.subwaytooter.api.TootApiClient
import jp.juggler.subwaytooter.api.entity.CustomEmoji
import jp.juggler.subwaytooter.api.entity.TootInstance
import jp.juggler.subwaytooter.api.entity.parseItem
import jp.juggler.subwaytooter.api.entity.parseList
import okhttp3.RequestBody
import org.json.JSONObject
import java.util.HashMap
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.ConcurrentLinkedQueue
class CustomEmojiLister(internal val context : Context) {

View File

@ -20,7 +20,8 @@ class DecodeOptions(
var emojiMapCustom : HashMap<String, CustomEmoji>? = null,
var emojiMapProfile : HashMap<String, NicoProfileEmoji>? = null,
var highlightTrie : WordTrieTree? = null,
var unwrapEmojiImageTag :Boolean = false
var unwrapEmojiImageTag :Boolean = false,
var enlargeCustomEmoji :Float = 1f
) {
internal fun isMediaAttachment(url : String?) : Boolean {

View File

@ -106,7 +106,7 @@ object EmojiDecoder {
sb.append(text)
val end = sb.length
sb.setSpan(
NetworkEmojiSpan(url),
NetworkEmojiSpan(url,scale = options.enlargeCustomEmoji),
start,
end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE

View File

@ -970,7 +970,10 @@ object MisskeyMarkdownDecoder {
// このファイルのエントリーポイント
fun decodeMarkdown(options : DecodeOptions, src : String?) =
SpannableStringBuilderEx().apply {
val save = options.enlargeCustomEmoji
options.enlargeCustomEmoji = 2.5f
try {
val env = SpanOutputEnv(options, this)
if(src != null) ParseEnv(src).parse { node ->
@ -990,6 +993,8 @@ object MisskeyMarkdownDecoder {
} catch(ex : Throwable) {
log.trace(ex)
log.e(ex, "decodeMarkdown failed")
}finally {
options.enlargeCustomEmoji = save
}
}
}