Best JavaScript code snippet using wpt
CFFTop.js
Source:CFFTop.js
1import r from 'restructure';2import { resolveLength } from 'restructure/src/utils';3import CFFDict from './CFFDict';4import CFFIndex from './CFFIndex';5import CFFPointer from './CFFPointer';6import CFFPrivateDict from './CFFPrivateDict';7import StandardStrings from './CFFStandardStrings';8import { StandardEncoding, ExpertEncoding } from './CFFEncodings';9import { ISOAdobeCharset, ExpertCharset, ExpertSubsetCharset } from './CFFCharsets';10import { ItemVariationStore } from '../tables/variations';11// Checks if an operand is an index of a predefined value,12// otherwise delegates to the provided type.13class PredefinedOp {14 constructor(predefinedOps, type) {15 this.predefinedOps = predefinedOps;16 this.type = type;17 }18 decode(stream, parent, operands) {19 if (this.predefinedOps[operands[0]]) {20 return this.predefinedOps[operands[0]];21 }22 return this.type.decode(stream, parent, operands);23 }24 size(value, ctx) {25 return this.type.size(value, ctx);26 }27 encode(stream, value, ctx) {28 let index = this.predefinedOps.indexOf(value);29 if (index !== -1) {30 return index;31 }32 return this.type.encode(stream, value, ctx);33 }34}35class CFFEncodingVersion extends r.Number {36 constructor() {37 super('UInt8');38 }39 decode(stream) {40 return r.uint8.decode(stream) & 0x7f;41 }42}43let Range1 = new r.Struct({44 first: r.uint16,45 nLeft: r.uint846});47let Range2 = new r.Struct({48 first: r.uint16,49 nLeft: r.uint1650});51let CFFCustomEncoding = new r.VersionedStruct(new CFFEncodingVersion(), {52 0: {53 nCodes: r.uint8,54 codes: new r.Array(r.uint8, 'nCodes')55 },56 1: {57 nRanges: r.uint8,58 ranges: new r.Array(Range1, 'nRanges')59 }60 // TODO: supplement?61});62let CFFEncoding = new PredefinedOp([ StandardEncoding, ExpertEncoding ], new CFFPointer(CFFCustomEncoding, { lazy: true }));63// Decodes an array of ranges until the total64// length is equal to the provided length.65class RangeArray extends r.Array {66 decode(stream, parent) {67 let length = resolveLength(this.length, stream, parent);68 let count = 0;69 let res = [];70 while (count < length) {71 let range = this.type.decode(stream, parent);72 range.offset = count;73 count += range.nLeft + 1;74 res.push(range);75 }76 return res;77 }78}79let CFFCustomCharset = new r.VersionedStruct(r.uint8, {80 0: {81 glyphs: new r.Array(r.uint16, t => t.parent.CharStrings.length - 1)82 },83 1: {84 ranges: new RangeArray(Range1, t => t.parent.CharStrings.length - 1)85 },86 2: {87 ranges: new RangeArray(Range2, t => t.parent.CharStrings.length - 1)88 }89});90let CFFCharset = new PredefinedOp([ ISOAdobeCharset, ExpertCharset, ExpertSubsetCharset ], new CFFPointer(CFFCustomCharset, {lazy: true}));91let FDRange3 = new r.Struct({92 first: r.uint16,93 fd: r.uint894});95let FDRange4 = new r.Struct({96 first: r.uint32,97 fd: r.uint1698});99let FDSelect = new r.VersionedStruct(r.uint8, {100 0: {101 fds: new r.Array(r.uint8, t => t.parent.CharStrings.length)102 },103 3: {104 nRanges: r.uint16,105 ranges: new r.Array(FDRange3, 'nRanges'),106 sentinel: r.uint16107 },108 4: {109 nRanges: r.uint32,110 ranges: new r.Array(FDRange4, 'nRanges'),111 sentinel: r.uint32112 }113});114let ptr = new CFFPointer(CFFPrivateDict);115class CFFPrivateOp {116 decode(stream, parent, operands) {117 parent.length = operands[0];118 return ptr.decode(stream, parent, [operands[1]]);119 }120 size(dict, ctx) {121 return [CFFPrivateDict.size(dict, ctx, false), ptr.size(dict, ctx)[0]];122 }123 encode(stream, dict, ctx) {124 return [CFFPrivateDict.size(dict, ctx, false), ptr.encode(stream, dict, ctx)[0]];125 }126}127let FontDict = new CFFDict([128 // key name type(s) default129 [18, 'Private', new CFFPrivateOp, null],130 [[12, 38], 'FontName', 'sid', null]131]);132let CFFTopDict = new CFFDict([133 // key name type(s) default134 [[12, 30], 'ROS', ['sid', 'sid', 'number'], null],135 [0, 'version', 'sid', null],136 [1, 'Notice', 'sid', null],137 [[12, 0], 'Copyright', 'sid', null],138 [2, 'FullName', 'sid', null],139 [3, 'FamilyName', 'sid', null],140 [4, 'Weight', 'sid', null],141 [[12, 1], 'isFixedPitch', 'boolean', false],142 [[12, 2], 'ItalicAngle', 'number', 0],143 [[12, 3], 'UnderlinePosition', 'number', -100],144 [[12, 4], 'UnderlineThickness', 'number', 50],145 [[12, 5], 'PaintType', 'number', 0],146 [[12, 6], 'CharstringType', 'number', 2],147 [[12, 7], 'FontMatrix', 'array', [0.001, 0, 0, 0.001, 0, 0]],148 [13, 'UniqueID', 'number', null],149 [5, 'FontBBox', 'array', [0, 0, 0, 0]],150 [[12, 8], 'StrokeWidth', 'number', 0],151 [14, 'XUID', 'array', null],152 [15, 'charset', CFFCharset, ISOAdobeCharset],153 [16, 'Encoding', CFFEncoding, StandardEncoding],154 [17, 'CharStrings', new CFFPointer(new CFFIndex), null],155 [18, 'Private', new CFFPrivateOp, null],156 [[12, 20], 'SyntheticBase', 'number', null],157 [[12, 21], 'PostScript', 'sid', null],158 [[12, 22], 'BaseFontName', 'sid', null],159 [[12, 23], 'BaseFontBlend', 'delta', null],160 // CID font specific161 [[12, 31], 'CIDFontVersion', 'number', 0],162 [[12, 32], 'CIDFontRevision', 'number', 0],163 [[12, 33], 'CIDFontType', 'number', 0],164 [[12, 34], 'CIDCount', 'number', 8720],165 [[12, 35], 'UIDBase', 'number', null],166 [[12, 37], 'FDSelect', new CFFPointer(FDSelect), null],167 [[12, 36], 'FDArray', new CFFPointer(new CFFIndex(FontDict)), null],168 [[12, 38], 'FontName', 'sid', null]169]);170let VariationStore = new r.Struct({171 length: r.uint16,172 itemVariationStore: ItemVariationStore173})174let CFF2TopDict = new CFFDict([175 [[12, 7], 'FontMatrix', 'array', [0.001, 0, 0, 0.001, 0, 0]],176 [17, 'CharStrings', new CFFPointer(new CFFIndex), null],177 [[12, 37], 'FDSelect', new CFFPointer(FDSelect), null],178 [[12, 36], 'FDArray', new CFFPointer(new CFFIndex(FontDict)), null],179 [24, 'vstore', new CFFPointer(VariationStore), null],180 [25, 'maxstack', 'number', 193]181]);182let CFFTop = new r.VersionedStruct(r.fixed16, {183 1: {184 hdrSize: r.uint8,185 offSize: r.uint8,186 nameIndex: new CFFIndex(new r.String('length')),187 topDictIndex: new CFFIndex(CFFTopDict),188 stringIndex: new CFFIndex(new r.String('length')),189 globalSubrIndex: new CFFIndex190 },191 2: {192 hdrSize: r.uint8,193 length: r.uint16,194 topDict: CFF2TopDict,195 globalSubrIndex: new CFFIndex196 }197});...
Using AI Code Generation
1var CFFPrivateDict = function (data) {2 this.rawDict = data;3 this.defaultWidthX = 0;4 this.nominalWidthX = 0;5 this.subrs = [];6 this.subrsBias = 0;7 this.subrsIndex = null;8 this.privateDict = new Dict(data);9 this.privateDict.getByName = function getByName(name) {10 return this.values[this.names.indexOf(name)];11 };12 this.privateDict.has = function has(name) {13 return this.names.indexOf(name) >= 0;14 };15 this.privateDict.setByName = function setByName(name, value) {16 var index = this.names.indexOf(name);17 if (index >= 0) {18 this.values[index] = value;19 } else {20 this.names.push(name);21 this.values.push(value);22 }23 };24 this.privateDict.getByName('defaultWidthX', this.defaultWidthX);25 this.privateDict.getByName('nominalWidthX', this.nominalWidthX);26 var subrsIndex = this.privateDict.getByName('Subrs');27 if (subrsIndex) {28 this.subrsIndex = subrsIndex;29 this.subrsBias = calculateCFFIndexBias(subrsIndex);30 }31};32CFFPrivateDict.prototype = {33 get defaultWidthX() {34 return this.privateDict.getByName('defaultWidthX');35 },36 set defaultWidthX(value) {37 this.privateDict.setByName('defaultWidthX', value);38 },39 get nominalWidthX() {40 return this.privateDict.getByName('nominalWidthX');41 },42 set nominalWidthX(value) {43 this.privateDict.setByName('nominalWidthX', value);44 },45 getSubr: function CFFPrivateDict_getSubr(index) {46 return this.subrs[index];47 },48 setSubr: function CFFPrivateDict_setSubr(index, subr) {49 this.subrs[index] = subr;50 },51 getSubrs: function CFFPrivateDict_getSubrs() {52 return this.subrs;53 },54 getSubrsBias: function CFFPrivateDict_getSubrsBias() {55 return this.subrsBias;56 },57 getSubrsIndex: function CFFPrivateDict_getSubrsIndex() {58 return this.subrsIndex;59 },
Using AI Code Generation
1var testharness = require('./testharness');2var testharnessreport = require('./testharnessreport');3var testharnessreport = require('./testharnessreport');4var CFFPrivateDict = require('./cffprivatedict');5var path = require('path');6var testdir = path.resolve(__dirname, 'test');7var testfile = path.resolve(testdir, 'test.js');8var testharness = require('./testharness');9var testharnessreport = require('./testharnessreport');10var testharness = require('./testharness');11var testharnessreport = require('./testharnessreport');12var testharness = require('./testharness');13var testharnessreport = require('./testharnessreport');14var testharness = require('./testharness');15var testharnessreport = require('./testharnessreport');16var testharness = require('./testharness');17var testharnessreport = require('./testharnessreport');18var testharness = require('./testharness');19var testharnessreport = require('./testharnessreport');20var testharness = require('./testharness');21var testharnessreport = require('./testharnessreport');22var testharness = require('./testharness');23var testharnessreport = require('./testharnessreport');24var testharness = require('./testharness');25var testharnessreport = require('./testharnessreport');26var testharness = require('./testharness');27var testharnessreport = require('./testharnessreport');28var testharness = require('./testharness');29var testharnessreport = require('./testharnessreport');30var testharnessreport = require('./testharnessreport');31var CFFPrivateDict = require('./cffprivatedict');32var path = require('path');33var testdir = path.resolve(__dirname, 'test');34var testfile = path.resolve(testdir, 'test.js');35var testharness = require('./testharness');36var testharnessreport = require('./testharnessreport');37var testharness = require('./testharness');38var testharnessreport = require('./testharnessreport');39var testharness = require('./testharness');40var testharnessreport = require('./testharnessreport');
Using AI Code Generation
1require('./testharness.js');2require('./testharnessreport.js');3test(function() {4 assert_true(true, "This is a test");5}, "This is a test description");6done();
Using AI Code Generation
1var CFFPrivateDict = require('./cff-private-dict.js').CFFPrivateDict;2var fs = require('fs');3var path = require('path');4var pdfjs = require('./pdfjs.js');5var pdfjsLib = require('pdfjs-dist');6var pdfjsWorker = require('pdfjs-dist/build/pdf.worker.entry');7var PDFJS = pdfjsLib.PDFJS;8PDFJS.workerSrc = pdfjsWorker;9var pdfPath = process.argv[2] || './test.pdf';10var jsonPath = process.argv[3] || './test.json';11var pdfFile = fs.readFileSync(pdfPath);12var pdfData = new Uint8Array(pdfFile);13var pdfName = path.basename(pdfPath, '.pdf');14var jsonFile = fs.readFileSync(jsonPath);15var jsonData = JSON.parse(jsonFile);16var pdfDoc = null;17var page = null;18var cffPrivateDict = null;19var cffPrivateDict2 = null;20var cffPrivateDict3 = null;21var getPDFDoc = function() {22 return PDFJS.getDocument(pdfData).promise.then(function(pdf) {23 pdfDoc = pdf;24 return pdfDoc;25 });26};27var getPage = function() {28 return pdfDoc.getPage(1).then(function(pg) {29 page = pg;30 return page;31 });32};33var getFont = function() {34 var font = null;35 page.getOperatorList().then(function(opList) {36 var opListData = opList.argsArray;37 for (var i = 0; i < opListData.length; i++) {38 if (opListData[i][0] === 'Tf') {39 font = opListData[i][1];40 break;41 }42 }43 return font;44 });45};46var getFontData = function(font) {47 return pdfDoc.embedFont(font).then(function(fontData) {48 return fontData;49 });50};51var getFontDict = function(fontData) {52 return pdfDoc.getMetadata().then(function(metadata) {53 var fontDict = null;54 var fontName = fontData.loadedName;55 var fontDataName = fontData.loadedName;56 var metadataName = metadata.info['FontName'];
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!!