InsetCropParser.java
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.scene7.is.util.RectInt
* org.jetbrains.annotations.NotNull
*/
package com.adobe.cq.dam.dm.process.workflow;
import com.adobe.cq.dam.dm.process.workflow.InvalidInsetCrop;
import com.scene7.is.util.RectInt;
import org.jetbrains.annotations.NotNull;
class InsetCropParser {
InsetCropParser() {
}
@NotNull
public static RectInt parseInsetCrop(@NotNull String value, @NotNull RectInt rect) throws InvalidInsetCrop {
try {
if (value.isEmpty()) {
return rect;
}
String[] s = value.split(",");
if (s.length != 4) {
throw new InvalidInsetCrop(value);
}
int[] inset = new int[4];
for (int i = 0; i != 4; ++i) {
inset[i] = Integer.parseInt(s[i]);
if (inset[i] >= 0) continue;
throw new InvalidInsetCrop(value);
}
int left = rect.x + inset[0];
int top = rect.y + inset[1];
int right = rect.x + rect.width - inset[2];
int bottom = rect.y + rect.height - inset[3];
if (left < right && top < bottom) {
return RectInt.rectInt((int)left, (int)top, (int)(right - left), (int)(bottom - top));
}
return RectInt.rectInt();
}
catch (NumberFormatException e) {
throw new InvalidInsetCrop(value, e);
}
}
}