package com.firemint.realracing; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Typeface; import java.nio.ByteBuffer; /* loaded from: classes2.dex */ class Font { public static final int OUTLINE_INSIDE = 2; public static final int OUTLINE_NONE = 0; public static final int OUTLINE_OUTSIDE = 3; public static final int OUTLINE_STROKE = 1; private Typeface m_typeface; private float m_size = 0.0f; private float m_widthScale = 1.0f; public Paint defaultPaint = null; public float ascent = 0.0f; public float descent = 0.0f; public float height = 0.0f; public float top = 0.0f; public float bottom = 0.0f; public float leading = 0.0f; public float glyphOffX = 0.0f; public float glyphOffY = 0.0f; public float glyphWidth = 0.0f; public float glyphHeight = 0.0f; public float glyphAdvance = 0.0f; public int bmpLeft = 0; public int bmpTop = 0; public int bmpWidth = 0; public int bmpHeight = 0; public int bmpPitch = 0; byte[] bmpData = null; public float getSize() { return this.m_size; } public Typeface getTypeface() { return this.m_typeface; } public float getWidthScale() { return this.m_widthScale; } public boolean init(String str, boolean z, boolean z2, float f, float f2) { Typeface createFromFile = Typeface.createFromFile(str); if (createFromFile == null) { return false; } Typeface create = Typeface.create(createFromFile, (z && z2) ? 3 : z ? 1 : z2 ? 2 : 0); this.m_typeface = create; if (create == null) { return false; } this.m_size = f; if (f2 > 0.0f) { this.m_widthScale = f2; } Paint paint = new Paint(); this.defaultPaint = paint; paint.setColor(-1); this.defaultPaint.setTypeface(this.m_typeface); this.defaultPaint.setTextSize(this.m_size); this.defaultPaint.setTextScaleX(this.m_widthScale); this.defaultPaint.setAntiAlias(true); this.defaultPaint.setTextAlign(Paint.Align.LEFT); Paint.FontMetrics fontMetrics = this.defaultPaint.getFontMetrics(); float f3 = -fontMetrics.ascent; this.ascent = f3; float f4 = fontMetrics.descent; this.descent = f4; this.height = f3 + f4; this.top = -fontMetrics.top; this.bottom = fontMetrics.bottom; this.leading = fontMetrics.leading; return true; } public boolean loadGlyph(int i) { if (this.defaultPaint == null) { return false; } try { String str = new String(new int[]{i}, 0, 1); this.defaultPaint.getTextBounds(str, 0, str.length(), new Rect()); this.glyphOffX = r6.left; this.glyphOffY = -r6.top; this.glyphWidth = r6.width(); this.glyphHeight = r6.height(); float[] fArr = new float[str.length()]; this.defaultPaint.getTextWidths(str, fArr); this.glyphAdvance = fArr[0]; return true; } catch (IllegalArgumentException unused) { return false; } } public boolean loadBitmap(int i, float f, float f2, float f3, int i2) { if (this.defaultPaint == null) { return false; } try { String str = new String(new int[]{i}, 0, 1); this.defaultPaint.getTextBounds(str, 0, str.length(), new Rect()); float f4 = (i2 == 1 || i2 == 3) ? 1.0f + f3 : 1.0f; float floor = (float) Math.floor((r7.left + f) - f4); float ceil = (float) Math.ceil(r7.right + f + f4); float floor2 = (float) Math.floor(f4); float ceil2 = (float) Math.ceil((r7.bottom - r7.top) + f4); this.bmpLeft = (int) floor; this.bmpTop = -((int) floor2); int i3 = (int) (ceil - floor); this.bmpWidth = i3; int i4 = (int) (ceil2 - floor2); this.bmpHeight = i4; if (i3 > 0 && i4 > 0) { Bitmap createBitmap = Bitmap.createBitmap(i3, i4, Bitmap.Config.ALPHA_8); Canvas canvas = new Canvas(createBitmap); createBitmap.eraseColor(Color.argb(0, 0, 0, 0)); canvas.drawText(str, f - floor, 0.0f, this.defaultPaint); byte[] bArr = new byte[createBitmap.getWidth() * createBitmap.getHeight()]; this.bmpData = bArr; createBitmap.copyPixelsToBuffer(ByteBuffer.wrap(bArr)); this.bmpPitch = createBitmap.getRowBytes(); createBitmap.recycle(); return true; } } catch (IllegalArgumentException unused) { } return false; } public boolean loadBitmapDynamic(int i, float f, float f2, float f3, int i2) { if (this.defaultPaint == null) { return false; } try { String str = new String(new int[]{i}, 0, 1); this.defaultPaint.getTextBounds(str, 0, str.length(), new Rect()); float f4 = (i2 == 1 || i2 == 3) ? 1.0f + f3 : 1.0f; float f5 = -f2; float floor = (float) Math.floor((r8.left + f) - f4); float ceil = (float) Math.ceil(r8.right + f + f4); float floor2 = (float) Math.floor((r8.top + f5) - f4); float ceil2 = (float) Math.ceil(r8.bottom + f5 + f4); this.bmpLeft = (int) floor; this.bmpTop = -((int) floor2); int i3 = (int) (ceil - floor); this.bmpWidth = i3; int i4 = (int) (ceil2 - floor2); this.bmpHeight = i4; if (i3 > 0 && i4 > 0) { Bitmap createBitmap = Bitmap.createBitmap(i3, i4, Bitmap.Config.ALPHA_8); Canvas canvas = new Canvas(createBitmap); createBitmap.eraseColor(Color.argb(0, 0, 0, 0)); canvas.drawText(str, f - floor, f5 - floor2, this.defaultPaint); byte[] bArr = new byte[createBitmap.getWidth() * createBitmap.getHeight()]; this.bmpData = bArr; createBitmap.copyPixelsToBuffer(ByteBuffer.wrap(bArr)); this.bmpPitch = createBitmap.getRowBytes(); createBitmap.recycle(); return true; } } catch (IllegalArgumentException unused) { } return false; } }