From 90f8f4484ca327f4ffad0205997f05f82c1e2e21 Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Fri, 3 May 2013 15:13:22 -0500 Subject: [PATCH] Rounding floats in CFF --- src/fonts.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fonts.js b/src/fonts.js index 02c28a3c2..6bad6b637 100644 --- a/src/fonts.js +++ b/src/fonts.js @@ -6897,6 +6897,14 @@ var CFFCompiler = (function CFFCompilerClosure() { }, encodeFloat: function CFFCompiler_encodeFloat(num) { var value = num.toString(); + + // rounding inaccurate doubles + var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value); + if (m) { + var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length)); + value = (Math.round(num * epsilon) / epsilon).toString(); + } + var nibbles = ''; for (var i = 0, ii = value.length; i < ii; ++i) { var a = value[i];