package androidx.emoji2.text;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.CharacterStyle;
import androidx.annotation.Nullable;

/* JADX INFO: loaded from: classes.dex */
public final class s0 extends e0 {

    @Nullable
    private static Paint sDebugPaint;

    @Nullable
    private TextPaint mWorkingPaint;

    @Nullable
    private TextPaint applyCharacterSpanStyles(@Nullable CharSequence charSequence, int i10, int i11, Paint paint) {
        if (!(charSequence instanceof Spanned)) {
            if (paint instanceof TextPaint) {
                return (TextPaint) paint;
            }
            return null;
        }
        CharacterStyle[] characterStyleArr = (CharacterStyle[]) ((Spanned) charSequence).getSpans(i10, i11, CharacterStyle.class);
        if (characterStyleArr.length != 0) {
            if (characterStyleArr.length != 1 || characterStyleArr[0] != this) {
                TextPaint textPaint = this.mWorkingPaint;
                if (textPaint == null) {
                    textPaint = new TextPaint();
                    this.mWorkingPaint = textPaint;
                }
                textPaint.set(paint);
                for (CharacterStyle characterStyle : characterStyleArr) {
                    characterStyle.updateDrawState(textPaint);
                }
                return textPaint;
            }
        }
        if (paint instanceof TextPaint) {
            return (TextPaint) paint;
        }
        return null;
    }

    @Override // android.text.style.ReplacementSpan
    public final void draw(Canvas canvas, CharSequence charSequence, int i10, int i11, float f10, int i12, int i13, int i14, Paint paint) {
        TextPaint textPaintApplyCharacterSpanStyles = applyCharacterSpanStyles(charSequence, i10, i11, paint);
        if (textPaintApplyCharacterSpanStyles != null && textPaintApplyCharacterSpanStyles.bgColor != 0) {
            int color = textPaintApplyCharacterSpanStyles.getColor();
            Paint.Style style = textPaintApplyCharacterSpanStyles.getStyle();
            textPaintApplyCharacterSpanStyles.setColor(textPaintApplyCharacterSpanStyles.bgColor);
            textPaintApplyCharacterSpanStyles.setStyle(Paint.Style.FILL);
            canvas.drawRect(f10, i12, f10 + this.f2226c, i14, textPaintApplyCharacterSpanStyles);
            textPaintApplyCharacterSpanStyles.setStyle(style);
            textPaintApplyCharacterSpanStyles.setColor(color);
        }
        t.a().getClass();
        float f11 = i13;
        Paint paint2 = textPaintApplyCharacterSpanStyles;
        if (textPaintApplyCharacterSpanStyles == null) {
            paint2 = paint;
        }
        r0 r0Var = this.f2225b;
        o0 o0Var = r0Var.f2264b;
        Typeface typeface = o0Var.f2254d;
        Typeface typeface2 = paint2.getTypeface();
        paint2.setTypeface(typeface);
        canvas.drawText(o0Var.f2252b, r0Var.f2263a * 2, 2, f10, f11, paint2);
        paint2.setTypeface(typeface2);
    }
}
