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 `OS/2' table.
2730 */
@@ -87,6 +90,26 @@ protected long pointerOf(int offset) {
8790
8891 private final @ NonNull SfntTable table ;
8992
93+ /**
94+ * Constructs an <code>OS2Table</code> object from the specified typeface.
95+ *
96+ * @param typeface The typeface from which the <code>OS2Table</code> object is constructed.
97+ * @return A new <code>OS2Table</code> object, or <code>null</code> if `OS/2' table does not
98+ * exist in the specified typeface.
99+ *
100+ * @throws NullPointerException if <code>typeface</code> is <code>null</code>.
101+ */
102+ public static @ Nullable OS2Table from (@ NonNull Typeface typeface ) {
103+ checkNotNull (typeface );
104+
105+ long pointer = SfntTables .getTablePointer (typeface , SfntTables .TABLE_OS_2 );
106+ if (pointer != 0 ) {
107+ return new OS2Table (new OS2StructTable (typeface , pointer ));
108+ }
109+
110+ return null ;
111+ }
112+
90113 /**
91114 * Constructs an <code>OS2Table</code> object from the specified typeface.
92115 *
@@ -108,6 +131,10 @@ public OS2Table(@NonNull Typeface typeface) {
108131 this .table = new OS2StructTable (typeface , pointer );
109132 }
110133
134+ private OS2Table (@ NonNull SfntTable table ) {
135+ this .table = table ;
136+ }
137+
111138 public int version () {
112139 return table .readUInt16 (VERSION );
113140 }
0 commit comments