mirror of
https://github.com/ryanoasis/nerd-fonts.git
synced 2024-09-19 09:51:48 +02:00
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>
This commit is contained in:
parent
676e60af71
commit
1e134ca8ff
1 changed files with 19 additions and 8 deletions
27
font-patcher
27
font-patcher
|
@ -665,16 +665,16 @@ class font_patcher:
|
|||
'default': {'align': 'c', 'valign': 'c', 'stretch': 'pa', 'params': {}},
|
||||
|
||||
# Arrow tips
|
||||
0xe0b0: {'align': 'l', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.02}},
|
||||
0xe0b1: {'align': 'l', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.02}},
|
||||
0xe0b2: {'align': 'r', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.02}},
|
||||
0xe0b3: {'align': 'r', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.02}},
|
||||
0xe0b0: {'align': 'l', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.02, 'xy-ratio': 0.7}},
|
||||
0xe0b1: {'align': 'l', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.02, 'xy-ratio': 0.7}},
|
||||
0xe0b2: {'align': 'r', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.02, 'xy-ratio': 0.7}},
|
||||
0xe0b3: {'align': 'r', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.02, 'xy-ratio': 0.7}},
|
||||
|
||||
# Rounded arcs
|
||||
0xe0b4: {'align': 'l', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.01}},
|
||||
0xe0b5: {'align': 'l', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.01}},
|
||||
0xe0b6: {'align': 'r', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.01}},
|
||||
0xe0b7: {'align': 'r', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.01}},
|
||||
0xe0b4: {'align': 'l', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.01, 'xy-ratio': 0.59}},
|
||||
0xe0b5: {'align': 'l', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.01, 'xy-ratio': 0.5}},
|
||||
0xe0b6: {'align': 'r', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.01, 'xy-ratio': 0.59}},
|
||||
0xe0b7: {'align': 'r', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.01, 'xy-ratio': 0.5}},
|
||||
|
||||
# Bottom Triangles
|
||||
0xe0b8: {'align': 'l', 'valign': 'c', 'stretch': 'xy', 'params': {'overlap': 0.02}},
|
||||
|
@ -1100,6 +1100,17 @@ class font_patcher:
|
|||
if overlap:
|
||||
scale_ratio_x *= 1 + overlap
|
||||
scale_ratio_y *= 1 + overlap
|
||||
# Size in x to size in y ratio limit (to prevent over-wide glyphs)
|
||||
xy_ratio_max = sym_attr['params'].get('xy-ratio')
|
||||
if (xy_ratio_max):
|
||||
if glyph_scale_data is not None and glyph_scale_data[1] is not None:
|
||||
dim = glyph_scale_data[1]
|
||||
else:
|
||||
dim = sym_dim
|
||||
xy_ratio = dim['width'] * scale_ratio_x / (dim['height'] * scale_ratio_y)
|
||||
if xy_ratio > xy_ratio_max:
|
||||
scale_ratio_x = scale_ratio_x * xy_ratio_max / xy_ratio
|
||||
|
||||
self.sourceFont[currentSourceFontGlyph].transform(psMat.scale(scale_ratio_x, scale_ratio_y))
|
||||
|
||||
# We pasted and scaled now we want to align/move
|
||||
|
|
Loading…
Reference in a new issue