mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Read multi-byte character codes based on codespace ranges.
This commit is contained in:
parent
31fda50123
commit
f32e65b19f
9 changed files with 592 additions and 124 deletions
BIN
test/pdfs/bug898853.pdf
Normal file
BIN
test/pdfs/bug898853.pdf
Normal file
Binary file not shown.
|
@ -869,6 +869,13 @@
|
|||
"link": true,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "bug898853.pdf",
|
||||
"file": "pdfs/bug898853.pdf",
|
||||
"md5": "37c37702bf98d33f9f74e2380c4d1a3f",
|
||||
"rounds": 1,
|
||||
"type": "eq",
|
||||
"about": "Has a multi-byte char codes."
|
||||
},
|
||||
{ "id": "issue1912",
|
||||
"file": "pdfs/issue1912.pdf",
|
||||
"md5": "15305b7c2cba971e7423de3f6ad38fef",
|
||||
|
|
86
test/unit/cmap_spec.js
Normal file
86
test/unit/cmap_spec.js
Normal file
|
@ -0,0 +1,86 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
/* globals expect, it, describe, StringStream, Lexer, CMapFactory */
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('cmap', function() {
|
||||
it('parses beginbfchar', function() {
|
||||
var str = '2 beginbfchar\n' +
|
||||
'<03> <00>\n' +
|
||||
'<04> <01>\n' +
|
||||
'endbfchar\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.lookup(0x03)).toEqual(String.fromCharCode(0x00));
|
||||
expect(cmap.lookup(0x04)).toEqual(String.fromCharCode(0x01));
|
||||
expect(cmap.lookup(0x05)).toBeUndefined();
|
||||
});
|
||||
it('parses beginbfrange with range', function() {
|
||||
var str = '1 beginbfrange\n' +
|
||||
'<06> <0B> 0\n' +
|
||||
'endbfrange\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.lookup(0x05)).toBeUndefined();
|
||||
expect(cmap.lookup(0x06)).toEqual(String.fromCharCode(0x00));
|
||||
expect(cmap.lookup(0x0B)).toEqual(String.fromCharCode(0x05));
|
||||
expect(cmap.lookup(0x0C)).toBeUndefined();
|
||||
});
|
||||
it('parses beginbfrange with array', function() {
|
||||
var str = '1 beginbfrange\n' +
|
||||
'<0D> <12> [ 0 1 2 3 4 5 ]\n' +
|
||||
'endbfrange\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.lookup(0x0C)).toBeUndefined();
|
||||
expect(cmap.lookup(0x0D)).toEqual(0x00);
|
||||
expect(cmap.lookup(0x12)).toEqual(0x05);
|
||||
expect(cmap.lookup(0x13)).toBeUndefined();
|
||||
});
|
||||
it('parses begincidchar', function() {
|
||||
var str = '1 begincidchar\n' +
|
||||
'<14> 0\n' +
|
||||
'endcidchar\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.lookup(0x14)).toEqual(String.fromCharCode(0x00));
|
||||
expect(cmap.lookup(0x15)).toBeUndefined();
|
||||
});
|
||||
it('parses begincidrange', function() {
|
||||
var str = '1 begincidrange\n' +
|
||||
'<0016> <001B> 0\n' +
|
||||
'endcidrange\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
expect(cmap.lookup(0x15)).toBeUndefined();
|
||||
expect(cmap.lookup(0x16)).toEqual(String.fromCharCode(0x00));
|
||||
expect(cmap.lookup(0x1B)).toEqual(String.fromCharCode(0x05));
|
||||
expect(cmap.lookup(0x1C)).toBeUndefined();
|
||||
});
|
||||
it('decodes codespace ranges', function() {
|
||||
var str = '1 begincodespacerange\n' +
|
||||
'<01> <02>\n' +
|
||||
'<00000003> <00000004>\n' +
|
||||
'endcodespacerange\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
var c = cmap.readCharCode(String.fromCharCode(1), 0);
|
||||
expect(c[0]).toEqual(1);
|
||||
expect(c[1]).toEqual(1);
|
||||
c = cmap.readCharCode(String.fromCharCode(0, 0, 0, 3), 0);
|
||||
expect(c[0]).toEqual(3);
|
||||
expect(c[1]).toEqual(4);
|
||||
});
|
||||
it('decodes 4 byte codespace ranges', function() {
|
||||
var str = '1 begincodespacerange\n' +
|
||||
'<8EA1A1A1> <8EA1FEFE>\n' +
|
||||
'endcodespacerange\n';
|
||||
var stream = new StringStream(str);
|
||||
var cmap = CMapFactory.create(stream);
|
||||
var c = cmap.readCharCode(String.fromCharCode(0x8E, 0xA1, 0xA1, 0xA1), 0);
|
||||
expect(c[0]).toEqual(0x8EA1A1A1);
|
||||
expect(c[1]).toEqual(4);
|
||||
});
|
||||
});
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
<script type="text/javascript" src="../../src/shared/colorspace.js"></script>
|
||||
<script type="text/javascript" src="../../src/core/crypto.js"></script>
|
||||
<script type="text/javascript" src="../../src/core/evaluator.js"></script>
|
||||
<script type="text/javascript" src="../../src/core/cmap.js"></script>
|
||||
<script type="text/javascript" src="../../src/core/fonts.js"></script>
|
||||
<script type="text/javascript" src="../../src/core/glyphlist.js"></script>
|
||||
<script type="text/javascript" src="../../src/core/image.js"></script>
|
||||
|
@ -49,6 +50,7 @@
|
|||
<script type="text/javascript" src="api_spec.js"></script>
|
||||
<script type="text/javascript" src="metadata_spec.js"></script>
|
||||
<script type="text/javascript" src="util_spec.js"></script>
|
||||
<script type="text/javascript" src="cmap_spec.js"></script>
|
||||
<script type="text/javascript">
|
||||
'use strict';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue