Best JavaScript code snippet using wpt
obj.js
Source:obj.js
...687 };688 return Catalog;689}();690var XRef = function XRefClosure() {691 function XRef(stream, pdfManager) {692 this.stream = stream;693 this.pdfManager = pdfManager;694 this.entries = [];695 this.xrefstms = Object.create(null);696 this.cache = [];697 this.stats = {698 streamTypes: [],699 fontTypes: []700 };701 }702 XRef.prototype = {703 setStartXRef: function XRef_setStartXRef(startXRef) {704 this.startXRefQueue = [startXRef];705 },706 parse: function XRef_parse(recoveryMode) {707 var trailerDict;708 if (!recoveryMode) {709 trailerDict = this.readXRef();710 } else {711 (0, _util.warn)('Indexing all PDF objects');712 trailerDict = this.indexObjects();713 }714 trailerDict.assignXref(this);715 this.trailer = trailerDict;716 var encrypt = trailerDict.get('Encrypt');717 if ((0, _primitives.isDict)(encrypt)) {718 var ids = trailerDict.get('ID');719 var fileId = ids && ids.length ? ids[0] : '';720 encrypt.suppressEncryption = true;721 this.encrypt = new _crypto.CipherTransformFactory(encrypt, fileId, this.pdfManager.password);722 }723 if (!(this.root = trailerDict.get('Root'))) {724 throw new _util.FormatError('Invalid root reference');725 }726 },727 processXRefTable: function XRef_processXRefTable(parser) {728 if (!('tableState' in this)) {729 this.tableState = {730 entryNum: 0,731 streamPos: parser.lexer.stream.pos,732 parserBuf1: parser.buf1,733 parserBuf2: parser.buf2734 };735 }736 var obj = this.readXRefTable(parser);737 if (!(0, _primitives.isCmd)(obj, 'trailer')) {738 throw new _util.FormatError('Invalid XRef table: could not find trailer dictionary');739 }740 var dict = parser.getObj();741 if (!(0, _primitives.isDict)(dict) && dict.dict) {742 dict = dict.dict;743 }744 if (!(0, _primitives.isDict)(dict)) {745 throw new _util.FormatError('Invalid XRef table: could not parse trailer dictionary');746 }747 delete this.tableState;748 return dict;749 },750 readXRefTable: function XRef_readXRefTable(parser) {751 var stream = parser.lexer.stream;752 var tableState = this.tableState;753 stream.pos = tableState.streamPos;754 parser.buf1 = tableState.parserBuf1;755 parser.buf2 = tableState.parserBuf2;756 var obj;757 while (true) {758 if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {759 if ((0, _primitives.isCmd)(obj = parser.getObj(), 'trailer')) {760 break;761 }762 tableState.firstEntryNum = obj;763 tableState.entryCount = parser.getObj();764 }765 var first = tableState.firstEntryNum;766 var count = tableState.entryCount;767 if (!Number.isInteger(first) || !Number.isInteger(count)) {768 throw new _util.FormatError('Invalid XRef table: wrong types in subsection header');769 }770 for (var i = tableState.entryNum; i < count; i++) {771 tableState.streamPos = stream.pos;772 tableState.entryNum = i;773 tableState.parserBuf1 = parser.buf1;774 tableState.parserBuf2 = parser.buf2;775 var entry = {};776 entry.offset = parser.getObj();777 entry.gen = parser.getObj();778 var type = parser.getObj();779 if ((0, _primitives.isCmd)(type, 'f')) {780 entry.free = true;781 } else if ((0, _primitives.isCmd)(type, 'n')) {782 entry.uncompressed = true;783 }784 if (!Number.isInteger(entry.offset) || !Number.isInteger(entry.gen) || !(entry.free || entry.uncompressed)) {785 throw new _util.FormatError('Invalid entry in XRef subsection: ' + first + ', ' + count);786 }787 if (i === 0 && entry.free && first === 1) {788 first = 0;789 }790 if (!this.entries[i + first]) {791 this.entries[i + first] = entry;792 }793 }794 tableState.entryNum = 0;795 tableState.streamPos = stream.pos;796 tableState.parserBuf1 = parser.buf1;797 tableState.parserBuf2 = parser.buf2;798 delete tableState.firstEntryNum;799 delete tableState.entryCount;800 }801 if (this.entries[0] && !this.entries[0].free) {802 throw new _util.FormatError('Invalid XRef table: unexpected first object');803 }804 return obj;805 },806 processXRefStream: function XRef_processXRefStream(stream) {807 if (!('streamState' in this)) {808 var streamParameters = stream.dict;809 var byteWidths = streamParameters.get('W');810 var range = streamParameters.get('Index');811 if (!range) {812 range = [0, streamParameters.get('Size')];813 }814 this.streamState = {815 entryRanges: range,816 byteWidths: byteWidths,817 entryNum: 0,818 streamPos: stream.pos819 };820 }821 this.readXRefStream(stream);822 delete this.streamState;823 return stream.dict;824 },825 readXRefStream: function XRef_readXRefStream(stream) {826 var i, j;827 var streamState = this.streamState;828 stream.pos = streamState.streamPos;829 var byteWidths = streamState.byteWidths;830 var typeFieldWidth = byteWidths[0];831 var offsetFieldWidth = byteWidths[1];832 var generationFieldWidth = byteWidths[2];833 var entryRanges = streamState.entryRanges;834 while (entryRanges.length > 0) {835 var first = entryRanges[0];836 var n = entryRanges[1];837 if (!Number.isInteger(first) || !Number.isInteger(n)) {838 throw new _util.FormatError('Invalid XRef range fields: ' + first + ', ' + n);839 }840 if (!Number.isInteger(typeFieldWidth) || !Number.isInteger(offsetFieldWidth) || !Number.isInteger(generationFieldWidth)) {841 throw new _util.FormatError('Invalid XRef entry fields length: ' + first + ', ' + n);842 }843 for (i = streamState.entryNum; i < n; ++i) {844 streamState.entryNum = i;845 streamState.streamPos = stream.pos;846 var type = 0,847 offset = 0,848 generation = 0;849 for (j = 0; j < typeFieldWidth; ++j) {850 type = type << 8 | stream.getByte();851 }852 if (typeFieldWidth === 0) {853 type = 1;854 }855 for (j = 0; j < offsetFieldWidth; ++j) {856 offset = offset << 8 | stream.getByte();857 }858 for (j = 0; j < generationFieldWidth; ++j) {859 generation = generation << 8 | stream.getByte();860 }861 var entry = {};862 entry.offset = offset;863 entry.gen = generation;864 switch (type) {865 case 0:866 entry.free = true;867 break;868 case 1:869 entry.uncompressed = true;870 break;871 case 2:872 break;873 default:874 throw new _util.FormatError('Invalid XRef entry type: ' + type);875 }876 if (!this.entries[first + i]) {877 this.entries[first + i] = entry;878 }879 }880 streamState.entryNum = 0;881 streamState.streamPos = stream.pos;882 entryRanges.splice(0, 2);883 }884 },885 indexObjects: function XRef_indexObjects() {886 var TAB = 0x9,887 LF = 0xA,888 CR = 0xD,889 SPACE = 0x20;890 var PERCENT = 0x25,891 LT = 0x3C;892 function readToken(data, offset) {893 var token = '',894 ch = data[offset];895 while (ch !== LF && ch !== CR && ch !== LT) {896 if (++offset >= data.length) {897 break;898 }899 token += String.fromCharCode(ch);900 ch = data[offset];901 }902 return token;903 }904 function skipUntil(data, offset, what) {905 var length = what.length,906 dataLength = data.length;907 var skipped = 0;908 while (offset < dataLength) {909 var i = 0;910 while (i < length && data[offset + i] === what[i]) {911 ++i;912 }913 if (i >= length) {914 break;915 }916 offset++;917 skipped++;918 }919 return skipped;920 }921 var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;922 var endobjRegExp = /\bendobj[\b\s]$/;923 var nestedObjRegExp = /\s+(\d+\s+\d+\s+obj[\b\s])$/;924 var CHECK_CONTENT_LENGTH = 25;925 var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);926 var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114, 101, 102]);927 var objBytes = new Uint8Array([111, 98, 106]);928 var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);929 this.entries.length = 0;930 var stream = this.stream;931 stream.pos = 0;932 var buffer = stream.getBytes();933 var position = stream.start,934 length = buffer.length;935 var trailers = [],936 xrefStms = [];937 while (position < length) {938 var ch = buffer[position];939 if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {940 ++position;941 continue;942 }943 if (ch === PERCENT) {944 do {945 ++position;946 if (position >= length) {947 break;948 }949 ch = buffer[position];950 } while (ch !== LF && ch !== CR);951 continue;952 }953 var token = readToken(buffer, position);954 var m;955 if (token.indexOf('xref') === 0 && (token.length === 4 || /\s/.test(token[4]))) {956 position += skipUntil(buffer, position, trailerBytes);957 trailers.push(position);958 position += skipUntil(buffer, position, startxrefBytes);959 } else if (m = objRegExp.exec(token)) {960 if (typeof this.entries[m[1]] === 'undefined') {961 this.entries[m[1]] = {962 offset: position - stream.start,963 gen: m[2] | 0,964 uncompressed: true965 };966 }967 var contentLength = void 0,968 startPos = position + token.length;969 while (startPos < buffer.length) {970 var endPos = startPos + skipUntil(buffer, startPos, objBytes) + 4;971 contentLength = endPos - position;972 var checkPos = Math.max(endPos - CHECK_CONTENT_LENGTH, startPos);973 var tokenStr = (0, _util.bytesToString)(buffer.subarray(checkPos, endPos));974 if (endobjRegExp.test(tokenStr)) {975 break;976 } else {977 var objToken = nestedObjRegExp.exec(tokenStr);978 if (objToken && objToken[1]) {979 (0, _util.warn)('indexObjects: Found new "obj" inside of another "obj", ' + 'caused by missing "endobj" -- trying to recover.');980 contentLength -= objToken[1].length;981 break;982 }983 }984 startPos += contentLength;985 }986 var content = buffer.subarray(position, position + contentLength);987 var xrefTagOffset = skipUntil(content, 0, xrefBytes);988 if (xrefTagOffset < contentLength && content[xrefTagOffset + 5] < 64) {989 xrefStms.push(position - stream.start);990 this.xrefstms[position - stream.start] = 1;991 }992 position += contentLength;993 } else if (token.indexOf('trailer') === 0 && (token.length === 7 || /\s/.test(token[7]))) {994 trailers.push(position);995 position += skipUntil(buffer, position, startxrefBytes);996 } else {997 position += token.length + 1;998 }999 }1000 var i, ii;1001 for (i = 0, ii = xrefStms.length; i < ii; ++i) {1002 this.startXRefQueue.push(xrefStms[i]);1003 this.readXRef(true);1004 }1005 var dict;1006 for (i = 0, ii = trailers.length; i < ii; ++i) {1007 stream.pos = trailers[i];1008 var parser = new _parser.Parser(new _parser.Lexer(stream), true, this, true);1009 var obj = parser.getObj();1010 if (!(0, _primitives.isCmd)(obj, 'trailer')) {1011 continue;1012 }1013 dict = parser.getObj();1014 if (!(0, _primitives.isDict)(dict)) {1015 continue;1016 }1017 if (dict.has('ID')) {1018 return dict;1019 }1020 }1021 if (dict) {1022 return dict;1023 }1024 throw new _util.InvalidPDFException('Invalid PDF structure');1025 },1026 readXRef: function XRef_readXRef(recoveryMode) {1027 var stream = this.stream;1028 var startXRefParsedCache = Object.create(null);1029 try {1030 while (this.startXRefQueue.length) {1031 var startXRef = this.startXRefQueue[0];1032 if (startXRefParsedCache[startXRef]) {1033 (0, _util.warn)('readXRef - skipping XRef table since it was already parsed.');1034 this.startXRefQueue.shift();1035 continue;1036 }1037 startXRefParsedCache[startXRef] = true;1038 stream.pos = startXRef + stream.start;1039 var parser = new _parser.Parser(new _parser.Lexer(stream), true, this);1040 var obj = parser.getObj();...
colorspace_spec.js
Source:colorspace_spec.js
1/**2 * @licstart The following is the entire license notice for the3 * Javascript code in this page4 *5 * Copyright 2017 Mozilla Foundation6 *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 at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing, software14 * 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 and17 * limitations under the License.18 *19 * @licend The above is the entire license notice for the20 * Javascript code in this page21 */22'use strict';23var _primitives = require('../../core/primitives');24var _stream = require('../../core/stream');25var _colorspace = require('../../core/colorspace');26var _function = require('../../core/function');27var _test_utils = require('./test_utils');28describe('colorspace', function () {29 describe('ColorSpace', function () {30 it('should be true if decode is not an array', function () {31 expect(_colorspace.ColorSpace.isDefaultDecode('string', 0)).toBeTruthy();32 });33 it('should be true if length of decode array is not correct', function () {34 expect(_colorspace.ColorSpace.isDefaultDecode([0], 1)).toBeTruthy();35 expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0], 1)).toBeTruthy();36 });37 it('should be true if decode map matches the default decode map', function () {38 expect(_colorspace.ColorSpace.isDefaultDecode([], 0)).toBeTruthy();39 expect(_colorspace.ColorSpace.isDefaultDecode([0, 0], 1)).toBeFalsy();40 expect(_colorspace.ColorSpace.isDefaultDecode([0, 1], 1)).toBeTruthy();41 expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 0, 1], 3)).toBeTruthy();42 expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 1, 1], 3)).toBeFalsy();43 expect(_colorspace.ColorSpace.isDefaultDecode([0, 1, 0, 1, 0, 1, 0, 1], 4)).toBeTruthy();44 expect(_colorspace.ColorSpace.isDefaultDecode([1, 0, 0, 1, 0, 1, 0, 1], 4)).toBeFalsy();45 });46 });47 describe('DeviceGrayCS', function () {48 it('should handle the case when cs is a Name object', function () {49 var cs = _primitives.Name.get('DeviceGray');50 var xref = new _test_utils.XRefMock([{51 ref: new _primitives.Ref(10, 0),52 data: new _primitives.Dict()53 }]);54 var res = new _primitives.Dict();55 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });56 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);57 var testSrc = new Uint8Array([27, 125, 250, 131]);58 var testDest = new Uint8Array(4 * 4 * 3);59 var expectedDest = new Uint8Array([27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131, 250, 250, 250, 250, 250, 250, 131, 131, 131, 131, 131, 131]);60 colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);61 expect(colorSpace.getRgb(new Float32Array([0.1]), 0)).toEqual(new Uint8Array([25, 25, 25]));62 expect(colorSpace.getOutputLength(2, 0)).toEqual(6);63 expect(colorSpace.isPassthrough(8)).toBeFalsy();64 expect(testDest).toEqual(expectedDest);65 });66 it('should handle the case when cs is an indirect object', function () {67 var cs = new _primitives.Ref(10, 0);68 var xref = new _test_utils.XRefMock([{69 ref: cs,70 data: _primitives.Name.get('DeviceGray')71 }]);72 var res = new _primitives.Dict();73 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });74 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);75 var testSrc = new Uint8Array([27, 125, 250, 131]);76 var testDest = new Uint8Array(3 * 3 * 3);77 var expectedDest = new Uint8Array([27, 27, 27, 27, 27, 27, 125, 125, 125, 27, 27, 27, 27, 27, 27, 125, 125, 125, 250, 250, 250, 250, 250, 250, 131, 131, 131]);78 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);79 expect(colorSpace.getRgb(new Float32Array([0.2]), 0)).toEqual(new Uint8Array([51, 51, 51]));80 expect(colorSpace.getOutputLength(3, 1)).toEqual(12);81 expect(colorSpace.isPassthrough(8)).toBeFalsy();82 expect(testDest).toEqual(expectedDest);83 });84 });85 describe('DeviceRgbCS', function () {86 it('should handle the case when cs is a Name object', function () {87 var cs = _primitives.Name.get('DeviceRGB');88 var xref = new _test_utils.XRefMock([{89 ref: new _primitives.Ref(10, 0),90 data: new _primitives.Dict()91 }]);92 var res = new _primitives.Dict();93 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });94 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);95 var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);96 var testDest = new Uint8Array(4 * 4 * 3);97 var expectedDest = new Uint8Array([27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255, 111, 25, 198, 111, 25, 198, 21, 147, 255, 21, 147, 255]);98 colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);99 expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([25, 51, 76]));100 expect(colorSpace.getOutputLength(4, 0)).toEqual(4);101 expect(colorSpace.isPassthrough(8)).toBeTruthy();102 expect(testDest).toEqual(expectedDest);103 });104 it('should handle the case when cs is an indirect object', function () {105 var cs = new _primitives.Ref(10, 0);106 var xref = new _test_utils.XRefMock([{107 ref: cs,108 data: _primitives.Name.get('DeviceRGB')109 }]);110 var res = new _primitives.Dict();111 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });112 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);113 var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);114 var testDest = new Uint8Array(3 * 3 * 3);115 var expectedDest = new Uint8Array([27, 125, 250, 27, 125, 250, 131, 139, 140, 27, 125, 250, 27, 125, 250, 131, 139, 140, 111, 25, 198, 111, 25, 198, 21, 147, 255]);116 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);117 expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([25, 51, 76]));118 expect(colorSpace.getOutputLength(4, 1)).toEqual(5);119 expect(colorSpace.isPassthrough(8)).toBeTruthy();120 expect(testDest).toEqual(expectedDest);121 });122 });123 describe('DeviceCmykCS', function () {124 it('should handle the case when cs is a Name object', function () {125 var cs = _primitives.Name.get('DeviceCMYK');126 var xref = new _test_utils.XRefMock([{127 ref: new _primitives.Ref(10, 0),128 data: new _primitives.Dict()129 }]);130 var res = new _primitives.Dict();131 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });132 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);133 var testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);134 var testDest = new Uint8Array(4 * 4 * 3);135 var expectedDest = new Uint8Array([135, 80, 18, 135, 80, 18, 113, 102, 97, 113, 102, 97, 135, 80, 18, 135, 80, 18, 113, 102, 97, 113, 102, 97, 112, 143, 75, 112, 143, 75, 188, 98, 27, 188, 98, 27, 112, 143, 75, 112, 143, 75, 188, 98, 27, 188, 98, 27]);136 colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);137 expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8Array([31, 27, 20]));138 expect(colorSpace.getOutputLength(4, 0)).toEqual(3);139 expect(colorSpace.isPassthrough(8)).toBeFalsy();140 expect(testDest).toEqual(expectedDest);141 });142 it('should handle the case when cs is an indirect object', function () {143 var cs = new _primitives.Ref(10, 0);144 var xref = new _test_utils.XRefMock([{145 ref: cs,146 data: _primitives.Name.get('DeviceCMYK')147 }]);148 var res = new _primitives.Dict();149 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });150 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);151 var testSrc = new Uint8Array([27, 125, 250, 128, 131, 139, 140, 45, 111, 25, 198, 78, 21, 147, 255, 69]);152 var testDest = new Uint8Array(3 * 3 * 3);153 var expectedDest = new Uint8Array([135, 80, 18, 135, 80, 18, 113, 102, 97, 135, 80, 18, 135, 80, 18, 113, 102, 97, 112, 143, 75, 112, 143, 75, 188, 98, 27]);154 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);155 expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3, 1]), 0)).toEqual(new Uint8Array([31, 27, 20]));156 expect(colorSpace.getOutputLength(4, 1)).toEqual(4);157 expect(colorSpace.isPassthrough(8)).toBeFalsy();158 expect(testDest).toEqual(expectedDest);159 });160 });161 describe('CalGrayCS', function () {162 it('should handle the case when cs is an array', function () {163 var params = new _primitives.Dict();164 params.set('WhitePoint', [1, 1, 1]);165 params.set('BlackPoint', [0, 0, 0]);166 params.set('Gamma', 2.0);167 var cs = [_primitives.Name.get('CalGray'), params];168 var xref = new _test_utils.XRefMock([{169 ref: new _primitives.Ref(10, 0),170 data: new _primitives.Dict()171 }]);172 var res = new _primitives.Dict();173 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });174 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);175 var testSrc = new Uint8Array([27, 125, 250, 131]);176 var testDest = new Uint8Array(4 * 4 * 3);177 var expectedDest = new Uint8Array([25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 25, 25, 25, 25, 25, 25, 143, 143, 143, 143, 143, 143, 251, 251, 251, 251, 251, 251, 148, 148, 148, 148, 148, 148, 251, 251, 251, 251, 251, 251, 148, 148, 148, 148, 148, 148]);178 colorSpace.fillRgb(testDest, 2, 2, 4, 4, 4, 8, testSrc, 0);179 expect(colorSpace.getRgb(new Float32Array([1.0]), 0)).toEqual(new Uint8Array([255, 255, 255]));180 expect(colorSpace.getOutputLength(4, 0)).toEqual(12);181 expect(colorSpace.isPassthrough(8)).toBeFalsy();182 expect(testDest).toEqual(expectedDest);183 });184 });185 describe('CalRGBCS', function () {186 it('should handle the case when cs is an array', function () {187 var params = new _primitives.Dict();188 params.set('WhitePoint', [1, 1, 1]);189 params.set('BlackPoint', [0, 0, 0]);190 params.set('Gamma', [1, 1, 1]);191 params.set('Matrix', [1, 0, 0, 0, 1, 0, 0, 0, 1]);192 var cs = [_primitives.Name.get('CalRGB'), params];193 var xref = new _test_utils.XRefMock([{194 ref: new _primitives.Ref(10, 0),195 data: new _primitives.Dict()196 }]);197 var res = new _primitives.Dict();198 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });199 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);200 var testSrc = new Uint8Array([27, 125, 250, 131, 139, 140, 111, 25, 198, 21, 147, 255]);201 var testDest = new Uint8Array(3 * 3 * 3);202 var expectedDest = new Uint8Array([0, 238, 255, 0, 238, 255, 185, 196, 195, 0, 238, 255, 0, 238, 255, 185, 196, 195, 235, 0, 243, 235, 0, 243, 0, 255, 255]);203 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);204 expect(colorSpace.getRgb(new Float32Array([0.1, 0.2, 0.3]), 0)).toEqual(new Uint8Array([0, 147, 151]));205 expect(colorSpace.getOutputLength(4, 0)).toEqual(4);206 expect(colorSpace.isPassthrough(8)).toBeFalsy();207 expect(testDest).toEqual(expectedDest);208 });209 });210 describe('LabCS', function () {211 it('should handle the case when cs is an array', function () {212 var params = new _primitives.Dict();213 params.set('WhitePoint', [1, 1, 1]);214 params.set('BlackPoint', [0, 0, 0]);215 params.set('Range', [-100, 100, -100, 100]);216 var cs = [_primitives.Name.get('Lab'), params];217 var xref = new _test_utils.XRefMock([{218 ref: new _primitives.Ref(10, 0),219 data: new _primitives.Dict()220 }]);221 var res = new _primitives.Dict();222 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });223 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);224 var testSrc = new Uint8Array([27, 25, 50, 31, 19, 40, 11, 25, 98, 21, 47, 55]);225 var testDest = new Uint8Array(3 * 3 * 3);226 var expectedDest = new Uint8Array([0, 49, 101, 0, 49, 101, 0, 53, 116, 0, 49, 101, 0, 49, 101, 0, 53, 116, 0, 40, 39, 0, 40, 39, 0, 43, 90]);227 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);228 expect(colorSpace.getRgb([55, 25, 35], 0)).toEqual(new Uint8Array([188, 99, 61]));229 expect(colorSpace.getOutputLength(4, 0)).toEqual(4);230 expect(colorSpace.isPassthrough(8)).toBeFalsy();231 expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();232 expect(testDest).toEqual(expectedDest);233 });234 });235 describe('IndexedCS', function () {236 it('should handle the case when cs is an array', function () {237 var lookup = new Uint8Array([23, 155, 35, 147, 69, 93, 255, 109, 70]);238 var cs = [_primitives.Name.get('Indexed'), _primitives.Name.get('DeviceRGB'), 2, lookup];239 var xref = new _test_utils.XRefMock([{240 ref: new _primitives.Ref(10, 0),241 data: new _primitives.Dict()242 }]);243 var res = new _primitives.Dict();244 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });245 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);246 var testSrc = new Uint8Array([2, 2, 0, 1]);247 var testDest = new Uint8Array(3 * 3 * 3);248 var expectedDest = new Uint8Array([255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 255, 109, 70, 23, 155, 35, 23, 155, 35, 147, 69, 93]);249 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);250 expect(colorSpace.getRgb([2], 0)).toEqual(new Uint8Array([255, 109, 70]));251 expect(colorSpace.isPassthrough(8)).toBeFalsy();252 expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();253 expect(testDest).toEqual(expectedDest);254 });255 });256 describe('AlternateCS', function () {257 it('should handle the case when cs is an array', function () {258 var fnDict = new _primitives.Dict();259 fnDict.set('FunctionType', 4);260 fnDict.set('Domain', [0.0, 1.0]);261 fnDict.set('Range', [0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]);262 fnDict.set('Length', 58);263 var fn = new _stream.StringStream('{ dup 0.84 mul ' + 'exch 0.00 exch ' + 'dup 0.44 mul ' + 'exch 0.21 mul }');264 fn = new _stream.Stream(fn.bytes, 0, 58, fnDict);265 var fnRef = new _primitives.Ref(10, 0);266 var cs = [_primitives.Name.get('Separation'), _primitives.Name.get('LogoGreen'), _primitives.Name.get('DeviceCMYK'), fnRef];267 var xref = new _test_utils.XRefMock([{268 ref: fnRef,269 data: fn270 }]);271 var res = new _primitives.Dict();272 var pdfFunctionFactory = new _function.PDFFunctionFactory({ xref: xref });273 var colorSpace = _colorspace.ColorSpace.parse(cs, xref, res, pdfFunctionFactory);274 var testSrc = new Uint8Array([27, 25, 50, 31]);275 var testDest = new Uint8Array(3 * 3 * 3);276 var expectedDest = new Uint8Array([227, 243, 242, 227, 243, 242, 228, 243, 242, 227, 243, 242, 227, 243, 242, 228, 243, 242, 203, 233, 229, 203, 233, 229, 222, 241, 239]);277 colorSpace.fillRgb(testDest, 2, 2, 3, 3, 3, 8, testSrc, 0);278 expect(colorSpace.getRgb([0.1], 0)).toEqual(new Uint8Array([228, 243, 241]));279 expect(colorSpace.isPassthrough(8)).toBeFalsy();280 expect(colorSpace.isDefaultDecode([0, 1])).toBeTruthy();281 expect(testDest).toEqual(expectedDest);282 });283 });...
primitives.js
Source:primitives.js
1/**2 * @licstart The following is the entire license notice for the3 * Javascript code in this page4 *5 * Copyright 2017 Mozilla Foundation6 *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 at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing, software14 * 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 and17 * limitations under the License.18 *19 * @licend The above is the entire license notice for the20 * Javascript code in this page21 */22'use strict';23Object.defineProperty(exports, "__esModule", {24 value: true25});26var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };27var EOF = {};28var Name = function NameClosure() {29 function Name(name) {30 this.name = name;31 }32 Name.prototype = {};33 var nameCache = Object.create(null);34 Name.get = function Name_get(name) {35 var nameValue = nameCache[name];36 return nameValue ? nameValue : nameCache[name] = new Name(name);37 };38 return Name;39}();40var Cmd = function CmdClosure() {41 function Cmd(cmd) {42 this.cmd = cmd;43 }44 Cmd.prototype = {};45 var cmdCache = Object.create(null);46 Cmd.get = function Cmd_get(cmd) {47 var cmdValue = cmdCache[cmd];48 return cmdValue ? cmdValue : cmdCache[cmd] = new Cmd(cmd);49 };50 return Cmd;51}();52var Dict = function DictClosure() {53 var nonSerializable = function nonSerializableClosure() {54 return nonSerializable;55 };56 function Dict(xref) {57 this._map = Object.create(null);58 this.xref = xref;59 this.objId = null;60 this.suppressEncryption = false;61 this.__nonSerializable__ = nonSerializable;62 }63 Dict.prototype = {64 assignXref: function Dict_assignXref(newXref) {65 this.xref = newXref;66 },67 get: function Dict_get(key1, key2, key3) {68 var value;69 var xref = this.xref,70 suppressEncryption = this.suppressEncryption;71 if (typeof (value = this._map[key1]) !== 'undefined' || key1 in this._map || typeof key2 === 'undefined') {72 return xref ? xref.fetchIfRef(value, suppressEncryption) : value;73 }74 if (typeof (value = this._map[key2]) !== 'undefined' || key2 in this._map || typeof key3 === 'undefined') {75 return xref ? xref.fetchIfRef(value, suppressEncryption) : value;76 }77 value = this._map[key3] || null;78 return xref ? xref.fetchIfRef(value, suppressEncryption) : value;79 },80 getAsync: function Dict_getAsync(key1, key2, key3) {81 var value;82 var xref = this.xref,83 suppressEncryption = this.suppressEncryption;84 if (typeof (value = this._map[key1]) !== 'undefined' || key1 in this._map || typeof key2 === 'undefined') {85 if (xref) {86 return xref.fetchIfRefAsync(value, suppressEncryption);87 }88 return Promise.resolve(value);89 }90 if (typeof (value = this._map[key2]) !== 'undefined' || key2 in this._map || typeof key3 === 'undefined') {91 if (xref) {92 return xref.fetchIfRefAsync(value, suppressEncryption);93 }94 return Promise.resolve(value);95 }96 value = this._map[key3] || null;97 if (xref) {98 return xref.fetchIfRefAsync(value, suppressEncryption);99 }100 return Promise.resolve(value);101 },102 getArray: function Dict_getArray(key1, key2, key3) {103 var value = this.get(key1, key2, key3);104 var xref = this.xref,105 suppressEncryption = this.suppressEncryption;106 if (!Array.isArray(value) || !xref) {107 return value;108 }109 value = value.slice();110 for (var i = 0, ii = value.length; i < ii; i++) {111 if (!isRef(value[i])) {112 continue;113 }114 value[i] = xref.fetch(value[i], suppressEncryption);115 }116 return value;117 },118 getRaw: function Dict_getRaw(key) {119 return this._map[key];120 },121 getKeys: function Dict_getKeys() {122 return Object.keys(this._map);123 },124 set: function Dict_set(key, value) {125 this._map[key] = value;126 },127 has: function Dict_has(key) {128 return key in this._map;129 },130 forEach: function Dict_forEach(callback) {131 for (var key in this._map) {132 callback(key, this.get(key));133 }134 }135 };136 Dict.empty = new Dict(null);137 Dict.merge = function (xref, dictArray) {138 var mergedDict = new Dict(xref);139 for (var i = 0, ii = dictArray.length; i < ii; i++) {140 var dict = dictArray[i];141 if (!isDict(dict)) {142 continue;143 }144 for (var keyName in dict._map) {145 if (mergedDict._map[keyName] !== undefined) {146 continue;147 }148 mergedDict._map[keyName] = dict._map[keyName];149 }150 }151 return mergedDict;152 };153 return Dict;154}();155var Ref = function RefClosure() {156 function Ref(num, gen) {157 this.num = num;158 this.gen = gen;159 }160 Ref.prototype = {161 toString: function Ref_toString() {162 var str = this.num + 'R';163 if (this.gen !== 0) {164 str += this.gen;165 }166 return str;167 }168 };169 return Ref;170}();171var RefSet = function RefSetClosure() {172 function RefSet() {173 this.dict = Object.create(null);174 }175 RefSet.prototype = {176 has: function RefSet_has(ref) {177 return ref.toString() in this.dict;178 },179 put: function RefSet_put(ref) {180 this.dict[ref.toString()] = true;181 },182 remove: function RefSet_remove(ref) {183 delete this.dict[ref.toString()];184 }185 };186 return RefSet;187}();188var RefSetCache = function RefSetCacheClosure() {189 function RefSetCache() {190 this.dict = Object.create(null);191 }192 RefSetCache.prototype = {193 get: function RefSetCache_get(ref) {194 return this.dict[ref.toString()];195 },196 has: function RefSetCache_has(ref) {197 return ref.toString() in this.dict;198 },199 put: function RefSetCache_put(ref, obj) {200 this.dict[ref.toString()] = obj;201 },202 putAlias: function RefSetCache_putAlias(ref, aliasRef) {203 this.dict[ref.toString()] = this.get(aliasRef);204 },205 forEach: function RefSetCache_forEach(fn, thisArg) {206 for (var i in this.dict) {207 fn.call(thisArg, this.dict[i]);208 }209 },210 clear: function RefSetCache_clear() {211 this.dict = Object.create(null);212 }213 };214 return RefSetCache;215}();216function isEOF(v) {217 return v === EOF;218}219function isName(v, name) {220 return v instanceof Name && (name === undefined || v.name === name);221}222function isCmd(v, cmd) {223 return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);224}225function isDict(v, type) {226 return v instanceof Dict && (type === undefined || isName(v.get('Type'), type));227}228function isRef(v) {229 return v instanceof Ref;230}231function isRefsEqual(v1, v2) {232 return v1.num === v2.num && v1.gen === v2.gen;233}234function isStream(v) {235 return (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object' && v !== null && v.getBytes !== undefined;236}237exports.EOF = EOF;238exports.Cmd = Cmd;239exports.Dict = Dict;240exports.Name = Name;241exports.Ref = Ref;242exports.RefSet = RefSet;243exports.RefSetCache = RefSetCache;244exports.isEOF = isEOF;245exports.isCmd = isCmd;246exports.isDict = isDict;247exports.isName = isName;248exports.isRef = isRef;249exports.isRefsEqual = isRefsEqual;...
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, resp) {4 console.log(resp);5 console.log(resp.xref);6 console.log(resp.xref.wikipedia.en);7 console.log(resp.xref.wikipedia.en.url);8 console.log(resp.xref.wikipedia.en.title);9 console.log(resp.xref.wikipedia.en.pageid);10 console.log(resp.xref.wikipedia.en.extract);11 console.log(resp.xref.wikipedia.en.wikidata);12 console.log(resp.xref.wikipedia.en.wikidata.url);13 console.log(resp.xref.wikipedia.en.wikidata.title);14 console.log(resp.xref.wikipedia.en.wikidata.pageid);15 console.log(resp.xref.wikipedia.en.wikidata.extract);16});
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.get(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Albert Einstein');8page.get(function
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, resp) {4 console.log(resp.data.imageinfo[0].url);5});6var wptools = require('wptools');7var page = wptools.page('Barack Obama');8page.get(function(err, resp) {9 console.log(resp.data.imageinfo[0].url);10});11var wptools = require('wptools');12var page = wptools.page('Barack Obama');13page.get(function(err, resp) {14 console.log(resp.data.imageinfo[0].url);15});16var wptools = require('wptools');17var page = wptools.page('Barack Obama');18page.get(function(err, resp) {19 console.log(resp.data.imageinfo[0].url);20});21var wptools = require('wptools');22var page = wptools.page('Barack Obama');23page.get(function(err, resp) {24 console.log(resp.data.imageinfo[0].url);25});26var wptools = require('wptools');27var page = wptools.page('Barack Obama');28page.get(function(err, resp) {29 console.log(resp.data.imageinfo[0].url);30});31var wptools = require('wptools');32var page = wptools.page('Barack Obama');33page.get(function(err, resp) {34 console.log(resp.data.imageinfo[0].url);35});36var wptools = require('wptools');37var page = wptools.page('Barack Obama');38page.get(function(err, resp) {39 console.log(resp.data.imageinfo[0].url);40});
Using AI Code Generation
1var wptools = require('wptools');2var wiki = wptools.page('Barack Obama');3wiki.get(function(err, resp) {4 console.log(resp.data);5 console.log(resp.data.xref);6});7var wptools = require('wptools');8var wiki = wptools.page('Barack Obama');9wiki.get(function(err, resp) {10 console.log(resp.data);11 console.log(resp.data.xref);12});13var wptools = require('wptools');14var wiki = wptools.page('Barack Obama');15wiki.get(function(err, resp) {16 console.log(resp.data);17 console.log(resp.data.xref);18});19var wptools = require('wptools');20var wiki = wptools.page('Barack Obama');21wiki.get(function(err, resp) {22 console.log(resp.data);23 console.log(resp.data.xref);24});25var wptools = require('wptools');26var wiki = wptools.page('Barack Obama');27wiki.get(function(err, resp) {28 console.log(resp.data);29 console.log(resp.data.xref);30});31var wptools = require('wptools');32var wiki = wptools.page('Barack Obama');33wiki.get(function(err, resp) {34 console.log(resp.data);35 console.log(resp.data.xref);36});37var wptools = require('wptools');38var wiki = wptools.page('Barack Obama');39wiki.get(function(err, resp) {40 console.log(resp.data);41 console.log(resp
Using AI Code Generation
1var wpt = require('wpt-api');2var wpt = new WebPageTest('www.webpagetest.org', 'A.9e3b7f8b8f2b2c4d4e4c4c4e4e4c4c4e4');3wpt.runTest('www.google.com', {4}, function(err, data) {5 if (err) return console.log(err);6 console.log('Test ID: %s', data.data.testId);7 console.log('Test status: %s', data.data.statusText);8 console.log('Test URL: %s', data.data.userUrl);9 console.log('Test results: %s', data.data.summary);10});11var wpt = require('wpt-api');12var wpt = new WebPageTest('www.webpagetest.org', 'A.9e3b7f8b8f2b2c4d4e4c4c4e4e4c4c4e4');13wpt.runTest('www.google.com', {14}, function(err, data) {15 if (err) return console.log(err);16 console.log('Test ID: %s', data.testId);17 console.log('Test status: %s', data.statusText);18 console.log('Test URL: %s', data.userUrl);19 console.log('Test results: %s', data.summary);20});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!