Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use python script to add FastFont into a existing font? #27

Open
WandersonAlves opened this issue Mar 5, 2025 · 3 comments
Open
Assignees
Labels
question Further information is requested

Comments

@WandersonAlves
Copy link

Hello!

There are no instructions on how to do this through python script.
Can it be added? Something that tells how to prepare the python environment, how to run the command, and whether it needs extra files to work.

Ty!

@Born2Root Born2Root self-assigned this Mar 7, 2025
@Born2Root Born2Root added the question Further information is requested label Mar 7, 2025
@Born2Root
Copy link
Owner

Hi,

the script is pretty straightforward to use.

  • install python & python-fonttools library
    pip install fonttools

  • download the script itself: addfeatures.py

  • download the FastFont ruleset opentype_feature.fea

  • give the script the following parameters:
    desired name of the final finished font
    the input-font that should be transformed to speed reading
    the substitute fea with the rules to apply

python3 ./addfeatures.py -o output_name.otf input_font.ttf opentype_feature.fea

In our other Repo where we showcased different Font experiments, there is also an elaborate explenation apart from the speed reading use case.

Featue Font Experiments - Example

@WandersonAlves
Copy link
Author

WandersonAlves commented Mar 26, 2025

Nice, ty! I managed to run the script, thanks again! But i'm receving some syntax errors

➜ python3 ./addfeatures.py -o Dosis-FastFont.otf Dosis-VariableFont_wght.ttf opentype_feature.fea
Adding features
Traceback (most recent call last):
  File "/Users/pops/Downloads/Dosis/./addfeatures.py", line 22, in <module>
    addOpenTypeFeatures(font, args.feature)
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/builder.py", line 65, in addOpenTypeFeatures
    builder.build(tables=tables, debug=debug)
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/builder.py", line 186, in build
    self.parseTree = Parser(self.file, self.glyphMap).parse()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 104, in parse
    statements.append(self.parse_feature_block_())
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 1744, in parse_feature_block_
    self.parse_block_(block, vertical, stylisticset, size_feature, cv_feature)
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 1968, in parse_block_
    statements.append(self.parse_substitute_())
                      ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 846, in parse_substitute_
    ) = self.parse_glyph_pattern_(vertical=False)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 442, in parse_glyph_pattern_
    gc = self.parse_glyphclass_(accept_glyphname=True)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 349, in parse_glyphclass_
    raise FeatureLibError(
fontTools.feaLib.error.FeatureLibError: opentype_feature.fea:15:9: Unknown glyph class @calt3

I'm trying to add Fast-Font into Dosis font from google.

Also i tried with the latin base .fea file from this documentation https://github.com/Born2Root/Fast-Font/blob/main/README_Tutorial.md but when i run it, i receive another error:

➜ python3 ./addfeatures.py -o Dosis-FastFont.otf Dosis-VariableFont_wght.ttf opentype_feature.fea
Adding features
Traceback (most recent call last):
  File "/Users/pops/Downloads/Dosis/./addfeatures.py", line 22, in <module>
    addOpenTypeFeatures(font, args.feature)
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/builder.py", line 65, in addOpenTypeFeatures
    builder.build(tables=tables, debug=debug)
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/builder.py", line 186, in build
    self.parseTree = Parser(self.file, self.glyphMap).parse()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 104, in parse
    statements.append(self.parse_feature_block_())
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 1744, in parse_feature_block_
    self.parse_block_(block, vertical, stylisticset, size_feature, cv_feature)
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 1944, in parse_block_
    statements.append(self.parse_glyphclass_definition_())
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 285, in parse_glyphclass_definition_
    glyphs = self.parse_glyphclass_(accept_glyphname=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 366, in parse_glyphclass_
    start, limit = self.split_glyph_range_(glyph, location)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/fontTools/feaLib/parser.py", line 320, in split_glyph_range_
    raise FeatureLibError(
fontTools.feaLib.error.FeatureLibError: opentype_feature.fea:4:8: "a.bold-z.bold" is not a glyph in the font, and it can not be split into a range of known glyphs

Perhaps Dosis is not compatible with this? I download the variable version of it

@Born2Root
Copy link
Owner

Hi,
it looks like the font you are using is missing some glyphs
You can just delete those glyph declaring lines in the .fea Feature definition or add the glyps in the font.

Using the Python script makes this adjustment process a bit complicated for the first time since it always gives you just a couple of errors. For the first time adjusting the font, it is much easier using a GUI-Software like Font-Lab.
That GUI-tools show you all missing glyphs directly at once, so you can adjust the font or remove the lines from the feature definition.

I made a detailled tutorial on howto apply the fast-reading features using the software.

https://github.com/Born2Root/Fast-Font/blob/main/README_Tutorial.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants