ttfmeta
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

ttfmeta

A Node.js module and a library that extracted metadata from ttf font file or buffer. It is forked from trevordixon/ttfinfo and improve, add test. Check live Demo using Vue is available...

workflows-badge travis-badge npm-badge webpack-badge test-mocha

Feature

  • [x] has TypeScript declarations
  • [x] support both ESM and CommonJS including browser
  • [x] Reading from file (or) buffer
  • [x] Demo

Usage

Node.JS

Oops: ttfmeta export ES module from CommonJS built version.

export * from "./index.js";

import * as e from "./index.js";
export default e;

npm i ttfmeta can be require or import from your Node.JS application. However ttfmeta is assuming that one day npm might force us to seperate ES module and CommonJS. Therefore, it is a good practice to start coding Node.JS application using ES module.

// ES6
import ttfMeta from 'ttfmeta';
import {ttfInfo,promise} from 'ttfmeta';

// CommonJS
const ttfMeta = require('ttfmeta');
const {ttfInfo,promise} = require('ttfmeta');

Browser

Include the file ttfmeta@latest/min.js in your web application. It is available on UNPKG and jsDelivr.

Now let's assume that you have picked the jsDelivr one...

<script src="https://cdn.jsdelivr.net/npm/ttfmeta@latest/min.js"></script>

<input type="file" name="files[]" multiple />
<script>
  // window.ttfMeta;
  var file = 'blob or arrayBuffer';

  var reader = new FileReader();
  reader.onload = function(evt) {
    var arrayBuffer =  evt.target.result;
    var data = new DataView(arrayBuffer, 0, arrayBuffer.byteLength);
    window.ttfMeta.promise(data).then(
      e => console.log(e)
    ).catch(
      e=>console.log('error',e)
    )
  }
  reader.readAsArrayBuffer(file);
</script>

API

You may assure that the APIs are not going to change without a good reason for end user. So any exported methods and classes name will stays the same as the last updates.

Promise

the ttfMeta.promise(), promise()

ttfMeta.promise('file.ttf').then(
  result => console.log(result)
).catch(
  err => console.log('error',err)
);

// or
promise('file.ttf (or) buffer').then(
  result => console.log(result)
).catch(
  err => console.log('error',err)
);

ttfInfo

the ttfMeta.ttfInfo(), ttfInfo()

ttfMeta.ttfInfo('file.ttf', (err, result) => {
  if (err) {
    console.log('error', err)
  } else {
    console.log('result', result)
  }
});

// or
ttfInfo('file.ttf (or) buffer', (err, result) => ...);

Result

This result promise an object with meta and tables regardless.

{
  meta: {
    property: [
      { name: 'font-family', text: String },
      { name: 'font-subfamily', text: String },
      { name: 'unique-identifier', text: String },
      { name: 'full-name', text: String },
      { name: 'version', text: String },
      { name: 'postscript-name', text: String },
      { name: 'company', text: String },
      { name: 'author', text: String }
    ],
    description: [
      { name: 'title', text: String },
      { name: 'paragraph', text: String },
      ...
    ],
    license: [
      { name: 'title', text: String },
      { name: 'paragraph', text: String },
      ...
    ],
    reference: [
      { name: 'url', text: 'http://...' },
      ...
    ]
  },
  tables: {
    name: {
      '0': String,
      '1': String,
      '2': String,
      '3': String,
      '4': String,
      '5': String,
      '6': String,
      '7': String,
      '8': String,
      '9': String,
      ...
      '18': String
    },
    post: {
      format: Number,
      italicAngle: Number,
      underlinePosition: Number,
      underlineThickness: Number,
      isFixedPitch: Number,
      minMemType42: Number,
      maxMemType42: Number,
      minMemType1: Number,
      maxMemType1: Number
    },
    os2: { version: Number, weightClass: Number }
  }
}

License

shield-license

Package Sidebar

Install

npm i ttfmeta

Weekly Downloads

290

Version

1.1.2

License

MIT

Unpacked Size

55.2 kB

Total Files

17

Last publish

Collaborators

  • khensolomon