[
https://issues.apache.org/jira/browse/PDFBOX-6335?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tilman Hausherr updated PDFBOX-6335:
------------------------------------
Affects Version/s: 2.0.37
> TTFSubsetter writes a 78-byte OS/2 table that keeps the original version
> number
> -------------------------------------------------------------------------------
>
> Key: PDFBOX-6335
> URL: https://issues.apache.org/jira/browse/PDFBOX-6335
> Project: PDFBox
> Issue Type: Bug
> Components: FontBox
> Affects Versions: 2.0.37, 3.0.8 PDFBox, 4.0.0
> Reporter: Martin Mirchev
> Priority: Major
>
> {{TTFSubsetter.buildOS2Table()}} writes only the fields of an OS/2 version 0
> table (78 bytes), but writes the source font's version number in the first
> field. For the usual version 3 or 4 fonts the subset therefore declares a
> version whose table is 96 bytes long. fontTools can't read such a table
> ({{struct.error: unpack requires a buffer of 18 bytes}}), and other strict
> font loaders may reject it too.
> This doesn't affect fonts embedded by PDFBox itself ({{TrueTypeEmbedder}}
> doesn't keep the OS/2 table), only direct users of {{TTFSubsetter}}. To
> reproduce: subset {{LiberationSans-Regular.ttf}} (OS/2 version 3) or
> {{JosefinSans-Italic.ttf}} (version 4) from the fontbox test resources with
> {{new TTFSubsetter(ttf)}}, {{add('H')}} … {{writeToStream()}}, then load the
> result with fontTools ({{TTFont(path)['OS/2']}}).
> A possible change is to declare version 0, which matches the fields written.
> With it, both subsets load in fontTools (OS/2 version 0, with fsSelection,
> usWinAscent etc. kept):
> {code}
> --- a/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java
> +++ b/fontbox/src/main/java/org/apache/fontbox/ttf/TTFSubsetter.java
> @@ -431,7 +431,8 @@
> ByteArrayOutputStream bos = new ByteArrayOutputStream(78);
> DataOutputStream out = new DataOutputStream(bos);
>
> - writeUint16(out, os2.getVersion());
> + // only the version 0 fields are written below
> + writeUint16(out, 0);
> writeSInt16(out, os2.getAverageCharWidth());
> writeUint16(out, os2.getWeightClass());
> writeUint16(out, os2.getWidthClass());
> {code}
> The module unit tests pass with the change (io, fontbox, xmpbox, pdfbox;
> trunk fff879b).
> This issue was found by an LLM-assisted tool and verified manually.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]