package r2;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Build;
import android.os.Trace;
import android.text.BoringLayout;
import android.text.Layout;
import android.text.Spanned;
import android.text.StaticLayout;
import android.text.TextDirectionHeuristic;
import android.text.TextPaint;
import android.text.TextUtils;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;

/* loaded from: classes.dex */
public final class u0 {

    /* renamed from: a, reason: collision with root package name */
    private final TextPaint f34389a;

    /* renamed from: b, reason: collision with root package name */
    private final boolean f34390b;

    /* renamed from: c, reason: collision with root package name */
    private final boolean f34391c;

    /* renamed from: d, reason: collision with root package name */
    private final z f34392d;

    /* renamed from: e, reason: collision with root package name */
    private final boolean f34393e;

    /* renamed from: f, reason: collision with root package name */
    private s2.g f34394f;

    /* renamed from: g, reason: collision with root package name */
    private final Layout f34395g;

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

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

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

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

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

    /* renamed from: m, reason: collision with root package name */
    private final boolean f34401m;

    /* renamed from: n, reason: collision with root package name */
    private final Paint.FontMetricsInt f34402n;

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

    /* renamed from: p, reason: collision with root package name */
    private final t2.h[] f34404p;

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

    /* renamed from: r, reason: collision with root package name */
    private y f34406r;

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r7v2 */
    /* JADX WARN: Type inference failed for: r7v3, types: [int] */
    /* JADX WARN: Type inference failed for: r7v5 */
    public u0(CharSequence charSequence, float f10, TextPaint textPaint, int i10, TextUtils.TruncateAt truncateAt, int i11, float f11, float f12, boolean z10, boolean z11, int i12, int i13, int i14, int i15, int i16, int i17, int[] iArr, int[] iArr2, z zVar) {
        boolean z12;
        boolean z13;
        TextDirectionHeuristic textDirectionHeuristic;
        Layout a10;
        long l10;
        t2.h[] j10;
        Paint.FontMetricsInt h10;
        this.f34389a = textPaint;
        this.f34390b = z10;
        this.f34391c = z11;
        this.f34392d = zVar;
        this.f34405q = new Rect();
        int length = charSequence.length();
        TextDirectionHeuristic k10 = w0.k(i11);
        Layout.Alignment a11 = s0.f34380a.a(i10);
        boolean z14 = (charSequence instanceof Spanned) && ((Spanned) charSequence).nextSpanTransition(-1, length, t2.a.class) < length;
        Trace.beginSection("TextLayout:initLayout");
        try {
            BoringLayout.Metrics a12 = zVar.a();
            double d10 = f10;
            int ceil = (int) Math.ceil(d10);
            if (a12 != null && zVar.b() <= f10 && !z14) {
                this.f34401m = true;
                z12 = true;
                a10 = k.f34349a.a(charSequence, textPaint, ceil, a12, a11, z10, z11, truncateAt, ceil);
                textDirectionHeuristic = k10;
                z13 = false;
            } else {
                z12 = true;
                this.f34401m = false;
                z13 = false;
                textDirectionHeuristic = k10;
                a10 = p0.f34356a.a(charSequence, textPaint, ceil, 0, charSequence.length(), k10, a11, i12, truncateAt, (int) Math.ceil(d10), f11, f12, i17, z10, z11, i13, i14, i15, i16, iArr, iArr2);
            }
            this.f34395g = a10;
            Trace.endSection();
            int min = Math.min(a10.getLineCount(), i12);
            this.f34396h = min;
            int i18 = min - 1;
            this.f34393e = (min >= i12 && (a10.getEllipsisCount(i18) > 0 || a10.getLineEnd(i18) != charSequence.length())) ? z12 : z13;
            l10 = w0.l(this);
            j10 = w0.j(this);
            this.f34404p = j10;
            long i19 = j10 != null ? w0.i(j10) : w0.f34415b;
            this.f34397i = Math.max(x0.c(l10), x0.c(i19));
            this.f34398j = Math.max(x0.b(l10), x0.b(i19));
            h10 = w0.h(this, textPaint, textDirectionHeuristic, j10);
            this.f34403o = h10 != null ? h10.bottom - ((int) s(i18)) : z13;
            this.f34402n = h10;
            this.f34399k = t2.d.b(a10, i18, null, 2, null);
            this.f34400l = t2.d.d(a10, i18, null, 2, null);
        } catch (Throwable th2) {
            Trace.endSection();
            throw th2;
        }
    }

    public static /* synthetic */ float B(u0 u0Var, int i10, boolean z10, int i11, Object obj) {
        if ((i11 & 2) != 0) {
            z10 = false;
        }
        return u0Var.A(i10, z10);
    }

    public static /* synthetic */ float E(u0 u0Var, int i10, boolean z10, int i11, Object obj) {
        if ((i11 & 2) != 0) {
            z10 = false;
        }
        return u0Var.D(i10, z10);
    }

    private final float g(int i10) {
        return i10 == this.f34396h + (-1) ? this.f34399k + this.f34400l : BitmapDescriptorFactory.HUE_RED;
    }

    private final y j() {
        y yVar = this.f34406r;
        if (yVar != null) {
            kotlin.jvm.internal.t.d(yVar);
            return yVar;
        }
        y yVar2 = new y(this.f34395g);
        this.f34406r = yVar2;
        return yVar2;
    }

    public final float A(int i10, boolean z10) {
        return j().c(i10, true, z10) + g(q(i10));
    }

    public final int[] C(RectF rectF, int i10, dn.p pVar) {
        return Build.VERSION.SDK_INT >= 34 ? f.f34345a.c(this, rectF, i10, pVar) : v0.d(this, this.f34395g, j(), rectF, i10, pVar);
    }

    public final float D(int i10, boolean z10) {
        return j().c(i10, false, z10) + g(q(i10));
    }

    public final void F(int i10, int i11, Path path) {
        this.f34395g.getSelectionPath(i10, i11, path);
        if (this.f34397i == 0 || path.isEmpty()) {
            return;
        }
        path.offset(BitmapDescriptorFactory.HUE_RED, this.f34397i);
    }

    public final CharSequence G() {
        return this.f34395g.getText();
    }

    public final TextPaint H() {
        return this.f34389a;
    }

    public final s2.g I() {
        s2.g gVar = this.f34394f;
        if (gVar != null) {
            return gVar;
        }
        s2.g gVar2 = new s2.g(this.f34395g.getText(), 0, this.f34395g.getText().length(), this.f34389a.getTextLocale());
        this.f34394f = gVar2;
        return gVar2;
    }

    public final boolean J() {
        if (this.f34401m) {
            k kVar = k.f34349a;
            Layout layout = this.f34395g;
            kotlin.jvm.internal.t.e(layout, "null cannot be cast to non-null type android.text.BoringLayout");
            return kVar.b((BoringLayout) layout);
        }
        p0 p0Var = p0.f34356a;
        Layout layout2 = this.f34395g;
        kotlin.jvm.internal.t.e(layout2, "null cannot be cast to non-null type android.text.StaticLayout");
        return p0Var.c((StaticLayout) layout2, this.f34391c);
    }

    public final boolean K(int i10) {
        return this.f34395g.isRtlCharAt(i10);
    }

    public final void L(Canvas canvas) {
        t0 t0Var;
        if (canvas.getClipBounds(this.f34405q)) {
            int i10 = this.f34397i;
            if (i10 != 0) {
                canvas.translate(BitmapDescriptorFactory.HUE_RED, i10);
            }
            t0Var = w0.f34414a;
            t0Var.a(canvas);
            this.f34395g.draw(t0Var);
            int i11 = this.f34397i;
            if (i11 != 0) {
                canvas.translate(BitmapDescriptorFactory.HUE_RED, (-1) * i11);
            }
        }
    }

    public final void a(int i10, int i11, float[] fArr, int i12) {
        float d10;
        float e10;
        int length = G().length();
        int i13 = 1;
        if (!(i10 >= 0)) {
            throw new IllegalArgumentException("startOffset must be > 0".toString());
        }
        if (!(i10 < length)) {
            throw new IllegalArgumentException("startOffset must be less than text length".toString());
        }
        if (!(i11 > i10)) {
            throw new IllegalArgumentException("endOffset must be greater than startOffset".toString());
        }
        if (!(i11 <= length)) {
            throw new IllegalArgumentException("endOffset must be smaller or equal to text length".toString());
        }
        if (!(fArr.length - i12 >= (i11 - i10) * 4)) {
            throw new IllegalArgumentException("array.size - arrayStart must be greater or equal than (endOffset - startOffset) * 4".toString());
        }
        int q10 = q(i10);
        int q11 = q(i11 - 1);
        v vVar = new v(this);
        if (q10 > q11) {
            return;
        }
        int i14 = q10;
        int i15 = i12;
        while (true) {
            int v10 = v(i14);
            int p10 = p(i14);
            int min = Math.min(i11, p10);
            float w10 = w(i14);
            float l10 = l(i14);
            int i16 = z(i14) == i13 ? i13 : 0;
            int i17 = i16 ^ 1;
            for (int max = Math.max(i10, v10); max < min; max++) {
                boolean K = K(max);
                if (i16 != 0 && !K) {
                    d10 = vVar.b(max);
                    e10 = vVar.c(max + 1);
                } else if (i16 != 0 && K) {
                    e10 = vVar.d(max);
                    d10 = vVar.e(max + 1);
                } else if (i17 == 0 || !K) {
                    d10 = vVar.d(max);
                    e10 = vVar.e(max + 1);
                } else {
                    e10 = vVar.b(max);
                    d10 = vVar.c(max + 1);
                }
                fArr[i15] = d10;
                fArr[i15 + 1] = w10;
                fArr[i15 + 2] = e10;
                fArr[i15 + 3] = l10;
                i15 += 4;
            }
            if (i14 == q11) {
                return;
            }
            i14++;
            i13 = 1;
        }
    }

    public final void b(int i10, float[] fArr) {
        float d10;
        float e10;
        int v10 = v(i10);
        int p10 = p(i10);
        int i11 = 0;
        if (!(fArr.length >= (p10 - v10) * 2)) {
            throw new IllegalArgumentException("array.size - arrayStart must be greater or equal than (endOffset - startOffset) * 2".toString());
        }
        v vVar = new v(this);
        boolean z10 = z(i10) == 1;
        while (v10 < p10) {
            boolean K = K(v10);
            if (z10 && !K) {
                d10 = vVar.b(v10);
                e10 = vVar.c(v10 + 1);
            } else if (z10 && K) {
                e10 = vVar.d(v10);
                d10 = vVar.e(v10 + 1);
            } else if (K) {
                e10 = vVar.b(v10);
                d10 = vVar.c(v10 + 1);
            } else {
                d10 = vVar.d(v10);
                e10 = vVar.e(v10 + 1);
            }
            fArr[i11] = d10;
            fArr[i11 + 1] = e10;
            i11 += 2;
            v10++;
        }
    }

    public final RectF c(int i10) {
        float D;
        float D2;
        float A;
        float A2;
        int q10 = q(i10);
        float w10 = w(q10);
        float l10 = l(q10);
        boolean z10 = z(q10) == 1;
        boolean isRtlCharAt = this.f34395g.isRtlCharAt(i10);
        if (!z10 || isRtlCharAt) {
            if (z10 && isRtlCharAt) {
                A = D(i10, false);
                A2 = D(i10 + 1, true);
            } else if (isRtlCharAt) {
                A = A(i10, false);
                A2 = A(i10 + 1, true);
            } else {
                D = D(i10, false);
                D2 = D(i10 + 1, true);
            }
            float f10 = A;
            D = A2;
            D2 = f10;
        } else {
            D = A(i10, false);
            D2 = A(i10 + 1, true);
        }
        return new RectF(D, w10, D2, l10);
    }

    public final boolean d() {
        return this.f34393e;
    }

    public final boolean e() {
        return this.f34391c;
    }

    public final int f() {
        return (this.f34393e ? this.f34395g.getLineBottom(this.f34396h - 1) : this.f34395g.getHeight()) + this.f34397i + this.f34398j + this.f34403o;
    }

    public final boolean h() {
        return this.f34390b;
    }

    public final Layout i() {
        return this.f34395g;
    }

    public final float k(int i10) {
        return this.f34397i + ((i10 != this.f34396h + (-1) || this.f34402n == null) ? this.f34395g.getLineBaseline(i10) : w(i10) - this.f34402n.ascent);
    }

    public final float l(int i10) {
        if (i10 != this.f34396h - 1 || this.f34402n == null) {
            return this.f34397i + this.f34395g.getLineBottom(i10) + (i10 == this.f34396h + (-1) ? this.f34398j : 0);
        }
        return this.f34395g.getLineBottom(i10 - 1) + this.f34402n.bottom;
    }

    public final int m() {
        return this.f34396h;
    }

    public final int n(int i10) {
        return this.f34395g.getEllipsisCount(i10);
    }

    public final int o(int i10) {
        return this.f34395g.getEllipsisStart(i10);
    }

    public final int p(int i10) {
        return this.f34395g.getEllipsisStart(i10) == 0 ? this.f34395g.getLineEnd(i10) : this.f34395g.getText().length();
    }

    public final int q(int i10) {
        return this.f34395g.getLineForOffset(i10);
    }

    public final int r(int i10) {
        return this.f34395g.getLineForVertical(i10 - this.f34397i);
    }

    public final float s(int i10) {
        return l(i10) - w(i10);
    }

    public final float t(int i10) {
        return this.f34395g.getLineLeft(i10) + (i10 == this.f34396h + (-1) ? this.f34399k : BitmapDescriptorFactory.HUE_RED);
    }

    public final float u(int i10) {
        return this.f34395g.getLineRight(i10) + (i10 == this.f34396h + (-1) ? this.f34400l : BitmapDescriptorFactory.HUE_RED);
    }

    public final int v(int i10) {
        return this.f34395g.getLineStart(i10);
    }

    public final float w(int i10) {
        return this.f34395g.getLineTop(i10) + (i10 == 0 ? 0 : this.f34397i);
    }

    public final int x(int i10) {
        if (this.f34395g.getEllipsisStart(i10) == 0) {
            return j().e(i10);
        }
        return this.f34395g.getEllipsisStart(i10) + this.f34395g.getLineStart(i10);
    }

    public final int y(int i10, float f10) {
        return this.f34395g.getOffsetForHorizontal(i10, f10 + ((-1) * g(i10)));
    }

    public final int z(int i10) {
        return this.f34395g.getParagraphDirection(i10);
    }

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public /* synthetic */ u0(CharSequence charSequence, float f10, TextPaint textPaint, int i10, TextUtils.TruncateAt truncateAt, int i11, float f11, float f12, boolean z10, boolean z11, int i12, int i13, int i14, int i15, int i16, int i17, int[] iArr, int[] iArr2, z zVar, int i18, kotlin.jvm.internal.k kVar) {
        this(charSequence, f10, textPaint, r7, r8, r9, (i18 & 64) != 0 ? 1.0f : f11, (i18 & 128) != 0 ? 0.0f : f12, (i18 & 256) != 0 ? false : z10, (i18 & 512) != 0 ? true : z11, (i18 & UserMetadata.MAX_ATTRIBUTE_SIZE) != 0 ? Integer.MAX_VALUE : i12, (i18 & 2048) != 0 ? 0 : i13, (i18 & 4096) != 0 ? 0 : i14, (i18 & UserMetadata.MAX_INTERNAL_KEY_SIZE) != 0 ? 0 : i15, (i18 & 16384) != 0 ? 0 : i16, (32768 & i18) != 0 ? 0 : i17, (65536 & i18) != 0 ? null : iArr, (131072 & i18) != 0 ? null : iArr2, (i18 & 262144) != 0 ? new z(charSequence, textPaint, r9) : zVar);
        int i19 = (i18 & 8) != 0 ? 0 : i10;
        TextUtils.TruncateAt truncateAt2 = (i18 & 16) != 0 ? null : truncateAt;
        int i20 = (i18 & 32) != 0 ? 2 : i11;
    }
}
