package r2;

import android.graphics.PointF;
import androidx.annotation.Nullable;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/* JADX INFO: loaded from: classes.dex */
public final class d {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Pattern f32342b = Pattern.compile("\\{([^}]*)\\}");

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final Pattern f32343c = Pattern.compile(Util.formatInvariant("\\\\pos\\((%1$s),(%1$s)\\)", "\\s*\\d+(?:\\.\\d+)?\\s*"));

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final Pattern f32344d = Pattern.compile(Util.formatInvariant("\\\\move\\(%1$s,%1$s,(%1$s),(%1$s)(?:,%1$s,%1$s)?\\)", "\\s*\\d+(?:\\.\\d+)?\\s*"));

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final Pattern f32345e = Pattern.compile("\\\\an(\\d+)");

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final int f32346a;

    @Nullable
    public final PointF position;

    private d(int i10, @Nullable PointF pointF) {
        this.f32346a = i10;
        this.position = pointF;
    }

    public static d a(String str) {
        Matcher matcher = f32342b.matcher(str);
        PointF pointF = null;
        int i10 = -1;
        while (matcher.find()) {
            String str2 = (String) Assertions.checkNotNull(matcher.group(1));
            try {
                PointF position = parsePosition(str2);
                if (position != null) {
                    pointF = position;
                }
            } catch (RuntimeException unused) {
            }
            try {
                Matcher matcher2 = f32345e.matcher(str2);
                int iA = matcher2.find() ? e.a((String) Assertions.checkNotNull(matcher2.group(1))) : -1;
                if (iA != -1) {
                    i10 = iA;
                }
            } catch (RuntimeException unused2) {
            }
        }
        return new d(i10, pointF);
    }

    @Nullable
    private static PointF parsePosition(String str) {
        String strGroup;
        String strGroup2;
        Matcher matcher = f32343c.matcher(str);
        Matcher matcher2 = f32344d.matcher(str);
        boolean zFind = matcher.find();
        boolean zFind2 = matcher2.find();
        if (zFind) {
            if (zFind2) {
                Log.i("SsaStyle.Overrides", "Override has both \\pos(x,y) and \\move(x1,y1,x2,y2); using \\pos values. override='" + str + "'");
            }
            strGroup = matcher.group(1);
            strGroup2 = matcher.group(2);
        } else {
            if (!zFind2) {
                return null;
            }
            strGroup = matcher2.group(1);
            strGroup2 = matcher2.group(2);
        }
        return new PointF(Float.parseFloat(((String) Assertions.checkNotNull(strGroup)).trim()), Float.parseFloat(((String) Assertions.checkNotNull(strGroup2)).trim()));
    }
}
