package com.firemint.realracing; import android.annotation.TargetApi; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.opengl.GLUtils; import android.text.BoringLayout; import android.text.Layout; import android.text.StaticLayout; import android.text.TextPaint; import android.text.TextUtils; import android.util.Log; import androidx.work.Data; import javax.microedition.khronos.opengles.GL10; /* loaded from: classes2.dex */ class GlyphVector { public static final int fmParagraphAlignCentered = 2; public static final int fmParagraphAlignJustified = 3; public static final int fmParagraphAlignLeft = 0; public static final int fmParagraphAlignNatural = 4; public static final int fmParagraphAlignRight = 1; public static final int fmParagraphCharWrap = 1; public static final int fmParagraphClip = 2; public static final int fmParagraphTruncateHead = 3; public static final int fmParagraphTruncateMiddle = 5; public static final int fmParagraphTruncateTail = 4; public static final int fmParagraphWordWrap = 0; public static final int fmParagraphWordWrapTruncate = 6; public float offsetX = 0.0f; public float offsetY = 0.0f; public float boundsW = 0.0f; public float boundsH = 0.0f; public float pixelBoundsW = 0.0f; public float pixelBoundsH = 0.0f; public float pixelTopOffset = 0.0f; public int numLines = 0; public int texId = -1; public int texWidth = 0; public int texHeight = 0; private String m_text = null; private TextPaint m_paint = null; private Rect m_bounds = null; private Layout m_layout = null; private int m_ellipsisOffset = 0; private StaticLayout m_ellipsisLayout = null; private String sanitize(String str) { return str; } public void init(Font font, String str) { String sanitize = sanitize(str); this.m_text = sanitize; TextPaint textPaint = new TextPaint(); this.m_paint = textPaint; textPaint.setColor(-1); this.m_paint.setTypeface(font.getTypeface()); this.m_paint.setTextSize(font.getSize()); this.m_paint.setTextScaleX(font.getWidthScale()); this.m_paint.setTextAlign(Paint.Align.LEFT); this.m_paint.setAntiAlias(true); this.m_bounds = new Rect(); this.m_paint.getTextBounds(sanitize, 0, sanitize.length(), this.m_bounds); Rect rect = this.m_bounds; rect.top--; rect.bottom = rect.bottom + 1; this.offsetX = -rect.left; this.offsetY = -r6; this.boundsW = rect.width(); this.boundsH = this.m_bounds.height(); this.pixelBoundsW = this.m_bounds.width(); this.pixelBoundsH = this.m_bounds.height(); this.pixelTopOffset = 0.0f; this.numLines = 1; } @TargetApi(29) public void initWithParagraph(Font font, String str, float f, float f2, int i, int i2) { int i3; int i4; int i5; float f3; float f4; int i6; float f5; String sanitize = sanitize(str); this.m_text = sanitize; TextPaint textPaint = new TextPaint(); this.m_paint = textPaint; textPaint.setColor(-1); this.m_paint.setTypeface(font.getTypeface()); this.m_paint.setTextSize(font.getSize()); this.m_paint.setTextScaleX(font.getWidthScale()); this.m_paint.setAntiAlias(true); float f6 = f < 0.0f ? 0.0f : f; float f7 = f2 < 0.0f ? 0.0f : f2; Layout.Alignment alignment = Layout.Alignment.ALIGN_NORMAL; if (i2 != 0) { if (i2 == 1) { alignment = Layout.Alignment.ALIGN_OPPOSITE; } else if (i2 == 2) { alignment = Layout.Alignment.ALIGN_CENTER; } } Layout.Alignment alignment2 = alignment; if (i == 1) { Log.e("RealRacing3", "Using unsupported text break style: fmParagraphCharWrap! Falling back to WordWrap."); i3 = 0; } else { i3 = i; } if (i3 == 0 || i3 == 1 || i3 == 2 || i3 == 6) { i4 = i3; i5 = 0; f3 = f7; f4 = f6; this.m_layout = new StaticLayout(sanitize, this.m_paint, (int) f4, alignment2, 1.0f, 0.0f, false); } else { TextUtils.TruncateAt truncateAt = TextUtils.TruncateAt.START; if (i3 != 3) { if (i3 == 4) { truncateAt = TextUtils.TruncateAt.END; } else if (i3 == 5) { truncateAt = TextUtils.TruncateAt.MIDDLE; } } TextUtils.TruncateAt truncateAt2 = truncateAt; sanitize.replace('\n', ' '); BoringLayout.Metrics isBoring = BoringLayout.isBoring(sanitize, this.m_paint); if (isBoring != null) { i4 = i3; f3 = f7; this.m_layout = new BoringLayout(sanitize, this.m_paint, (int) (2.0f * f6), alignment2, 1.0f, 0.0f, isBoring, false, truncateAt2, (int) f6); f5 = f6; } else { i4 = i3; f3 = f7; f5 = f6; this.m_layout = new StaticLayout(sanitize, 0, sanitize.length(), this.m_paint, (int) (2.0f * f6), alignment2, 1.0f, 0.0f, false, truncateAt2, (int) f6); } int i7 = 0; while (true) { if (i7 >= this.m_layout.getLineCount()) { f4 = f5; i5 = 0; break; } else { if (this.m_layout.getEllipsisCount(i7) > 0) { i5 = 0; sanitize = this.m_layout.getText().toString().substring(0, this.m_layout.getLineStart(i7) + this.m_layout.getEllipsisStart(i7) + 1); f4 = f5; this.m_layout = new StaticLayout(sanitize, 0, sanitize.length(), this.m_paint, (int) f4, alignment2, 1.0f, 0.0f, false); break; } i7++; } } } this.m_bounds = findLayoutBounds(this.m_layout); this.numLines = this.m_layout.getLineCount(); int i8 = i4; float f8 = f3; if (i8 == 2 && f8 > 0.0f) { int i9 = i5; while (true) { if (i9 >= this.numLines) { break; } if (this.m_layout.getLineBottom(i9) - this.m_bounds.top > ((int) f8)) { int i10 = i9 - 1; if (i10 < 0) { i10 = i5; } Layout staticLayout = new StaticLayout(sanitize, 0, this.m_layout.getLineVisibleEnd(i10), this.m_paint, (int) f4, alignment2, 1.0f, 0.0f, false); this.m_layout = staticLayout; this.m_bounds = findLayoutBounds(staticLayout); this.numLines = this.m_layout.getLineCount(); } else { i9++; } } } if (i8 == 6 && f8 > 0.0f) { int i11 = i5; while (true) { if (i11 >= this.numLines) { break; } if (this.m_layout.getLineBottom(i11) - this.m_bounds.top > ((int) f8)) { int i12 = i11 - 1; if (i12 < 0) { i12 = i5; } int lineStart = this.m_layout.getLineStart(i12); int length = sanitize.length(); TextPaint textPaint2 = this.m_paint; int i13 = (int) f4; TextUtils.TruncateAt truncateAt3 = TextUtils.TruncateAt.END; StaticLayout staticLayout2 = new StaticLayout(sanitize, lineStart, length, textPaint2, i13, alignment2, 1.0f, 0.0f, false, truncateAt3, i13); this.m_ellipsisLayout = staticLayout2; Rect findLayoutBounds = findLayoutBounds(staticLayout2); if (this.m_ellipsisLayout.getLineCount() > 1) { String substring = sanitize.substring(this.m_ellipsisLayout.getLineStart(i5), this.m_ellipsisLayout.getLineVisibleEnd(i5)); if (!substring.endsWith("…")) { substring = substring + "…"; } String str2 = substring; StaticLayout staticLayout3 = new StaticLayout(str2, 0, str2.length(), this.m_paint, i13, alignment2, 1.0f, 0.0f, false, truncateAt3, i13); this.m_ellipsisLayout = staticLayout3; findLayoutBounds = findLayoutBounds(staticLayout3); } if (i12 > 0) { Layout staticLayout4 = new StaticLayout(sanitize, 0, this.m_layout.getLineVisibleEnd(i12 - 1), this.m_paint, i13, alignment2, 1.0f, 0.0f, false); this.m_layout = staticLayout4; Rect findLayoutBounds2 = findLayoutBounds(staticLayout4); this.m_bounds = findLayoutBounds2; int height = findLayoutBounds2.height(); this.m_ellipsisOffset = height; findLayoutBounds.offset(i5, height); this.m_bounds.union(findLayoutBounds); this.numLines = this.m_layout.getLineCount() + this.m_ellipsisLayout.getLineCount(); } else { StaticLayout staticLayout5 = this.m_ellipsisLayout; this.m_layout = staticLayout5; this.m_ellipsisLayout = null; this.m_bounds = findLayoutBounds; this.numLines = staticLayout5.getLineCount(); } } else { i11++; } } } Rect rect = new Rect(); rect.left = 10000000; rect.right = -10000000; rect.top = 10000000; rect.bottom = -10000000; this.pixelTopOffset = 0.0f; int i14 = i5; while (true) { i6 = this.numLines; if (i14 >= i6) { break; } Rect rect2 = new Rect(); this.m_paint.getTextBounds(sanitize, this.m_layout.getLineStart(i14), this.m_layout.getLineEnd(i14), rect2); float lineBaseline = this.m_layout.getLineBaseline(i14); if (i14 == 0) { this.pixelTopOffset = (rect2.top + lineBaseline) - this.m_layout.getLineTop(i14); } int i15 = (int) (rect2.top + lineBaseline); rect2.top = i15; int i16 = (int) (rect2.bottom + lineBaseline); rect2.bottom = i16; int i17 = rect2.left; if (i17 < rect.left) { rect.left = i17; } int i18 = rect2.right; if (i18 > rect.right) { rect.right = i18; } if (i15 < rect.top) { rect.top = i15; } if (i16 > rect.bottom) { rect.bottom = i16; } i14++; } if (i6 > 0) { this.offsetX = 0.0f; Rect rect3 = new Rect(); int lineCount = this.m_layout.getLineCount() - 1; this.m_paint.getTextBounds(sanitize, this.m_layout.getLineStart(lineCount), this.m_layout.getLineEnd(lineCount), rect3); this.offsetY = Math.max(rect3.bottom - (MainActivity.IsAtLeastAPI(29) ? this.m_paint.getUnderlinePosition() : 0.0f), 0.0f); } this.boundsW = this.m_bounds.width(); this.boundsH = this.m_bounds.height(); this.pixelBoundsW = rect.right - rect.left; this.pixelBoundsH = rect.bottom - rect.top; } public Rect findLayoutBounds(Layout layout) { int lineCount = layout.getLineCount(); Rect rect = new Rect(); for (int i = 0; i < lineCount; i++) { Rect rect2 = new Rect(); if (layout.getEllipsisCount(i) > 0) { int floor = (int) Math.floor(layout.getLineLeft(i)); rect2.left = floor; rect2.right = floor + layout.getEllipsizedWidth(); } else { rect2.left = (int) Math.floor(layout.getLineLeft(i)); rect2.right = (int) Math.ceil(layout.getLineRight(i)); } rect2.top = layout.getLineTop(i); int lineBottom = layout.getLineBottom(i); rect2.bottom = lineBottom; if (i == 0 || rect2.left < rect.left) { rect.left = rect2.left; } if (i == 0 || rect2.top < rect.top) { rect.top = rect2.top; } if (i == 0 || rect2.right > rect.right) { rect.right = rect2.right; } if (i == 0 || lineBottom > rect.bottom) { rect.bottom = lineBottom; } } return rect; } public boolean createTexture() { if (this.m_text == null || this.m_paint == null || this.m_bounds == null) { return false; } this.texWidth = 1; while (this.texWidth < this.m_bounds.width()) { this.texWidth *= 2; } this.texHeight = 1; while (this.texHeight < this.m_bounds.height()) { this.texHeight *= 2; } Bitmap createBitmap = Bitmap.createBitmap(this.texWidth, this.texHeight, Bitmap.Config.ARGB_4444); Canvas canvas = new Canvas(createBitmap); createBitmap.eraseColor(Color.argb(0, 0, 0, 0)); if (this.m_layout == null) { String str = this.m_text; Rect rect = this.m_bounds; canvas.drawText(str, -rect.left, -rect.top, this.m_paint); } else { canvas.translate(-this.m_bounds.left, -this.pixelTopOffset); this.m_layout.draw(canvas); if (this.m_ellipsisLayout != null) { canvas.translate(0.0f, this.m_ellipsisOffset); this.m_ellipsisLayout.draw(canvas); } } int[] iArr = new int[1]; GL10 gl10 = (GL10) MainActivity.instance.getGLView().getGLContext().getGL(); gl10.glGenTextures(1, iArr, 0); int i = iArr[0]; this.texId = i; if (i < 0) { createBitmap.recycle(); return false; } gl10.glBindTexture(3553, i); gl10.glTexParameterf(3553, 10241, 9729.0f); gl10.glTexParameterf(3553, Data.MAX_DATA_BYTES, 9729.0f); gl10.glTexParameterf(3553, 10242, 33071.0f); gl10.glTexParameterf(3553, 10243, 33071.0f); gl10.glPixelStorei(3317, 1); GLUtils.texImage2D(3553, 0, createBitmap, 0); createBitmap.recycle(); return true; } public boolean renderToTexture(int i, int i2, int i3, float f) { if (this.m_text == null || this.m_paint == null || this.m_bounds == null) { return false; } Bitmap createBitmap = Bitmap.createBitmap(i2, i3, Bitmap.Config.ALPHA_8); Canvas canvas = new Canvas(createBitmap); createBitmap.eraseColor(Color.argb(0, 0, 0, 0)); float f2 = i3; canvas.translate(0.0f, f2); canvas.scale(1.0f, -1.0f); Rect rect = this.m_bounds; canvas.translate(((i2 - (this.m_bounds.width() * f)) * 0.5f) - (rect.left * f), ((f2 - (rect.height() * f)) * 0.5f) - (this.m_bounds.top * f)); canvas.scale(f, f); canvas.drawText(this.m_text, 0.0f, 0.0f, this.m_paint); GL10 gl10 = (GL10) MainActivity.instance.getGLView().getGLContext().getGL(); gl10.glBindTexture(3553, i); gl10.glPixelStorei(3317, 1); GLUtils.texSubImage2D(3553, 0, 0, 0, createBitmap, 6409, 5121); createBitmap.recycle(); return true; } }