How to use Type1CharString method in wpt

Best JavaScript code snippet using wpt

type1_parser.js

Source:type1_parser.js Github

copy

Full Screen

...45 'hmoveto': [22],46 'vhcurveto': [30],47 'hvcurveto': [31]48 };49 function Type1CharString() {50 this.width = 0;51 this.lsb = 0;52 this.flexing = false;53 this.output = [];54 this.stack = [];55 }56 Type1CharString.prototype = {57 convert: function Type1CharString_convert(encoded, subrs, seacAnalysisEnabled) {58 var count = encoded.length;59 var error = false;60 var wx, sbx, subrNumber;61 for (var i = 0; i < count; i++) {62 var value = encoded[i];63 if (value < 32) {64 if (value === 12) {65 value = (value << 8) + encoded[++i];66 }67 switch (value) {68 case 1:69 if (!HINTING_ENABLED) {70 this.stack = [];71 break;72 }73 error = this.executeCommand(2, COMMAND_MAP.hstem);74 break;75 case 3:76 if (!HINTING_ENABLED) {77 this.stack = [];78 break;79 }80 error = this.executeCommand(2, COMMAND_MAP.vstem);81 break;82 case 4:83 if (this.flexing) {84 if (this.stack.length < 1) {85 error = true;86 break;87 }88 var dy = this.stack.pop();89 this.stack.push(0, dy);90 break;91 }92 error = this.executeCommand(1, COMMAND_MAP.vmoveto);93 break;94 case 5:95 error = this.executeCommand(2, COMMAND_MAP.rlineto);96 break;97 case 6:98 error = this.executeCommand(1, COMMAND_MAP.hlineto);99 break;100 case 7:101 error = this.executeCommand(1, COMMAND_MAP.vlineto);102 break;103 case 8:104 error = this.executeCommand(6, COMMAND_MAP.rrcurveto);105 break;106 case 9:107 this.stack = [];108 break;109 case 10:110 if (this.stack.length < 1) {111 error = true;112 break;113 }114 subrNumber = this.stack.pop();115 if (!subrs[subrNumber]) {116 error = true;117 break;118 }119 error = this.convert(subrs[subrNumber], subrs, seacAnalysisEnabled);120 break;121 case 11:122 return error;123 case 13:124 if (this.stack.length < 2) {125 error = true;126 break;127 }128 wx = this.stack.pop();129 sbx = this.stack.pop();130 this.lsb = sbx;131 this.width = wx;132 this.stack.push(wx, sbx);133 error = this.executeCommand(2, COMMAND_MAP.hmoveto);134 break;135 case 14:136 this.output.push(COMMAND_MAP.endchar[0]);137 break;138 case 21:139 if (this.flexing) {140 break;141 }142 error = this.executeCommand(2, COMMAND_MAP.rmoveto);143 break;144 case 22:145 if (this.flexing) {146 this.stack.push(0);147 break;148 }149 error = this.executeCommand(1, COMMAND_MAP.hmoveto);150 break;151 case 30:152 error = this.executeCommand(4, COMMAND_MAP.vhcurveto);153 break;154 case 31:155 error = this.executeCommand(4, COMMAND_MAP.hvcurveto);156 break;157 case (12 << 8) + 0:158 this.stack = [];159 break;160 case (12 << 8) + 1:161 if (!HINTING_ENABLED) {162 this.stack = [];163 break;164 }165 error = this.executeCommand(2, COMMAND_MAP.vstem);166 break;167 case (12 << 8) + 2:168 if (!HINTING_ENABLED) {169 this.stack = [];170 break;171 }172 error = this.executeCommand(2, COMMAND_MAP.hstem);173 break;174 case (12 << 8) + 6:175 if (seacAnalysisEnabled) {176 this.seac = this.stack.splice(-4, 4);177 error = this.executeCommand(0, COMMAND_MAP.endchar);178 } else {179 error = this.executeCommand(4, COMMAND_MAP.endchar);180 }181 break;182 case (12 << 8) + 7:183 if (this.stack.length < 4) {184 error = true;185 break;186 }187 this.stack.pop();188 wx = this.stack.pop();189 var sby = this.stack.pop();190 sbx = this.stack.pop();191 this.lsb = sbx;192 this.width = wx;193 this.stack.push(wx, sbx, sby);194 error = this.executeCommand(3, COMMAND_MAP.rmoveto);195 break;196 case (12 << 8) + 12:197 if (this.stack.length < 2) {198 error = true;199 break;200 }201 var num2 = this.stack.pop();202 var num1 = this.stack.pop();203 this.stack.push(num1 / num2);204 break;205 case (12 << 8) + 16:206 if (this.stack.length < 2) {207 error = true;208 break;209 }210 subrNumber = this.stack.pop();211 var numArgs = this.stack.pop();212 if (subrNumber === 0 && numArgs === 3) {213 var flexArgs = this.stack.splice(this.stack.length - 17, 17);214 this.stack.push(flexArgs[2] + flexArgs[0], flexArgs[3] + flexArgs[1], flexArgs[4], flexArgs[5], flexArgs[6], flexArgs[7], flexArgs[8], flexArgs[9], flexArgs[10], flexArgs[11], flexArgs[12], flexArgs[13], flexArgs[14]);215 error = this.executeCommand(13, COMMAND_MAP.flex, true);216 this.flexing = false;217 this.stack.push(flexArgs[15], flexArgs[16]);218 } else if (subrNumber === 1 && numArgs === 0) {219 this.flexing = true;220 }221 break;222 case (12 << 8) + 17:223 break;224 case (12 << 8) + 33:225 this.stack = [];226 break;227 default:228 (0, _util.warn)('Unknown type 1 charstring command of "' + value + '"');229 break;230 }231 if (error) {232 break;233 }234 continue;235 } else if (value <= 246) {236 value = value - 139;237 } else if (value <= 250) {238 value = (value - 247) * 256 + encoded[++i] + 108;239 } else if (value <= 254) {240 value = -((value - 251) * 256) - encoded[++i] - 108;241 } else {242 value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 | (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;243 }244 this.stack.push(value);245 }246 return error;247 },248 executeCommand: function executeCommand(howManyArgs, command, keepStack) {249 var stackLength = this.stack.length;250 if (howManyArgs > stackLength) {251 return true;252 }253 var start = stackLength - howManyArgs;254 for (var i = start; i < stackLength; i++) {255 var value = this.stack[i];256 if (Number.isInteger(value)) {257 this.output.push(28, value >> 8 & 0xff, value & 0xff);258 } else {259 value = 65536 * value | 0;260 this.output.push(255, value >> 24 & 0xFF, value >> 16 & 0xFF, value >> 8 & 0xFF, value & 0xFF);261 }262 }263 this.output.push.apply(this.output, command);264 if (keepStack) {265 this.stack.splice(start, howManyArgs);266 } else {267 this.stack.length = 0;268 }269 return false;270 }271 };272 return Type1CharString;273}();274var Type1Parser = function Type1ParserClosure() {275 var EEXEC_ENCRYPT_KEY = 55665;276 var CHAR_STRS_ENCRYPT_KEY = 4330;277 function isHexDigit(code) {278 return code >= 48 && code <= 57 || code >= 65 && code <= 70 || code >= 97 && code <= 102;279 }280 function decrypt(data, key, discardNumber) {281 if (discardNumber >= data.length) {282 return new Uint8Array(0);283 }284 var r = key | 0,285 c1 = 52845,286 c2 = 22719,287 i,288 j;289 for (i = 0; i < discardNumber; i++) {290 r = (data[i] + r) * c1 + c2 & (1 << 16) - 1;291 }292 var count = data.length - discardNumber;293 var decrypted = new Uint8Array(count);294 for (i = discardNumber, j = 0; j < count; i++, j++) {295 var value = data[i];296 decrypted[j] = value ^ r >> 8;297 r = (value + r) * c1 + c2 & (1 << 16) - 1;298 }299 return decrypted;300 }301 function decryptAscii(data, key, discardNumber) {302 var r = key | 0,303 c1 = 52845,304 c2 = 22719;305 var count = data.length,306 maybeLength = count >>> 1;307 var decrypted = new Uint8Array(maybeLength);308 var i, j;309 for (i = 0, j = 0; i < count; i++) {310 var digit1 = data[i];311 if (!isHexDigit(digit1)) {312 continue;313 }314 i++;315 var digit2;316 while (i < count && !isHexDigit(digit2 = data[i])) {317 i++;318 }319 if (i < count) {320 var value = parseInt(String.fromCharCode(digit1, digit2), 16);321 decrypted[j++] = value ^ r >> 8;322 r = (value + r) * c1 + c2 & (1 << 16) - 1;323 }324 }325 return Array.prototype.slice.call(decrypted, discardNumber, j);326 }327 function isSpecial(c) {328 return c === 0x2F || c === 0x5B || c === 0x5D || c === 0x7B || c === 0x7D || c === 0x28 || c === 0x29;329 }330 function Type1Parser(stream, encrypted, seacAnalysisEnabled) {331 if (encrypted) {332 var data = stream.getBytes();333 var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) && isHexDigit(data[2]) && isHexDigit(data[3]));334 stream = new _stream.Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) : decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));335 }336 this.seacAnalysisEnabled = !!seacAnalysisEnabled;337 this.stream = stream;338 this.nextChar();339 }340 Type1Parser.prototype = {341 readNumberArray: function Type1Parser_readNumberArray() {342 this.getToken();343 var array = [];344 while (true) {345 var token = this.getToken();346 if (token === null || token === ']' || token === '}') {347 break;348 }349 array.push(parseFloat(token || 0));350 }351 return array;352 },353 readNumber: function Type1Parser_readNumber() {354 var token = this.getToken();355 return parseFloat(token || 0);356 },357 readInt: function Type1Parser_readInt() {358 var token = this.getToken();359 return parseInt(token || 0, 10) | 0;360 },361 readBoolean: function Type1Parser_readBoolean() {362 var token = this.getToken();363 return token === 'true' ? 1 : 0;364 },365 nextChar: function Type1_nextChar() {366 return this.currentChar = this.stream.getByte();367 },368 getToken: function Type1Parser_getToken() {369 var comment = false;370 var ch = this.currentChar;371 while (true) {372 if (ch === -1) {373 return null;374 }375 if (comment) {376 if (ch === 0x0A || ch === 0x0D) {377 comment = false;378 }379 } else if (ch === 0x25) {380 comment = true;381 } else if (!(0, _util.isSpace)(ch)) {382 break;383 }384 ch = this.nextChar();385 }386 if (isSpecial(ch)) {387 this.nextChar();388 return String.fromCharCode(ch);389 }390 var token = '';391 do {392 token += String.fromCharCode(ch);393 ch = this.nextChar();394 } while (ch >= 0 && !(0, _util.isSpace)(ch) && !isSpecial(ch));395 return token;396 },397 readCharStrings: function Type1Parser_readCharStrings(bytes, lenIV) {398 if (lenIV === -1) {399 return bytes;400 }401 return decrypt(bytes, CHAR_STRS_ENCRYPT_KEY, lenIV);402 },403 extractFontProgram: function Type1Parser_extractFontProgram() {404 var stream = this.stream;405 var subrs = [],406 charstrings = [];407 var privateData = Object.create(null);408 privateData['lenIV'] = 4;409 var program = {410 subrs: [],411 charstrings: [],412 properties: { 'privateData': privateData }413 };414 var token, length, data, lenIV, encoded;415 while ((token = this.getToken()) !== null) {416 if (token !== '/') {417 continue;418 }419 token = this.getToken();420 switch (token) {421 case 'CharStrings':422 this.getToken();423 this.getToken();424 this.getToken();425 this.getToken();426 while (true) {427 token = this.getToken();428 if (token === null || token === 'end') {429 break;430 }431 if (token !== '/') {432 continue;433 }434 var glyph = this.getToken();435 length = this.readInt();436 this.getToken();437 data = stream.makeSubStream(stream.pos, length);438 lenIV = program.properties.privateData['lenIV'];439 encoded = this.readCharStrings(data.getBytes(), lenIV);440 stream.skip(length);441 this.nextChar();442 token = this.getToken();443 if (token === 'noaccess') {444 this.getToken();445 }446 charstrings.push({447 glyph: glyph,448 encoded: encoded449 });450 }451 break;452 case 'Subrs':453 this.readInt();454 this.getToken();455 while (this.getToken() === 'dup') {456 var index = this.readInt();457 length = this.readInt();458 this.getToken();459 data = stream.makeSubStream(stream.pos, length);460 lenIV = program.properties.privateData['lenIV'];461 encoded = this.readCharStrings(data.getBytes(), lenIV);462 stream.skip(length);463 this.nextChar();464 token = this.getToken();465 if (token === 'noaccess') {466 this.getToken();467 }468 subrs[index] = encoded;469 }470 break;471 case 'BlueValues':472 case 'OtherBlues':473 case 'FamilyBlues':474 case 'FamilyOtherBlues':475 var blueArray = this.readNumberArray();476 if (blueArray.length > 0 && blueArray.length % 2 === 0 && HINTING_ENABLED) {477 program.properties.privateData[token] = blueArray;478 }479 break;480 case 'StemSnapH':481 case 'StemSnapV':482 program.properties.privateData[token] = this.readNumberArray();483 break;484 case 'StdHW':485 case 'StdVW':486 program.properties.privateData[token] = this.readNumberArray()[0];487 break;488 case 'BlueShift':489 case 'lenIV':490 case 'BlueFuzz':491 case 'BlueScale':492 case 'LanguageGroup':493 case 'ExpansionFactor':494 program.properties.privateData[token] = this.readNumber();495 break;496 case 'ForceBold':497 program.properties.privateData[token] = this.readBoolean();498 break;499 }500 }501 for (var i = 0; i < charstrings.length; i++) {502 glyph = charstrings[i].glyph;503 encoded = charstrings[i].encoded;504 var charString = new Type1CharString();505 var error = charString.convert(encoded, subrs, this.seacAnalysisEnabled);506 var output = charString.output;507 if (error) {508 output = [14];509 }510 program.charstrings.push({511 glyphName: glyph,512 charstring: output,513 width: charString.width,514 lsb: charString.lsb,515 seac: charString.seac516 });517 }518 return program;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.type1CharString('test');3var wptools = require('wptools');4wptools.type1CharString('test');5var wptools = require('wptools');6wptools.type1CharString('test');7var wptools = require('wptools');8wptools.type1CharString('test');9var wptools = require('wptools');10wptools.type1CharString('test');11var wptools = require('wptools');12wptools.type1CharString('test');13var wptools = require('wptools');14wptools.type1CharString('test');15var wptools = require('wptools');16wptools.type1CharString('test');17var wptools = require('wptools');18wptools.type1CharString('test');19var wptools = require('wptools');20wptools.type1CharString('test');21var wptools = require('wptools');22wptools.type1CharString('test');23var wptools = require('wptools');24wptools.type1CharString('test');

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var wptext = require('./wptext.js');3var text = fs.readFileSync('test.txt', 'utf8');4var charstrings = wptext.Type1CharString(text);5var charstring = charstrings[0];6var hex = wptext.charstringToHex(charstring);7console.log(hex);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var input = fs.createReadStream('test.txt');4var output = fs.createWriteStream('test-out.txt');5var type1 = new wptools.Type1CharString();6type1.on('data', function (chunk) {7 output.write(chunk);8});9input.pipe(type1);10var wptools = require('wptools');11var fs = require('fs');12var input = fs.createReadStream('test.txt');13var output = fs.createWriteStream('test-out.txt');14var type1 = new wptools.Type1CharString();15type1.on('data', function (chunk) {16 output.write(chunk);17});18input.pipe(type1);19var wptools = require('wptools');20var fs = require('fs');21var input = fs.createReadStream('test.txt');22var output = fs.createWriteStream('test-out.txt');23var type1 = new wptools.Type1CharString();24type1.on('data', function (chunk) {25 output.write(chunk);26});27input.pipe(type1);28var wptools = require('wptools');29var fs = require('fs');30var input = fs.createReadStream('test.txt');31var output = fs.createWriteStream('test-out.txt');32var type1 = new wptools.Type1CharString();33type1.on('data', function (chunk) {34 output.write(chunk);35});36input.pipe(type1);37var wptools = require('wptools');38var fs = require('fs');39var input = fs.createReadStream('test.txt');40var output = fs.createWriteStream('test-out.txt');41var type1 = new wptools.Type1CharString();42type1.on('data', function (chunk) {43 output.write(chunk);44});45input.pipe(type1);46var wptools = require('wptools');47var fs = require('fs');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var fontFile = path.join(__dirname, 'font.ttf');5var char = 'a';6wptools.Type1CharString.extractChar(fontFile, char, function(err, result) {7 if (err) {8 console.log(err);9 } else {10 console.log(JSON.stringify(result));11 }12});13{14 "bbox": {15 },16 {17 },18 {19 },20 {21 },22 {23 },24 {25 }26}27var wptools = require('wptools');28var fs = require('fs');29var path = require('path');30var fontFile = path.join(__dirname, 'font.ttf');31var char = 'a';32wptools.Type1CharString.extractChar(fontFile, char, function(err, result) {33 if (err) {34 console.log(err);35 } else {36 console.log(JSON.stringify(result));37 }38});39{40 "bbox": {41 },

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful