Initial CID0 font encodings
This commit is contained in:
parent
575e0b9f89
commit
66cd79f308
6932
cidmaps.js
Normal file
6932
cidmaps.js
Normal file
File diff suppressed because it is too large
Load Diff
1
fonts.js
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
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;
|
||||||
|
|
||||||
|
// 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++]
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
properties.widths = glyphsWidths;
|
|
||||||
|
|
||||||
var cidToGidMap = dict.get('CIDToGIDMap');
|
return Object.create(GlyphsUnicode);
|
||||||
if (!cidToGidMap || !IsRef(cidToGidMap)) {
|
|
||||||
return Object.create(GlyphsUnicode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract the encoding from the CIDToGIDMap
|
|
||||||
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++) {
|
|
||||||
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 (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');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
Normal file
1
test/pdfs/tcpdf_033.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
http://www.tcpdf.org/examples/example_033.pdf
|
@ -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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -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>
|
||||||
|
|
||||||
|
@ -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…
Reference in New Issue
Block a user