1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | 'use strict';
|
23 |
|
24 | var _fonts = require('../../core/fonts');
|
25 |
|
26 | var _stream = require('../../core/stream');
|
27 |
|
28 | var _type1_parser = require('../../core/type1_parser');
|
29 |
|
30 | describe('Type1Parser', function () {
|
31 | it('splits tokens', function () {
|
32 | var stream = new _stream.StringStream('/BlueValues[-17 0]noaccess def');
|
33 | var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
|
34 | expect(parser.getToken()).toEqual('/');
|
35 | expect(parser.getToken()).toEqual('BlueValues');
|
36 | expect(parser.getToken()).toEqual('[');
|
37 | expect(parser.getToken()).toEqual('-17');
|
38 | expect(parser.getToken()).toEqual('0');
|
39 | expect(parser.getToken()).toEqual(']');
|
40 | expect(parser.getToken()).toEqual('noaccess');
|
41 | expect(parser.getToken()).toEqual('def');
|
42 | expect(parser.getToken()).toEqual(null);
|
43 | });
|
44 | it('handles glued tokens', function () {
|
45 | var stream = new _stream.StringStream('dup/CharStrings');
|
46 | var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
|
47 | expect(parser.getToken()).toEqual('dup');
|
48 | expect(parser.getToken()).toEqual('/');
|
49 | expect(parser.getToken()).toEqual('CharStrings');
|
50 | });
|
51 | it('ignores whitespace', function () {
|
52 | var stream = new _stream.StringStream('\nab c\t');
|
53 | var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
|
54 | expect(parser.getToken()).toEqual('ab');
|
55 | expect(parser.getToken()).toEqual('c');
|
56 | });
|
57 | it('parses numbers', function () {
|
58 | var stream = new _stream.StringStream('123');
|
59 | var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
|
60 | expect(parser.readNumber()).toEqual(123);
|
61 | });
|
62 | it('parses booleans', function () {
|
63 | var stream = new _stream.StringStream('true false');
|
64 | var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
|
65 | expect(parser.readBoolean()).toEqual(1);
|
66 | expect(parser.readBoolean()).toEqual(0);
|
67 | });
|
68 | it('parses number arrays', function () {
|
69 | var stream = new _stream.StringStream('[1 2]');
|
70 | var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
|
71 | expect(parser.readNumberArray()).toEqual([1, 2]);
|
72 | stream = new _stream.StringStream('[ 1 2 ]');
|
73 | parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
|
74 | expect(parser.readNumberArray()).toEqual([1, 2]);
|
75 | });
|
76 | it('skips comments', function () {
|
77 | var stream = new _stream.StringStream('%!PS-AdobeFont-1.0: CMSY10 003.002\n' + '%%Title: CMSY10\n' + '%Version: 003.002\n' + 'FontDirectory');
|
78 | var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
|
79 | expect(parser.getToken()).toEqual('FontDirectory');
|
80 | });
|
81 | it('parses font program', function () {
|
82 | var stream = new _stream.StringStream('/ExpansionFactor 99\n' + '/Subrs 1 array\n' + 'dup 0 1 RD x noaccess put\n' + 'end\n' + '/CharStrings 46 dict dup begin\n' + '/.notdef 1 RD x ND\n' + 'end');
|
83 | var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
|
84 | var program = parser.extractFontProgram();
|
85 | expect(program.charstrings.length).toEqual(1);
|
86 | expect(program.properties.privateData.ExpansionFactor).toEqual(99);
|
87 | });
|
88 | it('parses font header font matrix', function () {
|
89 | var stream = new _stream.StringStream('/FontMatrix [0.001 0 0 0.001 0 0 ]readonly def\n');
|
90 | var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
|
91 | var props = {};
|
92 | parser.extractFontHeader(props);
|
93 | expect(props.fontMatrix).toEqual([0.001, 0, 0, 0.001, 0, 0]);
|
94 | });
|
95 | it('parses font header encoding', function () {
|
96 | var stream = new _stream.StringStream('/Encoding 256 array\n' + '0 1 255 {1 index exch /.notdef put} for\n' + 'dup 33 /arrowright put\n' + 'readonly def\n');
|
97 | var parser = new _type1_parser.Type1Parser(stream, false, _fonts.SEAC_ANALYSIS_ENABLED);
|
98 | var props = { overridableEncoding: true };
|
99 | parser.extractFontHeader(props);
|
100 | expect(props.builtInEncoding[33]).toEqual('arrowright');
|
101 | });
|
102 | }); |
\ | No newline at end of file |