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

Add support for all font-family names #71

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MeanderingProgrammer
Copy link

@MeanderingProgrammer MeanderingProgrammer commented Apr 14, 2024

Thanks for the awesome work on this application, makes recording demos much easier!

Let me know if there's any more info I can provide or testing to do.

Problem

While using this tool to generate recordings I noticed an odd behavior in how I had to specify font-family name.

For some reason the name I had to specify was another option that pops up in fc-list (typically the last one), which would end up not matching the value in FontBook on MacOS. This made determining the correct name of the font more difficult.

For example the following would work: --font-family "JetBrainsMono NFM"
But the more usual name for the font would fail: --font-family "JetBrainsMono Nerd Font Mono"

Solution

The problem is caused by the old version of fontdb being used. Prior 0.11.0 the library would choose the first valid value for the font family and that is all it would look at in the call to query.

The following commit fixed this by processing a list of font-families: RazrFalcon/fontdb@8ffb890

There are some tied dependencies here, in particular the version of fontdb needs to match the one used in resvg / usvg, or at least be compatible.

The first version of resvg and usvg that use a version of fontdb >= 0.11.0 is the very next version 0.29.0. And 0.29.0 depends on 0.12.0. So this seems like a good upgrade path.

Once fontdb is able to query the font no real change is needed other than handling a slightly different return type.

The only other change introduced is the removal of the keep_named_groups option in the call to convert_text in commit:
RazrFalcon/resvg@d5e5fcf

Testing

After building I was able to verify the both of the following succeed:

./target/release/agg demo.cast temp.gif --font-family "JetBrainsMono NFM"
./target/release/agg demo.cast temp.gif --font-family "JetBrainsMono Nerd Font Mono"

The latter usually fails with the following:

Error: no faces matching font families JetBrainsMono Nerd Font Mono

Side Effect

Since this implementation returns the first font family in the output of fontdb.query verbose logging is no longer guaranteed to write the exact font family name provided as input. The first font family as written in the fontdb docs states: "Where the first family is always English US, unless it's missing from the font".

For instance both of these commands:

./target/release/agg demo.cast temp.gif --font-family "JetBrainsMono NFM" -v
./target/release/agg demo.cast temp.gif --font-family "JetBrainsMono Nerd Font Mono" -v

Output:

[INFO  agg] selected font families: ["JetBrainsMono Nerd Font Mono"]

This can be changed back by modifying the implementation of find_font_family to return the input name if face_info.families is not empty rather than returning the first value in that list.

# Problem

While using this tool to generate recordings I noticed an odd behavior in
how I had to specify font-family name.

For some reason the name I had to specify was another option that pops up
in `fc-list` (typically the last one), which would end up not matching the
value in FontBook on MacOS. This made determining the correct name of the
font more difficult.

For example the following would work: `--font-family "JetBrainsMono NFM"`
But the more usual name for the font would fail: `--font-family "JetBrainsMono Nerd Font Mono"`

# Solution

The problem is caused by the old version of `fontdb` being used. Prior 0.11.0
the library would choose the first valid value for the font family and that
is all you could access.

This following commit fixed this by returning a list:
RazrFalcon/fontdb@8ffb890

There are some tied dependencies here, in particular the version of `fontdb`
needs to match the one used in `resvg` / `usvg`, or at least be compatible.

The first version of `resvg` and `usvg` that use a version of `fontdb` >= 0.11.0
is the very next version 0.29.0. And 0.29.0 depends on 0.12.0. So this seems like
a good upgrade path.

Once we have the list of fonts out of `fontdb` the actual code change is straightforward.

The only other change introduced is the removal of the `keep_named_groups` option
in the call to `convert_text` in commit:
RazrFalcon/resvg@d5e5fcf

# Testing

After building I was able to verify the both of the following succeed:

```
./target/release/agg demo.cast temp.gif --font-family "JetBrainsMono NFM"
./target/release/agg demo.cast temp.gif --font-family "JetBrainsMono Nerd Font Mono"
```

The latter usually fails with the following:

```
Error: no faces matching font families JetBrainsMono Nerd Font Mono
```
# Details

The real fix for handling fonts with mulitple families is in the
query logic in `fontdb` which iterates over the list looking for
a match rather than only looking at the first one.

Within the application can continue selecting the first one in
the response.
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 this pull request may close these issues.

None yet

1 participant