UNPKG

4.89 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2017 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * Javascript code in this page
21 */
22'use strict';
23
24var _fonts = require('../../core/fonts');
25
26var _stream = require('../../core/stream');
27
28var _type1_parser = require('../../core/type1_parser');
29
30describe('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