npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

font2svg

v0.0.0

Published

Create a SVG subset font from a font file

Downloads

20

Readme

font2svg

Dependency Status devDependency Status

Create a SVG subset font from a font file

var fs = require('fs');
var font2svg = require('font2svg');

var buf = fs.readFileSync('path/to/font.otf');

font2svg(buf, {include: ['A', 'B', 'C', '0', '1', '2']}, function(err, result) {
  if (err) {
    throw err;
  }

  result.toString(); //=> '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<svg>\n  <font ... '
});

Requirements

Before installing this module, you should install tx (a part of Adobe Font Development Kit for OpenType):

The FDK requires:

Mac OSX 10.4.x or later, or Windows XP or later

After installation, run tx -v command to check if tx has been installed successfully.

Installation

NPM version

Use npm.

npm install font2svg

API

var font2svg = require('font2svg');

font2svg(buffer[, options], callback)

buffer

Type: Buffer of a font file

Supported font formats depend on tx:

Conversion of font data represented in the following formats is supported: PFA, PFB, LWFN-POST, FFIL-sfnt, OTF, TTF, TTC, and AppleSingle/Double-sfnt. sfnt-formatted fonts with header versions of the following kinds are supported: 1.0, true, ttcf, typ1, CID, and OTTO. Note that OCF is not supported by tx.

options

In addition to the following, all options for child_process.exec except for encoding are available.

Note that maxBuffer option is 300000000 by default, unlike the original value (200*1024).

options.include

Type: String or Array of String
Default: []

The characters to be included in the SVG font subset.

options.fontFaceAttr

Type: Object
Default: {}

Set the attributes of font-face element.

font2svg(fontBuffer, {
  fontFaceAttr: {
    'font-weight': 'bold',
    'underline-position': '-100'
  }
}, function(err, result) {
  result.toString(); //=> ... <font-face ... font-weight="bold" underline-position="-100"> ...
});

Every key of the object must be a valid attribute name of font-face element.

// It throws an error because `font-weeight` is not a valid name of `font-face` element.
font2svg(fontBuffer, {'font-weeight': 'bold'}, callback);

options.encoding

Type: String
Default: null

Set encoding of the result (Buffer by default).

callback(error, svgData)

error: Error
svgData: Buffer or String (accoding to options.encoding)

var buf = fs.readFileSync('path/to/font.ttf');

font2svg(buf, {
  include: ['Hello, world.'],
  encoding: 'utf-8'
}, function(err, result) {
  result; //=> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<svg>\n  <font ... '
});

CLI

You can use this module as a CLI tool by installing it globally.

npm install -g font2svg

Usage

Usage1: font2svg <src path> <dest path> --include <string>
Usage2: font2svg <src path>  --include <string> > <dest path>
Usage3: cat <src path> | font2svg <dest path> --include <string>
Usage4: cat <src path> | font2svg --include <string> > <dest path>

Options:
--include, -in, -i -g <string>  Specify the characters to be included
--(attribute name)    <string>  Set attribute of font-face element
                                Example: --font-weight bold --units-per-em 980

--help,         -h              Print usage information
--version,      -v              Print version

Examples

font2svg src-font.otf dest-font.svg --include "foobar" --font-weight bold 
cat src-font.ttf | font2svg --include "bazqux" > dest-font.svg 

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT License.