Skip to content

Commit 7112aa0

Browse files
committed
[lib] Exception handling in typeface variation instance
1 parent 3bdad5c commit 7112aa0

File tree

1 file changed

+9
-2
lines changed
  • tehreer-android/src/main/java/com/mta/tehreer/graphics

1 file changed

+9
-2
lines changed

tehreer-android/src/main/java/com/mta/tehreer/graphics/Typeface.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.Collections;
4040
import java.util.List;
4141

42+
import static com.mta.tehreer.internal.util.Preconditions.checkArgument;
4243
import static com.mta.tehreer.internal.util.Preconditions.checkNotNull;
4344

4445
/**
@@ -222,8 +223,14 @@ private void setupNames() {
222223
}
223224
}
224225

225-
public Typeface getVariationInstance(float[] coordinates) {
226-
return new Typeface(nDeriveVariation(nativeTypeface, coordinates));
226+
public @NonNull Typeface getVariationInstance(@NonNull float[] coordinates) {
227+
if (variationAxes == null) {
228+
throw new IllegalStateException("This typeface does not support variations.");
229+
}
230+
checkNotNull(coordinates, "coordinates");
231+
checkArgument(coordinates.length == variationAxes.size(), "The number of coordinates does not match with variation axes.");
232+
233+
return new Typeface(nGetVariationInstance(nativeTypeface, coordinates));
227234
}
228235

229236
public @Nullable List<VariationAxis> getVariationAxes() {

0 commit comments

Comments
 (0)