GithubHelp home page GithubHelp logo

fontfinder's Introduction

FontFinder

Description

FontFinder is a helper class that finds fonts in a given path. It can search for fonts in a directory and its subdirectories, and can also handle a single font file.

The class allows for filtering based on various criteria such as outline format (TrueType or PostScript), font variations (static or variable), and font flavor ('woff', 'woff2' or None).

The class returns a list or a generator of FontTools TTFont objects, or of TTFont subclass objects, that meet the specified criteria.

Attributes

The FontFinder class has the following attributes:

  • input_path: the path to the directory or file
  • recursive: if True and input_path is a directory, search for fonts in the directory and its subdirectories
  • return_cls: the class to use for returned objects can be specified by passing a subclass of TTFont to the return_cls argument. If return_cls is None, TTFont is used
  • recalc_timestamp: if True, recalculate the font's modified timestamp on save
  • recalc_bboxes: if True, recalculate the font's bounding boxes on save
  • filter_out_sfnt: if True, filter out SFNT fonts
  • filter_out_woff: if True, filter out WOFF fonts
  • filter_out_woff2: if True, filter out WOFF2 fonts
  • filter_out_tt: if True, filter fonts with TrueType outlines
  • filter_out_ps: if True, filter fonts with PostScript outlines
  • filter_out_static: if True, filter out static fonts
  • filter_out_variable: if True, filter out variable fonts

Usage examples

List or Generator

Depending on the method used, FontFinder returns a list or a generator of FontTools TTFont objects (or of TTFont subclasses objects).

The find_fonts() method returns a list of TTFont objects, while the generate_fonts() method returns a generator of TTFont objects.

To get a list of TTFont objects, use the find_fonts() method:

from font_finder import FontFinder

# return a list of all fonts in a directory
finder = FontFinder("/path/to/directory")
fonts = finder.find_fonts()

To get a generator of TTFont objects, use the generate_fonts() method:

from font_finder import FontFinder

# return a generator of all fonts in a directory
finder = FontFinder("/path/to/directory")
fonts = finder.generate_fonts()

File or directory

FontFinder can handle a single font file or a directory. If a directory is passed, FontFinder can search for fonts in the directory and its subdirectories. If a file is passed, FontFinder will return a list or a generator with a single TTFont object.

Single file

from font_finder import FontFinder

# return a list with a single font
finder = FontFinder("/path/to/file.ttf")
fonts = finder.find_fonts()

Directory

from font_finder import FontFinder

# return a list of all fonts in a directory
finder = FontFinder("/path/to/directory")
fonts = finder.find_fonts()

Recursive search

from font_finder import FontFinder

# return a list of all fonts in a directory and its subdirectories
finder = FontFinder("/path/to/directory", recursive=True)
fonts = finder.find_fonts()

Return class

By default, FontFinder returns a list or a generator of FontTools TTFont objects. The class to use for returned objects can be specified by passing a subclass of TTFont to the return_cls argument. If return_cls is None, TTFont objects are returned.

Using filters

Find all fonts with PostScript outlines in a directory and its subdirectories

from font_finder import FontFinder

# find all fonts with PostScript outlines in a directory and its subdirectories
finder = FontFinder("/path/to/directory", recursive=True)
finder.filter_out_tt = True  # filter fonts with TrueType outlines
fonts = finder.find_fonts()

Find all fonts with TrueType outlines in a directory and its subdirectories

from font_finder import FontFinder

# find all web fonts in a directory and its subdirectories
finder = FontFinder("/path/to/directory", recursive=True)
finder.filter_out_sfnt = True  # filter out SFNT fonts
fonts = finder.find_fonts()

Find all static fonts in a directory and its subdirectories

from font_finder import FontFinder

# find all static fonts in a directory and its subdirectories
finder = FontFinder("/path/to/directory", recursive=True)
finder.filter_out_variable = True  # filter out variable fonts
fonts = finder.find_fonts()

Find all variable fonts in a directory and its subdirectories

from font_finder import FontFinder

# find all variable fonts in a directory and its subdirectories
finder = FontFinder("/path/to/directory", recursive=True)
finder.filter_out_static = True  # filter out static fonts
fonts = finder.find_fonts()

Find all web fonts in a directory and its subdirectories

from font_finder import FontFinder

# find all WOFF and WOFF2 fonts in a directory and its subdirectories
finder = FontFinder("/path/to/directory", recursive=True)
finder.filter_out_sfnt = True  # filter out SFNT fonts
fonts = finder.find_fonts()

Find all WOFF fonts in a directory and its subdirectories

from font_finder import FontFinder

# find all WOFF fonts in a directory and its subdirectories
finder = FontFinder("/path/to/directory", recursive=True)
finder.filter_out_sfnt = True  # filter out SFNT fonts
finder.filter_out_woff2 = True  # filter out WOFF2 fonts
fonts = finder.find_fonts()

Find all WOFF2 fonts with TrueType outlines in a directory and its subdirectories

from font_finder import FontFinder

# find all WOFF fonts with TrueType outlines in a directory and its subdirectories
finder = FontFinder("/path/to/directory", recursive=True)
finder.filter_out_sfnt = True  # filter out SFNT fonts
finder.filter_out_woff2 = True  # filter out WOFF2 fonts
finder.filter_out_ps = True  # filter out fonts with PostScript outlines
fonts = finder.find_fonts()

fontfinder's People

Contributors

ftcli avatar renovate[bot] avatar pre-commit-ci[bot] avatar

Watchers

 avatar

fontfinder's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/codecov.yml
  • actions/checkout v4
  • actions/setup-python v5
  • actions/setup-python v5
  • codecov/codecov-action v4
pip_requirements
requirements.txt
  • fonttools ==4.53.1

  • Check this box to trigger a request for Renovate to run again on this repository

How do I get information out of a "fontTools.ttLib.ttFont.TTFont object"? Or a <'name' table at 18f23a4ca90>

I'm testing FontFinder and have no clue how to get it to display human readable information out of the fonts it finds. Here's a small script I'm using to test:

import sys
from sys import argv
from sys import exit
import json
from font_finder import FontFinder

# find all variable fonts in a directory and its subdirectories
finder = FontFinder("D:/Fonts/Licensed/Sans Circular+/00 Temp", recursive=False)
finder.filter_out_static = True  # filter out static fonts
fonts = finder.find_fonts()

for x in range(len(fonts)):
    print(fonts[x]);

The above code prints out five lines corresponding to my variable fonts:

<fontTools.ttLib.ttFont.TTFont object at 0x00000253A247CAC0>
<fontTools.ttLib.ttFont.TTFont object at 0x00000253A247C430>
<fontTools.ttLib.ttFont.TTFont object at 0x00000253A247C400>
<fontTools.ttLib.ttFont.TTFont object at 0x00000253A247CE20>
<fontTools.ttLib.ttFont.TTFont object at 0x00000253A247D660>

But I am not able to figure out how to access the information from each TTFont object, like the font name, font path, etc. How can I accomplish this? I've tried reading the documentation but still can't figure it out.

I also tried:

import sys
from sys import argv
from sys import exit
import json
from font_finder import FontFinder

# find all variable fonts in a directory and its subdirectories
finder = FontFinder("D:/Fonts/Licensed/Sans Circular+/00 Temp", recursive=False)
finder.filter_out_static = True  # filter out static fonts
fonts = finder.find_fonts()

for x in range(len(fonts)):
    print(fonts[x]['name']);

But then I just get this:

<'name' table at 18f23a4ca90>
<'name' table at 18f26152440>
<'name' table at 18f26152d10>
<'name' table at 18f26153970>
<'name' table at 18f26170460>

Any help would be greatly, greatly appreciated!

Thanks again,
Joseph

How do I install this inside of an existing FontTool VENV?

I tried following instructions here: https://www.activestate.com/resources/quick-reads/how-to-manually-install-python-packages/

  1. Activate my FontTools VENV
  2. cd into the root directory where setup.py is located
  3. Enter: python setup.py install

This didn't work and gave me a bunch of depreciation warnings. Is there a proper way to install this that I'm missing? I'd really like to use this helper.

My FontTools VENV is using Python 3.10.11. Any help would be fantastic. Thank you for creating this helper tool.

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.