Giter VIP home page Giter VIP logo

fontra's Introduction

fontra

PyPI Version | PyPI Downloads | License

Some small work with fonts.

Features

  • Font indexing and querying via display name
  • Specifying custom font directories
  • CLI for listing fonts

Installation

Via pip:

pip install fontra

For some advanced tools:

pip install fontra[tools]

which currently enables you to:

  • Extract a .ttc file to .ttf files

Usage

Command-line interface

fontra --help
       --version
       list
                                            List available fonts.
            --tree/[--table] | -t/[-T]
                                            Whether to display a tree or a table.
            --sort/[--no-sort] | -s/[-S]
                                            Whether to output with sorted font names.
            --with-localized-names/[--without-localized-names] | -l/[-L]
                                            Whether to show localized font names.
       path
                                            Show the font directories.
       show
                                            Show the font information.
            [--localized]/--no-localized NAME...  # will fix name in next version
                                            Whether to lookup the localized index.
       unlocalized NAME  # will fix name in next version
                                            Convert a name into an unlocalized name.

Font indexing and querying

>>> import fontra
>>> fontra.all_fonts()
['Noto Sans Lisu', 'Noto Serif Tamil SemiCondensed', 'Noto Serif Georgian', 'Noto Sans Armenian', ...]
>>> fontra.get_font_styles("Arial")
['Regular', 'Italic', 'Bold', 'Bold Italic', 'Black']
>>> fontra.get_font("Arial", "Italic")
FontRef(path=PosixPath('/usr/share/fonts/TTF/ariali.ttf'), bank=0)
>>> fontra.has_font_family("Helvetica")
False
>>> fontra.has_font_style("Comic Sans MS", "Light")
False
>>> fontra.get_unlocalized_name("更紗ゴシック UI J")
'Sarasa UI J'
>>> fontra.get_localized_names("LXGW WenKai TC")
['霞鶩文楷 TC', '霞鹜文楷 TC']
>>> fontra.get_font("更纱黑体 SC", "SemiBold Italic")
FontRef(path=PosixPath('/usr/share/fonts/sarasa-gothic/Sarasa-SemiBoldItalic.ttc'), bank=1)

Custom font directories

>>> fontra.FONTDIR_CUSTOM.append("./data/fonts")
>>> fontra.update_custom_fontfiles_index()
>>> fontra.update_fontrefs_index()
>>> fontra.all_fonts()
[...]

License

This project is under MIT License.

fontra's People

Contributors

ncbm avatar komoridev 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.