How to use OpenTypeFileBuilder method in wpt

Best JavaScript code snippet using wpt

opentype_file_builder.js

Source:opentype_file_builder.js Github

copy

Full Screen

1/**2 * @licstart The following is the entire license notice for the3 * Javascript code in this page4 *5 * Copyright 2021 Mozilla Foundation6 *7 * Licensed under the Apache License, Version 2.0 (the "License");8 * you may not use this file except in compliance with the License.9 * You may obtain a copy of the License at10 *11 * http://www.apache.org/licenses/LICENSE-2.012 *13 * Unless required by applicable law or agreed to in writing, software14 * distributed under the License is distributed on an "AS IS" BASIS,15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16 * See the License for the specific language governing permissions and17 * limitations under the License.18 *19 * @licend The above is the entire license notice for the20 * Javascript code in this page21 */22"use strict";23Object.defineProperty(exports, "__esModule", {24 value: true25});26exports.OpenTypeFileBuilder = void 0;27var _core_utils = require("./core_utils.js");28var _util = require("../shared/util.js");29function writeInt16(dest, offset, num) {30 dest[offset] = num >> 8 & 0xff;31 dest[offset + 1] = num & 0xff;32}33function writeInt32(dest, offset, num) {34 dest[offset] = num >> 24 & 0xff;35 dest[offset + 1] = num >> 16 & 0xff;36 dest[offset + 2] = num >> 8 & 0xff;37 dest[offset + 3] = num & 0xff;38}39function writeData(dest, offset, data) {40 if (data instanceof Uint8Array) {41 dest.set(data, offset);42 } else if (typeof data === "string") {43 for (let i = 0, ii = data.length; i < ii; i++) {44 dest[offset++] = data.charCodeAt(i) & 0xff;45 }46 } else {47 for (let i = 0, ii = data.length; i < ii; i++) {48 dest[offset++] = data[i] & 0xff;49 }50 }51}52const OTF_HEADER_SIZE = 12;53const OTF_TABLE_ENTRY_SIZE = 16;54class OpenTypeFileBuilder {55 constructor(sfnt) {56 this.sfnt = sfnt;57 this.tables = Object.create(null);58 }59 static getSearchParams(entriesCount, entrySize) {60 let maxPower2 = 1,61 log2 = 0;62 while ((maxPower2 ^ entriesCount) > maxPower2) {63 maxPower2 <<= 1;64 log2++;65 }66 const searchRange = maxPower2 * entrySize;67 return {68 range: searchRange,69 entry: log2,70 rangeShift: entrySize * entriesCount - searchRange71 };72 }73 toArray() {74 let sfnt = this.sfnt;75 const tables = this.tables;76 const tablesNames = Object.keys(tables);77 tablesNames.sort();78 const numTables = tablesNames.length;79 let i, j, jj, table, tableName;80 let offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;81 const tableOffsets = [offset];82 for (i = 0; i < numTables; i++) {83 table = tables[tablesNames[i]];84 const paddedLength = (table.length + 3 & ~3) >>> 0;85 offset += paddedLength;86 tableOffsets.push(offset);87 }88 const file = new Uint8Array(offset);89 for (i = 0; i < numTables; i++) {90 table = tables[tablesNames[i]];91 writeData(file, tableOffsets[i], table);92 }93 if (sfnt === "true") {94 sfnt = (0, _util.string32)(0x00010000);95 }96 file[0] = sfnt.charCodeAt(0) & 0xff;97 file[1] = sfnt.charCodeAt(1) & 0xff;98 file[2] = sfnt.charCodeAt(2) & 0xff;99 file[3] = sfnt.charCodeAt(3) & 0xff;100 writeInt16(file, 4, numTables);101 const searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);102 writeInt16(file, 6, searchParams.range);103 writeInt16(file, 8, searchParams.entry);104 writeInt16(file, 10, searchParams.rangeShift);105 offset = OTF_HEADER_SIZE;106 for (i = 0; i < numTables; i++) {107 tableName = tablesNames[i];108 file[offset] = tableName.charCodeAt(0) & 0xff;109 file[offset + 1] = tableName.charCodeAt(1) & 0xff;110 file[offset + 2] = tableName.charCodeAt(2) & 0xff;111 file[offset + 3] = tableName.charCodeAt(3) & 0xff;112 let checksum = 0;113 for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {114 const quad = (0, _core_utils.readUint32)(file, j);115 checksum = checksum + quad >>> 0;116 }117 writeInt32(file, offset + 4, checksum);118 writeInt32(file, offset + 8, tableOffsets[i]);119 writeInt32(file, offset + 12, tables[tableName].length);120 offset += OTF_TABLE_ENTRY_SIZE;121 }122 return file;123 }124 addTable(tag, data) {125 if (tag in this.tables) {126 throw new Error("Table " + tag + " already exists");127 }128 this.tables[tag] = data;129 }130}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var OpenTypeFileBuilder = require('./wptext.js').OpenTypeFileBuilder;3var otfb = new OpenTypeFileBuilder();4var font = otfb.addFont('MyFont', 'MyFont.ttf');5var style = font.addStyle('MyTextStyle');6var run = style.addRun('Hello world!');7var otf = otfb.build();8fs.writeFileSync('test.otf', otf);

Full Screen

Using AI Code Generation

copy

Full Screen

1var font = new opentype.Font({2});3var path = new opentype.Path();4path.moveTo(250, 75);5path.lineTo(333, 301);6path.lineTo(131, 161);7path.lineTo(369, 161);8path.lineTo(167, 301);9path.closePath();10font.addGlyph({name: 'A', unicode: 65, path: path});11var path = new opentype.Path();12path.moveTo(500, 75);13path.lineTo(583, 301);14path.lineTo(381, 161);15path.lineTo(619, 161);16path.lineTo(417, 301);17path.closePath();18font.addGlyph({name: 'B', unicode: 66, path: path});19var path = new opentype.Path();20path.moveTo(750, 75);21path.lineTo(833, 301);22path.lineTo(631, 161);23path.lineTo(869, 161);24path.lineTo(667, 301);25path.closePath();26font.addGlyph({name: 'C', unicode: 67, path: path});27var path = new opentype.Path();28path.moveTo(250, 375);29path.lineTo(333, 601);30path.lineTo(131, 461);31path.lineTo(369, 461);32path.lineTo(167, 601);33path.closePath();34font.addGlyph({name: 'D', unicode: 68, path: path});35var path = new opentype.Path();36path.moveTo(500, 375);37path.lineTo(583, 601);38path.lineTo(381, 461);39path.lineTo(619, 461);40path.lineTo(417, 601);41path.closePath();42font.addGlyph({name: 'E', unicode: 69, path: path});43var path = new opentype.Path();44path.moveTo(750, 375);45path.lineTo(833, 601);46path.lineTo(631, 461);47path.lineTo(869, 461);48path.lineTo(667, 601);49path.closePath();50font.addGlyph({name: 'F', unicode: 70, path: path});51var path = new opentype.Path();52path.moveTo(250, 675);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var font = new wptools.OpenTypeFileBuilder();4font.addGlyph("A", 500, 0, 0, 0, 0, [ [ 0, 0 ], [ 0, 1000 ], [ 500, 1000 ], [ 500, 0 ] ]);5font.addGlyph("B", 500, 0, 0, 0, 0, [ [ 0, 0 ], [ 0, 1000 ], [ 500, 1000 ], [ 500, 0 ] ]);6font.addGlyph("C", 500, 0, 0, 0, 0, [ [ 0, 0 ], [ 0, 1000 ], [ 500, 1000 ], [ 500, 0 ] ]);7var fontFile = font.build();8fs.writeFileSync("testfont.otf", fontFile);9var wptools = require('wptools');10var fs = require('fs');11var font = new wptools.OpenTypeFileBuilder();12font.addGlyph("A", 500, 0, 0, 0, 0, [ [ 0, 0 ], [ 0, 1000 ], [ 500, 1000 ], [ 500, 0 ] ]);13font.addGlyph("B", 500, 0, 0, 0, 0, [ [ 0, 0 ], [ 0, 1000 ], [ 500, 1000 ], [ 500, 0 ] ]);14font.addGlyph("C", 500, 0, 0, 0, 0, [ [ 0, 0 ], [ 0, 1000 ], [ 500, 1000 ], [ 500, 0 ] ]);15var fontFile = font.build();16fs.writeFileSync("testfont.otf", fontFile);17var wptools = require('wptools');18var font = new wptools.OpenTypeFileBuilder();19font.addGlyph("A", 500, 0, 0, 0, 0, [ [ 0, 0 ], [ 0, 1000 ], [ 500

Full Screen

Using AI Code Generation

copy

Full Screen

1var OpenTypeFileBuilder = require('opentype.js').OpenTypeFileBuilder;2var fs = require('fs');3var font = new OpenTypeFileBuilder();4font.addGlyph({5});6font.addGlyph({7});8font.addKerningPair('a', 'b', 100);9font.download('myfont.ttf');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2var fs = require('fs');3var font = new wpt.OpenTypeFileBuilder();4font.addTable("head", new wpt.Table_head());5font.addTable("name", new wpt.Table_name());6font.addTable("OS/2", new wpt.Table_OS_2());7font.addTable("cmap", new wpt.Table_cmap());8font.addTable("hhea", new wpt.Table_hhea());9font.addTable("maxp", new wpt.Table_maxp());10font.addTable("hmtx", new wpt.Table_hmtx());11font.addTable("post", new wpt.Table_post());12var fontData = font.serialize();13fs.writeFileSync("test.otf", fontData);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('web-platform-test');2var fs = require('fs');3var builder = new wpt.OpenTypeFileBuilder();4builder.addTable('head', 0, 0, function (table) {5 table.version = 1.0;6 table.fontRevision = 1.0;7 table.checkSumAdjustment = 0;8 table.magicNumber = 0x5F0F3CF5;9 table.flags = 0;10 table.unitsPerEm = 1000;11 table.created = 0;12 table.modified = 0;13 table.xMin = 0;14 table.yMin = 0;15 table.xMax = 0;16 table.yMax = 0;17 table.macStyle = 0;18 table.lowestRecPPEM = 0;19 table.fontDirectionHint = 0;20 table.indexToLocFormat = 0;21 table.glyphDataFormat = 0;22});23builder.addTable('hhea', 0, 0, function (table) {24 table.version = 1.0;25 table.ascender = 0;26 table.descender = 0;27 table.lineGap = 0;28 table.advanceWidthMax = 0;29 table.minLeftSideBearing = 0;30 table.minRightSideBearing = 0;31 table.xMaxExtent = 0;32 table.caretSlopeRise = 0;33 table.caretSlopeRun = 0;34 table.caretOffset = 0;35 table.reserved = [0, 0, 0, 0, 0, 0];36 table.metricDataFormat = 0;37 table.numberOfHMetrics = 0;38});39builder.addTable('maxp', 0, 0, function (table) {40 table.version = 1.0;41 table.numGlyphs = 0;42});43builder.addTable('hmtx', 0, 0, function (table) {44 table.metrics = [];45});46builder.addTable('OS/2', 0, 0, function (table) {47 table.version = 0x0001;48 table.xAvgCharWidth = 0;49 table.usWeightClass = 0;50 table.usWidthClass = 0;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = new ActiveXObject("WPT.OpenTypeFileBuilder");2var font = new ActiveXObject("WPT.Font");3var fontFile = wpt.CreateFontFile(font);4fontFile.Save("test.otf");5var wpt = new ActiveXObject("WPT.OpenTypeFileBuilder");6var font = new ActiveXObject("WPT.Font");7var fontFile = wpt.CreateFontFile(font);8fontFile.Save("test.otf");9var wpt = new ActiveXObject("WPT.OpenTypeFileBuilder");10var font = new ActiveXObject("WPT.Font");11var fontFile = wpt.CreateFontFile(font);12fontFile.Save("test.otf");13var wpt = new ActiveXObject("WPT.OpenTypeFileBuilder");14var font = new ActiveXObject("WPT.Font");15var fontFile = wpt.CreateFontFile(font);16fontFile.Save("test.otf");17var wpt = new ActiveXObject("WPT.OpenTypeFileBuilder");18var font = new ActiveXObject("WPT.Font");19var fontFile = wpt.CreateFontFile(font);20fontFile.Save("test.otf");21var wpt = new ActiveXObject("WPT.OpenTypeFileBuilder");22var font = new ActiveXObject("WPT.Font");23var fontFile = wpt.CreateFontFile(font);24fontFile.Save("test.otf");25var wpt = new ActiveXObject("WPT.OpenTypeFileBuilder");26var font = new ActiveXObject("WPT.Font");27var fontFile = wpt.CreateFontFile(font);28fontFile.Save("test.otf");

Full Screen

Using AI Code Generation

copy

Full Screen

1var font = new OpenTypeFileBuilder();2font.addGlyph(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);3font.addGlyph(2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);4font.addGlyph(3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);5font.addGlyph(4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);6font.addGlyph(5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);7font.addGlyph(6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);8font.addGlyph(7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);9font.addGlyph(8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);10font.addGlyph(9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);11font.addGlyph(10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);12font.addGlyph(11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);13font.addGlyph(12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);14font.addGlyph(13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);15font.addGlyph(14

Full Screen

Using AI Code Generation

copy

Full Screen

1var builder = new wptools.OpenTypeFileBuilder();2builder.loadFile("existingFont.otf");3var font = builder.getFont();4var glyf = font.tables.glyf;5var aGlyph = glyf.glyphs["A"];6var aContours = aGlyph.contours;7var contour = new wptools.Contour();8contour.points.push(new wptools.Point(0, 0));9aContours.push(contour);10builder.saveFile("newFont.otf");11var builder = new wptools.OpenTypeFileBuilder();12var font = new wptools.Font();13var glyf = new wptools.GlyfTable();14var aGlyph = new wptools.Glyph();15var contour = new wptools.Contour();16contour.points.push(new wptools.Point(0, 0));17aGlyph.contours.push(contour);18glyf.glyphs["A"] = aGlyph;19font.tables.glyf = glyf;20builder.setFont(font);21builder.saveFile("newFont.otf");22var builder = new wptools.OpenTypeFileBuilder();23var font = new wptools.Font();

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