Skip to content

Commit bb4ad6b

Browse files
committed
[lib] Added convenience constructor in post table
1 parent a89c415 commit bb4ad6b

File tree

1 file changed

+28
-0
lines changed
  • tehreer-android/src/main/java/com/mta/tehreer/sfnt/tables

1 file changed

+28
-0
lines changed

tehreer-android/src/main/java/com/mta/tehreer/sfnt/tables/PostTable.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
package com.mta.tehreer.sfnt.tables;
1818

1919
import androidx.annotation.NonNull;
20+
import androidx.annotation.Nullable;
2021

2122
import com.mta.tehreer.graphics.Typeface;
2223
import com.mta.tehreer.internal.sfnt.SfntTable;
2324
import com.mta.tehreer.internal.sfnt.StructTable;
2425

26+
import static com.mta.tehreer.internal.util.Preconditions.checkNotNull;
27+
2528
/**
2629
* Represents an OpenType `post' table.
2730
*/
@@ -39,6 +42,26 @@ public final class PostTable {
3942
private final @NonNull Typeface typeface;
4043
private final @NonNull SfntTable table;
4144

45+
/**
46+
* Constructs a <code>PostTable</code> object from the specified typeface.
47+
*
48+
* @param typeface The typeface from which the <code>PostTable</code> object is constructed.
49+
* @return A new <code>PostTable</code> object, or <code>null</code> if `post' table does not
50+
* exist in the specified typeface.
51+
*
52+
* @throws NullPointerException if <code>typeface</code> is <code>null</code>.
53+
*/
54+
public static @Nullable PostTable from(@NonNull Typeface typeface) {
55+
checkNotNull(typeface);
56+
57+
long pointer = SfntTables.getTablePointer(typeface, SfntTables.TABLE_POST);
58+
if (pointer != 0) {
59+
return new PostTable(typeface, new StructTable(typeface, pointer));
60+
}
61+
62+
return null;
63+
}
64+
4265
/**
4366
* Constructs a <code>PostTable</code> object from the specified typeface.
4467
*
@@ -61,6 +84,11 @@ public PostTable(@NonNull Typeface typeface) {
6184
this.table = new StructTable(typeface, pointer);
6285
}
6386

87+
private PostTable(@NonNull Typeface typeface, @NonNull SfntTable table) {
88+
this.typeface = typeface;
89+
this.table = table;
90+
}
91+
6492
public int version() {
6593
return table.readInt32(VERSION);
6694
}

0 commit comments

Comments
 (0)