Best JavaScript code snippet using wpt
pattern.js
Source:pattern.js
...437 colors: figureColors,438 verticesPerRow: verticesPerRow439 };440 }441 function decodeType6Shading(mesh, reader) {442 // A special case of Type 7. The p11, p12, p21, p22 automatically filled443 var coords = mesh.coords;444 var colors = mesh.colors;445 var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33446 var cs = new Int32Array(4); // c00, c30, c03, c33447 while (reader.hasData) {448 var f = reader.readFlag();449 assert(0 <= f && f <= 3, 'Unknown type6 flag');450 var i, ii;451 var pi = coords.length;452 for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {453 coords.push(reader.readCoordinate());454 }455 var ci = colors.length;456 for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {457 colors.push(reader.readComponents());458 }459 var tmp1, tmp2, tmp3, tmp4;460 switch (f) {461 case 0:462 ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;463 ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;464 ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;465 ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;466 cs[2] = ci + 1; cs[3] = ci + 2;467 cs[0] = ci; cs[1] = ci + 3;468 break;469 case 1:470 tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];471 ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;472 ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;473 ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;474 ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;475 tmp1 = cs[2]; tmp2 = cs[3];476 cs[2] = ci + 1; cs[3] = ci;477 cs[0] = tmp1; cs[1] = tmp2;478 break;479 case 2:480 ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;481 ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;482 ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;483 ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;484 cs[2] = cs[3]; cs[3] = ci + 1;485 cs[0] = cs[1]; cs[1] = ci;486 break;487 case 3:488 ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];489 ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;490 ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;491 ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;492 cs[2] = cs[0]; cs[3] = cs[1];493 cs[0] = ci; cs[1] = ci + 1;494 break;495 }496 // set p11, p12, p21, p22497 ps[5] = coords.length;498 coords.push([499 (-4 * coords[ps[0]][0] - coords[ps[15]][0] +500 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -501 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +502 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,503 (-4 * coords[ps[0]][1] - coords[ps[15]][1] +504 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -505 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +506 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9507 ]);508 ps[6] = coords.length;509 coords.push([510 (-4 * coords[ps[3]][0] - coords[ps[12]][0] +511 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -512 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +513 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,514 (-4 * coords[ps[3]][1] - coords[ps[12]][1] +515 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -516 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +517 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9518 ]);519 ps[9] = coords.length;520 coords.push([521 (-4 * coords[ps[12]][0] - coords[ps[3]][0] +522 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -523 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +524 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,525 (-4 * coords[ps[12]][1] - coords[ps[3]][1] +526 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -527 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +528 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9529 ]);530 ps[10] = coords.length;531 coords.push([532 (-4 * coords[ps[15]][0] - coords[ps[0]][0] +533 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -534 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +535 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,536 (-4 * coords[ps[15]][1] - coords[ps[0]][1] +537 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -538 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +539 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9540 ]);541 mesh.figures.push({542 type: 'patch',543 coords: new Int32Array(ps), // making copies of ps and cs544 colors: new Int32Array(cs)545 });546 }547 }548 function decodeType7Shading(mesh, reader) {549 var coords = mesh.coords;550 var colors = mesh.colors;551 var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33552 var cs = new Int32Array(4); // c00, c30, c03, c33553 while (reader.hasData) {554 var f = reader.readFlag();555 assert(0 <= f && f <= 3, 'Unknown type7 flag');556 var i, ii;557 var pi = coords.length;558 for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {559 coords.push(reader.readCoordinate());560 }561 var ci = colors.length;562 for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {563 colors.push(reader.readComponents());564 }565 var tmp1, tmp2, tmp3, tmp4;566 switch (f) {567 case 0:568 ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;569 ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;570 ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;571 ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;572 cs[2] = ci + 1; cs[3] = ci + 2;573 cs[0] = ci; cs[1] = ci + 3;574 break;575 case 1:576 tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];577 ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;578 ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;579 ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;580 ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;581 tmp1 = cs[2]; tmp2 = cs[3];582 cs[2] = ci + 1; cs[3] = ci;583 cs[0] = tmp1; cs[1] = tmp2;584 break;585 case 2:586 ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;587 ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;588 ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;589 ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;590 cs[2] = cs[3]; cs[3] = ci + 1;591 cs[0] = cs[1]; cs[1] = ci;592 break;593 case 3:594 ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];595 ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;596 ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;597 ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;598 cs[2] = cs[0]; cs[3] = cs[1];599 cs[0] = ci; cs[1] = ci + 1;600 break;601 }602 mesh.figures.push({603 type: 'patch',604 coords: new Int32Array(ps), // making copies of ps and cs605 colors: new Int32Array(cs)606 });607 }608 }609 function updateBounds(mesh) {610 var minX = mesh.coords[0][0], minY = mesh.coords[0][1],611 maxX = minX, maxY = minY;612 for (var i = 1, ii = mesh.coords.length; i < ii; i++) {613 var x = mesh.coords[i][0], y = mesh.coords[i][1];614 minX = minX > x ? x : minX;615 minY = minY > y ? y : minY;616 maxX = maxX < x ? x : maxX;617 maxY = maxY < y ? y : maxY;618 }619 mesh.bounds = [minX, minY, maxX, maxY];620 }621 function packData(mesh) {622 var i, ii, j, jj;623 var coords = mesh.coords;624 var coordsPacked = new Float32Array(coords.length * 2);625 for (i = 0, j = 0, ii = coords.length; i < ii; i++) {626 var xy = coords[i];627 coordsPacked[j++] = xy[0];628 coordsPacked[j++] = xy[1];629 }630 mesh.coords = coordsPacked;631 var colors = mesh.colors;632 var colorsPacked = new Uint8Array(colors.length * 3);633 for (i = 0, j = 0, ii = colors.length; i < ii; i++) {634 var c = colors[i];635 colorsPacked[j++] = c[0];636 colorsPacked[j++] = c[1];637 colorsPacked[j++] = c[2];638 }639 mesh.colors = colorsPacked;640 var figures = mesh.figures;641 for (i = 0, ii = figures.length; i < ii; i++) {642 var figure = figures[i], ps = figure.coords, cs = figure.colors;643 for (j = 0, jj = ps.length; j < jj; j++) {644 ps[j] *= 2;645 cs[j] *= 3;646 }647 }648 }649 function Mesh(stream, matrix, xref, res) {650 assert(isStream(stream), 'Mesh data is not a stream');651 var dict = stream.dict;652 this.matrix = matrix;653 this.shadingType = dict.get('ShadingType');654 this.type = 'Pattern';655 this.bbox = dict.get('BBox');656 var cs = dict.get('ColorSpace', 'CS');657 cs = ColorSpace.parse(cs, xref, res);658 this.cs = cs;659 this.background = dict.has('Background') ?660 cs.getRgb(dict.get('Background'), 0) : null;661 var fnObj = dict.get('Function');662 var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;663 this.coords = [];664 this.colors = [];665 this.figures = [];666 var decodeContext = {667 bitsPerCoordinate: dict.get('BitsPerCoordinate'),668 bitsPerComponent: dict.get('BitsPerComponent'),669 bitsPerFlag: dict.get('BitsPerFlag'),670 decode: dict.get('Decode'),671 colorFn: fn,672 colorSpace: cs,673 numComps: fn ? 1 : cs.numComps674 };675 var reader = new MeshStreamReader(stream, decodeContext);676 var patchMesh = false;677 switch (this.shadingType) {678 case PatternType.FREE_FORM_MESH:679 decodeType4Shading(this, reader);680 break;681 case PatternType.LATTICE_FORM_MESH:682 var verticesPerRow = dict.get('VerticesPerRow') | 0;683 assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');684 decodeType5Shading(this, reader, verticesPerRow);685 break;686 case PatternType.COONS_PATCH_MESH:687 decodeType6Shading(this, reader);688 patchMesh = true;689 break;690 case PatternType.TENSOR_PATCH_MESH:691 decodeType7Shading(this, reader);692 patchMesh = true;693 break;694 default:695 error('Unsupported mesh type.');696 break;697 }698 if (patchMesh) {699 // dirty bounds calculation for determining, how dense shall be triangles700 updateBounds(this);701 for (var i = 0, ii = this.figures.length; i < ii; i++) {...
Using AI Code Generation
1var wptools = require('./wptools.js');2var fs = require('fs');3var buffer = fs.readFileSync('test.pdf');4var result = wptools.decodeType6Shading(buffer);5console.log(result);6var wptools = {};7wptools.decodeType6Shading = function(buffer){8 var result = {};9 result.type = "Type6Shading";10 result.function = {};11 result.function.type = "Type2Function";12 result.function.c0 = buffer.readFloatBE(0);13 result.function.c1 = buffer.readFloatBE(4);14 result.function.n = buffer.readFloatBE(8);15 result.coords = [];16 var coords = {};17 coords.x0 = buffer.readFloatBE(12);18 coords.y0 = buffer.readFloatBE(16);19 coords.r0 = buffer.readFloatBE(20);20 coords.x1 = buffer.readFloatBE(24);21 coords.y1 = buffer.readFloatBE(28);22 coords.r1 = buffer.readFloatBE(32);23 result.coords = coords;24 return result;25};26module.exports = wptools;27var shading = new Shading();28var shadingDict = shading.getShadingDict();29console.log(shadingDict);30{ Type: 'Shading',31 Extend: [ false, false ] }32var shading = new Shading();
Using AI Code Generation
1var wptools = require('./wptools.js');2var fs = require('fs');3var input = fs.readFileSync('test.pdf');4var output = wptools.decodeType6Shading(input);5console.log(output);6var Type6Shading = function (data) {7 this.data = data;8 this.read = function (offset) {9 var result = {};10 result.ColorSpace = this.data.readUInt16LE(offset);11 offset += 2;12 result.Function = this.data.readUInt16LE(offset);13 offset += 2;14 result.X0 = this.data.readUInt32LE(offset);15 offset += 4;16 result.Y0 = this.data.readUInt32LE(offset);17 offset += 4;18 result.X1 = this.data.readUInt32LE(offset);19 offset += 4;20 result.Y1 = this.data.readUInt32LE(offset);21 offset += 4;22 result.T0 = this.data.readUInt32LE(offset);23 offset += 4;24 result.T1 = this.data.readUInt32LE(offset);25 offset += 4;26 result.Matrix = [];27 for (var i = 0; i < 6; i++) {28 result.Matrix.push(this.data.readUInt32LE(offset));29 offset += 4;30 }31 result.BitsPerCoordinate = this.data.readUInt8(offset);32 offset += 1;33 result.BitsPerComponent = this.data.readUInt8(offset);34 offset += 1;35 result.BitsPerFlag = this.data.readUInt8(offset);36 offset += 1;37 result.Decode = [];38 for (var i = 0; i < 8; i++) {39 result.Decode.push(this.data.readUInt32LE(offset));40 offset += 4;41 }42 result.Colors = [];43 var colorCount = this.data.readUInt32LE(offset);44 offset += 4;45 for (var i = 0; i < colorCount; i++) {46 result.Colors.push(this.data.readUInt16LE(offset));47 offset += 2;48 }49 result.Length = this.data.readUInt32LE(offset);50 offset += 4;51 result.Data = this.data.slice(offset, offset + result.Length);52 return result;53 }54};
Using AI Code Generation
1var wptools = require('./wptools.js');2var fs = require('fs');3var pdfFile = fs.readFileSync('test.pdf');4var pdf = wptools.parsePDF(pdfFile);5var page = pdf.getPage(1);6var shading = page.getShading(1);7console.log(wptools.decodeType6Shading(shading));8console.log(wptools.decodeType6Shading(shading)[0]);9console.log(wptools.decodeType6Shading(shading)[1]);10console.log(wptools.decodeType6Shading(shading)[2]);11console.log(wptools.decodeType6Shading(shading)[3]);12console.log(wptools.decodeType6Shading(shading)[4]);13console.log(wptools.decodeType6Shading(shading)[5]);14console.log(wptools.decodeType6Shading(shading)[6]);15console.log(wptools.decodeType6Shading(shading)[7]);16console.log(wptools.decodeType6Shading(shading)[8]);17console.log(wptools.decodeType6Shading(shading)[9]);18console.log(wptools.decodeType6Shading(shading)[10]);19console.log(wptools.decodeType6Shading(shading)[11]);20console.log(wptools.decodeType6Shading(shading)[12]);21console.log(wptools.decodeType6Shading(shading)[13]);22console.log(wptools.decodeType6Shading(shading)[14]);23console.log(wptools.decodeType6Shading(shading)[15]);24console.log(wptools.decodeType6Shading(shading)[16]);25console.log(wptools.decodeType6Shading(shading)[17]);26console.log(wptools.decodeType6Shading(shading)[18]);27console.log(wptools.decodeType6Shading(shading)[19]);28console.log(wptools.decodeType6Shading(shading)[20]);29console.log(wptools.decodeType6Shading(shading)[21]);30console.log(wptools.decodeType6Shading(shading)[22]);31console.log(wptools.decodeType6Shading(shading)[23]);32console.log(wptools.decodeType6Shading(shading)[24]);33console.log(wptools.decodeType6Shading(shading)[25]);34console.log(wptools.decodeType6Shading(shading)[26]);35console.log(wptools.decodeType6Shading(shading)[27]);36console.log(wptools
Using AI Code Generation
1var fs = require('fs');2var wptools = require('./wptools.js');3var file = fs.readFileSync('shadingtype6.txt');4var shading = wptools.decodeType6Shading(file);5console.log(shading);6var fs = require(‘fs’);7var wptools = require(‘./wptools.js’);8var file = fs.readFileSync(‘shadingtype6.txt’);9var shading = wptools.decodeType6Shading(file);10console.log(shading);11var fs = require(‘fs’);12var wptools = require(‘./wptools.js’);13var file = fs.readFileSync(‘shadingtype6.txt’);14var shading = wptools.decodeType6Shading(file);15console.log(shading);16var fs = require(‘fs’);17var wptools = require(‘./wptools.js’);18var file = fs.readFileSync(‘shadingtype6.txt’);19var shading = wptools.decodeType6Shading(file);20console.log(shading);
Using AI Code Generation
1var wptextstream = require('wptextstream');2var fs = require('fs');3var stream = fs.createReadStream('test.pdf');4var wpts = new wptextstream();5wpts.on('decodeType6Shading', function (data) {6 console.log(data);7});8stream.pipe(wpts);9var wptextstream = require('wptextstream');10var fs = require('fs');11var stream = fs.createReadStream('test.pdf');12var wpts = new wptextstream();13wpts.on('decodeType7Shading', function (data) {14 console.log(data);15});16stream.pipe(wpts);17var wptextstream = require('wptextstream');18var fs = require('fs');19var stream = fs.createReadStream('test.pdf');
Using AI Code Generation
1var pdfDoc = new PDFDoc("input.pdf");2var page = pdfDoc.getPage(1);3var contents = page.getContents();4var wptextstream = contents.getTextStream();5var stream = wptextstream.getStream();6var resources = contents.getResources();7var xobject = resources.getXObject();8var pattern = resources.getPattern();9var decodeType6Shading = wptextstream.decodeType6Shading(stream, xobject, pattern);10console.log(decodeType6Shading);11var pdfDoc = new PDFDoc("input.pdf");12var page = pdfDoc.getPage(1);13var contents = page.getContents();14var wptextstream = contents.getTextStream();15var stream = wptextstream.getStream();16var resources = contents.getResources();17var xobject = resources.getXObject();18var pattern = resources.getPattern();19var decodeType4Shading = wptextstream.decodeType4Shading(stream, xobject, pattern);20console.log(decodeType4Shading);21var pdfDoc = new PDFDoc("input.pdf");22var page = pdfDoc.getPage(1);23var contents = page.getContents();24var wptextstream = contents.getTextStream();25var stream = wptextstream.getStream();26var resources = contents.getResources();27var xobject = resources.getXObject();28var pattern = resources.getPattern();29var decodeType2Shading = wptextstream.decodeType2Shading(stream, xobject, pattern);30console.log(decodeType2Shading);31var pdfDoc = new PDFDoc("input.pdf");32var page = pdfDoc.getPage(1);33var contents = page.getContents();34var wptextstream = contents.getTextStream();35var stream = wptextstream.getStream();36var resources = contents.getResources();37var xobject = resources.getXObject();38var pattern = resources.getPattern();39var decodeType3Shading = wptextstream.decodeType3Shading(stream, xobject, pattern);40console.log(decodeType3Shading);
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!!