fonttools | A library to manipulate font files from Python

 by   fonttools Python Version: 4.51.0 License: MIT

kandi X-RAY | fonttools Summary

kandi X-RAY | fonttools Summary

fonttools is a Python library. fonttools has build file available, it has a Permissive License and it has medium support. However fonttools has 108 bugs and it has 14 vulnerabilities. You can install using 'pip install fonttools' or download it from GitHub, PyPI.

A library to manipulate font files from Python.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              fonttools has a medium active ecosystem.
              It has 3671 star(s) with 426 fork(s). There are 115 watchers for this library.
              There were 10 major release(s) in the last 6 months.
              There are 268 open issues and 1209 have been closed. On average issues are closed in 443 days. There are 44 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of fonttools is 4.51.0

            kandi-Quality Quality

              OutlinedDot
              fonttools has 108 bugs (11 blocker, 0 critical, 9 major, 88 minor) and 16400 code smells.

            kandi-Security Security

              fonttools has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              OutlinedDot
              fonttools code analysis shows 14 unresolved vulnerabilities (14 blocker, 0 critical, 0 major, 0 minor).
              There are 52 security hotspots that need review.

            kandi-License License

              fonttools is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              fonttools releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.

            Top functions reviewed by kandi - BETA

            kandi has reviewed fonttools and discovered the below as its top functions. This is intended to give you an instant insight into fonttools implemented functionality, and help decide if they suit your requirements.
            • Tries to specialize the given commands .
            • Instantiates a variable font .
            • Parse a path definition .
            • Perform a test
            • Parses a substitution statement .
            • Groups the pairs of classes by the given alignment function .
            • Sets context classifier .
            • Refresh the glyphs for the specified font .
            • Returns the bytecode of the assembly .
            • Optimize the encodings .
            Get all kandi verified functions for this library.

            fonttools Key Features

            No Key Features are available at this moment for fonttools.

            fonttools Examples and Code Snippets

            Noto CJK VF Magisk,wght value
            Shelldot img1Lines of Code : 56dot img1License : Strong Copyleft (GPL-3.0)
            copy iconCopy
            # SC as a example. They were same.
            ttx -y 3 -t fvar NotoSansCJK-VF.ttc
            
              
            
                
                
                  wght
                  0x0
                  100.0
                  100.0
                  900.0
                  265
                
            
                
                
                
                  
                
            
                
                
                
                  
                
            
                
                
                
                  
                
            
                
                
            SVGinOT Color Font Builder,Usage - Linux
            Pythondot img2Lines of Code : 30dot img2License : Strong Copyleft (GPL-3.0)
            copy iconCopy
            $ bin/scfbuild --help
            usage: scfbuild [-h] [-o OUTPUT] [-g DIR] [-s DIR] [--transform TRANSFORM]
                            [--font-family FAMILY] [--font-subfamily SUBFAMILY]
                            [--font-version FONT_VERSION] [-c YAML_CONF] [-v] [-V]
            
            SCFBuild - SV  
            3.2 透過 Python 的 FontTools 解析字型檔
            Pythondot img3Lines of Code : 16dot img3License : Strong Copyleft (GPL-2.0)
            copy iconCopy
            import io
            import requests
            from fontTools.ttLib import TTFont
            
            ...
            
            url = "Font 所在 URL 位置路徑"
            resp = requests.get(url)
            
            # 如果直接讀取檔案 => TTFont("Font字型檔案位置")
            font = TTFont(io.BytesIO(resp.content))
            font.saveXML("保存的路徑")
            
            # getGlyphOrder 會回傳陣列,該陣列會以 Gly  

            Community Discussions

            QUESTION

            The font becomes thinner after editing
            Asked 2021-Jan-29 at 09:15

            I want remove unnecessary symbols from font «SFUI Text Regular». File size 104kb.

            1. FontForge

            Tried use FontForge. Deleted ~50% symbols. Save font. Tried use on the website. Result: the file size has decreased (104kb > 35kb), but the letters are thinner than originally. (i am sure, that this is wasn't system font, it's same font, but thinner)

            1. Fonttools

            Tried use fonttools, pyftsubset command.

            ...

            ANSWER

            Answered 2021-Jan-29 at 09:15

            I tried few more programs and services for this.

            FontCreator Pro helped decide problem. No specific settings. I just opened it, deleted characters, saved it.

            Source https://stackoverflow.com/questions/65922857

            QUESTION

            An unclear requirements.txt error which results in not being able to install
            Asked 2021-Jan-17 at 12:41

            From today, I started getting error while installing modules from requirements.txt, I tried to find the error module and remove it but I couldn't find.

            ...

            ANSWER

            Answered 2021-Jan-17 at 12:41

            Create a list of all the dependencies and run the following code.

            Source https://stackoverflow.com/questions/65759809

            QUESTION

            How to convert a set of images into a font `.ttf` file with python?
            Asked 2020-Dec-11 at 15:36
            Scenario

            I have a set of images named 32.png,..,126.png of handwritten letters pertaining to the ASCII printable characters of the number in the filenames, and I intend to convert these into a font file, like .ttf such that I can type (basic) latex letters with it.

            After going through the documentation of project description and documentation of fonttools I have not yet been able to determine how to convert these images into a .ttf font file in python.

            It appears I could convert the .png images into .svg format as the fonttools is normally used for font vectors, but I did not find a method that outputs a font file. Hence I wike to ask:

            Question

            How can I convert a set of images (either .png or .svg) into a .ttf font in python?

            Attempts
            1. After installing fontforge on windows and adding the ../FontForgeBuilds/bin folder to path, Anaconda does not recognize the fontforge module as it throws error:

            ModuleNotFoundError: No module named 'fontforge' in a script that converts .svg files into .ttf files. The script named svgs2ttf is called with command:python svgs2ttf.py examples/example.json.

            ...

            ANSWER

            Answered 2020-Dec-11 at 15:36

            FontForge is not a python module but separate software. Hence, instead of calling FontForge from a python script, one can call python from a fontforge executable. Since I wanted to create the font in .ttf format from a python script, I wrote an additional python script named execute.py which executes a cmd command that executes fontforge that executes the python svgs2ttf script.

            The execute.py contains:

            Source https://stackoverflow.com/questions/63380545

            QUESTION

            In what table of the ttf font is the actual size of the symbol?
            Asked 2020-Oct-31 at 09:58

            Question: Which font table contains data about the actual size of a lowercase character. I.e., the size that we actually see on the screen when this character is displayed. Please tell me the name of the table that contains this data. If they are not in the tables, then tell me how to calculate these values.

            If anything, I write Python code using fontTools

            ...

            ANSWER

            Answered 2020-Oct-31 at 09:58

            Glyphs' heights are not specified anywhere (at least, not for a horizontal layout). Probably, what you're looking for is sxHeight from the 'OS/2' table (the distance between the baseline and the approximate height of non-ascending lowercase letters). There's also sxCapHeight field (for uppercase letters). Though, those fields were defined in the second version of the OS/2 table.

            To find out the glyph's height, you can simply subtract its lowest point from the highest one (i.e. glyph height = yMax - yMin). yMax and yMin are stored in Glyph Header in the 'glyf' table (for TrueType outlines).

            If you need glyphs' widths, 'hmtx' table contains an advance width for every glyph in a font, as well as left-side and right-side bearings. 'hhea' table contains a maximum advance width value (advanceWidthMax).

            Source https://stackoverflow.com/questions/64616845

            QUESTION

            How do I convert a woff2 font to ttf using fonttools in Python?
            Asked 2020-Jul-03 at 08:35

            I have woff2 files that I would like to convert to ttf using Python and the fonttools library. I have seen some methods on how to convert ttf fonts to woff2 but I can't use them to do the opposite.

            Thanks in advance

            ...

            ANSWER

            Answered 2020-Jul-03 at 08:35

            I figured it out one can use fontTools.ttLib.woff2.decompress() to acheive this

            Source https://stackoverflow.com/questions/62652904

            QUESTION

            Python3 character maps to (MINGW64, Windows 10)?
            Asked 2020-Jun-22 at 18:40

            I try to use this code, that I found on https://superuser.com/questions/876572/how-do-i-find-out-which-font-contains-a-certain-special-character/1452828, on MINGW64 Python3 on a Windows 10 machine:

            ...

            ANSWER

            Answered 2020-Jun-22 at 18:40

            MingGW's console is converting the string to the console encoding (cp1252 from the error message`) and that encoding doesn't support the full range of Unicode characters.

            The standard Windows console does not get the error. Below is a cut-and-paste from the cmd.exe Windows console.

            Source https://stackoverflow.com/questions/62513266

            QUESTION

            module on test.pypi can't install dependencies, even thoug they exist
            Asked 2020-Mar-26 at 16:11

            I have done this small package that I want to distribute in my community. It is now on test.pypi and when I want to try to install it, it gives an error that dependencies couldn't be found.

            setup.py

            ...

            ANSWER

            Answered 2020-Mar-26 at 16:11

            -i URL, or --index-url URL means "use URL for installing packages from exclusively". By passing -i https://test.pypi.org/simple/, you thus prohibit searching and downloading packages from PyPI (https://pypi.org/simple). To use both indexes, use --extra-index-url:

            Source https://stackoverflow.com/questions/60868060

            QUESTION

            fonttools convert ttf to woff2
            Asked 2020-Feb-04 at 04:32

            Currenly, I'm using fonttools(https://github.com/fonttools/fonttools) to convert font file ttf to woff2 by ttx command with 2 steps

            • convert ttf to ttx
            • then convert ttx to woff2

            But it's too slow and ttx file to big, is there any way to convert ttf to woff2 directly by using fonttools to improve performance?

            ...

            ANSWER

            Answered 2020-Feb-04 at 04:32

            With fonttools installed in your Python (virtualenv, pipenv, etc):

            Source https://stackoverflow.com/questions/60049960

            QUESTION

            ImportError: cannot import name redirect_stderr
            Asked 2019-Sep-19 at 16:47

            I think this somehow related to installed Python, but I have no clue how to fix it.

            This is what I have:

            ...

            ANSWER

            Answered 2019-Sep-19 at 15:24

            You need to uninstall fontTools and then install the py27 branch of it. The version you are using isn't backwards compatible to Python 2.7

            Source https://stackoverflow.com/questions/58014172

            QUESTION

            How to use fontTools to detect Type 1 and OpenType CFF fonts
            Asked 2019-May-04 at 19:33

            I know that it's possible to detect Type 1 and OpenType CFF (“PostScript flavored OpenType”) fonts by checking the first 4 bytes for 'OTTO' (0x4F54544F).

            How would I do this in Python with the fontTools library? I.e., which font table would I need to check for this value?

            ...

            ANSWER

            Answered 2019-May-04 at 19:33

            The version is stored in the font file header, not in a font data table. If you have a ttLib.TTFont object (i.e. you've opened a font file with fontTools), you can look at the .sfntVersion attribute of your TTFont object to get the version (which will usually be either 0x00010000/Version 1 or 0x4F54544F/OTTO, but there are other possible values, see below). But that kind of assumes you've already created a TTFont object by opening a font file, so this might be a kind of chicken-and-egg issue. If you're interested in knowing the version before you attempt to open the file/create a TTFont, you'll have to sniff the first four bytes (at least), outside of fontTools.

            Note: I'm a little confused by your question. You mention Type 1, which is indeed a kind of PostScript font, but not (usually) the kind in OpenType/sfnt-housed fonts (that would be Type 2, "Compact Font Format", or CFF). There is supposedly a way to store Type 1 in OpenType/sfnt-housed fonts; Apple mentions this in their TrueType Reference manual:

            The values 'true' (0x74727565) and 0x00010000 are recognized by OS X and iOS as referring to TrueType fonts. The value 'typ1' (0x74797031) is recognized as referring to the old style of PostScript font housed in a sfnt wrapper. The value 'OTTO' (0x4F54544F) indicates an OpenType font with PostScript outlines (that is, a 'CFF ' table instead of a 'glyf' table). Other values are not currently supported.

            So if typ1 is in fact what you're asking about, you could look for 0x74797031/"typ1" in the first four bytes of the file. But actual typ1 sfnt-housed fonts are exceedingly rare -- like almost non-existent. The overwhelming majority of actual Type 1 fonts will be in either .PFA/.PFB files (for non-Mac platforms), or in a "Printer Font" file (pre-OS X Mac), which would be paired with the old resource-fork "suitcase" file containing bitmaps. Type 1 font files will have %!PS-AdobeFont-1 as the first bytes of the file.

            Source https://stackoverflow.com/questions/55966692

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install fonttools

            You can install using 'pip install fonttools' or download it from GitHub, PyPI.
            You can use fonttools like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install fonttools

          • CLONE
          • HTTPS

            https://github.com/fonttools/fonttools.git

          • CLI

            gh repo clone fonttools/fonttools

          • sshUrl

            git@github.com:fonttools/fonttools.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link