Commit graph

336 commits

Author SHA1 Message Date
Fini Jastrow
04c682fd9c font-patcher: Rewrite font height calculation
[why]
The initial font-patcher used the WIN font metrics to determine the cell
height. What has been found was forced into HHEA metrics but without
observing the USE_TYPO_METRICS flag.
That has been changed to use the TYPO metric instead of the WIN metric
when the font wants that. For that the gap value becomes important.

This is the current code. It still has problems to detect the correct
cell height. A more rigorous approach seem to be needed.

[how]
The baseline to baseline distance is what we need as 'cell height', to
fill it completely with the powerline glyphs. This is a little bit
complicated and not really specified, each font rendering application or
engine can handle the font metrics differently. But there are some
common approaches.

So we try to come up with the correct and congruent height, comparing
different metrics and issuing a warning on problematic fonts.
Afterwards we make all metrics equal (even if they were not before),
because our goal is clear now and we impose it onto all platforms.

[note]
Useful resources:
* https://glyphsapp.com/learn/vertical-metrics
* https://github.com/source-foundry/font-line

Fixes: #1056

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-22 15:23:08 +01:00
Fini Jastrow
ce6c161281 font-patcher: Handle -l option in all metrics
[why]
The -l option tries to improve (especially) the powerline glyphs by
making the baseline to baseline height (cell height) an even number.
But it does so only for 2 of the three possible metrics.

[how]
Assuming the hight is identical for all metrics we just need to add '1'
to all ascender values.

[note]
I'm not sure this does anything. After rounding an odd height might
create a 'sharper' triangle tip, not an even height?
Do not understand the real reason for the -l option.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-22 15:21:09 +01:00
Fini Jastrow
5cc911e559 font-patcher: Use format for output
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-22 15:21:08 +01:00
Fini Jastrow
dd3ed4dc74 font-patcher: Fix Monofur 'Nerd Font Mono' too wide
[why]
Although Monofur is monospaced it has one glyph (hyphen) that is
slightly wider than all others. This results in a Monospaced font that
is slightly too wide.

[how]
Ignore the hyphen width.

[note]
Additionally improve (commented out) debug code (shows now hex
codepoint).

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-22 14:53:21 +01:00
Fini Jastrow
326ccdf601 font-patcher: Improve monospace check
[why]
If a `Nerd Font Mono` font is to be created we need to make sure the
original font is indeed monospaced. If it is not and we enforce the same
adavnce width on all glyphs they will look very ugly. Fonts need to be
designed to be monospaced.

We spot check only some characteristic glyphs for that.

Hermit Bold has a problem. Although it looks more or less monospaced it
has some glyphs wider than all the others, for example the small letter
`m`.
Creating a `Nerd Font Mono` (a font where all glyphs have the same
width) will either: Add too much space to the right of all the other
(smaller) glyphs, or will have the wider glyphs cut off on the right.

[how]
Add small letter 'm' to the spot check list. Now the patcher will by
default refuse to --mono patch that font.

Also add output of first char that fails the monospace check. This makes
debugging easier.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-22 14:24:38 +01:00
Fini Jastrow
b942b12bf4 font-patcher: Improve warning on problematic mono patching
[why]
If a font is problematic to patch as monospaced font, that is detected
but the reporting is maybe not strong enough and gets overlooked.

[how]
Pull font property reporting into dedicated functions.
Use that function additionally in other warning.

[note]
The monospace check uses all glyphs to determine the advance width, but
the actual advance width later ignores some glyphs (that are problematic
in some fonts and are thus ignored, although that glyphs will 'break'
after patching).
This might or might not be useful, I just leave it as it was before.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-21 17:42:29 +01:00
Fini Jastrow
0c51571462 font-patcher: Remove obsolete comment
[why]
That feature mainlined since ... 2.2.0 or so?

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-21 17:42:29 +01:00
Fini Jastrow
7ef696a8b4 font-patcher: Fix: Fix more 'Nerd Font Mono' too wide
[why]
With commit
  99c260831  font-patcher: Fix more 'Nerd Font Mono' too wide

the glyphs 'ij' and 'IJ' are exempted from the advance width
calculation, because some fonts (i.e. Overpass Mono) defines them as two
cell wide glyphs (Hello? 'Mono'?)

For some obscure reason it was 'IJ' and 'J circumflex' that were
exempt, not 'ij'.

[how]
Exempt correct code.

Fixes: #703

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-21 17:42:16 +01:00
Fini Jastrow
8deda7fb49 font-patcher: Increase script version after last bugfix
[why]
With commit
  f240e073f font-patcher: Fix windows Mono family names with --makegroups

the script version did not change, which makes it impossible to say if a
user uses a bugfixed patcher or not.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-18 21:16:35 +01:00
Fini Jastrow
f240e073f0 font-patcher: Fix windows Mono family names with --makegroups
[why]
Without --makegroups the font family is "Name NFM", but with it enabled
we get "Name NF Mono".

[how]
Mimic the old short-naming also for the groups.

This feels a bit strange, why do we need to specify the names three
times for `inject_suffix()`, slightly different. At some point this
should probably be unified.

    def inject_suffix(self, fullname, fontname, family):
        """Add a custom additonal string that shows up in the resulting names"""

In principle Family + Subfamily -> Fullname -> Fontname
Somehow we rename not according to the default rules.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-18 15:15:24 +01:00
Finii
1cc7631da3 [ci] Bump release version 2023-01-17 19:02:09 +00:00
Fini Jastrow
54acb57739 font-patcher: Add ScaleGlyph for Material Design Icons
[why]
Scaling the glyphs individually breaks a lot of glyph pairs or groups,
for example F0718-F071E.

[how]
Use one ScaleGlyph for the complete set. The set itself is already very
well scaled, i.e. all glyphs are maximized in a given design space and
that they look good next to pairing glyphs.
There is no need to use ScaleRules which is quite costly for such a big
range of glyphs (they all are copied twice in the process).

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-13 13:02:05 +01:00
Fini Jastrow
cd39545628 font-patcher: Add mixture of ScaleGlyph and ScaleGroups
[why]
ScaleGlyph always did scaling only (no translation) based on one
reference glyph.

ScaleGroups does scaling and translation but can not work with one
reference glyph but constructs always a combined bounding box.

Missing is a way to scale AND translate, but with only one reference
glyph.

[how]
Invent GlyphsToScale+ keyword, that supports just that.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-13 13:01:17 +01:00
Fini Jastrow
5d0c65006d font-patcher: Prevent autohinting on added symbols
[why]
The files sizes of otf files are (especially with the addition of the
current Material Design Icons) big enough already. The autohints are not
really useful for symbols, so we can drop them and save some space.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-13 12:59:53 +01:00
Fini Jastrow
69e8c0e033 Add current Material Design Icons
[why]
Material Design Icons has grown quite a bit.

[how]
Add the icons at their original position which is in PUA1.
Use the desktop font instead of the webfont.
Add cheat cheat file.

Fixes: #365

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-13 12:59:53 +01:00
Fini Jastrow
7cb227c7e0 Rename "Material Design" to "Material Design Legacy"
[why]
We want to differentiate between the old, problematic Material Design
Icons (problematic because we map them to unicode blocks that we should
not), and a future new and updated set of Material Design Icons.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-13 12:59:53 +01:00
Zach DeCook
5426881a76 materialdesignicons: Update to newer version (fix #279)
With appropriate codepoint (fix #365)
2023-01-13 12:59:53 +01:00
Fini Jastrow
e97e7959d6 font-patcher: Fix unexpected 'Book' SubFamily
[why]
Sometimes we set an empty string as SubFamily name. That ends up as
'Book' which is unexpected.

[how]
The translation from empty to "Book" is done by Fontforge, at least
with version 20220308.

Make sure we always have a SubFamily, and if we don't that must be a
'Regular'.

[note]
This was only a problem with the old naming engine. --makegroups got
this right always.

Fixes: #1046

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-13 08:41:47 +01:00
Fini Jastrow
6115c0be11 font-patcher: Make trapezoids more slim
[why]
The trapezoids look very clumsy if scaled too wide.
No user request, just aesthetics.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-12 17:09:43 +01:00
Fini Jastrow
0db79a0b97 font-patcher: Fix vertical overlap
[why]
The vertical overlap is still not 'pixel perfect', it is off by a small
amount that differs by font.

[how]
The reason is the wrong formula. We take the relative widths of the
glyph to calculate the factor needed to add an overlap in height.
Of course we need to take the relative heights *duh*.

Sometimes I think how dumb can a single person be? :-}
I would say this is copy-and-paste laziness.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-12 16:55:38 +01:00
Fini Jastrow
ed929aa7f4 font-patcher: Wide fonts get only 1 cell Powerline glyphs
[why]
The change introduced with commit
  Default some Powerline glyphs to '2 cells wide'

scales some Powerline glyphs to fit exactly into a 2 cell width. That
looks good on 'normal' fonts, but when the font becomes wider and less
tall at some point that is just too wide.

This is especially the case with the SymbolsOnly font which has a 1:1
aspect ratio. Two cell Powerline glyphs would have an aspect ratio of
2:1 which is unusable.

[how]
Check the destination font cell aspect ratio.
When a two-cell glyph would be wider than 1.6 times its height the
two-cell-mode is forbitten and all Powerline glyphs are scaled into one
cell width.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-12 16:37:09 +01:00
Fini Jastrow
f311401e32 font-patcher: Add overlap to left-hexagons E0CC
[why]
The hexagons touch the left edge with a full body, so most likely people
do not want to have any visible gap there.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-12 16:35:08 +01:00
Fini Jastrow
95bdc420da font-patcher: Limit vertical overlap
[why]
The vertical overlap has never been a problem (as far as I know). It is
maybe good to have some overlap for the terminal emulators that support
vertical overlap.
On terminals that truncate at the nominal cell border too much overlap
looks bad, i.e. the glyphs 'distorted'.

If we ever increase the overlap it is most likely be meant to be the
left-right overlap.

Note that the glyphs are usually valign='c' and the overlap is
distributed half top and half bottom. There are no other valign values
implemented (just 'not align' which is ... most likely bad).

[note]
Originally this has been part of commit fecda6a of #780.

[note2]
Originally this has been part of PR #967.
Although that had a bug 😬
It used max() instead of min() (T_T)

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>

f
2023-01-12 16:31:23 +01:00
Fini Jastrow
1637ef7ff2 font-patcher: Unwrap complicated looking code
[why]
We have two variables that hold the same data (sym_dim and dim), which
is confusing ('why do we have it?').

There is also the big 'if' on 'do we want to scale', which contains too
much. In the unlikely event that we have a glyph that needs to be scaled
by 1.0 AND have an overlap the code produces the wrong results.

[how]
Shuffle lines but no functional change (except that now we obey
'overlap' always (not that it has been a problem)).

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-12 11:58:44 +01:00
Fini Jastrow
c303a1ee18 font-patcher: Default some Powerline glyphs to '2 cells wide'
[why]
When we scale all Powerline glyphs also horizontally (in X direction) to
'one cell' some might look a bit too small; especially because they were
very big previoulsy (before commit 'font-patcher: Do x-scale powerline
glyphs').

[how]
To get them to a reasonable and always equal width a new scale code is
introduced: '2'. It is evaluated in 'x' or 'y' scaling contexts and
doubles the target cell width (unless a "Nerd Font Mono" is generated
where all glyphs must be one cell wide).

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-12 11:58:42 +01:00
Fini Jastrow
eb396e617d font-patcher: Remove overlap from line-ish glyphs
[why]
Most Powerline glyphs have a little bit over overlap to the previous or
next glyph to prevent a 'break' in a colored prompt.

It does not make sense to have overlap with glyphs that can never
produce any of that issues, i.e. glyphs that are not filled to the
border. Like all the line-ish glyphs.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-12 11:26:35 +01:00
Fini Jastrow
a6a5a38af5 font-patcher: Do x-scale powerline glyphs
[why]
For the non-Mono variants ('Nerd Font' and 'Nerd Font Propo') the
Powerline symbols are scaled in Y but the width is just kept from the
symbol font, whatever that might be (and if it makes any sense).

If you have for example the triangular thing (`E0B0`) it is bigger than
'one cell' and extrudes into the following cell (on 'Nerd Font'). For
the other side (`E0B2`) it is even worse; it is right aligned in the
current cell and so (because it is wider than one cell) it protrudes
into the previous cell.

[how]
Just allow not only Y scaling but also X scaling for non-Mono fonts.

[note]
This is of relevance just for 'xy' scaling, and only the Powerline
symbols do that.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-12 11:06:42 +01:00
Fini Jastrow
b3c079d6d3 font-patcher: Correct overlap
[why]
The overlap formula seems to be off sometimes. Although the shift is
correct (and thus the number of 'pixels' that overlap), but the non
overlapping part of the glyph is often not as wide as expected, off by
up to some percent.

[how]
The formula is too simple. It just calculates an additional scale factor
on top of the already existing factor. To get it 'pixel perfect' we need
to calculate first how much the glyph fills the cell - because we want
the overlap to be in 'cell percent' and not 'glyph percent'. That might
be sometimes the same (if the cell is filled completely), but usually it
is not completely full, and that means the overlap will be smaller than
intended.

[note]
To get the current glyph bounding box we pull some lines up in the code
that get the 'dim' variable.

Also use float constants to calculate with float variables.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-12 10:53:40 +01:00
Fini Jastrow
95f29260b0 font-patcher: Prepare for code change
No functional change.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-11 18:55:14 +01:00
Fini Jastrow
5f85240519 font-patcher: Centralize more scaling code
[why]
Obviously we can drop more code and shuffle scaling logic into the
scaling function.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-11 18:37:14 +01:00
Fini Jastrow
b571415e6b font-patcher: Fix right-waveform scaling
[why]
While the left-side-waveform gets 'xy' scaled the right-side gets 'pa'
scaled. This has been obviously forgotten.

[how]
Add specific scale rule for right-side-waveform.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-11 18:03:20 +01:00
Fini Jastrow
22684bc4bc font-patcher: Allow glyph down-scaling for non-mono fonts
[why]
On very small source fonts the patched-in symbol-glyphs can become very
big and create overlay problems. It might be desirable to scale them
down to 'two advance widths'.

[how]
It could be that the glyphs in question are in a ScaleGlyph range. So we
need to activate that code also for non-single fonts.

Further we allow two slots wide symbols in get_scale_factors() for those
fonts.

Now we take the computed scale factors for non-single fonts - only if we
scale down and not up. It will confuse/upset people if the known symbols
in their fonts suddenly become bigger - and it also does not look right.

Fixes: #718
Fixes: #747

Reported-by: Rui Ming (Max) Xiong <xsrvmy>
Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-11 16:53:28 +01:00
Fini Jastrow
ebd381c86b font-patcher: Centralize scaling code
[why]
The glyph rescaling is scattered about two functions and several
branches. It becomes hard to follow what is done when and why.

[how]
Use one function that determines any glyph scaling, that includes all
handling except ScaleGlyph related stuff.

This simplifies the code in copy_glyphs() a lot, and keeps all the scaling
in get_scale_factors().

[note]
No behavioral change introduced with this.

[note]
Well, it fixes the possible problem (it will never happen, but lurks)
that a glyph is in the ScaleGlyph range AND has Y scaling set.

The old code first uses the ScaleGlyph scaling and afterwards violates
it by mindlessly doing the Y stretch. This would not happen anymore with
the new code. If a ScaleGlyph is specified for a certain glyph, that
ScaleGlyph is followed and nothing else.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-11 16:32:27 +01:00
Fini Jastrow
99c2608313 font-patcher: Fix more 'Nerd Font Mono' too wide
[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 some fonts that claim to be monospaced still have some
glyphs that are wider than the others.

[how]
Exclude a small group of glyphs from the 'find the widest glyph'.
The list is specifically targetted at the fonts we patch, see PR #1045.

Most of these glyphs are either visually small and it is unclear why
they are too wide (like double-quotes), or they are from the real
extended set, notably all the Eth (D with a slash) and other added-slash
or added-caron glyphs.

In ignoring them we might 'break' these specific glyphs for the people
who use them (like: they extend out of the cell into the next), but that
is the only way to keep the 'monospaced promise' without redesigning the
actual font.
But without these exceptions we have Nerd Font Mono fonts that increase
the cell width so that 'normal text' is rendered almost unreadable.
So this is an improvement for most users; and I see no way so solve
these font issues for all users (without redesigning the font itself ;).

Also add a 'warning' if a (still) problematic font is to be patched.
As reminder for self-patcher or when we add fonts here.

[note]
Related commit
  fbe07b8ab  Fix Noto too wide
  2945cecd1  Fix Overpass Mono too wide

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-11 12:58:27 +01:00
Fini Jastrow
8845e3fb99 font-patcher: Fix Overpass Mono too wide
[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 Overpass (Mono) has wide-as-two-letters IJ and ij ligatures.

[how]
Exclude a small sub-range from the 'find the widest glyph' that contain
these ligatures. Yes they will kind of break, but what can we do if we
want to create a strictly monospaced font?

[note]
Related commit
  fbe07b8ab  Fix Noto too wide

Related: #1043

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-11 12:58:27 +01:00
Fini Jastrow
8bcd7d9033 font-patcher: Fix ScaleRule evaluation (2)
[why]
Forgot to increase the script version with previous commit.

But especially after a bugfix we need a new version to identify
if people use the version before or after
the fix (e.g. docker image).

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-07 10:05:53 +01:00
Fini Jastrow
05a9ec8b6d font-patcher: Fix ScaleRule evaluation
[why]
In some cases only some ScaleRule glyphs are used.

[how]
Store mixture of integers and ranges for ScaleGlyph (as is done for
ScaleGroups).

Correctly evaluate mixture of integers and ranges.

[note]
Came up with PR #773

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-07 09:48:04 +01:00
Fini Jastrow
a56a4fad8e font-patcher: Warn if sourcefont is a VF
[why]
fontforge is not really able to work with OpenType variable fonts, at
least not with all. Some support is available as MM, for older formats.
But anyhow we do not really create a patched variable font but a fixed
font.

People might ignore all the errors Fontforge throws on opening, so an
explicit message might be in order.

[how]
It is not possible to detect a VF input font with current fontforge
reliably. Instead we search for the existence of one of the tables that
are  needed for a variable font. We can not rely on STAT, because that
might be also used in fixed fonts.

Some fontforges might crash on VFs, so we give a warning before we even
open the font and one after the patched font has been created.

Fixes: #512

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-06 16:42:01 +01:00
Fini Jastrow
257d6882fa Make output less verbose (with option)
[why]
Running gotta-patch-em-all creates a lot of output that is most likely
not wanted.

[how]
Add --verbose option to gotta-patch-em-all.
Hide debugging information unless it is wanted by specifying this option.

Also change font-patcher to produce less verbose output and respect
--quite in more places.

This includes a change that we try to tweak the font flags only if
source and destination font are ttf or otf, because we can not read the
other raw font files anyhow.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-06 08:32:48 +01:00
Fini Jastrow
40ded7c2f0 gotta-patch-em-all: Create all fonts with unified release timestamp
[why]
All the fonts will have different timestamps, and within each font the
creation and modification date might also differ. That is quite
confusing and makes automated testing very complicated.

[how]
Use one date-time for ALL fonts and for creation and modification date
in the font file.
But do not change the date-time if we already set that somewhere before :-}

Also remove the 'special' properitary fontforge timestamp tables FFTM from
the patched fonts. This is only possible since FontForge 20th Anniversary
Edition.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-06 08:32:48 +01:00
Fini Jastrow
1e134ca8ff font-patcher: Add ratio limit to xy scale
[why]
The powerline glyphs (and only them) undergo a xy scaling, where both
dimensions are maximized into the 'cell'.

Normally cells are taller than wide, and everyting looks fine. But we
have square cells (e.g. 2048 * 2048) with the SymbolsOnly font, and
there might be some self patched font that has similar very-wide (in
comparison to hight) cells.

In these fonts some powerline glyphs look rather ugly. For example the
'half cicles' become very wide and un-round, the triangulars become very
pointy.

[how]
Add a new patch-set attribute 'xy-ratio'. When that is set the vertical
(y) scaling is done as usual but the horizontal (x) scaling is limited
such that the width/height ratio is maximally the attributes value.

For example setting it to 0.75 the height is maximized (as usual) but
the width is maximized to be less then 0.75 times the hight (or as wide
as the cell is, whatever is smaller).

It will work with both, 'xy' and 'pa' scaling, at least theoretically.
It has been only checked where it is used now, i.e. with 'xy'.

A possible overlap is not taken into account.

[note]
The values are taken for this reasons:
- 0.59: This is the original half-circle ratio, higher values make them
        loose the (half) circular appearance
- 0.5:  The half circle lines are more shallow
- 0.7:  The triangulars should not be too pointy (random number)

Fixes: #658

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-04 17:40:25 +01:00
Fini Jastrow
676e60af71 font-patcher: Add documentation on ScaleGroups
[why]
The old doc was a bit unclear and I always had to read the code when
changes / additions to ScaleRules were needed.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-04 16:28:05 +01:00
Fini Jastrow
69ccea2ff5 font-patcher: Allow ScaleGroups and ScaleGlyph in one ScaleRules
[why]
If a ScaleGlyph is defined that ScaleRules will just be that one rule,
even if in parallel the user specified some ScaleGroups.

So it is either ScaleGroups or ScaleGlyph but not both.
If someone specifies both there is no warning or check.

[how]
Just allow both. Rewrite the ScaleGlyph to an additional (last) entry in
the ScaleGroups.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-04 16:27:03 +01:00
Fini Jastrow
122672b56b font-patcher: Simplify some ifs
[why]
There are several instances of
  if x is True:

This should be written as
  if x:

instead. See PEP 8:
https://peps.python.org/pep-0008/#programming-recommendations

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-04 16:27:03 +01:00
Fini Jastrow
70c4d034a9 font-patcher: Improve Nerd Font Propo with ScaleGroups
[why]
Assume a set of monospaced icons in a ScaleGroup that scatter all about
(like Braille).

With --variable-width-glyphs we forcefully remove all left side
bearings and set the width to the width of the combined bounding box.

This is not correct, usually with monospaced ScaleGroup icons we should
preserve the original advance width.

[how]
Do not remove left side bearings on ScaleGroup glyphs in
--variable-width-glyphs mode.

Set the width of any glyph in --variable-width-glyphs to the 'monoscaped
advance width' if that particular glyph has one (from a ScaleGroup).

The effect is that all positive bearings will be 'added' and put on the
right hand side of the glyph, while the glyph itself, or rather the
combined bounding box, is still strictly left aligned.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-04 16:27:03 +01:00
Fini Jastrow
e4e6887d9e font-patcher: Rename ScaleGlyph to ScaleRules
[why]
We have still a confusing naming. There are two different things that
are called 'ScaleGlyph':
- The setting in the patch set
- The reference glyph for old style scaling

[how]
Rename the patch set member to ScaleRules, as this is what in contained.
Also rename variable names accordingly.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-04 16:27:03 +01:00
Fini Jastrow
6bfad7872e font-patcher: Rename new GlyphsToScale
[why]
We now have the 'old' and the 'new' GlyphsToScale things, which behave
differently, but they have the same name. That can lead to confusion. At
least I am always confused when I look at the code after a month or so.

[how]
Call the 'new' method 'ScaleGroup' instead.

The 'new' feature (which includes creating a combined bounding box and
synchronized shifting) 'ScaleGroup'.

The 'old' feature (which scales all glyphs as if they would have the
size of one reference glyph; shifting is individual) still consists of
'ScaleGlyph' and 'GlyphsToScale'.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-04 16:27:03 +01:00
Fini Jastrow
2ba5dec363 font-patcher: Simplify bounding box scaling
[why]
The code looks so compliacted while in fact it is not (so much).
Rounding sometimes and sometimes not is hard to reaon about. The
un-rounded values should in principle be better, but there is some
rounding hidden in the font that we can not really simulate, so simulate
what we can.

[how]
Always scale (even if factor is one) and round to integer the BB.

[note]
Also use 'is not None' ideom.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-04 16:27:03 +01:00
Fini Jastrow
dc3b2183b4 font-patcher: Fix wrong advance width after group scale
[why]
The advance width in the bounding box data is sometimes wrong (usually
to small). Turned out only AFTER the glyph scaling.

[how]
The wrong scaling factor has been used *duh*.
Advance width is of course X axis.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-04 16:27:03 +01:00
Fini Jastrow
3cfe4a1a06 font-patcher: Fix monospaced glyph collection detection
[why]
When only one symbol glyph is examined we conclude that it comes from a
monospaced glyph set.

This might be correct or not, but when we can not positively say it is
monospaced we should not handle it as monospaced.

[how]
We require at least TWO glyphs with the same width (and no glyph
with a different width) until we set the 'advance' bounding box
property. Which says that this particular glyph subset is monospaced.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2023-01-04 16:27:03 +01:00