package com.amazing.utils;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.text.TextPaint;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;

public class TextMeshUtils {
    static {
        Covode.recordClassIndex(2315);
    }

    public static float getDeviceDpi() {
        return (float) Resources.getSystem().getDisplayMetrics().densityDpi;
    }

    /* JADX WARNING: Removed duplicated region for block: B:50:0x00d1 A[SYNTHETIC, Splitter:B:50:0x00d1] */
    /* JADX WARNING: Removed duplicated region for block: B:59:0x00db A[SYNTHETIC, Splitter:B:59:0x00db] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static java.lang.String[] getAndroidSystemFontPaths() {
        /*
            r11 = 6312(0x18a8, float:8.845E-42)
            com.bytedance.frameworks.apm.trace.MethodCollector.i(r11)
            r10 = 0
            org.xmlpull.v1.XmlPullParser r6 = android.util.Xml.newPullParser()     // Catch:{ Exception -> 0x00d8, all -> 0x00cb }
            java.io.File r1 = new java.io.File     // Catch:{ Exception -> 0x00d8, all -> 0x00cb }
            java.lang.String r0 = "/system/etc/fonts.xml"
            r1.<init>(r0)     // Catch:{ Exception -> 0x00d8, all -> 0x00cb }
            java.io.FileInputStream r3 = new java.io.FileInputStream     // Catch:{ Exception -> 0x00d8, all -> 0x00cb }
            r3.<init>(r1)     // Catch:{ Exception -> 0x00d8, all -> 0x00cb }
            java.lang.String r0 = "utf-8"
            r6.setInput(r3, r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            int r7 = r6.getEventType()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            java.util.ArrayList r4 = new java.util.ArrayList     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            r4.<init>()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            java.util.ArrayList r5 = new java.util.ArrayList     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            r5.<init>()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            r2 = r10
        L_0x002a:
            r0 = 1
            if (r7 == r0) goto L_0x00bb
            r0 = 2
            java.lang.String r1 = "family"
            if (r7 == r0) goto L_0x00a3
            r0 = 3
            if (r7 == r0) goto L_0x0039
            r0 = 4
            if (r7 == r0) goto L_0x00b1
            goto L_0x00b5
        L_0x0039:
            java.lang.String r0 = r6.getName()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            boolean r0 = r1.equals(r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            if (r0 == 0) goto L_0x0084
            r9 = -1
            r8 = 0
            r7 = 0
        L_0x0046:
            int r0 = r5.size()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            if (r7 >= r0) goto L_0x005f
            java.lang.Object r1 = r5.get(r7)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            java.lang.String r1 = (java.lang.String) r1     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            java.lang.String r0 = "Regular"
            boolean r0 = r1.contains(r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            if (r0 == 0) goto L_0x005b
            goto L_0x005e
        L_0x005b:
            int r7 = r7 + 1
            goto L_0x0046
        L_0x005e:
            r9 = r7
        L_0x005f:
            java.lang.String r1 = new java.lang.String     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            java.lang.String r0 = "/system/fonts/"
            r1.<init>(r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            if (r9 < 0) goto L_0x0076
            java.lang.Object r0 = r5.get(r9)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            java.lang.String r0 = (java.lang.String) r0     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            java.lang.String r0 = r1.concat(r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            r4.add(r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            goto L_0x00b5
        L_0x0076:
            java.lang.Object r0 = r5.get(r8)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            java.lang.String r0 = (java.lang.String) r0     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            java.lang.String r0 = r1.concat(r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            r4.add(r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            goto L_0x00b5
        L_0x0084:
            java.lang.String r1 = "font"
            java.lang.String r0 = r6.getName()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            boolean r0 = r1.equals(r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            if (r0 == 0) goto L_0x0094
            r5.add(r2)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            goto L_0x00b5
        L_0x0094:
            java.lang.String r1 = "familyset"
            java.lang.String r0 = r6.getName()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            boolean r0 = r1.equals(r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            if (r0 == 0) goto L_0x00b5
            java.lang.String r2 = "ending"
            goto L_0x00b5
        L_0x00a3:
            java.lang.String r0 = r6.getName()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            boolean r0 = r1.equals(r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            if (r0 == 0) goto L_0x00b5
            r5.clear()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            goto L_0x00b5
        L_0x00b1:
            java.lang.String r2 = r6.getText()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
        L_0x00b5:
            int r7 = r6.next()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            goto L_0x002a
        L_0x00bb:
            int r0 = r4.size()     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            java.lang.String[] r0 = new java.lang.String[r0]     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            r4.toArray(r0)     // Catch:{ Exception -> 0x00d9, all -> 0x00ce }
            r3.close()     // Catch:{ Exception -> 0x00c7 }
        L_0x00c7:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r11)
            return r0
        L_0x00cb:
            r0 = move-exception
            r3 = r10
            goto L_0x00cf
        L_0x00ce:
            r0 = move-exception
        L_0x00cf:
            if (r3 == 0) goto L_0x00d4
            r3.close()     // Catch:{ Exception -> 0x00d4 }
        L_0x00d4:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r11)
            throw r0
        L_0x00d8:
            r3 = r10
        L_0x00d9:
            if (r3 == 0) goto L_0x00de
            r3.close()     // Catch:{ Exception -> 0x00de }
        L_0x00de:
            com.bytedance.frameworks.apm.trace.MethodCollector.o(r11)
            return r10
        */
        throw new UnsupportedOperationException("Method not decompiled: com.amazing.utils.TextMeshUtils.getAndroidSystemFontPaths():java.lang.String[]");
    }

    public static Bitmap callIStaticGenerateBitmapForEmoji(byte[] bArr, int i) {
        MethodCollector.i(15512);
        String str = new String(bArr);
        TextPaint textPaint = new TextPaint();
        textPaint.setTextSize((float) i);
        textPaint.setAntiAlias(true);
        textPaint.setStyle(Paint.Style.FILL);
        textPaint.setTextAlign(Paint.Align.LEFT);
        Rect rect = new Rect();
        textPaint.getTextBounds(str, 0, str.length(), rect);
        Bitmap createBitmap = Bitmap.createBitmap(rect.width(), rect.height(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(createBitmap);
        canvas.drawText(str, (float) (-rect.left), (float) (-rect.top), textPaint);
        canvas.save();
        canvas.restore();
        MethodCollector.o(15512);
        return createBitmap;
    }

    public static float[] generateImageSize(String str, float f, byte[] bArr, int i, boolean z, float f2, int i2, boolean z2, float f3, float f4, int i3, float f5) {
        String str2 = new String(bArr);
        TextPaint textPaint = new TextPaint();
        textPaint.setTextSize(f);
        textPaint.setAntiAlias(true);
        textPaint.setStyle(Paint.Style.FILL);
        textPaint.setTextAlign(Paint.Align.LEFT);
        textPaint.setColor(i);
        Rect rect = new Rect();
        float[] fArr = new float[str2.length()];
        textPaint.getTextWidths(str2, fArr);
        textPaint.getTextBounds(str2, 0, str2.length(), rect);
        if (!z) {
            f2 = 0.0f;
        }
        if (!z2) {
            f3 = 0.0f;
            f4 = 0.0f;
        }
        return new float[]{(float) rect.left, (float) rect.right, (float) (-rect.bottom), (float) (-rect.top), fArr[0], (f2 + Math.max(Math.abs(f3), Math.abs(f4))) * f, textPaint.ascent(), textPaint.descent()};
    }

    public static Bitmap generateImage(String str, float f, byte[] bArr, int i, boolean z, float f2, int i2, boolean z2, float f3, float f4, int i3, float f5) {
        float f6 = f2;
        float f7 = f4;
        float f8 = f5;
        MethodCollector.i(6306);
        String str2 = new String(bArr);
        TextPaint textPaint = new TextPaint();
        textPaint.setTextSize(f);
        textPaint.setAntiAlias(true);
        textPaint.setStyle(Paint.Style.FILL);
        textPaint.setTextAlign(Paint.Align.LEFT);
        textPaint.setColor(i);
        Rect rect = new Rect();
        textPaint.getTextWidths(str2, new float[str2.length()]);
        textPaint.getTextBounds(str2, 0, str2.length(), rect);
        float f9 = 0.0f;
        if (!z) {
            f6 = 0.0f;
        }
        if (!z2) {
            f7 = 0.0f;
            f8 = 0.0f;
        } else {
            f9 = f3;
        }
        float max = Math.max(Math.abs(f9), Math.abs(f7)) + f6;
        TextPaint textPaint2 = new TextPaint();
        if (z || z2) {
            textPaint2.setTextSize(f);
            textPaint2.setAntiAlias(true);
            textPaint2.setStyle(Paint.Style.STROKE);
            textPaint2.setTextAlign(Paint.Align.LEFT);
            textPaint2.setStrokeWidth(f6 * 2.0f * f);
            textPaint2.setColor(i2);
            if (z2) {
                textPaint2.setShadowLayer(f8 * f, f9 * f, f7 * f, i3);
            }
        }
        float f10 = 2.0f * max * f;
        Bitmap createBitmap = Bitmap.createBitmap((int) (((float) rect.width()) + f10), (int) (((float) rect.height()) + f10), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(createBitmap);
        if (z || z2) {
            float f11 = max * f;
            canvas.drawText(str2, ((float) (-rect.left)) + f11, ((float) (-rect.top)) + f11, textPaint2);
        }
        float f12 = max * f;
        canvas.drawText(str2, ((float) (-rect.left)) + f12, ((float) (-rect.top)) + f12, textPaint);
        canvas.save();
        canvas.restore();
        MethodCollector.o(6306);
        return createBitmap;
    }

    public static Bitmap callIStaticGenerateBitmapFromTextMesh(byte[] bArr, String str, int i, int i2, int i3, float f, int i4, float f2, int i5, float f3, float f4, float f5, int i6, int i7, int i8, int i9) {
        MethodCollector.i(15339);
        String str2 = new String(bArr);
        int i10 = i8;
        int i11 = i9;
        Rect rect = new Rect(0, 0, i10, i11);
        Bitmap createBitmap = Bitmap.createBitmap(i10, i11, Bitmap.Config.ARGB_8888);
        Paint paint = new Paint();
        paint.setColor(0);
        paint.setStyle(Paint.Style.FILL);
        Canvas canvas = new Canvas(createBitmap);
        TextPaint textPaint = new TextPaint();
        textPaint.setColor(i2);
        float f6 = (float) i;
        textPaint.setTextSize(f6);
        textPaint.setAntiAlias(true);
        textPaint.setStyle(Paint.Style.FILL);
        int i12 = i7;
        if (i12 == 0) {
            textPaint.setTextAlign(Paint.Align.LEFT);
        } else if (i12 == 1) {
            textPaint.setTextAlign(Paint.Align.CENTER);
        } else {
            textPaint.setTextAlign(Paint.Align.RIGHT);
        }
        if ((i4 & 16) == 16) {
            textPaint.setUnderlineText(true);
        }
        if ((i4 & 32) == 32) {
            textPaint.setStrikeThruText(true);
        }
        if ((i4 & 4) == 4) {
            textPaint.setTextSkewX((-f) / 90.0f);
        }
        if ((i4 & 8) == 8) {
            textPaint.setFakeBoldText(true);
        }
        if ((i4 & 2) == 2) {
            float f7 = f4;
            textPaint.setShadowLayer(f3, f7, f5, i6);
        }
        Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
        float f8 = fontMetrics.top;
        float f9 = fontMetrics.bottom;
        String[] split = str2.split("\n");
        int length = split.length;
        int i13 = i3;
        if ((i4 & 1) == 1) {
            TextPaint textPaint2 = new TextPaint();
            textPaint2.setColor(i5);
            textPaint2.setTextSize(textPaint.getTextSize());
            textPaint2.setAntiAlias(textPaint.isAntiAlias());
            textPaint2.setStyle(Paint.Style.STROKE);
            textPaint2.setStrokeWidth((5.0f * f2) / f6);
            textPaint2.setTextAlign(textPaint.getTextAlign());
            textPaint2.setTextSkewX(textPaint.getTextSkewX());
            textPaint.setFakeBoldText(false);
            textPaint2.setFakeBoldText(true);
            float f10 = ((float) i13) / f6;
            float f11 = (-fontMetrics.ascent) + fontMetrics.descent;
            float f12 = f11 * 0.1f;
            for (int i14 = 0; i14 < length; i14++) {
                int centerY = (int) (((double) ((int) ((((float) rect.centerY()) - (f8 / 2.0f)) - (f9 / 2.0f)))) - (((((double) (length - 1)) * 0.5d) - ((double) i14)) * ((double) (f12 + f11))));
                textPaint2.setLetterSpacing(f10);
                if (i12 == 0) {
                    canvas.drawText(split[i14], (float) rect.left, (float) centerY, textPaint2);
                } else if (i12 == 1) {
                    canvas.drawText(split[i14], (float) rect.centerX(), (float) centerY, textPaint2);
                } else {
                    canvas.drawText(split[i14], (float) rect.right, (float) centerY, textPaint2);
                }
            }
        }
        float f13 = ((float) i13) / f6;
        float f14 = (-fontMetrics.ascent) + fontMetrics.descent;
        float f15 = 0.1f * f14;
        for (int i15 = 0; i15 < length; i15++) {
            int centerY2 = (int) (((double) ((int) ((((float) rect.centerY()) - (f8 / 2.0f)) - (f9 / 2.0f)))) - (((((double) (length - 1)) * 0.5d) - ((double) i15)) * ((double) (f15 + f14))));
            textPaint.setLetterSpacing(f13);
            if (i12 == 0) {
                canvas.drawText(split[i15], (float) rect.left, (float) centerY2, textPaint);
            } else if (i12 == 1) {
                canvas.drawText(split[i15], (float) rect.centerX(), (float) centerY2, textPaint);
            } else {
                canvas.drawText(split[i15], (float) rect.right, (float) centerY2, textPaint);
            }
        }
        canvas.save();
        canvas.restore();
        MethodCollector.o(15339);
        return createBitmap;
    }
}
