Best JavaScript code snippet using wpt
cff_parser.js
Source:cff_parser.js
...1043 };1044 return CFFFDSelect;1045}();1046var CFFOffsetTracker = function CFFOffsetTrackerClosure() {1047 function CFFOffsetTracker() {1048 this.offsets = Object.create(null);1049 }1050 CFFOffsetTracker.prototype = {1051 isTracking: function CFFOffsetTracker_isTracking(key) {1052 return key in this.offsets;1053 },1054 track: function CFFOffsetTracker_track(key, location) {1055 if (key in this.offsets) {1056 throw new _util.FormatError('Already tracking location of ' + key);1057 }1058 this.offsets[key] = location;1059 },1060 offset: function CFFOffsetTracker_offset(value) {1061 for (var key in this.offsets) {1062 this.offsets[key] += value;1063 }1064 },1065 setEntryLocation: function CFFOffsetTracker_setEntryLocation(key, values, output) {1066 if (!(key in this.offsets)) {1067 throw new _util.FormatError('Not tracking location of ' + key);1068 }1069 var data = output.data;1070 var dataOffset = this.offsets[key];1071 var size = 5;1072 for (var i = 0, ii = values.length; i < ii; ++i) {1073 var offset0 = i * size + dataOffset;1074 var offset1 = offset0 + 1;1075 var offset2 = offset0 + 2;1076 var offset3 = offset0 + 3;1077 var offset4 = offset0 + 4;1078 if (data[offset0] !== 0x1d || data[offset1] !== 0 || data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {1079 throw new _util.FormatError('writing to an offset that is not empty');1080 }1081 var value = values[i];1082 data[offset0] = 0x1d;1083 data[offset1] = value >> 24 & 0xFF;1084 data[offset2] = value >> 16 & 0xFF;1085 data[offset3] = value >> 8 & 0xFF;1086 data[offset4] = value & 0xFF;1087 }1088 }1089 };1090 return CFFOffsetTracker;1091}();1092var CFFCompiler = function CFFCompilerClosure() {1093 function CFFCompiler(cff) {1094 this.cff = cff;1095 }1096 CFFCompiler.prototype = {1097 compile: function CFFCompiler_compile() {1098 var cff = this.cff;1099 var output = {1100 data: [],1101 length: 0,1102 add: function CFFCompiler_add(data) {1103 this.data = this.data.concat(data);1104 this.length = this.data.length;1105 }1106 };1107 var header = this.compileHeader(cff.header);1108 output.add(header);1109 var nameIndex = this.compileNameIndex(cff.names);1110 output.add(nameIndex);1111 if (cff.isCIDFont) {1112 if (cff.topDict.hasName('FontMatrix')) {1113 var base = cff.topDict.getByName('FontMatrix');1114 cff.topDict.removeByName('FontMatrix');1115 for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {1116 var subDict = cff.fdArray[i];1117 var matrix = base.slice(0);1118 if (subDict.hasName('FontMatrix')) {1119 matrix = _util.Util.transform(matrix, subDict.getByName('FontMatrix'));1120 }1121 subDict.setByName('FontMatrix', matrix);1122 }1123 }1124 }1125 var compiled = this.compileTopDicts([cff.topDict], output.length, cff.isCIDFont);1126 output.add(compiled.output);1127 var topDictTracker = compiled.trackers[0];1128 var stringIndex = this.compileStringIndex(cff.strings.strings);1129 output.add(stringIndex);1130 var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);1131 output.add(globalSubrIndex);1132 if (cff.encoding && cff.topDict.hasName('Encoding')) {1133 if (cff.encoding.predefined) {1134 topDictTracker.setEntryLocation('Encoding', [cff.encoding.format], output);1135 } else {1136 var encoding = this.compileEncoding(cff.encoding);1137 topDictTracker.setEntryLocation('Encoding', [output.length], output);1138 output.add(encoding);1139 }1140 }1141 if (cff.charset && cff.topDict.hasName('charset')) {1142 if (cff.charset.predefined) {1143 topDictTracker.setEntryLocation('charset', [cff.charset.format], output);1144 } else {1145 var charset = this.compileCharset(cff.charset);1146 topDictTracker.setEntryLocation('charset', [output.length], output);1147 output.add(charset);1148 }1149 }1150 var charStrings = this.compileCharStrings(cff.charStrings);1151 topDictTracker.setEntryLocation('CharStrings', [output.length], output);1152 output.add(charStrings);1153 if (cff.isCIDFont) {1154 topDictTracker.setEntryLocation('FDSelect', [output.length], output);1155 var fdSelect = this.compileFDSelect(cff.fdSelect.raw);1156 output.add(fdSelect);1157 compiled = this.compileTopDicts(cff.fdArray, output.length, true);1158 topDictTracker.setEntryLocation('FDArray', [output.length], output);1159 output.add(compiled.output);1160 var fontDictTrackers = compiled.trackers;1161 this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);1162 }1163 this.compilePrivateDicts([cff.topDict], [topDictTracker], output);1164 output.add([0]);1165 return output.data;1166 },1167 encodeNumber: function CFFCompiler_encodeNumber(value) {1168 if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) {1169 return this.encodeInteger(value);1170 }1171 return this.encodeFloat(value);1172 },1173 encodeFloat: function CFFCompiler_encodeFloat(num) {1174 var value = num.toString();1175 var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);1176 if (m) {1177 var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));1178 value = (Math.round(num * epsilon) / epsilon).toString();1179 }1180 var nibbles = '';1181 var i, ii;1182 for (i = 0, ii = value.length; i < ii; ++i) {1183 var a = value[i];1184 if (a === 'e') {1185 nibbles += value[++i] === '-' ? 'c' : 'b';1186 } else if (a === '.') {1187 nibbles += 'a';1188 } else if (a === '-') {1189 nibbles += 'e';1190 } else {1191 nibbles += a;1192 }1193 }1194 nibbles += nibbles.length & 1 ? 'f' : 'ff';1195 var out = [30];1196 for (i = 0, ii = nibbles.length; i < ii; i += 2) {1197 out.push(parseInt(nibbles.substr(i, 2), 16));1198 }1199 return out;1200 },1201 encodeInteger: function CFFCompiler_encodeInteger(value) {1202 var code;1203 if (value >= -107 && value <= 107) {1204 code = [value + 139];1205 } else if (value >= 108 && value <= 1131) {1206 value = value - 108;1207 code = [(value >> 8) + 247, value & 0xFF];1208 } else if (value >= -1131 && value <= -108) {1209 value = -value - 108;1210 code = [(value >> 8) + 251, value & 0xFF];1211 } else if (value >= -32768 && value <= 32767) {1212 code = [0x1c, value >> 8 & 0xFF, value & 0xFF];1213 } else {1214 code = [0x1d, value >> 24 & 0xFF, value >> 16 & 0xFF, value >> 8 & 0xFF, value & 0xFF];1215 }1216 return code;1217 },1218 compileHeader: function CFFCompiler_compileHeader(header) {1219 return [header.major, header.minor, header.hdrSize, header.offSize];1220 },1221 compileNameIndex: function CFFCompiler_compileNameIndex(names) {1222 var nameIndex = new CFFIndex();1223 for (var i = 0, ii = names.length; i < ii; ++i) {1224 var name = names[i];1225 var length = Math.min(name.length, 127);1226 var sanitizedName = new Array(length);1227 for (var j = 0; j < length; j++) {1228 var char = name[j];1229 if (char < '!' || char > '~' || char === '[' || char === ']' || char === '(' || char === ')' || char === '{' || char === '}' || char === '<' || char === '>' || char === '/' || char === '%') {1230 char = '_';1231 }1232 sanitizedName[j] = char;1233 }1234 sanitizedName = sanitizedName.join('');1235 if (sanitizedName === '') {1236 sanitizedName = 'Bad_Font_Name';1237 }1238 nameIndex.add((0, _util.stringToBytes)(sanitizedName));1239 }1240 return this.compileIndex(nameIndex);1241 },1242 compileTopDicts: function CFFCompiler_compileTopDicts(dicts, length, removeCidKeys) {1243 var fontDictTrackers = [];1244 var fdArrayIndex = new CFFIndex();1245 for (var i = 0, ii = dicts.length; i < ii; ++i) {1246 var fontDict = dicts[i];1247 if (removeCidKeys) {1248 fontDict.removeByName('CIDFontVersion');1249 fontDict.removeByName('CIDFontRevision');1250 fontDict.removeByName('CIDFontType');1251 fontDict.removeByName('CIDCount');1252 fontDict.removeByName('UIDBase');1253 }1254 var fontDictTracker = new CFFOffsetTracker();1255 var fontDictData = this.compileDict(fontDict, fontDictTracker);1256 fontDictTrackers.push(fontDictTracker);1257 fdArrayIndex.add(fontDictData);1258 fontDictTracker.offset(length);1259 }1260 fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);1261 return {1262 trackers: fontDictTrackers,1263 output: fdArrayIndex1264 };1265 },1266 compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts, trackers, output) {1267 for (var i = 0, ii = dicts.length; i < ii; ++i) {1268 var fontDict = dicts[i];1269 var privateDict = fontDict.privateDict;1270 if (!privateDict || !fontDict.hasName('Private')) {1271 throw new _util.FormatError('There must be a private dictionary.');1272 }1273 var privateDictTracker = new CFFOffsetTracker();1274 var privateDictData = this.compileDict(privateDict, privateDictTracker);1275 var outputLength = output.length;1276 privateDictTracker.offset(outputLength);1277 if (!privateDictData.length) {1278 outputLength = 0;1279 }1280 trackers[i].setEntryLocation('Private', [privateDictData.length, outputLength], output);1281 output.add(privateDictData);1282 if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {1283 var subrs = this.compileIndex(privateDict.subrsIndex);1284 privateDictTracker.setEntryLocation('Subrs', [privateDictData.length], output);1285 output.add(subrs);1286 }1287 }...
Using AI Code Generation
1var wptools = require('wptools');2var cff = new wptools.CFFOffsetTracker();3var fs = require('fs');4var input = fs.readFileSync('./input.txt', 'utf8');5var output = cff.track(input);6fs.writeFileSync('./output.txt', output);
Using AI Code Generation
1var wptextcf = require('wptextcf');2var offsetTracker = new wptextcf.CFFOffsetTracker();3var text = "This is a test";4offsetTracker.addText(text);5var offset = offsetTracker.getOffset();6console.log(offset);7var wptextcf = require('wptextcf');8var offsetTracker = new wptextcf.CFFOffsetTracker();9var text = "This is a test";10offsetTracker.addText(text);11var offset = offsetTracker.getOffset();12console.log(offset);13var wptextcf = require('wptextcf');14var offsetTracker = new wptextcf.CFFOffsetTracker();15var text = "This is a test";16offsetTracker.addText(text);17var offset = offsetTracker.getOffset();18console.log(offset);19var wptextcf = require('wptextcf');20var offsetTracker = new wptextcf.CFFOffsetTracker();21var text = "This is a test";22offsetTracker.addText(text);23var offset = offsetTracker.getOffset();24console.log(offset);25var wptextcf = require('wptextcf');
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools();3wp.page('Albert Einstein').then(function(page){4 console.log(page);5});6var wptools = require('wptools');7var wp = new wptools();8wp.page('Albert Einstein').then(function(page){9 console.log(page);10});11var wptools = require('wptools');12var wp = new wptools();13wp.page('Albert Einstein').then(function(page){14 console.log(page);15});16var wptools = require('wptools');17var wp = new wptools();18wp.page('Albert Einstein').then(function(page){19 console.log(page);20});21var wptools = require('wptools');22var wp = new wptools();23wp.page('Albert Einstein').then(function(page){24 console.log(page);25});26var wptools = require('wptools');27var wp = new wptools();28wp.page('Albert Einstein').then(function(page){29 console.log(page);30});31var wptools = require('wptools');32var wp = new wptools();33wp.page('Albert Einstein').then(function(page){34 console.log(page);35});36var wptools = require('wptools');37var wp = new wptools();38wp.page('Albert Einstein').then(function(page){39 console.log(page);40});41var wptools = require('wptools');42var wp = new wptools();43wp.page('Albert Einstein').then(function(page){44 console.log(page);45});
Using AI Code Generation
1var tracker = new CFFOffsetTracker( 'This is a test.' );2var text = 'This is a test.';3console.log( tracker.getOffset( text, 1 ) );4console.log( tracker.getOffset( text, 2 ) );5console.log( tracker.getOffset( text, 3 ) );6console.log( tracker.getOffset( text, 4 ) );7console.log( tracker.getOffset( text, 5 ) );8console.log( tracker.getOffset( text, 6 ) );9console.log( tracker.getOffset( text, 7 ) );10console.log( tracker.getOffset( text, 8 ) );11console.log( tracker.getOffset( text, 9 ) );12console.log( tracker.getOffset( text, 10 ) );13console.log( tracker.getOffset( text, 11 ) );14console.log( tracker.getOffset( text, 12 ) );15console.log( tracker.getOffset( text, 13 ) );16console.log( tracker.getOffset( text, 14 ) );17var tracker = new CFFOffsetTracker( 'This is a test.' );18var text = 'This is a test.';19console.log( tracker.getOffset( text, 1 ) );20console.log( tracker.getOffset( text, 2 ) );21console.log( tracker.getOffset( text, 3 ) );22console.log( tracker.getOffset( text, 4 ) );23console.log( tracker.getOffset( text, 5 ) );24console.log( tracker.getOffset( text, 6 ) );25console.log( tracker.getOffset( text, 7 ) );26console.log( tracker.getOffset( text, 8 ) );27console.log( tracker.getOffset( text, 9 ) );28console.log( tracker.getOffset( text, 10 ) );29console.log( tracker.getOffset( text, 11 ) );30console.log( tracker.getOffset( text, 12 ) );31console.log( tracker.getOffset( text, 13 ) );32console.log( tracker.getOffset( text, 14 ) );
Using AI Code Generation
1var wptextlayout = require('wptextlayout');2var text = "This is a test string";3var font = "Arial";4var fontSize = 12;5var width = 100;6var height = 100;7var layout = new wptextlayout.CFFOffsetTracker(text, font, fontSize, width, height);8var offsets = layout.getOffsets();9console.log(offsets);10 function test() {11 var text = "This is a test string";12 var font = "Arial";13 var fontSize = 12;14 var width = 100;15 var height = 100;16 var layout = new wptextlayout.CFFOffsetTracker(text, font, fontSize, width, height);17 var offsets = layout.getOffsets();18 console.log(offsets);19 }20<body onload="test()">
Using AI Code Generation
1var CFFOffsetTracker = require('./wptdriver').CFFOffsetTracker;2var fs = require('fs');3var font = fs.readFileSync('testfont.ttf');4var cffOffset = CFFOffsetTracker.GetCFFOffset(font);5console.log(cffOffset);6var CFFOffsetTracker = function() {};7CFFOffsetTracker.GetCFFOffset = function(font) {8 var offset = 0;9 var numTables = font.readUInt16BE(4);10 var tableRecordSize = 16;11 var tableRecordStart = 12;12 for (var i = 0; i < numTables; i++) {13 var tableRecordOffset = tableRecordStart + (i * tableRecordSize);14 if (font.toString('ascii', tableRecordOffset, tableRecordOffset + 4) === 'CFF ') {15 offset = font.readUInt32BE(tableRecordOffset + 8);16 break;17 }18 }19 return offset;20};21module.exports.CFFOffsetTracker = CFFOffsetTracker;
Using AI Code Generation
1var CFFOffsetTracker = require( './cffoffsettracker' );2var tracker = new CFFOffsetTracker( 'I\'m a string with “quotes” and «guillemets».' );3var CFFOffsetTracker = require( './cffoffsettracker' );4var tracker = new CFFOffsetTracker( 'I\'m a string with “quotes” and «guillemets».' );5var CFFOffsetTracker = require( './cffoffsettracker' );6var tracker = new CFFOffsetTracker( 'I\'m a string with “quotes” and «guillemets».' );7var CFFOffsetTracker = require( './cffoffsettracker' );8var tracker = new CFFOffsetTracker( 'I\'m a string with “quotes” and «guillemets».' );9tracker.getOffset(
Using AI Code Generation
1var fs = require('fs');2var wptext = require('./wptext.js');3var fontFile = fs.readFileSync(process.argv[2]);4var cffOffsetTracker = new wptext.CFFOffsetTracker();5var cffOffset = cffOffsetTracker.findCFFOffset(fontFile);6console.log(cffOffset);7var cffOffsetTracker = new wptext.CFFOffsetTracker();8var cffOffset = cffOffsetTracker.findCFFOffset(fontFile);9console.log(cffOffset);10var cffOffsetTracker = new wptext.CFFOffsetTracker();11var cffOffset = cffOffsetTracker.findCFFOffset(fontFile);12console.log(cffOffset);13var cffOffsetTracker = new wptext.CFFOffsetTracker();14var cffOffset = cffOffsetTracker.findCFFOffset(fontFile);15console.log(cffOffset);16var cffOffsetTracker = new wptext.CFFOffsetTracker();17var cffOffset = cffOffsetTracker.findCFFOffset(fontFile);18console.log(cffOffset);19var cffOffsetTracker = new wptext.CFFOffsetTracker();20var cffOffset = cffOffsetTracker.findCFFOffset(fontFile);21console.log(cffOffset);22var cffOffsetTracker = new wptext.CFFOffsetTracker();
Using AI Code Generation
1(async function() {2 var wptAgent = await window.wptAgent;3 var cffOffset = await wptAgent.CFFOffsetTracker();4 console.log(cffOffset);5})();6CFFOffsetTracker() {7 return new Promise((resolve, reject) => {8 var cffOffset = 0;9 var cffOffsetInWoff = 0;10 var cffOffsetInWoff2 = 0;11 var woff2Buffer = new ArrayBuffer(0);12 var woff2BufferView = new Uint8Array(woff2Buffer);13 var woffBuffer = new ArrayBuffer(0);14 var woffBufferView = new Uint8Array(woffBuffer);15 var fontBuffer = new ArrayBuffer(0);16 var fontBufferView = new Uint8Array(fontBuffer);17 var fontFile = new File([fontBufferView], "testfont.woff2", {type: "font/woff2"});18 var woffFile = new File([woffBufferView], "testfont.woff", {type: "font/woff"});19 var fontFileUrl = URL.createObjectURL(fontFile);20 var woffFileUrl = URL.createObjectURL(woffFile);21 var font = new FontFace('test
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!!