Best JavaScript code snippet using wpt
fonts.js
Source:fonts.js  
...473      return true;474    }475    return false;476  }477  function buildToFontChar(encoding, glyphsUnicodeMap, differences) {478    var toFontChar = [],479        unicode;480    for (var i = 0, ii = encoding.length; i < ii; i++) {481      unicode = (0, _unicode.getUnicodeForGlyph)(encoding[i], glyphsUnicodeMap);482      if (unicode !== -1) {483        toFontChar[i] = unicode;484      }485    }486    for (var charCode in differences) {487      unicode = (0, _unicode.getUnicodeForGlyph)(differences[charCode], glyphsUnicodeMap);488      if (unicode !== -1) {489        toFontChar[+charCode] = unicode;490      }491    }492    return toFontChar;493  }494  function isProblematicUnicodeLocation(code) {495    var i = 0,496        j = ProblematicCharRanges.length - 1;497    while (i < j) {498      var c = i + j + 1 >> 1;499      if (code < ProblematicCharRanges[c]) {500        j = c - 1;501      } else {502        i = c;503      }504    }505    return !(i & 1);506  }507  function adjustMapping(charCodeToGlyphId, properties, missingGlyphs) {508    var toUnicode = properties.toUnicode;509    var isSymbolic = !!(properties.flags & FontFlags.Symbolic);510    var isIdentityUnicode = properties.toUnicode instanceof IdentityToUnicodeMap;511    var newMap = Object.create(null);512    var toFontChar = [];513    var usedFontCharCodes = [];514    var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;515    for (var originalCharCode in charCodeToGlyphId) {516      originalCharCode |= 0;517      var glyphId = charCodeToGlyphId[originalCharCode];518      if (missingGlyphs[glyphId]) {519        continue;520      }521      var fontCharCode = originalCharCode;522      var hasUnicodeValue = false;523      if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {524        hasUnicodeValue = true;525        var unicode = toUnicode.get(fontCharCode);526        if (unicode.length === 1) {527          fontCharCode = unicode.charCodeAt(0);528        }529      }530      if (usedFontCharCodes[fontCharCode] !== undefined || isProblematicUnicodeLocation(fontCharCode) || isSymbolic && !hasUnicodeValue) {531        do {532          if (nextAvailableFontCharCode > PRIVATE_USE_OFFSET_END) {533            (0, _util.warn)('Ran out of space in font private use area.');534            break;535          }536          fontCharCode = nextAvailableFontCharCode++;537          if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {538            fontCharCode = 0xF020;539            nextAvailableFontCharCode = fontCharCode + 1;540          }541        } while (usedFontCharCodes[fontCharCode] !== undefined);542      }543      newMap[fontCharCode] = glyphId;544      toFontChar[originalCharCode] = fontCharCode;545      usedFontCharCodes[fontCharCode] = true;546    }547    return {548      toFontChar: toFontChar,549      charCodeToGlyphId: newMap,550      nextAvailableFontCharCode: nextAvailableFontCharCode551    };552  }553  function getRanges(glyphs, numGlyphs) {554    var codes = [];555    for (var charCode in glyphs) {556      if (glyphs[charCode] >= numGlyphs) {557        continue;558      }559      codes.push({560        fontCharCode: charCode | 0,561        glyphId: glyphs[charCode]562      });563    }564    if (codes.length === 0) {565      codes.push({566        fontCharCode: 0,567        glyphId: 0568      });569    }570    codes.sort(function fontGetRangesSort(a, b) {571      return a.fontCharCode - b.fontCharCode;572    });573    var ranges = [];574    var length = codes.length;575    for (var n = 0; n < length;) {576      var start = codes[n].fontCharCode;577      var codeIndices = [codes[n].glyphId];578      ++n;579      var end = start;580      while (n < length && end + 1 === codes[n].fontCharCode) {581        codeIndices.push(codes[n].glyphId);582        ++end;583        ++n;584        if (end === 0xFFFF) {585          break;586        }587      }588      ranges.push([start, end, codeIndices]);589    }590    return ranges;591  }592  function createCmapTable(glyphs, numGlyphs) {593    var ranges = getRanges(glyphs, numGlyphs);594    var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;595    var cmap = '\x00\x00' + string16(numTables) + '\x00\x03' + '\x00\x01' + (0, _util.string32)(4 + numTables * 8);596    var i, ii, j, jj;597    for (i = ranges.length - 1; i >= 0; --i) {598      if (ranges[i][0] <= 0xFFFF) {599        break;600      }601    }602    var bmpLength = i + 1;603    if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {604      ranges[i][1] = 0xFFFE;605    }606    var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;607    var segCount = bmpLength + trailingRangesCount;608    var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);609    var startCount = '';610    var endCount = '';611    var idDeltas = '';612    var idRangeOffsets = '';613    var glyphsIds = '';614    var bias = 0;615    var range, start, end, codes;616    for (i = 0, ii = bmpLength; i < ii; i++) {617      range = ranges[i];618      start = range[0];619      end = range[1];620      startCount += string16(start);621      endCount += string16(end);622      codes = range[2];623      var contiguous = true;624      for (j = 1, jj = codes.length; j < jj; ++j) {625        if (codes[j] !== codes[j - 1] + 1) {626          contiguous = false;627          break;628        }629      }630      if (!contiguous) {631        var offset = (segCount - i) * 2 + bias * 2;632        bias += end - start + 1;633        idDeltas += string16(0);634        idRangeOffsets += string16(offset);635        for (j = 0, jj = codes.length; j < jj; ++j) {636          glyphsIds += string16(codes[j]);637        }638      } else {639        var startCode = codes[0];640        idDeltas += string16(startCode - start & 0xFFFF);641        idRangeOffsets += string16(0);642      }643    }644    if (trailingRangesCount > 0) {645      endCount += '\xFF\xFF';646      startCount += '\xFF\xFF';647      idDeltas += '\x00\x01';648      idRangeOffsets += '\x00\x00';649    }650    var format314 = '\x00\x00' + string16(2 * segCount) + string16(searchParams.range) + string16(searchParams.entry) + string16(searchParams.rangeShift) + endCount + '\x00\x00' + startCount + idDeltas + idRangeOffsets + glyphsIds;651    var format31012 = '';652    var header31012 = '';653    if (numTables > 1) {654      cmap += '\x00\x03' + '\x00\x0A' + (0, _util.string32)(4 + numTables * 8 + 4 + format314.length);655      format31012 = '';656      for (i = 0, ii = ranges.length; i < ii; i++) {657        range = ranges[i];658        start = range[0];659        codes = range[2];660        var code = codes[0];661        for (j = 1, jj = codes.length; j < jj; ++j) {662          if (codes[j] !== codes[j - 1] + 1) {663            end = range[0] + j - 1;664            format31012 += (0, _util.string32)(start) + (0, _util.string32)(end) + (0, _util.string32)(code);665            start = end + 1;666            code = codes[j];667          }668        }669        format31012 += (0, _util.string32)(start) + (0, _util.string32)(range[1]) + (0, _util.string32)(code);670      }671      header31012 = '\x00\x0C' + '\x00\x00' + (0, _util.string32)(format31012.length + 16) + '\x00\x00\x00\x00' + (0, _util.string32)(format31012.length / 12);672    }673    return cmap + '\x00\x04' + string16(format314.length + 4) + format314 + header31012 + format31012;674  }675  function validateOS2Table(os2) {676    var stream = new _stream.Stream(os2.data);677    var version = stream.getUint16();678    stream.getBytes(60);679    var selection = stream.getUint16();680    if (version < 4 && selection & 0x0300) {681      return false;682    }683    var firstChar = stream.getUint16();684    var lastChar = stream.getUint16();685    if (firstChar > lastChar) {686      return false;687    }688    stream.getBytes(6);689    var usWinAscent = stream.getUint16();690    if (usWinAscent === 0) {691      return false;692    }693    os2.data[8] = os2.data[9] = 0;694    return true;695  }696  function createOS2Table(properties, charstrings, override) {697    override = override || {698      unitsPerEm: 0,699      yMax: 0,700      yMin: 0,701      ascent: 0,702      descent: 0703    };704    var ulUnicodeRange1 = 0;705    var ulUnicodeRange2 = 0;706    var ulUnicodeRange3 = 0;707    var ulUnicodeRange4 = 0;708    var firstCharIndex = null;709    var lastCharIndex = 0;710    if (charstrings) {711      for (var code in charstrings) {712        code |= 0;713        if (firstCharIndex > code || !firstCharIndex) {714          firstCharIndex = code;715        }716        if (lastCharIndex < code) {717          lastCharIndex = code;718        }719        var position = (0, _unicode.getUnicodeRangeFor)(code);720        if (position < 32) {721          ulUnicodeRange1 |= 1 << position;722        } else if (position < 64) {723          ulUnicodeRange2 |= 1 << position - 32;724        } else if (position < 96) {725          ulUnicodeRange3 |= 1 << position - 64;726        } else if (position < 123) {727          ulUnicodeRange4 |= 1 << position - 96;728        } else {729          throw new _util.FormatError('Unicode ranges Bits > 123 are reserved for internal usage');730        }731      }732    } else {733      firstCharIndex = 0;734      lastCharIndex = 255;735    }736    var bbox = properties.bbox || [0, 0, 0, 0];737    var unitsPerEm = override.unitsPerEm || 1 / (properties.fontMatrix || _util.FONT_IDENTITY_MATRIX)[0];738    var scale = properties.ascentScaled ? 1.0 : unitsPerEm / PDF_GLYPH_SPACE_UNITS;739    var typoAscent = override.ascent || Math.round(scale * (properties.ascent || bbox[3]));740    var typoDescent = override.descent || Math.round(scale * (properties.descent || bbox[1]));741    if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {742      typoDescent = -typoDescent;743    }744    var winAscent = override.yMax || typoAscent;745    var winDescent = -override.yMin || -typoDescent;746    return '\x00\x03' + '\x02\x24' + '\x01\xF4' + '\x00\x05' + '\x00\x00' + '\x02\x8A' + '\x02\xBB' + '\x00\x00' + '\x00\x8C' + '\x02\x8A' + '\x02\xBB' + '\x00\x00' + '\x01\xDF' + '\x00\x31' + '\x01\x02' + '\x00\x00' + '\x00\x00\x06' + String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) + '\x00\x00\x00\x00\x00\x00' + (0, _util.string32)(ulUnicodeRange1) + (0, _util.string32)(ulUnicodeRange2) + (0, _util.string32)(ulUnicodeRange3) + (0, _util.string32)(ulUnicodeRange4) + '\x2A\x32\x31\x2A' + string16(properties.italicAngle ? 1 : 0) + string16(firstCharIndex || properties.firstChar) + string16(lastCharIndex || properties.lastChar) + string16(typoAscent) + string16(typoDescent) + '\x00\x64' + string16(winAscent) + string16(winDescent) + '\x00\x00\x00\x00' + '\x00\x00\x00\x00' + string16(properties.xHeight) + string16(properties.capHeight) + string16(0) + string16(firstCharIndex || properties.firstChar) + '\x00\x03';747  }748  function createPostTable(properties) {749    var angle = Math.floor(properties.italicAngle * Math.pow(2, 16));750    return '\x00\x03\x00\x00' + (0, _util.string32)(angle) + '\x00\x00' + '\x00\x00' + (0, _util.string32)(properties.fixedPitch) + '\x00\x00\x00\x00' + '\x00\x00\x00\x00' + '\x00\x00\x00\x00' + '\x00\x00\x00\x00';751  }752  function createNameTable(name, proto) {753    if (!proto) {754      proto = [[], []];755    }756    var strings = [proto[0][0] || 'Original licence', proto[0][1] || name, proto[0][2] || 'Unknown', proto[0][3] || 'uniqueID', proto[0][4] || name, proto[0][5] || 'Version 0.11', proto[0][6] || '', proto[0][7] || 'Unknown', proto[0][8] || 'Unknown', proto[0][9] || 'Unknown'];757    var stringsUnicode = [];758    var i, ii, j, jj, str;759    for (i = 0, ii = strings.length; i < ii; i++) {760      str = proto[1][i] || strings[i];761      var strBufUnicode = [];762      for (j = 0, jj = str.length; j < jj; j++) {763        strBufUnicode.push(string16(str.charCodeAt(j)));764      }765      stringsUnicode.push(strBufUnicode.join(''));766    }767    var names = [strings, stringsUnicode];768    var platforms = ['\x00\x01', '\x00\x03'];769    var encodings = ['\x00\x00', '\x00\x01'];770    var languages = ['\x00\x00', '\x04\x09'];771    var namesRecordCount = strings.length * platforms.length;772    var nameTable = '\x00\x00' + string16(namesRecordCount) + string16(namesRecordCount * 12 + 6);773    var strOffset = 0;774    for (i = 0, ii = platforms.length; i < ii; i++) {775      var strs = names[i];776      for (j = 0, jj = strs.length; j < jj; j++) {777        str = strs[j];778        var nameRecord = platforms[i] + encodings[i] + languages[i] + string16(j) + string16(str.length) + string16(strOffset);779        nameTable += nameRecord;780        strOffset += str.length;781      }782    }783    nameTable += strings.join('') + stringsUnicode.join('');784    return nameTable;785  }786  Font.prototype = {787    name: null,788    font: null,789    mimetype: null,790    encoding: null,791    get renderer() {792      var renderer = _font_renderer.FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);793      return (0, _util.shadow)(this, 'renderer', renderer);794    },795    exportData: function Font_exportData() {796      var data = {};797      for (var i in this) {798        if (this.hasOwnProperty(i)) {799          data[i] = this[i];800        }801      }802      return data;803    },804    fallbackToSystemFont: function Font_fallbackToSystemFont() {805      var _this = this;806      this.missingFile = true;807      var charCode, unicode;808      var name = this.name;809      var type = this.type;810      var subtype = this.subtype;811      var fontName = name.replace(/[,_]/g, '-');812      var stdFontMap = (0, _standard_fonts.getStdFontMap)(),813          nonStdFontMap = (0, _standard_fonts.getNonStdFontMap)();814      var isStandardFont = !!stdFontMap[fontName] || !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);815      fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;816      this.bold = fontName.search(/bold/gi) !== -1;817      this.italic = fontName.search(/oblique/gi) !== -1 || fontName.search(/italic/gi) !== -1;818      this.black = name.search(/Black/g) !== -1;819      this.remeasure = Object.keys(this.widths).length > 0;820      if (isStandardFont && type === 'CIDFontType2' && this.cidEncoding.indexOf('Identity-') === 0) {821        var GlyphMapForStandardFonts = (0, _standard_fonts.getGlyphMapForStandardFonts)();822        var map = [];823        for (charCode in GlyphMapForStandardFonts) {824          map[+charCode] = GlyphMapForStandardFonts[charCode];825        }826        if (/Arial-?Black/i.test(name)) {827          var SupplementalGlyphMapForArialBlack = (0, _standard_fonts.getSupplementalGlyphMapForArialBlack)();828          for (charCode in SupplementalGlyphMapForArialBlack) {829            map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];830          }831        }832        var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;833        if (!isIdentityUnicode) {834          this.toUnicode.forEach(function (charCode, unicodeCharCode) {835            map[+charCode] = unicodeCharCode;836          });837        }838        this.toFontChar = map;839        this.toUnicode = new ToUnicodeMap(map);840      } else if (/Symbol/i.test(fontName)) {841        this.toFontChar = buildToFontChar(_encodings.SymbolSetEncoding, (0, _glyphlist.getGlyphsUnicode)(), this.differences);842      } else if (/Dingbats/i.test(fontName)) {843        if (/Wingdings/i.test(name)) {844          (0, _util.warn)('Non-embedded Wingdings font, falling back to ZapfDingbats.');845        }846        this.toFontChar = buildToFontChar(_encodings.ZapfDingbatsEncoding, (0, _glyphlist.getDingbatsGlyphsUnicode)(), this.differences);847      } else if (isStandardFont) {848        this.toFontChar = buildToFontChar(this.defaultEncoding, (0, _glyphlist.getGlyphsUnicode)(), this.differences);849      } else {850        var glyphsUnicodeMap = (0, _glyphlist.getGlyphsUnicode)();851        this.toUnicode.forEach(function (charCode, unicodeCharCode) {852          if (!_this.composite) {853            var glyphName = _this.differences[charCode] || _this.defaultEncoding[charCode];854            unicode = (0, _unicode.getUnicodeForGlyph)(glyphName, glyphsUnicodeMap);855            if (unicode !== -1) {856              unicodeCharCode = unicode;857            }858          }859          _this.toFontChar[charCode] = unicodeCharCode;860        });861      }862      this.loadedName = fontName.split('-')[0];...Using AI Code Generation
1var wptext = require('wptext');2var text = 'Hello World';3var font = 'Arial';4var size = 12;5var color = '000000';6var output = wptext.buildToFontChar(text, font, size, color);7console.log(output);8var wptext = require('wptext');9var text = 'Hello World';10var font = 'Arial';11var size = 12;12var color = '000000';13var output = wptext.buildToFontChar(text, font, size, color);14console.log(output);15var wptext = require('wptext');16var text = 'Hello World';17var font = 'Arial';18var size = 12;19var color = '000000';20var output = wptext.buildToFontChar(text, font, size, color);21console.log(output);22var wptext = require('wptext');23var text = 'Hello World';24var font = 'Arial';25var size = 12;26var color = '000000';27var output = wptext.buildToFontChar(text, font, size, color);28console.log(output);29var wptext = require('wptext');30var text = 'Hello World';31var font = 'Arial';32var size = 12;33var color = '000000';34var output = wptext.buildToFontChar(text, font, size, color);35console.log(output);Using AI Code Generation
1var wptext = require("wptext");2var options = {3};4var text = wptext.buildToFontChar("Hello World", options);5console.log(text);6var wptext = require("wptext");7var options = {8};9var text = wptext.buildToFontChar("Hello World", options);10console.log(text);11var wptext = require("wptext");12var options = {13};14var text = wptext.buildToFontChar("Hello World", options);15console.log(text);Using AI Code Generation
1var encoder = new TextEncoder();2var data = encoder.encodeToFontChars("Hello World");3console.log(data);4  import { TextEncoder } from "./test.js";5  var encoder = new TextEncoder();6  var data = encoder.encodeToFontChars("Hello World");7  console.log(data);8  var encoder = new TextEncoder();9  var data = encoder.encodeToFontChars("Hello World");10  console.log(data);11var encoder = new TextEncoder();12var data = encoder.encodeToFontChars("Hello World");13console.log(data);14  import { TextEncoder } from "./test.js";15  var encoder = new TextEncoder();16  var data = encoder.encodeToFontChars("Hello World");17  console.log(data);18  var encoder = new TextEncoder();19  var data = encoder.encodeToFontChars("Hello World");20  console.log(data);21var encoder = new TextEncoder();22var data = encoder.encodeToFontChars("Hello World");23console.log(data);24  import { TextEncoder } from "./test.js";25  var encoder = new TextEncoder();26  var data = encoder.encodeToFontChars("Hello World");27  console.log(data);28  var encoder = new TextEncoder();29  var data = encoder.encodeToFontChars("Hello World");30  console.log(data);31var encoder = new TextEncoder();32var data = encoder.encodeToFontChars("Hello World");33console.log(data);Using AI Code Generation
1var wptext = require('wptext');2var mytext = new wptext();3var font = mytext.buildToFontChar('Hello World');4console.log(font);5var wptext = require('wptext');6var mytext = new wptext();7var font = mytext.buildToFontChar('Hello World',12,'normal','normal','#000000','left',1.2,'Arial','none');8console.log(font);9var wptext = require('wptext');10var mytext = new wptext();11var font = mytext.buildToFontChar('Hello World',12,'normal','normal','#000000','left',1.2,'Arial','none');12console.log(font);13var wptext = require('wptext');14var mytext = new wptext();15var color = mytext.buildToColorChar('#000000');16console.log(color);17var wptext = require('wptext');18var mytext = new wptext();19var color = mytext.buildToColorChar('#000000');20console.log(color);21var wptext = require('wptUsing AI Code Generation
1var wptext = require('wptext');2var font = wptext.buildToFontChar("Hello World", "Arial", 12, 12, "red", "black");3var wptext = require('wptext');4var font = wptext.buildToFontChar("Hello World", "Arial", 12, 12, "red", "black");5var wptext = require('wptext');6var font = wptext.buildToFontChar("Hello World", "Arial", 12, 12, "red", "black");7var wptext = require('wptext');8var font = wptext.buildToFontChar("Hello World", "Arial", 12, 12, "red", "black");9var wptext = require('wptext');10var font = wptext.buildToFontChar("Hello World", "Arial", 12, 12, "red", "black");11var wptext = require('wptext');12var font = wptext.buildToFontChar("Hello World", "Arial", 12, 12, "red", "black");13var wptext = require('wptext');14var font = wptext.buildToFontChar("Hello World", "Arial", 12, 12, "red", "black");15var wptext = require('wptext');Using AI Code Generation
1var editor = new WpTextEditor();2var fontChar = editor.buildToFontChar("Hello World");3var editor = new WpTextEditor();4var fontChar = editor.buildToFontChar("Hello World");5var editor = new WpTextEditor();6var fontChar = editor.buildToFontChar("Hello World");7var editor = new WpTextEditor();8var fontChar = editor.buildToFontChar("Hello World");9var editor = new WpTextEditor();10var fontChar = editor.buildToFontChar("Hello World");11var editor = new WpTextEditor();12var fontChar = editor.buildToFontChar("Hello World");13var editor = new WpTextEditor();14var fontChar = editor.buildToFontChar("Hello World");15var editor = new WpTextEditor();16var fontChar = editor.buildToFontChar("Hello World");17var editor = new WpTextEditor();18var fontChar = editor.buildToFontChar("Hello World");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!!
