Commit graph

11 commits

Author SHA1 Message Date
Fini Jastrow
0265034054 name-parser: Tweak mild name shortening
[why]
When we have a weight/width that can take a modifier, and a modifier is
present we always take the shortest form of the weight/width.

This is not how it is customarily done.

Experienced:
  ExtraCondensed ExtraBold -> ExtCd ExtBd
Expected:
  ExtraCondensed ExtraBold -> ExtCond ExtBd

[how]
In case a modifier is present:
Use the shortest form for weights.
Use the longer short form for widths.

[note]
Also circumvent CodeClimate issue by replacing if-s with formulas.
And adding one nonsense entry to the data tables, because they were
too 'similar' :rolleyes:

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-04-19 18:19:54 +02:00
Fini Jastrow
9be4835c29 font-patcher: Introduce less severe family name shortening
[why]
We want to keep "Nerd Font" in the font name if possible and instead
shorten the weight part with accepted abbreviations. But these abbrevs
are hard to read and sometimes a more mild abbreviating might be
sufficient to get the desired name length.

[how]
Introduce a new shortening method for the weight parts of a family name.
It takes a longer word (often un-shortened) when a weight stands on its
own, but when a modifier is used together with the weight the more
aggressive two-letter abbreviations are used.

That new shortening method becomes the default and all the functions get
a new parameter to enforce completely aggressive shortening, i.e. always
use the shortest possible form.

The new way to shorten is exposed all the way out to the font-patcher
user who can select the shortening method as parameter to the
--makegroups option. That option is undocumented because I expect some
changes later on, still.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-04-19 15:57:50 +02:00
Fini Jastrow
725df33434 name-parser: Allow generic renaming parts
[why]
Some name parts occur in several fonts but they take too much length
that we need to add 'Nerd Font' to the font name.

This can be handled as 'generic' SIL table parts, but the algorithm
stops searching for replacements one it has found one.

[how]
Always evaluate all rules of the SIL table.

Add entries for generics to the SIL table.
Add rule for BigBlueTerminal (437TT).
Also fix rule for MPlus that underwent a naming change with its update.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-04-15 21:14:00 +02:00
Fini Jastrow
0558b14525 CI: Fix codeclimate issues
[why]
Cognitive burden of shorten_style_name() is 13 (allowed 9).

Duplicate code
        if self.use_short_families[1]:
            weights = FontnameTools.short_styles(weights)
            styles = FontnameTools.short_styles(styles)

[how]
I do not really buy the duplicate code issue (but circumvent it anyway).

shorten_style_name() was really hard to grasp, maybe use of a helper
function makes it more readable.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-04-15 20:57:08 +02:00
Fini Jastrow
ae656bad83 name-parser: Further formalize style handling
[why]
Some styles can not take modifiers. We handle the shortening as if they
can. That is not a problem but mighht be unexpected.

Do detect weights we have a fixed list, but that is missing a lot
weights that we would be able to shorten.

The shortening does not work for 'Retina', which is imho a more recent
'invention' (after the paper of the previous commit has been written).

[how]
Separate known weights and make them accessible from other functions.
Use these data tables also for weight detection.
Introduce 'Retina' in the weights table.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-04-15 20:57:07 +02:00
Fini Jastrow
81e2e1f988 name-parser: Generalize and shorten style-shortening
[why]
We really struggle to keep the font names below the length limits. To
achieve this some styles are abbreviated. The abbreviations have been
taken from Noto and were initially used to mimic Noto's naming scheme.

But a bit shorter names would help in some instances to produce short
enough name entries. Also some styles that are used by fonts other than
Noto are not abbreviated at all.

[how]
In document [1] Adobe gives examples of very short style abbreviations.
We just implement all these.

Example: 'ExtraCondensed' now becomes 'XCn' instead of the more readable
but longer 'ExtCond' that Noto uses.

[1] https://adobe-type-tools.github.io/font-tech-notes/pdfs/5088.FontNames.pdf

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-04-15 20:57:07 +02:00
Fini Jastrow
44ffebcaa3 name-parser: Add Extended to known styles
[why]
This is missing, for example for
  iosevka-extendedextralightoblique

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-04-14 08:01:12 +02:00
Fini Jastrow
e5d835080e Drop 'IBM' from 3270's names
[why]
The font was always called 3270.
Having a big company's name in the fontname is scary 😬

See
https://github.com/rbanffy/3270font/issues/60

[how]
Add renaming rule.

Fixes: #1012

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-17 15:44:20 +01:00
Fini Jastrow
b52f0a7cb1 Fix 3270 naming
[why]
Somehow the `IBM 3270 SemiCondensed` font turn out as
`IBM3270Semi Nerd Font Condensed`.

The 3270 font always had the quirk to have a non-standard style with a
dash. We have specific code to circumvent that.

[how]
After updating 3270 the 'Narrow' had been renamed to 'Condensed' and so
our specific patch did not work anymore.

Adapt the regex to find the new style that needs correction.

[note]
https://github.com/ryanoasis/nerd-fonts/issues/1012#issuecomment-1385497230

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-17 15:31:59 +01:00
Fini Jastrow
080a86e966 name-parser: Fix Python2 compatibility
[why]
The naming has bizarre blanks strewn in sometimes,
or is all caps. For example
`C a s k a y d i a   C o v e` or
`CASKAYDIACOVE-Regular`

[how]
When run under Python2 all strings are unicode strings because
`unicode_literals` is imported by `font-patcher`.
Unfortunately the code checks for type str; but that will all become
type unicode with the import.

One check is suboptimal anyhow and can be dropped, while the other is
turned around.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-08-22 10:53:05 +02:00
Fini Jastrow
6d86114a38 Draft: Introduce a file name parser
DO NOT MERGE

[why]
A lot of the fonts have incorrect naming after patching. A completely
different approach can help to come up with a consistent naming scheme.

[how]
See bin/scripts/name-parser/README.md

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-08-22 10:53:05 +02:00