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

Autogenerate original-source glyph font #931

Merged
merged 12 commits into from
Sep 21, 2022
Merged

Conversation

Finii
Copy link
Collaborator

@Finii Finii commented Sep 17, 2022

Description

Add original-source.otf generator script

[why]
When we add a custom glyph (or want to update Seti) the process is
rather laborious and we are needed to change the font and the
accompanying i_seti.sh in sync.

[how]
We use a data file to map icon (svg) filenames to codepoints and
readable names.

That file is parsed and the font and info file is created (overwritten
in the repo); and could then be easily committed. This can be a CI
workflow.

Having a dedicated mapping file (icons.tsv) enables us to have stable
codepoints for the same symbol over time. Changes in codepoint
allocation can be checked in git.

Having the font autogenerated help guarantee that the icons are all
likely scaled. We rescale them all to the same size and mid-position.
That is not needed for font-patcher, because it rescales and shifts
again based on to-be-patched font metrics. But it certainly is better
for a view into the original-source font.

Sizes and position are still roughly equivalent to the hand positioned
glyphs.

Requirements / Checklist

What does this Pull Request (PR) do?

Possibility to generate src/glyphs/original-source.otf and bin/scripts/lib/i_seti.sh from a file that contains a list of codepoints and all the glyph files in src/svgs/.

How should this be manually tested?

Make backup of original-source.otf and i_seti.sh.
Run it (from the script dir). Check changed made to both aforementioned files.

Any background context you can provide?

First motivation:
#833 (comment)

Came up again and again, for example #929 (comment)
when we want to update complete Seti...

What are the relevant tickets (if any)?

Screenshots (if appropriate or helpful)

image

[why]
With commits

  ef8c12e Document and update cheat sheet data
  bcef53d Update cheat sheet

the README has not been updated, and i_cod.sh is still
listed as 'not existing'.

Signed-off-by: Fini Jastrow <[email protected]>
@Finii
Copy link
Collaborator Author

Finii commented Sep 17, 2022

This needs:

  • CI integration
  • A run to update the two files

@Finii
Copy link
Collaborator Author

Finii commented Sep 17, 2022

Ah, codeclimate :-}
It's always annoying, but afterwards it often does look better :->
And better codeclimate than ESlint ;-)

...fixing up

@Finii Finii force-pushed the feature/autogenerate-original branch from 0de28e0 to c970fc7 Compare September 17, 2022 17:30
[why]
When we add a custom glyph (or want to update Seti) the process is
rather laborious and we are needed to change the font and the
accompanying `i_seti.sh` in sync.

[how]
We use a data file to map icon (svg) filenames to codepoints and
readable names.

That file is parsed and the font and info file is created (overwritten
in the repo); and could then be easily committed. This can be a CI
workflow.

Having a dedicated mapping file (`icons.tsv`) enables us to have stable
codepoints for the same symbol over time. Changes in codepoint
allocation can be checked in git.

Having the font autogenerated help guarantee that the icons are all
likely scaled. We rescale them all to the same size and mid-position.
That is not needed for font-patcher, because it rescales and shifts
again based on to-be-patched font metrics. But it certainly is better
for a view into the original-source font.

Sizes and position are still roughly equivalent to the hand positioned
glyphs.

Signed-off-by: Fini Jastrow <[email protected]>
@Finii Finii force-pushed the feature/autogenerate-original branch from c970fc7 to 972fdac Compare September 19, 2022 13:58
[why]
Often the SVGs are rather detailed and result in a big
original-source.otf, which then again results in bigger than needed
patched fonts.

[how]
Typically people suggest using svgo to make SVGs smaller, but that just
tackles the representation of the icon, i.e. the actual svg file. That
does not help us at all. We do not need small svg files, we need simple
icons with few points and lines. svgo does not have that capability.

Instead Inkscape's 'Simplify' is used. Repeated use can destroy a glyph,
so we need a scale down margin to stop 'over-simplification'.

The values given for the margin at the moment are purely empirical, the
current glyphs survive repeated use of the new simplification script and
still look good.

The resultant original-source.otf file size is approximately similar to
the previously achieved by Ryan's manual work.

[note]
We need a newer Inkscape, thus update to Ubuntu 22.04

Signed-off-by: Fini Jastrow <[email protected]>
@Finii Finii force-pushed the feature/autogenerate-original branch from ca599d7 to 86a372f Compare September 19, 2022 14:09
@Finii
Copy link
Collaborator Author

Finii commented Sep 19, 2022

Ah yes! 🎉 How beautifully is that working?

First it looks at all svgs and simplifies them. That has been previously a manual task...

Checking for SVG simplifications
  Files might be MODIFIED by this run ('doit' specified)
Found 58 svgs in ../../src/svgs
Simplification for go.svg (19570 -> 5504) 28%
Simplification for config-folder.svg (14779 -> 3029) 20%
Simplification for grunt.svg (16596 -> 8178) 49%
Simplification for config.svg (14830 -> 3555) 23%
Simplification for octocat-folder.svg (8043 -> 2884) 35%
Simplification for react.svg (8004 -> 5748) 71%
Simplification for typescript.svg (3973 -> 2427) 61%
Simplification for go2.svg (25555 -> 6855) 26%
Simplification for bower.svg (6223 -> 4602) 73%
Simplification for c.svg (3758 -> 2384) 63%
Simplification for electron.svg (6024 -> 4212) 69%
Simplification for separator.svg (4938 -> 2115) 42%
Simplification for handlebars.svg (3101 -> 2097) 67%
Simplification for stylus.svg (4388 -> 2112) 48%
Simplification for coffeescript.svg (4146 -> 3297) 79%
Simplification for c++.svg (4338 -> 3254) 75%
Simplification for git-folder.svg (3107 -> 2471) 79%
Simplification for rss.svg (4227 -> 2175) 51%
Simplification for ms-dos.svg (8842 -> 5174) 58%
Simplification for license.svg (22305 -> 4062) 18%
Simplification for javascript.svg (4807 -> 2681) 55%
Simplification for npm-folder.svg (4477 -> 2738) 61%
Simplification for twig.svg (13214 -> 3455) 26%
Simplification for less.svg (8921 -> 3189) 35%
Simplification for php.svg (4790 -> 3346) 69%
Found 25 svgs to simplify

And as you can see, quite a number were not optimized :->

And then the font is spit out...:

[Nerd Fonts]  Glyph collection font generator 2.2.2

Read glyph data successfully with 65 entries (6 aliases)
Generating original-source.otf with 59 glyphs
Generating GlyphInfo i_seti.sh
Finished

And both of these changes are automatically added to the PR. 😀

@Finii
Copy link
Collaborator Author

Finii commented Sep 19, 2022

Here is what came out ...

The font got smaller, all SVGs got bigger? Yes, they are not optimized with svgo anymore, but that does optimize only the filesize of the svg and NOT the contents. And we do not care about the file size, we want small in number of nodes and paths, and do not care about svg-file-size. Because font file size depends only on number of nodes and paths.

image

And the actual font became even smaller. Without the optimization, created from the (un-simplified source svgs) the size was roughly 120k.

And even the go symbol looks ok now, which has been broken a long time with big ugly eyes...

image

Edit: Use better image for font

[why]
When the CI triggers a rebuild of the original-source and the font
contents is unchanged we do not want to commit the new version back to
the repo.

But because fontforge puts the creation date into the font file it will
always differ on every run, and we would needlessly create commits.

[how]
We could use the SOURCE_DATE_EPOCH approach and set the dates to the
relevant change (commit) times like so:

cd src/svgs
export SOURCE_DATE_EPOCH="$(git log -1 --format=%ct -- *.svg)"

and only afterwards call the generator script / fontforge.

But that would need a complete git repo checkout and not just a shallow
one (which is faster and thus is used by github action/checkout).

Instead we can instruct fontforge to not put any timestamp into the
file. The timestamps are anyhow a fontforge proprietary extension.

Signed-off-by: Fini Jastrow <[email protected]>
@Finii
Copy link
Collaborator Author

Finii commented Sep 20, 2022

This should not have happened:

image

I just added some documentation, and a 'new' original-source.otf has been automagically committed.
It should only commit a new font, if the font is changed.

This is fixed by the following (force pushed) change:

@Finii Finii force-pushed the feature/autogenerate-original branch from 9c9fa3f to fd0849f Compare September 20, 2022 08:30
@Finii
Copy link
Collaborator Author

Finii commented Sep 20, 2022

Obviously the fix did not ... fix it. :-(

@Finii Finii force-pushed the feature/autogenerate-original branch from 6628e4e to 5fb3d01 Compare September 20, 2022 13:35
@Finii
Copy link
Collaborator Author

Finii commented Sep 20, 2022

That did work in my fork, why not here? :-(
Continuing later.

@Finii
Copy link
Collaborator Author

Finii commented Sep 21, 2022

Found it:

image

It detects a difference, because we force 'both' timestamps to the previous font's creation time, but THAT font has different creation and modification time set. Creation time is the time when creation started, and mod time, when it finished, and when that hits a seconds boundary we have to different times. That is the reason why it does only happen sometimes.

Fixing...

[why]
Despite commit
  cc2b547 generate-original-source: Remove FFTM table
we still get unneeded font rebuilds.

The reason is that the font creation time is not only encoded in FFTM but
also in HEAD.

[how]
We could simply diable timestamps also in HEAD, but that would leave us
with a strange font; strange because no one knows when it has been
created.

Instead we take the more laberous route here: Do detect changes and not
rely on the git history:
* Find out current font's creation date
* Create the font anew with that date as creation date
* If the 'real' font content is unchanged we would now have a 100%
  identical new font file; we can detect that with `git diff`
* If it is not identical, something apart from the timestamp has
  changed and we create the font again, this time with the real current
  time as timestamp and commit that file back to the repo

This only works if creation and modification time are always the same on
all font creations; we need to ensure this by always using the
SOURCE_DATE_EPOCH method, even for 'normal' font creation.

This is a bit more involved than what I would have hoped for, but there
seems to be no easy solution.

Signed-off-by: Fini Jastrow <[email protected]>
[why]
This is so big, it will shrink 2 times with a
optimize-original-source.sh run, and we want to have 'optimal' glyphs
after the next (automated) CI run

[how]
Use optimize-original-source.sh once and just commit the php.svg.

Signed-off-by: Fini Jastrow <[email protected]>
@Finii Finii force-pushed the feature/autogenerate-original branch 4 times, most recently from 9b71905 to d6f6e5d Compare September 21, 2022 10:13
[why]
When so svg files could be optimized we still try to commit the
'changes'. There are no changes - so nothing is committed (empty commits
are avoided).

But the workflow run still shows the 'commit back to repo' step,
although we know beforehand that it will not commit anything.

[how]
Technically that is no problem and the behavior is unchanged, but we can
just skip the commit step if we know there can not be anything to
commit...

It just looks nicer :-}

Signed-off-by: Fini Jastrow <[email protected]>
@Finii Finii force-pushed the feature/autogenerate-original branch from d6f6e5d to b255bc1 Compare September 21, 2022 11:58
@Finii Finii merged commit 46a7c03 into master Sep 21, 2022
@Finii Finii deleted the feature/autogenerate-original branch September 21, 2022 12:09
LNKLEO pushed a commit to LNKLEO/Nerd that referenced this pull request Nov 24, 2023
…original

Autogenerate original-source glyph font
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.

1 participant