package t2;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.text.style.ReplacementSpan;
import kotlin.jvm.internal.t;

/* loaded from: classes.dex */
public final class j extends ReplacementSpan {

    /* renamed from: p, reason: collision with root package name */
    private final float f36105p;

    /* renamed from: q, reason: collision with root package name */
    private final int f36106q;

    /* renamed from: r, reason: collision with root package name */
    private final float f36107r;

    /* renamed from: s, reason: collision with root package name */
    private final int f36108s;

    /* renamed from: t, reason: collision with root package name */
    private final float f36109t;

    /* renamed from: u, reason: collision with root package name */
    private final int f36110u;

    /* renamed from: v, reason: collision with root package name */
    private Paint.FontMetricsInt f36111v;

    /* renamed from: w, reason: collision with root package name */
    private int f36112w;

    /* renamed from: x, reason: collision with root package name */
    private int f36113x;

    /* renamed from: y, reason: collision with root package name */
    private boolean f36114y;

    /* renamed from: z, reason: collision with root package name */
    public static final a f36104z = new a(null);
    public static final int A = 8;

    /* loaded from: classes.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(kotlin.jvm.internal.k kVar) {
            this();
        }
    }

    public final Paint.FontMetricsInt a() {
        Paint.FontMetricsInt fontMetricsInt = this.f36111v;
        if (fontMetricsInt != null) {
            return fontMetricsInt;
        }
        t.y("fontMetrics");
        return null;
    }

    public final int b() {
        if (this.f36114y) {
            return this.f36113x;
        }
        throw new IllegalStateException("PlaceholderSpan is not laid out yet.".toString());
    }

    public final int c() {
        return this.f36110u;
    }

    public final int d() {
        if (this.f36114y) {
            return this.f36112w;
        }
        throw new IllegalStateException("PlaceholderSpan is not laid out yet.".toString());
    }

    @Override // android.text.style.ReplacementSpan
    public void draw(Canvas canvas, CharSequence charSequence, int i10, int i11, float f10, int i12, int i13, int i14, Paint paint) {
    }

    @Override // android.text.style.ReplacementSpan
    public int getSize(Paint paint, CharSequence charSequence, int i10, int i11, Paint.FontMetricsInt fontMetricsInt) {
        float f10;
        int a10;
        this.f36114y = true;
        float textSize = paint.getTextSize();
        this.f36111v = paint.getFontMetricsInt();
        if (!(a().descent > a().ascent)) {
            throw new IllegalArgumentException("Invalid fontMetrics: line height can not be negative.".toString());
        }
        int i12 = this.f36106q;
        if (i12 == 0) {
            f10 = this.f36105p * this.f36109t;
        } else {
            if (i12 != 1) {
                throw new IllegalArgumentException("Unsupported unit.");
            }
            f10 = this.f36105p * textSize;
        }
        this.f36112w = k.a(f10);
        int i13 = this.f36108s;
        if (i13 == 0) {
            a10 = k.a(this.f36107r * this.f36109t);
        } else {
            if (i13 != 1) {
                throw new IllegalArgumentException("Unsupported unit.");
            }
            a10 = k.a(this.f36107r * textSize);
        }
        this.f36113x = a10;
        if (fontMetricsInt != null) {
            fontMetricsInt.ascent = a().ascent;
            fontMetricsInt.descent = a().descent;
            fontMetricsInt.leading = a().leading;
            switch (this.f36110u) {
                case 0:
                    if (fontMetricsInt.ascent > (-b())) {
                        fontMetricsInt.ascent = -b();
                        break;
                    }
                    break;
                case 1:
                case 4:
                    if (fontMetricsInt.ascent + b() > fontMetricsInt.descent) {
                        fontMetricsInt.descent = fontMetricsInt.ascent + b();
                        break;
                    }
                    break;
                case 2:
                case 5:
                    if (fontMetricsInt.ascent > fontMetricsInt.descent - b()) {
                        fontMetricsInt.ascent = fontMetricsInt.descent - b();
                        break;
                    }
                    break;
                case 3:
                case 6:
                    if (fontMetricsInt.descent - fontMetricsInt.ascent < b()) {
                        int b10 = fontMetricsInt.ascent - ((b() - (fontMetricsInt.descent - fontMetricsInt.ascent)) / 2);
                        fontMetricsInt.ascent = b10;
                        fontMetricsInt.descent = b10 + b();
                        break;
                    }
                    break;
                default:
                    throw new IllegalArgumentException("Unknown verticalAlign.");
            }
            fontMetricsInt.top = Math.min(a().top, fontMetricsInt.ascent);
            fontMetricsInt.bottom = Math.max(a().bottom, fontMetricsInt.descent);
        }
        return d();
    }
}
