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

Feature: Select name source #1319

Merged
merged 3 commits into from
Jul 17, 2023
Merged

Feature: Select name source #1319

merged 3 commits into from
Jul 17, 2023

Conversation

Finii
Copy link
Collaborator

@Finii Finii commented Jul 17, 2023

Description

font-patcher: Add option to select postscript name as name source

[why]
In the post we used these information sources to determine the name and
weights/styles of the to-be-patched font:

  • The filename
  • The fullname (ID 4)
  • The postscriptname (ID 6)

Usually it is best to use the Fullname of a font to determine its real
name and styles/weights:

The Postscript name has the advantage to have a hyphen between name and
styles/weight; but as it can not contain blanks the correct name can not
be determined by this. To get the styles/weights back we use a list of
all possible (?!) weights and styles and sort all the string parts.

This works reasonably well and the fullname is usually best.

Not so with Input Mono Condensed. Here are its names:
ID4: "InputMonoCondensed LightIta"
ID6: "InputMonoConsensed-LightItalic"

[how]
Add option to select between fullname and postscriptname as font naming
source.

For special purposes, also allow a custom (arbitrary) name input.
If that is given the specified name will be used to name the patched
font without adding any suffix - the user has full control on the name.

Fixes: #1314

Requirements / Checklist

What does this Pull Request (PR) do?

How should this be manually tested?

Any background context you can provide?

What are the relevant tickets (if any)?

Screenshots (if appropriate or helpful)

[why]
A lot arguments need one user supplied value, but that is not enforced.
For example
    font-patcher src/unpatched-fonts/Agave/Agave-Regular.ttf --out

results in a crash, because the needed output directory has not been
passed, but the default is also not used.

The problem is that the option is defined to take any amount of values,
includeing zero values (and more than one value).
That all does not make sense. The switch does need exactly one value.

[how]
Remove the wrong nargs specification. Instead use the default, which is
'expect one value' for the default action 'store'.

Instead of a crash the user is now presented with this output:
    font-patcher: error: argument -out/--outputdir: expected one argument

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
In the post we used these information sources to determine the name and
weights/styles of the to-be-patched font:
* The filename
* The fullname (ID 4)
* The postscriptname (ID 6)

Usually it is best to use the Fullname of a font to determine its real
name and styles/weights:

The Postscript name has the advantage to have a hyphen between name and
styles/weight; but as it can not contain blanks the correct name can not
be determined by this. To get the styles/weights back we use a list of
all possible (?!) weights and styles and sort all the string parts.

This works reasonably well and the fullname is usually best.

Not so with Input Mono Condensed. Here are its names:
ID4: "InputMonoCondensed LightIta"
IF6: "InputMonoConsensed-LightItalic"

[how]
Add option to select between fullname and postscriptname as font naming
source.

For special purposes, also allow a custom (arbitrary) name input.
If that is given the specified name will be used to name the patched
font without adding any suffix - the user has full control on the name.

Fixes: #1314

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@Finii Finii merged commit 64cf3e9 into master Jul 17, 2023
4 checks passed
@Finii Finii deleted the feature/select-name-source branch July 17, 2023 09:58
@HUMORCE
Copy link

HUMORCE commented Jul 19, 2023

Screenshot_230719035208

When specifying name with arg --name 'Example NF', space was ignored. How to specify a font name contains spaces?

@Finii
Copy link
Collaborator Author

Finii commented Jul 19, 2023

Oh. Well, I guess you can't because blanks are always removed from the name (e.g. NetBrains Mono -> NetBrainsMono).

Can you describe your use-case?

@Finii
Copy link
Collaborator Author

Finii commented Jul 19, 2023

$ fontforge font-patcher --dry --debug 2 --name 'Example Mono' src/unpatched-fonts/Agave/Agave-Regular.ttf
[...]
DEBUG: =====> Family (ID 1)      ok       (11 <=31): ExampleMono
DEBUG: =====> SubFamily (ID 2)   ok       ( 7 <=31): Regular
DEBUG: =====> Fullname (ID 4)    ok       (11 <=63): ExampleMono
DEBUG: =====> PSN (ID 6)         ok       (11 <=63): ExampleMono
DEBUG: =====> Filename 'ExampleMono-Regular.ttf'

If you can edit the font-patcher script you can enable the blanks by changing the circled value from True to False:

image

@Finii
Copy link
Collaborator Author

Finii commented Jul 19, 2023

Maybe that should be the default if --name is given? 🤔

Use case would be helpful to decide on this. I in fact did not think anybody would ever use that feature :-D

@HUMORCE
Copy link

HUMORCE commented Jul 19, 2023

Can you describe your use-case?

I just want to get a font name that is as short as possiable.

e.g.: Input Mono #1314

fontforge -script font-patcher --mono Input/Input-Bold.ttf --name 'Input NF Bold'
# actual: InputNF
# expect: Input NF

enable the blanks by changing the circled value from True to False

Yeah, It works like I expected. Thanks!

$ fontforge -script font-patcher --dry --debug 2 --name 'Input NF' --mono source/Input/Input-Regular.ttf
Copyright (c) 2000-2022. See AUTHORS for Contributors.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 with many parts BSD <http://fontforge.org/license.html>. Please read LICENSE.
 Version: 20201107
 Based on sources from 2022-01-13 19:13 UTC-ML-D-GDK3.
PythonUI_Init()
copyUIMethodsToBaseTable()
Nerd Fonts Patcher v3.0.2 (4.5.0) (ff 20201107)
DEBUG: Naming mode 1
The glyph named Tcommaaccent is mapped to U+021A.
  But its name indicates it should be mapped to U+0162.
The glyph named Delta is mapped to U+0394.
  But its name indicates it should be mapped to U+2206.
The glyph named Omega is mapped to U+03A9.
  But its name indicates it should be mapped to U+2126.
The glyph named tcommaaccent is mapped to U+021B.
  But its name indicates it should be mapped to U+0163.
The glyph named mu is mapped to U+03BC.
  But its name indicates it should be mapped to U+00B5.
DEBUG: Monospace check: Panose says "monospaced"; glyph-width-mono True
DEBUG: Extended glyphs wider bounding box than basic glyphs
DEBUG: Font has negative right side bearing in extended glyphs
DEBUG: Final font cell dimensions 662 w x 1320 h
Done with Patch Sets, generating font...
DEBUG: =====> Family (ID 1)      ok       ( 8 <=31): Input NF
DEBUG: =====> SubFamily (ID 2)   ok       ( 7 <=31): Regular
DEBUG: =====> Fullname (ID 4)    ok       ( 8 <=63): Input NF
DEBUG: =====> PSN (ID 6)         ok       ( 7 <=63): InputNF
DEBUG: =====> Filename 'InputNF-Regular.ttf'

Maybe that should be the default if --name is given? 🤔

Use case would be helpful to decide on this. I in fact did not think anybody would ever use that feature :-D

It should be default, IMO. Becuase user explicitly specified a name contains space, but space disappeared after patching.

@Finii
Copy link
Collaborator Author

Finii commented Jul 19, 2023

Makes sense, thank you. Will change accordingly.

Finii added a commit that referenced this pull request Jul 19, 2023
[why]
If a user specified a name we should probably not camel-casify it.

Fixes (idea mentioned in): #1319

Suggested-by: HUMORCE
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
@Finii
Copy link
Collaborator Author

Finii commented Jul 19, 2023

Implemented via 12b51f5 in font patcher 4.5.1

LNKLEO pushed a commit to LNKLEO/Nerd that referenced this pull request Nov 24, 2023
[why]
If a user specified a name we should probably not camel-casify it.

Fixes (idea mentioned in): ryanoasis#1319

Suggested-by: HUMORCE
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error patching Input Mono Condensed font
2 participants