Code Monkey home page Code Monkey logo

fontname.py's Introduction

fontname.py

About

fontname.py is a .ttf and .otf font renaming script that is developed in Python. It supports font renaming with the Python 3.6+ interpreter.

Dependency

  • fonttools Python library (requires v4.0.0+)

Install with:

pip3 install fonttools

Usage

The script usage is as follows:

$ python3 fontname.py [NEW FONT FAMILY NAME] [FONT PATH 1] <FONT PATH ...>

This script updates the OpenType name table records nameID 1, 4, 6, and 16 with appropriately formatted font names using the font style definition in the font and the new font family name defined by the user as the first command line argument. The CFF fontName, familyName, and fullName fields are edited in CFF fonts (*.otf). You can include any number of subsequent font paths on the command line. The style will be detected in the OpenType tables of the fonts filepath arguments and will be used to create new name strings in the OpenType tables.

Note: this re-writes the name tables in the fonts passed as arguments on the command line (i.e. writes files in place) so make copies first if you intend to maintain the fonts with the former naming for any reason (though you can simply re-write with the previous name if you forget...).

Examples

$ python3 fontname.py "Hack DEV" Hack-Regular.ttf

fscw-hack

$ python3 fontname.py "Source Code Pro DEV" SourceCodePro-Regular.otf

fscw-scp

$ python3 fontname.py "DejaVu Sans Mono DEV" DejaVuSansMono-Bold.ttf

fscw-djv

These should all be detected as "different" fonts so that you can install them side-by-side with the pre-modified versions.

License

MIT License

fontname.py's People

Contributors

chrissimpkins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fontname.py's Issues

FullName in CFF table is not changed

I recently used your script and it works fatastic, however I realised, that the FullName in CFF table is not changed.
I had no problems whatsoever so far with renamed fonts, yet I’m still wondering what this entry in the CFF table does.
So far all apps I tested the fonts with don't seem to care about this entry. Is it not important? Do I not need to change it?
For the sake of consistency I changed it manually with ttx, but I was wondering if there is a better way/it is necessary.

Name ID 3 also needs to be changed (unique identifier)

The unique identifier also needs to be changed. Adding this to the code fixes it (line 94):

 elif record.nameID == 3:
       record.string = nameID6_string

The issue made a font unusable by some applications.
Hope it helps!

Error: Unable to detect the font style

Running this on some TTF files gives the following error:

[fontname.py] Unable to detect the font style from the OpenType name table in '[FONT-NAME].ttf'. 
Unable to complete execution of the script. 

Does this mean my TTF files are corrupt or missing something or is this actually a bug? Wondering if I need to use TTX to do the recompile to get the name to change or if there's some changes I might be able to make to fontname.py to fix the issue.

Thanks, and thanks for this cool repo!

"can't find '__main__' module"

Running this:

$ python /Users/[obfuscated]/Code/github/chrissimpkins/fontname.py "Hack DEV" Hack-Regular.ttf

produces this error:

/Users/[obfuscated]/.asdf/installs/python/3.6.2/bin/python3.6: 
can't find '__main__' module in 
'/Users/[obfuscated]/Code/github/chrissimpkins/fontname.py'

Any ideas?

Location of the files

Hello,
The fontmake.py files should always be stored in the folder where the font files are or there is a way to install "globally" on a computer?

Thanks,
Maciej

Support for localized names

Many CJK fonts have localized names, do we support modifying them now?

e.g.

{
en: "Source Han Sans SC"
}, {
 zh: "思源黑体"
}

Not renaming font family on MacOS

Reproduce steps:

  1. Download FontAwesome for web
  2. Run:
python fontname.py "TEST" /Users/ryan/Downloads/fontawesome-free-5.8.1-web/webfonts/fa-solid-900.ttf

[OK] Updated '/Users/ryan/Downloads/fontawesome-free-5.8.1-web/webfonts/fa-solid-900.ttf' with the name 'TEST Solid'
  1. Open fa-solid-900.ttf with Font Book app (or another app that displays .ttf font family)
  2. Note that font family is still Font Awesome 5 free

I wrote a blog post where this used to work (at least on 12/27/2018). I can't figure out what has changed.

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.