Skip to content

Commit 6b709ef

Browse files
committed
Merge pull request mozilla#3199 from yurydelendik/cff-floats
Rounding floats in CFF
2 parents d1cea4a + 90f8f44 commit 6b709ef

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/fonts.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6897,6 +6897,14 @@ var CFFCompiler = (function CFFCompilerClosure() {
68976897
},
68986898
encodeFloat: function CFFCompiler_encodeFloat(num) {
68996899
var value = num.toString();
6900+
6901+
// rounding inaccurate doubles
6902+
var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
6903+
if (m) {
6904+
var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
6905+
value = (Math.round(num * epsilon) / epsilon).toString();
6906+
}
6907+
69006908
var nibbles = '';
69016909
for (var i = 0, ii = value.length; i < ii; ++i) {
69026910
var a = value[i];

0 commit comments

Comments
 (0)