Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add woffToOTF #691

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Add woffToOTF #691

wants to merge 9 commits into from

Conversation

graphicore
Copy link
Contributor

@graphicore graphicore commented Mar 26, 2024

Add woffToOTF conversion function that doesn't parse table contents.

Motivation and Context

In a project I need to uncompress woff files to otf/ttf in order to use them with harfbuzzjs which doesn't support woff.
I'm already using opentype.js, however, Font.toArrayBuffer relies on parsing the table contents, which results in incomplete translations when opentype.js doesn't support a table.

I looked at the python lib hanikesn/woff2otf and the node port mondeja/woff2otf and decided that opentype.js has already all the essential tooling required to do the same, so for me this is much better than adding a new dependency.

I added to src/opentype.js

/**
 * Convert/Uncompress a buffer of a woff font to otf/ttf without parsing
 * table contents.
 * @param  {ArrayBuffer}
 * @return {ArrayBuffer}
 */
function woffToOTF(buffer) {

I added checksum to the result of parseWOFFTableEntries.

I also repaired(?*) the ./bin/ot command and added the sub-command $./bin/ot woff_2_otf font-in.woff fount-out.ttf
(?*) imports weren't working for me calling ./bin/ot with an error(below), so i switched to require which is also used by ./bin/test-render:

SyntaxError: Cannot use import statement outside a module

How Has This Been Tested?

It works well in my local project with harfbuzzjs and opentypejs, i.e. both libraries can open and parse the result buffer.

$./bin/ot woff-2-otf produces the same output as hanikesn/woff2otf

$ ./woff2otf/woff2otf.py RobotoFlex.woff RobotoFlex-python.tff
$ ./opentype.js/bin/ot woff_2_otf RobotoFlex.woff RobotoFlex-opentypejs.ttf
$ sha1sum -b RobotoFlex-python.tff RobotoFlex-opentypejs.ttf 
92eea1fb16b2e15c3fd01219ec15451a644fc89d *RobotoFlex-python.tff
92eea1fb16b2e15c3fd01219ec15451a644fc89d *RobotoFlex-opentypejs.ttf

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x ] I did npm run test and all tests passed green (including code styling checks).
  • I have added tests to cover my changes.
  • My change requires a change to the documentation.
  • I have updated the README accordingly.
  • [x ] I have read the CONTRIBUTING document.

@graphicore graphicore changed the title Add woff_to_otf Add woffToOTF Mar 26, 2024
@graphicore
Copy link
Contributor Author

I just updated this to merge again with master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants