Browse Source

Initial CID0 font encodings

notmasteryet 14 years ago
parent
commit
66cd79f308
  1. 6932
      cidmaps.js
  2. 1
      fonts.js
  3. 155
      pdf.js
  4. 1
      test/pdfs/tcpdf_033.pdf.link
  5. 6
      test/test_manifest.json
  6. 1
      test/test_slave.html
  7. 1
      web/viewer.html

6932
cidmaps.js

File diff suppressed because it is too large Load Diff

1
fonts.js

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

155
pdf.js

@ -4437,72 +4437,107 @@ var PartialEvaluator = (function partialEvaluator() {
properties) { properties) {
var type = properties.type, encoding; var type = properties.type, encoding;
if (properties.composite) { if (properties.composite) {
if (type == 'CIDFontType2') { var defaultWidth = xref.fetchIfRef(dict.get('DW')) || 1000;
var defaultWidth = xref.fetchIfRef(dict.get('DW')) || 1000; properties.defaultWidth = defaultWidth;
properties.defaultWidth = defaultWidth;
var glyphsWidths = {};
var glyphsWidths = {}; var widths = xref.fetchIfRef(dict.get('W'));
var widths = xref.fetchIfRef(dict.get('W')); if (widths) {
if (widths) { var start = 0, end = 0;
var start = 0, end = 0; for (var i = 0; i < widths.length; i++) {
for (var i = 0; i < widths.length; i++) { var code = widths[i];
var code = widths[i]; if (IsArray(code)) {
if (IsArray(code)) { for (var j = 0; j < code.length; j++)
for (var j = 0; j < code.length; j++) glyphsWidths[start++] = code[j];
glyphsWidths[start++] = code[j]; start = 0;
start = 0; } else if (start) {
} else if (start) { var width = widths[++i];
var width = widths[++i]; for (var j = start; j <= code; j++)
for (var j = start; j <= code; j++) glyphsWidths[j] = width;
glyphsWidths[j] = width; start = 0;
start = 0; } else {
} else { start = code;
start = code;
}
} }
} }
properties.widths = glyphsWidths; }
properties.widths = glyphsWidths;
var cidToGidMap = dict.get('CIDToGIDMap');
if (!cidToGidMap || !IsRef(cidToGidMap)) { // Glyph ids are big-endian 2-byte values
return Object.create(GlyphsUnicode); encoding = properties.encoding;
}
var cidToGidMap = dict.get('CIDToGIDMap');
// Extract the encoding from the CIDToGIDMap if (!cidToGidMap || !IsRef(cidToGidMap)) {
var glyphsStream = xref.fetchIfRef(cidToGidMap); // trying to guess encoding from CIDSystemInfo
var glyphsData = glyphsStream.getBytes(0); var cidSystemInfo = dict.get('CIDSystemInfo');
var cidToUnicode;
// Glyph ids are big-endian 2-byte values if (IsDict(cidSystemInfo)) {
encoding = properties.encoding; cidToUnicode = CIDToUnicodeMaps[
cidSystemInfo.get('Registry') + '-' +
// Set encoding 0 to later verify the font has an encoding cidSystemInfo.get('Ordering')];
encoding[0] = { unicode: 0, width: 0 };
for (var j = 0; j < glyphsData.length; j++) {
var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
if (glyphID == 0)
continue;
var code = j >> 1;
var width = glyphsWidths[code];
encoding[code] = {
unicode: glyphID,
width: IsNum(width) ? width : defaultWidth
};
} }
} else if (type == 'CIDFontType0') { if (cidToUnicode) {
if (IsName(encoding)) { encoding[0] = { unicode: 0, width: 0 };
// Encoding is a predefined CMap var glyph = 1, i, j;
if (encoding.name == 'Identity-H') { for (i = 0; i < cidToUnicode.length; ++i) {
TODO('Need to create an identity cmap'); var unicode = cidToUnicode[i];
} else { if (IsArray(unicode)) {
TODO('Need to support predefined CMaps see PDF 32000-1:2008 ' + var length = unicode.length;
'9.7.5.2 Predefined CMaps'); 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++]
};
}
} }
} else {
TODO('Need to support encoding streams see PDF 32000-1:2008 ' +
'9.7.5.3');
} }
return Object.create(GlyphsUnicode);
} }
// Extract the encoding from the CIDToGIDMap
var glyphsStream = xref.fetchIfRef(cidToGidMap);
var glyphsData = glyphsStream.getBytes(0);
// 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++) {
var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
if (glyphID == 0)
continue;
var code = j >> 1;
var width = glyphsWidths[code];
encoding[code] = {
unicode: glyphID,
width: IsNum(width) ? width : defaultWidth
};
}
return Object.create(GlyphsUnicode); return Object.create(GlyphsUnicode);
} }

1
test/pdfs/tcpdf_033.pdf.link

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

6
test/test_manifest.json

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

1
test/test_slave.html

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

1
web/viewer.html

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

Loading…
Cancel
Save