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 can you build the font with certain features enabled? #1348

Closed
Mango0x45 opened this issue Jan 5, 2022 · 20 comments
Closed

How can you build the font with certain features enabled? #1348

Mango0x45 opened this issue Jan 5, 2022 · 20 comments

Comments

@Mango0x45
Copy link

I would like to have the alternative ligatures for <= and >= (feature ss02) however emacs (the editor I use) doesn't have support for enabling font features. Would it be possible to just build the font from source with my desired features as the defaults? If so, how can I go about doing so?

I tried to investigate this myself, and decided that as a start I should see if I can simply build the thing without any changes, however from a clean clone of the repository I execute the following:

$ doas make  PWD=`pwd`  # Docker wants me to be root

and I get the following error as output:

docker build -t fira:latest .
Sending build context to Docker daemon  16.83MB
Step 1/4 : FROM python:3
 ---> a5d7930b60cc
Step 2/4 : WORKDIR /opt
 ---> Using cache
 ---> d95a74d9c1dc
Step 3/4 : RUN pip install --upgrade Pillow==5.4.1 idna==2.8 requests==2.21.0 urllib3==1.24.1 pycairo==1.20.1 gftools==0.7.4 fontmake==2.4.0 fontbakery==0.8.0
 ---> Using cache
 ---> b7618fbeefd5
Step 4/4 : RUN apt-get update &&     apt-get install -y ttfautohint &&     apt-get install -y woff2 &&     apt-get install -y sfnt2woff-zopfli
 ---> Using cache
 ---> 43c13ef81cc3
Successfully built 43c13ef81cc3
Successfully tagged fira:latest
docker run --rm -v /home/thomas/down/fonts/FiraCode-6.2:/opt fira:latest ./script/build.sh
Making  distr/ttf/FiraCode-Light.ttf
INFO:fontmake.font_project:Building master UFOs and designspace from Glyphs source
INFO:glyphsLib.classes:Parsing "FiraCode.glyphs" file into <GSFont>
INFO:fontmake.font_project:Interpolating master UFOs from designspace
INFO:fontmake.font_project:Generating instance UFO for "Fira Code Light"
INFO:fontmake.font_project:Building TTF for FiraCode-Light
INFO:ufo2ft:Pre-processing glyphs
INFO:ufo2ft.filters.base:Running EraseOpenCornersFilter on FiraCode-Light
INFO:ufo2ft.filters.base:Running DecomposeComponentsFilter on FiraCode-Light
INFO:ufo2ft.filters.base:Running RemoveOverlapsFilter on FiraCode-Light
INFO:ufo2ft.filters.base:Running CubicToQuadraticFilter on FiraCode-Light
INFO:ufo2ft.filters.cubicToQuadratic:New spline lengths: 1: 345, 2: 2869, 3: 1186, 4: 369, 5: 40, 6: 7
INFO:ufo2ft:Building OpenType tables
fontmake: Error: In 'FiraCode.glyphs' -> 'master_ufo/FiraCode.designspace' -> 'master_ufo/instance_ufo/FiraCode-Light.ufo': Compiling UFO failed: master_ufo/instance_ufo/FiraCode-Light.ufo/features.fea:2031:1: Expected glyph class definition or statement: got NAME featureNames
make: *** [Makefile:7: build] Error 1

as someone who has no idea about anything related to fonts, how can I deal with this error?

@tonsky
Copy link
Owner

tonsky commented Jan 5, 2022

Interesting! Our CI uses docker image and it seems to work: https://github.com/tonsky/FiraCode/blob/master/.github/workflows/build.yml

One difference might be that this docker image was built from a different Dockerfile? I am not sure how to check for that

Screenshot 2022-01-05 at 16 02 23

Screenshot 2022-01-05 at 16 02 32

@tonsky
Copy link
Owner

tonsky commented Jan 5, 2022

Check with tonsky/firacode:latest maybe?

@Mango0x45
Copy link
Author

Doesn't seem to be working, the Dockerfile is exactly the same as the image above, and compiling still gives me this error:

[thomas@mango-os FiraCode-6.2 $] doas make PWD=`pwd`
docker build -t tonsky/firacode:latest .
Sending build context to Docker daemon  16.83MB
Step 1/4 : FROM python:3
 ---> a5d7930b60cc
Step 2/4 : WORKDIR /opt
 ---> Using cache
 ---> d95a74d9c1dc
Step 3/4 : RUN pip install --upgrade Pillow==5.4.1 idna==2.8 requests==2.21.0 urllib3==1.24.1 pycairo==1.20.1 gftools==0.7.4 fontmake==2.4.0 fontbakery==0.8.0
 ---> Using cache
 ---> b7618fbeefd5
Step 4/4 : RUN apt-get update &&     apt-get install -y ttfautohint &&     apt-get install -y woff2 &&     apt-get install -y sfnt2woff-zopfli
 ---> Using cache
 ---> 43c13ef81cc3
Successfully built 43c13ef81cc3
Successfully tagged tonsky/firacode:latest
docker run --rm -v /home/thomas/down/fonts/FiraCode-6.2:/opt tonsky/firacode:latest ./script/build.sh
Making  distr/ttf/FiraCode-Light.ttf
INFO:fontmake.font_project:Building master UFOs and designspace from Glyphs source
INFO:glyphsLib.classes:Parsing "FiraCode.glyphs" file into <GSFont>
INFO:fontmake.font_project:Interpolating master UFOs from designspace
INFO:fontmake.font_project:Generating instance UFO for "Fira Code Light"
INFO:fontmake.font_project:Building TTF for FiraCode-Light
INFO:ufo2ft:Pre-processing glyphs
INFO:ufo2ft.filters.base:Running EraseOpenCornersFilter on FiraCode-Light
INFO:ufo2ft.filters.base:Running DecomposeComponentsFilter on FiraCode-Light
INFO:ufo2ft.filters.base:Running RemoveOverlapsFilter on FiraCode-Light
INFO:ufo2ft.filters.base:Running CubicToQuadraticFilter on FiraCode-Light
INFO:ufo2ft.filters.cubicToQuadratic:New spline lengths: 1: 345, 2: 2869, 3: 1186, 4: 369, 5: 40, 6: 7
INFO:ufo2ft:Building OpenType tables
fontmake: Error: In 'FiraCode.glyphs' -> 'master_ufo/FiraCode.designspace' -> 'master_ufo/instance_ufo/FiraCode-Light.ufo': Compiling UFO failed: master_ufo/instance_ufo/FiraCode-Light.ufo/features.fea:2031:1: Expected glyph class definition or statement: got NAME featureNames
make: *** [Makefile:7: build] Error 1

Heres the diff showing the changes I made to the Makefile (I've never used Docker before so I hope I did this correctly?)

4c4
< 	docker build -t fira:latest .
---
> 	docker build -t tonsky/firacode:latest .
7c7
< 	docker run --rm -v ${PWD}:/opt fira:latest ./script/build.sh
---
> 	docker run --rm -v ${PWD}:/opt tonsky/firacode:latest ./script/build.sh

@Mango0x45
Copy link
Author

Also once I get building to actually work, how could I go about replacing certain default ligatures with their variants?

@tonsky
Copy link
Owner

tonsky commented Jan 5, 2022

I have re-checked on a fresh machine and fresh checkout, it builds ok with the Docker. Have you modified the FiraCode.glyphs file maybe?

As for modification, you might need to modify glyphs file. The way I would go about it I’d take ss02 code (search for name = ss02 entry and copy what it has for code) and appended it to the end of calt code (search for name = calt).

Alternatively, find greater_equal.liga in calt code and replace it with greater_equal.ss02, then repeat for less_equal.liga. Hope that works!

@Mango0x45
Copy link
Author

I have re-checked on a fresh machine and fresh checkout, it builds ok with the Docker. Have you modified the FiraCode.glyphs file maybe?

Nope, it's from a fresh clone of the repo, I haven't modified anything. Perhaps I am doing something wrong running the Makefile as root? Docker seems to insist that I be root for basically everything, although I don't know if that's intentional or not.

Also to make sure that I am actually doing this properly, here are all my steps:

$ git clone https://github.com/tonsky/FiraCode.git
$ cd FiraCode
$ doas dockerd --dns=8.8.8.8 # This is in another terminal
$ doas make PWD=`pwd`

@tonsky
Copy link
Owner

tonsky commented Jan 5, 2022

Funny, I thought Docker is meant to be reproducible :) I am no expert in it, can’t help you, unfortunately

@Mango0x45
Copy link
Author

Do you have any idea what the error means though? Perhaps I can try to find a way to fix it. Also I got the whole "docker needs me to be root" thing sorted out and that doesn't seem to be the issue

@tonsky
Copy link
Owner

tonsky commented Jan 5, 2022

Well, fontmake doesn’t like the glyphs file for some reason 🤷‍♂️

@Mango0x45
Copy link
Author

What exact commands are you running to build it? I can try on another machine tomorrow.

@tonsky
Copy link
Owner

tonsky commented Jan 6, 2022

docker run --rm -v $PWD:/opt tonsky/firacode:latest ./script/build.sh

@Mango0x45
Copy link
Author

I managed to get a build to work! For anyone in the future with the same issue, here is what I did:

$ doas rm -rf /var/lib/docker  # Remove all the cache
$ doas dockerd --dns=8.8.8.8 & >&2 2>/dev/null  # Start the docker daemon
$ docker run --rm -v $(PWD):/opt tonsky/firacode:latest ./script/build.sh  # Build everything

Why it didn't work the previous times? No clue, but it works now so that's all I care about. I'll update later with my results at patching in the desired features as defaults.

@Mango0x45
Copy link
Author

How can I enable a feature such as cv25? It doesn't seem to be as straight forwards as ss02.

@tonsky
Copy link
Owner

tonsky commented Jan 10, 2022

cv25 enables .- ligature. It’s exactly the same: append its code to calt

@Mango0x45
Copy link
Author

If only it was that easy:

fontmake: Error: In 'FiraCode.glyphs' -> 'master_ufo/FiraCode.designspace' -> 'master_ufo/instance_ufo/FiraCode-Light.ufo': Compiling UFO failed: <features>:1748:5: Lookup "period_hyphen" has already been defined

@tonsky
Copy link
Owner

tonsky commented Jan 15, 2022

Interesting! Maybe remove block related to cv25?

@Mango0x45
Copy link
Author

Tried that and got this:

fontmake: Error: In 'FiraCode.glyphs' -> 'master_ufo/FiraCode.designspace' -> 'master_ufo/instance_ufo/FiraCode-Light.ufo': Compiling UFO failed: <features>:84:5: Feature cv25 has not been defined

@tonsky
Copy link
Owner

tonsky commented Jan 17, 2022

Find and remove references to it?

@Daxtorim
Copy link
Contributor

Daxtorim commented Mar 4, 2022

You must only copy the parts inside the lookups to calt to avoid the multiple definitions error. Only copy it though, the original definition must remain intact.

The original FiraCode.glyphs (the actual file uses \012 instead of newline characters for some reason, so the formatting will be hard to read, but inside vim a simple :%s@\\012@\r@g will convert it to an easier to read format. You don't need to change it back, the file works like that as well):

{
code = "
[original calt code here...]
";
name = calt;
},
{
code = "sub greater_equal.liga by greater_equal.ss02;
sub less_equal.liga by less_equal.ss02;";
name = ss02;
notes = "Name: Less Than/Greater Than with horizontal bar";
},
{
code = "lookup slash_equal_as_not_equal {
  sub slash.spacer equal_end.seq' by exclam_equal.liga;
  sub slash_equal_start.seq' equal_end.seq by slash.spacer;
} slash_equal_as_not_equal;";
name = cv24;
notes = "Name: /= as not equal";
},

should become

{
code = "
[original calt code here...]

### Paste your desired features here *after* the original part: ###

# ss02
sub greater_equal.liga by greater_equal.ss02;
sub less_equal.liga by less_equal.ss02;

# cv24 ### do NOT copy the lookup surroundings
sub slash.spacer equal_end.seq' by exclam_equal.liga;
sub slash_equal_start.seq' equal_end.seq by slash.spacer;

";
name = calt;
},
### keep the original feature definitions intact, they are still needed ###
{
code = "sub greater_equal.liga by greater_equal.ss02;
sub less_equal.liga by less_equal.ss02;";
name = ss02;
notes = "Name: Less Than/Greater Than with horizontal bar";
},
{
code = "lookup slash_equal_as_not_equal {
  sub slash.spacer equal_end.seq' by exclam_equal.liga;
  sub slash_equal_start.seq' equal_end.seq by slash.spacer;
} slash_equal_as_not_equal;";
name = cv24;
notes = "Name: /= as not equal";
},

Then from the root of the git repo you can use the docker command from above to build the font.
docker run --rm -v ${PWD}:/opt tonsky/firacode:latest ./script/build.sh

Your finished font will be in distr/variable_tff/FiraCode_VF.tff. Individual font weights will be in distr/tff/.

@tonsky
Copy link
Owner

tonsky commented Mar 15, 2022

Resolved via #1387

@tonsky tonsky closed this as completed Mar 15, 2022
achuie added a commit to achuie/dotfiles that referenced this issue Oct 6, 2023
…f just the rules like an overly-cautious reading of tonsky/FiraCode#1348 (comment) would suggest.
achuie added a commit to achuie/dotfiles that referenced this issue Oct 6, 2023
…nstead of just the rules like an overly-cautious reading of tonsky/FiraCode#1348 (comment) would suggest."

This reverts commit 1cacd16.

Fixes some ligatures like ellipses and circumflex-equals.
achuie added a commit to achuie/dotfiles that referenced this issue Oct 6, 2023
* Switch away from flake-utils.

* Better pset organization.

* Update flake.lock

* Glyph-editing script.

* Add logging.

* Account for different ligature block endings; open file exclusively for writing to fix length difference bug.

* Update flake.lock

* Testing reveals that the whole lookup block can be removed, instead of just the rules like an overly-cautious reading of tonsky/FiraCode#1348 (comment) would suggest.

* Revert "Testing reveals that the whole lookup block can be removed, instead of just the rules like an overly-cautious reading of tonsky/FiraCode#1348 (comment) would suggest."

This reverts commit 1cacd16.

Fixes some ligatures like ellipses and circumflex-equals.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants