Skip to content

Conversation

@Pomax
Copy link
Contributor

@Pomax Pomax commented Oct 10, 2018

The spec for the searchRange and entrySelector specifies the following constraints:

searchRange: (Maximum power of 2 <= numTables) x 16
entrySelector: Log2(maximum power of 2 <= numTables)
rangeShift: NumTables x 16-searchRange

But the code was computing searchRange as just the power index, not the actual power of two that it should be.

Fixes #149
Fixes #179

The spec for the searchRange and entrySelector specified the following:

>uint16	searchRange	(Maximum power of 2 <= numTables) x 16.
>uint16	entrySelector	Log2(maximum power of 2 <= numTables).
>uint16	rangeShift	NumTables x 16-searchRange.
this.entrySelector = Math.floor(this.searchRange / Math.LN2);
let maxPowerOf2 = 2 ** Math.floor((Math.log(this.numTables) / Math.LN2));
this.searchRange = maxPowerOf2 * 16;
this.entrySelector = Math.log(maxPowerOf2) / Math.LN2;
Copy link
Contributor Author

@Pomax Pomax Oct 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L47 guarantees that L49 is always* integer

*) up to the font-impossible value of Math.log(2**750), at least.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you may need to add a Babel plugin for the exponentiation operator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll rewrite it to Math.pow form - eventually IE will be dead and all those can be cleaned up, until then it's not really worth asking babel to do the conversion for.

@Pomax
Copy link
Contributor Author

Pomax commented Oct 25, 2018

@devongovett ?

@Pomax
Copy link
Contributor Author

Pomax commented Nov 3, 2018

Bump, again, because it's getting new issues filed over it. Can this be landed @devongovett?

@Pomax
Copy link
Contributor Author

Pomax commented Nov 5, 2018

@devongovett switched ** to Math.pow and added a test to the PR to catch any future regression.

@devongovett devongovett merged commit 29751ed into foliojs:master Nov 6, 2018
@devongovett
Copy link
Member

Thanks @Pomax!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants