Project

fontist

0.0
The project is in a healthy, maintained state
A libarary find or download fonts
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
 Project Readme

Fontist

windows macos ubuntu

A simple library to find and download fonts for Windows, Linux and Mac.

Installation

Add this line to your application's Gemfile:

gem "fontist"

And then execute:

bundle install

Or install it yourself as:

gem install fontist

Fetch formulas

After installation please fetch formulas to your system:

fontist update

Usage

Font

The Fontist::Font is your go to place to deal with any font using fontist. This interface will allow you to find a font or install a font. Lets start with how can we find a font in your system.

Finding a font

The Fontist::Fontist.find interface can be used a find a font in your system. It will look into the operating system specific font directories, and also the fontist specific ~/.fontist directory.

Fontist::Font.find(name)

If fontist find a font then it will return the paths, but if not found then it will could raise an unsupported font error or maybe an installation instruction for that specific font.

Install a font

The Fontist::Font.install interface can be used to install any supported font. This interface first checks if you already have that font installed or not and if you do then it will return the paths.

If you don't but supported by fontist, then it will download the font and copy it to ~/.fontist directory and also return the paths.

Fontist::Font.install(name, confirmation: "no")

If there are some issue with the provided font, like not supported or some other issue then it will raise those errors.

List all fonts

The Fontist::Font interface exposes an interface to list all supported fonts, this might be useful if want to know the name of the font or the available styles. You can do that by using:

Fontist::Font.all

The return values are OpenStruct object, so you can easily do any other operation you would do in any ruby object.

Formula

The fontist gem internally usages the Fontist::Formula interface to find a registered formula or fonts supported by any formula. Unless, you need to do anything with that you shouldn't need to work with this interface directly. But if you do then these are the public interface it offers.

Find a formula

The Fontist::Formula.find interface allows you to find any of the registered formula. This interface takes a font name as an argument and it looks through each of the registered formula that offers this font installation. Usages:

Fontist::Formula.find("Calibri")

The above method will find which formula offers this font and then it will return a installable formula that can be used to check licences or install that fonts in your system.

Find formula fonts

Normally, each font name can be associated with multiple styles or collection, for example the Calibri font might contains a regular, bola or italic styles fonts and if you want a interface that can return the complete list then this is your friend. You can use it as following:

Fontist::Formula.find_fonts("Calibri")

List all formulas

The Fontist::Formula interface exposes an interface to list all registered font formula. This might be useful if want to know the name of the formula or what type fonts can be installed using that formula. Usages:

Fontist::Formula.all

The return values are OpenStruct object, so you can easily do any other operation you would do in any ruby object.

Manifest

Locations

Fontist lets find font locations from a YAML manifest of the following format:

Segoe UI:
- Regular
- Bold
Roboto Mono:
- Regular

Calling the following code returns a nested hash with font paths.

Fontist::Manifest::Locations.call(manifest_path)
{"Segoe UI"=>
  {"Regular"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"],
   "Bold"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]},
 "Roboto Mono"=>
  {"Regular"=>[]}}

Install

Fontist lets not only to get font locations but also to install fonts from the manifest:

Fontist::Manifest::Install.call(manifest, confirmation: "yes")

It will install fonts and return their locations:

{"Segoe UI"=>
  {"Regular"=>["/Users/user/.fontist/fonts/SEGOEUI.TTF"],
   "Bold"=>["/Users/user/.fontist/fonts/SEGOEUIB.TTF"]},
 "Roboto Mono"=>
  {"Regular"=>["/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"]}}

CLI

These commands makes possible to operate with fonts via command line. The CLI properly supports exit status, so in a case of error it returns a status code higher or equal than 1.

All searches are case-insensitive for ease of use.

Install

The install command is similar to the Font.install call. It first checks whether this font is already installed, and if not, then installs the font and returns its paths. Font or formula could be specified as a name.

$ fontist install "segoe ui"
These fonts are found or installed:
/Users/user/.fontist/fonts/SEGOEUI.TTF
/Users/user/.fontist/fonts/SEGOEUIB.TTF
/Users/user/.fontist/fonts/SEGOEUII.TTF
/Users/user/.fontist/fonts/SEGOEUIZ.TTF

Uninstall

Uninstalls any font supported by Fontist. Returns paths of an uninstalled font, or prints an error telling that the font isn't installed or could not be found in Fontist formulas. Aliased as remove.

$ fontist uninstall "segoe ui"
These fonts are removed:
/Users/user/.fontist/fonts/SEGOEUII.TTF
/Users/user/.fontist/fonts/SEGOEUIZ.TTF
/Users/user/.fontist/fonts/SEGOEUIB.TTF
/Users/user/.fontist/fonts/SEGOEUI.TTF

Status

Prints installed font paths grouped by formula and font.

$ fontist status "segoe ui"
Fontist::Formulas::SegoeUIFont
 Segoe UI
  Regular (/Users/user/.fontist/fonts/SEGOEUI.TTF)
  Bold (/Users/user/.fontist/fonts/SEGOEUIB.TTF)
  Italic (/Users/user/.fontist/fonts/SEGOEUII.TTF)
  Bold Italic (/Users/user/.fontist/fonts/SEGOEUIZ.TTF)

List

Lists installation status of fonts supported by Fontist.

$ fontist list "segoe ui"
Fontist::Formulas::SegoeUIFont
 Segoe UI
  Regular (installed)
  Bold (installed)
  Italic (installed)
  Bold Italic (installed)
$ fontist list "roboto mono"
Fontist::Formulas::RobotoMonoFont
 Roboto Mono
  Regular (uninstalled)
  Italic (uninstalled)

Locations from manifest

Returns locations of fonts specified in a YAML file as an input.

For example, if there is a file manifest.yml:

Segoe UI:
- Regular
- Bold
Roboto Mono:
- Regular

Then the command will return the following YAML output:

$ fontist manifest-locations manifest.yml
---
Segoe UI:
  Regular:
  - "/Users/user/.fontist/fonts/SEGOEUI.TTF"
  Bold:
  - "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
Roboto Mono:
  Regular: []

Since Segoe UI is installed, but Roboto Mono is not.

Install from manifest

Install fonts from a YAML manifest:

$ fontist manifest-install --confirm-license manifest.yml
---
Segoe UI:
  Regular:
  - "/Users/user/.fontist/fonts/SEGOEUI.TTF"
  Bold:
  - "/Users/user/.fontist/fonts/SEGOEUIB.TTF"
Roboto Mono:
  Regular:
  - "/Users/user/.fontist/fonts/RobotoMono-VariableFont_wght.ttf"

Help

List of all commands could be seen by:

fontist help

Development

We are following Sandi Metz's Rules for this gem, you can read the description of the rules here All new code should follow these rules. If you make changes in a pre-existing file that violates these rules you should fix the violations as part of your contribution.

Setup

Clone the repository.

git clone https://github.com/fontist/fontist

Setup your environment.

bin/setup

Run the test suite

bin/rspec

Formulas storage

All formulas are kept in the formulas repository. If you'd like to add a new one or change any existing, please refer to its documentation.

Auto-generate a formula

A formula could be generated from a fonts archive. Just specify a URL to the archive:

fontist create-formula https://www.latofonts.com/download/lato2ofl-zip/
cp lato.yml ~/.fontist/formulas/Formulas/
cd ~/.fontist/formulas
git add Formulas/lato.yml
git commit -m "Add Lato formula"

Google Import

The library contains formulas for Google Foonts. A GHA workflow checks for fonts update every day. In case an update is found, it could be fetched to the library by:

bin/import_google

The script would update formulas which should be committed to a separate repository formulas:

cd ~/.fontist/formulas
git add Formulas/google
git commit -m "Google Fonts update"
git push

Contributing

First, thank you for contributing! We love pull requests from everyone. By participating in this project, you hereby grant Ribose Inc. the right to grant or transfer an unlimited number of non exclusive licenses or sub-licenses to third parties, under the copyright covering the contribution to use the contribution by all means.

Here are a few technical guidelines to follow:

  1. Open an issue to discuss a new feature.
  2. Write tests to support your new feature.
  3. Make sure the entire test suite passes locally and on CI.
  4. Open a Pull Request.
  5. Squash your commits after receiving feedback.
  6. Party!

Credit

This gem is developed, maintained and funded by Ribose Inc.