1717package com .mta .tehreer .sfnt .tables ;
1818
1919import androidx .annotation .NonNull ;
20+ import androidx .annotation .Nullable ;
2021
2122import com .mta .tehreer .graphics .Typeface ;
2223import com .mta .tehreer .internal .sfnt .SfntTable ;
2324import 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