From 1d59de6c12f1a75455a087d98fd4f7e4f256f706 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas <21@vingtetun.org> Date: Thu, 21 Jul 2011 11:01:38 +0200 Subject: [PATCH] Fix a > 32000 conversion error in type1 to type2 charstring --- fonts.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fonts.js b/fonts.js index 8770c8d06..5a64a645a 100755 --- a/fonts.js +++ b/fonts.js @@ -1786,8 +1786,10 @@ CFF.prototype = { String.fromCharCode((value >> 8) & 0xFF) + String.fromCharCode(value & 0xFF); } else if (value >= (-2147483648) && value <= 2147483647) { + value ^= 0xffffffff; + value += 1; return '\xff' + - String.fromCharCode((value >>> 24) & 0xFF) + + String.fromCharCode((value >> 24) & 0xFF) + String.fromCharCode((value >> 16) & 0xFF) + String.fromCharCode((value >> 8) & 0xFF) + String.fromCharCode(value & 0xFF); @@ -1893,7 +1895,14 @@ CFF.prototype = { charstring[i] = cmd; } } else { - charstring.splice(i, 1, 28, command >> 8, command & 0xff); + // Type1 charstring use a division for number above 32000 + if (command > 32000) { + var divisor = charstring[i + 1]; + command /= divisor; + charstring.splice(i, 3, 28, command >> 8, command & 0xff); + } else { + charstring.splice(i, 1, 28, command >> 8, command & 0xff); + } i += 2; } }