From 95ca8ede85f2d08f6d67cc93394d436ad75e8076 Mon Sep 17 00:00:00 2001
From: Vivien Nicolas <21@vingtetun.org>
Date: Sun, 11 Sep 2011 17:38:02 +0200
Subject: [PATCH] Add support for Type1C advanced charsets
---
charsets.js | 101 ++++++++++++++++++++++++++++++++++++++++++++++++
fonts.js | 35 ++++++++++-------
web/viewer.html | 1 +
3 files changed, 122 insertions(+), 15 deletions(-)
create mode 100644 charsets.js
diff --git a/charsets.js b/charsets.js
new file mode 100644
index 000000000..4066976c9
--- /dev/null
+++ b/charsets.js
@@ -0,0 +1,101 @@
+
+var ISOAdobeCharset = [
+ ".notdef", "space", "exclam", "quotedbl", "numbersign", "dollar",
+ "percent", "ampersand", "quoteright", "parenleft", "parenright",
+ "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero",
+ "one", "two", "three", "four", "five", "six", "seven", "eight",
+ "nine", "colon", "semicolon", "less", "equal", "greater", "question",
+ "at", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
+ "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
+ "bracketleft", "backslash", "bracketright", "asciicircum", "underscore",
+ "quoteleft", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l",
+ "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
+ "braceleft", "bar", "braceright", "asciitilde", "exclamdown", "cent",
+ "sterling", "fraction", "yen", "florin", "section", "currency",
+ "quotesingle", "quotedblleft", "guillemotleft", "guilsinglleft",
+ "guilsinglright", "fi", "fl", "endash", "dagger", "daggerdbl",
+ "periodcentered", "paragraph", "bullet", "quotesinglbase",
+ "quotedblbase", "quotedblright", "guillemotright", "ellipsis",
+ "perthousand", "questiondown", "grave", "acute", "circumflex", "tilde",
+ "macron", "breve", "dotaccent", "dieresis", "ring", "cedilla",
+ "hungarumlaut", "ogonek", "caron", "emdash", "AE", "ordfeminine",
+ "Lslash", "Oslash", "OE", "ordmasculine", "ae", "dotlessi", "lslash",
+ "oslash", "oe", "germandbls", "onesuperior", "logicalnot", "mu",
+ "trademark", "Eth", "onehalf", "plusminus", "Thorn", "onequarter",
+ "divide", "brokenbar", "degree", "thorn", "threequarters", "twosuperior",
+ "registered", "minus", "eth", "multiply", "threesuperior", "copyright",
+ "Aacute", "Acircumflex", "Adieresis", "Agrave", "Aring", "Atilde",
+ "Ccedilla", "Eacute", "Ecircumflex", "Edieresis", "Egrave", "Iacute",
+ "Icircumflex", "Idieresis", "Igrave", "Ntilde", "Oacute", "Ocircumflex",
+ "Odieresis", "Ograve", "Otilde", "Scaron", "Uacute", "Ucircumflex",
+ "Udieresis", "Ugrave", "Yacute", "Ydieresis", "Zcaron", "aacute",
+ "acircumflex", "adieresis", "agrave", "aring", "atilde", "ccedilla",
+ "eacute", "ecircumflex", "edieresis", "egrave", "iacute", "icircumflex",
+ "idieresis", "igrave", "ntilde", "oacute", "ocircumflex", "odieresis",
+ "ograve", "otilde", "scaron", "uacute", "ucircumflex", "udieresis",
+ "ugrave", "yacute", "ydieresis", "zcaron"
+];
+
+var ExpertCharset = [
+ ".notdef", "space", "exclamsmall", "Hungarumlautsmall", "dollaroldstyle",
+ "dollarsuperior", "ampersandsmall", "Acutesmall", "parenleftsuperior",
+ "parenrightsuperior", "twodotenleader", "onedotenleader", "comma",
+ "hyphen", "period", "fraction", "zerooldstyle", "oneoldstyle",
+ "twooldstyle", "threeoldstyle", "fouroldstyle", "fiveoldstyle",
+ "sixoldstyle", "sevenoldstyle", "eightoldstyle", "nineoldstyle",
+ "colon", "semicolon", "commasuperior", "threequartersemdash",
+ "periodsuperior", "questionsmall", "asuperior", "bsuperior",
+ "centsuperior", "dsuperior", "esuperior", "isuperior", "lsuperior",
+ "msuperior", "nsuperior", "osuperior", "rsuperior", "ssuperior",
+ "tsuperior", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior",
+ "parenrightinferior", "Circumflexsmall", "hyphensuperior", "Gravesmall",
+ "Asmall", "Bsmall", "Csmall", "Dsmall", "Esmall", "Fsmall", "Gsmall",
+ "Hsmall", "Ismall", "Jsmall", "Ksmall", "Lsmall", "Msmall", "Nsmall",
+ "Osmall", "Psmall", "Qsmall", "Rsmall", "Ssmall", "Tsmall", "Usmall",
+ "Vsmall", "Wsmall", "Xsmall", "Ysmall", "Zsmall", "colonmonetary",
+ "onefitted", "rupiah", "Tildesmall", "exclamdownsmall", "centoldstyle",
+ "Lslashsmall", "Scaronsmall", "Zcaronsmall", "Dieresissmall",
+ "Brevesmall", "Caronsmall", "Dotaccentsmall", "Macronsmall",
+ "figuredash", "hypheninferior", "Ogoneksmall", "Ringsmall",
+ "Cedillasmall", "onequarter", "onehalf", "threequarters",
+ "questiondownsmall", "oneeighth", "threeeighths", "fiveeighths",
+ "seveneighths", "onethird", "twothirds", "zerosuperior", "onesuperior",
+ "twosuperior", "threesuperior", "foursuperior", "fivesuperior",
+ "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior",
+ "zeroinferior", "oneinferior", "twoinferior", "threeinferior",
+ "fourinferior", "fiveinferior", "sixinferior", "seveninferior",
+ "eightinferior", "nineinferior", "centinferior", "dollarinferior",
+ "periodinferior", "commainferior", "Agravesmall", "Aacutesmall",
+ "Acircumflexsmall", "Atildesmall", "Adieresissmall", "Aringsmall",
+ "AEsmall", "Ccedillasmall", "Egravesmall", "Eacutesmall",
+ "Ecircumflexsmall", "Edieresissmall", "Igravesmall", "Iacutesmall",
+ "Icircumflexsmall", "Idieresissmall", "Ethsmall", "Ntildesmall",
+ "Ogravesmall", "Oacutesmall", "Ocircumflexsmall", "Otildesmall",
+ "Odieresissmall", "OEsmall", "Oslashsmall", "Ugravesmall", "Uacutesmall",
+ "Ucircumflexsmall", "Udieresissmall", "Yacutesmall", "Thornsmall",
+ "Ydieresissmall"
+];
+
+var ExpertSubsetCharset = [
+ ".notdef", "space", "dollaroldstyle", "dollarsuperior",
+ "parenleftsuperior", "parenrightsuperior", "twodotenleader",
+ "onedotenleader", "comma", "hyphen", "period", "fraction",
+ "zerooldstyle", "oneoldstyle", "twooldstyle", "threeoldstyle",
+ "fouroldstyle", "fiveoldstyle", "sixoldstyle", "sevenoldstyle",
+ "eightoldstyle", "nineoldstyle", "colon", "semicolon", "commasuperior",
+ "threequartersemdash", "periodsuperior", "asuperior", "bsuperior",
+ "centsuperior", "dsuperior", "esuperior", "isuperior", "lsuperior",
+ "msuperior", "nsuperior", "osuperior", "rsuperior", "ssuperior",
+ "tsuperior", "ff", "fi", "fl", "ffi", "ffl", "parenleftinferior",
+ "parenrightinferior", "hyphensuperior", "colonmonetary", "onefitted",
+ "rupiah", "centoldstyle", "figuredash", "hypheninferior", "onequarter",
+ "onehalf", "threequarters", "oneeighth", "threeeighths", "fiveeighths",
+ "seveneighths", "onethird", "twothirds", "zerosuperior", "onesuperior",
+ "twosuperior", "threesuperior", "foursuperior", "fivesuperior",
+ "sixsuperior", "sevensuperior", "eightsuperior", "ninesuperior",
+ "zeroinferior", "oneinferior", "twoinferior", "threeinferior",
+ "fourinferior", "fiveinferior", "sixinferior", "seveninferior",
+ "eightinferior", "nineinferior", "centinferior", "dollarinferior",
+ "periodinferior", "commainferior"
+];
+
diff --git a/fonts.js b/fonts.js
index 8323f895d..6a361e60e 100755
--- a/fonts.js
+++ b/fonts.js
@@ -2429,37 +2429,42 @@ var Type2CFF = (function() {
},
parseCharsets: function cff_parsecharsets(pos, length, strings) {
+ if (pos == 0) {
+ return ISOAdobeCharset;
+ } else if (pos == 1) {
+ return CFFExpertCharset;
+ } else if (pos == 2) {
+ return CFFExpertSubsetCharset;
+ }
+
var bytes = this.bytes;
var format = bytes[pos++];
var charset = ['.notdef'];
+
// subtract 1 for the .notdef glyph
length -= 1;
switch (format) {
case 0:
- for (var i = 0; i < length; ++i) {
- var id = bytes[pos++];
- id = (id << 8) | bytes[pos++];
- charset.push(strings[id]);
+ for (var i = 0; i < length; i++) {
+ var sid = (bytes[pos++] << 8) | bytes[pos++];
+ charset.push(strings[sid]);
}
break;
case 1:
while (charset.length <= length) {
- var first = bytes[pos++];
- first = (first << 8) | bytes[pos++];
- var numLeft = bytes[pos++];
- for (var i = 0; i <= numLeft; ++i)
- charset.push(strings[first++]);
+ var sid = (bytes[pos++] << 8) | bytes[pos++];
+ var count = bytes[pos++];
+ for (var i = 0; i <= count; i++)
+ charset.push(strings[sid++]);
}
break;
case 2:
while (charset.length <= length) {
- var first = bytes[pos++];
- first = (first << 8) | bytes[pos++];
- var numLeft = bytes[pos++];
- numLeft = (numLeft << 8) | bytes[pos++];
- for (var i = 0; i <= numLeft; ++i)
- charset.push(strings[first++]);
+ var sid = (bytes[pos++] << 8) | bytes[pos++];
+ var count = (bytes[pos++] << 8) | bytes[pos++];
+ for (var i = 0; i <= count; i++)
+ charset.push(strings[sid++]);
}
break;
default:
diff --git a/web/viewer.html b/web/viewer.html
index a53593df3..00950a44c 100644
--- a/web/viewer.html
+++ b/web/viewer.html
@@ -11,6 +11,7 @@
+