[why]
A lot people expect the font-patcher to be a stand alone script. They
even think that the source glyphs (symbols) to be added to be somehow
magically there and one PR makes sure that they are fetched if missing.
The same problem arises when we have a script distributed over multiple
files. For maintenance reasons and code quality this is what one wants.
But that might hinder easy use of the font-patcher.
[how]
Put all the code in the main script.
That has an additional drawback: For the nameparser_test* scripts to
work we need stand alone files for that classes. Now the code is
duplicated and will get out of sync.
I have no solution for that, and it all boils down what Nerd Font wants
to do.
One solution would be to have font-patcher properly set up / divided in
many .py files, and to create one monolithic font-patcher from all the
sources on demand (via github actions or manually when someone pushes
changes to any of the constituends). That approach is taken by a lot of
C++ 'header only libraries' that originally consist of a lot files but
create one big 'all in one' file automatically from all the small files.
For now I guess we can live with the duplication, but we need to think
about a solution, as this will bite us sooner or later.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
Some CJK fonts seem to have no Fullname.
[how]
But they have a Postscript name. Use that for parsing the names.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
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>
[why]
The symbol only fonts Symbols-1000-em Nerd Font Complete.ttf
and 2048-em in `NerdFontsSymbolsOnly/` are generated from
some 'almost' empty source fonts, that are assumable in turn generated
from the sfd font descriptions in `src/glyphs/`?
The process is not documented and we have issues in the generated font
(for example the glyph for capital `E` is defined (and empty) #581#765).
[how]
Use the existing font definitions from `src/glyphs/*.sfd` directly as
source font. That needs a change in font-patcher because the empty
fonts have no glyphs that can be used to orient the scaling upon. In
that case scale on the source font definitions EM.
Then we need patch-em-all to also patch *.sfd fonts.
And finally we need patch-em-all to take a font specific command line
switch for font-patcher (compare 9e2bc9a26 of #723) to instruct it to
create a ttf rather than a sfd font file.
In the sfd file we additionally set the Panose type.
And the UnderlinePosition is adjusted to match the current patched font.
[note]
Also fix wrong glob pattern in patch-em-all `*.[o,t]tf`. The comma is
for sure some leftover from a '{}' shell pattern, that is not used
anymore. (This comment is probably outdated, due to rebasing.)
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
When the source font does not have a HEAD table (i.e. is not a ttf/otf
font but for example a sfd) we can not copy the PPEM and flag values.
The patcher crashes.
[how]
Just put the code into a try block. We could check the signature
instead, but this would add more and complex code.
Reported-by: Jakub Jirutka <jakub@jirutka.cz>
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
Some fonts set specific lower resolutions and handle the small rendering
very nicely. But fontforge does not copy that information when it opens
a font; rather some default values are always written. That can destroy
the small font rendering.
The responsible settings are the 'ppem_to_int' flag and the
'lowestRecPPEM' setting, both in the HEAD table.
[how]
After successfully patching and generating the new font we copy that
settings over from the source font.
Instead of using fontTools (and thereby requiring all users to pull that
dependency) we handle the raw font file changes ourselves.
Fixes: 612
Reported-by: nojus297
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
When the patched font does not have a fullname (which can never happen)
the postprocess is called with a wrong filename.
[note]
Also output the file name of the patched font, for easier access by the user.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
The 'monospace' width is determined by examining all the 'normal' glyphs
and taking the widest one.
'Normal' means 0x00-0x17f: the Latin Extended-A range.
Unfortunately Noto has the '1/2', '1/4', '3/4' that are all wider then the
normal (i.e. letter) glyphs.
[how]
Exclude a small sub-range from the 'find the widest glyph' that contain
no glyphs one would call 'letter'.
Fixes: #610
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
Before Font Logos 1.0.0 there was no stable-codepoint guarantee, and the
later revisions (0.18) reassigned the codepoints. That makes updating
for us very hard, because we would have to resort the icons or follow
the codepoint changes.
With 1.0.0 this changed. That new major release introduced not only a
codepoint guarantee, but it also shifted the codepoints from the F100
region to the F300 region, where we put them anyhow (in most cases).
That is one subset less with 'dynamic base codepoint'.
The reassignment of codepoints in Font Logos kept the codepoints stable
for the icons we already have in release 2.1.0. But at the moment the
2.2.0 Release Candidate (which updated Font Logos with commit 557b8da)
have added glyphs, which are on different points as compared with the
Font Logos 1.0.0 release.
What I want to say, we need to get this straight, before our 2.2.0 RC
turns into a Release 2.2.0.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
In ligature-enabled environments the accent grave will be rendered as
zero width, thus overlapping with the next character (in some source
fonts).
The problem is, that the glyph type in the sourcefonts is set to 'auto',
and fontforge exports these as 'mark' - the patched font will be broken.
[how]
There is no way we can get that glyph to be 'auto', but we can force it
to be an ordinary 'baseglyph' instead, and that will be respected on
export.
Maybe I should raise an Issue at fontforge... maybe later.
Fixes: #858Fixes: #582
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
When a True Type Collection file (.ttc) is used as font source this is
not handled and just the first file in the collection is processed and
saved. But the user is not informed.
When the target file format is True Type Collection, no file at all is
written.
These are two distinct cases, because you can in fact open a .ttc and
save the first font (patched) when specifying a different extension via
`-ext`. Or open a normal font and specify `ttc` as extension i.e. target
file format.
[how]
Check if a collection is to be opened. As we currently have no code to
loop through all fonts (and just the first font is processed) a message
is issued and we exit. Typically a user would want all the fonts and
would have to 'explode' the collection into multiple single font files
beforehand.
Prevent the target to be ttc, as that is not handled in fontforge at
all. To save TTCs a different API function is to be used. Unfortunately
fontforge does not care and just does nothing.
font.generateTtc() would have to be used with ttc extensions...
Anyhow. As the looping through all fonts is missing anyhow, and I feel
the usefulness is very slim, we just prevent silent failures with this
commit.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
The symbol glyphs are rescaled (when --mono is specified) so that they
have a predefined width after insertion in the source font (to be
patched font, called 'target font' below).
Sometimes the width of the glyph after insertion is off a bit, like
0.2% or so. This seems strange, as we calculate the target width
exactly.
[how]
As expected this are rounding errors. In the old code we take the
original width of the glyph when it is in the symbol font and
rescale it when it is in the target font. The width of the glyph
should be the same in the source and the target font, right?
It fact it is not, because the coordinate systems of the two fonts can
(and usually are) different. fontforge's magic scales the glyph
into the new coordinate system on insertion, such that it is approx
the same as before. But when the coordinate system is integer based
we get some small rounding errors just from copy and paste.
To solve this, we
- first copy the glyph from the source into the target font
- then determine the glyphs width
- then rescale the glyph to the target width
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
The ScaleGlyph just gives a lot of anonymous numbers.
[how]
Write down which glyphs are rescaled and group them to related
groups.
They are not changed to 'new' ScaleGlyph method.
[note]
Checked the current Devicons, and they are completely different to ours.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
While patching for --mono with Font Awesome we get glyphs that are
too wide, for example '_520' (0xF22B). In the symbol font original
it is about 1918 wide. According to ScaleGlyph FONTA_SCALE_LIST
it shall be scaled as 0xF17A - which is only 1664 wide.
[how]
Fill the ScaleGlyph of Font Awesome with groups of glyphs that shall be
kept same-sized after scaling.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
While patching for --mono with Font Awesome we get glyphs that are
too wide, for example '_520' (0xF22B). In the symbol font original
it is about 1918 wide. According to ScaleGlyph FONTA_SCALE_LIST
it shall be scaled as 0xF17A - which is only 1664 wide.
This results in too wide symbols in the patched font.
[how]
The ScaleGlyph dict works like this:
- 'ScaleGlyph' Lead glyph, which scaling factor is taken
- 'GlyphsToScale': List of (glyph code) or (list of two glyph codes
that form a closed range)) that shall be scaled
Note that this allows only one group for the whole symbol font, and
that the scaling factor is defined by a specific character, which
needs to be manually selected (on each symbol font update).
The redesign drops 'ScaleGlyph' and changes the glyph list to:
- 'GlyphsToScale': List of ((lists of glyph codes) or (ranges of glyph codes)) that shall be scaled
Each item in 'GlyphsToScale' (a range or an explicit list) forms a group of glyphs that shall be
as rescaled all with the same and maximum possible (for the included glyphs) factor.
The old data structure is automatically rewritten to new entries.
[note]
This commit just changes the algorithm. As the new ScaleGlyph is not
used for any font, there is no change in the patched fonts.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
Sometimes fonts patched with --mono are not recognized as monospaced
fonts.
One reason can be that the inserted glyphs are too wide. This will show
in the end in the font's advanceWidthMax property which is not congruent
to the normal font width.
[how]
After all the scaling and jiggling we double check if the new glyph
already in the to-be-patched is not wider than our design goal for the
width. Normally one would expect that this always holds.
An exemption could be if we insert ligatures, that are two spaces wide.
But at the moment we can not anyhow (because there is no way to add
information to the ligature tables right now).
If a glyph is wider a warning is issued.
No warning is issued if the glyph shall have some overlap. That overlap
is taken into account of this check.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
The code around `currentSourceFontGlyph` and `copiedToSlot` is
needlessly complex and checks for conditions that are impossible to
occur (possibly because the algorithm was different in the past).
It becomes rather hard to follow which variable holds what kind of value
and when.
[how]
Drop all the string-that-contain-hex-numbers stuff and use a regular
integer list/variable.
Format the string when it is output.
Drop obsolete checks.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
In the patch loop we use two methods to do something with the glyphs
- the glyph object directly (i.e. font[codepoint])
- a selection of glyphs in the font
Using the selection is a bit anonymous and depends on lines far away
(where the selection is set); direct glyph access seems to be easier
understood and is used almost everywhere.
Direct glyph access can not be used for copy() and paste(), but for
everything else.
[how]
The direct glyph addressing is already in use almost for everything, but
not for the transform() calls. This is changed.
Now we transform a specific glyph and not 'all selected glyphs' (with
selection = that specific glyph).
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
The selection is never used.
Later in the code we use a sourceFont selection to paste the glyphs into
it, but that is selected just there, before, and locally not totally.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
This is a TODO item. Well, two in fact.
The symbolFont's selection is used for two things
- the main loop to iterate over all glyphs to insert
- to select the one glyph that is actually copied over
Because the main loop uses iterators on the selection.
The iterator is not 'stable' but invalidates if the selection
is changed.
The current code therefor restores the old selection before the loop
jumps to the head again.
This design is not very robust.
[how]
We need the selection to copy the symbol glyph.
But we can rewrite the loop that it does not need the selection at every
iteration, but that the selection is copied into a list, and we loop
over that list - which is independent on a later selection state.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
Some of the patched Mono fonts do not turn up in the font chooser
of Windows CMD and PowerShell (and probably more).
[how]
For some reasons Windows does not identify the fonts as being strictly
monospaced, so they are hidden in that font choosers.
For the monospaced fonts we set now the Panose proportion 'monospaced'.
Windows seems to honor the Panose properties.
It is not clear why we need to set the old Panose props, especially as
Cascadia Code does not (!) set them and is still detected as monospaced.
Anyhow, the way Windows detects if a font is monospaced is a mystery (at
least for me), and this works, so ;-)
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
Sometimes fontforge returns None for font.path. That should not be the
case according to specs:
font.path
(readonly) Returns a string containing the name of the file from
which the font was originally read (in this session), or if this
is a new font, returns a made up filename in the current directory
named something like “Untitled1.sfd”. See also font.sfd_path.
This seems to be the case for fonts that do not have a fullname set.
I did not search for nor file any issue at Fontforge.
[how]
In fact we already have the original font file name, and we want to
retain its extension anyhow (if nothing is specified), so we use the
filename that we opened to determine the extension.
[note]
Related: #412
Related: #641
[note]
This was the sole usage of font.path.
Has been introduced with commit d8b760aee which looks uncritical.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
When we overwrite a glyph that originally had some special handling, be
it a substitution or position table entry (GPOS/GSUB), that special
handling is usually not appropriate anymore and has to be removed.
If we need special lookup table entries for the new glyph we would have
to add them later anyhow, because we can not rely on their existance.
In Issue #509 it was a ligature entry, that replaced 'f' followed by 'i'
with the 'fi' ligature. The ligature glyph is overwritten by us with a
telephone symbol and the substitution table entry makes no sense
anymore.
[how]
If we overwrite a preexisting codepoint we remove it from all lookup
tables.
Thanks to all other reporters with details.
Fixes: #509#254
Reported-by: mangelozzi <mangelozzi@gmail.com>
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
When the font file is not existing the message we get is either
unreadable or missleading (at least for normal users).
[how]
Explicitely state why we can not open a font file, at least in the cases
where we can.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
The Nerd Font Version is not added to the SFNT Version.
This is also a TODO item in `font-patcher`.
The SFNT-Revision is not updated at all.
[how]
Set the SFNT Version and Revision.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
With commit
f7d6fcb5 font-patcher: Allow processing of fonts with fsType set
we added support for fonts with the fsType set. This came up in
issue #686 with font 'Bicubik'.
The solution in that commit uses (modern) textual flags in the
`fontforge` open() method. But they have been only introduced in 2020,
so people using older `fontforge` could not patch anything anymore.
This has been reported in issue #691.
As a quick fix the fsType support has been removed with commit
ab6fa3c5 Reverts part of #687 * the patcher refuses to patch all/most fonts with this flag in the open options
[how]
Revert f7d6fcb5 but use the old fashioned numerical open flags
interface instead.
[note]
The textual open() flags have been introduced into `fontforge`s python
interface with their commit
4a76712f0c
Font Open flag improvements
* Document more Open flags
* Add string tuple interface to python FontOpen API
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
When fontforge is not able to open the font we fail with a meaninless
exception. Users might think that the font-patcher script itself is
broken.
[how]
Exit the script with a hint how to get more information if fontforge was
not able to open the font.
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
[why]
Through fsType certain restrictions can be set on a font. When fontforge
is used in interactive mode the user can override the restrictions with
a popup dialogue. The font-patcher script dies instead, without any
meaningful message.
[how]
Allow the script to ignore fsType settings when opening.
The restrictions will still persist into the generated patched font.
[note]
This came up with Bicubik by Anton Kudin, that has fsType = 2
(modification restriction) set.
Fixes: #686
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
Useful for allowing installation in system wide
locations as a package from the package manager.
This way the script can be installed in /usr/bin
and glyphs can be in /usr/share/nerd-fonts/glyphs.
Signed-off-by: Aisha Tammy <floss@bsd.ac>