opentypejs / opentype.js

Read and write OpenType fonts using JavaScript.
https://opentype.js.org/
MIT License
4.37k stars 467 forks source link

Font validate is incomplete #607

Closed danielronnkvist closed 3 months ago

danielronnkvist commented 11 months ago

Expected Behavior

Font.validate should return a boolean or the list of warnings that have been generated.

Current Behavior

Font.validate doesn't do anything.

Possible Solution

After asserting return the warnings array.

Context

I'm referencing this method.

Connum commented 11 months ago

Good catch, would you lake to contribute a PR for this fix, along with some tests to catch this behaviour?

danielronnkvist commented 10 months ago

@Connum are all the assertions a true test for a valid font? For example running the validate function on the Roboto-Black font in the test folder returns these warnings. I would guess that most are just warnings and shouldn't invalidate the font.

[
  'No English weightName specified.',
  'No English manufacturer specified.'
]

Running fontlint for the same font output this information:

Copyright (c) 2000-2023. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Version: 20230101
 Based on sources from 2023-01-01 05:27 UTC-D.
Internal Error: Attempt to unget two characters
CHECKING     test/fonts/Roboto-Black.ttf
The following table(s) in the font have been ignored by FontForge
  Ignoring 'hdmx' horizontal device metrics table
ERROR      2 Self-intersecting glyph
ERROR      5 Missing points at extrema
FAIL         test/fonts/Roboto-Black.ttf
Connum commented 8 months ago

Good question. I think a font should always at least have all its meta data provided in English, but of course it also works without it. Maybe we need to be able to provide the severieties that we want to get back from that function? But that would require that we categorize errors/warnings by severity in the first place.

I would like to get the rest of @opentypejs/owners on board for this.

Connum commented 7 months ago

I'm currently working on restructuring the error handling. See also #337 and #643. You can check out the work-in-progress branch here, where Font.validate() will return an array of validation messages:

https://github.com/Connum/opentype.js/tree/WIP/validation-error-handling

image