Initial CID0 font encodings

This commit is contained in:
notmasteryet 2011-09-28 19:54:40 -05:00
parent 575e0b9f89
commit 66cd79f308
7 changed files with 7037 additions and 60 deletions

6932
cidmaps.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -443,6 +443,7 @@ var Font = (function Font() {
this.defaultWidth = properties.defaultWidth;
this.loadedName = fontName.split('-')[0];
this.composite = properties.composite;
this.loading = false;
return;
}

71
pdf.js
View File

@ -4437,7 +4437,6 @@ var PartialEvaluator = (function partialEvaluator() {
properties) {
var type = properties.type, encoding;
if (properties.composite) {
if (type == 'CIDFontType2') {
var defaultWidth = xref.fetchIfRef(dict.get('DW')) || 1000;
properties.defaultWidth = defaultWidth;
@ -4463,8 +4462,60 @@ var PartialEvaluator = (function partialEvaluator() {
}
properties.widths = glyphsWidths;
// Glyph ids are big-endian 2-byte values
encoding = properties.encoding;
var cidToGidMap = dict.get('CIDToGIDMap');
if (!cidToGidMap || !IsRef(cidToGidMap)) {
// trying to guess encoding from CIDSystemInfo
var cidSystemInfo = dict.get('CIDSystemInfo');
var cidToUnicode;
if (IsDict(cidSystemInfo)) {
cidToUnicode = CIDToUnicodeMaps[
cidSystemInfo.get('Registry') + '-' +
cidSystemInfo.get('Ordering')];
}
if (cidToUnicode) {
encoding[0] = { unicode: 0, width: 0 };
var glyph = 1, i, j;
for (i = 0; i < cidToUnicode.length; ++i) {
var unicode = cidToUnicode[i];
if (IsArray(unicode)) {
var length = unicode.length;
if (glyph in glyphsWidths) {
for (j = 0; j < length; j++) {
encoding[unicode[j]] = {
unicode: unicode[j],
width: glyphsWidths[glyph]
};
}
}
glyph++;
} else if (typeof unicode === 'object') {
var fillLength = unicode.f;
if (fillLength) {
unicode = unicode.c;
for (j = 0; j < fillLength; ++j) {
if (!(glyph in glyphsWidths))
continue;
encoding[unicode] = {
unicode: unicode,
width: glyphsWidths[glyph]
};
unicode++;
glyph++;
}
} else
glyph += unicode.s;
} else if (unicode) {
encoding[unicode] = {
unicode: unicode,
width: glyphsWidths[glyph++]
};
}
}
}
return Object.create(GlyphsUnicode);
}
@ -4472,9 +4523,6 @@ var PartialEvaluator = (function partialEvaluator() {
var glyphsStream = xref.fetchIfRef(cidToGidMap);
var glyphsData = glyphsStream.getBytes(0);
// Glyph ids are big-endian 2-byte values
encoding = properties.encoding;
// Set encoding 0 to later verify the font has an encoding
encoding[0] = { unicode: 0, width: 0 };
for (var j = 0; j < glyphsData.length; j++) {
@ -4489,20 +4537,7 @@ var PartialEvaluator = (function partialEvaluator() {
width: IsNum(width) ? width : defaultWidth
};
}
} else if (type == 'CIDFontType0') {
if (IsName(encoding)) {
// Encoding is a predefined CMap
if (encoding.name == 'Identity-H') {
TODO('Need to create an identity cmap');
} else {
TODO('Need to support predefined CMaps see PDF 32000-1:2008 ' +
'9.7.5.2 Predefined CMaps');
}
} else {
TODO('Need to support encoding streams see PDF 32000-1:2008 ' +
'9.7.5.3');
}
}
return Object.create(GlyphsUnicode);
}

View File

@ -0,0 +1 @@
http://www.tcpdf.org/examples/example_033.pdf

View File

@ -164,5 +164,11 @@
"rounds": 1,
"skipPages": [ 16 ],
"type": "load"
},
{ "id": "tcpdf_033",
"file": "pdfs/tcpdf_033.pdf",
"link": true,
"rounds": 1,
"type": "eq"
}
]

View File

@ -8,6 +8,7 @@
<script type="text/javascript" src="/glyphlist.js"></script>
<script type="text/javascript" src="/metrics.js"></script>
<script type="text/javascript" src="/charsets.js"></script>
<script type="text/javascript" src="/cidmaps.js"></script>
<script type="text/javascript" src="driver.js"></script>
</head>

View File

@ -12,6 +12,7 @@
<script type="text/javascript" src="../glyphlist.js"></script>
<script type="text/javascript" src="../metrics.js"></script>
<script type="text/javascript" src="../charsets.js"></script>
<script type="text/javascript" src="../cidmaps.js"></script>
</head>
<body>