package com.kofax.mobile.sdk.t; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; import android.graphics.RectF; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import com.kofax.android.abc.document.Element; import com.kofax.android.abc.document.Field; import java.util.ArrayList; import java.util.Iterator; import org.bouncycastle.asn1.x509.DisplayText; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes3.dex */ class e { private final b NJ = new b(); /* JADX INFO: Access modifiers changed from: package-private */ public Bitmap b(Bitmap bitmap, String str) { return a(bitmap, new a(str)); } /* JADX INFO: Access modifiers changed from: package-private */ public Bitmap a(Bitmap bitmap, Iterable iterable) { Bitmap j = j(bitmap); Canvas canvas = new Canvas(j); Iterator it = iterable.iterator(); while (it.hasNext()) { canvas.drawRect(it.next().getRectangle(), this.NJ.NL); } return j; } /* JADX INFO: Access modifiers changed from: package-private */ public Bitmap b(Bitmap bitmap, Iterable iterable) { Bitmap j = j(bitmap); Canvas canvas = new Canvas(j); Iterator it = iterable.iterator(); while (it.hasNext()) { a(canvas, it.next()); } return j; } public Bitmap c(Bitmap bitmap, Iterable iterable) { Bitmap a2 = a(bitmap, iterable); Canvas canvas = new Canvas(a2); for (Element element : iterable) { Rect rectangle = element.getRectangle(); canvas.drawRect(rectangle, this.NJ.NM); a(canvas, element.getToken(), rectangle, this.NJ.NN); } return a2; } /* JADX INFO: Access modifiers changed from: package-private */ public Bitmap d(Bitmap bitmap, Iterable iterable) { Bitmap b2 = b(bitmap, iterable); Canvas canvas = new Canvas(b2); for (Field field : iterable) { Rect rectangle = field.getRectangle(); canvas.drawRect(rectangle, this.NJ.NM); a(canvas, field.getValue(), rectangle, this.NJ.NN); a(canvas, field); } return b2; } private Bitmap a(Bitmap bitmap, a aVar) { Bitmap j = j(bitmap); Canvas canvas = new Canvas(j); Iterator it = aVar.ov().iterator(); while (it.hasNext()) { canvas.drawRect(it.next(), this.NJ.NL); } return j; } private void a(Canvas canvas, Field field) { canvas.drawRect(field.getRectangle(), this.NJ.NL); Paint paint = this.NJ.NN; float textSize = paint.getTextSize(); try { paint.setTextSize(canvas.getWidth() / DisplayText.DISPLAY_TEXT_MAXIMUM_SIZE); canvas.drawText(field.getLabel(), r0.left, r0.top, paint); } finally { paint.setTextSize(textSize); } } private static void a(Canvas canvas, String str, Rect rect, Paint paint) { float textSize = paint.getTextSize(); float textScaleX = paint.getTextScaleX(); try { Path path = new Path(); RectF rectF = new RectF(); paint.setTextSize(rect.height()); a(paint, str, path, rectF); paint.setTextSize((paint.getTextSize() * rect.height()) / rectF.height()); a(paint, str, path, rectF); paint.setTextScaleX((paint.getTextScaleX() * rect.width()) / rectF.width()); a(paint, str, path, rectF); canvas.drawText(str, rect.left + (((rect.width() - rectF.width()) / 2.0f) - rectF.left), rect.bottom + (((-(rect.height() - rectF.height())) / 2.0f) - rectF.bottom), paint); } finally { paint.setTextSize(textSize); paint.setTextScaleX(textScaleX); } } private static void a(Paint paint, String str, Path path, RectF rectF) { paint.getTextPath(str, 0, str.length(), BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, path); path.computeBounds(rectF, true); } private static Bitmap j(Bitmap bitmap) { return bitmap.copy(bitmap.getConfig(), true); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public static class b { final Paint NL; final Paint NM; final Paint NN; private b() { Paint paint = new Paint(1); this.NL = paint; paint.setStyle(Paint.Style.STROKE); paint.setColor(-65536); Paint paint2 = new Paint(1); this.NM = paint2; paint2.setStyle(Paint.Style.FILL_AND_STROKE); paint2.setColor(-1); Paint paint3 = new Paint(1); this.NN = paint3; paint3.setStyle(Paint.Style.FILL_AND_STROKE); paint3.setLinearText(true); paint3.setSubpixelText(true); paint3.setColor(-65536); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes3.dex */ public static class a { final JSONObject NK; a(String str) { try { this.NK = new JSONObject(str).getJSONObject("Front Side"); } catch (JSONException e) { throw new RuntimeException(e); } } Iterable ot() { return a(this.NK.optJSONObject("Text Lines").optJSONArray("Lines")); } Iterable ou() { ArrayList arrayList = new ArrayList(); Iterator it = ot().iterator(); while (it.hasNext()) { Iterator it2 = b(it.next()).iterator(); while (it2.hasNext()) { arrayList.add(it2.next()); } } return arrayList; } Iterable ov() { ArrayList arrayList = new ArrayList(); Iterator it = ou().iterator(); while (it.hasNext()) { arrayList.add(c(it.next())); } return arrayList; } static Iterable a(JSONArray jSONArray) { ArrayList arrayList = new ArrayList(jSONArray.length()); for (int i = 0; i < jSONArray.length(); i++) { arrayList.add(jSONArray.optJSONObject(i)); } return arrayList; } static Iterable b(JSONObject jSONObject) { return a(jSONObject.optJSONArray("Words")); } static Rect c(JSONObject jSONObject) { return new Rect(jSONObject.optInt("TLx"), jSONObject.optInt("TLy"), jSONObject.optInt("BRx"), jSONObject.optInt("BRy")); } } }