How to use CFFIndex method in wpt

Best JavaScript code snippet using wpt

cff_index.js

Source:cff_index.js Github

copy

Full Screen

1'use strict';2/**3 * @license4 * Copyright 2015 Google Inc. All rights reserved.5 *6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not7 * use this file except in compliance with the License. You may obtain a copy of8 * the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the15 * License for the specific language governing permissions and limitations under16 * the License.17 */18goog.provide('tachyfont.CffIndex');19goog.require('tachyfont.CffDict');20/**21 * This class reads a CFF (Adobe's Compact Font Format) INDEX.22 * See cff.js for an overview of how the CFF table is being modified.23 * For a detailed description of a CFF INDEX @see24 * http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/font/pdfs/5176.CFF.pdf25 * For a detailed description of the OpenType font format @see26 * http://www.microsoft.com/typography/otspec/27 * @param {string} name The table name.28 * @param {number} offset The offset from start of the CFF table.29 * @param {!tachyfont.CffIndex.type} type Indicates the data type in the index.30 * @param {!tachyfont.BinaryFontEditor} binaryEditor A binary font editor.31 * @constructor @struct @final32 */33tachyfont.CffIndex = function(name, offset, type, binaryEditor) {34 /** @private @const {string} */35 this.name_ = name;36 /**37 * The offset in the CFF table to this INDEX.38 * @private @const {number} */39 this.offsetToIndex_ = offset;40 /**41 * The type of the elements in this INDEX.42 * Possible types are STRING, BINARY_STRING, and (CFF) DICT.43 * @private @const {!tachyfont.CffIndex.type}44 */45 this.type_ = type;46 /** @private {!Array<string|!DataView|!tachyfont.CffDict>} */47 this.elements_ = [];48 binaryEditor.seek(offset);49 // Get the INDEX's count.50 var count = binaryEditor.getUint16();51 /**52 * The number offsets.53 * Note: not strictly following the CFF spec here. The spec says an empty54 * INDEX (count == 0) is only 2 bytes long (ie: does not have a offsetSize nor55 * any offsets). However, all the fonts handled by TachyFont have been56 * processed by fontTools and it always adds a 0x01 byte for offsetSize and a57 * single 0x01 byte for the offsets array.58 * @private @const {number}59 */60 this.numberOfOffsets_ = count + 1;61 /**62 * The number of bytes per element in the offset array.63 * @private @const {number}64 */65 this.offsetSize_ = binaryEditor.getUint8();66 /**67 * The offsets array.68 * Note: that offsets are 1-indexed; ie: the element[0] is at offset 1.69 * @private {!Array<number>}70 */71 this.offsets_ = [];72 // Read in the offsets.73 for (var i = 0; i < this.numberOfOffsets_; i++) {74 var elementOffset = binaryEditor.getElementOffset(this.offsetSize_);75 this.offsets_.push(elementOffset);76 }77 /**78 * Calculate the INDEX length.79 * @private @const {number}80 */81 this.indexByteLength_ =82 2 + // The count field size.83 1 + // The offsetSize field size (indicates the bytes per offset).84 this.numberOfOffsets_ * this.offsetSize_ + // The offsets array size.85 this.offsets_[this.numberOfOffsets_ - 1] - 1; // The elements size.86};87/**88 * Computes a CFF INDEX's length.89 * @param {number} offset The offset from start of the CFF table.90 * @param {!tachyfont.BinaryFontEditor} binaryEditor A binary font editor.91 * @return {number} The length of the INDEX.92 */93tachyfont.CffIndex.computeLength = function(offset, binaryEditor) {94 var tmpIndex = new tachyfont.CffIndex('tmpName', offset,95 tachyfont.CffIndex.type.STRING, binaryEditor);96 return tmpIndex.indexByteLength_;97};98/**99 * Gets the INDEX's name.100 * @return {string}101 */102tachyfont.CffIndex.prototype.getName = function() {103 return this.name_;104};105/**106 * Gets the offset in the CFF table to this INDEX.107 * @return {number}108 */109tachyfont.CffIndex.prototype.getOffsetToIndex = function() {110 return this.offsetToIndex_;111};112/**113 * Defines the type of data held in a CFF INDEX.114 * @enum {number}115 */116tachyfont.CffIndex.type = {117 /** The INDEX hold human readable strings. */118 STRING: 1,119 /** The INDEX hold binary strings. */120 BINARY_STRING: 2,121 /** The INDEX hold CFF DICT(s). */122 DICT: 3123};124/**125 * Gets an INDEX element.126 * @param {number} index The index of the element.127 * @return {?(tachyfont.CffDict|DataView|string)} A element from the INDEX.128 */129tachyfont.CffIndex.prototype.getElement = function(index) {130 if (index in this.elements_) {131 return this.elements_[index];132 }133 return null;134};135/**136 * Gets an INDEX DICT element.137 * @param {number} index The index of the element.138 * @return {?tachyfont.CffDict} The DICT element from the INDEX.139 */140tachyfont.CffIndex.prototype.getDictElement = function(index) {141 // TODO(bstell): make subclasses instead of testing for type.142 if (this.type_ != tachyfont.CffIndex.type.DICT) {143 return null;144 }145 if (index in this.elements_) {146 return /** @type {!tachyfont.CffDict} */ (this.elements_[index]);147 }148 return null;149};150/**151 * Gets the offsetSize of elements.152 * This is the number of bytes used by each element offset.153 * @return {number} The offsetSize of elements.154 */155tachyfont.CffIndex.prototype.getOffsetSize = function() {156 return this.offsetSize_;157};158/**159 * Gets the number of offsets.160 * @return {number}161 */162tachyfont.CffIndex.prototype.getNumberOfOffsets = function() {163 return this.numberOfOffsets_;164};165/**166 * Gets the elements lenght.167 * @return {number}168 */169tachyfont.CffIndex.prototype.getNumberOfElements = function() {170 return this.elements_.length;171};172/**173 * Gets the elements.174 * @return {!Array<string|!DataView|!tachyfont.CffDict>} The elements.175 */176tachyfont.CffIndex.prototype.getElements = function() {177 return this.elements_;178};179/**180 * Pushes an element.181 * @param {string|!DataView|!tachyfont.CffDict} element An element to push.182 */183tachyfont.CffIndex.prototype.pushElement = function(element) {184 this.elements_.push(element);185};186/**187 * Gets the element's offset from the beginning of the INDEX.188 * When lazily loading glyph data this is needed to update the CharStrings data189 * and the DICT data.190 * @param {number} index The index to get the offset for.191 * @return {number} The element's offset.192 */193tachyfont.CffIndex.prototype.getAdjustedElementOffset = function(index) {194 var offset = 2 + 1 + (this.offsetSize_ * this.numberOfOffsets_) - 1;195 return offset + this.offsets_[index];196};197/**198 * Gets the element offsets.199 * @return {!Array<number>} The element offsets.200 */201tachyfont.CffIndex.prototype.getOffsets = function() {202 return this.offsets_;203};204/**205 * Gets the number of bytes used by this INDEX.206 * @return {number} The length of the table.207 */208tachyfont.CffIndex.prototype.getIndexByteLength = function() {209 return this.indexByteLength_;210};211/**212 * Gets the table type.213 * TODO(bstell): make subclasses for binary string and DICT.214 * @return {number} The type of the table.215 */216tachyfont.CffIndex.prototype.getType = function() {217 return this.type_;218};219/**220 * Loads the INDEX strings.221 * TODO(bstell): put this in a binary string subclass.222 * @param {!tachyfont.BinaryFontEditor} binaryEditor A binary font editor.223 */224tachyfont.CffIndex.prototype.loadStrings = function(binaryEditor) {225 var dataStart = this.offsetToIndex_ + 2 + 1 +226 this.numberOfOffsets_ * this.offsetSize_;227 binaryEditor.seek(dataStart);228 var count = this.numberOfOffsets_ - 1;229 for (var i = 0; i < count; i++) {230 var dataLength = this.offsets_[i + 1] - this.offsets_[i];231 if (this.type_ == tachyfont.CffIndex.type.STRING) {232 var str = binaryEditor.readString(dataLength);233 this.elements_.push(str);234 } else {235 var dataView = binaryEditor.readDataView(dataLength);236 this.elements_.push(dataView);237 }238 }239};240/**241 * Loads the INDEX DICTs.242 * TODO(bstell): put this in a DICT subclass.243 * @param {!tachyfont.BinaryFontEditor} binaryEditor A binary font editor.244 */245tachyfont.CffIndex.prototype.loadDicts = function(binaryEditor) {246 if (this.type_ != tachyfont.CffIndex.type.DICT) {247 // Library fatal error: something is deeply wrong; perhaps a bad font. No248 // recovery is possible.249 throw new Error(this.name_ + ' does not hold DICTS');250 }251 var dataView = binaryEditor.getDataView();252 var arrayBuffer = dataView.buffer;253 var dataStart = this.offsetToIndex_ + 2 + 1 +254 this.numberOfOffsets_ * this.offsetSize_;255 var count = this.numberOfOffsets_ - 1;256 for (var i = 0; i < count; i++) {257 var name = this.name_ + i;258 var length = this.offsets_[i + 1] - this.offsets_[i];259 var offset = dataView.byteOffset + binaryEditor.getBaseOffset() +260 dataStart + this.offsets_[i] - 1;261 var dictDataView = new DataView(arrayBuffer, offset, length);262 var dict = new tachyfont.CffDict(name, dictDataView);263 this.elements_.push(dict);264 }...

Full Screen

Full Screen

CFFTop.js

Source:CFFTop.js Github

copy

Full Screen

...165 [[12, 33], 'CIDFontType', 'number', 0],166 [[12, 34], 'CIDCount', 'number', 8720],167 [[12, 35], 'UIDBase', 'number', null],168 [[12, 37], 'FDSelect', new CFFPointer(FDSelect), null],169 [[12, 36], 'FDArray', new CFFPointer(new CFFIndex(FontDict)), null],170 [[12, 38], 'FontName', 'sid', null]171]);172let VariationStore = new r.Struct({173 length: r.uint16,174 itemVariationStore: ItemVariationStore175})176let CFF2TopDict = new CFFDict([177 [[12, 7], 'FontMatrix', 'array', [0.001, 0, 0, 0.001, 0, 0]],178 [17, 'CharStrings', new CFFPointer(new CFFIndex), null],179 [[12, 37], 'FDSelect', new CFFPointer(FDSelect), null],180 [[12, 36], 'FDArray', new CFFPointer(new CFFIndex(FontDict)), null],181 [24, 'vstore', new CFFPointer(VariationStore), null],182 [25, 'maxstack', 'number', 193]183]);184let CFFTop = new r.VersionedStruct(r.fixed16, {185 1: {186 hdrSize: r.uint8,187 offSize: r.uint8,188 nameIndex: new CFFIndex(new r.String('length')),189 topDictIndex: new CFFIndex(CFFTopDict),190 stringIndex: new CFFIndex(new r.String('length')),191 globalSubrIndex: new CFFIndex192 },193 2: {194 hdrSize: r.uint8,195 length: r.uint16,196 topDict: CFF2TopDict,197 globalSubrIndex: new CFFIndex198 }199});...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.page('Barack Obama').then(function(page) {3 return page.getWikiText();4}).then(function(wikitext) {5 console.log(wikitext);6});7var wptools = require('wptools');8wptools.page('Barack Obama').then(function(page) {9 return page.getWikiText();10}).then(function(wikitext) {11 console.log(wikitext);12});13var wptools = require('wptools');14wptools.page('Barack Obama').then(function(page) {15 return page.getWikiText();16}).then(function(wikitext) {17 console.log(wikitext);18});19var wptools = require('wptools');20wptools.page('Barack Obama').then(function(page) {21 return page.getWikiText();22}).then(function(wikitext) {23 console.log(wikitext);24});25var wptools = require('wptools');26wptools.page('Barack Obama').then(function(page) {27 return page.getWikiText();28}).then(function(wikitext) {29 console.log(wikitext);30});31var wptools = require('wptools');32wptools.page('Barack Obama').then(function(page) {33 return page.getWikiText();34}).then(function(wikitext) {35 console.log(wikitext);36});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var w = wptools.page('Albert Einstein');3w.get(function(err, resp) {4 if (err) {5 console.log(err);6 }7 else {8 console.log(resp.data);9 }10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, resp) {4 console.log(resp);5});6var wptools = require('wptools');7var page = wptools.page('Barack Obama', {api: 'wikipedia'});8page.get(function(err, resp) {9 console.log(resp);10});11var wptools = require('wptools');12var page = wptools.page('Barack Obama', {api: 'wikipedia'});13page.get(function(err, resp) {14 console.log(resp);15});16var wptools = require('wptools');17var page = wptools.page('Barack Obama', {api: 'wikipedia'});18page.get(function(err, resp) {19 console.log(resp.json());20});21var wptools = require('wptools');22var page = wptools.page('Barack Obama', {api: 'wikipedia'});23page.get(function(err, resp) {24 console.log(resp.json());25});26var wptools = require('wptools');27var page = wptools.page('Barack Obama', {api: 'wikipedia'});28page.get(function(err, resp) {29 console.log(resp.json());30});31var wptools = require('wptools');32var page = wptools.page('Barack Obama', {api: 'wikipedia'});33page.get(function(err, resp) {34 console.log(resp.json());35});36var wptools = require('wptools');37var page = wptools.page('Barack Obama', {api: 'wikipedia'});38page.get(function(err, resp) {39 console.log(resp.json());40});41var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2wptools.page('Barack_Obama').get(function(err, data){3 console.log(data);4});5var wptools = require('wptools');6wptools.page('Barack_Obama').get(function(err, data){7 console.log(data);8});9var wptools = require('wptools');10wptools.page('Barack_Obama').get(function(err, data){11 console.log(data);12});13var wptools = require('wptools');14wptools.page('Barack_Obama').get(function(err, data){15 console.log(data);16});17var wptools = require('wptools');18wptools.page('Barack_Obama').get(function(err, data){19 console.log(data);20});21var wptools = require('wptools');22wptools.page('Barack_Obama').get(function(err, data){23 console.log(data);24});25var wptools = require('wptools');26wptools.page('Barack_Obama').get(function(err, data){27 console.log(data);28});29var wptools = require('wptools');30wptools.page('Barack_Obama').get(function(err, data){31 console.log(data);32});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2const index = wptools.page('CFFIndex').then(page => page.get());3index.then(console.log);4const wptools = require('wptools');5const index = wptools.page('CFFIndex').then(page => page.get());6index.then(console.log);7const wptools = require('wptools');8const index = wptools.page('CFFIndex').then(page => page.get());9index.then(console.log);10const wptools = require('wptools');11const index = wptools.page('CFFIndex').then(page => page.get());12index.then(console.log);13const wptools = require('wptools');14const index = wptools.page('CFFIndex').then(page => page.get());15index.then(console.log);16const wptools = require('wptools');17const index = wptools.page('CFFIndex').then(page => page.get());18index.then(console.log);19const wptools = require('wptools');20const index = wptools.page('CFFIndex').then(page => page.get());21index.then(console.log);22const wptools = require('wptools');23const index = wptools.page('CFFIndex').then(page => page.get());24index.then(console.log);25const wptools = require('wptools');26const index = wptools.page('CFFIndex').then(page => page.get());27index.then(console.log);28const wptools = require('wptools');29const index = wptools.page('C

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Albert Einstein').get();3page.then(function(response) {4 console.log(response);5});6var wptools = require('wptools');7var page = wptools.page('Albert Einstein').get();8page.then(function(response) {9 console.log(response);10});11{ [Error: ENOENT, open 'C:\Users\Apoorv\AppData\Roaming\npm\node_modules\wptools\lib\cache\Albert Einstein.json']12 path: 'C:\\Users\\Apoorv\\AppData\\Roaming\\npm\\node_modules\\wptools\\lib\\cache\\Albert Einstein.json' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, resp) {4 console.log(resp);5});6MIT © [Amit Agarwal](

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