154 lines
5.6 KiB
Java
154 lines
5.6 KiB
Java
|
package com.google.android.gms.vision.text;
|
||
|
|
||
|
import android.graphics.Point;
|
||
|
import android.graphics.Rect;
|
||
|
import android.util.SparseArray;
|
||
|
import com.google.android.gms.internal.vision.zzae;
|
||
|
import com.google.android.gms.internal.vision.zzy;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Collections;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.List;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public class TextBlock implements Text {
|
||
|
private Point[] cornerPoints;
|
||
|
private zzae[] zzev;
|
||
|
private List<Line> zzew;
|
||
|
private String zzex;
|
||
|
private Rect zzey;
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public TextBlock(SparseArray<zzae> sparseArray) {
|
||
|
this.zzev = new zzae[sparseArray.size()];
|
||
|
int i = 0;
|
||
|
while (true) {
|
||
|
zzae[] zzaeVarArr = this.zzev;
|
||
|
if (i >= zzaeVarArr.length) {
|
||
|
return;
|
||
|
}
|
||
|
zzaeVarArr[i] = sparseArray.valueAt(i);
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public String getLanguage() {
|
||
|
String str = this.zzex;
|
||
|
if (str != null) {
|
||
|
return str;
|
||
|
}
|
||
|
HashMap hashMap = new HashMap();
|
||
|
for (zzae zzaeVar : this.zzev) {
|
||
|
hashMap.put(zzaeVar.zzex, Integer.valueOf((hashMap.containsKey(zzaeVar.zzex) ? ((Integer) hashMap.get(zzaeVar.zzex)).intValue() : 0) + 1));
|
||
|
}
|
||
|
String str2 = (String) ((Map.Entry) Collections.max(hashMap.entrySet(), new zza(this))).getKey();
|
||
|
this.zzex = str2;
|
||
|
if (str2 == null || str2.isEmpty()) {
|
||
|
this.zzex = "und";
|
||
|
}
|
||
|
return this.zzex;
|
||
|
}
|
||
|
|
||
|
@Override // com.google.android.gms.vision.text.Text
|
||
|
public String getValue() {
|
||
|
zzae[] zzaeVarArr = this.zzev;
|
||
|
if (zzaeVarArr.length == 0) {
|
||
|
return "";
|
||
|
}
|
||
|
StringBuilder sb = new StringBuilder(zzaeVarArr[0].zzfg);
|
||
|
for (int i = 1; i < this.zzev.length; i++) {
|
||
|
sb.append("\n");
|
||
|
sb.append(this.zzev[i].zzfg);
|
||
|
}
|
||
|
return sb.toString();
|
||
|
}
|
||
|
|
||
|
@Override // com.google.android.gms.vision.text.Text
|
||
|
public Point[] getCornerPoints() {
|
||
|
zzae[] zzaeVarArr;
|
||
|
TextBlock textBlock = this;
|
||
|
if (textBlock.cornerPoints == null) {
|
||
|
int i = 0;
|
||
|
if (textBlock.zzev.length == 0) {
|
||
|
textBlock.cornerPoints = new Point[0];
|
||
|
} else {
|
||
|
int i2 = Integer.MAX_VALUE;
|
||
|
int i3 = 0;
|
||
|
int i4 = Integer.MIN_VALUE;
|
||
|
int i5 = Integer.MIN_VALUE;
|
||
|
int i6 = Integer.MAX_VALUE;
|
||
|
while (true) {
|
||
|
zzaeVarArr = textBlock.zzev;
|
||
|
if (i3 >= zzaeVarArr.length) {
|
||
|
break;
|
||
|
}
|
||
|
zzy zzyVar = zzaeVarArr[i3].zzfd;
|
||
|
zzy zzyVar2 = textBlock.zzev[i].zzfd;
|
||
|
int i7 = -zzyVar2.left;
|
||
|
int i8 = -zzyVar2.top;
|
||
|
double sin = Math.sin(Math.toRadians(zzyVar2.zzfb));
|
||
|
double cos = Math.cos(Math.toRadians(zzyVar2.zzfb));
|
||
|
Point point = new Point(zzyVar.left, zzyVar.top);
|
||
|
point.offset(i7, i8);
|
||
|
int i9 = (int) ((r8[0].x * cos) + (r8[0].y * sin));
|
||
|
int i10 = (int) (((-r8[0].x) * sin) + (r8[0].y * cos));
|
||
|
r8[0].x = i9;
|
||
|
r8[0].y = i10;
|
||
|
Point[] pointArr = {point, new Point(zzyVar.width + i9, i10), new Point(zzyVar.width + i9, zzyVar.height + i10), new Point(i9, i10 + zzyVar.height)};
|
||
|
i2 = i2;
|
||
|
for (int i11 = 0; i11 < 4; i11++) {
|
||
|
Point point2 = pointArr[i11];
|
||
|
i2 = Math.min(i2, point2.x);
|
||
|
i4 = Math.max(i4, point2.x);
|
||
|
i6 = Math.min(i6, point2.y);
|
||
|
i5 = Math.max(i5, point2.y);
|
||
|
}
|
||
|
i3++;
|
||
|
i = 0;
|
||
|
textBlock = this;
|
||
|
}
|
||
|
int i12 = i2;
|
||
|
int i13 = i;
|
||
|
zzy zzyVar3 = zzaeVarArr[i13].zzfd;
|
||
|
int i14 = zzyVar3.left;
|
||
|
int i15 = zzyVar3.top;
|
||
|
double sin2 = Math.sin(Math.toRadians(zzyVar3.zzfb));
|
||
|
double cos2 = Math.cos(Math.toRadians(zzyVar3.zzfb));
|
||
|
Point[] pointArr2 = {new Point(i12, i6), new Point(i4, i6), new Point(i4, i5), new Point(i12, i5)};
|
||
|
while (i13 < 4) {
|
||
|
pointArr2[i13].x = (int) ((pointArr2[i13].x * cos2) - (pointArr2[i13].y * sin2));
|
||
|
pointArr2[i13].y = (int) ((pointArr2[i13].x * sin2) + (pointArr2[i13].y * cos2));
|
||
|
pointArr2[i13].offset(i14, i15);
|
||
|
i13++;
|
||
|
}
|
||
|
textBlock = this;
|
||
|
textBlock.cornerPoints = pointArr2;
|
||
|
}
|
||
|
}
|
||
|
return textBlock.cornerPoints;
|
||
|
}
|
||
|
|
||
|
@Override // com.google.android.gms.vision.text.Text
|
||
|
public List<? extends Text> getComponents() {
|
||
|
if (this.zzev.length == 0) {
|
||
|
return new ArrayList(0);
|
||
|
}
|
||
|
if (this.zzew == null) {
|
||
|
this.zzew = new ArrayList(this.zzev.length);
|
||
|
for (zzae zzaeVar : this.zzev) {
|
||
|
this.zzew.add(new Line(zzaeVar));
|
||
|
}
|
||
|
}
|
||
|
return this.zzew;
|
||
|
}
|
||
|
|
||
|
@Override // com.google.android.gms.vision.text.Text
|
||
|
public Rect getBoundingBox() {
|
||
|
if (this.zzey == null) {
|
||
|
this.zzey = zzc.zza(this);
|
||
|
}
|
||
|
return this.zzey;
|
||
|
}
|
||
|
}
|