Skip to content

Commit 022d2cc

Browse files
committed
os2: Fill Panose when writing font
[why] When an existing font file is read from a buffer and then written back into a buffer all Panose values will be zero. The problem has been most likly been introduced with PR opentypejs#630 (but I did not check that). There are two disjunct data structures in the font.tables.os2 object that describe the panose values: * An array with the Panose values `.panose = [ 1, 2, ...]` * Dedicated properties for each Panose value e.g. `.bFamilyType` The aforementioned PR seems to address only fonts created from scratch and not parsed from a buffer. Writing out the font into a buffer will always use the dedicated Panose properties and ignore the .panose array. Parsing a font does set the array but not the dedicated properties. They are not even existing then. [how] When an existing font is parsed the `.panose` array is filled (as before). But now the dedicated properties are also created and filled with the individual values. [note] The written font is always using the dedicated values. If a user changes the panose array that will have no effect. There are no checks if the data is consistent. Having the same data in two disjunct structures is not so nice to handle. Signed-off-by: Fini Jastrow <[email protected]>
1 parent aa8ad76 commit 022d2cc

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/tables/os2.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ function parseOS2Table(data, start) {
165165
for (let i = 0; i < 10; i++) {
166166
os2.panose[i] = p.parseByte();
167167
}
168+
os2.bFamilyType = os2.panose[0];
169+
os2.bSerifStyle = os2.panose[1];
170+
os2.bWeight = os2.panose[2];
171+
os2.bProportion = os2.panose[3];
172+
os2.bContrast = os2.panose[4];
173+
os2.bStrokeVariation = os2.panose[5];
174+
os2.bArmStyle = os2.panose[6];
175+
os2.bLetterform = os2.panose[7];
176+
os2.bMidline = os2.panose[8];
177+
os2.bXHeight = os2.panose[9];
168178

169179
os2.ulUnicodeRange1 = p.parseULong();
170180
os2.ulUnicodeRange2 = p.parseULong();

0 commit comments

Comments
 (0)