Skip to content

Parsing font with potentially faulty GDEF table #789

@JonasGruenwald

Description

@JonasGruenwald

Hello, big fan of the package here!

I've got an issue that's maybe more of a question, not a bug in the package itself:

I'm trying to parse a font file and opentype.js is throwing this error:

'Unsupported GDEF table version.');

Now if I add the parsed tableVersion to the logged error message there, it's showing a value of 0.
It seems that something in the font file is incorrect, as that appears to not be a valid version for the GDEF table according to the spec I could find.

Now my thing is, I'd still like to parse that font file even though it has this inconsistency. I've added a local patch to my project as a workaround:

--- a/dist/opentype.js
+++ b/dist/opentype.js
@@ -13820,8 +13820,10 @@
 	    start = start || 0;
 	    var p = new Parser(data, start);
 	    var tableVersion = p.parseVersion(1);
-	    check.argument(tableVersion === 1 || tableVersion === 1.2 || tableVersion === 1.3,
-	        'Unsupported GDEF table version.');
+	    if(!(tableVersion === 1 || tableVersion === 1.2 || tableVersion === 1.3)){
+        console.warn(`Unsupported GDEF table version: ${tableVersion}, not parsing table!`);
+        return undefined;
+      }
 	    var gdef = {
 	        version: tableVersion,
 	        classDef: p.parsePointer(Parser.classDef),

Also worth noting that any other software seems to be able to open the font file just fine, and FontForge for example does not report any issues when loading the font.

My questions are:

Would some form of fault tolerant parsing be in scope for opentype.js?
Would contributions along those lines be welcome?
Or does the project generally only aim to be able to parse files that 100% adhere to the spec?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions