Code Monkey home page Code Monkey logo

monospacifier's Introduction

monospacifier.py

A great way to increase the Unicode coverage of your favorite programming font.

monospacifier.py adjusts every character of your favorite variable-width font to match a reference monospace font. The result is a good fallback font for characters not covered by the reference: the result is a font setup with good Unicode coverage, without breaking indentation.

default vs monospacified

Pre-monospacified fonts (monospace fonts with good Unicode coverage)

Instead of running this program, you can use one of the pre-generated monospace fonts listed below (to be use as a fallback, for symbols not covered by your favorite font).

Download a fallback font

Choose from this list, based on your main programming font. Note that some fonts needed to be renamed to comply with their licenses (Asana → Asanb, STIX → STIY).

Programming font Monospacified fallback fonts
DejaVu Sans Mono Asana Math, FreeSerif, Latin Modern Math, STIX Math, Symbola, TeX Gyre Schola Math, XITS Math, XITS Math
Inconsolata LGC for Powerline Asana Math, FreeSerif, Latin Modern Math, STIX Math, Symbola, TeX Gyre Schola Math, XITS Math, XITS Math
Inconsolata Asana Math, FreeSerif, Latin Modern Math, STIX Math, Symbola, TeX Gyre Schola Math, XITS Math, XITS Math
Liberation Mono Asana Math, FreeSerif, Latin Modern Math, STIX Math, Symbola, TeX Gyre Schola Math, XITS Math, XITS Math
Source Code Pro Asana Math, FreeSerif, Latin Modern Math, STIX Math, Symbola, TeX Gyre Schola Math, XITS Math, XITS Math
Terminus (TTF) Asana Math, FreeSerif, Latin Modern Math, STIX Math, Symbola, TeX Gyre Schola Math, XITS Math, XITS Math
Ubuntu Mono Asana Math, FreeSerif, Latin Modern Math, STIX Math, Symbola, TeX Gyre Schola Math, XITS Math, XITS Math
mononoki Asana Math, FreeSerif, Latin Modern Math, STIX Math, Symbola, TeX Gyre Schola Math, XITS Math, XITS Math

If your favorite combination is not available, please let me know.

Install it

  • On Windows put the font in C:\Windows\Font.
  • On Debian-inspired systems put the font in ~/.fonts and run fc-cache.

Configure fallback

Emacs

Add the following snippet to your .emacs (replacing font names as appropriate), then restart:

(dolist (ft (fontset-list))
  (set-fontset-font ft 'unicode (font-spec :name "<monospace font>"))
  (set-fontset-font ft 'unicode (font-spec :name "<variable-width font> monospacified for <monospace font>") nil 'append))

Here are two examples:

(dolist (ft (fontset-list))
  (set-fontset-font ft 'unicode (font-spec :name "Consolas"))
  (set-fontset-font ft 'unicode (font-spec :name "Symbola monospacified for Consolas") nil 'append))
(dolist (ft (fontset-list))
  (set-fontset-font ft 'unicode (font-spec :name "DejaVu Sans Mono"))
  (set-fontset-font ft 'unicode (font-spec :name "Asanb Math monospacified for DejaVu Sans Mono") nil 'append))

urxvt

Fallback fonts can be used with urxvt using comma-separated values to the -fn switch:

urxvt -fn 'xft:Consolas,xft:Symbola monospacified for Consolas'

This can also be set in the .Xresources file:

URxvt.font: xft:Consolas,xft:Symbola monospacified for Consolas

Source it by running xrdb -merge .Xresources.

Other editors

Please submit recipes for other editors or operating systems!

Demo

inconsistent fallbacks consistent fallback monospacified fallback

Monospace font + default fallbacks — Monospace font + original Symbola — Monospace font + Monospacified Symbola

Usage

Details

  • For help, run ./monospacifier.py -h
  • For examples of use, see the Makefile (I use it to generate the files listed here)

monospacifier.py includes multiple scaling algorithms (only one is exposed on the CLI). They are all rather basic, so don't expect this program to create anything except a decent fallback font.

The most advanced algorithm (demoed) sets the bounding box of each glyph appropriately (to match the most common width in the monospace font), and slightly compresses wide characters to reduce bleeding (wide glyphs will overlap with neighboring characters), while preserving distinctions between long and short glyphs (so ↦ and ⟼ are still distinguishable). Then (conditional on the --copy-metrics flag), monospacifier.py adjusts the metrics of the newly created font to match those of the reference (this fixes a number of issues that I don't understand well, in particular with hhea_descent and os2_typodescent metrics; if you have a clue about this, please do get in touch by opening an issue).

monospacifier's People

Contributors

cpitclaudel avatar ideasman42 avatar jasongross avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.