How to use compileCharString method in wpt

Best JavaScript code snippet using wpt

font_renderer.js

Source:font_renderer.js Github

copy

Full Screen

...277 startPoint = endPoint + 1;278 }279 }280 }281 function compileCharString(code, js, font) {282 var stack = [];283 var x = 0, y = 0;284 var stems = 0;285 function moveTo(x, y) {286 js.push('c.moveTo(' + x + ',' + y + ');');287 }288 function lineTo(x, y) {289 js.push('c.lineTo(' + x + ',' + y + ');');290 }291 function bezierCurveTo(x1, y1, x2, y2, x, y) {292 js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +293 x + ',' + y + ');');294 }295 function parse(code) {296 var i = 0;297 while (i < code.length) {298 var stackClean = false;299 var v = code[i++];300 var xa, xb, ya, yb, y1, y2, y3, n, subrCode;301 switch (v) {302 case 1: // hstem303 stems += stack.length >> 1;304 stackClean = true;305 break;306 case 3: // vstem307 stems += stack.length >> 1;308 stackClean = true;309 break;310 case 4: // vmoveto311 y += stack.pop();312 moveTo(x, y);313 stackClean = true;314 break;315 case 5: // rlineto316 while (stack.length > 0) {317 x += stack.shift();318 y += stack.shift();319 lineTo(x, y);320 }321 break;322 case 6: // hlineto323 while (stack.length > 0) {324 x += stack.shift();325 lineTo(x, y);326 if (stack.length === 0) {327 break;328 }329 y += stack.shift();330 lineTo(x, y);331 }332 break;333 case 7: // vlineto334 while (stack.length > 0) {335 y += stack.shift();336 lineTo(x, y);337 if (stack.length === 0) {338 break;339 }340 x += stack.shift();341 lineTo(x, y);342 }343 break;344 case 8: // rrcurveto345 while (stack.length > 0) {346 xa = x + stack.shift(); ya = y + stack.shift();347 xb = xa + stack.shift(); yb = ya + stack.shift();348 x = xb + stack.shift(); y = yb + stack.shift();349 bezierCurveTo(xa, ya, xb, yb, x, y);350 }351 break;352 case 10: // callsubr353 n = stack.pop() + font.subrsBias;354 subrCode = font.subrs[n];355 if (subrCode) {356 parse(subrCode);357 }358 break;359 case 11: // return360 return;361 case 12:362 v = code[i++];363 switch (v) {364 case 34: // flex365 xa = x + stack.shift();366 xb = xa + stack.shift(); y1 = y + stack.shift();367 x = xb + stack.shift();368 bezierCurveTo(xa, y, xb, y1, x, y1);369 xa = x + stack.shift();370 xb = xa + stack.shift();371 x = xb + stack.shift();372 bezierCurveTo(xa, y1, xb, y, x, y);373 break;374 case 35: // flex375 xa = x + stack.shift(); ya = y + stack.shift();376 xb = xa + stack.shift(); yb = ya + stack.shift();377 x = xb + stack.shift(); y = yb + stack.shift();378 bezierCurveTo(xa, ya, xb, yb, x, y);379 xa = x + stack.shift(); ya = y + stack.shift();380 xb = xa + stack.shift(); yb = ya + stack.shift();381 x = xb + stack.shift(); y = yb + stack.shift();382 bezierCurveTo(xa, ya, xb, yb, x, y);383 stack.pop(); // fd384 break;385 case 36: // hflex1386 xa = x + stack.shift(); y1 = y + stack.shift();387 xb = xa + stack.shift(); y2 = y1 + stack.shift();388 x = xb + stack.shift();389 bezierCurveTo(xa, y1, xb, y2, x, y2);390 xa = x + stack.shift();391 xb = xa + stack.shift(); y3 = y2 + stack.shift();392 x = xb + stack.shift();393 bezierCurveTo(xa, y2, xb, y3, x, y);394 break;395 case 37: // flex1396 var x0 = x, y0 = y;397 xa = x + stack.shift(); ya = y + stack.shift();398 xb = xa + stack.shift(); yb = ya + stack.shift();399 x = xb + stack.shift(); y = yb + stack.shift();400 bezierCurveTo(xa, ya, xb, yb, x, y);401 xa = x + stack.shift(); ya = y + stack.shift();402 xb = xa + stack.shift(); yb = ya + stack.shift();403 x = xb; y = yb;404 if (Math.abs(x - x0) > Math.abs(y - y0)) {405 x += stack.shift();406 } else {407 y += stack.shift();408 }409 bezierCurveTo(xa, ya, xb, yb, x, y);410 break;411 default:412 error('unknown operator: 12 ' + v);413 }414 break;415 case 14: // endchar416 if (stack.length >= 4) {417 var achar = stack.pop();418 var bchar = stack.pop();419 y = stack.pop();420 x = stack.pop();421 js.push('c.save();');422 js.push('c.translate('+ x + ',' + y + ');');423 var gid = lookupCmap(font.cmap, String.fromCharCode(424 font.glyphNameMap[Encodings.StandardEncoding[achar]]));425 compileCharString(font.glyphs[gid], js, font);426 js.push('c.restore();');427 gid = lookupCmap(font.cmap, String.fromCharCode(428 font.glyphNameMap[Encodings.StandardEncoding[bchar]]));429 compileCharString(font.glyphs[gid], js, font);430 }431 return;432 case 18: // hstemhm433 stems += stack.length >> 1;434 stackClean = true;435 break;436 case 19: // hintmask437 stems += stack.length >> 1;438 i += (stems + 7) >> 3;439 stackClean = true;440 break;441 case 20: // cntrmask442 stems += stack.length >> 1;443 i += (stems + 7) >> 3;444 stackClean = true;445 break;446 case 21: // rmoveto447 y += stack.pop();448 x += stack.pop();449 moveTo(x, y);450 stackClean = true;451 break;452 case 22: // hmoveto453 x += stack.pop();454 moveTo(x, y);455 stackClean = true;456 break;457 case 23: // vstemhm458 stems += stack.length >> 1;459 stackClean = true;460 break;461 case 24: // rcurveline462 while (stack.length > 2) {463 xa = x + stack.shift(); ya = y + stack.shift();464 xb = xa + stack.shift(); yb = ya + stack.shift();465 x = xb + stack.shift(); y = yb + stack.shift();466 bezierCurveTo(xa, ya, xb, yb, x, y);467 }468 x += stack.shift();469 y += stack.shift();470 lineTo(x, y);471 break;472 case 25: // rlinecurve473 while (stack.length > 6) {474 x += stack.shift();475 y += stack.shift();476 lineTo(x, y);477 }478 xa = x + stack.shift(); ya = y + stack.shift();479 xb = xa + stack.shift(); yb = ya + stack.shift();480 x = xb + stack.shift(); y = yb + stack.shift();481 bezierCurveTo(xa, ya, xb, yb, x, y);482 break;483 case 26: // vvcurveto484 if (stack.length % 2) {485 x += stack.shift();486 }487 while (stack.length > 0) {488 xa = x; ya = y + stack.shift();489 xb = xa + stack.shift(); yb = ya + stack.shift();490 x = xb; y = yb + stack.shift();491 bezierCurveTo(xa, ya, xb, yb, x, y);492 }493 break;494 case 27: // hhcurveto495 if (stack.length % 2) {496 y += stack.shift();497 }498 while (stack.length > 0) {499 xa = x + stack.shift(); ya = y;500 xb = xa + stack.shift(); yb = ya + stack.shift();501 x = xb + stack.shift(); y = yb;502 bezierCurveTo(xa, ya, xb, yb, x, y);503 }504 break;505 case 28:506 stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);507 i += 2;508 break;509 case 29: // callgsubr510 n = stack.pop() + font.gsubrsBias;511 subrCode = font.gsubrs[n];512 if (subrCode) {513 parse(subrCode);514 }515 break;516 case 30: // vhcurveto517 while (stack.length > 0) {518 xa = x; ya = y + stack.shift();519 xb = xa + stack.shift(); yb = ya + stack.shift();520 x = xb + stack.shift();521 y = yb + (stack.length === 1 ? stack.shift() : 0);522 bezierCurveTo(xa, ya, xb, yb, x, y);523 if (stack.length === 0) {524 break;525 }526 xa = x + stack.shift(); ya = y;527 xb = xa + stack.shift(); yb = ya + stack.shift();528 y = yb + stack.shift();529 x = xb + (stack.length === 1 ? stack.shift() : 0);530 bezierCurveTo(xa, ya, xb, yb, x, y);531 }532 break;533 case 31: // hvcurveto534 while (stack.length > 0) {535 xa = x + stack.shift(); ya = y;536 xb = xa + stack.shift(); yb = ya + stack.shift();537 y = yb + stack.shift();538 x = xb + (stack.length === 1 ? stack.shift() : 0);539 bezierCurveTo(xa, ya, xb, yb, x, y);540 if (stack.length === 0) {541 break;542 }543 xa = x; ya = y + stack.shift();544 xb = xa + stack.shift(); yb = ya + stack.shift();545 x = xb + stack.shift();546 y = yb + (stack.length === 1 ? stack.shift() : 0);547 bezierCurveTo(xa, ya, xb, yb, x, y);548 }549 break;550 default:551 if (v < 32) {552 error('unknown operator: ' + v);553 }554 if (v < 247) {555 stack.push(v - 139);556 } else if (v < 251) {557 stack.push((v - 247) * 256 + code[i++] + 108);558 } else if (v < 255) {559 stack.push(-(v - 251) * 256 - code[i++] - 108);560 } else {561 stack.push(((code[i] << 24) | (code[i + 1] << 16) |562 (code[i + 2] << 8) | code[i + 3]) / 65536);563 i += 4;564 }565 break;566 }567 if (stackClean) {568 stack.length = 0;569 }570 }571 }572 parse(code);573 }574 var noop = '';575 function CompiledFont(fontMatrix) {576 this.compiledGlyphs = {};577 this.fontMatrix = fontMatrix;578 }579 CompiledFont.prototype = {580 getPathJs: function (unicode) {581 var gid = lookupCmap(this.cmap, unicode);582 var fn = this.compiledGlyphs[gid];583 if (!fn) {584 this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);585 }586 return fn;587 },588 compileGlyph: function (code) {589 if (!code || code.length === 0 || code[0] === 14) {590 return noop;591 }592 var js = [];593 js.push('c.save();');594 js.push('c.transform(' + this.fontMatrix.join(',') + ');');595 js.push('c.scale(size, -size);');596 this.compileGlyphImpl(code, js);597 js.push('c.restore();');598 return js.join('\n');599 },600 compileGlyphImpl: function () {601 error('Children classes should implement this.');602 },603 hasBuiltPath: function (unicode) {604 var gid = lookupCmap(this.cmap, unicode);605 return gid in this.compiledGlyphs;606 }607 };608 function TrueTypeCompiled(glyphs, cmap, fontMatrix) {609 fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];610 CompiledFont.call(this, fontMatrix);611 this.glyphs = glyphs;612 this.cmap = cmap;613 this.compiledGlyphs = [];614 }615 Util.inherit(TrueTypeCompiled, CompiledFont, {616 compileGlyphImpl: function (code, js) {617 compileGlyf(code, js, this);618 }619 });620 function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {621 fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];622 CompiledFont.call(this, fontMatrix);623 this.glyphs = cffInfo.glyphs;624 this.gsubrs = cffInfo.gsubrs || [];625 this.subrs = cffInfo.subrs || [];626 this.cmap = cmap;627 this.glyphNameMap = glyphNameMap || GlyphsUnicode;628 this.compiledGlyphs = [];629 this.gsubrsBias = (this.gsubrs.length < 1240 ?630 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));631 this.subrsBias = (this.subrs.length < 1240 ?632 107 : (this.subrs.length < 33900 ? 1131 : 32768));633 }634 Util.inherit(Type2Compiled, CompiledFont, {635 compileGlyphImpl: function (code, js) {636 compileCharString(code, js, this);637 }638 });639 return {640 create: function FontRendererFactory_create(font) {641 var data = new Uint8Array(font.data);642 var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;643 var numTables = getUshort(data, 4);644 for (var i = 0, p = 12; i < numTables; i++, p += 16) {645 var tag = bytesToString(data.subarray(p, p + 4));646 var offset = getLong(data, p + 8);647 var length = getLong(data, p + 12);648 switch (tag) {649 case 'cmap':650 cmap = parseCmap(data, offset, offset + length);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var charString = wptoolkit.compileCharString('hello world');3console.log(charString);4var wptoolkit = require('wptoolkit');5var charString = wptoolkit.compileCharString('hello world');6console.log(charString);7var wptoolkit = require('wptoolkit');8var charString = wptoolkit.compileCharString('hello world');9console.log(charString);10var wptoolkit = require('wptoolkit');11var charString = wptoolkit.compileCharString('hello world');12console.log(charString);13var wptoolkit = require('wptoolkit');14var charString = wptoolkit.compileCharString('hello world');15console.log(charString);16var wptoolkit = require('wptoolkit');17var charString = wptoolkit.compileCharString('hello world');18console.log(charString);19var wptoolkit = require('wptoolkit');20var charString = wptoolkit.compileCharString('hello world');21console.log(charString);22var wptoolkit = require('wptoolkit');23var charString = wptoolkit.compileCharString('hello world');24console.log(charString);25var wptoolkit = require('wptoolkit');26var charString = wptoolkit.compileCharString('hello world');27console.log(charString);28var wptoolkit = require('wptoolkit');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptext = require('wptext');2var text = 'Hello World!';3var compiled = wptext.compileCharString(text);4console.log(compiled);5var wptext = require('wptext');6var text = 'Hello World!';7var compiled = wptext.compileCharString(text);8console.log(compiled);9var wptext = require('wptext');10var text = 'Hello World!';11var compiled = wptext.compileCharString(text);12console.log(compiled);13var wptext = require('wptext');14var text = 'Hello World!';15var compiled = wptext.compileCharString(text);16console.log(compiled);17var wptext = require('wptext');18var text = 'Hello World!';19var compiled = wptext.compileCharString(text);20console.log(compiled);21var wptext = require('wptext');22var text = 'Hello World!';23var compiled = wptext.compileCharString(text);24console.log(compiled);25var wptext = require('wptext');26var text = 'Hello World!';27var compiled = wptext.compileCharString(text);28console.log(compiled);29var wptext = require('wptext');30var text = 'Hello World!';31var compiled = wptext.compileCharString(text);32console.log(compiled);33var wptext = require('wptext');34var text = 'Hello World!';35var compiled = wptext.compileCharString(text);36console.log(compiled);37var wptext = require('wptext');38var text = 'Hello World!';39var compiled = wptext.compileCharString(text);40console.log(compiled);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpTextConverter = require('wp-text-converter');2var fs = require('fs');3var data = fs.readFileSync('test.txt', 'utf8');4var compiled = wpTextConverter.compileCharString(data);5console.log(compiled);6var wpTextConverter = require('wp-text-converter');7var fs = require('fs');8var data = fs.readFileSync('test.txt', 'utf8');9var compiled = wpTextConverter.compileCharString(data);10console.log(compiled);11var wpTextConverter = require('wp-text-converter');12var fs = require('fs');13var data = fs.readFileSync('test.txt', 'utf8');14var compiled = wpTextConverter.compileCharString(data);15console.log(compiled);16var wpTextConverter = require('wp-text-converter');17var fs = require('fs');18var data = fs.readFileSync('test.txt', 'utf8');19var compiled = wpTextConverter.compileCharString(data);20console.log(compiled);21var wpTextConverter = require('wp-text-converter');22var fs = require('fs');23var data = fs.readFileSync('test.txt', 'utf8');24var compiled = wpTextConverter.compileCharString(data);25console.log(compiled);26var wpTextConverter = require('wp-text-converter');27var fs = require('fs');28var data = fs.readFileSync('test.txt', 'utf8');29var compiled = wpTextConverter.compileCharString(data);30console.log(compiled);31var wpTextConverter = require('wp-text-converter');32var fs = require('fs');33var data = fs.readFileSync('test.txt', 'utf8');34var compiled = wpTextConverter.compileCharString(data);35console.log(compiled);36var wpTextConverter = require('wp-text-converter');37var fs = require('fs');

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2var cs = wptools.compileCharString("Hello World!");3console.log(cs);4var canvas = document.getElementById('canvas');5var ctx = canvas.getContext('2d');6ctx.font = "30px Arial";7ctx.fillText(cs,10,50);

Full Screen

Using AI Code Generation

copy

Full Screen

1var encoder = new TextEncoder();2var buffer = encoder.encode("Hello World");3var module = new WebAssembly.Module(buffer);4var module = await WebAssembly.compileStreaming("Hello World");5var instance = await WebAssembly.instantiateStreaming("Hello World");6var instance = await WebAssembly.instantiateStreaming("Hello World", { js: { import1: function() { return 1; }, import2: function() { return 2; } } });7var instance = await WebAssembly.instantiateStreaming("Hello World", { js: { import1: function() { return 1; }, import2: function() { return 2; } } }, { js: { import1: function() { return 1; }, import2: function() { return 2; } } });8var instance = await WebAssembly.instantiateStreaming("Hello World", { js: { import1: function() { return 1; }, import2: function() { return 2; } } }, { js: { import1: function() { return 1; }, import2: function() { return 2; } } });9var instance = await WebAssembly.instantiateStreaming("Hello World", { js: { import1: function() { return 1; }, import2: function() { return 2; } } }, { js: { import1: function() { return 1; }, import2: function() { return 2; }

Full Screen

Using AI Code Generation

copy

Full Screen

1var text = new wpText();2var textString = 'Hello World';3var textObject = text.compileCharString(textString);4text.drawText(textObject);5function wpText() {6 this.textSize = 10;7 this.fontFamily = 'Arial';8 this.fontWeight = 'normal';9 this.fontStyle = 'normal';10 this.color = '#000000';11 this.textAlign = 'left';12 this.textBaseline = 'bottom';13 this.textDecoration = 'none';14 this.textShadow = 'none';15 this.lineHeight = 0;16 this.letterSpacing = 0;17 this.textIndent = 0;18 this.textTransform = 'none';19 this.wordSpacing = 0;20 this.textDirection = 'ltr';21 this.unicodeBidi = 'normal';22}23wpText.prototype.compileCharString = function (textString) {24 var textObject = {25 textArray: textString.split(''),26 };27 for (var i = 0; i < textObject.textLength; i++) {28 var charObject = {29 };30 textObject.charArray.push(charObject);31 }32 return textObject;33};34wpText.prototype.drawText = function (textObject) {35};36function wpText() {37 this.textSize = 10;38 this.fontFamily = 'Arial';39 this.fontWeight = 'normal';40 this.fontStyle = 'normal';41 this.color = '#000000';42 this.textAlign = 'left';43 this.textBaseline = 'bottom';44 this.textDecoration = 'none';45 this.textShadow = 'none';46 this.lineHeight = 0;47 this.letterSpacing = 0;

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