From c67037e268bf5d70fd002891e4673cae43eb4d6e Mon Sep 17 00:00:00 2001 From: sbarman Date: Thu, 21 Jul 2011 11:51:39 -0700 Subject: [PATCH 01/10] added ability to write data to file --- fonts.js | 8 ++++++++ utils/fonts_utils.js | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fonts.js b/fonts.js index 77ad85a00..e4a426cbe 100755 --- a/fonts.js +++ b/fonts.js @@ -384,6 +384,14 @@ var Font = (function Font() { break; } + var fileArr = []; + file.reset(); + for (var i = 0, ii = file.length; i < ii; ++i) + fileArr.push(file[i]); + + writeToFile(data, '/tmp/' + name + '_orig'); + writeToFile(fileArr, '/tmp/' + name + '_new'); + this.data = data; this.textMatrix = properties.textMatrix || IDENTITY_MATRIX; this.type = properties.type; diff --git a/utils/fonts_utils.js b/utils/fonts_utils.js index edfc22186..98ea60757 100644 --- a/utils/fonts_utils.js +++ b/utils/fonts_utils.js @@ -1,8 +1,6 @@ /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- / /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ -'use strict'; - /** * The Type2 reader code below is only used for debugging purpose since Type2 * is only a CharString format and is never used directly as a Font file. @@ -391,7 +389,7 @@ function writeToFile(aBytes, aFilePath) { var stream = Cc['@mozilla.org/network/file-output-stream;1'] .createInstance(Ci.nsIFileOutputStream); - stream.init(file, 0x04 | 0x08 | 0x20, 0x180, 0); + stream.init(file, 0x04 | 0x08 | 0x20, 0666, 0); var bos = Cc['@mozilla.org/binaryoutputstream;1'] .createInstance(Ci.nsIBinaryOutputStream); From dbc6d67ea6fc8d37628d45f34bb67f79e3ecaba8 Mon Sep 17 00:00:00 2001 From: sbarman Date: Thu, 21 Jul 2011 15:13:18 -0700 Subject: [PATCH 02/10] added include to fonts_util.js --- web/viewer.html | 1 + 1 file changed, 1 insertion(+) diff --git a/web/viewer.html b/web/viewer.html index df9604db4..96012d6d8 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -10,6 +10,7 @@ + From 7d5470a7e551c2f6b8383362f73bdff22ddd7fca Mon Sep 17 00:00:00 2001 From: sbarman Date: Thu, 21 Jul 2011 15:13:49 -0700 Subject: [PATCH 03/10] added include to fonts_util.js --- web/viewer.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/viewer.html b/web/viewer.html index 96012d6d8..bf708c4ff 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -10,7 +10,7 @@ - + From c4d81646dc558f76e1cac3b06a351314c391cfb7 Mon Sep 17 00:00:00 2001 From: sbarman Date: Thu, 21 Jul 2011 15:18:00 -0700 Subject: [PATCH 04/10] fixed reading from sream --- fonts.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fonts.js b/fonts.js index e4a426cbe..3a52ae83a 100755 --- a/fonts.js +++ b/fonts.js @@ -386,11 +386,12 @@ var Font = (function Font() { var fileArr = []; file.reset(); + file = file.getBytes(); for (var i = 0, ii = file.length; i < ii; ++i) fileArr.push(file[i]); - writeToFile(data, '/tmp/' + name + '_orig'); - writeToFile(fileArr, '/tmp/' + name + '_new'); + writeToFile(data, '/tmp/' + name + '_new'); + writeToFile(fileArr, '/tmp/' + name + '_orig'); this.data = data; this.textMatrix = properties.textMatrix || IDENTITY_MATRIX; From 23d37f98dbdf99ed0a22ba1b7ad4d83ee023931e Mon Sep 17 00:00:00 2001 From: sbarman Date: Tue, 16 Aug 2011 10:25:02 -0700 Subject: [PATCH 05/10] working on subroutines --- fonts.js | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/fonts.js b/fonts.js index 66d8428e2..e38edef8d 100755 --- a/fonts.js +++ b/fonts.js @@ -1598,6 +1598,17 @@ var Type1Parser = function() { var c = ''; var count = eexecStr.length; for (var i = 0; i < count; i++) { + var getToken = function() { + while(i < count && (eexecStr[i] == ' ' || eexecStr[i] == '\n')) + ++i; + + var t = ''; + while(i < count && !(eexecStr[i] == ' ' || eexecStr[i] == '\n')) + t += eexecStr[i++]; + + return t; + } + var c = eexecStr[i]; if ((glyphsSection || subrsSection) && c == 'R') { @@ -1627,7 +1638,25 @@ var Type1Parser = function() { glyphsSection = true; break; case '/Subrs': - subrsSection = true; + ++i; + var num = parseInt(getToken()); + getToken(); // read in 'array' + for (var j = 0; j < num; ++j) { + var t = getToken(); // read in 'dup' + if (t == 'ND') + break; + var index = parseInt(getToken()); + if (index > j) + j = index; + var length = parseInt(getToken()); + getToken(); // read in 'RD' + var data = eexec.slice(i + 1, i + 1 + length); + var encoded = decrypt(data, kCharStringsEncryptionKey, 4); + var str = decodeCharString(encoded); + i = i + 1 + length; + getToken(); //read in 'NP' + program.subrs[index] = str.charstring; + } break; case '/BlueValues': case '/OtherBlues': @@ -1909,8 +1938,13 @@ CFF.prototype = { for (var i = 0; i < bias; i++) type2Subrs.push([0x0B]); - for (var i = 0; i < count; i++) - type2Subrs.push(this.flattenCharstring(type1Subrs[i], this.commandsMap)); + for (var i = 0; i < count; i++) { + var subr = type1Subrs[i]; + if (!subr) + subr = [0x0B]; + + type2Subrs.push(this.flattenCharstring(subr, this.commandsMap)); + } return type2Subrs; }, From c592d5ed3b8a95a4392996f1222943645553d7ae Mon Sep 17 00:00:00 2001 From: sbarman Date: Tue, 16 Aug 2011 14:49:12 -0700 Subject: [PATCH 06/10] still mucking with subroutines --- fonts.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fonts.js b/fonts.js index e38edef8d..356d7f948 100755 --- a/fonts.js +++ b/fonts.js @@ -1469,7 +1469,7 @@ var Type1Parser = function() { var value = ''; var count = array.length; for (var i = 0; i < count; i++) { - value = parseInt(array[i]); + value = array[i]; if (value < 32) { var command = null; @@ -1479,8 +1479,8 @@ var Type1Parser = function() { // TODO Clean this code if (escape == 16) { var index = charstring.pop(); - var argc = charstring.pop(); - var data = charstring.pop(); +// var argc = charstring.pop(); +// var data = charstring.pop(); // If the flex mechanishm is not used in a font program, Adobe // state that that entries 0, 1 and 2 can simply be replace by @@ -1492,8 +1492,8 @@ var Type1Parser = function() { // This is the same things about hint replacement, if it is not used // entry 3 can be replaced by {3} if (index == 3) { - charstring.push(3); - i++; +// charstring.push(3); +// i++; continue; } } @@ -1532,11 +1532,11 @@ var Type1Parser = function() { value = command; } else if (value <= 246) { - value = parseInt(value) - 139; + value = value - 139; } else if (value <= 250) { - value = ((value - 247) * 256) + parseInt(array[++i]) + 108; + value = ((value - 247) * 256) + array[++i] + 108; } else if (value <= 254) { - value = -((value - 251) * 256) - parseInt(array[++i]) - 108; + value = -((value - 251) * 256) - array[++i] - 108; } else { value = (array[++i] & 0xff) << 24 | (array[++i] & 0xff) << 16 | (array[++i] & 0xff) << 8 | (array[++i] & 0xff) << 0; From 9f615036d9ff1709e348764bc799a2b8b33fb682 Mon Sep 17 00:00:00 2001 From: sbarman Date: Tue, 16 Aug 2011 16:14:29 -0700 Subject: [PATCH 07/10] Still testing type1 charstring conversion --- fonts.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fonts.js b/fonts.js index e2f278523..77183a602 100755 --- a/fonts.js +++ b/fonts.js @@ -1488,8 +1488,9 @@ var Type1Parser = function() { // TODO Clean this code if (escape == 16) { var index = charstring.pop(); -// var argc = charstring.pop(); -// var data = charstring.pop(); + var argc = charstring.pop(); + for (var j = 0; j < argc; j++) + var data = charstring.pop(); // If the flex mechanishm is not used in a font program, Adobe // state that that entries 0, 1 and 2 can simply be replace by @@ -1501,8 +1502,8 @@ var Type1Parser = function() { // This is the same things about hint replacement, if it is not used // entry 3 can be replaced by {3} if (index == 3) { -// charstring.push(3); -// i++; + charstring.push(3); + i++; continue; } } From bd567fc322b60096659035dcd8c00c852249447a Mon Sep 17 00:00:00 2001 From: sbarman Date: Wed, 17 Aug 2011 15:55:09 -0700 Subject: [PATCH 08/10] working font --- fonts.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fonts.js b/fonts.js index 77183a602..a55fc63a2 100755 --- a/fonts.js +++ b/fonts.js @@ -1490,7 +1490,7 @@ var Type1Parser = function() { var index = charstring.pop(); var argc = charstring.pop(); for (var j = 0; j < argc; j++) - var data = charstring.pop(); + charstring.push('drop'); // If the flex mechanishm is not used in a font program, Adobe // state that that entries 0, 1 and 2 can simply be replace by @@ -1976,6 +1976,8 @@ CFF.prototype = { 'sub': [12, 11], 'div': [12, 12], 'pop': [1, 12, 18], +// 'pop': [], + 'drop' : [12, 18], 'endchar': 14, 'rmoveto': 21, 'hmoveto': 22, From 8ff8a92244350d6fac72954957fcaa1426cb29c6 Mon Sep 17 00:00:00 2001 From: sbarman Date: Wed, 17 Aug 2011 16:00:54 -0700 Subject: [PATCH 09/10] Revert "Merge branch 'writeToFile' into hmm" This reverts commit 9b91fca34702e37b7f6d7eb958e8d70f51b2602d, reversing changes made to c592d5ed3b8a95a4392996f1222943645553d7ae. --- fonts.js | 9 --------- utils/fonts_utils.js | 4 +++- web/viewer.html | 1 - 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/fonts.js b/fonts.js index a55fc63a2..a4976b0ac 100755 --- a/fonts.js +++ b/fonts.js @@ -446,15 +446,6 @@ var Font = (function Font() { break; } - var fileArr = []; - file.reset(); - file = file.getBytes(); - for (var i = 0, ii = file.length; i < ii; ++i) - fileArr.push(file[i]); - - writeToFile(data, '/tmp/' + name + '_new'); - writeToFile(fileArr, '/tmp/' + name + '_orig'); - this.data = data; this.type = properties.type; this.textMatrix = properties.textMatrix; diff --git a/utils/fonts_utils.js b/utils/fonts_utils.js index 98ea60757..edfc22186 100644 --- a/utils/fonts_utils.js +++ b/utils/fonts_utils.js @@ -1,6 +1,8 @@ /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- / /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ +'use strict'; + /** * The Type2 reader code below is only used for debugging purpose since Type2 * is only a CharString format and is never used directly as a Font file. @@ -389,7 +391,7 @@ function writeToFile(aBytes, aFilePath) { var stream = Cc['@mozilla.org/network/file-output-stream;1'] .createInstance(Ci.nsIFileOutputStream); - stream.init(file, 0x04 | 0x08 | 0x20, 0666, 0); + stream.init(file, 0x04 | 0x08 | 0x20, 0x180, 0); var bos = Cc['@mozilla.org/binaryoutputstream;1'] .createInstance(Ci.nsIBinaryOutputStream); diff --git a/web/viewer.html b/web/viewer.html index 5498d8a1c..285dadb01 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -10,7 +10,6 @@ - From a24ec410ee7ee81ba74eb7700395a5420a1dd28a Mon Sep 17 00:00:00 2001 From: sbarman Date: Wed, 17 Aug 2011 16:04:14 -0700 Subject: [PATCH 10/10] cleanup --- fonts.js | 1 - 1 file changed, 1 deletion(-) diff --git a/fonts.js b/fonts.js index a4976b0ac..1860df2e5 100755 --- a/fonts.js +++ b/fonts.js @@ -1967,7 +1967,6 @@ CFF.prototype = { 'sub': [12, 11], 'div': [12, 12], 'pop': [1, 12, 18], -// 'pop': [], 'drop' : [12, 18], 'endchar': 14, 'rmoveto': 21,